/* リセット */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: #f5f5f7;
    color: #1d1d1f;
    line-height: 1.6;
}

/* ===== App Header ===== */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-header h1 {
    font-size: 1.4rem;
    font-weight: 700;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.mobile-sidebar-btn {
    display: none;
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Sidebar overlay (mobile) */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 80;
}

.sidebar-overlay.active {
    display: block;
}

/* Auth UI */
.btn-login {
    display: inline-block;
    padding: 6px 16px;
    background: rgba(255,255,255,0.2);
    color: white;
    border-radius: 6px;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.2s;
}

.btn-login:hover {
    background: rgba(255,255,255,0.35);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.5);
}

.user-name {
    font-size: 14px;
    font-weight: 500;
}

.btn-logout {
    padding: 4px 10px;
    background: rgba(255,255,255,0.15);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    text-decoration: none;
}

.btn-logout:hover {
    background: rgba(255,255,255,0.3);
}

.btn-admin {
    padding: 4px 10px;
    background: rgba(255,200,0,0.3);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    text-decoration: none;
}

.btn-admin:hover {
    background: rgba(255,200,0,0.5);
}

/* ===== Layout ===== */
.app-layout {
    display: flex;
    min-height: calc(100vh - 56px);
}

/* ===== Sidebar ===== */
.sidebar {
    width: 280px;
    min-width: 280px;
    background: white;
    border-right: 1px solid #e1e1e1;
    position: sticky;
    top: 56px;
    height: calc(100vh - 56px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid #e1e1e1;
}

.sidebar-header h2 {
    font-size: 1rem;
    font-weight: 300;
    color: #333;
    text-align: center;
    width: 100%;
}

.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: #666;
}

.sidebar-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.sidebar-empty {
    text-align: center;
    color: #999;
    padding: 20px 8px;
    font-size: 13px;
}

/* Sidebar session cards */
.sidebar-card {
    border: 1px solid #e8e8e8;
    border-radius: 6px;
    padding: 6px;
    margin-bottom: 6px;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.sidebar-card:hover {
    border-color: #667eea;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.15);
}

.sidebar-card-date {
    font-size: 11px;
    font-weight: 600;
    color: #666;
    margin-bottom: 4px;
}

.sidebar-thumbnails {
    display: flex;
    gap: 2px;
}

.sidebar-thumbnails img {
    flex: 1;
    min-width: 0;
    height: auto;
    aspect-ratio: 1;
    border-radius: 2px;
    object-fit: cover;
}

/* Domain accordion */
.domain-group {
    margin-bottom: 4px;
}

.domain-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.15s;
    user-select: none;
}

.domain-header:hover {
    background: #f0f0f5;
}

.domain-name {
    flex: 1;
    font-size: 13px;
    font-weight: 600;
    color: #333;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.domain-count {
    font-size: 11px;
    font-weight: 500;
    color: #fff;
    background: #667eea;
    border-radius: 10px;
    padding: 1px 7px;
    min-width: 20px;
    text-align: center;
}

.domain-arrow {
    font-size: 10px;
    color: #999;
    transition: transform 0.2s;
}

.domain-group.open .domain-arrow {
    transform: rotate(90deg);
}

.domain-sessions {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease;
}

.domain-group.open .domain-sessions {
    max-height: 2000px;
}

.domain-sessions .sidebar-card {
    margin: 0 4px 6px 12px;
}

.sidebar-card.active {
    border-color: #667eea;
    background: #f5f3ff;
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    padding: 20px 24px;
    max-width: 1000px;
}

.subtitle {
    text-align: center;
    font-size: 1rem;
    color: #666;
    margin-bottom: 24px;
}

/* フォームセクション */
.form-section {
    background: white;
    padding: 24px;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    margin-bottom: 24px;
    text-align: center;
}

.form-group {
    margin-bottom: 16px;
    text-align: left;
}

/* Bootstrap form-floating override */
.form-floating > .form-control:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
}

.checkbox-group {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 8px;
}

.checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.checkbox-group label {
    margin: 0;
    cursor: pointer;
    font-size: 14px;
    color: #666;
    display: flex;
    align-items: center;
    gap: 6px;
}

.badge-info {
    display: inline-block;
    font-size: 11px;
    padding: 2px 8px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 12px;
    font-weight: 500;
}

.btn-generate {
    padding: 12px 28px;
    font-size: 16px;
    font-weight: 600;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.btn-generate:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-generate:active:not(:disabled) {
    transform: translateY(0);
}

.btn-generate:disabled {
    background: linear-gradient(135deg, #94a3b8 0%, #64748b 100%);
    cursor: not-allowed;
    opacity: 0.8;
}

/* スピナーアニメーション */
.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: none;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.btn-generate.loading .spinner {
    display: block;
}

/* 追加画像生成ボタン */
.btn-generate-more {
    margin-top: 20px;
    padding: 12px 24px;
    font-size: 16px;
    font-weight: 600;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.btn-generate-more:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

.btn-generate-more:active:not(:disabled) {
    transform: translateY(0);
}

.btn-generate-more:disabled {
    background: linear-gradient(135deg, #94a3b8 0%, #64748b 100%);
    cursor: not-allowed;
    opacity: 0.8;
}

.btn-generate-more .spinner {
    display: none;
}

.btn-generate-more.loading .spinner {
    display: block;
}

/* 進捗セクション */
.progress-section {
    background: white;
    padding: 24px;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    margin-bottom: 24px;
}

.progress-content {
    text-align: center;
}

.progress-message {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 16px;
    color: #667eea;
}

.progress-bar-container {
    position: relative;
    margin-bottom: 10px;
}

#progress-bar {
    width: 100%;
    height: 30px;
    border-radius: 15px;
    -webkit-appearance: none;
    appearance: none;
}

#progress-bar::-webkit-progress-bar {
    background-color: #e1e1e1;
    border-radius: 15px;
}

#progress-bar::-webkit-progress-value {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 15px;
}

#progress-bar::-moz-progress-bar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 15px;
}

.progress-text {
    display: block;
    margin-top: 8px;
    font-size: 14px;
    color: #666;
}

/* グリッドセクション */
.grid-section {
    margin-top: 24px;
}

.grid {
    margin: 0 auto;
}

/* Masonry sizing */
.grid-sizer,
.grid-item {
    width: calc(33.333% - 6px);
}

.gutter-sizer {
    width: 8px;
}

.grid-item {
    margin-bottom: 8px;
}

.grid-item img {
    width: 100%;
    height: auto;
    display: block;
}

/* アニメーション */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.grid-item {
    animation: fadeIn 0.5s ease-out;
}

/* ===== Responsive ===== */

/* Tablet: 2-column grid */
@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 56px;
        bottom: 0;
        z-index: 90;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0,0,0,0.15);
    }

    .sidebar-toggle {
        display: block;
    }

    /* Show toggle button in header on mobile */
    .mobile-sidebar-btn {
        display: inline-block;
    }

    .main-content {
        padding: 16px;
    }

    .grid-sizer,
    .grid-item {
        width: calc(50% - 4px);
    }
}

/* Phone: single column grid */
@media (max-width: 600px) {
    .app-header h1 {
        font-size: 1.1rem;
    }

    .grid-sizer,
    .grid-item {
        width: 100%;
    }

    .gutter-sizer {
        width: 0;
    }

    .grid-item {
        margin-bottom: 8px;
    }

    .form-section {
        padding: 16px;
    }

    .btn-generate {
        font-size: 16px;
    }

    .subtitle {
        font-size: 0.9rem;
    }
}
