/* Taleclip Web UI Styles */

:root {
    /* ═══════════════════════════════════════════════════
       TALECLIP GLASS DESIGN SYSTEM — Dark Mode (Default)
       ═══════════════════════════════════════════════════ */

    /* ── Base Background ── */
    --tc-bg-base:         #0a0f1e;
    --tc-bg-gradient:     linear-gradient(160deg, #0c1425 0%, #0e1a30 40%, #0b1222 100%);

    /* ── Glass Surfaces ── */
    --tc-glass-bg:        rgba(255, 255, 255, 0.06);
    --tc-glass-bg-hover:  rgba(255, 255, 255, 0.10);
    --tc-glass-bg-active: rgba(255, 255, 255, 0.14);
    --tc-glass-bg-input:  rgba(255, 255, 255, 0.05);
    --tc-glass-bg-sidebar:rgba(255, 255, 255, 0.04);
    --tc-glass-bg-topbar: rgba(255, 255, 255, 0.05);
    --tc-glass-blur:      16px;
    --tc-glass-blur-heavy:24px;
    --tc-glass-blur-light:8px;

    /* ── Glass Borders ── */
    --tc-glass-border:      1px solid rgba(148, 163, 184, 0.08);
    --tc-glass-border-hover:1px solid rgba(148, 163, 184, 0.15);
    --tc-glass-border-focus:1px solid rgba(59, 130, 246, 0.4);
    --tc-glass-border-subtle:1px solid rgba(255, 255, 255, 0.04);

    /* ── Primary Accent — Electric Blue ── */
    --tc-primary:         #3B82F6;
    --tc-primary-hover:   #2563eb;
    --tc-primary-glow:    rgba(59, 130, 246, 0.25);
    --tc-primary-glow-strong: rgba(59, 130, 246, 0.4);
    --tc-primary-surface: rgba(59, 130, 246, 0.1);
    --tc-primary-gradient:linear-gradient(135deg, #3B82F6, #8B5CF6);

    /* ── Secondary Accent — Violet ── */
    --tc-secondary:       #8B5CF6;
    --tc-secondary-glow:  rgba(139, 92, 246, 0.2);

    /* ── Success — Teal ── */
    --tc-success:         #14b8a6;
    --tc-success-glow:    rgba(20, 184, 166, 0.25);
    --tc-success-surface: rgba(20, 184, 166, 0.1);

    /* ── Warning — Amber ── */
    --tc-warning:         #f59e0b;
    --tc-warning-glow:    rgba(245, 158, 11, 0.25);
    --tc-warning-surface: rgba(245, 158, 11, 0.1);

    /* ── Error — Red ── */
    --tc-error:           #ef4444;
    --tc-error-glow:      rgba(239, 68, 68, 0.25);
    --tc-error-surface:   rgba(239, 68, 68, 0.1);

    /* ── CTA — Gold ── */
    --tc-cta:             #eab308;
    --tc-cta-hover:       #ca8a04;
    --tc-cta-glow:        rgba(234, 179, 8, 0.3);

    /* ── Text ── */
    --tc-text-primary:    #f1f5f9;
    --tc-text-secondary:  #94a3b8;
    --tc-text-muted:      #64748b;
    --tc-text-disabled:   #475569;
    --tc-text-inverse:    #0f172a;

    /* ── Typography ── */
    --tc-font-sans:       'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --tc-font-mono:       'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
    --tc-font-size-xs:    0.7rem;
    --tc-font-size-sm:    0.8rem;
    --tc-font-size-base:  0.9rem;
    --tc-font-size-md:    1rem;
    --tc-font-size-lg:    1.15rem;
    --tc-font-size-xl:    1.35rem;
    --tc-font-size-2xl:   1.75rem;
    --tc-font-size-3xl:   2.25rem;
    --tc-line-height:     1.6;
    --tc-font-weight-normal:  400;
    --tc-font-weight-medium:  500;
    --tc-font-weight-semi:    600;
    --tc-font-weight-bold:    700;

    /* ── Spacing (8px grid) ── */
    --tc-space-1:  4px;
    --tc-space-2:  8px;
    --tc-space-3:  12px;
    --tc-space-4:  16px;
    --tc-space-5:  20px;
    --tc-space-6:  24px;
    --tc-space-8:  32px;
    --tc-space-10: 40px;
    --tc-space-12: 48px;
    --tc-space-16: 64px;

    /* ── Corner Radius ── */
    --tc-radius-sm:    6px;
    --tc-radius-md:    10px;
    --tc-radius-lg:    18px;
    --tc-radius-xl:    24px;
    --tc-radius-pill:  9999px;
    --tc-radius-round: 50%;

    /* ── Shadows ── */
    --tc-shadow-sm:    0 2px 8px rgba(0, 0, 0, 0.15);
    --tc-shadow-md:    0 4px 16px rgba(0, 0, 0, 0.2);
    --tc-shadow-lg:    0 8px 32px rgba(0, 0, 0, 0.25);
    --tc-shadow-xl:    0 16px 48px rgba(0, 0, 0, 0.35);
    --tc-shadow-2xl:   0 24px 64px rgba(0, 0, 0, 0.45);

    /* ── Glow Shadows ── */
    --tc-glow-primary: 0 0 20px rgba(59, 130, 246, 0.15), 0 4px 16px rgba(59, 130, 246, 0.1);
    --tc-glow-success: 0 0 20px rgba(20, 184, 166, 0.15);
    --tc-glow-warning: 0 0 20px rgba(245, 158, 11, 0.15);
    --tc-glow-error:   0 0 20px rgba(239, 68, 68, 0.15);
    --tc-glow-cta:     0 0 24px rgba(234, 179, 8, 0.2), 0 4px 16px rgba(234, 179, 8, 0.15);

    /* ── Focus Ring ── */
    --tc-focus-ring:   0 0 0 2px rgba(59, 130, 246, 0.4), 0 0 16px rgba(59, 130, 246, 0.15);

    /* ── Transitions ── */
    --tc-transition-fast:    150ms ease;
    --tc-transition-normal:  200ms ease;
    --tc-transition-slow:    300ms ease;

    /* ── Z-Index Scale ── */
    --tc-z-sidebar:    100;
    --tc-z-topbar:     110;
    --tc-z-dropdown:   200;
    --tc-z-drawer:     300;
    --tc-z-modal:      1000;
    --tc-z-chat:       2000;
    --tc-z-overlay:    9000;
    --tc-z-toast:      9500;
    --tc-z-critical:   10000;

    /* ── Layout ── */
    --tc-sidebar-width:      220px;
    --tc-sidebar-collapsed:  60px;
    --tc-topbar-height:      56px;
    --tc-content-max-width:  1200px;
    --tc-content-padding-x:  48px;
    --tc-content-padding-y:  32px;

    /* ── Legacy Aliases (backward compat) ── */
    --primary: var(--tc-primary);
    --primary-dark: var(--tc-primary-hover);
    --secondary: var(--tc-success);
    --accent: var(--tc-cta);
    --bg: var(--tc-bg-base);
    --bg-darker: #080c14;
    --bg-card: var(--tc-glass-bg);
    --bg-input: var(--tc-glass-bg-input);
    --bg-sidebar: var(--tc-glass-bg-sidebar);
    --text: var(--tc-text-primary);
    --text-muted: var(--tc-text-secondary);
    --border: var(--tc-text-disabled);
    --error: var(--tc-error);
    --warning: var(--tc-warning);
    --success: var(--tc-success);
    --sidebar-width: var(--tc-sidebar-width);
    --text-primary: var(--tc-text-primary);
    --text-secondary: var(--tc-text-secondary);
    --border-color: var(--tc-text-disabled);
    --bg-body: var(--tc-bg-base);
    color-scheme: dark;
}

/* ═══════════════════════════════════════════════════
   LIGHT MODE
   ═══════════════════════════════════════════════════ */
[data-theme="light"] {
    --tc-bg-base:         #e8eef6;
    --tc-bg-gradient:     linear-gradient(160deg, #e8eef6 0%, #dce4f0 40%, #eef2f8 100%);

    --tc-glass-bg:        rgba(255, 255, 255, 0.6);
    --tc-glass-bg-hover:  rgba(255, 255, 255, 0.72);
    --tc-glass-bg-active: rgba(255, 255, 255, 0.8);
    --tc-glass-bg-input:  rgba(255, 255, 255, 0.55);
    --tc-glass-bg-sidebar:rgba(255, 255, 255, 0.65);
    --tc-glass-bg-topbar: rgba(255, 255, 255, 0.65);

    --tc-glass-border:      1px solid rgba(100, 116, 139, 0.22);
    --tc-glass-border-hover:1px solid rgba(100, 116, 139, 0.35);
    --tc-glass-border-focus:1px solid rgba(59, 130, 246, 0.5);
    --tc-glass-border-subtle:1px solid rgba(0, 0, 0, 0.08);

    --tc-primary:         #3B82F6;
    --tc-primary-hover:   #2563eb;
    --tc-primary-glow:    rgba(59, 130, 246, 0.15);
    --tc-primary-glow-strong: rgba(59, 130, 246, 0.25);
    --tc-primary-surface: rgba(59, 130, 246, 0.08);
    --tc-primary-gradient:linear-gradient(135deg, #3B82F6, #8B5CF6);

    --tc-text-primary:    #1e293b;
    --tc-text-secondary:  #64748b;
    --tc-text-muted:      #94a3b8;
    --tc-text-disabled:   #cbd5e1;
    --tc-text-inverse:    #f1f5f9;

    --tc-shadow-sm:    0 2px 8px rgba(0, 0, 0, 0.06);
    --tc-shadow-md:    0 4px 16px rgba(0, 0, 0, 0.08);
    --tc-shadow-lg:    0 8px 32px rgba(0, 0, 0, 0.1);
    --tc-shadow-xl:    0 16px 48px rgba(0, 0, 0, 0.12);

    /* Legacy aliases */
    --primary: var(--tc-primary);
    --primary-dark: var(--tc-primary-hover);
    --secondary: #059669;
    --accent: #ca8a04;
    --bg: var(--tc-bg-base);
    --bg-darker: #e2e8f0;
    --bg-card: var(--tc-glass-bg);
    --bg-input: var(--tc-glass-bg-input);
    --bg-sidebar: var(--tc-glass-bg-sidebar);
    --text: var(--tc-text-primary);
    --text-muted: var(--tc-text-secondary);
    --border: var(--tc-text-disabled);
    --error: #dc2626;
    --warning: #d97706;
    --success: #059669;
    --text-primary: var(--tc-text-primary);
    --text-secondary: var(--tc-text-secondary);
    --border-color: var(--tc-text-disabled);
    --bg-body: var(--tc-bg-base);
    color-scheme: light;
}

/* Light mode: stronger borders & card definition */
[data-theme="light"] .sidebar {
    border-right: 1px solid rgba(100, 116, 139, 0.22);
}
[data-theme="light"] .nav-item:hover,
[data-theme="light"] .nav-item.active {
    background: rgba(0,0,0,0.06);
}
[data-theme="light"] .card,
[data-theme="light"] .dashboard-card {
    border: 1px solid rgba(100, 116, 139, 0.22);
    box-shadow: var(--tc-shadow-sm);
}
[data-theme="light"] .top-bar {
    border-bottom: 1px solid rgba(100, 116, 139, 0.22);
}
[data-theme="light"] .creation-card {
    border: 1px solid rgba(100, 116, 139, 0.22);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}
[data-theme="light"] .feature-card,
[data-theme="light"] .highlight-card {
    border: 1px solid rgba(100, 116, 139, 0.22);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}
[data-theme="light"] .feature-card:hover,
[data-theme="light"] .highlight-card:hover {
    border-color: rgba(100, 116, 139, 0.35);
}
[data-theme="light"] .mode-toggle {
    border: 1px solid rgba(100, 116, 139, 0.22);
}
[data-theme="light"] .prompt-input-wrapper,
[data-theme="light"] .prompt-input,
[data-theme="light"] textarea {
    border: 1px solid rgba(100, 116, 139, 0.25);
}
[data-theme="light"] .prompt-input:focus,
[data-theme="light"] textarea:focus {
    border-color: var(--tc-primary);
}
[data-theme="light"] select,
[data-theme="light"] .form-control,
[data-theme="light"] input[type="text"],
[data-theme="light"] input[type="number"],
[data-theme="light"] input[type="email"],
[data-theme="light"] input[type="password"] {
    border: 1px solid rgba(100, 116, 139, 0.25);
}
[data-theme="light"] .mode-tabs {
    border: 1px solid rgba(100, 116, 139, 0.18);
    border-radius: var(--tc-radius-lg);
}
[data-theme="light"] .home-section {
    background: rgba(255, 255, 255, 0.5);
    border: 1px solid rgba(100, 116, 139, 0.15);
    border-radius: 16px;
    padding: 24px;
    margin-bottom: 16px;
}
[data-theme="light"] .sidebar-section {
    border-top: 1px solid rgba(100, 116, 139, 0.15);
}
[data-theme="light"] .admin-drawer {
    border: 1px solid rgba(100, 116, 139, 0.22);
    border-radius: var(--tc-radius-lg);
}
[data-theme="light"] .settings-panel {
    border: 1px solid rgba(100, 116, 139, 0.22);
}
[data-theme="light"] .modal-content {
    border: 1px solid rgba(100, 116, 139, 0.22);
}
[data-theme="light"] .upload-dropzone {
    border: 2px dashed rgba(100, 116, 139, 0.3);
}
[data-theme="light"] .upload-dropzone:hover,
[data-theme="light"] .upload-dropzone.dragover {
    border-color: var(--tc-primary);
}
[data-theme="light"] .settings-bar {
    background: rgba(255, 255, 255, 0.6);
    border: 1px solid rgba(100, 116, 139, 0.18);
    border-radius: 12px;
    padding: 10px 14px;
}
[data-theme="light"] .progress-card {
    border: 1px solid rgba(100, 116, 139, 0.22);
}
[data-theme="light"] .result-card {
    border: 1px solid rgba(100, 116, 139, 0.22);
}
[data-theme="light"] .gallery-section {
    border: 1px solid rgba(100, 116, 139, 0.15);
    border-radius: 12px;
    padding: 16px;
    background: rgba(255, 255, 255, 0.35);
}
[data-theme="light"] .gallery-tab {
    border: 1px solid rgba(100, 116, 139, 0.15);
}
[data-theme="light"] .gallery-tab.active {
    border-color: var(--tc-primary);
}
[data-theme="light"] .history-panel {
    border: 1px solid rgba(100, 116, 139, 0.22);
}
[data-theme="light"] .history-header {
    border-bottom: 1px solid rgba(100, 116, 139, 0.18);
    background: rgba(100, 116, 139, 0.05);
}
[data-theme="light"] .video-main-mode-toggle {
    border: 1px solid rgba(100, 116, 139, 0.18);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.5);
}
[data-theme="light"] .main-mode-btn {
    border: 1px solid transparent;
}
[data-theme="light"] .main-mode-btn.active {
    border-color: var(--tc-primary);
    background: rgba(255, 255, 255, 0.8);
}
[data-theme="light"] .setting-select,
[data-theme="light"] .setting-select-small {
    border: 1px solid rgba(100, 116, 139, 0.25);
}
[data-theme="light"] .scene-entry {
    border: 1px solid rgba(100, 116, 139, 0.2);
    border-radius: 10px;
}
[data-theme="light"] .dialogue-section {
    border: 1px solid rgba(100, 116, 139, 0.15);
    border-radius: 10px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.4);
}
[data-theme="light"] .btn-generate {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}
[data-theme="light"] .image-upload-inline {
    border: 1px solid rgba(100, 116, 139, 0.18);
    border-radius: 12px;
}
[data-theme="light"] .page-title {
    color: var(--tc-text-primary);
}
[data-theme="light"] .sidebar-footer {
    border-top: 1px solid rgba(100, 116, 139, 0.15);
}

/* ═══════════════════════════════════════════════════
   COLOR THEMES (accent overrides, work in both modes)
   ═══════════════════════════════════════════════════ */
[data-color-theme="ocean"] {
    --tc-primary: #3b82f6; --tc-primary-hover: #2563eb;
    --tc-primary-glow: rgba(59, 130, 246, 0.25); --tc-primary-glow-strong: rgba(59, 130, 246, 0.4);
    --tc-primary-surface: rgba(59, 130, 246, 0.1); --tc-primary-gradient: linear-gradient(135deg, #3b82f6, #2563eb);
    --primary: var(--tc-primary); --primary-dark: var(--tc-primary-hover);
}
[data-color-theme="forest"] {
    --tc-primary: #22c55e; --tc-primary-hover: #16a34a;
    --tc-primary-glow: rgba(34, 197, 94, 0.25); --tc-primary-glow-strong: rgba(34, 197, 94, 0.4);
    --tc-primary-surface: rgba(34, 197, 94, 0.1); --tc-primary-gradient: linear-gradient(135deg, #22c55e, #16a34a);
    --primary: var(--tc-primary); --primary-dark: var(--tc-primary-hover);
}
[data-color-theme="sunset"] {
    --tc-primary: #f97316; --tc-primary-hover: #ea580c;
    --tc-primary-glow: rgba(249, 115, 22, 0.25); --tc-primary-glow-strong: rgba(249, 115, 22, 0.4);
    --tc-primary-surface: rgba(249, 115, 22, 0.1); --tc-primary-gradient: linear-gradient(135deg, #f97316, #ea580c);
    --primary: var(--tc-primary); --primary-dark: var(--tc-primary-hover);
}
[data-color-theme="rose"] {
    --tc-primary: #f43f5e; --tc-primary-hover: #e11d48;
    --tc-primary-glow: rgba(244, 63, 94, 0.25); --tc-primary-glow-strong: rgba(244, 63, 94, 0.4);
    --tc-primary-surface: rgba(244, 63, 94, 0.1); --tc-primary-gradient: linear-gradient(135deg, #f43f5e, #e11d48);
    --primary: var(--tc-primary); --primary-dark: var(--tc-primary-hover);
}

/* ═══════════════════════════════════════════════════
   GLASSMORPHIC ANIMATIONS
   ═══════════════════════════════════════════════════ */

/* Glass breath — subtle glow pulsation for active cards */
@keyframes glassBreath {
    0%, 100% { box-shadow: var(--tc-glow-primary); }
    50%      { box-shadow: 0 0 30px rgba(168, 85, 247, 0.2), 0 4px 20px rgba(168, 85, 247, 0.15); }
}

/* Progress bar shimmer */
@keyframes progressShimmer {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* Modal slide up */
@keyframes modalSlideUp {
    from { opacity: 0; transform: translateY(16px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Backdrop fade in */
@keyframes backdropFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* Slide in from right (panels) */
@keyframes slideInRight {
    from { transform: translateX(100%); }
    to   { transform: translateX(0); }
}

/* Status dot pulse */
@keyframes statusPulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.5; }
}

/* Dropzone drag-over pulse */
@keyframes dropzonePulse {
    0%, 100% { box-shadow: var(--tc-glow-primary); }
    50%      { box-shadow: 0 0 32px rgba(168, 85, 247, 0.3); }
}

/* Glass utility classes */
.tc-glass {
    background: var(--tc-glass-bg);
    backdrop-filter: blur(var(--tc-glass-blur)) saturate(140%);
    -webkit-backdrop-filter: blur(var(--tc-glass-blur)) saturate(140%);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--tc-radius-lg);
    box-shadow: var(--tc-shadow-md), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.tc-glass-dense {
    background: var(--tc-glass-bg-sidebar);
    backdrop-filter: blur(var(--tc-glass-blur-heavy));
    -webkit-backdrop-filter: blur(var(--tc-glass-blur-heavy));
    border: var(--tc-glass-border);
}

.tc-glass-elevated {
    background: var(--tc-glass-bg-active);
    backdrop-filter: blur(var(--tc-glass-blur-heavy));
    -webkit-backdrop-filter: blur(var(--tc-glass-blur-heavy));
    border: var(--tc-glass-border-hover);
    box-shadow: var(--tc-shadow-2xl);
}

/* Theme Toggle Switch */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    vertical-align: middle;
}
.theme-toggle input { display: none; }
.toggle-track {
    position: relative;
    width: 36px;
    height: 20px;
    background: var(--tc-glass-bg-input);
    border-radius: var(--tc-radius-pill);
    border: var(--tc-glass-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 4px;
    box-sizing: border-box;
}
.toggle-icon {
    font-size: 10px;
    line-height: 1;
    user-select: none;
}
.toggle-sun  { color: #f59e0b; }
.toggle-moon { color: #94a3b8; }
.toggle-thumb {
    position: absolute;
    left: 2px;
    top: 2px;
    width: 14px;
    height: 14px;
    background: var(--primary);
    border-radius: 50%;
    transition: left 0.2s ease;
}
.theme-toggle input:checked + .toggle-track .toggle-thumb {
    left: 18px;
}

/* Color Theme Selector */
.theme-select {
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
    cursor: pointer;
    height: 24px;
}

/* ============================================
   NEW ARTLIST-STYLE LAYOUT
   ============================================ */

/* App Layout - Sidebar + Main */
.app-layout {
    display: flex;
    min-height: 100vh;
    background: transparent;
    position: relative;
    z-index: 1;
}

/* Sidebar */
.sidebar {
    width: var(--tc-sidebar-width);
    background: var(--tc-glass-bg-sidebar);
    backdrop-filter: blur(var(--tc-glass-blur-heavy)) saturate(140%);
    -webkit-backdrop-filter: blur(var(--tc-glass-blur-heavy)) saturate(140%);
    border-right: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: var(--tc-z-sidebar);
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-logo {
    padding: var(--tc-space-5) var(--tc-space-4);
    display: flex;
    align-items: center;
    gap: var(--tc-space-3);
    border-bottom: var(--tc-glass-border-subtle);
    flex-shrink: 0;
}

.logo-icon {
    font-size: 1.5rem;
    color: var(--tc-cta);
    filter: drop-shadow(0 0 8px var(--tc-cta-glow));
}

.logo-text {
    font-size: 1.25rem;
    font-weight: var(--tc-font-weight-bold);
    color: var(--tc-text-primary);
}

.sidebar-body {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.sidebar-nav {
    padding: var(--tc-space-3) var(--tc-space-2);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--tc-space-3);
    padding: var(--tc-space-2) var(--tc-space-3);
    border-radius: var(--tc-radius-md);
    color: var(--tc-text-secondary);
    text-decoration: none;
    transition: all var(--tc-transition-fast);
    margin-bottom: 2px;
    position: relative;
    font-size: var(--tc-font-size-base);
}

.nav-item:hover {
    background: rgba(255,255,255,0.04);
    color: var(--tc-text-primary);
}

.nav-item.active {
    background: rgba(59, 130, 246, 0.12);
    color: var(--tc-primary);
    box-shadow: 0 0 16px rgba(59, 130, 246, 0.1);
    border-radius: var(--tc-radius-md);
}

.nav-item.active::before {
    display: none;
}

.nav-icon {
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    opacity: 0.85;
    flex-shrink: 0;
}

.nav-icon svg {
    width: 18px;
    height: 18px;
}

.nav-item.active .nav-icon {
    opacity: 1;
    filter: drop-shadow(0 0 4px var(--tc-primary-glow));
}

.nav-label {
    font-size: var(--tc-font-size-base);
    font-weight: var(--tc-font-weight-medium);
}

/* Collapsible nav groups */
.nav-group-wrap {
    margin-bottom: 2px;
}
.nav-group-wrap:not(.expanded) .nav-group-items {
    display: none;
}
.nav-group-wrap.expanded .nav-group-chevron {
    transform: rotate(180deg);
}
.nav-group {
    display: flex;
    align-items: center;
    gap: var(--tc-space-3);
    padding: var(--tc-space-2) var(--tc-space-3);
    border-radius: var(--tc-radius-md);
    color: var(--tc-text-secondary);
    cursor: pointer;
    transition: all var(--tc-transition-fast);
    margin-bottom: 2px;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.nav-group:hover {
    background: rgba(255,255,255,0.04);
    color: var(--tc-text-primary);
}
.nav-group:focus {
    outline: none;
}
.nav-group:focus-visible {
    box-shadow: var(--tc-focus-ring);
}
.nav-group-chevron {
    margin-left: auto;
    font-size: 0.65rem;
    opacity: 0.7;
    transition: transform 0.2s ease;
}
.nav-group-items {
    padding-left: var(--tc-space-3);
    margin-left: 20px;
    border-left: var(--tc-glass-border-subtle);
}
.nav-item-child {
    padding: 10px 14px 10px 10px;
    margin-bottom: 2px;
}

.sidebar-section {
    padding: var(--tc-space-4);
    border-top: var(--tc-glass-border-subtle);
}

.sidebar-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--tc-text-muted);
    font-size: var(--tc-font-size-xs);
    font-weight: var(--tc-font-weight-semi);
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

.sidebar-add-btn {
    background: transparent;
    border: var(--tc-glass-border);
    color: var(--tc-text-muted);
    width: 22px;
    height: 22px;
    border-radius: var(--tc-radius-sm);
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--tc-transition-fast);
}

.sidebar-add-btn:hover {
    background: var(--tc-glass-bg);
    color: var(--tc-text-primary);
    border-color: rgba(148, 163, 184, 0.15);
}

.sidebar-footer {
    padding: var(--tc-space-4);
    border-top: var(--tc-glass-border-subtle);
}

.sidebar-footer-links {
    display: flex;
    flex-direction: column;
    gap: var(--tc-space-1);
    margin-bottom: var(--tc-space-3);
    padding-bottom: var(--tc-space-3);
    border-bottom: var(--tc-glass-border-subtle);
}

.footer-link {
    display: flex;
    align-items: center;
    gap: var(--tc-space-2);
    padding: var(--tc-space-2) var(--tc-space-3);
    color: var(--tc-text-secondary);
    text-decoration: none;
    font-size: var(--tc-font-size-sm);
    border-radius: var(--tc-radius-sm);
    transition: all var(--tc-transition-fast);
    background: none;
    border: none;
    cursor: pointer;
    width: 100%;
    text-align: left;
}

.footer-link:hover {
    background: rgba(255,255,255,0.04);
    color: var(--tc-text-primary);
}

.user-info-compact {
    display: flex;
    align-items: center;
    gap: var(--tc-space-3);
}

.user-avatar {
    font-size: 1.2rem;
}

.user-email-short {
    font-size: var(--tc-font-size-sm);
    color: var(--tc-text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Main Content Area */
.main-content {
    flex: 1;
    margin-left: var(--tc-sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding-top: var(--tc-topbar-height);
}

/* Top Bar — Frosted Glass */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--tc-space-3) var(--tc-space-6);
    background: var(--tc-glass-bg-topbar);
    backdrop-filter: blur(var(--tc-glass-blur-heavy));
    -webkit-backdrop-filter: blur(var(--tc-glass-blur-heavy));
    border-bottom: var(--tc-glass-border);
    position: fixed;
    top: 0;
    left: var(--tc-sidebar-width);
    right: 0;
    height: var(--tc-topbar-height);
    box-sizing: border-box;
    z-index: var(--tc-z-topbar);
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: var(--tc-space-4);
}

.page-title-header {
    font-size: var(--tc-font-size-xl);
    font-weight: var(--tc-font-weight-semi);
    color: var(--tc-text-primary);
}

/* Breadcrumb navigation */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: var(--tc-space-2);
    font-size: var(--tc-font-size-xl);
    font-weight: var(--tc-font-weight-semi);
    color: var(--tc-text-primary);
}

.breadcrumb-item {
    display: inline-flex;
    align-items: center;
    font-size: var(--tc-font-size-sm);
    color: var(--tc-text-muted);
    padding: var(--tc-space-1) var(--tc-space-2);
    border-radius: var(--tc-radius-sm);
    transition: all var(--tc-transition-fast);
}

.breadcrumb-item:hover {
    background: var(--tc-glass-bg);
    color: var(--tc-text-primary);
}

.breadcrumb-item:not(:last-child)::after {
    content: "›";
    margin-left: var(--tc-space-2);
    color: var(--tc-text-muted);
    font-weight: var(--tc-font-weight-normal);
}

.breadcrumb-item:last-child {
    color: var(--tc-text-primary);
    font-weight: var(--tc-font-weight-medium);
}

/* Breadcrumb on page content */
.breadcrumb-page {
    display: flex;
    align-items: center;
    gap: var(--tc-space-2);
    font-size: var(--tc-font-size-base);
    font-weight: var(--tc-font-weight-medium);
    color: var(--tc-text-secondary);
    margin-top: var(--tc-space-2);
    margin-bottom: var(--tc-space-5);
}

.breadcrumb-page .breadcrumb-item {
    display: inline-flex;
    align-items: center;
    font-size: var(--tc-font-size-base);
}

.breadcrumb-page .breadcrumb-item:not(:last-child)::after {
    content: "›";
    margin-left: var(--tc-space-2);
    color: var(--tc-text-muted);
    font-weight: var(--tc-font-weight-normal);
}

/* Icon Button — Glass */
.btn-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--tc-glass-bg);
    backdrop-filter: blur(var(--tc-glass-blur-light));
    -webkit-backdrop-filter: blur(var(--tc-glass-blur-light));
    border: var(--tc-glass-border);
    border-radius: var(--tc-radius-md);
    color: var(--tc-text-secondary);
    font-size: 1.1rem;
    cursor: pointer;
    transition: all var(--tc-transition-fast);
}

.btn-icon:hover {
    background: var(--tc-glass-bg-hover);
    color: var(--tc-text-primary);
    box-shadow: var(--tc-shadow-sm);
}

/* Theme toggle button */
.theme-toggle-btn {
    position: relative;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--tc-radius-md);
    color: var(--tc-text-secondary);
    transition: color var(--tc-transition-fast), background var(--tc-transition-fast);
}
.theme-toggle-btn:hover {
    color: var(--tc-text-primary);
}
.theme-icon { display: none; }
[data-theme="dark"] .theme-icon-moon { display: block; }
[data-theme="light"] .theme-icon-sun { display: block; }
:root:not([data-theme]) .theme-icon-moon { display: block; }

.top-bar-right {
    display: flex;
    align-items: center;
    gap: var(--tc-space-3);
}

.user-credits-badge {
    background: var(--tc-primary-surface);
    color: var(--tc-primary);
    padding: var(--tc-space-1) var(--tc-space-3);
    border-radius: var(--tc-radius-pill);
    font-size: var(--tc-font-size-sm);
    font-weight: var(--tc-font-weight-semi);
    font-variant-numeric: tabular-nums;
    border: 1px solid color-mix(in srgb, var(--primary) 20%, transparent);
    box-shadow: 0 0 12px color-mix(in srgb, var(--primary) 10%, transparent);
    transition: all var(--tc-transition-normal);
}

.btn-buy-credits {
    background: var(--tc-cta) !important;
    color: var(--tc-text-inverse) !important;
    font-weight: var(--tc-font-weight-semi);
    box-shadow: var(--tc-glow-cta);
    border-radius: var(--tc-radius-md);
    transition: all var(--tc-transition-normal);
}
.btn-buy-credits:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

/* Header overflow dropdown — Glass */
.header-overflow-wrap {
    position: relative;
}
.header-overflow-btn {
    padding: var(--tc-space-2) var(--tc-space-3);
    font-size: 1.2rem;
    line-height: 1;
    letter-spacing: 0.05em;
}
.header-overflow-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: var(--tc-space-2);
    min-width: 220px;
    background: var(--tc-glass-bg-active);
    backdrop-filter: blur(var(--tc-glass-blur-heavy));
    -webkit-backdrop-filter: blur(var(--tc-glass-blur-heavy));
    border: var(--tc-glass-border-hover);
    border-radius: var(--tc-radius-lg);
    box-shadow: var(--tc-shadow-xl);
    padding: var(--tc-space-1) 0;
    z-index: var(--tc-z-dropdown);
    animation: modalSlideUp 0.15s ease;
}
.header-overflow-wrap.open .header-overflow-dropdown {
    display: block;
}
.header-overflow-item {
    display: flex;
    align-items: center;
    gap: var(--tc-space-3);
    width: 100%;
    padding: var(--tc-space-3) var(--tc-space-4);
    border: none;
    background: none;
    color: var(--tc-text-primary);
    font-size: var(--tc-font-size-base);
    cursor: pointer;
    text-align: left;
    transition: background var(--tc-transition-fast);
    text-decoration: none;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
}
.header-overflow-item:hover {
    background: var(--tc-glass-bg);
}
.header-overflow-icon {
    font-size: 1.1rem;
    width: 24px;
    text-align: center;
    opacity: 0.7;
}
.header-overflow-divider {
    border: none;
    border-top: var(--tc-glass-border-subtle);
    margin: var(--tc-space-1) 0;
}
.header-overflow-admin {
    display: none;
}
.header-overflow-admin.visible {
    display: flex !important;
}

/* Profile avatar dropdown */
.profile-avatar-wrap {
    position: relative;
}
.profile-avatar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 2px solid transparent;
    border-radius: 50%;
    padding: 0;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
    width: 36px;
    height: 36px;
    overflow: hidden;
}
.profile-avatar-btn:hover {
    border-color: var(--tc-glass-border-color, rgba(255,255,255,0.15));
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.3);
}
.profile-avatar-wrap.open .profile-avatar-btn {
    border-color: var(--tc-primary, #8b5cf6);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.4);
}
.profile-avatar-placeholder {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}
.profile-avatar-placeholder .tc-avatar {
    width: 32px !important;
    height: 32px !important;
}
.profile-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 260px;
    background: var(--tc-glass-bg-dense, rgba(15, 15, 30, 0.92));
    backdrop-filter: blur(var(--tc-glass-blur-heavy, 24px)) saturate(140%);
    -webkit-backdrop-filter: blur(var(--tc-glass-blur-heavy, 24px)) saturate(140%);
    border: var(--tc-glass-border-hover, 1px solid rgba(255,255,255,0.12));
    border-radius: var(--tc-radius-lg, 16px);
    box-shadow: 0 12px 48px rgba(0,0,0,0.5);
    padding: 8px 0;
    z-index: 300;
}
.profile-avatar-wrap.open .profile-dropdown {
    display: block;
}
.profile-dropdown-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 16px 12px;
}
.profile-dropdown-avatar {
    flex-shrink: 0;
}
.profile-dropdown-info {
    min-width: 0;
    overflow: hidden;
}
.profile-dropdown-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text, #e2e8f0);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.profile-dropdown-email {
    font-size: 0.8rem;
    color: var(--text-secondary, #94a3b8);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.profile-dropdown-divider {
    border: none;
    border-top: var(--tc-glass-border, 1px solid rgba(255,255,255,0.08));
    margin: 4px 0;
}
.profile-dropdown-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 16px;
    border: none;
    background: none;
    color: var(--text, #e2e8f0);
    font-size: 0.9rem;
    cursor: pointer;
    text-align: left;
    text-decoration: none;
    transition: background 0.2s;
    min-height: 40px;
}
.profile-dropdown-item:hover {
    background: var(--tc-glass-bg-hover, rgba(255,255,255,0.1));
}
.profile-dropdown-icon {
    font-size: 1rem;
    width: 22px;
    text-align: center;
    flex-shrink: 0;
}
.profile-dropdown-admin {
    display: none;
}
.profile-dropdown-logout:hover {
    color: #f87171;
}

/* Creator Area */
.creator-area {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: var(--tc-content-padding-y) var(--tc-content-padding-x);
    max-width: var(--tc-content-max-width);
    margin: 0 auto;
    width: 100%;
}

.page-title {
    font-size: var(--tc-font-size-2xl);
    font-weight: var(--tc-font-weight-semi);
    color: var(--tc-text-primary);
    margin-bottom: var(--tc-space-6);
}

/* Creation Card — Glass */
.creation-card {
    background: var(--tc-glass-bg);
    backdrop-filter: blur(var(--tc-glass-blur)) saturate(140%);
    -webkit-backdrop-filter: blur(var(--tc-glass-blur)) saturate(140%);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--tc-radius-lg);
    padding: var(--tc-space-6);
    margin-bottom: var(--tc-space-8);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.1);
    transition: box-shadow var(--tc-transition-normal);
}

/* Mode Toggle — Glass Pills */
.mode-toggle {
    display: inline-flex;
    align-items: center;
    gap: var(--tc-space-1);
    margin-bottom: var(--tc-space-4);
    background: var(--tc-glass-bg);
    backdrop-filter: blur(var(--tc-glass-blur));
    -webkit-backdrop-filter: blur(var(--tc-glass-blur));
    border: var(--tc-glass-border);
    border-radius: var(--tc-radius-pill);
    padding: 3px;
}

.mode-btn {
    background: transparent;
    border: none;
    border-radius: var(--tc-radius-pill);
    padding: var(--tc-space-2) var(--tc-space-4);
    cursor: pointer;
    transition: all var(--tc-transition-fast);
    color: var(--tc-text-secondary);
    font-size: var(--tc-font-size-sm);
    font-weight: var(--tc-font-weight-medium);
}

.mode-btn:hover {
    color: var(--tc-text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.mode-btn.active {
    background: var(--tc-primary-gradient);
    color: #fff;
    box-shadow: 0 2px 8px var(--tc-primary-glow);
}

.mode-icon {
    font-size: 1.1rem;
}

.mode-tabs {
    display: flex;
    gap: 16px;
    margin-left: 8px;
}

.mode-tab {
    color: var(--tc-text-secondary);
    font-size: var(--tc-font-size-sm);
    cursor: pointer;
    padding: var(--tc-space-2) var(--tc-space-3);
    border: var(--tc-glass-border);
    border-radius: var(--tc-radius-md);
    background: var(--tc-glass-bg);
    transition: all var(--tc-transition-fast);
}

.mode-tab:hover {
    color: var(--tc-text-primary);
    background: var(--tc-glass-bg-hover);
    border-color: rgba(148, 163, 184, 0.15);
}

.mode-tab.active {
    color: var(--tc-primary);
    background: var(--tc-primary-surface);
    border-color: var(--tc-primary);
    box-shadow: 0 0 12px var(--tc-primary-glow);
}

/* Image Upload Inline */
.image-upload-inline {
    margin-bottom: 16px;
}

.upload-dropzone {
    background: var(--tc-glass-bg);
    backdrop-filter: blur(var(--tc-glass-blur-light));
    -webkit-backdrop-filter: blur(var(--tc-glass-blur-light));
    border: 2px dashed rgba(148, 163, 184, 0.15);
    border-radius: var(--tc-radius-lg);
    padding: var(--tc-space-6);
    text-align: center;
    cursor: pointer;
    transition: all var(--tc-transition-normal);
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.upload-dropzone:hover {
    border-color: var(--tc-primary);
    background: var(--tc-primary-surface);
}

.upload-dropzone.dragover {
    border-color: var(--tc-primary);
    background: var(--tc-primary-surface);
    box-shadow: var(--tc-glow-primary);
}

.upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
}

.upload-placeholder[hidden] {
    display: none !important;
}

.image-preview-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.image-preview-container[hidden] {
    display: none !important;
}

.image-preview-container img {
    max-width: 100%;
    max-height: 300px;
    border-radius: 8px;
    object-fit: contain;
}

.upload-icon {
    font-size: 2rem;
    opacity: 0.6;
}

.upload-text {
    font-size: 0.9rem;
}

.image-preview-thumb {
    max-height: 150px;
    max-width: 100%;
    border-radius: 8px;
    object-fit: contain;
}

/* Override for watermark removal preview - needs larger size for mask painting */
#watermarkImagePreview.image-preview-thumb {
    max-height: none;
    max-width: none;
}

/* Prompt Input */
.prompt-input-wrapper {
    position: relative;
    margin-bottom: var(--tc-space-4);
}

.prompt-input {
    width: 100%;
    background: var(--tc-glass-bg-input);
    backdrop-filter: blur(var(--tc-glass-blur));
    -webkit-backdrop-filter: blur(var(--tc-glass-blur));
    border: var(--tc-glass-border);
    border-radius: var(--tc-radius-lg);
    padding: var(--tc-space-4);
    color: var(--tc-text-primary);
    font-family: var(--tc-font-sans);
    font-size: var(--tc-font-size-md);
    line-height: var(--tc-line-height);
    resize: vertical;
    min-height: 80px;
    transition: all var(--tc-transition-fast);
}

.prompt-input:focus {
    outline: none;
    border: var(--tc-glass-border-focus);
    box-shadow: var(--tc-focus-ring);
}

.prompt-input::placeholder {
    color: var(--tc-text-muted);
}

/* Settings Bar */
.settings-bar {
    display: flex;
    align-items: center;
    gap: var(--tc-space-3);
    flex-wrap: wrap;
    padding-top: var(--tc-space-2);
    border-top: var(--tc-glass-border-subtle);
}

.setting-item {
    display: flex;
    align-items: center;
    gap: var(--tc-space-2);
}

.setting-select {
    background: var(--tc-glass-bg-input);
    backdrop-filter: blur(var(--tc-glass-blur-light));
    -webkit-backdrop-filter: blur(var(--tc-glass-blur-light));
    border: var(--tc-glass-border);
    border-radius: var(--tc-radius-md);
    padding: var(--tc-space-2) var(--tc-space-3);
    color: var(--tc-text-primary);
    font-size: var(--tc-font-size-sm);
    cursor: pointer;
    min-width: 140px;
    transition: border var(--tc-transition-fast);
}

.setting-select:focus {
    outline: none;
    border: var(--tc-glass-border-focus);
    box-shadow: var(--tc-focus-ring);
}

.setting-select-small {
    background: var(--tc-glass-bg-input);
    backdrop-filter: blur(var(--tc-glass-blur-light));
    -webkit-backdrop-filter: blur(var(--tc-glass-blur-light));
    border: var(--tc-glass-border);
    border-radius: var(--tc-radius-md);
    padding: var(--tc-space-2) var(--tc-space-3);
    color: var(--tc-text-primary);
    font-size: var(--tc-font-size-sm);
    cursor: pointer;
    min-width: 80px;
    transition: border var(--tc-transition-fast);
}

.setting-select-small:focus {
    outline: none;
    border: var(--tc-glass-border-focus);
    box-shadow: var(--tc-focus-ring);
}

.setting-icon {
    color: var(--tc-text-muted);
    font-size: var(--tc-font-size-base);
}

.setting-label {
    color: var(--tc-text-secondary);
    font-size: var(--tc-font-size-sm);
}

.setting-toggle {
    display: flex;
    align-items: center;
    gap: var(--tc-space-2);
}

/* Toggle Switch — Glass */
.toggle-switch {
    position: relative;
    width: 40px;
    height: 22px;
    display: inline-block;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--tc-glass-bg-input);
    border: var(--tc-glass-border);
    border-radius: var(--tc-radius-pill);
    transition: all var(--tc-transition-fast);
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 2px;
    background: var(--tc-text-muted);
    border-radius: 50%;
    transition: all var(--tc-transition-fast);
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--tc-primary);
    border-color: var(--tc-primary);
    box-shadow: 0 0 12px var(--tc-primary-glow);
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(18px);
    background: #fff;
}

.settings-spacer {
    flex: 1;
}

/* Credit Estimate Inline */
.credit-estimate-inline {
    display: flex;
    align-items: baseline;
    gap: var(--tc-space-1);
    padding: var(--tc-space-2) var(--tc-space-4);
    background: var(--tc-primary-surface);
    border-radius: var(--tc-radius-md);
    border: 1px solid rgba(168, 85, 247, 0.1);
}

.credit-amount {
    font-size: var(--tc-font-size-lg);
    font-weight: var(--tc-font-weight-bold);
    color: var(--tc-primary);
    text-shadow: 0 0 20px var(--tc-primary-glow);
}

.credit-label {
    font-size: var(--tc-font-size-sm);
    color: var(--tc-text-muted);
}

/* Memory Status Indicator (near Generate button) — hidden: queue-based flow, users do not see memory stats */
#memoryStatusBar,
.memory-status-bar {
    display: none !important;
}
.memory-status-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    margin-bottom: 8px;
    border-radius: 6px;
    background: rgba(255,255,255,0.04);
    font-size: 0.8rem;
    color: var(--text-muted);
    transition: all 0.3s;
}
.memory-status-bar.status-ok { border-left: 3px solid var(--success); }
.memory-status-bar.status-warning { border-left: 3px solid var(--warning); background: rgba(245,158,11,0.08); }
.memory-status-bar.status-critical { border-left: 3px solid var(--error); background: rgba(239,68,68,0.08); }
.memory-status-bar.status-emergency { border-left: 3px solid #dc2626; background: rgba(220,38,38,0.12); animation: memory-pulse 1s infinite; }
.memory-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
}
.memory-status-bar.status-ok .memory-dot { background: var(--success); }
.memory-status-bar.status-warning .memory-dot { background: var(--warning); }
.memory-status-bar.status-critical .memory-dot { background: var(--error); }
.memory-status-bar.status-emergency .memory-dot { background: #dc2626; }
@keyframes memory-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* Generate Button — Gold CTA */
.btn-generate {
    background: var(--tc-cta);
    border: none;
    border-radius: var(--tc-radius-md);
    padding: var(--tc-space-3) var(--tc-space-6);
    color: var(--tc-text-inverse);
    font-size: var(--tc-font-size-base);
    font-weight: var(--tc-font-weight-semi);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: var(--tc-space-2);
    box-shadow: var(--tc-glow-cta);
    transition: all var(--tc-transition-normal);
}

.btn-generate:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
    box-shadow: 0 0 32px rgba(234, 179, 8, 0.3), 0 4px 20px rgba(234, 179, 8, 0.2);
}

.btn-generate:active {
    filter: brightness(0.95);
    transform: translateY(0);
}

.btn-generate:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
    filter: none;
}

/* Unified hover lift for secondary action buttons */
.btn-generate-avatar:hover,
.btn-generate-narrate:hover,
.auth-submit-btn:hover {
    transform: translateY(-2px);
    filter: brightness(1.1);
}

/* Focus-visible rings for keyboard accessibility */
.btn-generate:focus-visible,
.btn-generate-avatar:focus-visible,
.btn-generate-narrate:focus-visible,
.auth-submit-btn:focus-visible,
.nav-item:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.btn-icon {
    font-size: 1.1rem;
}

/* Progress Card — Glass */
.progress-card {
    background: var(--tc-glass-bg);
    backdrop-filter: blur(var(--tc-glass-blur));
    -webkit-backdrop-filter: blur(var(--tc-glass-blur));
    border: var(--tc-glass-border);
    border-radius: var(--tc-radius-lg);
    padding: var(--tc-space-6);
    margin-bottom: var(--tc-space-8);
    box-shadow: var(--tc-shadow-md);
}

.progress-card.active {
    border: 1px solid rgba(168, 85, 247, 0.2);
    box-shadow: var(--tc-glow-primary);
    animation: glassBreath 3s ease-in-out infinite;
}

.progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--tc-space-4);
}

.progress-header h3 {
    font-size: var(--tc-font-size-lg);
    font-weight: var(--tc-font-weight-semi);
    color: var(--tc-text-primary);
}

.progress-content {
    margin-bottom: 16px;
}

.progress-bar-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.progress-bar {
    flex: 1;
    height: 8px;
    background: var(--tc-glass-bg-input);
    border-radius: var(--tc-radius-pill);
    overflow: hidden;
    position: relative;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--tc-primary), var(--tc-secondary));
    border-radius: var(--tc-radius-pill);
    transition: width 0.3s ease;
    width: 0%;
    position: relative;
}

.progress-fill.active::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.2) 50%, transparent 100%);
    animation: progressShimmer 2s ease-in-out infinite;
}

.progress-percent {
    font-size: var(--tc-font-size-base);
    font-weight: var(--tc-font-weight-semi);
    color: var(--tc-primary);
    min-width: 45px;
    font-family: var(--tc-font-mono);
}

.progress-status {
    color: var(--tc-text-secondary);
    font-size: var(--tc-font-size-base);
    margin-bottom: var(--tc-space-1);
}

.progress-segment {
    color: var(--tc-text-muted);
    font-size: var(--tc-font-size-sm);
}

/* Video creation progress: Elapsed, Remaining, Est. Finish, Credits */
.progress-time-info {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem 1.5rem;
    margin-top: 12px;
    align-items: flex-start;
}

.progress-time-info > div {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
}

.progress-time-info > div > div:first-child {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.progress-time-info > div > div:last-child {
    font-size: 1rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* ETA and Credit Estimation Display */
.estimation-display {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px 16px;
    margin-top: 12px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    font-size: 0.85rem;
}

.estimation-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.estimation-label {
    color: var(--text-muted);
}

.estimation-value {
    color: var(--text-primary);
    font-weight: 500;
    font-family: monospace;
}

.estimation-row.credits-row .estimation-value {
    color: var(--accent);
    font-weight: 600;
}

/* Result Card — Glass */
.result-card {
    background: var(--tc-glass-bg);
    backdrop-filter: blur(var(--tc-glass-blur));
    -webkit-backdrop-filter: blur(var(--tc-glass-blur));
    border: var(--tc-glass-border);
    border-radius: var(--tc-radius-lg);
    padding: var(--tc-space-6);
    margin-bottom: var(--tc-space-8);
    box-shadow: var(--tc-shadow-lg);
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--tc-space-4);
}

.result-header h3 {
    font-size: var(--tc-font-size-lg);
    font-weight: var(--tc-font-weight-semi);
    color: var(--tc-success);
}

.result-actions {
    display: flex;
    gap: var(--tc-space-2);
    align-items: center;
}

.result-actions .btn-close {
    background: transparent;
    border: none;
    color: var(--tc-text-muted);
    font-size: 1.2rem;
    padding: var(--tc-space-1) var(--tc-space-2);
    cursor: pointer;
    opacity: 0.7;
    transition: all var(--tc-transition-fast);
}

.result-actions .btn-close:hover {
    opacity: 1;
    color: var(--tc-text-primary);
}

.result-video-wrapper {
    border-radius: var(--tc-radius-md);
    overflow: hidden;
    background: #000;
    margin-bottom: var(--tc-space-3);
    display: flex;
    flex-direction: row;
    align-items: stretch;
    box-shadow: var(--tc-shadow-md);
}

.result-video {
    flex: 1 1 auto;
    width: 0;
    min-width: 0;
    max-height: 420px;
    display: block;
    object-fit: contain;
}

.result-ref-image-panel {
    flex: 0 0 38%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #0a0a0a;
    border-left: 1px solid rgba(255,255,255,0.08);
    position: relative;
    overflow: hidden;
}

.result-ref-image-panel[hidden] {
    display: none !important;
}

/* When ref panel is hidden (e.g. text-to-video), video fills the wrapper — no empty black area */
.result-video-wrapper:has(.result-ref-image-panel[hidden]) .result-video,
.result-video-wrapper:not(:has(.result-ref-image-panel:not([hidden]))) .result-video {
    width: 100%;
    max-width: 100%;
}

.result-ref-label {
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255,255,255,0.45);
    pointer-events: none;
    z-index: 1;
}

.result-ref-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.result-meta {
    display: flex;
    gap: 16px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Result Prompt Display */
.result-prompt {
    margin-top: 16px;
    padding: 12px 16px;
    background: var(--bg-darker);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.result-prompt-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.result-prompt-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

.result-prompt-text {
    margin: 0;
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-word;
}

.result-prompt .btn-icon {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 1rem;
}

.result-prompt .btn-icon:hover {
    background: var(--bg-lighter);
}

/* Result Image - Thumbnail style */
.result-image {
    max-width: 300px;
    max-height: 300px;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 2px solid transparent;
}

.result-image:hover {
    transform: scale(1.02);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    border-color: var(--primary);
}

.result-content {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
}

.result-content .click-hint {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.75rem;
    color: var(--text-muted);
    opacity: 0;
    transition: opacity 0.2s;
}

.result-content:hover .click-hint {
    opacity: 1;
}

.btn-download {
    background: var(--success) !important;
    color: white !important;
}

/* Gallery Section */
.gallery-section {
    margin-top: 32px;
}

.gallery-tabs {
    display: flex;
    gap: 24px;
    margin-bottom: 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding-bottom: 12px;
}

.gallery-tab {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    padding: 8px 0;
    position: relative;
    transition: color 0.2s;
}

.gallery-tab:hover {
    color: var(--text);
}

.gallery-tab.active {
    color: var(--text);
}

.gallery-tab.active::after {
    content: '';
    position: absolute;
    bottom: -13px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--primary);
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.gallery-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 48px;
    color: var(--text-muted);
}

.gallery-item {
    position: relative;
    border-radius: var(--tc-radius-lg);
    overflow: hidden;
    aspect-ratio: 16/9;
    background: var(--tc-glass-bg);
    backdrop-filter: blur(var(--tc-glass-blur-light));
    -webkit-backdrop-filter: blur(var(--tc-glass-blur-light));
    border: var(--tc-glass-border);
    cursor: pointer;
    transition: all var(--tc-transition-normal);
}

.gallery-item:hover {
    transform: scale(1.02);
    box-shadow: var(--tc-shadow-lg);
    border: var(--tc-glass-border-hover);
}

.gallery-item img,
.gallery-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gallery-badge {
    position: absolute;
    top: var(--tc-space-2);
    left: var(--tc-space-2);
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Admin Drawer */
.admin-drawer {
    background: var(--bg-card);
    padding: 12px 24px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.admin-drawer-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        width: 60px;
    }

    .sidebar .nav-label,
    .sidebar .logo-text,
    .sidebar-section-header span,
    .sidebar-add-btn,
    .user-email-short {
        display: none;
    }

    .sidebar-logo {
        justify-content: center;
        padding: 16px 8px;
    }

    .nav-item {
        justify-content: center;
        padding: 12px;
    }

    .main-content {
        margin-left: 60px;
    }

    .creator-area {
        padding: 20px 16px;
    }

    .settings-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .settings-spacer {
        display: none;
    }

    .btn-generate {
        width: 100%;
        justify-content: center;
    }
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--tc-font-sans);
    background: var(--tc-bg-base);
    background-image: var(--tc-bg-gradient);
    background-attachment: fixed;
    color: var(--tc-text-primary);
    min-height: 100vh;
    min-height: -webkit-fill-available;
    line-height: var(--tc-line-height);
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse 60% 50% at 20% 20%, rgba(59, 130, 246, 0.06) 0%, transparent 70%),
        radial-gradient(ellipse 50% 60% at 80% 80%, rgba(139, 92, 246, 0.05) 0%, transparent 70%),
        radial-gradient(ellipse 40% 40% at 50% 50%, rgba(59, 130, 246, 0.03) 0%, transparent 60%);
    pointer-events: none;
    z-index: 0;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    padding: 24px 0;
}

header h1 {
    font-size: 2.2rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 6px;
}

.subtitle {
    color: var(--text-muted);
    font-size: 1rem;
}

/* ComfyUI Status */
.comfyui-status {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
    padding: 8px 14px;
    background: var(--bg-card);
    border-radius: 20px;
    font-size: 0.85rem;
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
}

.status-indicator.online {
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
}

.status-indicator.offline {
    background: var(--error);
}

.status-indicator.starting {
    background: var(--warning);
    animation: pulse 1s infinite;
}

.btn-small {
    padding: 8px 14px;
    font-size: 0.8rem;
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    touch-action: manipulation;
}

.btn-small:hover,
.btn-small:active {
    background: var(--border);
}

.btn-small:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-small.btn-stop {
    background: var(--error);
    border-color: var(--error);
}

.btn-small.btn-stop:hover {
    background: #dc2626;
    border-color: #dc2626;
}

.btn-small.btn-start {
    background: var(--success);
    border-color: var(--success);
}

.btn-small.btn-start:hover {
    background: #059669;
    border-color: #059669;
}

.btn-small.btn-restart-app {
    background: #a855f7;
    border-color: #a855f7;
    margin-left: 8px;
}

.btn-small.btn-restart-app:hover {
    background: #9333ea;
    border-color: #9333ea;
}

.btn-small.btn-screenshot {
    background: rgba(168, 85, 247, 0.2);
    border-color: rgba(168, 85, 247, 0.4);
    padding: 8px 10px;
}

.btn-small.btn-screenshot:hover {
    background: rgba(168, 85, 247, 0.4);
    border-color: rgba(168, 85, 247, 0.6);
}

.btn-small.btn-admin {
    background: #f59e0b;
    border-color: #f59e0b;
    color: #000;
    font-weight: 600;
    text-decoration: none;
}

.btn-small.btn-admin:hover {
    background: #d97706;
    border-color: #d97706;
}

/* Admin System Toggle Button */
.btn-small.btn-system-toggle {
    background: rgba(100, 116, 139, 0.2);
    border-color: rgba(100, 116, 139, 0.4);
    color: #94a3b8;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    padding: 4px 10px;
}

.btn-small.btn-system-toggle:hover {
    background: rgba(100, 116, 139, 0.3);
    border-color: rgba(100, 116, 139, 0.5);
    color: #cbd5e1;
}

.btn-small.btn-system-toggle.active {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.4);
    color: #ef4444;
}

.btn-small.btn-system-toggle .toggle-icon {
    font-size: 0.9rem;
}

.btn-small.btn-system-toggle .toggle-text {
    font-weight: 500;
}

/* Voice select row with preview button */
.voice-select-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.voice-select-row select {
    flex: 1;
}

.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-icon:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.btn-icon:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-preview-voice .preview-icon {
    font-size: 12px;
}

.btn-preview-voice.playing {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.btn-preview-voice.playing .preview-icon::before {
    content: "■";
}

/* Label row with clear button */
.label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.label-row label {
    margin-bottom: 0;
}

.btn-clear {
    width: 24px;
    height: 24px;
    font-size: 12px;
    padding: 0;
    color: var(--text-muted);
    background: transparent;
    border: 1px solid transparent;
}

.btn-clear:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.3);
}

.btn-clear-all {
    width: 36px;
    height: 36px;
    font-size: 16px;
    padding: 0;
    color: var(--text-muted);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-clear-all:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.3);
    transform: scale(1.05);
}

/* Dashboard */
.dashboard-section {
    margin-bottom: 12px;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.dashboard-card {
    background: var(--tc-glass-bg);
    backdrop-filter: blur(var(--tc-glass-blur)) saturate(140%);
    -webkit-backdrop-filter: blur(var(--tc-glass-blur)) saturate(140%);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--tc-radius-lg);
    padding: var(--tc-space-2);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.dashboard-card h3 {
    color: var(--text);
    font-size: 0.75rem;
    font-weight: 500;
    margin-bottom: 4px;
    text-align: center;
}

.gauge-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.gauge {
    width: 70px;
    height: 44px;
}

.gauge-value {
    position: absolute;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    white-space: nowrap;
}

.gauge-number {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text);
}

.gauge-unit {
    font-size: 0.5rem;
    color: var(--text-muted);
    margin-left: 1px;
}

.gauge-label {
    margin-top: 1px;
    font-size: 0.55rem;
    color: var(--text-muted);
    text-align: center;
}

.chart-card {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.chart-header {
    font-size: 0.6rem;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.chart-card canvas {
    width: 100% !important;
    height: 35px !important;
    background: rgba(0, 100, 200, 0.1);
    border-radius: 4px;
}

/* Tab Navigation - Grouped by Category */
.tab-nav-grouped {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 12px;
}

/* Tab Section */
.tab-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.tab-section-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
}

.section-icon {
    font-size: 1.2rem;
    line-height: 1;
}

.section-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tab-section-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* Tab Nav — Glass */
.tab-nav {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--tc-space-1);
    background: var(--tc-glass-bg);
    backdrop-filter: blur(var(--tc-glass-blur-light));
    -webkit-backdrop-filter: blur(var(--tc-glass-blur-light));
    padding: 3px;
    border-radius: var(--tc-radius-pill);
    margin-bottom: var(--tc-space-5);
    border: var(--tc-glass-border);
    overflow: visible;
    position: relative;
}

.tab-nav::-webkit-scrollbar {
    display: none;
    height: 0;
}


.tab-btn {
    flex: none;
    min-width: 0;
    padding: var(--tc-space-2) var(--tc-space-3);
    background: transparent;
    border: none;
    border-radius: var(--tc-radius-pill);
    color: var(--tc-text-secondary);
    font-size: var(--tc-font-size-sm);
    font-weight: var(--tc-font-weight-medium);
    cursor: pointer;
    transition: all var(--tc-transition-fast);
    white-space: nowrap;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    text-align: left;
}

/* Grouped tabs show full text */
.tab-nav-grouped .tab-btn {
    width: 100%;
    text-align: center;
}

/* Gallery Button - Full Width Below Menu */
.gallery-button-container {
    margin-bottom: 20px;
}

.gallery-tab-btn {
    width: 100%;
    background: var(--tc-glass-bg);
    backdrop-filter: blur(var(--tc-glass-blur-light));
    -webkit-backdrop-filter: blur(var(--tc-glass-blur-light));
    border: var(--tc-glass-border);
    padding: var(--tc-space-3) var(--tc-space-5);
    font-size: var(--tc-font-size-md);
    font-weight: var(--tc-font-weight-semi);
    border-radius: var(--tc-radius-lg);
    color: var(--tc-text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--tc-space-2);
    transition: all 0.2s;
}

.gallery-tab-btn:hover {
    background: var(--bg-input);
    border-color: var(--primary);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.gallery-tab-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 4px 16px rgba(168, 85, 247, 0.4);
}

/* Mobile responsive for grouped navigation */
@media (max-width: 768px) {
    .tab-nav-grouped {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    
    .section-title {
        font-size: 0.75rem;
    }
    
    .tab-btn {
        font-size: 0.8rem;
        padding: 8px 10px;
    }
    
    .gallery-tab-btn {
        padding: 12px 16px;
        font-size: 0.95rem;
    }
}

@media (max-width: 480px) {
    .tab-nav-grouped {
        grid-template-columns: 1fr;
    }
    
    .tab-section-content {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 4px;
    }
}

/* Legacy grid nav uses shortened labels via ::after */
.tab-nav .tab-btn {
    font-size: 0;
}

.tab-nav .tab-btn::after {
    font-size: 0.8rem;
    display: inline-block;
}

.tab-nav .tab-btn[data-tab="create-video"]::after { content: "Create"; }
.tab-nav .tab-btn[data-tab="talking-avatar"]::after { content: "Avatar"; }
.tab-nav .tab-btn[data-tab="edit-image"]::after { content: "Edit"; }
.tab-nav .tab-btn[data-tab="merge-videos"]::after { content: "Merge"; }
.tab-nav .tab-btn[data-tab="gallery"]::after { content: "Gallery"; }
.tab-nav .tab-btn[data-tab="enhance-photo"]::after { content: "Enhance"; }
.tab-nav .tab-btn[data-tab="narrate"]::after { content: "Narrate"; }
.tab-nav .tab-btn[data-tab="prompt-engineer"]::after { content: "Prompt"; }

.tab-btn:hover {
    color: var(--tc-text-primary);
    background: rgba(255, 255, 255, 0.04);
}

.tab-btn.active {
    background: var(--tc-primary-gradient);
    color: #fff;
    box-shadow: 0 2px 8px var(--tc-primary-glow);
}

/* Tab Content */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Live Log Section */
.log-section {
    margin-bottom: 16px;
}

.log-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
}

.log-header:hover {
    background: var(--bg-input);
}

.log-header.expanded {
    border-radius: 10px 10px 0 0;
    border-bottom: none;
}

.log-icon {
    font-size: 1.1rem;
}

.log-title {
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text);
}

.log-badge {
    background: var(--primary);
    color: white;
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

.log-toggle {
    margin-left: auto;
    color: var(--text-muted);
    font-size: 0.8rem;
    transition: transform 0.2s;
}

.log-header.expanded .log-toggle {
    transform: rotate(180deg);
}

.log-content {
    background: #0d1117;
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 10px 10px;
    overflow: hidden;
}

.log-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid var(--border);
}

.log-autoscroll {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--text-muted);
    cursor: pointer;
}

.log-autoscroll input {
    width: 14px;
    height: 14px;
    cursor: pointer;
}

.log-output {
    margin: 0;
    padding: 12px;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', monospace;
    font-size: 0.75rem;
    line-height: 1.5;
    color: #c9d1d9;
    background: transparent;
    max-height: 200px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

.log-output::-webkit-scrollbar {
    width: 8px;
}

.log-output::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

.log-output::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.log-output .log-time {
    color: #6e7681;
}

.log-output .log-info {
    color: #58a6ff;
}

.log-output .log-success {
    color: #3fb950;
}

.log-output .log-warning {
    color: #d29922;
}

.log-output .log-error {
    color: #f85149;
}

.log-output .log-progress {
    color: #a371f7;
}

.card {
    background: var(--tc-glass-bg);
    backdrop-filter: blur(var(--tc-glass-blur)) saturate(140%);
    -webkit-backdrop-filter: blur(var(--tc-glass-blur)) saturate(140%);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--tc-radius-lg);
    padding: var(--tc-space-5);
    margin-bottom: var(--tc-space-5);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.card h2 {
    margin-bottom: 16px;
    font-size: 1.2rem;
    color: var(--text);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.card-header h2 {
    margin-bottom: 0;
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0 8px;
    line-height: 1;
    transition: color 0.2s;
}

.close-btn:hover {
    color: var(--text);
}

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

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 0.95rem;
    color: var(--text);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 16px;
}

/* Two-column equal layout when form-row has form-groups */
.form-row > .form-group {
    margin-bottom: 0;
}

.form-row:has(.form-group + .form-group) {
    grid-template-columns: 1fr 1fr;
}

/* Input row with button */
.input-row {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.input-row input {
    flex: 1;
}

.input-row .btn {
    white-space: nowrap;
}

/* Field hints */
.field-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 6px;
    margin-bottom: 12px;
}

.field-hint.success {
    color: #10b981;
}

input[type="text"],
input[type="number"],
textarea {
    width: 100%;
    padding: 14px 16px;
    background: var(--tc-glass-bg-input);
    backdrop-filter: blur(var(--tc-glass-blur-light));
    -webkit-backdrop-filter: blur(var(--tc-glass-blur-light));
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: var(--tc-radius-md);
    color: var(--text);
    font-size: 16px; /* Prevents iOS zoom on focus */
    transition: border-color 0.2s, box-shadow 0.2s;
    -webkit-appearance: none;
    appearance: none;
}

input:focus,
textarea:focus {
    outline: none;
    border-color: rgba(59, 130, 246, 0.4);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.4), 0 0 16px rgba(59, 130, 246, 0.15);
}

textarea {
    resize: vertical;
    min-height: 100px;
}

.hint {
    display: block;
    margin-top: 6px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.text-to-video-info {
    display: block;
    padding: 8px 12px;
    margin-top: 8px;
    background: rgba(168, 85, 247, 0.1);
    border: 1px solid rgba(168, 85, 247, 0.3);
    border-radius: 6px;
    color: #a5b4fc;
    font-size: 0.85rem;
}

/* T2V Audio Options */
.t2v-audio-options {
    margin-top: 12px;
    padding: 10px 12px;
    background: rgba(30, 30, 50, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
}
.t2v-audio-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 5px 0;
}
.t2v-audio-row + .t2v-audio-row {
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    margin-top: 4px;
    padding-top: 8px;
}
.t2v-audio-row .checkbox-label {
    font-size: 0.85rem;
    min-width: 140px;
}
.t2v-select, .t2v-voice-row select {
    padding: 4px 8px;
    font-size: 0.82rem;
    background: rgba(20, 20, 40, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 5px;
    color: #e2e8f0;
}
.t2v-voice-row {
    display: flex;
    gap: 8px;
    margin-top: 6px;
}
#t2vNarrationOptions {
    width: 100%;
    margin-top: 6px;
}
#t2vNarrationText {
    font-size: 0.85rem;
}

/* Prompt input with optimize button */
.prompt-input-wrapper {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.prompt-input-wrapper textarea {
    flex: 1;
    padding-right: 50px;
}

.btn-optimize {
    position: absolute;
    right: 8px;
    top: 8px;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, #8b5cf6, #a855f7);
    color: white;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn-optimize:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);
}

.btn-optimize:active {
    transform: scale(0.95);
}

.btn-optimize:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-optimize .optimize-icon {
    line-height: 1;
}

.btn-optimize .optimize-loading {
    font-size: 14px;
    animation: pulse 0.5s infinite;
}

/* Upload Area */
.upload-area {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 32px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    overflow: hidden;
    touch-action: manipulation;
}

.upload-area:hover,
.upload-area:active {
    border-color: var(--primary);
    background: rgba(168, 85, 247, 0.1);
}

.upload-area.dragover {
    border-color: var(--primary);
    background: rgba(168, 85, 247, 0.2);
}

.clipboard-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    cursor: pointer;
    transition: all 0.2s;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.clipboard-btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(168, 85, 247, 0.3);
}

.clipboard-btn:active {
    transform: translateY(0);
}

.clipboard-icon {
    font-size: 1.2rem;
    display: block;
}

.upload-placeholder {
    color: var(--text-muted);
}

.upload-icon {
    font-size: 2.5rem;
    display: block;
    margin-bottom: 10px;
}

.image-preview {
    max-width: 100%;
    max-height: 250px;
    border-radius: 8px;
}

/* Mode Toggle */
.mode-toggle {
    display: flex;
    gap: 0;
    background: var(--bg-input);
    border-radius: 8px;
    padding: 4px;
    width: fit-content;
}

.mode-btn {
    padding: 10px 20px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.mode-btn:hover {
    color: var(--text);
}

.mode-btn.active {
    background: var(--primary);
    color: white;
}

/* Multi-Image Upload */
.multi-image-upload-area {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 24px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 16px;
}

.multi-image-upload-area:hover {
    border-color: var(--primary);
    background: rgba(168, 85, 247, 0.1);
}

.multi-image-upload-area.dragover {
    border-color: var(--primary);
    background: rgba(168, 85, 247, 0.2);
}

.multi-upload-placeholder {
    color: var(--text-muted);
}

.multi-image-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    margin-bottom: 12px;
}

.multi-image-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-input);
}

.multi-image-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.multi-image-item .image-number {
    position: absolute;
    top: 4px;
    left: 4px;
    background: var(--primary);
    color: white;
    font-size: 0.7rem;
    font-weight: bold;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.multi-image-item .remove-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(239, 68, 68, 0.9);
    color: white;
    border: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
}

.multi-image-item:hover .remove-btn {
    opacity: 1;
}

.multi-image-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Audio Options */
.audio-options {
    background: var(--bg-input);
    padding: 16px;
    border-radius: 8px;
    margin-top: 8px;
}

/* Video Model Selection */
.model-info {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
    padding: 10px;
    background: var(--bg-input);
    border-radius: 6px;
    font-size: 0.85rem;
}

.model-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.model-badge.local,
.model-badge.included {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
    border: 1px solid rgba(34, 197, 94, 0.3);
}

.model-badge.cloud,
.model-badge.premium {
    background: rgba(245, 158, 11, 0.2);
    color: #f59e0b;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.model-specs {
    color: var(--text-muted);
    font-size: 0.8rem;
}

#videoModel optgroup {
    font-weight: 600;
    color: var(--primary);
}

#videoModel option {
    padding: 8px;
}

.audio-section-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
    margin: 0 0 12px 0;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.audio-option-row {
    margin-bottom: 12px;
}

.audio-option-row:last-child {
    margin-bottom: 0;
}

.music-option {
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.music-option label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.music-option select {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.9rem;
    cursor: pointer;
    transition: border-color 0.2s;
}

.music-option select:focus {
    outline: none;
    border-color: var(--primary);
}

.music-note {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 6px;
    margin-bottom: 0;
    font-style: italic;
}

.lip-sync-option {
    padding: 12px;
    background: rgba(168, 85, 247, 0.1);
    border-radius: 6px;
    border: 1px solid rgba(168, 85, 247, 0.2);
}

.lip-sync-note {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: 6px 0 0 30px;
    font-style: italic;
}

.lip-sync-method-wrapper {
    margin-top: 10px;
    margin-left: 30px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.lip-sync-method-wrapper label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.lip-sync-method-wrapper select {
    flex: 1;
    max-width: 300px;
}

/* Talking Avatar Section */
.avatar-section {
    max-width: 800px;
    margin: 0 auto;
}

.avatar-voice-settings h4,
.avatar-lipsync-settings h4 {
    margin: 0 0 12px 0;
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.voice-options-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
}

.voice-option {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.voice-option label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.voice-option-wide {
    grid-column: span 2;
}

.avatar-lipsync-settings {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.avatar-lipsync-settings select {
    max-width: 400px;
}

.lip-sync-method-note {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 8px;
    font-style: italic;
}

.avatar-progress {
    margin-top: 20px;
}

.avatar-status {
    display: block;
    text-align: center;
    margin-top: 10px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.avatar-result {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

.avatar-result h3 {
    margin: 0 0 16px 0;
    text-align: center;
}

.avatar-result-actions {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 16px;
}

/* Character Dialogue Section */
.dialogue-section {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    margin-top: 16px;
}

.dialogue-section label {
    color: var(--accent);
    font-weight: 600;
}

.dialogue-section textarea {
    margin-top: 8px;
    margin-bottom: 4px;
}

.dialogue-options {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.dialogue-voice-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.dialogue-voice-row .voice-option {
    flex: 1;
    min-width: 120px;
}

.dialogue-voice-row label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
    display: block;
}

.dialogue-voice-row select {
    width: 100%;
}

/* Image analysis status indicator */
.analysis-status {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(168, 85, 247, 0.9);
    color: white;
    padding: 6px 14px;
    border-radius: 16px;
    font-size: 0.85rem;
    animation: pulse 1.5s ease-in-out infinite;
    z-index: 10;
}

.analysis-status.success {
    background: rgba(34, 197, 94, 0.9);
    animation: none;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

@media (max-width: 600px) {
    .voice-options-grid {
        grid-template-columns: 1fr 1fr;
    }

    .voice-option-wide {
        grid-column: span 2;
    }
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
}

.checkbox-label input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--primary);
    cursor: pointer;
}

.checkbox-text {
    font-size: 0.95rem;
    color: var(--text);
}

.voice-select-wrapper {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.voice-select-wrapper label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.voice-select-wrapper select {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.9rem;
    cursor: pointer;
}

.voice-select-wrapper select:focus {
    outline: none;
    border-color: var(--primary);
}

/* Buttons — Glassmorphic (Auth page variants) */
.btn-primary,
.btn-secondary {
    display: inline-block;
    padding: var(--tc-space-3) var(--tc-space-6);
    font-size: var(--tc-font-size-md);
    font-weight: var(--tc-font-weight-semi);
    border: none;
    border-radius: var(--tc-radius-md);
    cursor: pointer;
    transition: all var(--tc-transition-normal);
    text-decoration: none;
    text-align: center;
    touch-action: manipulation;
    -webkit-appearance: none;
    appearance: none;
}

.btn-primary {
    width: 100%;
    background: var(--tc-primary-gradient);
    color: #fff;
    min-height: 52px;
    box-shadow: 0 4px 16px var(--tc-primary-glow);
}

.btn-primary:hover:not(:disabled),
.btn-primary:active:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 24px var(--tc-primary-glow-strong);
}

.btn-primary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none;
}

.btn-secondary {
    background: var(--tc-glass-bg-input);
    color: var(--tc-text-primary);
    border: var(--tc-glass-border);
    min-height: 48px;
}

.btn-secondary:hover,
.btn-secondary:active {
    background: var(--tc-glass-bg-hover);
    border-color: rgba(148, 163, 184, 0.2);
}

.btn-danger {
    display: inline-block;
    padding: var(--tc-space-3) var(--tc-space-6);
    font-size: var(--tc-font-size-md);
    font-weight: var(--tc-font-weight-semi);
    border: none;
    border-radius: var(--tc-radius-md);
    cursor: pointer;
    transition: all var(--tc-transition-normal);
    background: var(--tc-error);
    color: #fff;
    min-height: 48px;
    box-shadow: 0 4px 12px var(--tc-error-glow);
}

.btn-danger:hover,
.btn-danger:active {
    background: #dc2626;
    box-shadow: 0 6px 20px rgba(239, 68, 68, 0.4);
}

.btn-danger:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.stop-generation {
    margin-top: 20px;
    text-align: center;
}

.btn-loading {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-loading[hidden],
.btn-text[hidden] {
    display: none !important;
}

/* Progress Section */
.status-message {
    padding: 14px;
    background: var(--bg-input);
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.95rem;
    word-break: break-word;
}

.progress-container {
    margin-bottom: 16px;
}

.progress-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.progress-bar {
    height: 10px;
    background: var(--bg-input);
    border-radius: 5px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    border-radius: 5px;
    transition: width 0.3s ease;
    width: 0%;
}

/* Completed Scenes Thumbnails (shown during generation) */
.completed-scenes-section {
    margin-bottom: 20px;
}

.completed-scenes-section .card {
    padding: 16px;
}

.completed-scenes-section h3 {
    font-size: 1rem;
    margin: 0 0 8px 0;
    color: var(--secondary);
}

.completed-scenes-section .hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin: 0 0 16px 0;
}

.completed-scenes {
    margin: 16px 0;
    padding: 16px;
    background: var(--bg-input);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.completed-scenes h3 {
    font-size: 0.95rem;
    margin: 0 0 12px 0;
    color: var(--secondary);
}

.completed-scenes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
}

.completed-scene-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    animation: fadeSlideIn 0.4s ease;
}

@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.completed-scene-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    background: rgba(16, 185, 129, 0.15);
    border-bottom: 1px solid var(--border);
}

.scene-number {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text);
}

.scene-status {
    color: var(--secondary);
    font-size: 0.9rem;
}

.completed-scene-video {
    position: relative;
    cursor: pointer;
    aspect-ratio: 16/9;
    background: #000;
}

.completed-scene-video video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.scene-play-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 36px;
    height: 36px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 14px;
    transition: all 0.2s;
    pointer-events: none;
}

.completed-scene-video:hover .scene-play-overlay {
    background: rgba(168, 85, 247, 0.9);
    transform: translate(-50%, -50%) scale(1.1);
}

.scene-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.7rem;
    background: rgba(0, 0, 0, 0.6);
    padding: 6px 12px;
    border-radius: 4px;
    pointer-events: none;
}

.completed-scene-desc {
    padding: 8px 10px;
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.4;
    max-height: 50px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Live scene feedback buttons */
.live-scene-feedback-btns {
    display: flex;
    gap: 4px;
}

.live-fb-btn {
    background: rgba(30, 41, 59, 0.8);
    border: 1px solid rgba(148, 163, 184, 0.3);
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s ease;
    opacity: 0.7;
}

.live-fb-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

.live-fb-btn.thumbs-up.active {
    background: rgba(34, 197, 94, 0.3);
    border-color: rgba(34, 197, 94, 0.6);
    opacity: 1;
}

.live-fb-btn.thumbs-down.active {
    background: rgba(239, 68, 68, 0.3);
    border-color: rgba(239, 68, 68, 0.6);
    opacity: 1;
}

.completed-scene-card.approved {
    border-color: rgba(34, 197, 94, 0.5);
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.2);
}

.completed-scene-card.flagged {
    border-color: rgba(239, 68, 68, 0.5);
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.2);
}

/* Live scene comment section */
.live-scene-comment {
    padding: 8px;
    background: rgba(0, 0, 0, 0.3);
    border-top: 1px solid rgba(148, 163, 184, 0.2);
}

.live-scene-comment textarea {
    width: 100%;
    min-height: 50px;
    padding: 6px;
    font-size: 0.75rem;
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid rgba(148, 163, 184, 0.3);
    border-radius: 4px;
    color: var(--text);
    resize: vertical;
    margin-bottom: 6px;
}

.live-scene-comment textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.live-scene-comment .btn-small {
    width: 100%;
    padding: 6px;
    font-size: 0.75rem;
    background: var(--primary);
    border: none;
    border-radius: 4px;
    color: white;
    cursor: pointer;
}

.live-scene-comment .btn-small:hover {
    background: var(--primary-hover);
}

/* Live feedback toast */
.live-feedback-toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: rgba(34, 197, 94, 0.95);
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 10000;
    animation: slideInRight 0.3s ease;
}

.live-feedback-toast.fade-out {
    animation: slideOutRight 0.3s ease forwards;
}

@keyframes slideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes slideOutRight {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(100%); opacity: 0; }
}

/* Narrative display */
.narrative-display {
    margin-bottom: 16px;
    padding: 14px;
    background: var(--bg-input);
    border-radius: 8px;
    border-left: 3px solid var(--primary);
}

.narrative-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.narrative-header h3 {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin: 0;
}

.narrative-text {
    font-size: 0.85rem;
    line-height: 1.5;
    word-break: break-word;
    white-space: pre-wrap;
}

.btn-copy {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px 8px;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s;
}

.btn-copy:hover {
    background: var(--bg-card);
    color: var(--text);
    border-color: var(--primary);
}

.btn-copy .copy-success {
    color: var(--success);
}

.scene-list h3,
.current-segment h3 {
    font-size: 0.9rem;
    margin-bottom: 10px;
    color: var(--text-muted);
}

.scene-list ul {
    list-style: none;
}

.scene-list li {
    padding: 10px 12px;
    background: var(--bg-input);
    border-radius: 6px;
    margin-bottom: 6px;
    font-size: 0.85rem;
    border-left: 3px solid var(--border);
    word-break: break-word;
}

.scene-list li.active {
    border-left-color: var(--primary);
    background: rgba(168, 85, 247, 0.2);
}

.scene-list li.complete {
    border-left-color: var(--success);
}

.current-segment {
    margin-top: 16px;
    padding: 14px;
    background: var(--bg-input);
    border-radius: 8px;
}

#currentDescription {
    margin-bottom: 10px;
    font-size: 0.9rem;
    word-break: break-word;
}

.sampling-progress {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.mini-progress {
    flex: 1;
    height: 6px;
    background: var(--bg);
    border-radius: 3px;
    overflow: hidden;
}

.mini-progress-fill {
    height: 100%;
    background: var(--primary);
    transition: width 0.2s;
    width: 0%;
}

/* Result Section */
.video-container {
    margin-bottom: 14px;
    border-radius: 10px;
    overflow: hidden;
    background: #000;
}

.video-container video {
    width: 100%;
    display: block;
    max-height: 60vh;
}

.video-info {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 14px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.video-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.video-actions .btn-secondary,
.video-actions .btn-primary {
    flex: 1;
    min-width: 120px;
    text-align: center;
    text-decoration: none;
}

.video-actions .btn-primary {
    width: auto;
}

/* Gallery */
.video-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
}

.gallery-item {
    position: relative;
    background: var(--bg-input);
    border-radius: 10px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s;
    touch-action: manipulation;
}

/* Gallery quick action button */
.gallery-item-action {
  position: absolute;
  bottom: 10px;
  right: 10px;
  padding: 6px 10px;
  font-size: 0.8rem;
  border-radius: 8px;
  border: 1px solid rgba(37, 99, 235, 0.45);
  background: rgba(37, 99, 235, 0.25);
  color: #e2e8f0;
  cursor: pointer;
  backdrop-filter: blur(6px);
}

.gallery-item-action:hover {
  background: rgba(37, 99, 235, 0.35);
}

/* Gallery item overlay */
.gallery-item-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  gap: 8px;
  justify-content: center;
  padding: 8px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
  opacity: 0;
  transition: opacity 0.2s ease;
}

.gallery-item:hover .gallery-item-overlay {
  opacity: 1;
}

.gallery-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  font-size: 1rem;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s ease;
}

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

/* Gallery bulk selection toolbar */
.gallery-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin: 10px 0 14px 0;
}

.btn-sm {
  padding: 8px 12px;
  min-height: 36px;
  font-size: 0.9rem;
}

/* Gallery selection checkboxes - always visible */
.gallery-item.selected,
.photo-item.selected {
  outline: 2px solid rgba(34, 197, 94, 0.85);
  box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.15);
}

.gallery-select-check {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.85);
  border: 2px solid rgba(148, 163, 184, 0.6);
  color: transparent;
  font-size: 12px;
  font-weight: bold;
  z-index: 11;
  cursor: pointer;
  transition: all 0.15s ease;
  backdrop-filter: blur(6px);
}

.gallery-select-check:hover {
  border-color: rgba(168, 85, 247, 0.8);
  background: rgba(168, 85, 247, 0.2);
}

.gallery-select-check.checked {
  background: rgba(34, 197, 94, 0.95);
  border-color: rgba(34, 197, 94, 1);
  color: #fff;
}

.gallery-item:hover,
.gallery-item:active {
    transform: scale(1.02);
}

.gallery-item video {
    width: 100%;
    height: 100px;
    object-fit: cover;
    background: #000;
}

.gallery-item-delete {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 24px;
    height: 24px;
    background: rgba(239, 68, 68, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
    touch-action: manipulation;
    z-index: 10;
}

.gallery-item:hover .gallery-item-delete {
    opacity: 1;
}

.gallery-item-delete:hover {
    background: rgba(220, 38, 38, 1);
}

/* ── Gallery rename button ── */
.gallery-item-rename {
    position: absolute;
    top: 6px;
    right: 36px; /* sits left of the delete button */
    width: 24px;
    height: 24px;
    background: rgba(99, 102, 241, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
    touch-action: manipulation;
    z-index: 10;
}
.gallery-item:hover .gallery-item-rename { opacity: 1; }
.gallery-item-rename:hover { background: rgba(79, 70, 229, 1); }

/* List view: make rename button static like delete */
.video-gallery.view-list .gallery-item-rename {
    position: static;
    opacity: 0.5;
    flex-shrink: 0;
}
.video-gallery.view-list .gallery-item:hover .gallery-item-rename { opacity: 1; }

/* Compact view: same as grid (absolute) */
.video-gallery.view-compact .gallery-item-rename {
    right: 36px;
    opacity: 0;
}
.video-gallery.view-compact .gallery-item:hover .gallery-item-rename { opacity: 1; }

/* ── Rename video modal ── */
.rename-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 10000;
    align-items: center;
    justify-content: center;
}
.rename-modal-panel {
    background: #1e2435;
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 12px;
    padding: 0;
    width: 420px;
    max-width: 90vw;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.rename-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.rename-modal-title {
    font-size: 1rem;
    font-weight: 600;
    color: #e2e8f0;
}
.rename-modal-close {
    background: none;
    border: none;
    color: rgba(255,255,255,0.5);
    font-size: 20px;
    cursor: pointer;
    line-height: 1;
    padding: 0 2px;
}
.rename-modal-close:hover { color: #fff; }
.rename-modal-body {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 4px;
}
.rename-modal-label {
    display: none; /* handled by placeholder */
}
.rename-modal-input {
    flex: 1;
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 6px;
    color: #e2e8f0;
    font-size: 0.875rem;
    padding: 8px 10px;
    outline: none;
    transition: border-color 0.2s;
}
.rename-modal-input:focus { border-color: rgba(99,102,241,0.7); }
.rename-modal-ext {
    font-size: 0.875rem;
    color: rgba(255,255,255,0.4);
    flex-shrink: 0;
}
.rename-modal-footer {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding: 12px 20px 16px;
    border-top: 1px solid rgba(255,255,255,0.08);
}

/* ── Gallery view toggle buttons ── */
.gallery-view-spacer { flex: 1; }

.gallery-view-toggle {
  display: flex;
  gap: 2px;
  background: rgba(255,255,255,0.06);
  border-radius: 6px;
  padding: 2px;
}

.gallery-view-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: #64748b;
  font-size: 1.1rem;
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.gallery-view-btn:hover {
  color: #94a3b8;
  background: rgba(255,255,255,0.08);
}

.gallery-view-btn.active {
  color: #e2e8f0;
  background: rgba(255,255,255,0.14);
}

/* ── Gallery list view ── */
.video-gallery.view-list {
  grid-template-columns: 1fr !important;
  gap: 4px !important;
}

.video-gallery.view-list .gallery-item {
  display: flex !important;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 6px;
  aspect-ratio: unset !important;
  overflow: visible;
}

.video-gallery.view-list .gallery-item video,
.video-gallery.view-list .gallery-item .gallery-thumb {
  width: 80px !important;
  height: 45px !important;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
  background: #000;
}

.video-gallery.view-list .gallery-item-info {
  flex: 1;
  padding: 0;
  display: flex !important;
  align-items: center;
  gap: 16px;
}

.video-gallery.view-list .gallery-item-name {
  flex: 1;
  margin-bottom: 0;
}

.video-gallery.view-list .gallery-item-date {
  flex-shrink: 0;
  font-size: 0.75rem;
}

.video-gallery.view-list .gallery-select-check {
  position: static;
  flex-shrink: 0;
  opacity: 1;
}

.video-gallery.view-list .gallery-item-action {
  position: static;
  flex-shrink: 0;
}

.video-gallery.view-list .gallery-item-delete {
  position: static;
  opacity: 0.5;
  flex-shrink: 0;
}

.video-gallery.view-list .gallery-item:hover .gallery-item-delete {
  opacity: 1;
}

/* ── Gallery compact view ── */
.video-gallery.view-compact {
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)) !important;
  gap: 6px !important;
}

.video-gallery.view-compact .gallery-item video,
.video-gallery.view-compact .gallery-item .gallery-thumb {
  height: 65px !important;
}

.video-gallery.view-compact .gallery-item-info {
  display: none !important;
}

.video-gallery.view-compact .gallery-item-action {
  display: none !important;
}

.video-gallery.view-compact .gallery-select-check {
  width: 18px;
  height: 18px;
  font-size: 0.6rem;
  top: 3px;
  left: 3px;
}

.video-gallery.view-compact .gallery-item-delete {
  width: 18px;
  height: 18px;
  font-size: 0.65rem;
  top: 3px;
  right: 3px;
}

/* Audio Assets Gallery — compact accordion list */
.audio-assets-gallery {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.audio-asset-item {
    display: flex;
    flex-direction: column;
    background: var(--tc-glass-bg-input, rgba(255,255,255,0.04));
    border-radius: var(--tc-radius-md, 10px);
    overflow: hidden;
    transition: box-shadow 0.15s;
}

.audio-asset-item:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.audio-asset-item.selected {
    outline: 2px solid rgba(34, 197, 94, 0.85);
    box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.15);
}

/* Compact single-line row */
.audio-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 10px;
    height: 44px;
    min-width: 0;
}

.audio-row .gallery-select-check {
    position: relative;
    top: auto;
    left: auto;
    flex-shrink: 0;
}

/* Circular play / collapse button */
.audio-play-btn {
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: rgba(99, 102, 241, 0.25);
    border: 1px solid rgba(99, 102, 241, 0.4);
    color: #fff;
    font-size: 0.7rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, border-color 0.15s;
    padding: 0;
    line-height: 1;
}

.audio-play-btn:hover {
    background: rgba(99, 102, 241, 0.45);
    border-color: rgba(99, 102, 241, 0.7);
}

.audio-play-btn.playing {
    background: rgba(16, 185, 129, 0.3);
    border-color: rgba(16, 185, 129, 0.6);
}

.audio-source-badge {
    flex-shrink: 0;
    display: inline-block;
    padding: 2px 7px;
    border-radius: 10px;
    font-size: 0.68rem;
    color: #fff;
    font-weight: 500;
}

/* Track name — fills remaining space */
.audio-track-name {
    flex: 1;
    min-width: 0;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Date + size — right-aligned, de-emphasized */
.audio-track-meta {
    flex-shrink: 0;
    font-size: 0.72rem;
    opacity: 0.55;
    white-space: nowrap;
}

.audio-asset-actions {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-shrink: 0;
}

.audio-asset-actions .gallery-btn {
    text-decoration: none;
    font-size: 1rem;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    background: transparent;
    color: inherit;
    border: none;
}

.audio-asset-actions .gallery-btn:hover {
    background: rgba(255,255,255,0.1);
}

.audio-asset-actions .gallery-item-delete {
    position: relative;
    top: auto;
    right: auto;
}

/* Expandable player — shown when a track is opened */
.audio-expand-panel {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px 10px;
    border-top: 1px solid rgba(255,255,255,0.07);
    background: rgba(0,0,0,0.12);
}

.audio-expand-panel audio {
    flex: 1;
    min-width: 0;
    height: 36px;
}

.audio-speed-select {
    flex-shrink: 0;
    width: 62px;
    padding: 3px 4px;
    font-size: 0.75rem;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.15);
    background: rgba(255,255,255,0.06);
    color: inherit;
    cursor: pointer;
    text-align: center;
}

.audio-speed-select:hover {
    border-color: rgba(255,255,255,0.3);
}

.audio-speed-select:focus {
    outline: 2px solid rgba(99, 102, 241, 0.5);
    outline-offset: 1px;
}

/* Photo Gallery */
.photo-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
}

.photo-item {
    position: relative;
    background: var(--bg-input);
    border-radius: 10px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s;
    touch-action: manipulation;
    aspect-ratio: 1;
}

.photo-item:hover,
.photo-item:active {
    transform: scale(1.02);
}

.photo-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.photo-item-delete {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 24px;
    height: 24px;
    background: rgba(239, 68, 68, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
    touch-action: manipulation;
    z-index: 10;
}

.photo-item:hover .photo-item-delete {
    opacity: 1;
}

.photo-item-delete:hover {
    background: rgba(220, 38, 38, 1);
}

.photo-item-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 6px 8px;
    background: linear-gradient(transparent, rgba(0,0,0,0.7));
    font-size: 0.7rem;
    color: white;
}

/* Photo lightbox */
.photo-lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--tc-z-modal);
    padding: var(--tc-space-5);
    animation: backdropFadeIn 0.2s ease;
}

/* Video lightbox (gallery) */
.video-lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--tc-z-modal);
    padding: var(--tc-space-5);
    animation: backdropFadeIn 0.2s ease;
}

.video-lightbox-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    max-width: 92vw;
    max-height: 92vh;
}

.video-lightbox-content video {
    width: min(1100px, 92vw);
    max-height: calc(92vh - 80px);
    background: rgba(0,0,0,0.6);
    border-radius: 10px;
}

.video-lightbox-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 6px;
}

.video-lightbox-actions .btn-primary,
.video-lightbox-actions .btn-secondary {
    min-width: 120px;
}

/* Free-user diagonal watermark overlay */
.watermark-overlay {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: 2;
    border-radius: 10px;
}
.watermark-overlay::before {
    content: 'TaleClip.com    TaleClip.com    TaleClip.com    TaleClip.com    TaleClip.com    TaleClip.com    TaleClip.com    TaleClip.com    TaleClip.com    TaleClip.com    TaleClip.com    TaleClip.com    TaleClip.com    TaleClip.com    TaleClip.com    TaleClip.com';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    display: flex;
    flex-wrap: wrap;
    align-content: space-around;
    justify-content: space-around;
    font-size: 24px;
    font-weight: 700;
    letter-spacing: 4px;
    color: rgba(255, 255, 255, 0.12);
    transform: rotate(-30deg);
    word-spacing: 80px;
    line-height: 80px;
    white-space: normal;
    pointer-events: none;
}

.photo-lightbox img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
}

.photo-lightbox-close {
    position: absolute;
    top: var(--tc-space-5);
    right: var(--tc-space-5);
    width: 40px;
    height: 40px;
    background: var(--tc-glass-bg-active);
    backdrop-filter: blur(var(--tc-glass-blur));
    -webkit-backdrop-filter: blur(var(--tc-glass-blur));
    color: var(--tc-text-primary);
    border: var(--tc-glass-border);
    border-radius: var(--tc-radius-round);
    cursor: pointer;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--tc-transition-fast);
}

.photo-lightbox-close:hover {
    background: var(--tc-primary);
    border-color: var(--tc-primary);
    box-shadow: var(--tc-glow-primary);
}

.photo-lightbox-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    max-width: 90vw;
    max-height: 90vh;
}

.photo-lightbox-content img {
    max-width: 100%;
    max-height: calc(90vh - 60px);
    object-fit: contain;
    border-radius: 8px;
}

.photo-lightbox-actions {
    display: flex;
    gap: 12px;
    flex-wrap: nowrap;
    justify-content: center;
    margin-bottom: 20px;
}

.photo-lightbox-actions .btn-primary,
.photo-lightbox-actions .btn-secondary {
    min-width: 120px;
}

/* Edit Result Lightbox */
.edit-result-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    animation: fadeIn 0.2s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.edit-result-lightbox-content {
    position: relative;
    max-width: 95vw;
    max-height: 95vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.edit-result-lightbox-content img {
    max-width: 100%;
    max-height: 95vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.edit-result-lightbox-close {
    position: absolute;
    top: -50px;
    right: 0;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    cursor: pointer;
    font-size: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    line-height: 1;
    padding: 0;
}

.edit-result-lightbox-close:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
    transform: scale(1.1);
}

.gallery-item-info {
    padding: 8px 10px;
    font-size: 0.8rem;
}

.gallery-item-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.gallery-item-date {
    color: var(--text-muted);
    font-size: 0.75rem;
}
.owner-badge {
    display: inline-block;
    background: rgba(168, 85, 247, 0.2);
    color: var(--primary);
    font-size: 0.65rem;
    padding: 1px 5px;
    border-radius: 8px;
    margin-left: 4px;
    font-weight: 600;
}
.gallery-merged-badge {
    position: absolute;
    top: 6px;
    left: 6px;
    background: rgba(0, 0, 0, 0.85);
    color: #fbbf24;
    font-size: 0.7rem;
    font-weight: 800;
    width: 20px;
    height: 20px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    pointer-events: none;
    line-height: 1;
}

.empty-message {
    color: var(--text-muted);
    text-align: center;
    padding: 30px 20px;
}

/* Gallery loading skeletons */
.gallery-skeleton {
    pointer-events: none;
}
.skeleton-thumb {
    width: 100%;
    aspect-ratio: 16 / 9;
    background: rgba(255, 255, 255, 0.06);
    position: relative;
    overflow: hidden;
}
.skeleton-thumb::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.12) 50%, transparent 100%);
    background-size: 200% 100%;
    animation: shimmer 1.6s infinite;
}
.skeleton-line {
    height: 10px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.06);
    position: relative;
    overflow: hidden;
}
.skeleton-line::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.12) 50%, transparent 100%);
    background-size: 200% 100%;
    animation: shimmer 1.6s infinite;
}
.skeleton-line-long { width: 80%; }
.skeleton-line-short { width: 50%; margin-top: 6px; }

/* Gallery loading overlay with spinner */
.gallery-loading-overlay {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    gap: 16px;
}
.gallery-loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--tc-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
.gallery-loading-text {
    color: var(--tc-text-muted, #64748b);
    font-size: 0.85rem;
}

.section-desc {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 16px;
}

/* Image Edit Section */
.edit-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.edit-grid.single {
    grid-template-columns: 1fr;
}

.edit-input,
.edit-output {
    display: flex;
    flex-direction: column;
}

.edit-output {
    background: var(--bg-input);
    border-radius: 12px;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
}

.edit-output .image-preview {
    max-height: 300px;
    width: 100%;
    object-fit: contain;
    cursor: pointer;
    transition: opacity 0.2s;
}

.edit-output .image-preview:hover {
    opacity: 0.9;
}

.edit-actions {
    margin-bottom: 16px;
}

.edit-progress {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    padding: 12px;
    background: var(--bg-input);
    border-radius: 8px;
}

.edit-progress .progress-bar {
    flex: 1;
}

.edit-status {
    font-size: 0.85rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.edit-result-actions {
    display: flex;
    gap: 10px;
}

.edit-result-actions .btn-secondary {
    flex: 1;
}

/* Video Concatenation */
.concat-upload-area {
    border: 2px dashed var(--border);
    border-radius: 10px;
    padding: 24px 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 16px;
    touch-action: manipulation;
}

.concat-upload-area:hover,
.concat-upload-area:active,
.concat-upload-area.dragover {
    border-color: var(--primary);
    background: rgba(168, 85, 247, 0.1);
}

.concat-upload-placeholder {
    color: var(--text-muted);
}

.concat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
    min-height: 0;
    margin-bottom: 16px;
}

.concat-grid:empty {
    display: none;
}

.concat-item {
    position: relative;
    background: var(--bg-input);
    border-radius: 10px;
    overflow: hidden;
    cursor: grab;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 2px solid transparent;
    touch-action: none;
}

.concat-item:hover {
    transform: scale(1.02);
}

.concat-item.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.concat-item.drag-over {
    border-color: var(--primary);
    box-shadow: 0 0 12px rgba(168, 85, 247, 0.4);
}

.concat-item video {
    width: 100%;
    height: 90px;
    object-fit: cover;
    background: #000;
    pointer-events: none;
}

.concat-item-info {
    padding: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.concat-item-order {
    background: var(--primary);
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    min-width: 24px;
    text-align: center;
}

.concat-item-duration {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.concat-item-remove {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 24px;
    height: 24px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
    touch-action: manipulation;
}

.concat-item:hover .concat-item-remove,
.concat-item:active .concat-item-remove {
    opacity: 1;
}

/* ==================== Merge Reorder Storyboard ==================== */

.merge-reorder-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.merge-reorder-grid {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 16px 8px;
    min-height: 160px;
    align-items: flex-start;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    border: 2px dashed rgba(255, 255, 255, 0.08);
}

.merge-reorder-grid::-webkit-scrollbar {
    height: 6px;
}

.merge-reorder-grid::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}

.merge-reorder-grid::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}

.merge-reorder-item {
    position: relative;
    flex-shrink: 0;
    width: 140px;
    background: var(--bg-input);
    border-radius: 8px;
    overflow: hidden;
    cursor: grab;
    transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
    border: 2px solid transparent;
    user-select: none;
}

.merge-reorder-item:hover {
    transform: scale(1.04);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.merge-reorder-item.dragging {
    opacity: 0.4;
    cursor: grabbing;
    transform: scale(0.95);
}

.merge-reorder-item.drag-over {
    border-color: var(--primary);
    box-shadow: 0 0 16px rgba(168, 85, 247, 0.5);
    transform: scale(1.06);
}

.merge-reorder-item img {
    width: 100%;
    height: 80px;
    object-fit: cover;
    background: #000;
    pointer-events: none;
    display: block;
}

.merge-reorder-item-info {
    padding: 6px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.merge-reorder-item-order {
    position: absolute;
    top: 6px;
    left: 6px;
    background: var(--primary);
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.merge-reorder-item-name {
    font-size: 0.65rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Arrow connector between storyboard items */
.merge-reorder-arrow {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    color: rgba(255, 255, 255, 0.2);
    font-size: 1.2rem;
    padding: 0 2px;
    align-self: center;
}

.concat-info {
    display: flex;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-input);
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.9rem;
}

#concatCount {
    color: var(--text);
    font-weight: 500;
}

#concatDuration {
    color: var(--secondary);
    font-weight: 600;
}

.concat-actions {
    display: flex;
    gap: 10px;
}

.concat-actions .btn-secondary {
    flex: 0 0 auto;
    padding: 12px 16px;
}

.concat-actions .btn-primary {
    flex: 1;
}

/* Drag placeholder */
.concat-placeholder {
    background: rgba(168, 85, 247, 0.2);
    border: 2px dashed var(--primary);
    border-radius: 10px;
    min-height: 130px;
}

/* ==================== VIDEO MAIN MODE TOGGLE ==================== */

.video-main-mode-toggle {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    padding: 8px;
    background: var(--card-bg);
    border-radius: 12px;
    border: 1px solid var(--border);
}

.main-mode-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.main-mode-btn:hover {
    background: var(--hover-bg);
    color: var(--text);
}

.main-mode-btn.active {
    background: var(--primary);
    color: white;
}

.main-mode-btn .mode-icon {
    font-size: 18px;
}

/* ==================== VIDEO ENHANCEMENT ==================== */

.video-enhance-upload {
    margin-bottom: 24px;
}

.video-enhance-upload .upload-dropzone {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--card-bg);
}

.video-enhance-upload .upload-dropzone:hover,
.video-enhance-upload .upload-dropzone.dragover {
    border-color: var(--primary);
    background: rgba(168, 85, 247, 0.1);
}

.video-enhance-upload .upload-icon {
    font-size: 48px;
    display: block;
    margin-bottom: 16px;
}

.video-enhance-upload .upload-hint {
    font-size: 0.85em;
    color: var(--text-muted);
    margin-top: 8px;
}

.video-enhance-preview {
    margin-bottom: 24px;
}

.video-enhance-preview .preview-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-bottom: 16px;
}

.video-enhance-preview .preview-box {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 16px;
}

.video-enhance-preview .preview-box h4 {
    margin: 0 0 12px 0;
    font-size: 14px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.video-enhance-preview .preview-box video {
    width: 100%;
    border-radius: 8px;
    background: #000;
}

.video-enhance-preview .preview-placeholder {
    width: 100%;
    aspect-ratio: 16/9;
    background: var(--bg-tertiary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 14px;
}

.video-enhance-preview .preview-info {
    margin-top: 8px;
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
}

.video-enhance-options {
    margin-bottom: 24px;
}

.video-enhance-options h3 {
    margin: 0 0 16px 0;
    font-size: 16px;
}

.video-enhance-options .options-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.video-enhance-options .option-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.video-enhance-options .option-group label {
    font-size: 13px;
    color: var(--text-muted);
}

.video-enhance-options .option-group.checkbox-group {
    flex-direction: row;
    align-items: center;
}

.video-enhance-options .option-group.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

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

.video-enhance-options .form-select {
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text);
    font-size: 14px;
}

.video-enhance-options .form-range {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-tertiary);
    cursor: pointer;
}

.video-enhance-progress {
    margin-bottom: 24px;
    padding: 20px;
    background: var(--bg-secondary);
    border-radius: 12px;
}

.video-enhance-progress .progress-status {
    display: flex;
    justify-content: space-between;
    margin-bottom: 12px;
    font-size: 14px;
}

.video-enhance-progress .progress-bar {
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
}

.video-enhance-progress .progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--primary-light));
    border-radius: 4px;
    transition: width 0.3s ease;
}

.video-enhance-progress .progress-detail {
    margin-top: 12px;
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
}

.video-enhance-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.video-enhance-actions .btn-primary {
    flex: 1;
    min-width: 200px;
}

.video-enhance-actions .btn-secondary {
    flex: 0 0 auto;
}

/* Page subtitle */
.page-subtitle {
    color: var(--text-muted);
    font-size: 16px;
    margin-top: -8px;
    margin-bottom: 24px;
}

/* Responsive */
@media (max-width: 768px) {
    .video-enhance-preview .preview-container {
        grid-template-columns: 1fr;
    }

    .video-enhance-options .options-grid {
        grid-template-columns: 1fr;
    }
}

/* Gallery drag hint */
.gallery-item.draggable {
    cursor: grab;
}

.gallery-item.draggable:active {
    cursor: grabbing;
}

/* Footer */
footer {
    text-align: center;
    padding: 24px 0;
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* Animations */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.processing {
    animation: pulse 1.5s infinite;
}

/* ============================================
   TABLET BREAKPOINT (768px and below)
   ============================================ */
@media (max-width: 768px) {
    .container {
        padding: 16px;
    }

    header {
        padding: 20px 0;
    }

    header h1 {
        font-size: 1.9rem;
    }

    .form-row {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .video-gallery {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }

    /* Tabs - tablet: 4x2 grid layout */
    .tab-nav {
        display: grid !important;
        grid-template-columns: repeat(4, 1fr) !important;
        padding: 5px !important;
        gap: 4px !important;
        flex-wrap: nowrap !important;
        overflow-x: visible !important;
    }
    
    .tab-nav::after {
        display: none !important;
    }

    .tab-btn {
        padding: 8px 10px !important;
        font-size: 0 !important;
        flex: none !important;
        min-width: 0 !important;
    }
    
    .tab-btn::after {
        font-size: 0.75rem !important;
        display: inline-block !important;
    }
    
    .tab-btn[data-tab="create-video"]::after { content: "Create" !important; }
    .tab-btn[data-tab="talking-avatar"]::after { content: "Avatar" !important; }
    .tab-btn[data-tab="generate-image"]::after { content: "Generate" !important; }
    .tab-btn[data-tab="edit-image"]::after { content: "Edit" !important; }
    .tab-btn[data-tab="merge-videos"]::after { content: "Merge" !important; }
    .tab-btn[data-tab="gallery"]::after { content: "Gallery" !important; }
    .tab-btn[data-tab="enhance-photo"]::after { content: "Enhance" !important; }
    .tab-btn[data-tab="narrate"]::after { content: "Narrate" !important; }
    .tab-btn[data-tab="prompt-engineer"]::after { content: "Prompt" !important; }
}

/* ============================================
   MOBILE BREAKPOINT (480px and below)
   ============================================ */
@media (max-width: 480px) {
    html {
        font-size: 15px;
    }

    .container {
        padding: 12px;
    }

    header {
        padding: 16px 0;
    }

    header h1 {
        font-size: 1.6rem;
    }

    .subtitle {
        font-size: 0.9rem;
    }

    .comfyui-status {
        font-size: 0.8rem;
        padding: 6px 12px;
        gap: 6px;
    }

    #comfyuiStatusText {
        max-width: 100px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Compact dashboard for mobile - 2x2 grid */
    .dashboard-grid {
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }

    .dashboard-card {
        padding: 6px 5px;
        border-radius: 8px;
    }

    .dashboard-card h3 {
        font-size: 0.65rem;
        margin-bottom: 3px;
    }

    .gauge {
        width: 50px;
        height: 31px;
    }

    .gauge-value {
        top: 16px;
    }

    .gauge-number {
        font-size: 0.6rem;
    }

    .gauge-unit {
        font-size: 0.45rem;
    }

    .gauge-label {
        font-size: 0.5rem;
    }

    .chart-card canvas {
        height: 25px !important;
    }

    .chart-header {
        font-size: 0.55rem;
    }

    .card {
        padding: 14px;
        border-radius: 12px;
        margin-bottom: 14px;
    }

    .card h2 {
        font-size: 1.1rem;
        margin-bottom: 14px;
    }

    .form-group {
        margin-bottom: 14px;
    }

    .form-group label {
        font-size: 0.9rem;
        margin-bottom: 5px;
    }

    .upload-area {
        padding: 24px 16px;
    }

    .upload-icon {
        font-size: 2rem;
    }

    .image-preview {
        max-height: 200px;
    }

    .mode-toggle {
        width: 100%;
    }

    .mode-btn {
        flex: 1;
        padding: 10px 12px;
        font-size: 0.8rem;
    }

    .multi-image-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }

    .multi-image-item .image-number {
        width: 18px;
        height: 18px;
        font-size: 0.65rem;
    }

    .multi-image-item .remove-btn {
        width: 18px;
        height: 18px;
        font-size: 12px;
        opacity: 1;
    }

    .btn-primary {
        padding: 14px 20px;
        min-height: 50px;
    }

    .btn-secondary {
        padding: 12px 16px;
        min-height: 46px;
        font-size: 0.9rem;
    }

    .video-actions {
        flex-direction: column;
        gap: 8px;
    }

    .video-gallery {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .gallery-item {
        border-radius: 8px;
    }

    .gallery-item video {
        height: 80px;
    }

    .gallery-item-delete {
        opacity: 1;
        width: 22px;
        height: 22px;
    }

    .gallery-item-info {
        padding: 6px 8px;
    }

    .gallery-item-name {
        font-size: 0.75rem;
    }

    .gallery-item-date {
        font-size: 0.7rem;
    }

    /* Edit section mobile */
    .edit-grid {
        grid-template-columns: 1fr;
    }

    .edit-output {
        min-height: 150px;
    }

    .edit-result-actions {
        flex-direction: column;
        gap: 8px;
    }

    /* Concat mobile */
    .concat-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .concat-item video {
        height: 70px;
    }

    .concat-item-info {
        padding: 6px;
    }

    .concat-item-order {
        font-size: 0.65rem;
        padding: 2px 6px;
    }

    .concat-item-remove {
        opacity: 1;
        width: 22px;
        height: 22px;
    }

    .concat-info {
        padding: 10px 12px;
        font-size: 0.85rem;
    }

    .concat-actions {
        flex-direction: column;
        gap: 8px;
    }

    .concat-actions .btn-secondary,
    .concat-actions .btn-primary {
        flex: none;
        width: 100%;
    }

    .scene-list li {
        padding: 8px 10px;
        font-size: 0.8rem;
    }

    .status-message {
        padding: 12px;
        font-size: 0.9rem;
    }

    footer {
        padding: 20px 0;
        font-size: 0.75rem;
    }

    /* Tabs - mobile: 2x4 grid layout */
    .tab-nav {
        display: grid !important;
        grid-template-columns: repeat(4, 1fr) !important;
        padding: 4px !important;
        gap: 3px !important;
        border-radius: 10px !important;
        margin-bottom: 14px !important;
        overflow-x: visible !important;
        flex-wrap: nowrap !important;
    }
    
    .tab-nav::after {
        display: none !important;
    }

    .tab-btn {
        padding: 9px 6px !important;
        border-radius: 6px !important;
        min-width: 0 !important;
        font-size: 0 !important; /* Hide original text */
        flex: none !important;
    }
    
    /* Shorter labels for mobile */
    .tab-btn::after {
        font-size: 0.7rem !important;
        line-height: 1.2 !important;
        display: inline-block !important;
    }
    
    .tab-btn[data-tab="create-video"]::after { content: "Create" !important; }
    .tab-btn[data-tab="talking-avatar"]::after { content: "Avatar" !important; }
    .tab-btn[data-tab="generate-image"]::after { content: "Generate" !important; }
    .tab-btn[data-tab="edit-image"]::after { content: "Edit" !important; }
    .tab-btn[data-tab="merge-videos"]::after { content: "Merge" !important; }
    .tab-btn[data-tab="gallery"]::after { content: "Gallery" !important; }
    .tab-btn[data-tab="enhance-photo"]::after { content: "Enhance" !important; }
    .tab-btn[data-tab="narrate"]::after { content: "Narrate" !important; }
    .tab-btn[data-tab="prompt-engineer"]::after { content: "Prompt" !important; }
}

/* ============================================
   LARGE PHONE (iPhone Pro Max, etc - 430px and below)
   ============================================ */
@media (max-width: 430px) {
    .tab-nav {
        padding: 4px !important;
        gap: 3px !important;
    }

    .tab-btn {
        padding: 9px 4px !important;
    }
    
    .tab-btn::after {
        font-size: 0.68rem !important;
    }
}

/* ============================================
   SMALL MOBILE (360px and below)
   ============================================ */
@media (max-width: 360px) {
    .container {
        padding: 10px;
    }

    header h1 {
        font-size: 1.4rem;
    }

    .comfyui-status {
        flex-direction: column;
        gap: 4px;
    }

    #comfyuiStatusText {
        max-width: none;
    }

    .dashboard-grid {
        gap: 4px;
    }

    .gauge {
        width: 43px;
        height: 27px;
    }

    .gauge-value {
        top: 14px;
    }

    .gauge-number {
        font-size: 0.5rem;
    }

    .chart-card canvas {
        height: 20px !important;
    }

    .card {
        padding: 12px;
    }

    .video-gallery {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    /* Tabs - very small mobile */
    .tab-nav {
        padding: 3px !important;
        gap: 2px !important;
    }

    .tab-btn {
        padding: 8px 3px !important;
    }
    
    .tab-btn::after {
        font-size: 0.65rem !important;
    }
}

/* ============================================
   LANDSCAPE MODE ON MOBILE
   ============================================ */
@media (max-height: 500px) and (orientation: landscape) {
    header {
        padding: 10px 0;
    }

    header h1 {
        font-size: 1.4rem;
        margin-bottom: 4px;
    }

    .subtitle {
        font-size: 0.8rem;
    }

    .dashboard-section {
        margin-bottom: 8px;
    }

    .dashboard-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 6px;
    }

    .dashboard-card {
        padding: 5px;
    }

    .gauge {
        width: 40px;
        height: 25px;
    }

    .gauge-value {
        top: 13px;
    }

    .gauge-number {
        font-size: 0.5rem;
    }

    .chart-card canvas {
        height: 20px !important;
    }

    .card {
        padding: 12px;
        margin-bottom: 12px;
    }

    .video-container video {
        max-height: 40vh;
    }

    .image-preview {
        max-height: 150px;
    }
}

/* ============================================
   SAFE AREA INSETS (for notched phones)
   ============================================ */
@supports (padding: max(0px)) {
    .container {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
}

/* ============================================
   DARK MODE PREFERENCE (already dark, but ensures consistency)
   ============================================ */
@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
    }
}

/* ============================================
   REDUCED MOTION PREFERENCE
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .progress-fill,
    .mini-progress-fill {
        transition: none;
    }
}

/* Conversation Section */
#conversationSection {
    margin-top: 20px;
    margin-bottom: 20px;
}

#conversationSection label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text);
}

.conversation-messages {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 12px;
}

.conversation-message {
    margin-bottom: 16px;
    padding: 12px;
    border-radius: 8px;
    animation: fadeIn 0.3s ease-out;
}

.conversation-message:last-child {
    margin-bottom: 0;
}

.conversation-message.ai {
    background: rgba(168, 85, 247, 0.1);
    border-left: 3px solid var(--primary);
}

.conversation-message.user {
    background: rgba(16, 185, 129, 0.1);
    border-left: 3px solid var(--secondary);
    margin-left: 20px;
}

.message-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    margin-bottom: 6px;
    opacity: 0.7;
}

.message-label.ai {
    color: var(--primary);
}

.message-label.user {
    color: var(--secondary);
}

.message-content {
    font-size: 0.9rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

.conversation-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.conversation-input-wrapper textarea {
    flex: 1;
    min-height: 60px;
}

.conversation-input-wrapper button {
    min-width: 120px;
    white-space: nowrap;
}

/* Optimized Prompt Section */
#optimizedPromptSection {
    margin-top: 20px;
    padding: 16px;
    background: rgba(168, 85, 247, 0.05);
    border-radius: 12px;
    border: 1px solid rgba(168, 85, 247, 0.2);
}

#optimizedPromptSection .label-row {
    margin-bottom: 8px;
}

#optimizedPromptSection label {
    color: var(--primary);
    font-weight: 600;
}

#optimizedPrompt {
    background: var(--bg-card);
    border: 1px solid rgba(168, 85, 247, 0.3);
}

#optimizedPrompt:focus {
    border-color: var(--primary);
    outline: none;
}

/* =============================================================================
   AI CHAT WIDGET
   ============================================================================= */

.ai-chat-widget {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: var(--tc-z-chat);
}

.chat-toggle-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    background: var(--tc-primary-gradient);
    border: none;
    border-radius: var(--tc-radius-pill);
    color: #fff;
    font-weight: var(--tc-font-weight-semi);
    font-size: var(--tc-font-size-md);
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(168, 85, 247, 0.4);
    transition: all 0.3s ease;
}

.chat-toggle-btn:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 12px 32px var(--tc-primary-glow-strong);
}

.chat-toggle-btn:active {
    transform: translateY(0) scale(0.98);
}

.chat-icon {
    font-size: 1.5rem;
    line-height: 1;
}

.chat-label {
    font-size: 1rem;
}

.chat-panel {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 420px;
    height: 600px;
    background: var(--tc-glass-bg-active);
    backdrop-filter: blur(var(--tc-glass-blur-heavy));
    -webkit-backdrop-filter: blur(var(--tc-glass-blur-heavy));
    border: var(--tc-glass-border-hover);
    border-radius: var(--tc-radius-xl);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Expanded/Fullscreen Mode */
.chat-panel.expanded {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    bottom: auto !important;
    right: auto !important;
    width: 85vw !important;
    height: 85vh !important;
    max-width: 1100px !important;
    max-height: 850px !important;
    z-index: 3000 !important;
    border: 2px solid var(--primary) !important;
    box-shadow: 0 0 60px rgba(168, 85, 247, 0.4) !important;
}

.chat-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 2999;
    backdrop-filter: blur(4px);
}

/* Chat Header */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    background: rgba(51, 65, 85, 0.8);
    border-bottom: 1px solid rgba(148, 163, 184, 0.2);
}

.chat-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text);
}

.chat-logo {
    font-size: 1.5rem;
    line-height: 1;
}

.chat-controls {
    display: flex;
    gap: 0.5rem;
}

.chat-control-btn {
    padding: 0.5rem;
    background: transparent;
    border: 1px solid rgba(148, 163, 184, 0.3);
    border-radius: 6px;
    color: var(--text);
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.chat-control-btn:hover {
    background: rgba(168, 85, 247, 0.2);
    border-color: var(--primary);
}

.chat-control-btn.muted {
    opacity: 0.5;
    color: var(--text-muted);
}

.chat-control-btn.muted:hover {
    opacity: 0.7;
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: rgba(15, 23, 42, 0.6);
}

.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 4px;
}

.chat-message {
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    animation: fadeIn 0.3s ease;
}

.chat-message.ai-message {
    background: rgba(168, 85, 247, 0.1);
    border-left: 3px solid var(--primary);
    margin-right: 2rem;
}

.chat-message.user-message {
    background: rgba(16, 185, 129, 0.1);
    border-left: 3px solid var(--secondary);
    margin-left: 2rem;
}

.message-label {
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    opacity: 0.8;
}

.message-content {
    font-size: 0.95rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

.ai-greeting {
    color: var(--primary);
    font-weight: 700;
    font-size: 1.1rem;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    margin: 0 1rem 1rem 1rem;
    background: rgba(168, 85, 247, 0.1);
    border-radius: 12px;
    border-left: 3px solid var(--primary);
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {
    0%, 60%, 100% {
        opacity: 0.3;
        transform: translateY(0);
    }
    30% {
        opacity: 1;
        transform: translateY(-8px);
    }
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideOutRight {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100px);
    }
}

/* Chat Input */
.chat-input-container {
    padding: 1rem;
    background: rgba(51, 65, 85, 0.8);
    border-top: 1px solid rgba(148, 163, 184, 0.2);
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}

.chat-input {
    flex: 1;
    padding: 0.75rem;
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid rgba(148, 163, 184, 0.3);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.95rem;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    transition: border-color 0.2s;
}

.chat-input:focus {
    outline: none;
    border-color: var(--primary);
}

.chat-send-btn {
    padding: 0.75rem 1.25rem;
    background: var(--primary);
    border: none;
    border-radius: 8px;
    color: white;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s;
}

.chat-send-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.chat-send-btn:active {
    transform: translateY(0);
}

.send-icon {
    font-size: 1.1rem;
}

/* Chat Footer */
.chat-footer {
    padding: 0.5rem 1rem;
    background: rgba(51, 65, 85, 0.6);
    border-top: 1px solid rgba(148, 163, 184, 0.2);
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.gpu-status {
    font-family: 'Courier New', monospace;
}

/* Toast Notifications */
.chat-toast {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    pointer-events: auto;
    transition: all 0.3s ease;
}

.chat-toast:hover {
    transform: translateX(-4px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.4);
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .ai-chat-widget {
        bottom: 1rem;
        right: 1rem;
    }

    .chat-panel {
        width: calc(100vw - 2rem);
        max-width: 420px;
        height: 500px;
    }

    .chat-toggle-btn {
        padding: 0.75rem 1.25rem;
        font-size: 0.9rem;
    }

    .chat-label {
        display: none;
    }

    .chat-icon {
        font-size: 1.8rem;
    }

    .chat-panel.expanded {
        width: 95vw !important;
        height: 90vh !important;
    }
    
    .chat-toast {
        right: 10px;
        left: 10px;
        max-width: calc(100vw - 20px);
    }
}

/* Feedback Section */
/* Segments Feedback Section */
.final-video-section {
    margin-bottom: 20px;
}

.segments-feedback-section {
    margin: 20px 0;
    padding: 16px;
    background: var(--bg);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.segments-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.segments-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text);
}

.segments-header .hint {
    flex: 1;
    margin: 0 12px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.segments-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
    margin-top: 16px;
}

.segment-card {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    transition: all 0.2s;
}

.segment-card.flagged {
    border-color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

.segment-card.approved {
    border-color: #22c55e;
    background: rgba(34, 197, 94, 0.1);
}

.segment-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.segment-title {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text);
}

.segment-feedback-btns {
    display: flex;
    gap: 4px;
}

.feedback-btn {
    padding: 4px 8px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1.2rem;
}

.feedback-btn:hover {
    transform: scale(1.1);
}

.feedback-btn.thumbs-up {
    color: #94a3b8;
}

.feedback-btn.thumbs-up.active {
    color: #22c55e;
    background: rgba(34, 197, 94, 0.2);
    border-color: #22c55e;
}

.feedback-btn.thumbs-down {
    color: #94a3b8;
}

.feedback-btn.thumbs-down.active {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.2);
    border-color: #ef4444;
}

.segment-video-container {
    width: 100%;
    margin-bottom: 8px;
    border-radius: 4px;
    overflow: hidden;
}

.segment-video-container video {
    width: 100%;
    height: auto;
    display: block;
}

.segment-description {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    padding: 6px;
    background: var(--bg-darker);
    border-radius: 4px;
    font-style: italic;
}

.segment-dialogue {
    font-size: 0.75rem;
    color: #a78bfa;
    margin-bottom: 8px;
    padding: 4px 6px;
    background: rgba(167, 139, 250, 0.1);
    border-left: 2px solid #7c3aed;
    border-radius: 2px;
}

.segment-feedback-comment {
    margin-top: 8px;
    display: none;
}

.segment-feedback-comment.visible {
    display: block;
}

.segment-feedback-comment textarea {
    width: 100%;
    padding: 8px;
    background: var(--bg-darker);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-size: 0.8rem;
    resize: vertical;
    min-height: 60px;
}

.segment-feedback-comment button {
    margin-top: 6px;
    padding: 4px 12px;
    font-size: 0.8rem;
}

.feedback-label {
    display: block;
    font-size: 0.75rem;
    color: var(--primary);
    margin-bottom: 6px;
    font-weight: 500;
}

.btn-feedback-save {
    background: var(--primary) !important;
    color: white !important;
    border: none !important;
}

.segment-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.segment-expand-btn {
    background: rgba(168, 85, 247, 0.2);
    border: 1px solid var(--primary);
    color: var(--primary);
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.segment-expand-btn:hover {
    background: var(--primary);
    color: white;
}

.segment-video-container {
    position: relative;
    cursor: pointer;
    border-radius: 6px;
    overflow: hidden;
    margin: 8px 0;
}

.segment-video-container video {
    width: 100%;
    height: 140px;
    object-fit: cover;
    background: #000;
}

.segment-play-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 16px;
    transition: opacity 0.2s;
    pointer-events: none;
}

.segment-video-container:hover .segment-play-overlay {
    opacity: 0.8;
}

.segment-info {
    padding: 4px 0;
}

/* Segment Lightbox */
.segment-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.segment-lightbox-content {
    background: var(--bg-card);
    border-radius: 12px;
    max-width: 900px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}

.segment-lightbox-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.segment-lightbox-header h3 {
    margin: 0;
    font-size: 1.2rem;
}

.lightbox-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    padding: 4px 8px;
    transition: color 0.2s;
}

.lightbox-close:hover {
    color: var(--text);
}

.segment-lightbox-content video {
    width: 100%;
    max-height: 50vh;
    background: #000;
}

.segment-lightbox-info {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.segment-lightbox-info .segment-description {
    font-size: 0.95rem;
    color: var(--text);
    margin-bottom: 8px;
}

.segment-lightbox-info .segment-dialogue {
    font-style: italic;
    color: var(--text-muted);
}

.segment-lightbox-feedback {
    padding: 16px 20px;
}

.segment-lightbox-feedback h4 {
    margin: 0 0 12px 0;
    font-size: 1rem;
    color: var(--primary);
}

.feedback-btns-large {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.feedback-btn-lg {
    flex: 1;
    padding: 12px 20px;
    border: 2px solid var(--border);
    background: var(--bg-input);
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text);
}

.feedback-btn-lg.thumbs-up:hover,
.feedback-btn-lg.thumbs-up.active {
    border-color: #22c55e;
    background: rgba(34, 197, 94, 0.2);
}

.feedback-btn-lg.thumbs-down:hover,
.feedback-btn-lg.thumbs-down.active {
    border-color: #ef4444;
    background: rgba(239, 68, 68, 0.2);
}

.segment-lightbox-feedback textarea {
    width: 100%;
    padding: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.9rem;
    resize: vertical;
    min-height: 80px;
    margin-bottom: 12px;
}

.segment-lightbox-feedback .btn-primary {
    width: 100%;
}

.feedback-section {
    margin-top: 20px;
    padding: 16px;
    background: var(--bg);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.feedback-section h3 {
    font-size: 14px;
    margin-bottom: 8px;
    color: var(--text);
}

.feedback-section .hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.feedback-section textarea {
    width: 100%;
    padding: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 14px;
    resize: vertical;
    min-height: 80px;
}

.feedback-section textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.feedback-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
}

.feedback-status {
    font-size: 13px;
    color: var(--success);
}

.feedback-status.error {
    color: var(--error);
}

/* =============================================================================
   VIDEO-LEVEL FEEDBACK (Thumbs up/down on result screen)
   ============================================================================= */

.video-feedback-section {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    margin-top: 8px;
}

.video-feedback-section[hidden] {
    display: none !important;
}

.video-feedback-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.video-feedback-label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.video-feedback-btns {
    display: flex;
    gap: 8px;
}

.video-fb-btn {
    padding: 6px 14px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--text-muted);
}

.video-fb-btn:hover {
    transform: scale(1.05);
}

.video-fb-btn.thumbs-up.active {
    color: #22c55e;
    background: rgba(34, 197, 94, 0.15);
    border-color: #22c55e;
}

.video-fb-btn.thumbs-down.active {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.15);
    border-color: #ef4444;
}

.video-feedback-comment[hidden] {
    display: none !important;
}

.video-feedback-comment {
    margin-top: 8px;
}

.video-feedback-comment textarea {
    width: 100%;
    padding: 8px 10px;
    background: var(--bg-input, #1a1f2e);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.8rem;
    resize: vertical;
    min-height: 50px;
    margin-bottom: 6px;
}

.video-feedback-comment textarea:focus {
    outline: none;
    border-color: var(--primary, #6c5ce7);
}

.video-feedback-comment .btn-small {
    font-size: 0.78rem;
}

.video-feedback-status {
    font-size: 0.75rem;
    margin-top: 4px;
    min-height: 1.2em;
    color: var(--success, #22c55e);
}

.video-feedback-status.error {
    color: var(--error, #ef4444);
}

/* =============================================================================
   FOLDER BROWSE ICON BUTTON
   ============================================================================= */

.btn-icon {
    padding: 0.5rem 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
}

.btn-icon:hover {
    background: var(--bg-hover);
    border-color: var(--primary);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.btn-icon:active {
    transform: translateY(0);
    box-shadow: none;
}

/* =============================================================================
   FILE BROWSER MODAL OVERLAY
   ============================================================================= */

#fileBrowserModal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    animation: fadeIn 0.3s ease;
}

.file-browser-content {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    width: 90%;
    max-width: 700px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    animation: slideUpFade 0.3s ease;
}

@keyframes slideUpFade {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    color: var(--text);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.modal-close:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.file-browser-body {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Browse Mode Tabs */
.browse-mode-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    border-bottom: 2px solid var(--border);
}

.browse-tab {
    flex: 1;
    padding: 0.75rem 1rem;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    color: var(--text-muted);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.browse-tab:hover {
    color: var(--text);
    background: var(--bg-hover);
}

.browse-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: rgba(168, 85, 247, 0.1);
}

.browse-mode-content {
    animation: fadeIn 0.3s ease;
}

.file-browser-path {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.file-browser-path input {
    flex: 1;
    padding: 0.5rem 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
}

.file-browser-list {
    min-height: 300px;
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-secondary);
    padding: 0.5rem;
}

.file-browser-list::-webkit-scrollbar {
    width: 8px;
}

.file-browser-list::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
}

.file-browser-list::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 4px;
}

.file-browser-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    margin-bottom: 0.25rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.file-browser-item:hover {
    background: var(--bg-hover);
    border-color: var(--primary);
    transform: translateX(4px);
}

.file-browser-item.folder {
    color: var(--text);
}

.file-browser-item .item-icon {
    font-size: 1.3rem;
    line-height: 1;
}

.file-browser-item .item-name {
    flex: 1;
    font-size: 0.95rem;
}

.file-browser-empty,
.file-browser-error {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.file-browser-error {
    color: var(--danger);
}

.loading-spinner {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
}

.modal-footer .btn {
    padding: 0.6rem 1.25rem;
    border-radius: 6px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.modal-footer .btn-secondary {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
}

.modal-footer .btn-secondary:hover {
    background: var(--bg-hover);
}

.modal-footer .btn-primary {
    background: var(--primary);
    border: 1px solid var(--primary);
    color: white;
}

.modal-footer .btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(168, 85, 247, 0.4);
}

/* Local Network Path Input UI */
.local-browse-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    text-align: center;
    min-height: 300px;
}

.local-browse-info .info-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.8;
}

.local-browse-info h4 {
    margin: 0 0 0.75rem 0;
    font-size: 1.25rem;
    color: var(--text);
}

.local-browse-info p {
    margin: 0 0 2rem 0;
    color: var(--text-muted);
    font-size: 0.95rem;
    max-width: 500px;
    line-height: 1.5;
}

/* Local Folder Picker */
.local-folder-picker {
    width: 100%;
    max-width: 600px;
    margin-bottom: 2rem;
}

.btn-browse-local {
    width: 100%;
    font-size: 1.1rem;
    padding: 1rem 1.5rem;
    margin-bottom: 1.5rem;
}

.constructed-path {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.5rem;
    margin-top: 1rem;
    text-align: left;
}

.constructed-path h5 {
    margin: 0 0 1rem 0;
    font-size: 1rem;
    color: var(--text);
    font-weight: 600;
}

.path-construction-info {
    margin-bottom: 1rem;
}

.construction-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.75rem;
    padding: 0.5rem;
    background: var(--bg-card);
    border-radius: 6px;
}

.construction-label {
    font-weight: 600;
    color: var(--text-muted);
    min-width: 100px;
    font-size: 0.9rem;
}

.construction-value {
    color: var(--text);
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
}

.share-name-input {
    flex: 1;
    background: var(--bg-darker);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.5rem;
    color: var(--text);
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
}

.share-name-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(168, 85, 247, 0.2);
}

.final-path-display {
    background: var(--bg-darker);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 1rem;
    margin-bottom: 1rem;
}

.final-path-display strong {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.final-path-display code {
    display: block;
    background: var(--bg-card);
    padding: 0.75rem;
    border-radius: 4px;
    color: var(--success);
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    word-break: break-all;
}

.divider-text {
    display: flex;
    align-items: center;
    text-align: center;
    margin: 2rem 0;
    width: 100%;
    max-width: 600px;
}

.divider-text::before,
.divider-text::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--border);
}

.divider-text span {
    padding: 0 1rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
}

.network-path-input-group {
    width: 100%;
    max-width: 550px;
    text-align: left;
}

.network-path-input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--text);
}

.network-path-input {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border: 2px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-family: 'Courier New', monospace;
    font-size: 0.95rem;
    margin-bottom: 1.5rem;
    transition: border-color 0.2s;
}

.network-path-input:focus {
    outline: none;
    border-color: var(--primary);
}

.path-examples {
    background: rgba(168, 85, 247, 0.1);
    border: 1px solid var(--primary);
    border-radius: 6px;
    padding: 1rem;
    margin-bottom: 1.5rem;
    text-align: left;
}

.path-examples strong {
    display: block;
    margin-bottom: 0.75rem;
    color: var(--primary);
}

.example-item {
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: var(--text);
}

.example-item code {
    background: var(--bg);
    padding: 0.25rem 0.5rem;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    color: var(--secondary);
}

.btn-large {
    width: 100%;
    padding: 1rem 2rem;
    font-size: 1.1rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .file-browser-content {
        width: 95%;
        max-height: 90vh;
    }
    
    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 1rem;
    }
    
    .file-browser-list {
        min-height: 250px;
        max-height: 300px;
    }
    
    .browse-tab {
        font-size: 0.85rem;
        padding: 0.6rem 0.75rem;
    }
    
    .browse-tab span {
        font-size: 0.85rem;
    }
    
    .local-browse-info {
        padding: 2rem 1rem;
        min-height: 250px;
    }
    
    .local-browse-info .info-icon {
        font-size: 3rem;
    }
    
    .local-browse-info h4 {
        font-size: 1.1rem;
    }
}

/* ===============================================
   AUTH MODAL STYLES
   =============================================== */

.auth-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 15, 30, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.auth-modal-content {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--tc-glass-border-hover, rgba(148, 163, 184, 0.15));
    animation: modalIn 0.3s ease-out;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

.auth-logo {
    text-align: center;
    margin-bottom: 32px;
}

.auth-logo h1 {
    font-size: 2.5rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.auth-logo p {
    color: var(--text-muted);
    font-size: 0.95rem;
}

.auth-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    background: var(--bg-input);
    padding: 4px;
    border-radius: 8px;
}

.auth-tab-btn {
    flex: 1;
    padding: 12px 16px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 1rem;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.auth-tab-btn:hover {
    color: var(--text);
}

.auth-tab-btn.active {
    background: var(--primary);
    color: white;
}

.auth-form {
    display: none;
}

.auth-form.active {
    display: block;
}

.auth-form .form-group {
    margin-bottom: 20px;
}

.auth-form label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text);
}

.auth-form input {
    width: 100%;
    padding: var(--tc-space-3) var(--tc-space-4);
    background: var(--tc-glass-bg-input);
    border: var(--tc-glass-border);
    border-radius: var(--tc-radius-md);
    color: var(--tc-text-primary);
    font-size: var(--tc-font-size-md);
    font-family: var(--tc-font-sans);
    transition: all var(--tc-transition-fast);
}

.auth-form input:focus {
    outline: none;
    border: var(--tc-glass-border-focus);
    box-shadow: var(--tc-focus-ring);
}

.auth-form input::placeholder {
    color: var(--tc-text-muted);
}

/* Password visibility toggle */
.password-wrapper {
    position: relative;
}

.password-wrapper input {
    padding-right: 44px;
}

.password-toggle {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: var(--text-muted);
    font-size: 18px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: color 0.15s ease;
}

.password-toggle:hover {
    color: var(--text);
}

/* Side-by-side name fields */
.name-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
}

.name-row .form-group {
    margin-bottom: 0;
}

.auth-error {
    color: var(--error);
    font-size: 0.9rem;
    margin-bottom: 16px;
    min-height: 1.4em;
}

.auth-submit-btn {
    width: 100%;
    padding: 14px 24px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.auth-submit-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(168, 85, 247, 0.4);
}

.auth-submit-btn:active {
    transform: translateY(0);
}

.auth-submit-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.auth-footer {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.auth-footer strong {
    color: var(--secondary);
}

/* Header with user profile */
.header-main {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
}

.header-left {
    text-align: left;
}

.header-left h1 {
    margin-bottom: 4px;
}

.header-right.user-profile {
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--bg-card);
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.user-email {
    color: var(--text);
    font-weight: 500;
}

.user-credits {
    color: var(--secondary);
    font-weight: 600;
    padding: 4px 12px;
    background: rgba(16, 185, 129, 0.15);
    border-radius: 16px;
}

.btn-logout {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s ease;
}

.btn-logout:hover {
    background: var(--error);
    border-color: var(--error);
    color: white;
}

/* Responsive auth */
@media (max-width: 480px) {
    .auth-modal-content {
        margin: 16px;
        padding: 24px;
    }

    .auth-logo h1 {
        font-size: 2rem;
    }

    .header-main {
        flex-direction: column;
        text-align: center;
    }

    .header-left {
        text-align: center;
    }

    .header-right.user-profile {
        flex-wrap: wrap;
        justify-content: center;
    }
}

/* Credit Estimate Section */
.credit-estimate-section {
    background: rgba(168, 85, 247, 0.1);
    border: 1px solid rgba(168, 85, 247, 0.3);
    border-radius: 12px;
    padding: 16px;
    margin: 20px 0;
}

.credit-estimate-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    font-weight: 600;
    color: var(--primary);
}

.credit-icon {
    font-size: 1.2rem;
}

.credit-title {
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.credit-breakdown {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.credit-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 6px;
    font-size: 0.9rem;
}

.credit-label {
    color: var(--text-muted);
}

.credit-value {
    font-weight: 600;
    color: var(--text);
}

.credit-row.credit-total {
    background: rgba(168, 85, 247, 0.2);
    border: 1px solid rgba(168, 85, 247, 0.3);
    margin-top: 8px;
    padding: 8px 12px;
}

.credit-total-value {
    font-size: 1.1rem;
    color: var(--primary);
}

.credit-usd {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 0.85rem;
    color: var(--text-muted);
}

.credit-balance {
    color: var(--secondary);
    font-weight: 500;
}

.credit-insufficient {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: var(--error);
    padding: 12px;
    border-radius: 8px;
    margin-top: 12px;
    text-align: center;
    font-size: 0.9rem;
}

.credit-insufficient a {
    color: var(--primary);
    font-weight: 600;
    text-decoration: underline;
}

.credit-row-lipsync {
    background: rgba(245, 158, 11, 0.1);
    border: 1px dashed rgba(245, 158, 11, 0.3);
}

.credit-row-lipsync .credit-label {
    color: var(--warning);
}

@media (max-width: 480px) {
    .credit-estimate-section {
        padding: 12px;
    }

    .credit-row {
        font-size: 0.85rem;
    }

    .credit-usd {
        flex-direction: column;
        gap: 4px;
        text-align: center;
    }
}

/* ============================================
   PAGE SECTIONS & NAVIGATION
   ============================================ */

.page-section {
    display: none;
}

/* Higher specificity ensures inactive sections stay hidden even if other classes set display */
.page-section:not(.active) {
    display: none;
}

.page-section.active {
    display: block;
    animation: pageReveal 0.25s ease-out;
}

@keyframes pageReveal {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Code/Dev Cockpit page: fill height so file tree can scroll */
#page-code.page-section.active {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: pageReveal 0.25s ease-out;
}

/* Book page: fill height so 3-pane layout expands to bottom */
#page-book.page-section.active {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: pageReveal 0.25s ease-out;
}

/* Train page: fill height, no padding, dark background */
#page-train.page-section.active {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0 !important;
    animation: pageReveal 0.25s ease-out;
}

/* Code page: remove creator-area padding/max-width so editor fills full width */
.creator-area:has(#page-code.active) {
    padding: 0;
    max-width: 100%;
    margin: 0;
    width: 100%;
    overflow: hidden;
}

/* Train page: same treatment as Code page */
.creator-area:has(#page-train.active) {
    padding: 0;
    max-width: 100%;
    margin: 0;
    width: 100%;
    overflow: hidden;
}

/* Notebook/Colab page: full-bleed like Code page */
.creator-area:has(#page-notebook.active) {
    padding: 0;
    max-width: 100%;
    margin: 0;
    width: 100%;
    overflow: hidden;
}

#page-notebook.page-section.active {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

@media (max-width: 768px) {
    .creator-area:has(#page-code.active) {
        padding: 0;
    }
    .creator-area:has(#page-train.active) {
        padding: 0;
    }
    .creator-area:has(#page-notebook.active) {
        padding: 0;
    }
}

/* Mode spacer */
.mode-spacer {
    flex: 1;
}

/* Enhance Button */
.btn-enhance {
    background: linear-gradient(135deg, #8b5cf6, #a855f7);
    border: none;
    border-radius: 8px;
    padding: 8px 16px;
    color: white;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.btn-enhance:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(168, 85, 247, 0.3);
}

.enhance-icon {
    font-size: 1rem;
}

/* ============================================
   AI VOICEOVER PAGE STYLES
   ============================================ */

.voiceover-hero {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 60px 40px;
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.1), rgba(139, 92, 246, 0.05));
    border-radius: 24px;
    margin-bottom: 40px;
}

.hero-content {
    max-width: 550px;
}

.hero-title {
    font-size: 2.5rem;
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 16px;
    color: var(--text);
}

.hero-subtitle {
    font-size: 1.1rem;
    color: var(--text-muted);
    line-height: 1.6;
    margin-bottom: 24px;
}

.btn-hero {
    background: var(--accent);
    border: none;
    border-radius: 8px;
    padding: 14px 32px;
    color: #000;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-hero:hover {
    background: #d4a00a;
    transform: translateY(-2px);
}

.btn-hero-outline {
    background: transparent;
    border: 2px solid var(--text-muted);
    border-radius: 8px;
    padding: 12px 28px;
    color: var(--text);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    margin-left: 12px;
}

.btn-hero-outline:hover {
    border-color: var(--text);
    background: rgba(255,255,255,0.05);
}

.hero-visual {
    display: flex;
    align-items: center;
    justify-content: center;
}

.voice-wave {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 80px;
}

.voice-wave span {
    width: 8px;
    background: linear-gradient(to top, var(--primary), var(--accent));
    border-radius: 4px;
    animation: voiceWave 1.2s ease-in-out infinite;
}

.voice-wave span:nth-child(1) { height: 30%; animation-delay: 0s; }
.voice-wave span:nth-child(2) { height: 60%; animation-delay: 0.1s; }
.voice-wave span:nth-child(3) { height: 100%; animation-delay: 0.2s; }
.voice-wave span:nth-child(4) { height: 60%; animation-delay: 0.3s; }
.voice-wave span:nth-child(5) { height: 30%; animation-delay: 0.4s; }

@keyframes voiceWave {
    0%, 100% { transform: scaleY(0.5); }
    50% { transform: scaleY(1); }
}

/* Voice Type Tabs */
.voice-type-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 40px;
    flex-wrap: wrap;
}

.voice-type-tab {
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    padding: 12px 24px;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: all 0.2s;
}

.voice-type-tab:hover {
    background: rgba(255,255,255,0.05);
    color: var(--text);
}

.voice-type-tab.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* Voice Explorer */
.voice-explorer {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 32px;
    border: 1px solid rgba(255,255,255,0.06);
}

.section-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 24px;
}

.voice-filters {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
    align-items: center;
}

.filter-item {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.filter-select {
    background: var(--bg-input);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    padding: 10px 14px;
    color: var(--text);
    font-size: 0.9rem;
    cursor: pointer;
    min-width: 140px;
}

.filter-spacer {
    flex: 1;
}

.btn-clone-voice {
    background: var(--bg-input);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 8px;
    padding: 10px 20px;
    color: var(--text);
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.btn-clone-voice:hover {
    background: rgba(255,255,255,0.1);
    border-color: var(--primary);
}

.badge-new {
    background: var(--accent);
    color: #000;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
}

/* Voice Cards */
.voice-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}

.voice-card {
    background: var(--tc-glass-bg);
    backdrop-filter: blur(var(--tc-glass-blur-light));
    -webkit-backdrop-filter: blur(var(--tc-glass-blur-light));
    border: var(--tc-glass-border);
    border-width: 2px;
    border-radius: var(--tc-radius-lg);
    padding: var(--tc-space-4);
    display: flex;
    align-items: center;
    gap: var(--tc-space-3);
    cursor: pointer;
    transition: all var(--tc-transition-fast);
}

.voice-card:hover {
    background: var(--tc-glass-bg-hover);
    border-color: rgba(148, 163, 184, 0.15);
    transform: translateX(2px);
}

.voice-card.selected {
    border-color: var(--tc-primary);
    background: var(--tc-primary-surface);
    box-shadow: 0 0 12px var(--tc-primary-glow);
}

.voice-avatar {
    width: 48px;
    height: 48px;
    background: rgba(168, 85, 247, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.voice-info {
    flex: 1;
    min-width: 0;
}

.voice-info h4 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.voice-info p {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.voice-tags {
    font-size: 0.7rem;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    opacity: 0.7;
}

.voice-selected {
    color: var(--primary);
    font-size: 0.8rem;
    font-weight: 600;
}

.btn-preview {
    width: 40px;
    height: 40px;
    background: rgba(255,255,255,0.1);
    border: none;
    border-radius: 50%;
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-preview:hover {
    background: var(--primary);
    color: white;
}

/* ============================================
   MUSIC PAGE STYLES
   ============================================ */

.music-hero {
    padding: 60px 40px;
    background: linear-gradient(135deg, rgba(234, 179, 8, 0.1), rgba(168, 85, 247, 0.05));
    border-radius: 24px;
    margin-bottom: 32px;
    text-align: center;
}

.music-hero .hero-content {
    max-width: 700px;
    margin: 0 auto;
}

.hero-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 24px;
}

/* Brand Logos */
.brand-logos {
    display: flex;
    align-items: center;
    gap: 32px;
    padding: 24px 0;
    margin-bottom: 32px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.brand-logos .logos {
    display: flex;
    gap: 32px;
}

.brand {
    font-weight: 600;
    opacity: 0.5;
    font-size: 1.1rem;
}

/* Music Filters */
.music-filters {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    flex-wrap: wrap;
    align-items: center;
    padding: 16px;
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.06);
}

.filter-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    font-size: 0.9rem;
    cursor: pointer;
}

.filter-toggle input {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
}

.filter-select-small {
    background: var(--bg-input);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    padding: 8px 12px;
    color: var(--text);
    font-size: 0.85rem;
    cursor: pointer;
}

.btn-filters {
    background: var(--bg-input);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    padding: 8px 16px;
    color: var(--text);
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-filters:hover {
    background: rgba(255,255,255,0.1);
}

/* Track List */
.track-list {
    background: var(--bg-card);
    border-radius: 16px;
    border: 1px solid rgba(255,255,255,0.06);
    overflow: hidden;
    margin-bottom: 100px; /* Space for audio player bar */
}

.track-item {
    display: flex;
    align-items: center;
    gap: var(--tc-space-4);
    padding: var(--tc-space-3) var(--tc-space-4);
    border-bottom: var(--tc-glass-border-subtle);
    transition: all var(--tc-transition-fast);
}

.track-item:hover {
    background: var(--tc-glass-bg);
    transform: translateX(2px);
}

.track-item:last-child {
    border-bottom: none;
}

.track-item:hover {
    background: rgba(255,255,255,0.03);
}

.track-play {
    width: 40px;
    height: 40px;
    background: var(--bg-input);
    border: none;
    border-radius: 50%;
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    transition: all 0.2s;
    flex-shrink: 0;
}

.track-play:hover {
    background: var(--primary);
    color: white;
}

.track-thumb {
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.track-info {
    flex: 1;
    min-width: 150px;
}

.track-info h4 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.track-artist {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.track-genre {
    font-size: 0.8rem;
    color: var(--text-muted);
    min-width: 120px;
}

.track-duration {
    font-size: 0.85rem;
    color: var(--text-muted);
    min-width: 50px;
    text-align: right;
}

.track-waveform {
    flex: 1;
    max-width: 200px;
    height: 32px;
    background: var(--bg-input);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.waveform-bars {
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, 
        rgba(168, 85, 247, 0.3) 0%,
        rgba(168, 85, 247, 0.5) 30%,
        rgba(168, 85, 247, 0.3) 100%
    );
}

.track-actions {
    display: flex;
    gap: 8px;
}

.track-actions button {
    width: 36px;
    height: 36px;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.track-actions button:hover {
    background: rgba(255,255,255,0.1);
    color: var(--text);
}

/* Audio Player Bar (Fixed Bottom) */
.audio-player-bar {
    position: fixed;
    bottom: 0;
    left: var(--sidebar-width);
    right: 0;
    background: var(--bg-darker);
    border-top: 1px solid rgba(255,255,255,0.1);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 24px;
    z-index: 90;
}

.player-track {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 200px;
}

.player-thumb {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.player-info {
    display: flex;
    flex-direction: column;
}

.player-title {
    font-weight: 600;
    font-size: 0.95rem;
}

.player-artist {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.player-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.player-controls button {
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: all 0.2s;
}

.player-controls .btn-play {
    width: 48px;
    height: 48px;
    background: var(--primary);
    border-radius: 50%;
    font-size: 1.2rem;
}

.player-controls .btn-play:hover {
    background: var(--primary-dark);
}

.player-progress {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 500px;
}

.player-progress span {
    font-size: 0.8rem;
    color: var(--text-muted);
    min-width: 40px;
}

.progress-track {
    flex: 1;
    height: 4px;
    background: var(--bg-input);
    border-radius: 2px;
    overflow: hidden;
    cursor: pointer;
}

.progress-track .progress-fill {
    width: 40%;
    height: 100%;
    background: var(--primary);
}

.player-volume {
    display: flex;
    align-items: center;
    gap: 8px;
}

.player-volume button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
}

.player-volume input[type="range"] {
    width: 80px;
    height: 4px;
    accent-color: var(--primary);
}

/* ============================================
   ASSETS PAGE STYLES
   ============================================ */

.assets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 24px;
}

.asset-category {
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 16px;
    padding: 32px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.asset-category:hover {
    background: rgba(255,255,255,0.05);
    border-color: rgba(255,255,255,0.1);
    transform: translateY(-4px);
}

.asset-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.asset-category h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.asset-category p {
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* ============================================
   RESPONSIVE - PAGE SECTIONS
   ============================================ */

@media (max-width: 768px) {
    .voiceover-hero,
    .music-hero {
        padding: 40px 24px;
        flex-direction: column;
        text-align: center;
    }

    .hero-title {
        font-size: 1.75rem;
    }

    .hero-visual {
        margin-top: 32px;
    }

    .voice-type-tabs {
        justify-content: center;
    }

    .voice-cards {
        grid-template-columns: 1fr;
    }

    .track-waveform,
    .track-genre {
        display: none;
    }

    .audio-player-bar {
        left: 60px;
        flex-wrap: wrap;
        padding: 12px 16px;
    }

    .player-progress {
        order: 3;
        width: 100%;
        max-width: none;
    }

    .player-volume {
        display: none;
    }

    .assets-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .asset-category {
        padding: 20px;
    }

    .asset-icon {
        font-size: 2rem;
    }
}

/* ============================================
   HOME PAGE STYLES
   ============================================ */

.home-hero {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 60px 48px;
    background: linear-gradient(135deg,
        color-mix(in srgb, var(--primary) 15%, transparent),
        color-mix(in srgb, var(--accent, #eab308) 8%, transparent));
    border-radius: 24px;
    margin-bottom: 48px;
    position: relative;
    overflow: hidden;
}

.home-hero::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -20%;
    width: 60%;
    height: 200%;
    background: radial-gradient(ellipse, color-mix(in srgb, var(--primary) 10%, transparent) 0%, transparent 70%);
    pointer-events: none;
}

.home-hero .hero-content {
    max-width: 550px;
    position: relative;
    z-index: 1;
}

.home-hero .hero-title {
    font-size: 3rem;
    font-weight: 800;
    line-height: 1.15;
    margin-bottom: 20px;
    color: var(--text);
}

.home-hero .hero-subtitle {
    font-size: 1.2rem;
    color: var(--text-muted);
    line-height: 1.7;
    margin-bottom: 32px;
}

.hero-image-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    position: relative;
    z-index: 1;
}

.hero-preview {
    width: 120px;
    height: 120px;
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    transition: all 0.3s;
}

.hero-preview:hover {
    transform: scale(1.05);
    border-color: var(--primary);
}

.hero-preview.video {
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.2), rgba(168, 85, 247, 0.05));
}

.hero-preview.image {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.2), rgba(16, 185, 129, 0.05));
}

.hero-preview.voice {
    background: linear-gradient(135deg, rgba(234, 179, 8, 0.2), rgba(234, 179, 8, 0.05));
    grid-column: span 2;
    width: 100%;
}

/* Features Section */
.home-features {
    margin-bottom: 48px;
}

.home-features .section-title {
    text-align: center;
    margin-bottom: 32px;
}

.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 24px;
}

.feature-card {
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 16px;
    padding: 28px;
    cursor: pointer;
    transition: all 0.3s;
}

.feature-card:hover {
    background: rgba(255,255,255,0.04);
    border-color: rgba(255,255,255,0.12);
    transform: translateY(-4px);
}

.feature-icon {
    font-size: 2.5rem;
    margin-bottom: 16px;
}

.feature-card h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 12px;
}

.feature-card p {
    font-size: 0.95rem;
    color: var(--text-muted);
    line-height: 1.6;
    margin-bottom: 16px;
}

.feature-link {
    color: var(--primary);
    font-size: 0.9rem;
    font-weight: 600;
    transition: color 0.2s;
}

.feature-card:hover .feature-link {
    color: var(--accent);
}

/* Credit Cost Badges */
.credit-cost-badge {
    display: inline-block;
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.2) 0%, rgba(139, 92, 246, 0.2) 100%);
    color: #a78bfa;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 12px;
    border: 1px solid rgba(167, 139, 250, 0.3);
}

.credit-cost-badge.free-badge {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.2) 0%, rgba(5, 150, 105, 0.2) 100%);
    color: #34d399;
    border-color: rgba(52, 211, 153, 0.3);
}

.section-credit-cost {
    display: inline-flex;
    align-items: center;
    background: rgba(168, 85, 247, 0.15);
    color: #a78bfa;
    padding: 8px 16px;
    border-radius: 25px;
    font-size: 0.9rem;
    font-weight: 500;
    border: 1px solid rgba(167, 139, 250, 0.25);
}

.section-credit-cost.free-badge {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
    border-color: rgba(52, 211, 153, 0.25);
}

.page-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 20px;
}

.mode-credit-cost {
    display: inline-block;
    background: rgba(168, 85, 247, 0.1);
    color: #818cf8;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-left: 8px;
}

/* Stats Section */
.home-stats {
    display: flex;
    justify-content: center;
    gap: 48px;
    padding: 40px;
    background: var(--bg-card);
    border-radius: 16px;
    border: 1px solid rgba(255,255,255,0.06);
}

.stat-item {
    text-align: center;
}

.stat-number {
    display: block;
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--accent);
    margin-bottom: 8px;
}

.stat-label {
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* Responsive Home Page */
@media (max-width: 900px) {
    .home-hero {
        flex-direction: column;
        text-align: center;
        padding: 40px 24px;
    }

    .home-hero .hero-title {
        font-size: 2rem;
    }

    .home-hero .hero-buttons {
        justify-content: center;
    }

    .hero-image-grid {
        margin-top: 32px;
    }

    .home-stats {
        flex-wrap: wrap;
        gap: 32px;
        padding: 32px 24px;
    }

    .stat-item {
        flex: 1 1 40%;
    }
}

@media (max-width: 480px) {
    .hero-preview {
        width: 80px;
        height: 80px;
        font-size: 2rem;
    }

    .stat-number {
        font-size: 1.75rem;
    }
}

/* Image Preview with Clear Button */
.upload-dropzone {
    position: relative;
}

.btn-clear-image {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 36px;
    height: 36px;
    background: #ef4444;
    border: 3px solid white;
    border-radius: 50%;
    color: white;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

.btn-clear-image:hover {
    background: #dc2626;
    transform: scale(1.15);
    box-shadow: 0 6px 16px rgba(0,0,0,0.6);
}

/* Prompt input with enhance button */
.prompt-input-wrapper {
    position: relative;
}

/* Prompt header with label and enhance button */
.prompt-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.prompt-header label {
    font-size: 0.9rem;
    color: var(--text-secondary, #94a3b8);
    font-weight: 500;
    white-space: nowrap;
}

.prompt-header .btn-enhance {
    padding: 4px 12px;
    font-size: 0.8rem;
    width: auto;
    margin: 0;
    flex-shrink: 0;
}

/* Mode tabs clickable */
.mode-tab {
    cursor: pointer;
}

/* ============================================
   PROJECTS LIST STYLES
   ============================================ */

.projects-list {
    max-height: 200px;
    overflow-y: auto;
    padding: 8px 0;
}

.projects-empty {
    padding: 12px 14px;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-style: italic;
}

.project-category-label {
    padding: 6px 14px 2px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    opacity: 0.7;
}

.project-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: 6px;
    margin: 2px 8px;
}

.project-item:hover {
    background: rgba(255,255,255,0.05);
}

.project-item.active {
    background: rgba(168, 85, 247, 0.15);
    border-left: 3px solid var(--primary);
}

.project-icon {
    font-size: 1rem;
    flex-shrink: 0;
}

.project-name {
    flex: 1;
    font-size: 0.85rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.project-item.active .project-name {
    color: var(--text);
}

.project-delete {
    opacity: 0;
    background: none;
    border: none;
    color: var(--error);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 2px 6px;
    transition: opacity 0.2s;
}

.project-item:hover .project-delete {
    opacity: 0.6;
}

.project-delete:hover {
    opacity: 1 !important;
}

.project-expand {
    font-size: 0.6rem;
    color: var(--text-muted);
    cursor: pointer;
    width: 12px;
    flex-shrink: 0;
    text-align: center;
    opacity: 0.6;
    transition: opacity 0.2s;
}
.project-expand:hover {
    opacity: 1;
}
.project-expand.hidden {
    visibility: hidden;
}

.project-children {
    padding-left: 22px;
    margin: 0 8px;
}

.project-child-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 10px;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.2s;
}
.project-child-item:hover {
    background: rgba(255,255,255,0.05);
}

.project-child-icon {
    font-size: 0.8rem;
    flex-shrink: 0;
}

.project-child-name {
    font-size: 0.78rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================
   MODAL STYLES (Generic)
   ============================================ */

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--tc-z-modal);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    animation: backdropFadeIn 0.2s ease;
}

.modal-content {
    background: var(--tc-glass-bg-active);
    backdrop-filter: blur(var(--tc-glass-blur-heavy));
    -webkit-backdrop-filter: blur(var(--tc-glass-blur-heavy));
    border: var(--tc-glass-border-hover);
    border-radius: var(--tc-radius-xl);
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--tc-shadow-2xl);
    animation: modalSlideUp 0.25s ease;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--tc-space-5) var(--tc-space-6);
    border-bottom: var(--tc-glass-border-subtle);
}

.modal-header h3 {
    font-size: var(--tc-font-size-xl);
    font-weight: var(--tc-font-weight-semi);
    color: var(--tc-text-primary);
}

.modal-close {
    background: none;
    border: none;
    color: var(--tc-text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: var(--tc-space-1) var(--tc-space-2);
    line-height: 1;
    transition: color var(--tc-transition-fast);
}

.modal-close:hover {
    color: var(--tc-text-primary);
}

.modal-body {
    padding: var(--tc-space-6);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--tc-space-3);
    padding: 16px 24px;
    border-top: 1px solid rgba(255,255,255,0.06);
}

/* Form Elements for Modals — Glass */
.form-group {
    margin-bottom: var(--tc-space-5);
}

.form-group label {
    display: block;
    font-size: var(--tc-font-size-base);
    font-weight: var(--tc-font-weight-medium);
    margin-bottom: var(--tc-space-2);
    color: var(--tc-text-secondary);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    background: var(--tc-glass-bg-input);
    backdrop-filter: blur(var(--tc-glass-blur-light));
    -webkit-backdrop-filter: blur(var(--tc-glass-blur-light));
    border: var(--tc-glass-border);
    border-radius: var(--tc-radius-md);
    padding: var(--tc-space-3) var(--tc-space-4);
    color: var(--tc-text-primary);
    font-size: var(--tc-font-size-base);
    font-family: var(--tc-font-sans);
    transition: all var(--tc-transition-fast);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border: var(--tc-glass-border-focus);
    box-shadow: var(--tc-focus-ring);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.form-textarea {
    resize: vertical;
    min-height: 80px;
}

/* Button Styles — Glassmorphic */
.btn-primary {
    background: var(--tc-primary-gradient);
    border: none;
    border-radius: var(--tc-radius-pill);
    padding: var(--tc-space-3) var(--tc-space-6);
    color: #fff;
    font-size: var(--tc-font-size-base);
    font-weight: var(--tc-font-weight-semi);
    cursor: pointer;
    transition: all 200ms ease;
    box-shadow: 0 0 20px var(--tc-primary-glow);
}

.btn-primary:hover {
    transform: scale(1.02);
    box-shadow: 0 0 30px var(--tc-primary-glow-strong);
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-secondary {
    background: var(--tc-glass-bg-input);
    backdrop-filter: blur(var(--tc-glass-blur-light));
    -webkit-backdrop-filter: blur(var(--tc-glass-blur-light));
    border: var(--tc-glass-border);
    border-radius: var(--tc-radius-md);
    padding: var(--tc-space-3) var(--tc-space-6);
    color: var(--tc-text-primary);
    font-size: var(--tc-font-size-base);
    font-weight: var(--tc-font-weight-medium);
    cursor: pointer;
    transition: all var(--tc-transition-normal);
}

.btn-secondary:hover {
    background: var(--tc-glass-bg-hover);
    border-color: rgba(148, 163, 184, 0.2);
}

/* Radio Pill Styles — Glass */
.radio-pill {
    display: inline-flex;
    cursor: pointer;
    gap: var(--tc-space-2);
}

.radio-pill input[type="radio"] {
    display: none;
}

.radio-pill span {
    padding: var(--tc-space-2) var(--tc-space-4);
    background: var(--tc-glass-bg);
    border: var(--tc-glass-border);
    border-radius: var(--tc-radius-pill);
    font-size: var(--tc-font-size-sm);
    color: var(--tc-text-secondary);
    transition: all var(--tc-transition-fast);
}

.radio-pill input[type="radio"]:checked + span {
    background: var(--tc-primary-surface);
    border-color: var(--tc-primary);
    color: var(--tc-primary);
    box-shadow: 0 0 12px var(--tc-primary-glow);
}

.radio-pill span:hover {
    background: var(--tc-glass-bg-hover);
    border-color: rgba(148, 163, 184, 0.15);
}

.radio-pill input[type="radio"]:checked + span:hover {
    background: var(--tc-primary-surface);
    filter: brightness(1.1);
}

/* ============================================
   ARTLIST-STYLE IMPROVEMENTS
   ============================================ */

/* Sidebar favorites section */
.sidebar-favorites {
    padding: 8px;
    border-top: 1px solid rgba(255,255,255,0.06);
}

.favorites-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.85rem;
    transition: all 0.2s;
}

.favorites-item:hover {
    background: rgba(255,255,255,0.05);
    color: var(--text);
}

.favorites-icon {
    color: var(--accent);
}

/* Mini player (for video preview) */
.mini-player {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 320px;
    background: var(--bg-darker);
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    z-index: 80;
    overflow: hidden;
    display: none;
}

.mini-player.active {
    display: block;
}

.mini-player-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: rgba(0,0,0,0.3);
}

.mini-player-title {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
}

.mini-player-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
}

.mini-player-video {
    width: 100%;
    display: block;
}

/* Scrollbar styling */
.projects-list::-webkit-scrollbar,
.modal-body::-webkit-scrollbar {
    width: 6px;
}

.projects-list::-webkit-scrollbar-track,
.modal-body::-webkit-scrollbar-track {
    background: transparent;
}

.projects-list::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
}

.projects-list::-webkit-scrollbar-thumb:hover,
.modal-body::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.2);
}

/* ==================== OVERLAY NOTIFICATIONS ==================== */
.overlay-notification {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: overlayFadeIn 0.2s ease;
}

@keyframes overlayFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.overlay-notification-content {
    background: var(--card-bg, #1e293b);
    border: 1px solid var(--border, #334155);
    border-radius: 16px;
    padding: 24px 32px;
    max-width: 420px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: overlaySlideIn 0.25s ease;
}

@keyframes overlaySlideIn {
    from { transform: scale(0.9) translateY(-20px); opacity: 0; }
    to { transform: scale(1) translateY(0); opacity: 1; }
}

.overlay-notification-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.overlay-notification-message {
    font-size: 16px;
    color: var(--text, #e2e8f0);
    margin-bottom: 24px;
    line-height: 1.5;
}

.overlay-notification-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.overlay-notification-buttons button {
    min-width: 100px;
    padding: 10px 24px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.overlay-notification-buttons .btn-primary {
    background: var(--primary, #a855f7);
    color: white;
    border: none;
}

.overlay-notification-buttons .btn-primary:hover {
    background: var(--primary-hover, #9333ea);
    transform: translateY(-1px);
}

.overlay-notification-buttons .btn-secondary {
    background: transparent;
    color: var(--text-muted, #94a3b8);
    border: 1px solid var(--border, #334155);
}

.overlay-notification-buttons .btn-secondary:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text, #e2e8f0);
}

.overlay-notification-buttons .btn-danger {
    background: #ef4444;
    color: white;
    border: none;
}

.overlay-notification-buttons .btn-danger:hover {
    background: #dc2626;
}

/* Toast notifications */
.toast-container {
    position: fixed;
    top: var(--tc-space-5);
    right: var(--tc-space-5);
    z-index: var(--tc-z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--tc-space-3);
    pointer-events: none;
}

.toast {
    background: var(--tc-glass-bg-active);
    backdrop-filter: blur(var(--tc-glass-blur-heavy));
    -webkit-backdrop-filter: blur(var(--tc-glass-blur-heavy));
    border: var(--tc-glass-border-hover);
    border-left: 4px solid var(--tc-text-muted);
    border-radius: var(--tc-radius-md);
    padding: var(--tc-space-3) var(--tc-space-4);
    color: var(--tc-text-primary);
    font-size: var(--tc-font-size-sm);
    line-height: 1.4;
    box-shadow: var(--tc-shadow-xl);
    animation: toastSlideIn 0.25s ease;
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: var(--tc-space-3);
    max-width: 380px;
    min-width: 240px;
    word-break: break-word;
}

@keyframes toastSlideIn {
    from { transform: translateX(110%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.toast.toast-out {
    animation: toastSlideOut 0.25s ease forwards;
}

@keyframes toastSlideOut {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(110%); opacity: 0; }
}

.toast-success {
    border-left-color: var(--tc-success);
    background: var(--tc-success-surface);
}

.toast-error {
    border-left-color: var(--tc-error);
    background: var(--tc-error-surface);
}

.toast-warning {
    border-left-color: var(--tc-warning);
    background: var(--tc-warning-surface);
}

.toast-info {
    border-left-color: var(--tc-secondary);
    background: rgba(129, 140, 248, 0.1);
}

.toast-icon {
    font-size: 16px;
    flex-shrink: 0;
    margin-top: 1px;
}

.toast-message {
    flex: 1;
    color: #f1f5f9;
}

/* Fix dropdown option text color - ALL dropdowns across the app */
select option,
.form-select option,
select.form-select option {
    background: white !important;
    color: black !important;
}

/* ============================================
   MOBILE OPTIMIZATION
   ============================================ */

/* Mobile Menu Toggle Button */
.mobile-menu-btn {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 200;
    width: 44px;
    height: 44px;
    background: var(--bg-card);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    color: var(--text);
    font-size: 1.5rem;
    -webkit-tap-highlight-color: transparent;
}

.mobile-menu-btn:active {
    background: var(--bg-input);
}

/* Mobile Overlay */
.mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.6);
    z-index: 90;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-overlay.active {
    opacity: 1;
}

/* Mobile Header Bar */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--bg-sidebar);
    border-bottom: 1px solid rgba(255,255,255,0.06);
    z-index: 150;
    align-items: center;
    justify-content: center;
    padding: 0 60px;
}

.mobile-header .logo-text {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text);
}

.mobile-header .logo-icon {
    margin-right: 8px;
}

/* ============================================
   MOBILE BREAKPOINT (max-width: 768px)
   ============================================ */
@media (max-width: 768px) {
    /* Show mobile elements */
    .mobile-menu-btn {
        display: flex;
    }
    
    .mobile-header {
        display: flex;
    }
    
    .mobile-overlay {
        display: block;
        pointer-events: none;
    }
    
    .mobile-overlay.active {
        pointer-events: auto;
    }
    
    /* Hide sidebar by default, slide in when active */
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        width: var(--sidebar-width);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .sidebar.mobile-open {
        transform: translateX(0);
    }
    
    /* Show labels when sidebar is open on mobile */
    .sidebar.mobile-open .nav-label,
    .sidebar.mobile-open .logo-text,
    .sidebar.mobile-open .sidebar-section-header span,
    .sidebar.mobile-open .sidebar-add-btn,
    .sidebar.mobile-open .user-email-short {
        display: inline;
    }
    
    .sidebar.mobile-open .nav-item {
        justify-content: flex-start;
        padding: 12px 16px;
    }
    
    .sidebar.mobile-open .sidebar-logo {
        justify-content: flex-start;
        padding: 20px 16px;
    }
    
    /* Main content takes full width */
    .main-content {
        margin-left: 0;
        padding-top: 56px;
    }
    
    /* Header adjustments */
    .top-header {
        padding: 12px 16px;
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .search-bar {
        order: 3;
        width: 100%;
        max-width: 100%;
    }
    
    .header-actions {
        gap: 6px;
    }
    
    .header-actions .btn {
        padding: 8px 12px;
        font-size: 0.85rem;
    }
    
    /* Hide less important header buttons on mobile */
    .header-actions .btn-icon:not(#screenshotBtn) {
        display: none;
    }
    
    /* Creator area */
    .creator-area {
        padding: 16px 12px;
    }
    
    /* Home hero section */
    .home-hero {
        flex-direction: column;
        padding: 24px 16px;
        gap: 24px;
    }
    
    .hero-content {
        text-align: center;
    }
    
    .home-hero .hero-title {
        font-size: 2rem;
    }
    
    .hero-buttons {
        justify-content: center;
    }
    
    .hero-image-grid {
        justify-content: center;
    }
    
    /* Feature cards */
    .features-grid {
        grid-template-columns: 1fr;
        padding: 16px;
        gap: 16px;
    }
    
    /* Form controls */
    .form-group {
        margin-bottom: 16px;
    }
    
    .form-row {
        flex-direction: column;
        gap: 16px;
    }
    
    /* Settings bar */
    .settings-bar {
        flex-direction: column;
        gap: 12px;
        padding: 12px;
    }
    
    .settings-bar .setting-item {
        width: 100%;
    }
    
    .settings-bar select,
    .settings-bar input {
        width: 100%;
    }
    
    /* Buttons - larger touch targets */
    .btn {
        min-height: 44px;
        padding: 12px 16px;
    }
    
    .btn-generate {
        width: 100%;
    }
    
    /* Gallery grid */
    .gallery-grid,
    .video-gallery-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    
    /* Upload area */
    .upload-area {
        padding: 24px 16px;
    }
    
    /* Textarea */
    textarea {
        min-height: 120px;
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    /* Input fields - prevent zoom on iOS */
    input[type="text"],
    input[type="number"],
    input[type="email"],
    input[type="password"],
    select {
        font-size: 16px;
    }
    
    /* Modal adjustments */
    .modal-content,
    .lightbox-modal-content {
        width: 95vw;
        max-width: 95vw;
        margin: 10px;
        max-height: 90vh;
    }
    
    /* Progress section */
    .progress-section {
        padding: 16px;
    }
    
    /* Video result */
    .result-section video {
        max-height: 50vh;
    }
    
    /* Tabs */
    .mode-toggle {
        flex-wrap: wrap;
    }
    
    .mode-toggle .btn {
        flex: 1 1 auto;
        min-width: 100px;
    }
}

/* ============================================
   SMALL MOBILE (max-width: 480px)
   ============================================ */
@media (max-width: 480px) {
    .mobile-header {
        padding: 0 50px;
    }
    
    .home-hero .hero-title {
        font-size: 1.6rem;
    }
    
    .home-hero .hero-subtitle {
        font-size: 1rem;
    }
    
    .hero-buttons {
        flex-direction: column;
        width: 100%;
    }
    
    .hero-buttons .btn {
        width: 100%;
    }
    
    .hero-image-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    
    .hero-preview {
        width: 80px;
        height: 80px;
    }
    
    /* Single column gallery on very small screens */
    .gallery-grid,
    .video-gallery-grid {
        grid-template-columns: 1fr;
    }
    
    /* Header actions */
    .header-actions {
        gap: 4px;
    }
    
    .credits-display {
        font-size: 0.8rem;
        padding: 6px 10px;
    }
    
    /* Adjust tab buttons */
    .tab-nav-grouped {
        gap: 6px;
    }
    
    .gallery-tab-btn {
        padding: 10px 12px;
        font-size: 0.85rem;
    }
    
    /* Feature cards */
    .feature-card {
        padding: 16px;
    }
    
    .feature-card h3 {
        font-size: 1.1rem;
    }
    
    /* Chat widget */
    .chat-widget {
        width: calc(100vw - 20px);
        right: 10px;
        bottom: 10px;
        max-height: 70vh;
    }
}

/* ============================================
   TOUCH OPTIMIZATION
   ============================================ */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .nav-item,
    .nav-group {
        min-height: 48px;
    }
    
    .btn,
    button {
        min-height: 44px;
    }
    
    /* Remove hover effects that don't work on touch */
    .nav-item:hover {
        background: transparent;
    }
    
    .nav-item:active {
        background: rgba(255,255,255,0.1);
    }
    
    .btn:hover {
        transform: none;
    }
    
    .btn:active {
        transform: scale(0.98);
    }
    
    /* Scrollable areas */
    .sidebar-nav,
    .main-content {
        -webkit-overflow-scrolling: touch;
    }
    
    /* Prevent text selection on buttons */
    .btn,
    .nav-item,
    .tab-btn {
        -webkit-user-select: none;
        user-select: none;
    }
}

/* ============================================
   LANDSCAPE MOBILE
   ============================================ */
@media (max-width: 900px) and (orientation: landscape) {
    .mobile-header {
        height: 48px;
    }
    
    .main-content {
        padding-top: 48px;
    }
    
    .home-hero {
        flex-direction: row;
        padding: 16px;
    }
    
    .modal-content {
        max-height: 85vh;
    }
}

/* ============================================
   SAFE AREA INSETS (notch support)
   ============================================ */
@supports (padding: max(0px)) {
    .mobile-header {
        padding-top: max(0px, env(safe-area-inset-top));
        height: calc(56px + env(safe-area-inset-top));
    }
    
    .main-content {
        padding-top: calc(56px + env(safe-area-inset-top));
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    .sidebar {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ============================================
   AGGRESSIVE MOBILE OVERHAUL
   ============================================ */
@media (max-width: 768px) {
    /* Hide desktop header elements */
    .top-header .search-bar {
        display: none;
    }
    
    .header-actions .btn:not(.credits-display):not(#screenshotBtn) {
        display: none;
    }
    
    .top-header {
        justify-content: flex-end;
        padding: 8px 12px;
        min-height: 48px;
    }
    
    /* Stack all two-column layouts */
    .prompt-layout,
    .two-column-layout,
    .split-layout,
    .creator-layout {
        display: flex !important;
        flex-direction: column !important;
        gap: 16px !important;
    }

    /* Stack video + ref image on mobile */
    .result-video-wrapper {
        flex-direction: column !important;
    }
    .result-video {
        width: 100% !important;
        max-height: 280px !important;
    }
    .result-ref-image-panel {
        flex: 0 0 200px !important;
        border-left: none !important;
        border-top: 1px solid rgba(255,255,255,0.08) !important;
    }
    
    .prompt-layout > *,
    .two-column-layout > *,
    .split-layout > *,
    .creator-layout > * {
        width: 100% !important;
        max-width: 100% !important;
        flex: none !important;
    }
    
    /* Page titles */
    .page-title,
    .section-title-large,
    h1 {
        font-size: 1.5rem !important;
        margin-bottom: 8px !important;
    }
    
    .page-subtitle,
    .section-subtitle {
        font-size: 0.9rem !important;
        margin-bottom: 16px !important;
    }
    
    /* Cards - full width, less padding */
    .card,
    .form-card,
    .settings-card,
    .upload-card,
    .result-card {
        padding: 16px !important;
        margin: 0 !important;
        border-radius: 12px !important;
    }
    
    .card h2,
    .card h3,
    .form-card h2,
    .form-card h3 {
        font-size: 1.1rem !important;
        margin-bottom: 12px !important;
    }
    
    /* Form elements - full width */
    .form-group {
        margin-bottom: 16px !important;
    }
    
    .form-group label {
        font-size: 0.85rem !important;
        margin-bottom: 6px !important;
    }
    
    input[type="text"],
    input[type="number"],
    input[type="email"],
    input[type="password"],
    textarea,
    select {
        width: 100% !important;
        padding: 14px 12px !important;
        font-size: 16px !important;
        border-radius: 10px !important;
    }
    
    textarea {
        min-height: 100px !important;
    }
    
    /* Buttons - full width, larger */
    .btn {
        width: 100% !important;
        padding: 14px 16px !important;
        font-size: 1rem !important;
        border-radius: 10px !important;
        justify-content: center !important;
    }
    
    .btn-group,
    .button-group,
    .action-buttons {
        flex-direction: column !important;
        gap: 10px !important;
        width: 100% !important;
    }
    
    .btn-group .btn,
    .button-group .btn {
        margin: 0 !important;
    }
    
    /* Mode toggles - wrap and stack */
    .mode-toggle,
    .tab-toggle,
    .toggle-group {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
    }
    
    .mode-toggle .btn,
    .tab-toggle .btn,
    .toggle-group .btn {
        flex: 1 1 45% !important;
        min-width: 0 !important;
        padding: 12px 8px !important;
        font-size: 0.85rem !important;
    }
    
    /* Enhancement style buttons */
    .style-buttons,
    .option-buttons {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
    }
    
    .style-buttons .btn,
    .option-buttons .btn {
        flex: 1 1 auto !important;
        min-width: 70px !important;
        padding: 10px 12px !important;
        font-size: 0.8rem !important;
    }
    
    /* Upload areas */
    .upload-area,
    .drop-zone,
    .image-upload-area {
        padding: 24px 16px !important;
        min-height: 120px !important;
    }
    
    .upload-area p,
    .drop-zone p {
        font-size: 0.9rem !important;
    }
    
    /* Gallery grids */
    .gallery-grid,
    .video-gallery-grid,
    .photo-gallery-grid,
    .assets-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
        padding: 0 !important;
    }
    
    .gallery-item,
    .video-item,
    .photo-item {
        border-radius: 10px !important;
    }
    
    /* Progress sections */
    .progress-section,
    .status-section {
        padding: 16px !important;
    }
    
    .progress-bar {
        height: 8px !important;
        border-radius: 4px !important;
    }
    
    /* Result video */
    .result-section video,
    .video-preview video {
        max-height: 40vh !important;
        border-radius: 12px !important;
    }
    
    /* Settings bars - vertical stack */
    .settings-bar,
    .options-bar,
    .controls-bar {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
        padding: 12px !important;
        background: var(--bg-card) !important;
        border-radius: 12px !important;
    }
    
    .settings-bar > *,
    .options-bar > *,
    .controls-bar > * {
        width: 100% !important;
    }
    
    .setting-item,
    .control-item {
        display: flex !important;
        flex-direction: column !important;
        gap: 6px !important;
    }
    
    .setting-item label {
        font-size: 0.8rem !important;
        color: var(--text-muted) !important;
    }
    
    /* Tab navigation */
    .tab-nav,
    .gallery-tabs {
        display: flex !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        gap: 8px !important;
        padding-bottom: 8px !important;
        scrollbar-width: none !important;
    }
    
    .tab-nav::-webkit-scrollbar,
    .gallery-tabs::-webkit-scrollbar {
        display: none !important;
    }
    
    .tab-btn,
    .gallery-tab-btn {
        flex-shrink: 0 !important;
        padding: 12px 16px !important;
        font-size: 0.9rem !important;
        white-space: nowrap !important;
        border-radius: 8px !important;
    }
    
    /* Creator area padding */
    .creator-area,
    .page-content,
    .main-section {
        padding: 16px 12px !important;
    }
    
    /* Home page hero */
    .home-hero {
        padding: 20px 16px !important;
        text-align: center !important;
    }
    
    .home-hero .hero-content {
        max-width: 100% !important;
    }
    
    .home-hero .hero-title {
        font-size: 1.8rem !important;
        line-height: 1.2 !important;
    }
    
    .home-hero .hero-subtitle {
        font-size: 1rem !important;
    }
    
    .hero-buttons {
        flex-direction: column !important;
        gap: 10px !important;
    }
    
    .hero-image-grid {
        display: none !important;
    }
    
    /* Feature cards */
    .features-grid,
    .feature-cards {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
        padding: 0 12px !important;
    }
    
    .feature-card {
        padding: 16px !important;
    }
    
    .feature-card .feature-icon {
        font-size: 2rem !important;
        margin-bottom: 12px !important;
    }
    
    .feature-card h3 {
        font-size: 1rem !important;
    }
    
    .feature-card p {
        font-size: 0.85rem !important;
    }
    
    /* Modals */
    .modal-content,
    .lightbox-modal-content,
    .dialog-content {
        width: 100% !important;
        max-width: 100% !important;
        min-height: 100vh !important;
        margin: 0 !important;
        border-radius: 0 !important;
        padding: 16px !important;
    }
    
    .modal-header {
        padding: 12px 0 !important;
        font-size: 1.1rem !important;
    }
    
    .modal-close {
        width: 40px !important;
        height: 40px !important;
        font-size: 1.5rem !important;
    }
    
    /* Chat widget */
    .chat-widget {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        max-height: 100% !important;
        border-radius: 0 !important;
    }
    
    .chat-toggle-btn {
        width: 56px !important;
        height: 56px !important;
        bottom: 16px !important;
        right: 16px !important;
    }
    
    /* Scrollable content */
    .scrollable-content {
        -webkit-overflow-scrolling: touch !important;
    }
    
    /* Fix any remaining side padding */
    .container,
    .content-container {
        padding-left: 12px !important;
        padding-right: 12px !important;
    }
}

/* Extra small screens */
@media (max-width: 380px) {
    .mode-toggle .btn,
    .tab-toggle .btn {
        flex: 1 1 100% !important;
        font-size: 0.9rem !important;
    }
    
    .style-buttons .btn,
    .option-buttons .btn {
        flex: 1 1 100% !important;
    }
    
    .gallery-grid,
    .video-gallery-grid {
        grid-template-columns: 1fr !important;
    }
    
    .home-hero .hero-title {
        font-size: 1.5rem !important;
    }
}

/* Fix iOS input zoom */
@media (max-width: 768px) {
    input, select, textarea {
        font-size: 16px !important;
    }
}

/* Bottom navigation bar for mobile */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: var(--bg-sidebar);
    border-top: 1px solid rgba(255,255,255,0.1);
    z-index: 100;
    padding-bottom: env(safe-area-inset-bottom);
}

.mobile-bottom-nav-inner {
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: 64px;
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.7rem;
    gap: 4px;
    min-width: 64px;
    -webkit-tap-highlight-color: transparent;
}

.mobile-nav-item.active {
    color: var(--primary);
}

.mobile-nav-item .nav-icon {
    width: 24px;
    height: 24px;
}

.mobile-nav-item .nav-icon svg {
    width: 22px;
    height: 22px;
}

@media (max-width: 768px) {
    .mobile-bottom-nav {
        display: block;
    }
    
    /* Add padding at bottom for nav bar */
    .main-content {
        padding-bottom: calc(64px + env(safe-area-inset-bottom)) !important;
    }
    
    /* Hide sidebar hamburger, use bottom nav instead */
    .mobile-menu-btn {
        display: none !important;
    }
    
    .mobile-header {
        display: none !important;
    }
    
    .sidebar {
        display: none !important;
    }
    
    .main-content {
        margin-left: 0 !important;
        padding-top: 56px !important;
    }

    .top-bar {
        left: 0 !important;
    }

    /* Mobile: hide most header items, show only status + credits + overflow */
    .header-buy-credits,
    .header-admin,
    .header-logout {
        display: none !important;
    }
    .header-overflow-buy {
        display: flex !important;
    }
    .top-bar-right {
        gap: 8px;
    }
    .user-credits-badge {
        font-size: 0.75rem;
        padding: 4px 8px;
    }
    .header-overflow-btn {
        min-width: 44px;
        min-height: 44px;
    }
}

/* Mobile More Menu */
.mobile-more-menu {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: 0;
    background: rgba(0,0,0,0.7);
    z-index: 200;
    align-items: flex-end;
    justify-content: center;
}

.mobile-more-menu.active {
    display: flex;
}

.mobile-more-menu-content {
    background: var(--bg-card);
    width: 100%;
    border-radius: 20px 20px 0 0;
    padding: 20px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    animation: slideUp 0.3s ease;
    max-height: 80vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

.mobile-more-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    font-weight: 600;
    font-size: 1.1rem;
}

.mobile-more-close {
    background: none;
    border: none;
    color: var(--text);
    font-size: 1.5rem;
    padding: 8px;
    cursor: pointer;
}

.mobile-more-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    color: var(--text);
    text-decoration: none;
    border-radius: 12px;
    font-size: 1rem;
}

.mobile-more-item:active {
    background: rgba(255,255,255,0.1);
}

.mobile-more-item .nav-icon {
    width: 26px;
    height: 26px;
}

.mobile-more-item .nav-icon svg {
    width: 24px;
    height: 24px;
}

button.mobile-more-item {
    width: 100%;
    background: transparent;
    border: none;
    text-align: left;
    cursor: pointer;
    min-height: 48px;
}

.mobile-more-section {
    margin-bottom: 12px;
}
.mobile-more-section-label {
    display: block;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    padding: 8px 16px 4px;
}
.mobile-more-child {
    padding: 14px 16px 14px 20px;
    min-height: 48px;
}

/* ============================================
   PROMPT ENHANCER PAGE STYLES
   ============================================ */

/* Page Header */
.prompt-page-header {
    margin-bottom: 20px;
}

.prompt-page-header .page-title {
    font-size: 1.5rem;
    margin-bottom: 4px;
}

.prompt-page-header .page-subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Two-column layout - desktop */
.prompt-enhancer-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

/* Cards */
.prompt-card-main,
.prompt-card-context {
    padding: 20px;
}

.card-title {
    font-size: 1.1rem;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.optional-badge {
    font-size: 0.7rem;
    padding: 2px 8px;
    background: rgba(255,255,255,0.1);
    border-radius: 10px;
    color: var(--text-muted);
    font-weight: normal;
}

/* Style pills for enhancement options */
.style-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.radio-pill {
    display: inline-block;
    cursor: pointer;
}

.radio-pill input {
    display: none;
}

.radio-pill span {
    display: inline-block;
    padding: 8px 16px;
    background: var(--bg-input);
    border-radius: 20px;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.radio-pill input:checked + span {
    background: var(--primary);
    color: white;
}

/* Enhance button - full width only on prompt enhancer page */
.prompt-card-main .btn-enhance,
#page-prompt .btn-enhance:not(.prompt-header .btn-enhance) {
    width: 100%;
    padding: 14px;
    font-size: 1rem;
    margin: 16px 0;
}

/* Result header */
.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.btn-copy {
    padding: 6px 12px;
    background: var(--bg-input);
    border: none;
    border-radius: 6px;
    color: var(--text);
    cursor: pointer;
    font-size: 0.8rem;
}

.result-textarea {
    background: rgba(0,0,0,0.3) !important;
}

/* Context buttons */
.context-buttons {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.context-buttons .btn-secondary,
.context-buttons .btn-primary {
    flex: 1;
    padding: 12px;
}

/* File path display */
.file-path-display {
    padding: 10px 12px;
    background: rgba(0,0,0,0.2);
    border-radius: 8px;
    font-size: 0.8rem;
    color: var(--text-muted);
    word-break: break-all;
    margin-bottom: 8px;
}

/* OR divider */
.divider-or {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 16px 0;
    color: var(--text-muted);
    font-size: 0.75rem;
}

.divider-or::before,
.divider-or::after {
    content: '';
    flex: 1;
    height: 1px;
    background: rgba(255,255,255,0.1);
}

/* Folder input group */
.folder-input-group {
    display: flex;
    gap: 8px;
}

.folder-input-group input {
    flex: 1;
}

.folder-input-group .btn-secondary {
    flex-shrink: 0;
    padding: 12px 16px;
}

/* Analysis status */
.analysis-status {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    background: rgba(168, 85, 247, 0.1);
    border-radius: 8px;
    border: 1px solid rgba(168, 85, 247, 0.2);
    margin-top: 12px;
}

.analysis-status .status-text {
    flex: 1;
}

.analysis-status .status-detail {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* File tree */
.file-tree {
    max-height: 200px;
    overflow-y: auto;
    background: rgba(0,0,0,0.2);
    border-radius: 8px;
    padding: 12px;
    font-family: monospace;
    font-size: 0.75rem;
    margin-top: 12px;
}

/* Project summary */
.project-summary {
    margin-top: 12px;
    padding: 12px;
    background: rgba(0,0,0,0.2);
    border-radius: 8px;
}

.project-summary .summary-title {
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 0.85rem;
}

.project-summary .summary-text {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.5;
}

/* ============================================
   PROMPT ENHANCER MOBILE STYLES
   ============================================ */
@media (max-width: 768px) {
    .prompt-page-header {
        text-align: center;
        padding: 0 12px;
        margin-bottom: 16px;
    }

    .prompt-page-header .page-title {
        font-size: 1.3rem;
    }

    .prompt-page-header .page-subtitle {
        font-size: 0.85rem;
    }

    /* Stack cards vertically, main card first */
    .prompt-enhancer-layout {
        display: flex;
        flex-direction: column;
        gap: 16px;
        padding: 0;
    }

    .prompt-card-main {
        order: 1;
    }

    .prompt-card-context {
        order: 2;
    }

    .prompt-card-main,
    .prompt-card-context {
        padding: 16px;
        margin: 0;
        border-radius: 12px;
    }

    .card-title {
        font-size: 1rem;
        margin-bottom: 12px;
    }

    /* Style pills - 2x2 grid */
    .style-pills {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .radio-pill {
        display: block;
    }

    .radio-pill span {
        display: block;
        text-align: center;
        padding: 12px;
        font-size: 0.9rem;
    }

    /* Textareas */
    #originalPrompt {
        min-height: 100px;
    }

    #enhancedPrompt {
        min-height: 120px;
    }

    /* Enhance button */
    .btn-enhance {
        padding: 16px;
        font-size: 1.1rem;
    }

    /* Context buttons - stack */
    .context-buttons {
        flex-direction: column;
    }

    .context-buttons .btn-secondary,
    .context-buttons .btn-primary {
        width: 100%;
    }

    /* Folder input - stack */
    .folder-input-group {
        flex-direction: column;
    }

    .folder-input-group .btn-secondary {
        width: 100%;
    }

    /* Hide project context by default, show as collapsible */
    .prompt-card-context {
        background: var(--bg-card);
    }

    .prompt-card-context .card-title {
        cursor: pointer;
    }

    /* File tree smaller */
    .file-tree {
        max-height: 150px;
        font-size: 0.7rem;
    }

    /* History section */
    #page-prompt .card:last-child {
        margin-top: 16px !important;
    }
}

/* ============================================
   VOICEOVER PAGE MOBILE STYLES
   ============================================ */
@media (max-width: 768px) {
    /* Voiceover Hero */
    .voiceover-hero {
        flex-direction: column !important;
        padding: 20px 16px !important;
        text-align: center !important;
    }

    .voiceover-hero .hero-content {
        max-width: 100% !important;
    }

    .voiceover-hero .hero-title {
        font-size: 1.5rem !important;
        line-height: 1.3 !important;
    }

    .voiceover-hero .hero-title br {
        display: none;
    }

    .voiceover-hero .hero-subtitle {
        font-size: 0.9rem !important;
        margin-bottom: 16px !important;
    }

    .voiceover-hero .btn-hero {
        width: 100% !important;
        padding: 14px !important;
    }

    .voiceover-hero .hero-visual {
        display: none !important;
    }

    /* Voice Type Tabs - horizontal scroll */
    .voice-type-tabs {
        display: flex !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        gap: 8px !important;
        padding: 12px 16px !important;
        scrollbar-width: none !important;
    }

    .voice-type-tabs::-webkit-scrollbar {
        display: none;
    }

    .voice-type-tab {
        flex-shrink: 0 !important;
        padding: 10px 16px !important;
        font-size: 0.75rem !important;
        white-space: nowrap !important;
        border-radius: 20px !important;
    }

    /* Voice Explorer */
    .voice-explorer {
        padding: 16px !important;
    }

    .voice-explorer .section-title {
        font-size: 1.1rem !important;
        text-align: center !important;
        margin-bottom: 16px !important;
    }

    /* Voice Filters - stack vertically */
    .voice-filters {
        display: flex !important;
        flex-direction: column !important;
        gap: 10px !important;
    }

    .voice-filters .filter-item {
        width: 100% !important;
    }

    .voice-filters .filter-select {
        width: 100% !important;
        padding: 12px !important;
        font-size: 0.9rem !important;
    }

    .voice-filters .filter-spacer {
        display: none !important;
    }

    .voice-filters .btn-clone-voice {
        width: 100% !important;
        padding: 14px !important;
        justify-content: center !important;
    }

    /* Voice Cards - single column */
    .voice-cards {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
        margin-top: 16px !important;
    }

    .voice-card {
        padding: 16px !important;
        border-radius: 12px !important;
    }

    .voice-card .voice-avatar {
        width: 48px !important;
        height: 48px !important;
        font-size: 1.5rem !important;
    }

    .voice-card .voice-info h4 {
        font-size: 1rem !important;
    }

    .voice-card .voice-info p {
        font-size: 0.85rem !important;
    }

    .voice-card .btn-preview {
        width: 44px !important;
        height: 44px !important;
        font-size: 1rem !important;
    }

    /* Music Page Hero */
    .music-hero {
        padding: 20px 16px !important;
        text-align: center !important;
    }

    .music-hero .hero-title {
        font-size: 1.5rem !important;
        line-height: 1.3 !important;
    }

    .music-hero .hero-title br {
        display: none;
    }

    .music-hero .hero-subtitle {
        font-size: 0.9rem !important;
    }

    .music-hero .hero-buttons {
        flex-direction: column !important;
        gap: 10px !important;
    }

    .music-hero .btn-hero,
    .music-hero .btn-hero-outline {
        width: 100% !important;
        padding: 14px !important;
    }

    /* Brand Logos - hide on mobile */
    .brand-logos {
        display: none !important;
    }

    /* Music Filters - horizontal scroll */
    .music-filters {
        display: flex !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        gap: 8px !important;
        padding: 12px 16px !important;
        scrollbar-width: none !important;
    }

    .music-filters::-webkit-scrollbar {
        display: none;
    }

    .music-filters .filter-select,
    .music-filters .filter-select-small {
        flex-shrink: 0 !important;
        padding: 10px 14px !important;
        font-size: 0.8rem !important;
    }

    .music-filters .filter-spacer {
        display: none !important;
    }

    .music-filters .filter-toggle {
        flex-shrink: 0 !important;
    }

    .music-filters .btn-filters {
        flex-shrink: 0 !important;
        padding: 10px 14px !important;
    }

    /* Track List */
    .track-list {
        padding: 0 12px !important;
    }

    .track-item {
        padding: 12px !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
    }

    .track-item .track-play {
        width: 40px !important;
        height: 40px !important;
    }

    .track-item .track-thumb {
        width: 40px !important;
        height: 40px !important;
    }

    .track-item .track-info {
        flex: 1 !important;
        min-width: 120px !important;
    }

    .track-item .track-info h4 {
        font-size: 0.9rem !important;
    }

    .track-item .track-info .track-artist {
        font-size: 0.75rem !important;
    }

    .track-item .track-genre,
    .track-item .track-duration {
        font-size: 0.7rem !important;
    }

    .track-item .track-waveform {
        display: none !important;
    }

    .track-item .track-actions {
        width: 100% !important;
        justify-content: flex-end !important;
        gap: 8px !important;
        padding-top: 8px !important;
        border-top: 1px solid rgba(255,255,255,0.1) !important;
    }

    .track-item .track-actions button {
        width: 36px !important;
        height: 36px !important;
    }

    /* Audio player bar - fixed at bottom above nav */
    .audio-player-bar {
        bottom: calc(64px + env(safe-area-inset-bottom)) !important;
        padding: 8px 12px !important;
    }
}

/* ============================================
   VOICEOVER PAGE - FUNCTIONAL UI
   ============================================ */
.voiceover-page {
    padding: 20px;
}

.voiceover-header {
    margin-bottom: 24px;
}

.voiceover-header .page-title {
    font-size: 1.5rem;
    margin-bottom: 4px;
}

.voiceover-header .page-subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Two-column layout */
.voiceover-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

/* Input card */
.voiceover-input-card {
    padding: 20px;
}

.voiceover-input-card .card-title {
    font-size: 1rem;
    margin-bottom: 12px;
    color: var(--text);
}

/* Upload area in voiceover */
.voiceover-input-card .upload-area {
    min-height: 180px;
    margin-bottom: 12px;
}

.voiceover-input-card .upload-preview {
    max-height: 200px;
    width: auto;
    max-width: 100%;
    object-fit: contain;
    border-radius: 8px;
}

.btn-clear-avatar {
    margin-bottom: 16px;
    padding: 8px 16px;
    font-size: 0.85rem;
}

/* Voice settings grid */
.voice-settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
    margin-bottom: 12px;
}

.voice-settings-grid .form-group {
    margin-bottom: 0;
}

.voice-settings-grid label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    display: block;
}

.voice-settings-grid select {
    width: 100%;
    padding: 10px;
    font-size: 0.85rem;
}

/* Generate button */
.btn-generate-avatar {
    width: 100%;
    padding: 14px;
    margin-top: 16px;
    font-size: 1rem;
}

/* Output section */
.voiceover-output {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.voiceover-progress-card,
.voiceover-result-card {
    padding: 20px;
}

.voiceover-progress-card .progress-bar-container {
    height: 8px;
    background: var(--bg-input);
    border-radius: 4px;
    overflow: hidden;
    margin: 12px 0;
}

.voiceover-progress-card .progress-bar {
    height: 100%;
    background: var(--primary);
    transition: width 0.3s;
}

.voiceover-progress-card .progress-status {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Result video */
.voiceover-result-card .result-video {
    width: 100%;
    max-height: 300px;
    border-radius: 8px;
    background: #000;
    margin-bottom: 12px;
}

.voiceover-result-card .result-actions {
    display: flex;
    gap: 10px;
}

.voiceover-result-card .result-actions .btn-primary,
.voiceover-result-card .result-actions .btn-secondary {
    flex: 1;
    padding: 12px;
    text-align: center;
    text-decoration: none;
}

/* Help card */
.voiceover-help-card {
    padding: 16px;
    background: rgba(168, 85, 247, 0.1);
    border: 1px solid rgba(168, 85, 247, 0.2);
}

.voiceover-help-card h3 {
    font-size: 0.9rem;
    margin-bottom: 10px;
}

.voiceover-help-card ul {
    margin: 0;
    padding-left: 20px;
}

.voiceover-help-card li {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

/* Mobile voiceover */
@media (max-width: 768px) {
    .voiceover-page {
        padding: 16px 12px;
    }

    .voiceover-header {
        text-align: center;
        margin-bottom: 16px;
    }

    .voiceover-header .page-title {
        font-size: 1.3rem;
    }

    .voiceover-layout {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .voiceover-input-card {
        padding: 16px;
    }

    .voiceover-input-card .upload-area {
        min-height: 150px;
    }

    /* Voice settings - stack on mobile */
    .voice-settings-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .voice-settings-grid select {
        padding: 12px;
        font-size: 16px;
    }

    .btn-generate-avatar {
        padding: 16px;
        font-size: 1.1rem;
    }

    .voiceover-output {
        gap: 12px;
    }

    .voiceover-result-card .result-actions {
        flex-direction: column;
    }

    .voiceover-help-card {
        display: none; /* Hide tips on mobile to save space */
    }
}

/* ============================================
   AUDIO TAB BAR
   ============================================ */
.audio-tab-bar {
    display: flex;
    gap: 4px;
    background: var(--bg-card, #1e1e2e);
    border-radius: 10px;
    padding: 4px;
    margin-bottom: 20px;
}

.audio-tab {
    flex: 1;
    padding: 10px 16px;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--text-muted, #888);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.audio-tab:hover {
    color: var(--text, #fff);
    background: rgba(255,255,255,0.05);
}

.audio-tab.active {
    background: var(--primary, #a855f7);
    color: #fff;
}

.audio-tab-icon {
    font-size: 1rem;
}

.audio-tab-panel {
    display: none;
}

.audio-tab-panel.active {
    display: block;
}

/* ============================================
   TRANSCRIBE TAB STYLES
   ============================================ */
.transcribe-layout {
    width: 100%;
}

.transcribe-upload-card {
    padding: 20px;
}

.transcribe-drop-zone {
    border: 2px dashed rgba(168, 85, 247, 0.3);
    border-radius: 12px;
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: rgba(168, 85, 247, 0.03);
}

.transcribe-drop-zone:hover,
.transcribe-drop-zone.dragover {
    border-color: var(--primary, #a855f7);
    background: rgba(168, 85, 247, 0.08);
}

.transcribe-drop-icon {
    font-size: 2.5rem;
    display: block;
    margin-bottom: 8px;
}

.transcribe-drop-text {
    font-size: 1rem;
    color: var(--text, #fff);
    margin-bottom: 4px;
}

.transcribe-drop-hint {
    font-size: 0.8rem;
    color: var(--text-muted, #888);
}

/* Upload progress */
.transcribe-upload-progress {
    margin-top: 16px;
}

.transcribe-progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.transcribe-progress-label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text, #fff);
}

.transcribe-progress-pct {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--primary, #a855f7);
}

.transcribe-progress-track {
    height: 6px;
    background: var(--bg-input, #2a2a3e);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 8px;
}

.transcribe-progress-fill {
    height: 100%;
    background: var(--primary, #a855f7);
    border-radius: 3px;
    transition: width 0.3s;
}

.transcribe-progress-stats {
    display: flex;
    gap: 16px;
    font-size: 0.8rem;
    color: var(--text-muted, #888);
}

/* KPI cards */
.transcribe-kpis {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-top: 16px;
}

.transcribe-kpi {
    background: var(--bg-card, #1e1e2e);
    border: 1px solid var(--border, #333);
    border-radius: 8px;
    padding: 12px;
    text-align: center;
}

.transcribe-kpi-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted, #888);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.transcribe-kpi-value {
    display: block;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text, #fff);
    word-break: break-all;
}

/* Transcribe button */
.transcribe-actions {
    margin-top: 16px;
}

.btn-transcribe {
    width: 100%;
    padding: 14px;
    font-size: 1rem;
}

/* Transcription progress card */
.transcribe-progress-card {
    margin-top: 16px;
    padding: 20px;
}

/* Result card */
.transcribe-result-card {
    margin-top: 16px;
    padding: 20px;
}

.transcribe-result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.transcribe-result-header h3 {
    margin: 0;
    font-size: 1rem;
}

.transcribe-lang-badge {
    background: rgba(168, 85, 247, 0.2);
    color: var(--primary, #a855f7);
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.transcribe-result-text {
    background: var(--bg-input, #2a2a3e);
    border: 1px solid var(--border, #333);
    border-radius: 8px;
    padding: 16px;
    max-height: 400px;
    overflow-y: auto;
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text, #fff);
    white-space: pre-wrap;
    margin-bottom: 12px;
}

.transcribe-result-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.transcribe-result-actions .btn-secondary {
    flex: 1;
    min-width: 120px;
    padding: 10px 16px;
    text-align: center;
    font-size: 0.85rem;
}

/* Mobile transcribe */
@media (max-width: 768px) {
    .audio-tab-bar {
        gap: 2px;
        padding: 3px;
    }
    .audio-tab {
        padding: 8px 10px;
        font-size: 0.8rem;
        gap: 4px;
    }
    .audio-tab-icon {
        font-size: 0.9rem;
    }
    .transcribe-kpis {
        grid-template-columns: repeat(2, 1fr);
    }
    .transcribe-drop-zone {
        padding: 30px 16px;
    }
    .transcribe-result-actions {
        flex-direction: column;
    }
    .transcribe-result-actions .btn-secondary {
        min-width: unset;
    }
}

/* ============================================
   NARRATION/TTS PAGE STYLES
   ============================================ */
.narrate-page {
    padding: 20px;
}

.narrate-header {
    margin-bottom: 24px;
}

.narrate-header .page-title {
    font-size: 1.5rem;
    margin-bottom: 4px;
}

.narrate-header .page-subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Two-column layout */
.narrate-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

/* Main card */
.narrate-main-card {
    padding: 20px;
}

.narrate-textarea {
    min-height: 150px;
    resize: vertical;
}

.char-count {
    text-align: right;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Settings grid */
.narrate-settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.narrate-settings-grid label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    display: block;
}

.narrate-settings-grid select {
    width: 100%;
    padding: 10px;
}

/* Buttons */
.btn-preview-voice {
    width: 100%;
    padding: 12px;
    margin-bottom: 12px;
}

.btn-generate-narrate {
    width: 100%;
    padding: 14px;
    font-size: 1rem;
}

/* Status */
.narrate-status {
    margin-top: 12px;
    padding: 12px;
    background: rgba(168, 85, 247, 0.1);
    border-radius: 8px;
    text-align: center;
    color: var(--text-muted);
}

/* Output section */
.narrate-output {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.narrate-result-card {
    padding: 20px;
}

.narrate-player {
    margin-bottom: 16px;
}

.narrate-audio {
    width: 100%;
    border-radius: 8px;
}

.narrate-actions {
    display: flex;
    gap: 10px;
}

.narrate-actions button {
    flex: 1;
    padding: 12px;
}

/* Tips card */
.narrate-tips-card {
    padding: 16px;
    background: rgba(168, 85, 247, 0.1);
    border: 1px solid rgba(168, 85, 247, 0.2);
}

.narrate-tips-card h3 {
    font-size: 0.9rem;
    margin-bottom: 10px;
}

.narrate-tips-card ul {
    margin: 0;
    padding-left: 20px;
}

.narrate-tips-card li {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

/* Mobile narration */
@media (max-width: 768px) {
    .narrate-page {
        padding: 16px 12px;
    }

    .narrate-header {
        text-align: center;
        margin-bottom: 16px;
    }

    .narrate-layout {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .narrate-main-card {
        padding: 16px;
    }

    .narrate-settings-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .narrate-settings-grid select {
        padding: 12px;
        font-size: 16px;
    }

    .btn-generate-narrate {
        padding: 16px;
        font-size: 1.1rem;
    }

    .narrate-actions {
        flex-direction: column;
    }

    .narrate-tips-card {
        display: none;
    }
}

/* ============================================
   SCENE PLAYBOOK & DIALOGUE STYLES
   ============================================ */

/* Narrative Mode Toggle */
.mode-toggle .mode-btn {
    padding: 8px 16px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9em;
}

.mode-toggle .mode-btn:hover {
    background: rgba(255,255,255,0.05);
    color: var(--text);
}

.mode-toggle .mode-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* Script Import Section */
.script-import-section {
    background: rgba(37,99,235,0.15);
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 15px;
    border: 1px solid rgba(37,99,235,0.3);
}

/* Scene Sets Panel */
.scene-sets-panel {
    background: rgba(16,185,129,0.10);
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 12px;
    border: 1px solid rgba(16,185,129,0.25);
}

/* Scene Voice Settings */
.scene-voice-settings {
    background: rgba(124,58,237,0.15);
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 15px;
    border: 1px solid rgba(124,58,237,0.3);
}

/* Scene Entry */
.scene-entry {
    background: rgba(255,255,255,0.05);
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 10px;
    border: 1px solid rgba(255,255,255,0.1);
}

.scene-entry:hover {
    border-color: rgba(124,58,237,0.4);
}

.scene-entry textarea {
    width: 100%;
    background: rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 6px;
    color: var(--text);
    padding: 8px;
    font-size: 0.9em;
    resize: vertical;
}

.scene-entry textarea:focus {
    border-color: var(--primary);
    outline: none;
}

/* Scene Dialogue Section */
.scene-dialogue-section {
    margin-top: 8px;
    padding: 10px;
    background: rgba(167,139,250,0.1);
    border-radius: 6px;
    border-left: 3px solid #7c3aed;
}

/* Character Dialogue Section */
.dialogue-section {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.dialogue-section textarea {
    width: 100%;
    background: rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 6px;
    color: var(--text);
    padding: 10px;
    font-size: 0.9em;
}

.dialogue-options {
    margin-top: 12px;
    padding: 12px;
    background: rgba(124,58,237,0.1);
    border-radius: 8px;
    border: 1px solid rgba(124,58,237,0.2);
}

.voice-option {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.voice-option label {
    font-size: 0.8em;
    color: var(--text-muted);
}

.voice-option select {
    background: rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.15);
    color: var(--text);
    border-radius: 4px;
}

/* Audio Options Section */
.audio-options-section {
    margin-top: 15px;
    padding: 15px;
    background: rgba(37,99,235,0.1);
    border-radius: 8px;
    border: 1px solid rgba(37,99,235,0.2);
}

.audio-option-row {
    margin-bottom: 8px;
}

.audio-option-row:last-child {
    margin-bottom: 0;
}

/* Mobile responsiveness for playbook */
@media (max-width: 768px) {
    .mode-toggle {
        flex-wrap: wrap;
    }

    .mode-toggle .mode-btn {
        flex: 1;
        min-width: 120px;
    }

    .scene-voice-settings > div {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 10px !important;
    }

    .dialogue-voice-row {
        flex-direction: column;
        gap: 10px !important;
    }

    .audio-option-row {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 8px !important;
    }
}

/* User Settings Overlay */
.settings-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.settings-panel {
    background: var(--tc-glass-bg-active);
    backdrop-filter: blur(var(--tc-glass-blur-heavy));
    -webkit-backdrop-filter: blur(var(--tc-glass-blur-heavy));
    border-radius: var(--tc-radius-xl);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--tc-shadow-2xl);
    border: var(--tc-glass-border-hover);
    animation: modalSlideUp 0.25s ease;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.settings-header h2 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: #fff;
}

.settings-close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted, #94a3b8);
    padding: 0;
    line-height: 1;
    transition: color 0.2s;
}

.settings-close-btn:hover {
    color: #fff;
}

.settings-content {
    padding: 24px;
}

.settings-section h3 {
    margin: 0 0 8px;
    font-size: 1rem;
    color: #fff;
}

.settings-hint {
    color: var(--text-muted, #94a3b8);
    font-size: 0.85rem;
    margin: 0 0 20px;
}

/* Theme color swatches inside settings panel */
.theme-swatch {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.12s, border-color 0.12s;
    flex-shrink: 0;
}
.theme-swatch:hover { transform: scale(1.15); }
.theme-swatch.active { border-color: #fff; box-shadow: 0 0 0 2px rgba(255,255,255,0.4); }

.api-key-group {
    margin-bottom: 16px;
}

.api-key-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 6px;
    color: #fff;
}

.api-key-input-row {
    display: flex;
    gap: 8px;
}

.api-key-input-row input {
    flex: 1;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(0, 0, 0, 0.3);
    color: #fff;
    font-size: 0.9rem;
}

.api-key-input-row input:focus {
    outline: none;
    border-color: #a855f7;
    box-shadow: 0 0 0 2px rgba(168, 85, 247, 0.2);
}

.api-key-input-row input::placeholder {
    color: var(--text-muted, #94a3b8);
}

.btn-show-key {
    padding: 10px 14px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.3);
    color: var(--text-muted, #94a3b8);
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
}

.btn-show-key:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.api-key-hint {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted, #64748b);
    margin-top: 4px;
}

.settings-actions {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.settings-actions .btn-primary {
    width: 100%;
    padding: 12px 20px;
    background: linear-gradient(135deg, #a855f7, #7c3aed);
    border: none;
    border-radius: 8px;
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.settings-actions .btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(168, 85, 247, 0.4);
}

.settings-actions .btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Settings gear icon in sidebar */
.settings-gear {
    margin-left: auto;
    opacity: 0.4;
    font-size: 0.9rem;
    transition: opacity 0.2s;
}

.user-info-compact:hover .settings-gear {
    opacity: 1;
}

.user-info-compact {
    padding: 10px 12px;
    margin: -10px -12px;
    cursor: pointer !important;
}

.user-info-compact:hover {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 8px;
}

/* Mobile responsiveness for settings */
@media (max-width: 480px) {
    .settings-panel {
        width: 95%;
        max-height: 95vh;
        border-radius: 12px;
    }

    .settings-header {
        padding: 16px 20px;
    }

    .settings-content {
        padding: 20px;
    }
}

/* ============================================
   VOICEOVER SECTION MOBILE
   ============================================ */

/* Voiceover inline content */
.voiceover-inline-content {
    padding: 10px 0;
}

/* Tablets and medium screens */
@media (max-width: 768px) {
    .voiceover-settings-row {
        flex-wrap: wrap;
    }

    .voiceover-settings-row .form-group {
        min-width: 45% !important;
    }

    .mode-tabs {
        flex-wrap: wrap;
        gap: 8px;
    }

    .mode-tab {
        padding: 8px 12px;
    }
}

/* Small mobile devices */
@media (max-width: 480px) {
    .voiceover-settings-row {
        flex-direction: column !important;
        gap: 10px !important;
    }

    .voiceover-settings-row .form-group {
        width: 100% !important;
        min-width: auto !important;
    }

    .mode-tabs {
        width: 100%;
        margin-left: 0;
    }

    .mode-tab {
        flex: 1;
        text-align: center;
        min-width: 80px;
        padding: 10px 8px;
        font-size: 0.85rem;
    }
}

/* Touch-friendly adjustments */
@media (hover: none) and (pointer: coarse) {
    .mode-tab {
        padding: 10px 14px;
    }

    .btn-clear-image {
        width: 32px;
        height: 32px;
        font-size: 1rem;
    }
}

/* ============================================
   ENHANCE PROGRESS OVERLAY
   ============================================ */
.enhance-progress-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.95);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    backdrop-filter: blur(4px);
}

.enhance-progress-content {
    text-align: center;
    padding: 20px;
}

.enhance-progress-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(168, 85, 247, 0.3);
    border-top-color: #a855f7;
    border-radius: 50%;
    margin: 0 auto 15px;
    animation: enhance-spin 1s linear infinite;
}

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

.enhance-progress-text {
    color: #f1f5f9;
    font-size: 14px;
    margin-bottom: 15px;
    font-weight: 500;
}

.enhance-progress-bar {
    width: 200px;
    height: 4px;
    background: rgba(168, 85, 247, 0.2);
    border-radius: 2px;
    overflow: hidden;
    margin: 0 auto;
}

.enhance-progress-bar-fill {
    height: 100%;
    width: 30%;
    background: linear-gradient(90deg, #a855f7, #8b5cf6);
    border-radius: 2px;
    animation: enhance-progress 1.5s ease-in-out infinite;
}

@keyframes enhance-progress {
    0% { width: 0%; margin-left: 0%; }
    50% { width: 60%; margin-left: 20%; }
    100% { width: 0%; margin-left: 100%; }
}

.enhance-success-icon {
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, #10b981, #059669);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 10px;
    font-size: 24px;
    color: white;
    animation: enhance-pop 0.3s ease-out;
}

@keyframes enhance-pop {
    0% { transform: scale(0); }
    70% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.enhance-progress-content.enhance-success .enhance-progress-text {
    color: #10b981;
    font-weight: 600;
}

/* ============================================
   PASTE MODAL - For clipboard paste on HTTP
   ============================================ */

.paste-modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 10000;
    justify-content: center;
    align-items: center;
}

.paste-modal {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 30px;
    text-align: center;
    max-width: 420px;
    width: 90%;
    position: relative;
    border: 1px solid var(--border);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.paste-modal-close {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    transition: color 0.2s;
}

.paste-modal-close:hover {
    color: var(--text);
}

.paste-modal-icon {
    font-size: 48px;
    margin-bottom: 15px;
}

.paste-modal h3 {
    color: var(--text);
    margin: 0 0 10px 0;
    font-size: 20px;
}

.paste-modal p {
    color: var(--text-muted);
    margin: 0 0 20px 0;
}

.paste-modal kbd {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px 8px;
    font-family: monospace;
    color: var(--text);
    font-size: 13px;
}

.paste-capture-area {
    width: 100%;
    height: 120px;
    background: var(--bg-input);
    border: 2px dashed var(--primary);
    border-radius: 8px;
    color: var(--text-muted);
    resize: none;
    padding: 15px;
    font-size: 14px;
    box-sizing: border-box;
    transition: border-color 0.2s, background 0.2s;
}

.paste-capture-area:focus {
    outline: none;
    border-color: #9f7aea;
    background: var(--bg);
    color: var(--text);
}

.paste-capture-area::placeholder {
    color: var(--text-muted);
}

/* ============================================
   WATERMARK REMOVAL STYLES
   ============================================ */

/* Watermark canvas wrapper */
.watermark-canvas-wrapper {
    position: relative;
    display: inline-block;
}

.watermark-mask-canvas {
    position: absolute;
    top: 0;
    left: 0;
    touch-action: none;
    z-index: 10;
}

/* Watermark upload area */
#watermarkUploadArea {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 30px;
    text-align: center;
    transition: all 0.3s ease;
    background: var(--bg-input);
    cursor: pointer;
}

#watermarkUploadArea:hover,
#watermarkUploadArea.dragover {
    border-color: var(--primary);
    background: rgba(168, 85, 247, 0.1);
}

#watermarkPreviewContainer {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

/* Watermark mode buttons */
#watermarkArea .mode-btn {
    flex: 1;
    max-width: 200px;
}

/* Comparison slider */
.comparison-slider {
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
}

.comparison-before,
.comparison-after {
    position: relative;
    max-width: 300px;
}

.comparison-before img,
.comparison-after img {
    width: 100%;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.comparison-label {
    position: absolute;
    bottom: 10px;
    left: 10px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
}

/* Watermark result area */
#watermarkResult .comparison-after .comparison-label {
    background: rgba(0, 255, 136, 0.8);
}

/* Brush size slider */
#watermarkBrushSize {
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    outline: none;
}

#watermarkBrushSize::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
}

#watermarkBrushSize::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

/* ============================================
   TIPS/NOTES STYLES
   ============================================ */

/* Tips sidebar section */
.tips-list {
    max-height: 300px;
    overflow-y: auto;
    padding: 5px 0;
}

.tip-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    margin: 4px 8px;
    background: var(--bg-input);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.tip-item:hover {
    background: var(--bg-hover);
    border-color: var(--border);
}

.tip-item-title {
    flex: 1;
    font-size: 0.9rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 8px;
}

.tip-item-date {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.tips-empty {
    padding: 15px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-style: italic;
}

/* Tip Modal Styles */
.tip-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.tip-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.tip-modal-content {
    background: var(--bg-card);
    border-radius: 16px;
    width: 90%;
    max-width: 900px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.tip-modal-overlay.active .tip-modal-content {
    transform: scale(1);
}

.tip-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}

.tip-modal-header h2 {
    margin: 0;
    font-size: 1.3rem;
    color: var(--text);
}

.tip-modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 5px;
    line-height: 1;
    transition: color 0.2s ease;
}

.tip-modal-close:hover {
    color: var(--danger);
}

.tip-modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.tip-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
}

/* Tip Form */
.tip-form-group {
    margin-bottom: 20px;
}

.tip-form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text);
}

.tip-form-group input[type="text"] {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 1rem;
    transition: border-color 0.2s ease;
}

.tip-form-group input[type="text"]:focus {
    outline: none;
    border-color: var(--primary);
}

/* Tip Modal specific overrides */
.tip-modal-content .form-group label {
    color: #ffffff !important;
    font-weight: 600;
}

.tip-modal-content .form-input,
.tip-modal-content .form-textarea {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: #ffffff;
}

/* EasyMDE Customizations */
.EasyMDEContainer {
    border-radius: 8px;
    overflow: hidden;
}

.EasyMDEContainer .CodeMirror {
    background: var(--bg-input) !important;
    color: var(--text) !important;
    border: 1px solid var(--border) !important;
    border-radius: 0 0 8px 8px !important;
    min-height: 300px;
}

.EasyMDEContainer .CodeMirror-cursor {
    border-left: 2px solid var(--primary) !important;
}

.EasyMDEContainer .CodeMirror-selected {
    background: rgba(168, 85, 247, 0.3) !important;
}

.EasyMDEContainer .CodeMirror-linenumber {
    color: var(--text-secondary) !important;
}

.EasyMDEContainer .CodeMirror-gutters {
    background: var(--bg-secondary) !important;
    border-right: 1px solid var(--border) !important;
}

.EasyMDEContainer .editor-toolbar {
    background: var(--bg-secondary) !important;
    border: 1px solid var(--border) !important;
    border-bottom: none !important;
    border-radius: 8px 8px 0 0 !important;
    padding: 8px !important;
}

.EasyMDEContainer .editor-toolbar button {
    color: #ffffff !important;
    border: none !important;
    background: transparent !important;
    border-radius: 4px !important;
    transition: background 0.2s ease !important;
}

.EasyMDEContainer .editor-toolbar button i,
.EasyMDEContainer .editor-toolbar button::before {
    color: #ffffff !important;
}

.EasyMDEContainer .editor-toolbar a {
    color: #ffffff !important;
}

.EasyMDEContainer .editor-toolbar button:hover {
    background: rgba(255, 255, 255, 0.1) !important;
}

.EasyMDEContainer .editor-toolbar button.active {
    background: var(--primary) !important;
    color: white !important;
}

.EasyMDEContainer .editor-toolbar i.separator {
    border-left: 1px solid var(--border) !important;
    margin: 0 8px !important;
}

.EasyMDEContainer .editor-statusbar {
    background: var(--bg-secondary) !important;
    color: var(--text-secondary) !important;
    border-top: 1px solid var(--border) !important;
    padding: 8px 12px !important;
}

.EasyMDEContainer .editor-preview {
    background: var(--bg-input) !important;
    color: var(--text) !important;
}

.EasyMDEContainer .editor-preview-side {
    background: var(--bg-input) !important;
    color: var(--text) !important;
    border: 1px solid var(--border) !important;
}

/* Markdown Content Rendering */
.markdown-content {
    line-height: 1.7;
    color: var(--text);
}

.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4,
.markdown-content h5,
.markdown-content h6 {
    margin-top: 24px;
    margin-bottom: 12px;
    color: var(--text);
    font-weight: 600;
}

.markdown-content h1 { font-size: 2rem; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.markdown-content h2 { font-size: 1.5rem; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.markdown-content h3 { font-size: 1.25rem; }
.markdown-content h4 { font-size: 1.1rem; }
.markdown-content h5 { font-size: 1rem; }
.markdown-content h6 { font-size: 0.9rem; color: var(--text-secondary); }

.markdown-content p {
    margin-bottom: 16px;
}

.markdown-content ul,
.markdown-content ol {
    margin-bottom: 16px;
    padding-left: 24px;
}

.markdown-content li {
    margin-bottom: 6px;
}

.markdown-content blockquote {
    margin: 16px 0;
    padding: 12px 20px;
    border-left: 4px solid var(--primary);
    background: var(--bg-input);
    border-radius: 0 8px 8px 0;
    color: var(--text-secondary);
}

.markdown-content code {
    background: var(--bg-input);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Fira Code', 'Consolas', monospace;
    font-size: 0.9em;
    color: var(--accent);
}

.markdown-content pre {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    overflow-x: auto;
    margin: 16px 0;
}

.markdown-content pre code {
    background: transparent;
    padding: 0;
    color: var(--text);
}

.markdown-content a {
    color: var(--primary);
    text-decoration: none;
}

.markdown-content a:hover {
    text-decoration: underline;
}

.markdown-content img {
    max-width: 100%;
    border-radius: 8px;
    margin: 16px 0;
}

.markdown-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
}

.markdown-content th,
.markdown-content td {
    border: 1px solid var(--border);
    padding: 10px 12px;
    text-align: left;
}

.markdown-content th {
    background: var(--bg-secondary);
    font-weight: 600;
}

.markdown-content tr:nth-child(even) {
    background: var(--bg-input);
}

.markdown-content hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 24px 0;
}

/* Tip View Modal Specific */
.tip-view-meta {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.tip-view-meta i {
    margin-right: 6px;
}

.tip-view-content {
    background: var(--bg-input);
    border-radius: 8px;
    padding: 24px;
    min-height: 200px;
}

.tip-view-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

/* Export Dropdown */
.tip-export-dropdown {
    position: relative;
    display: inline-block;
}

.tip-export-btn {
    display: flex;
    align-items: center;
    gap: 6px;
}

.tip-export-menu {
    position: absolute;
    bottom: 100%;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    min-width: 180px;
    padding: 8px 0;
    z-index: 1000;
    margin-bottom: 8px;
}

.tip-export-menu button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 16px;
    background: none;
    border: none;
    color: var(--text);
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s ease;
    text-align: left;
}

.tip-export-menu button:hover {
    background: var(--bg-hover);
}

.tip-export-menu button i {
    width: 20px;
    text-align: center;
    color: var(--text-secondary);
}

/* Grammar Check Button */
.tip-grammar-btn {
    margin-left: auto;
}

.grammar-issues {
    margin-top: 12px;
    padding: 12px;
    background: rgba(255, 193, 7, 0.1);
    border: 1px solid rgba(255, 193, 7, 0.3);
    border-radius: 8px;
}

.grammar-issue {
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 193, 7, 0.2);
}

.grammar-issue:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.grammar-issue-text {
    color: var(--warning);
    font-weight: 500;
}

.grammar-issue-suggestion {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-top: 4px;
}

/* Toast Notification */
.tip-toast {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px 24px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    z-index: 20000;
    display: flex;
    align-items: center;
    gap: 12px;
    animation: tipToastFade 0.3s ease;
}

.tip-toast.success {
    border-color: var(--success);
}

.tip-toast.success i {
    color: var(--success);
}

.tip-toast.error {
    border-color: var(--danger);
}

.tip-toast.error i {
    color: var(--danger);
}

@keyframes tipToastFade {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Spell Check Error Styling */
.cm-spell-error {
    background: rgba(255, 0, 0, 0.1);
    border-bottom: 2px wavy red;
}

/* ==================== Tips Tree Structure ==================== */

/* Main topic container */
.tip-topic {
    margin-bottom: 4px;
}

/* Topic header row */
.tip-topic-header {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s ease;
    gap: 8px;
}

.tip-topic-header:hover {
    background: var(--bg-hover);
}

/* Expand/collapse icon */
.tip-expand-icon {
    font-size: 10px;
    color: var(--text-secondary);
    transition: transform 0.2s ease;
    width: 16px;
    text-align: center;
    flex-shrink: 0;
}

.tip-topic.expanded .tip-expand-icon {
    transform: rotate(90deg);
}

/* Topic title */
.tip-topic-title {
    flex: 1;
    color: var(--text);
    font-weight: 500;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Add thread button */
.tip-add-thread-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.tip-topic-header:hover .tip-add-thread-btn {
    opacity: 1;
}

.tip-add-thread-btn:hover {
    background: var(--primary);
    color: white;
}

/* Threads container */
.tip-threads {
    margin-left: 24px;
    padding-left: 12px;
    border-left: 1px solid var(--border);
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease;
}

.tip-threads.collapsed {
    max-height: 0;
    opacity: 0;
    pointer-events: none;
}

.tip-threads.expanded {
    max-height: 1000px;
    opacity: 1;
}

/* Individual thread */
.tip-thread {
    display: flex;
    align-items: center;
    padding: 6px 10px;
    margin: 2px 0;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s ease;
    gap: 6px;
}

.tip-thread:hover {
    background: var(--bg-hover);
}

/* Thread tree connector icon */
.tip-thread-icon {
    color: var(--text-secondary);
    font-size: 0.75rem;
    opacity: 0.5;
    flex-shrink: 0;
}

/* Thread title */
.tip-thread-title {
    flex: 1;
    color: var(--text-secondary);
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tip-thread:hover .tip-thread-title {
    color: var(--text);
}

/* Empty state for tips */
.tips-empty {
    padding: 16px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* Tip modal form label visibility fix */
.tip-modal-content .form-group label {
    color: #ffffff !important;
    font-weight: 600;
    margin-bottom: 8px;
    display: block;
}

/* Parent topic selector in modal */
.tip-parent-selector {
    margin-bottom: 16px;
}

.tip-parent-selector label {
    color: var(--text) !important;
    font-weight: 500;
    margin-bottom: 8px;
    display: block;
}

.tip-parent-selector select {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.9rem;
}

.tip-parent-selector select:focus {
    outline: none;
    border-color: var(--primary);
}

/* Tips sidebar section specific styling */
#tipsList {
    max-height: 300px;
    overflow-y: auto;
    padding: 4px 0;
}

#tipsList::-webkit-scrollbar {
    width: 6px;
}

#tipsList::-webkit-scrollbar-track {
    background: transparent;
}

#tipsList::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

#tipsList::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ============================================
   UGC VIDEO GENERATION STYLES
   ============================================ */

/* UGC Sidebar Section */
.ugc-sidebar-section {
    border-top: 1px solid var(--border);
    padding-top: 12px;
    margin-top: 8px;
}

.ugc-memory-status {
    padding: 8px 12px;
    margin-bottom: 8px;
}

.ugc-memory-status .memory-bar {
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 4px;
}

.ugc-memory-status .memory-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s ease, background-color 0.3s ease;
}

.ugc-memory-status .memory-fill.status-ok {
    background: var(--success, #10b981);
}

.ugc-memory-status .memory-fill.status-warning {
    background: var(--warning, #f59e0b);
}

.ugc-memory-status .memory-fill.status-critical {
    background: var(--danger, #ef4444);
}

.ugc-memory-status .memory-fill.status-emergency {
    background: #dc2626;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.ugc-memory-status .memory-text {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ugc-memory-status .memory-status {
    font-weight: 500;
}

.ugc-memory-status .memory-status.status-ok {
    color: var(--success, #10b981);
}

.ugc-memory-status .memory-status.status-warning {
    color: var(--warning, #f59e0b);
}

.ugc-memory-status .memory-status.status-critical,
.ugc-memory-status .memory-status.status-emergency {
    color: var(--danger, #ef4444);
}

/* UGC Template List */
.ugc-template-list {
    max-height: 200px;
    overflow-y: auto;
    padding: 4px 0;
}

.ugc-template-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    margin: 4px 8px;
    background: var(--bg-input);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.ugc-template-item:hover {
    background: var(--bg-hover);
    border-color: var(--primary);
}

.ugc-template-item .template-icon {
    font-size: 1.1rem;
}

.ugc-template-item .template-name {
    font-size: 0.85rem;
    color: var(--text);
}

/* UGC Model Status */
.ugc-model-status {
    padding: 8px 12px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-indicator.status-active {
    background: var(--success, #10b981);
}

.status-indicator.status-inactive {
    background: var(--text-secondary);
}

/* UGC Generate Modal */
.ugc-modal-content {
    background: var(--bg-card);
}

.ugc-template-info {
    background: var(--bg-input);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
}

.ugc-template-info .template-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.ugc-template-info .template-header h4 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text);
}

.ugc-template-info .template-vram {
    font-size: 0.8rem;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    padding: 4px 8px;
    border-radius: 4px;
}

.ugc-template-info .template-desc {
    margin: 0 0 12px 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.ugc-template-info .template-tags {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.ugc-template-info .template-tags .tag {
    background: var(--primary);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
}

/* Input with button */
.input-with-button {
    display: flex;
    gap: 8px;
}

.input-with-button input {
    flex: 1;
}

/* Form hint text */
.form-hint {
    display: block;
    margin-top: 4px;
    font-size: 0.8rem;
    color: var(--text-muted, #6b7280);
    font-style: italic;
}

/* Memory indicator in modal */
.ugc-memory-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-input);
    border-radius: 6px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 16px;
}

.ugc-memory-indicator .memory-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.ugc-memory-indicator .memory-indicator.status-ok {
    background: var(--success, #10b981);
}

.ugc-memory-indicator .memory-indicator.status-warning {
    background: var(--warning, #f59e0b);
}

.ugc-memory-indicator .memory-indicator.status-critical,
.ugc-memory-indicator .memory-indicator.status-emergency {
    background: var(--danger, #ef4444);
}

/* Progress Section */
.progress-header {
    text-align: center;
    margin-bottom: 20px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

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

.progress-bar-outer {
    height: 12px;
    background: var(--bg-input);
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 12px;
}

.progress-bar-inner {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    border-radius: 6px;
    transition: width 0.3s ease;
}

.progress-status {
    font-size: 0.9rem;
    color: var(--text);
}

.progress-status .success-text {
    color: var(--success, #10b981);
    font-weight: 600;
}

.progress-status .error-text {
    color: var(--danger, #ef4444);
    font-weight: 600;
}

.progress-status .error-detail {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 8px;
}

/* ==========================================
   Marketing Page Styles
   ========================================== */

.marketing-page-header {
    margin-bottom: 24px;
}

.marketing-page-header .page-title {
    font-size: 1.75rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text);
}

.marketing-content {
    max-width: 1200px;
}

/* Memory Status Bar */
.marketing-memory-status {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-card);
    border-radius: 8px;
    margin-bottom: 24px;
}

.marketing-memory-status .memory-label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
}

.marketing-memory-status .memory-bar {
    flex: 1;
    height: 8px;
    background: var(--bg-input);
    border-radius: 4px;
    overflow: hidden;
}

.marketing-memory-status .memory-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease;
}

.marketing-memory-status .memory-fill.status-ok {
    background: var(--success, #10b981);
}

.marketing-memory-status .memory-fill.status-warning {
    background: var(--warning, #f59e0b);
}

.marketing-memory-status .memory-fill.status-critical,
.marketing-memory-status .memory-fill.status-emergency {
    background: var(--danger, #ef4444);
}

.marketing-memory-status .memory-text {
    font-size: 0.85rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* Marketing Sections */
.marketing-section {
    margin-bottom: 32px;
}

.marketing-section .section-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text);
}

.marketing-section .section-subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}

/* AI Template Suggestion Box */
.ai-suggestion-box {
    background: linear-gradient(135deg, rgba(139,92,246,0.1), rgba(59,130,246,0.1));
    border: 1px solid rgba(139,92,246,0.2);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 20px;
}

.ai-suggestion-input-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.ai-suggestion-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-input);
    color: var(--text);
    font-size: 0.95rem;
    transition: border-color 0.2s ease;
}

.ai-suggestion-input:focus {
    outline: none;
    border-color: var(--primary);
}

.ai-suggestion-input::placeholder {
    color: var(--text-muted);
}

.btn-suggest {
    padding: 12px 20px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.2s ease, transform 0.1s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-suggest:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-suggest:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

/* Spinner for loading state */
.spinner-small {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Suggestion Results */
.ai-suggestion-results {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid rgba(139,92,246,0.2);
}

.suggestion-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 20px;
    color: var(--text-muted);
}

.suggestion-loading .spinner-small {
    border-color: rgba(139,92,246,0.3);
    border-top-color: var(--primary);
}

.suggestion-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.suggestion-count {
    font-weight: 500;
    color: var(--success);
}

.btn-show-all-templates {
    padding: 6px 12px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-show-all-templates:hover {
    background: var(--bg-hover);
    color: var(--text);
    border-color: var(--text-muted);
}

.suggestion-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.suggestion-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.suggestion-item:hover {
    background: var(--bg-hover);
    border-color: var(--primary);
    transform: translateX(4px);
}

.suggestion-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.suggestion-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.suggestion-name {
    font-weight: 600;
    color: var(--text);
}

.suggestion-reason {
    font-size: 0.85rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.suggestion-score {
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
    flex-shrink: 0;
}

.suggestion-score.high {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
}

.suggestion-score.medium {
    background: rgba(245, 158, 11, 0.2);
    color: #f59e0b;
}

.suggestion-score.low {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

/* No Match Box */
.no-match-box {
    background: rgba(245,158,11,0.1);
    border: 1px dashed #f59e0b;
    border-radius: 8px;
    padding: 20px;
    text-align: center;
}

.no-match-icon {
    font-size: 2rem;
    display: block;
    margin-bottom: 8px;
}

.no-match-text {
    font-weight: 500;
    color: var(--text);
    display: block;
}

.no-match-subtext {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin: 8px 0 16px;
}

.no-match-hint {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid rgba(139,92,246,0.2);
    font-size: 0.9rem;
    color: var(--text-muted);
}

.no-match-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.btn-create-custom {
    padding: 10px 20px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
}

.btn-create-custom:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.custom-suggestion-preview {
    background: var(--bg-card);
    border-radius: 8px;
    padding: 12px;
    margin: 12px 0;
    text-align: left;
}

.custom-preview-name {
    font-weight: 600;
    color: var(--text);
    margin-top: 4px;
}

.custom-preview-tags {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Template Grid */
/* Collapsible Templates Section */
.templates-section {
    transition: all 0.3s ease;
}

.templates-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    cursor: pointer;
    padding: 4px 0;
    margin-bottom: 16px;
    border-radius: 8px;
    transition: background 0.2s ease;
}

.templates-header:hover {
    background: rgba(var(--primary-rgb, 139, 92, 246), 0.05);
    margin: -8px;
    padding: 12px 8px;
    margin-bottom: 8px;
}

.templates-section.collapsed .templates-header {
    margin-bottom: 0;
}

.templates-section.collapsed .templates-header:hover {
    margin-bottom: -8px;
}

.templates-header-left {
    flex: 1;
}

.templates-header-left .section-title {
    margin-bottom: 4px;
}

.templates-header-left .section-subtitle {
    margin: 0;
    transition: opacity 0.2s ease;
}

.templates-header-right {
    display: flex;
    align-items: center;
    padding-top: 4px;
}

.collapse-icon {
    color: var(--text-muted);
    transition: transform 0.3s ease;
}

.templates-section.collapsed .collapse-icon {
    transform: rotate(-90deg);
}

/* Collapsed view - selected template preview */
.templates-collapsed {
    margin-top: 16px;
}

.selected-template-preview {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    background: var(--bg-input);
    border: 2px solid var(--primary);
    border-radius: 12px;
}

.selected-template-preview .preview-icon {
    font-size: 2.5rem;
    flex-shrink: 0;
}

.selected-template-preview .preview-info {
    flex: 1;
    min-width: 0;
}

.selected-template-preview .preview-name {
    display: block;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 2px;
}

.selected-template-preview .preview-desc {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-change-template {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-card);
    color: var(--text);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.btn-change-template:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* Expanded view */
.templates-expanded {
    transition: opacity 0.2s ease;
}

.marketing-template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
}

/* Load More Button */
.template-load-more-wrapper {
    grid-column: 1 / -1;
    display: flex;
    justify-content: center;
    padding: 16px 0;
}

.btn-load-more-templates {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    border: 2px dashed var(--border);
    border-radius: 10px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-load-more-templates:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(var(--primary-rgb, 139, 92, 246), 0.05);
}

.btn-load-more-templates .load-more-count {
    font-size: 0.8rem;
    opacity: 0.7;
}

.btn-load-more-templates.btn-show-less {
    border-style: solid;
    border-color: var(--border);
}

.btn-load-more-templates.btn-show-less:hover {
    border-color: var(--text-muted);
    color: var(--text);
}

.marketing-template-card {
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 20px 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.template-edit-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: var(--bg-input);
    color: var(--text-muted);
    cursor: pointer;
    opacity: 0;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.marketing-template-card:hover .template-edit-btn {
    opacity: 1;
}

.template-edit-btn:hover {
    background: var(--primary);
    color: white;
}

/* Frequent template badge */
.frequent-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: #f59e0b;
    background: rgba(245, 158, 11, 0.15);
    border-radius: 50%;
}

.marketing-template-card.frequent-template {
    border-color: rgba(245, 158, 11, 0.3);
}

.marketing-template-card.frequent-template:hover {
    border-color: var(--primary);
}

.marketing-template-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.marketing-template-card.selected {
    border-color: var(--primary);
    background: rgba(var(--primary-rgb, 139, 92, 246), 0.1);
}

.marketing-template-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
}

.marketing-template-name {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}

.marketing-template-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.3;
}

.template-loading,
.template-empty,
.template-error {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

.template-error {
    color: var(--danger, #ef4444);
}

/* Form Section */
.marketing-form-section {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 24px;
}

.selected-template-info {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: var(--bg-input);
    border-radius: 8px;
    margin-bottom: 20px;
}

.selected-template-info .selected-icon {
    font-size: 2rem;
}

.selected-template-info .selected-name {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
}

.selected-template-info .selected-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-left: auto;
}

/* Marketing Image Upload */
.marketing-upload-area {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--bg-input);
    min-height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.marketing-upload-area:hover {
    border-color: var(--primary);
    background: rgba(var(--primary-rgb, 139, 92, 246), 0.05);
}

.marketing-upload-area.drag-over {
    border-color: var(--primary);
    background: rgba(var(--primary-rgb, 139, 92, 246), 0.1);
    border-style: solid;
}

.upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.upload-placeholder .upload-icon {
    font-size: 2.5rem;
}

.upload-placeholder .upload-text {
    font-size: 1rem;
    color: var(--text);
    font-weight: 500;
}

.upload-placeholder .upload-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.upload-preview {
    position: relative;
    width: 100%;
    max-width: 300px;
}

.upload-preview img {
    width: 100%;
    height: auto;
    max-height: 200px;
    object-fit: contain;
    border-radius: 8px;
}

.preview-remove {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--danger, #ef4444);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
}

.preview-remove:hover {
    transform: scale(1.1);
}

/* Multi-Image Upload Area */
.multi-image-upload-area {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 16px;
    background: var(--bg-input);
    transition: all 0.2s ease;
}

.multi-image-upload-area.drag-over {
    border-color: var(--primary);
    background: rgba(var(--primary-rgb, 139, 92, 246), 0.1);
    border-style: solid;
}

.image-count-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: normal;
    margin-left: 8px;
}

.image-slots {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: flex-start;
}

.image-slot {
    flex: 0 0 auto;
    width: 140px;
}

.slot-upload {
    width: 140px;
    height: 120px;
    border: 2px dashed var(--border);
    border-radius: 10px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: all 0.2s ease;
    background: var(--bg-card);
}

.slot-upload:hover {
    border-color: var(--primary);
    background: rgba(var(--primary-rgb, 139, 92, 246), 0.05);
}

.image-slot.required .slot-upload {
    border-color: var(--primary);
}

.image-slot.optional .slot-upload {
    border-style: dotted;
    opacity: 0.7;
}

.image-slot.optional:hover .slot-upload {
    opacity: 1;
}

.image-slot.has-image .slot-upload {
    border-style: solid;
    border-color: var(--success);
    opacity: 1;
}

.slot-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 12px;
    text-align: center;
}

.slot-icon {
    font-size: 1.8rem;
    margin-bottom: 4px;
}

.slot-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.slot-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.slot-preview {
    width: 100%;
    height: 100%;
    position: relative;
}

.slot-preview-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px;
}

.slot-label-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0,0,0,0.7));
    color: white;
    font-size: 0.75rem;
    padding: 16px 8px 6px;
    text-align: center;
    border-radius: 0 0 8px 8px;
}

.slot-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--danger, #ef4444);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.slot-upload:hover .slot-remove {
    opacity: 1;
}

.slot-remove:hover {
    transform: scale(1.1);
}

.upload-drag-hint {
    text-align: center;
    margin-top: 12px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Duration Selector */
.duration-selector {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.duration-btn {
    padding: 10px 20px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-input);
    color: var(--text);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.duration-btn:hover {
    border-color: var(--primary);
}

.duration-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Form Actions */
.form-actions {
    margin-top: 20px;
}

.btn-large {
    padding: 14px 32px;
    font-size: 1rem;
}

/* Progress Section */
.marketing-progress-section {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 32px;
    text-align: center;
}

.progress-info {
    margin-bottom: 24px;
}

.progress-job-id {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Results Section */
.marketing-results-section {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 24px;
}

.result-video-container {
    margin-bottom: 20px;
}

.result-video {
    width: 100%;
    max-width: 800px;
    border-radius: 8px;
    background: #000;
}

.result-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

/* Gallery */
.marketing-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 16px;
}

.marketing-gallery .empty-gallery {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
    font-style: italic;
}

.gallery-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s ease;
}

.gallery-item:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
}

.gallery-thumb {
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    background: var(--bg-input);
}

.gallery-info {
    padding: 8px 12px;
}

.gallery-template {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Responsive */
@media (max-width: 768px) {
    .marketing-template-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .selected-template-info {
        flex-direction: column;
        text-align: center;
    }

    .selected-template-info .selected-desc {
        margin-left: 0;
    }

    .duration-selector {
        justify-content: center;
    }

    .result-actions {
        flex-direction: column;
    }

    /* Collapsed template preview mobile */
    .selected-template-preview {
        flex-wrap: wrap;
        gap: 12px;
    }

    .selected-template-preview .preview-icon {
        font-size: 2rem;
    }

    .selected-template-preview .preview-info {
        flex-basis: calc(100% - 60px);
    }

    .btn-change-template {
        width: 100%;
        text-align: center;
    }
}

/* ============================================
   Template Editor Overlay
   ============================================ */

.template-editor-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.template-editor-overlay.active {
    opacity: 1;
    visibility: visible;
}

.template-editor-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.template-editor-dialog {
    position: relative;
    width: 90%;
    max-width: 650px;
    max-height: 90vh;
    background: var(--bg-card);
    border-radius: 16px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.template-editor-overlay.active .template-editor-dialog {
    transform: translateY(0);
}

.template-editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.template-editor-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.1rem;
    color: var(--text);
}

.template-editor-title .editor-icon {
    font-size: 1.5rem;
}

.template-editor-close {
    width: 36px;
    height: 36px;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.template-editor-close:hover {
    background: var(--bg-input);
    color: var(--text);
}

.template-editor-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.editor-section {
    margin-bottom: 20px;
}

.editor-section-half {
    flex: 1;
}

.editor-row {
    display: flex;
    gap: 24px;
}

.editor-label {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
}

.editor-hint {
    display: block;
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-muted);
    margin-top: 2px;
}

.editor-value {
    float: right;
    font-weight: 500;
    color: var(--primary);
}

.editor-textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-input);
    color: var(--text);
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.85rem;
    line-height: 1.5;
    resize: vertical;
    transition: border-color 0.2s ease;
}

.editor-textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.editor-textarea::placeholder {
    color: var(--text-muted);
}

.editor-slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-input);
    appearance: none;
    outline: none;
    cursor: pointer;
}

.editor-slider::-webkit-slider-thumb {
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    transition: transform 0.2s ease;
}

.editor-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.editor-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border: none;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
}

.editor-slider-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.editor-info {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 14px;
    background: rgba(var(--primary-rgb, 139, 92, 246), 0.1);
    border-radius: 8px;
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.editor-info svg {
    flex-shrink: 0;
    margin-top: 2px;
    color: var(--primary);
}

.template-editor-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
}

.editor-footer-right {
    display: flex;
    gap: 12px;
}

/* Mobile adjustments for editor */
@media (max-width: 600px) {
    .template-editor-dialog {
        width: 95%;
        max-height: 95vh;
    }

    .editor-row {
        flex-direction: column;
        gap: 20px;
    }

    .template-editor-footer {
        flex-direction: column;
        gap: 12px;
    }

    .editor-footer-right {
        width: 100%;
        justify-content: stretch;
    }

    .editor-footer-right .btn-secondary,
    .editor-footer-right .btn-primary {
        flex: 1;
    }
}

/* ========================================
   CODE ASSISTANT - Goose AI Integration
   ======================================== */

.code-page-header {
    padding: 16px 24px;
    margin-bottom: 0;
}

.code-page-header .section-description {
    color: var(--text-muted, #999);
    margin-top: 8px;
    font-size: 0.9rem;
}

/* Main container */
.code-assistant-container {
    display: flex;
    flex-direction: column;
    max-width: 900px;
    margin: 0 auto;
    padding: 0 24px 24px;
}

/* Chat History - reasonable size */
.goose-chat-history {
    overflow-y: auto;
    border: 1px solid var(--border-color, #333);
    border-radius: 12px;
    padding: 16px;
    background: var(--bg-primary, #121212);
    min-height: 150px;
    max-height: 300px;
}

/* Input wrapper - fixed at bottom */
.goose-input-wrapper {
    flex-shrink: 0;
    padding-top: 16px;
    background: var(--bg-primary, #121212);
}

/* Welcome Message */
.goose-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px 10px;
    text-align: center;
    color: var(--text-muted, #999);
}

.goose-welcome-icon {
    font-size: 32px;
    margin-bottom: 8px;
}

.goose-welcome h3 {
    color: var(--text-primary, #fff);
    margin-bottom: 4px;
    font-size: 1rem;
}

.goose-welcome p {
    margin-bottom: 12px;
    font-size: 0.85rem;
}

.goose-examples {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    align-items: center;
}

.example-label {
    font-size: 0.85rem;
    color: var(--text-muted, #666);
}

.example-btn {
    padding: 4px 10px;
    font-size: 0.75rem;
    background: var(--bg-secondary, #1e1e1e);
    border: 1px solid var(--border-color, #333);
    border-radius: 12px;
    color: var(--text-primary, #fff);
    cursor: pointer;
    transition: all 0.2s ease;
}

.example-btn:hover {
    background: var(--accent-color, #a855f7);
    border-color: var(--accent-color, #a855f7);
}

/* Chat Messages */
.goose-message {
    margin-bottom: 16px;
    padding: 12px 16px;
    border-radius: 12px;
    max-width: 85%;
    animation: messageSlideIn 0.3s ease;
    position: relative;
}

.copy-msg-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 6px;
    color: rgba(255,255,255,0.4);
    padding: 3px 6px;
    cursor: pointer;
    font-size: 0.7rem;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.goose-message:hover .copy-msg-btn {
    opacity: 1;
}

.copy-msg-btn:hover {
    background: rgba(168, 85, 247, 0.25);
    border-color: rgba(168, 85, 247, 0.5);
    color: #c084fc;
}

.copy-msg-btn.copied {
    color: #22c55e;
    border-color: rgba(34, 197, 94, 0.4);
    background: rgba(34, 197, 94, 0.1);
    opacity: 1;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.goose-message.user {
    background: var(--accent-color, #a855f7);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.goose-message.assistant {
    background: var(--bg-secondary, #1e1e1e);
    border: 1px solid var(--border-color, #333);
    margin-right: auto;
    border-bottom-left-radius: 4px;
}

.goose-message.error {
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid #ef4444;
    color: #fca5a5;
}

.goose-message.system {
    background: rgba(59, 130, 246, 0.2);
    border: 1px solid #3b82f6;
    color: #93c5fd;
    text-align: center;
    max-width: 100%;
}

.goose-message.thinking {
    background: transparent;
    max-width: 100%;
    text-align: center;
}

.message-role {
    font-weight: 600;
    font-size: 0.75rem;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.8;
}

.message-content {
    font-size: 0.9rem;
    line-height: 1.6;
    word-wrap: break-word;
}

.message-content code.inline-code {
    background: rgba(168, 85, 247, 0.2);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Fira Code', 'Monaco', 'Menlo', monospace;
    font-size: 0.85em;
}

.message-content pre.code-block {
    background: #0d0d0d;
    border-radius: 8px;
    padding: 12px;
    margin: 8px 0;
    overflow-x: auto;
}

.message-content pre.code-block code {
    font-family: 'Fira Code', 'Monaco', 'Menlo', monospace;
    font-size: 0.85rem;
    line-height: 1.5;
}

/* Thinking Animation */
.thinking-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px;
}

.thinking-dot {
    width: 8px;
    height: 8px;
    background: var(--accent-color, #a855f7);
    border-radius: 50%;
    animation: thinkingPulse 1.4s ease-in-out infinite;
}

.thinking-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.thinking-dot:nth-child(3) {
    animation-delay: 0.4s;
}

.thinking-text {
    margin-left: 8px;
    color: var(--text-muted, #999);
    font-size: 0.85rem;
}

@keyframes thinkingPulse {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Input Area */
.goose-input-area {
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    gap: 12px;
    margin-bottom: 12px;
    width: 100%;
}

.goose-input-area textarea#goose-input {
    flex: 1 1 auto !important;
    width: calc(100% - 100px) !important;
    min-width: 200px !important;
    resize: vertical;
    min-height: 60px;
    max-height: 150px;
    padding: 12px;
    border: 1px solid var(--border-color, #333);
    border-radius: 12px;
    background: var(--bg-primary, #121212);
    color: var(--text-primary, #fff);
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.2s ease;
    box-sizing: border-box;
    display: block;
}

.goose-input-area textarea#goose-input:focus {
    outline: none;
    border-color: var(--accent-color, #a855f7);
}

.goose-input-area textarea#goose-input::placeholder {
    color: var(--text-muted, #666);
}

.goose-input-area button#goose-send,
.goose-input-area .btn,
.goose-input-area .btn-primary {
    flex: 0 0 auto !important;
    width: auto !important;
    min-width: 80px !important;
    max-width: 120px !important;
    padding: 12px 24px;
    font-weight: 600;
}

/* Controls */
.goose-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Toolbar right group: font size + fullscreen + status */
.goose-toolbar-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.goose-tool-btn {
    background: var(--bg-secondary, #1e1e1e);
    border: 1px solid var(--border-color, #333);
    border-radius: 6px;
    color: var(--text-muted, #999);
    padding: 4px 8px;
    font-size: 0.75rem;
    cursor: pointer;
    line-height: 1;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.goose-tool-btn:hover {
    background: var(--accent-color, #a855f7);
    border-color: var(--accent-color, #a855f7);
    color: #fff;
}

/* Fullscreen overlay */
#page-code.code-fullscreen-mode {
    position: fixed;
    inset: 0;
    z-index: 500;
    background: var(--bg-darker, #0d0d0d);
    display: flex !important;
    flex-direction: column;
    padding: 0;
    margin: 0;
    overflow: hidden;
}

#page-code.code-fullscreen-mode .code-page-header {
    flex-shrink: 0;
    padding: 12px 24px 8px;
}

#page-code.code-fullscreen-mode .code-assistant-container {
    flex: 1 1 auto;
    max-width: none;
    margin: 0;
    padding: 0 16px 16px;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

#page-code.code-fullscreen-mode .goose-chat-history {
    flex: 1 1 auto;
    max-height: none;
    min-height: 0;
}

.goose-status {
    font-size: 0.8rem;
    padding: 6px 12px;
    border-radius: 16px;
    font-weight: 500;
}

.goose-status.checking {
    background: rgba(251, 191, 36, 0.2);
    color: #fbbf24;
}

.goose-status.ready {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
}

.goose-status.processing {
    background: rgba(168, 85, 247, 0.2);
    color: #818cf8;
}

.goose-status.error {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

/* Mobile Responsiveness for Code Assistant */
@media (max-width: 768px) {
    .code-page-header {
        padding: 12px 16px;
    }

    .code-page-header .page-title {
        font-size: 1.25rem;
    }

    .code-page-header .section-description {
        font-size: 0.8rem;
    }

    .code-assistant-container {
        height: calc(100vh - 200px);
        padding: 0 12px 12px;
    }

    .goose-chat-history {
        padding: 12px;
        border-radius: 8px;
    }

    .goose-welcome {
        padding: 20px 10px;
    }

    .goose-welcome-icon {
        font-size: 40px;
        margin-bottom: 12px;
    }

    .goose-welcome h3 {
        font-size: 1rem;
    }

    .goose-welcome p {
        font-size: 0.85rem;
        margin-bottom: 16px;
    }

    .goose-examples {
        flex-direction: column;
        gap: 8px;
        width: 100%;
    }

    .example-btn {
        width: 100%;
        padding: 10px 16px;
        font-size: 0.85rem;
    }

    .goose-message {
        max-width: 95%;
        padding: 10px 12px;
        border-radius: 10px;
        margin-bottom: 12px;
    }

    .message-role {
        font-size: 0.7rem;
    }

    .message-content {
        font-size: 0.85rem;
        line-height: 1.5;
    }

    .message-content pre.code-block {
        padding: 10px;
        font-size: 0.75rem;
        overflow-x: auto;
    }

    .goose-input-wrapper {
        padding-top: 12px;
    }

    .goose-input-area {
        flex-direction: column;
        gap: 10px;
    }

    .goose-input-area textarea {
        min-height: 44px;
        font-size: 16px; /* Prevent iOS zoom */
        padding: 10px 12px;
        border-radius: 10px;
    }

    .goose-input-area .btn {
        width: 100%;
        padding: 12px;
        font-size: 1rem;
        border-radius: 10px;
    }

    .goose-controls {
        flex-wrap: wrap;
        gap: 8px;
        margin-top: 8px;
    }

    .goose-controls .btn-secondary {
        padding: 8px 16px;
        font-size: 0.8rem;
    }

    /* Toolbar: show all buttons, make them tap-friendly */
    .goose-toolbar-right {
        gap: 4px;
        flex-wrap: wrap;
    }

    .goose-tool-btn {
        padding: 6px 10px;
        font-size: 0.8rem;
        min-width: 36px;
        min-height: 32px;
    }

    /* Copy button always visible on touch screens */
    .copy-msg-btn {
        opacity: 1;
        top: 6px;
        right: 6px;
        padding: 5px 7px;
    }

    .goose-status {
        font-size: 0.75rem;
        padding: 4px 10px;
    }

    /* Thinking indicator mobile */
    .thinking-indicator {
        padding: 8px;
    }

    .thinking-dot {
        width: 6px;
        height: 6px;
    }

    .thinking-text {
        font-size: 0.8rem;
    }
}

/* Extra small screens */
@media (max-width: 480px) {
    .goose-chat-history {
        max-height: calc(100vh - 360px);
        min-height: 180px;
    }

    /* Stack controls vertically on very small screens */
    .goose-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }

    .goose-toolbar-right {
        justify-content: flex-end;
    }

    /* Fullscreen covers entire screen including browser chrome on mobile */
    #page-code.code-fullscreen-mode {
        padding-top: env(safe-area-inset-top, 0);
    }

    .goose-welcome-icon {
        font-size: 40px;
    }

    .goose-welcome h3 {
        font-size: 1rem;
    }

    .example-label {
        display: none;
    }

    .message-content {
        font-size: 0.8rem;
    }
}

/* ========================================
   VOICEOVER MODE SELECTOR
   ======================================== */

.voiceover-mode-selector {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
    padding: 0 24px;
}

.mode-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 20px;
    background: var(--bg-secondary, #1e1e1e);
    border: 2px solid var(--border-color, #333);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.mode-btn:hover {
    border-color: var(--accent-color, #a855f7);
    background: rgba(168, 85, 247, 0.1);
}

.mode-btn.active {
    border-color: var(--accent-color, #a855f7);
    background: rgba(168, 85, 247, 0.15);
}

.mode-icon {
    font-size: 28px;
    margin-bottom: 8px;
}

.mode-label {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary, #fff);
    margin-bottom: 4px;
}

.mode-desc {
    font-size: 0.75rem;
    color: var(--text-muted, #999);
}

/* Audio result styling */
.audio-result-container {
    padding: 20px;
    background: var(--bg-primary, #121212);
    border-radius: 12px;
    margin-bottom: 16px;
}

.result-audio {
    width: 100%;
    height: 50px;
}

/* Mobile responsiveness for mode selector */
@media (max-width: 768px) {
    .voiceover-mode-selector {
        padding: 0 16px;
        gap: 12px;
    }

    .mode-btn {
        padding: 12px 16px;
    }

    .mode-icon {
        font-size: 24px;
        margin-bottom: 6px;
    }

    .mode-label {
        font-size: 0.9rem;
    }

    .mode-desc {
        font-size: 0.7rem;
    }
}

/* Voice preview button */
.voice-select-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.voice-select-row .form-select {
    flex: 1;
}

.voice-preview-btn {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent-color, #a855f7);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.1s;
}

.voice-preview-btn:hover {
    background: var(--accent-hover, #9333ea);
    transform: scale(1.05);
}

.voice-preview-btn:active {
    transform: scale(0.95);
}

.voice-preview-btn:disabled {
    background: var(--bg-tertiary, #333);
    cursor: not-allowed;
    transform: none;
}

.voice-preview-btn .preview-icon {
    font-size: 14px;
}

.voice-preview-btn .preview-loading {
    font-size: 12px;
    animation: pulse 1s infinite;
}

.voice-preview-btn.playing .preview-icon::before {
    content: "⏹";
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* =============================================================================
   CONNECTION STATUS BANNER
   ============================================================================= */

.connection-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    padding: 8px 16px;
    text-align: center;
    font-size: 0.85em;
    font-weight: 600;
    transition: opacity 0.3s ease;
}

.connection-banner.disconnected {
    background: #dc2626;
    color: #fff;
}

.connection-banner.connected {
    background: #16a34a;
    color: #fff;
}

/* =============================================================================
   SYSTEM STATUS BADGE
   ============================================================================= */

.top-bar-center {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
}

.header-stats-strip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    color: var(--text-muted, #94a3b8);
    white-space: nowrap;
}

.header-stat {
    font-variant-numeric: tabular-nums;
}

.header-stats-sep {
    opacity: 0.6;
}

@media (max-width: 480px) {
    .header-stats-strip {
        display: none;
    }
}

.system-status-badge {
    font-size: 0.8em;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.system-status-badge::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.status-ready {
    color: #4ade80;
}

.status-ready::before {
    background: #4ade80;
}

.status-generating {
    color: #fbbf24;
}

.status-generating::before {
    background: #fbbf24;
    animation: pulse 1.5s infinite;
}

.status-busy {
    color: #f87171;
}

.status-busy::before {
    background: #f87171;
}

/* =============================================================================
   RUN SUMMARY
   ============================================================================= */

.run-summary {
    margin-top: 16px;
    padding: 16px;
    background: rgba(168, 85, 247, 0.08);
    border-radius: 10px;
    border: 1px solid rgba(168, 85, 247, 0.25);
    border-left: 4px solid #a855f7;
}

.run-summary-header {
    font-size: 0.85em;
    font-weight: 600;
    color: #a5b4fc;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 12px;
}

.run-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
}

.run-summary-item {
    text-align: center;
}

.run-summary-item .label {
    display: block;
    font-size: 0.75em;
    color: #94a3b8;
    margin-bottom: 4px;
}

.run-summary-item .value {
    display: block;
    font-size: 1.1em;
    font-weight: 600;
    color: #e2e8f0;
}

.run-summary-timings {
    margin-top: 8px;
    font-size: 0.8em;
    color: #94a3b8;
    text-align: center;
}

.run-summary-warnings {
    margin-top: 6px;
    font-size: 0.8em;
    color: #f59e0b;
    text-align: center;
}

/* Audiobook drag-and-drop highlight */
.book-drag-over {
    outline: 2px dashed var(--primary, #a855f7) !important;
    outline-offset: -4px;
    background: rgba(168, 85, 247, 0.05) !important;
}

/* -------------------------------------------------------------------------
   Segment Preview Modal
   ----------------------------------------------------------------------- */
.segment-preview-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.segment-preview-overlay[hidden] {
    display: none;
}

.segment-preview-dialog {
    background: #1e1e2e;
    border: 1px solid #3b3b5c;
    border-radius: 12px;
    width: 100%;
    max-width: 680px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

.segment-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 12px;
    border-bottom: 1px solid #2a2a3e;
}

.segment-preview-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: #e2e8f0;
}

.segment-preview-close {
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
}

.segment-preview-close:hover {
    color: #e2e8f0;
    background: rgba(255, 255, 255, 0.07);
}

.segment-preview-hint {
    margin: 0;
    padding: 10px 20px;
    font-size: 0.82rem;
    color: #94a3b8;
}

.segment-preview-list {
    overflow-y: auto;
    padding: 8px 20px 12px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.segment-preview-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.segment-preview-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--primary, #a855f7);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.segment-preview-textarea {
    width: 100%;
    background: #13131f;
    border: 1px solid #2a2a3e;
    border-radius: 6px;
    color: #e2e8f0;
    font-size: 0.88rem;
    line-height: 1.5;
    padding: 8px 10px;
    resize: vertical;
    min-height: 64px;
    box-sizing: border-box;
    transition: border-color 0.15s;
}

.segment-preview-textarea:focus {
    outline: none;
    border-color: var(--primary, #a855f7);
}

.segment-preview-footer {
    padding: 12px 20px 16px;
    border-top: 1px solid #2a2a3e;
    display: flex;
    gap: 10px;
    align-items: center;
}

.segment-preview-footer .btn-generate {
    flex: 1;
}

/* ===== Scene Placeholder Thumbnails ===== */
.scene-card-placeholder .placeholder-video {
    position: relative;
    aspect-ratio: 16/9;
    background: var(--bg-input);
    overflow: hidden;
}

.placeholder-shimmer {
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255,255,255,0.06) 50%,
        transparent 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.6s infinite;
}

@keyframes shimmer {
    0%   { background-position: -200% 0; }
    100% { background-position:  200% 0; }
}

.placeholder-label {
    position: absolute;
    bottom: 8px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.scene-progress-pct {
    display: none;
    position: absolute;
    inset: 0;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    font-weight: 800;
    color: #fff;
    text-shadow: 0 2px 8px rgba(0,0,0,0.6);
    z-index: 2;
    border-radius: 8px;
    letter-spacing: -1px;
}

.scene-progress-failed {
    color: #ef4444;
    font-size: 1.5rem;
    letter-spacing: 0;
    background: rgba(0,0,0,0.5);
}

.scene-card-failed {
    opacity: 0.6;
}

/* ===== Video Playback Modal ===== */
.video-modal-content {
    max-width: 860px;
    width: 92vw;
}

.video-modal-body {
    padding: 16px;
}

.video-modal-body video {
    width: 100%;
    border-radius: 6px;
    background: #000;
    max-height: 70vh;
    display: block;
}

/* ===== Generation Summary — Scene Prompts ===== */
.run-summary-scenes {
    margin-top: 12px;
    border-top: 1px solid rgba(255,255,255,0.08);
    padding-top: 10px;
}

.run-summary-scenes-heading {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--secondary, #a855f7);
    margin-bottom: 8px;
}

.run-summary-scene-row {
    display: flex;
    gap: 10px;
    padding: 6px 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    align-items: flex-start;
}

.run-summary-scene-row:last-child {
    border-bottom: none;
}

.run-summary-scene-num {
    flex-shrink: 0;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--secondary, #a855f7);
    width: 52px;
    padding-top: 2px;
}

.run-summary-scene-body {
    flex: 1;
    min-width: 0;
}

.run-summary-scene-desc {
    font-size: 0.82rem;
    color: var(--text, #e2e8f0);
    line-height: 1.45;
    word-break: break-word;
}

.run-summary-scene-motion {
    font-size: 0.74rem;
    color: var(--text-muted, #94a3b8);
    margin-top: 3px;
    font-style: italic;
}

/* ========================================================================
   GENERATION HISTORY PANEL
   ======================================================================== */

.history-panel {
    margin-top: 24px;
    border: 1px solid var(--border-color, #334155);
    border-radius: 12px;
    background: var(--card-bg, #1e293b);
    overflow: hidden;
}

.history-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    background: rgba(168, 85, 247, 0.06);
    border-bottom: 1px solid var(--border-color, #334155);
    user-select: none;
}

.history-header h3 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary, #e2e8f0);
}

.history-count {
    font-size: 0.78rem;
    color: var(--text-muted, #94a3b8);
}

.history-toggle {
    margin-left: auto;
    font-size: 0.75rem;
    color: var(--text-muted, #94a3b8);
    transition: transform 0.2s;
}

.history-list {
    max-height: 400px;
    overflow-y: auto;
}

.history-empty {
    padding: 24px;
    text-align: center;
    color: var(--text-muted, #94a3b8);
    font-size: 0.85rem;
}

.history-loading {
    padding: 20px;
    text-align: center;
    color: var(--text-muted, #94a3b8);
    font-size: 0.85rem;
}

/* History Card (list item) */
.history-card {
    padding: 10px 18px;
    border-bottom: 1px solid rgba(51, 65, 85, 0.5);
    cursor: pointer;
    transition: background 0.15s;
}

.history-card:hover {
    background: rgba(168, 85, 247, 0.08);
}

.history-card.selected {
    background: rgba(168, 85, 247, 0.14);
    border-left: 3px solid #a855f7;
}

.history-card-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.history-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.history-status-dot.success { background: #22c55e; }
.history-status-dot.error { background: #ef4444; }
.history-status-dot.warning { background: #f59e0b; }

.history-date {
    font-size: 0.8rem;
    color: var(--text-muted, #94a3b8);
    min-width: 100px;
}

.history-badge {
    font-size: 0.68rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 4px;
    background: rgba(168, 85, 247, 0.2);
    color: #c084fc;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.history-quality {
    font-size: 0.75rem;
    color: var(--text-secondary, #cbd5e1);
}

.history-time {
    font-size: 0.78rem;
    color: var(--text-secondary, #cbd5e1);
    font-variant-numeric: tabular-nums;
}

.history-segments {
    font-size: 0.75rem;
    color: var(--text-muted, #94a3b8);
    margin-left: auto;
}

.history-copy-btn {
    background: none;
    border: 1px solid transparent;
    color: var(--text-muted, #94a3b8);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 2px 6px;
    border-radius: 4px;
    flex-shrink: 0;
    transition: all 0.15s;
    line-height: 1;
}

.history-copy-btn:hover {
    background: rgba(168, 85, 247, 0.15);
    border-color: #a855f7;
    color: #c084fc;
}

.history-copy-detail-btn {
    margin-top: 10px;
    margin-left: 8px;
    font-size: 0.78rem;
    padding: 5px 14px;
}

/* Error Details Card (shown on generation failure) */
.error-details-card {
    margin-top: 12px;
    background: rgba(239, 68, 68, 0.08);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 8px;
    overflow: hidden;
}
.error-details-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 14px;
    background: rgba(239, 68, 68, 0.12);
    border-bottom: 1px solid rgba(239, 68, 68, 0.2);
}
.error-details-title {
    font-weight: 600;
    font-size: 0.85rem;
    color: #ef4444;
}
.error-copy-btn {
    font-size: 0.75rem;
    padding: 4px 12px;
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s;
}
.error-copy-btn:hover {
    background: rgba(239, 68, 68, 0.35);
}
.error-copy-btn.copied {
    background: rgba(34, 197, 94, 0.2);
    color: #86efac;
    border-color: rgba(34, 197, 94, 0.3);
}
.error-details-content {
    padding: 12px 14px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.78rem;
    line-height: 1.5;
    color: #fca5a5;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 300px;
    overflow-y: auto;
    margin: 0;
}

/* History Detail View */
.history-detail {
    padding: 18px;
    border-top: 1px solid var(--border-color, #334155);
    max-height: 600px;
    overflow-y: auto;
}

.history-detail-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color, #334155);
    flex-wrap: wrap;
}

.history-back-btn {
    background: none;
    border: 1px solid var(--border-color, #334155);
    color: var(--text-secondary, #cbd5e1);
    padding: 4px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
}

.history-back-btn:hover {
    background: rgba(168, 85, 247, 0.1);
    border-color: #a855f7;
}

.history-detail-section {
    margin-bottom: 18px;
}

.history-detail-section h4 {
    font-size: 0.82rem;
    font-weight: 600;
    color: #a855f7;
    margin: 0 0 10px 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.history-settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 6px;
}

.setting-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 8px;
    border-radius: 4px;
    background: rgba(30, 41, 59, 0.5);
}

.setting-label {
    font-size: 0.75rem;
    color: var(--text-muted, #94a3b8);
}

.setting-value {
    font-size: 0.78rem;
    color: var(--text-primary, #e2e8f0);
    font-weight: 500;
}

.history-reuse-btn {
    margin-top: 10px;
    font-size: 0.78rem;
    padding: 5px 14px;
}

/* Narrative block */
.history-narrative {
    font-size: 0.82rem;
    color: var(--text-secondary, #cbd5e1);
    line-height: 1.6;
    white-space: pre-wrap;
    background: rgba(15, 23, 42, 0.5);
    padding: 12px;
    border-radius: 8px;
    max-height: 200px;
    overflow-y: auto;
}

/* Scene entries */
.history-scene {
    padding: 10px 12px;
    margin-bottom: 6px;
    background: rgba(15, 23, 42, 0.4);
    border-radius: 6px;
    border-left: 3px solid #a855f7;
}

.history-scene-num {
    font-size: 0.72rem;
    font-weight: 700;
    color: #a855f7;
    text-transform: uppercase;
    margin-bottom: 4px;
}

.history-scene-desc {
    font-size: 0.82rem;
    color: var(--text-primary, #e2e8f0);
    line-height: 1.5;
}

.history-scene-motion {
    font-size: 0.75rem;
    color: var(--text-muted, #94a3b8);
    margin-top: 4px;
    font-style: italic;
}

.history-scene-dialogue {
    font-size: 0.78rem;
    color: #60a5fa;
    margin-top: 4px;
}

/* Segment details */
.history-segment-detail {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 8px;
    font-size: 0.78rem;
    border-bottom: 1px solid rgba(51, 65, 85, 0.3);
}

.history-segment-detail .seg-num {
    font-weight: 700;
    color: #a855f7;
    min-width: 28px;
}

.history-segment-detail .seg-file {
    color: var(--text-secondary, #cbd5e1);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-segment-detail .seg-dur {
    color: var(--text-muted, #94a3b8);
    font-variant-numeric: tabular-nums;
}

/* Timing bars */
.history-timing-bars {
    margin-top: 10px;
}

.timing-bar-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.timing-label {
    font-size: 0.72rem;
    color: var(--text-muted, #94a3b8);
    min-width: 42px;
}

.timing-bar-track {
    flex: 1;
    height: 6px;
    background: rgba(51, 65, 85, 0.5);
    border-radius: 3px;
    overflow: hidden;
}

.timing-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #a855f7, #7c3aed);
    border-radius: 3px;
    transition: width 0.3s;
}

.timing-value {
    font-size: 0.72rem;
    color: var(--text-secondary, #cbd5e1);
    min-width: 40px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Warnings */
.history-warning {
    font-size: 0.78rem;
    color: #f59e0b;
    padding: 6px 10px;
    background: rgba(245, 158, 11, 0.08);
    border-radius: 4px;
    margin-bottom: 4px;
}

/* Load More button */
#loadMoreHistory {
    display: block;
    width: calc(100% - 36px);
    margin: 12px 18px;
    text-align: center;
    font-size: 0.8rem;
}

/* ── AI Evaluation Styles ── */
.history-eval-section {
    border-top: 1px solid rgba(139, 92, 246, 0.3);
    padding-top: 12px;
}
.history-eval-section h4 {
    color: #a78bfa;
}
.eval-subsection {
    margin-bottom: 14px;
    padding: 10px 12px;
    background: rgba(30, 30, 50, 0.4);
    border-radius: 8px;
}
.eval-subsection h5 {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-primary, #e2e8f0);
    margin: 0 0 6px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}
.eval-badge {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
    text-transform: uppercase;
}
.eval-fast { background: rgba(34, 197, 94, 0.2); color: #22c55e; }
.eval-avg { background: rgba(234, 179, 8, 0.2); color: #eab308; }
.eval-slow { background: rgba(239, 68, 68, 0.2); color: #ef4444; }
.eval-drift-low { background: rgba(34, 197, 94, 0.2); color: #22c55e; }
.eval-drift-med { background: rgba(234, 179, 8, 0.2); color: #eab308; }
.eval-drift-high { background: rgba(239, 68, 68, 0.2); color: #ef4444; }
.eval-running {
    background: rgba(96, 165, 250, 0.2);
    color: #60a5fa;
    animation: pulse 1.5s infinite;
}
.eval-score { font-weight: 700; font-size: 0.85rem; }
.eval-tips {
    margin: 6px 0 0 0;
    padding-left: 18px;
    font-size: 0.78rem;
    color: var(--text-secondary, #94a3b8);
}
.eval-tips li { margin-bottom: 4px; }
.eval-comparison {
    font-size: 0.78rem;
    color: var(--text-secondary, #94a3b8);
    margin: 4px 0;
}
.eval-strengths {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin: 6px 0;
}
.eval-strength-tag {
    font-size: 0.7rem;
    padding: 2px 8px;
    background: rgba(34, 197, 94, 0.15);
    color: #86efac;
    border-radius: 10px;
}
.eval-rec-list {
    font-size: 0.8rem;
    padding-left: 20px;
    margin: 6px 0 0 0;
    color: var(--text-primary, #e2e8f0);
}
.eval-rec-list li { margin-bottom: 6px; }
.eval-drift-explanation {
    font-size: 0.78rem;
    color: var(--text-secondary, #94a3b8);
    margin: 4px 0;
}
.eval-flagged {
    font-size: 0.75rem;
    color: #f59e0b;
    margin: 4px 0;
}
.eval-loading, .eval-failed, .eval-none {
    font-size: 0.8rem;
    color: var(--text-muted, #94a3b8);
    padding: 8px 0;
}
/* List view eval badges */
.history-eval-badge {
    font-size: 0.7rem;
    padding: 1px 6px;
    border-radius: 8px;
}
.history-eval-score {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted, #94a3b8);
}

/* ============================================
   BOOK STUDIO — MAIN TABS
   ============================================ */
.book-main-tabs {
    display: flex;
    gap: 4px;
    margin: 1rem 0 0;
    border-bottom: 1px solid var(--border-color, #333);
}
.book-main-tab {
    padding: 8px 20px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted, #94a3b8);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.15s ease;
    margin-bottom: -1px;
    border-radius: 0;
}
.book-main-tab.active {
    color: var(--primary, #a855f7);
    border-bottom-color: var(--primary, #a855f7);
    font-weight: 600;
}
.book-main-tab:hover:not(.active) {
    color: var(--text-primary, #e2e8f0);
}
.book-main-pane {
    display: none;
    padding-top: 1rem;
}
.book-main-pane.active {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* ============================================
   BOOK STUDIO — TOP BAR
   ============================================ */
.bk-topbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: var(--bg-card, #1e293b);
    border: 1px solid var(--border-color, #334155);
    border-radius: 6px;
    margin-bottom: 6px;
    flex-wrap: wrap;
    position: relative;
    z-index: 10;
}
.bk-topbar-left, .bk-topbar-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.bk-topbar-center { flex: 1; min-width: 120px; }
.bk-topbar-title {
    font-weight: 600;
    font-size: 0.92rem;
    text-align: center;
}
.bk-topbar-select { max-width: 180px; }
.bk-topbar-model { max-width: 160px; }
.bk-topbar-status { white-space: nowrap; }

/* Project ⋯ menu */
.bk-proj-menu-wrap {
    position: relative;
    display: inline-flex;
}
.bk-proj-menu-btn { letter-spacing: 2px; padding: 2px 8px; }
.bk-proj-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 160px;
    background: var(--bg-card, #1e293b);
    border: 1px solid var(--border, #475569);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.35);
    z-index: 200;
    overflow: hidden;
}
.bk-proj-menu-item {
    display: block;
    width: 100%;
    padding: 9px 14px;
    background: none;
    border: none;
    text-align: left;
    font-size: 0.85rem;
    color: var(--text-primary, #f1f5f9);
    cursor: pointer;
    white-space: nowrap;
}
.bk-proj-menu-item:hover { background: rgba(168,85,247,0.12); }
.bk-proj-menu-danger { color: #f87171 !important; }
.bk-proj-menu-danger:hover { background: rgba(248,113,113,0.1) !important; }

/* ============================================
   BOOK STUDIO — 3-PANE CSS GRID
   ============================================ */
.bk-3pane {
    display: grid;
    grid-template-columns:
        var(--bk-binder-width, 240px) 4px 1fr 4px var(--bk-inspector-width, 280px);
    grid-template-rows: 1fr;
    flex: 1;
    min-height: 0;
    gap: 0;
}

/* Pane shared styles */
.bk-binder, .bk-editor, .bk-inspector {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-card, #1e293b);
    border: 1px solid var(--border-color, #334155);
    border-radius: 6px;
}

/* ── Resizer handles ─────────────────────── */
.bk-resizer {
    width: 4px;
    cursor: col-resize;
    background: transparent;
    transition: background 0.15s;
    position: relative;
    z-index: 5;
}
.bk-resizer:hover, .bk-resizer.active {
    background: var(--primary, #a855f7);
}
.bk-resizer::before {
    content: '';
    position: absolute;
    top: 0; bottom: 0;
    left: -4px; right: -4px;
}

/* ── Inspector close state ───────────────── */
.bk-3pane.inspector-closed {
    grid-template-columns:
        var(--bk-binder-width, 240px) 4px 1fr 0px 0px;
}
.bk-3pane.inspector-closed .bk-inspector,
.bk-3pane.inspector-closed #bkResizerRight {
    display: none;
}

/* ============================================
   BINDER PANE (left)
   ============================================ */
.bk-binder-header, .bk-inspector-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    border-bottom: 1px solid var(--border-color, #334155);
    flex-shrink: 0;
}
.bk-binder-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}
.bk-import-progress {
    padding: 6px 10px 4px;
    border-top: 1px solid var(--border-color, #334155);
}
.bk-import-progress-track {
    background: rgba(100, 116, 139, 0.2);
    border-radius: 4px;
    height: 4px;
    overflow: hidden;
}
.bk-import-progress-bar {
    height: 100%;
    background: var(--primary, #a855f7);
    border-radius: 4px;
    width: 0%;
    transition: width 0.35s ease;
}
.bk-import-progress-label {
    display: block;
    margin-top: 4px;
    font-size: 0.72rem;
    color: var(--text-muted, #94a3b8);
}
.bk-tree-empty-import {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 1.5rem 0.75rem;
    text-align: center;
}
.bk-tree-empty-import p {
    font-size: 0.8rem;
    color: var(--text-muted, #64748b);
    margin: 0;
}
.bk-import-empty-btn {
    font-size: 0.78rem;
}
#bkImportDocBtn {
    font-size: 0.75rem;
    white-space: nowrap;
}
.bk-pane-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted, #94a3b8);
}
.bk-binder-tree {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}
.bk-binder-footer {
    padding: 4px 10px;
    border-top: 1px solid var(--border-color, #334155);
    flex-shrink: 0;
    font-size: 0.72rem;
}
.bk-tree-empty {
    font-size: 0.82rem;
    color: var(--text-muted, #64748b);
    text-align: center;
    padding: 1.5rem 0.5rem;
    margin: 0;
}

/* Context checkboxes in binder tree */
.bk-ctx-cb {
    width: 13px;
    height: 13px;
    flex-shrink: 0;
    margin-right: 2px;
    cursor: pointer;
    accent-color: var(--primary, #a855f7);
    opacity: 0.5;
    transition: opacity 0.12s;
}
.bk-ctx-cb:hover,
.bk-ctx-cb:checked,
.bk-tree-node-row:hover .bk-ctx-cb,
.bk-tree-folder-row:hover .bk-ctx-cb,
.bk-tree-part-row:hover .bk-ctx-cb { opacity: 1; }

/* Binder tree nodes */
.bk-tree-node-row {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    cursor: pointer;
    border-radius: 4px;
    margin: 1px 4px;
    font-size: 0.82rem;
    color: var(--text-primary, #e2e8f0);
    transition: background 0.1s;
    user-select: none;
    border: 1px solid transparent;
}
.bk-tree-node-row:hover {
    background: rgba(168, 85, 247, 0.08);
}
.bk-tree-node-row.selected {
    background: rgba(168, 85, 247, 0.18);
    color: var(--primary, #a855f7);
    font-weight: 600;
}
.bk-tree-node-row.drag-over {
    border-top: 2px solid var(--primary, #a855f7);
}
.bk-tree-toggle {
    width: 14px;
    text-align: center;
    font-size: 0.65rem;
    color: var(--text-muted, #64748b);
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.15s;
}
.bk-tree-toggle.expanded { transform: rotate(90deg); }
.bk-tree-icon {
    font-size: 0.75rem;
    width: 16px;
    text-align: center;
    flex-shrink: 0;
}
.bk-tree-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.bk-tree-status {
    font-size: 0.65rem;
    flex-shrink: 0;
    margin-left: auto;
}
.bk-tree-status.final { color: #22c55e; }
.bk-tree-status.draft { color: var(--text-muted, #64748b); }
.bk-tree-children {
    padding-left: 16px;
}
.bk-tree-children.collapsed {
    display: none;
}
.bk-tree-part-row {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--primary, #a855f7);
    opacity: 0.75;
    padding: 10px 8px 4px;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 4px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-top: 4px;
}
.bk-tree-folder-row {
    font-size: 0.79rem;
    font-weight: 600;
    color: var(--text-secondary, #94a3b8);
    padding: 6px 8px 3px;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 4px;
    border-left: 2px solid rgba(168,85,247,0.25);
    margin-left: -2px;
}

/* ============================================
   EDITOR PANE (center)
   ============================================ */
.bk-editor {
    min-width: 0;
}
.bk-editor-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 3rem 1.5rem;
    text-align: center;
}
.bk-editor-empty[hidden] {
    display: none !important;
}
.bk-editor-workspace {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}
.bk-editor-workspace[hidden] {
    display: none !important;
}
.bk-editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--border-color, #334155);
    background: var(--bg-card, #1e293b);
    flex-shrink: 0;
    min-height: 48px;
}
.bk-editor-header-left {
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}
.bk-editor-header-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.bk-editor-path {
    display: none; /* path hidden — chapter title provides enough context */
}
.bk-editor-title {
    font-size: 0.9rem;
    font-weight: 600;
    margin: 0;
    color: var(--text-primary, #e2e8f0);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}
/* Divider between button groups */
.bk-header-divider {
    width: 1px;
    height: 18px;
    background: var(--border-color, #334155);
    flex-shrink: 0;
}
.book-chapter-badge {
    font-size: 0.65rem;
    padding: 1px 6px;
    border-radius: 8px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex-shrink: 0;
}
.book-chapter-badge.draft {
    background: rgba(100, 116, 139, 0.2);
    color: #94a3b8;
}
.book-chapter-badge.final {
    background: rgba(34, 197, 94, 0.15);
    color: #22c55e;
}

/* Quill editor area — fills remaining space */
.bk-editor-quill {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#bookEditorToolbar {
    border-bottom: 1px solid var(--border-color, #334155);
    background: var(--bg-card, #1e293b);
    padding: 6px 8px;
    flex-shrink: 0;
    z-index: 10;
}
/* Show native tooltips immediately on toolbar items */
#bookEditorToolbar button[title],
#bookEditorToolbar select[title] {
    cursor: pointer;
}
#bookEditorToolbar .ql-stroke { stroke: var(--text-secondary, #94a3b8); }
#bookEditorToolbar .ql-fill { fill: var(--text-secondary, #94a3b8); }
#bookEditorToolbar .ql-picker-label { color: var(--text-secondary, #94a3b8); }
#bookEditorToolbar .ql-picker-options {
    background: var(--bg-card, #1e293b);
    border-color: var(--border-color, #334155);
}
#bookEditorToolbar .ql-picker-item { color: var(--text-secondary, #94a3b8); }
#bookEditorToolbar .ql-picker-item:hover,
#bookEditorToolbar .ql-picker-item.ql-selected { color: var(--primary, #22c55e); }
#bookEditorToolbar button:hover .ql-stroke,
#bookEditorToolbar button.ql-active .ql-stroke { stroke: var(--primary, #22c55e); }
#bookEditorToolbar button:hover .ql-fill,
#bookEditorToolbar button.ql-active .ql-fill { fill: var(--primary, #22c55e); }

#bookChapterEditor { flex: 1; overflow-y: auto; }
#bookChapterEditor .ql-editor {
    min-height: 300px; padding: 1rem 1.25rem;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 0.95rem; line-height: 1.7;
    color: var(--text-primary, #e2e8f0);
}
#bookChapterEditor .ql-editor.ql-blank::before {
    color: var(--text-muted, #64748b); font-style: italic;
}
#bookChapterEditor.ql-container { border: none; }
#bookEditorToolbar.ql-toolbar { border: none; }

/* Document View Mode */
.book-doc-view #bookChapterEditor {
    max-width: 720px; margin: 0 auto;
    background: var(--bg-card, #1e293b);
    box-shadow: 0 2px 12px rgba(0,0,0,0.3);
    border-radius: 4px; min-height: 60vh; max-height: none;
}

/* Status bar */
.book-editor-status-bar {
    display: flex; align-items: center; gap: 1rem;
    padding: 4px 12px; font-size: 0.72rem;
    color: var(--text-muted, #94a3b8);
    background: var(--bg-card, #1e293b);
    border-top: 1px solid var(--border-color, #334155);
    flex-shrink: 0;
}
.book-status-spacer { flex: 1; }
.book-status-save { color: var(--primary, #22c55e); }
.book-status-save.unsaved { color: #f59e0b; }
.book-status-muted { opacity: 0.7; }

/* Unified small action buttons in editor header */
.btn-xs {
    padding: 4px 10px;
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1.4;
    border-radius: 5px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.btn-ghost {
    background: transparent;
    border: 1px solid var(--border-color, #334155);
    color: var(--text-secondary, #94a3b8);
}
.btn-ghost:hover { background: rgba(255,255,255,0.07); color: var(--text-primary, #e2e8f0); }
.btn-ghost.active { background: var(--primary, #22c55e); color: #fff; border-color: var(--primary); }

/* Narrate (speak) button */
.btn-narrate {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: transparent;
    border: 1px solid var(--border-color, #334155);
    color: var(--text-secondary, #94a3b8);
    padding: 4px 10px;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
    white-space: nowrap;
}
.btn-narrate:hover { background: rgba(99,102,241,0.1); color: #818cf8; border-color: #818cf8; }
.btn-narrate.narrating { background: rgba(99,102,241,0.18); color: #818cf8; border-color: #818cf8; }
.btn-narrate.bk-narrate-paused { background: rgba(234,179,8,0.13); color: #fbbf24; border-color: #fbbf24; }
.btn-narrate.bk-narrate-paused:hover { background: rgba(234,179,8,0.22); }
.btn-narrate svg { flex-shrink: 0; }

/* Download audio button (anchor styled as icon button) */
.btn-narrate-download {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    background: transparent;
    border: 1px solid #334155;
    border-radius: 5px;
    color: #94a3b8;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
    flex-shrink: 0;
}
.btn-narrate-download:hover { background: rgba(34,197,94,0.12); color: #4ade80; border-color: #4ade80; }
.btn-narrate-download svg { flex-shrink: 0; }

/* Skip back / forward buttons */
.btn-narrate-skip {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 0 7px;
    height: 26px;
    background: transparent;
    border: 1px solid #334155;
    border-radius: 5px;
    color: #94a3b8;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
    flex-shrink: 0;
}
.btn-narrate-skip:hover { background: rgba(99,102,241,0.1); color: #818cf8; border-color: #818cf8; }
.btn-narrate-skip-label { line-height: 1; }

/* ── Karaoke reading bar ─────────────────────────────────────── */
.bk-reading-bar {
    background: #0d1929;
    border-top: 1px solid #1e3a5f;
    border-bottom: 1px solid #1e3a5f;
    padding: 10px 14px 6px;
    height: 80px;
    min-height: 44px;
    max-height: 420px;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    box-sizing: border-box;
}
.bk-reading-bar-handle {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 8px;
    cursor: ns-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
}
.bk-reading-bar-handle::before {
    content: '';
    display: block;
    width: 32px;
    height: 3px;
    border-radius: 2px;
    background: #2a4a6b;
    transition: background 0.15s;
}
.bk-reading-bar-handle:hover::before {
    background: #4a80b0;
}
.bk-reading-bar-words {
    display: flex;
    flex-wrap: wrap;
    gap: 2px 4px;
    line-height: 1.9;
}
.bk-word {
    font-size: 0.82rem;
    color: #64748b;
    border-radius: 3px;
    padding: 1px 3px;
    transition: color 0.08s, background 0.08s;
    cursor: pointer;
}
.bk-word:hover {
    color: #cbd5e1;
    background: rgba(99,102,241,0.15);
}
.bk-word.active {
    color: #f1f5f9;
    background: rgba(99,102,241,0.35);
    font-weight: 600;
}

.book-export-dropdown { position: relative; display: inline-block; }
.book-export-menu {
    position: absolute; bottom: 100%; left: 0;
    background: var(--bg-card, #1e293b); border: 1px solid var(--border-color, #334155);
    border-radius: 6px; box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 20; min-width: 160px; margin-bottom: 4px;
}
.book-export-option {
    display: block; width: 100%; padding: 6px 12px; text-align: left;
    background: none; border: none; color: var(--text-primary, #e2e8f0);
    font-size: 0.8rem; cursor: pointer;
}
.book-export-option:hover { background: rgba(255,255,255,0.05); }

/* ============================================
   INSPECTOR PANE (right)
   ============================================ */
.bk-inspector-body {
    flex: 1;
    overflow-y: auto;
}
.bk-inspector-section {
    border-bottom: 1px solid var(--border-color, #334155);
}
.bk-inspector-section summary {
    padding: 8px 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    color: var(--text-secondary, #94a3b8);
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
    user-select: none;
}
.bk-inspector-section summary::-webkit-details-marker { display: none; }
.bk-inspector-section summary::before {
    content: '\25B6';
    font-size: 0.55rem;
    transition: transform 0.15s;
    display: inline-block;
}
.bk-inspector-section[open] summary::before {
    transform: rotate(90deg);
}
.bk-inspector-section-body {
    padding: 4px 12px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.bk-inspector-textarea {
    font-size: 0.8rem;
    resize: vertical;
}
.bk-inspector-row {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: nowrap;
    margin-top: 4px;
}
.bk-inspector-row .btn {
    flex-shrink: 0;
}
.bk-inspector-field {
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.bk-inspector-field .form-label {
    font-size: 0.72rem;
    margin: 0;
}

/* Metadata grid */
.bk-meta-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 10px;
    font-size: 0.78rem;
}
.bk-meta-label {
    color: var(--text-muted, #94a3b8);
    font-weight: 600;
}
.bk-meta-value {
    color: var(--text-primary, #e2e8f0);
}

/* Guardrails */
.book-guardrails-textarea {
    min-height: 80px;
    font-family: var(--font-mono, 'JetBrains Mono', monospace);
    font-size: 0.8rem;
    line-height: 1.5;
    resize: vertical;
}
.bk-unsaved-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--warning, #e67e22);
    display: inline-block;
}

/* Source content */
.book-source-file-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    padding: 4px 8px;
    background: rgba(34, 197, 94, 0.08);
    border-radius: 4px;
    border: 1px solid rgba(34, 197, 94, 0.2);
    font-size: 0.78rem;
}

/* Generation progress bar */
.bk-gen-progress-wrap {
    margin-top: 8px;
}
.bk-gen-progress-wrap[hidden] { display: none !important; }
.bk-gen-progress-track {
    height: 4px;
    background: rgba(168,85,247,0.15);
    border-radius: 4px;
    overflow: hidden;
}
.bk-gen-progress-bar {
    height: 100%;
    width: 0%;
    background: var(--primary, #a855f7);
    border-radius: 4px;
    transition: width 0.3s ease;
}
.bk-gen-progress-bar.indeterminate {
    width: 40%;
    animation: bk-gen-pulse 1.4s ease-in-out infinite;
}
@keyframes bk-gen-pulse {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(350%); }
}
.bk-gen-progress-label {
    font-size: 0.75rem;
    color: var(--text-muted, #94a3b8);
    margin-top: 4px;
    display: block;
}

/* Generation status (legacy, keep for compat) */
.book-gen-status {
    font-size: 0.78rem;
    color: var(--text-muted, #94a3b8);
    padding: 4px 8px;
    background: rgba(168, 85, 247, 0.08);
    border-radius: 6px;
}
.book-toggle-label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.8rem;
    color: var(--text-secondary, #94a3b8);
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
}

/* ============================================
   BINDER CONTEXT MENU
   ============================================ */
.bk-context-menu {
    position: fixed;
    background: var(--bg-card, #1e293b);
    border: 1px solid var(--border-color, #334155);
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    z-index: 9999;
    min-width: 160px;
    padding: 4px 0;
}
.bk-ctx-option {
    display: block;
    width: 100%;
    padding: 6px 14px;
    text-align: left;
    background: none;
    border: none;
    color: var(--text-primary, #e2e8f0);
    font-size: 0.8rem;
    cursor: pointer;
}
.bk-ctx-option:hover {
    background: rgba(168, 85, 247, 0.1);
}
.bk-ctx-danger {
    color: #ef4444;
}
.bk-ctx-danger:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* ============================================
   BOOK STUDIO — FULLSCREEN MODE
   ============================================ */
#book-tab-book.bk-fullscreen {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 9990;
    background: var(--bg-body, #0f172a);
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
#book-tab-book.bk-fullscreen .bk-topbar {
    border-radius: 0;
    margin-bottom: 0;
    border-left: none;
    border-right: none;
    border-top: none;
}
#book-tab-book.bk-fullscreen .bk-3pane {
    flex: 1;
    height: auto;
    border-radius: 0;
}
#book-tab-book.bk-fullscreen .bk-binder,
#book-tab-book.bk-fullscreen .bk-editor,
#book-tab-book.bk-fullscreen .bk-inspector {
    border-radius: 0;
}
/* ============================================
   BOOK STUDIO — RESPONSIVE
   ============================================ */
@media (max-width: 900px) {
    .bk-3pane {
        display: flex;
        flex-direction: column;
        height: auto;
    }
    .bk-binder {
        max-height: 200px;
    }
    .bk-inspector {
        max-height: 300px;
    }
    .bk-resizer {
        display: none;
    }
    .bk-3pane.inspector-closed .bk-inspector {
        display: none;
    }
    .bk-topbar {
        flex-direction: column;
        align-items: stretch;
    }
    .bk-topbar-left, .bk-topbar-center, .bk-topbar-right {
        justify-content: center;
    }
}
@media (max-width: 600px) {
    .book-main-tabs { gap: 0; }
    .book-main-tab { padding: 8px 14px; font-size: 0.85rem; }
}

/* ============================================
   BOOK STUDIO — COMPILE PANEL
   ============================================ */

/* Overlay backdrop */
.bk-compile-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 2100;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

/* Main panel container */
.bk-compile-panel {
    background: var(--card-bg, #1e293b);
    border: 1px solid var(--border, #334155);
    border-radius: 16px;
    width: 92%;
    max-width: 960px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

/* Header bar */
.bk-compile-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border, #334155);
    flex-shrink: 0;
}
.bk-compile-header h3 {
    color: var(--text-primary, #f1f5f9);
    font-size: 1.1rem;
}
.bk-compile-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Body: flex row of sidebar + content */
.bk-compile-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* Left sidebar navigation */
.bk-compile-sidebar {
    width: 170px;
    min-width: 170px;
    padding: 12px 8px;
    border-right: 1px solid var(--border, #334155);
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.15);
}

/* Tab buttons in sidebar */
.bk-compile-tab {
    text-align: left;
    padding: 8px 12px;
    border: none;
    background: none;
    color: var(--text-muted, #94a3b8);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}
.bk-compile-tab:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary, #f1f5f9);
}
.bk-compile-tab.active {
    background: var(--primary, #22c55e);
    color: #fff;
    font-weight: 500;
}

/* Right content area */
.bk-compile-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    min-height: 0;
}

/* Tab panes (show/hide) */
.bk-compile-pane {
    display: none;
}
.bk-compile-pane.active {
    display: block;
}
.bk-compile-pane h4 {
    margin: 0 0 16px 0;
    color: var(--text-primary, #f1f5f9);
    font-size: 1rem;
}

/* Form field container */
.bk-compile-field {
    margin-bottom: 14px;
}
.bk-compile-field > label {
    display: block;
    margin-bottom: 4px;
    font-size: 0.85rem;
    color: var(--text-muted, #94a3b8);
}
.bk-compile-field > label:has(input[type="checkbox"]) {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    color: var(--text-primary, #f1f5f9);
}

/* Category selection grid (Compile For tab) */
.bk-compile-category-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin: 12px 0;
}
.bk-compile-category-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 14px 8px;
    border: 2px solid var(--border, #334155);
    border-radius: 10px;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    text-align: center;
}
.bk-compile-category-card:hover {
    border-color: var(--text-muted, #64748b);
}
.bk-compile-category-card:has(input:checked) {
    border-color: var(--primary, #22c55e);
    background: rgba(34, 197, 94, 0.1);
}
.bk-compile-category-card input[type="radio"] {
    display: none;
}
.bk-compile-category-label {
    font-size: 0.85rem;
    color: var(--text-primary, #f1f5f9);
}

/* Layout grid (Section Layouts, Separators, Page, Typography tabs) */
.bk-compile-layout-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.bk-compile-layout-row {
    display: flex;
    align-items: center;
    gap: 12px;
}
.bk-compile-layout-label {
    width: 160px;
    min-width: 160px;
    font-size: 0.85rem;
    color: var(--text-muted, #94a3b8);
}

/* Contents tree (checkboxes) */
.bk-compile-contents-tree {
    max-height: 420px;
    overflow-y: auto;
    border: 1px solid var(--border, #334155);
    border-radius: 8px;
    padding: 8px;
}
.bk-compile-tree-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 4px 4px 0;
    font-size: 0.88rem;
    color: var(--text-primary, #f1f5f9);
}
.bk-compile-tree-row.depth-0 { padding-left: 4px; font-weight: 600; }
.bk-compile-tree-row.depth-1 { padding-left: 24px; }
.bk-compile-tree-row.depth-2 { padding-left: 44px; }
.bk-compile-tree-row.depth-3 { padding-left: 64px; }
.bk-compile-tree-row .bk-compile-tree-type {
    font-size: 0.75rem;
    padding: 1px 6px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-muted, #94a3b8);
    text-transform: uppercase;
}
.bk-compile-tree-row .bk-compile-tree-words {
    margin-left: auto;
    font-size: 0.75rem;
    color: var(--text-muted, #64748b);
}

/* Preset row */
.bk-compile-preset-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Footer bar */
.bk-compile-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border, #334155);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    gap: 16px;
}
.bk-compile-footer-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

/* Progress bar in footer */
.bk-compile-progress {
    flex: 1;
    min-width: 0;
}
.bk-compile-progress-track {
    height: 6px;
    background: var(--bg-input, #0f172a);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 4px;
}
.bk-compile-progress-bar {
    height: 100%;
    width: 0%;
    background: var(--primary, #22c55e);
    border-radius: 3px;
    transition: width 0.3s ease;
}

/* Preview section */
.bk-compile-preview-outline {
    border: 1px solid var(--border, #334155);
    border-radius: 8px;
    padding: 12px;
    max-height: 350px;
    overflow-y: auto;
}
.bk-compile-preview-outline ol {
    margin: 0;
    padding-left: 24px;
}
.bk-compile-preview-outline li {
    padding: 4px 0;
    font-size: 0.88rem;
    color: var(--text-primary, #f1f5f9);
}
.bk-compile-preview-outline li.part-item {
    font-weight: 700;
    margin-top: 8px;
}
.bk-compile-preview-outline li .preview-type {
    font-size: 0.72rem;
    color: var(--text-muted, #64748b);
    margin-left: 6px;
}

/* Preview meta line */
.bk-compile-preview-meta {
    font-size: 0.78rem;
    color: var(--text-muted, #64748b);
    margin-bottom: 6px;
}
.bk-compile-preview-icon { font-size: 0.8rem; }
.bk-compile-preview-row {
    font-size: 0.83rem;
    padding: 3px 0;
    color: var(--text-primary, #f1f5f9);
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Preview warnings — collapsible, at the bottom */
.bk-compile-warnings-details {
    margin-top: 12px;
}
.bk-compile-warnings-summary {
    font-size: 0.82rem;
    color: #eab308;
    cursor: pointer;
    user-select: none;
    padding: 6px 0;
}
.bk-compile-warnings {
    margin-top: 6px;
    max-height: 160px;
    overflow-y: auto;
}
.bk-compile-warning {
    font-size: 0.78rem;
    color: var(--text-muted, #94a3b8);
    padding: 2px 0;
}

/* ── Light mode overrides ── */
[data-theme="light"] .bk-compile-panel {
    background: #fff;
    border-color: #e2e8f0;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.15);
}
[data-theme="light"] .bk-compile-header {
    border-color: #e2e8f0;
}
[data-theme="light"] .bk-compile-header h3 {
    color: #1e293b;
}
[data-theme="light"] .bk-compile-sidebar {
    border-color: #e2e8f0;
    background: #f8fafc;
}
[data-theme="light"] .bk-compile-tab {
    color: #64748b;
}
[data-theme="light"] .bk-compile-tab:hover {
    background: rgba(0, 0, 0, 0.04);
    color: #1e293b;
}
[data-theme="light"] .bk-compile-tab.active {
    background: var(--primary, #22c55e);
    color: #fff;
}
[data-theme="light"] .bk-compile-pane h4 {
    color: #1e293b;
}
[data-theme="light"] .bk-compile-category-card {
    border-color: #e2e8f0;
}
[data-theme="light"] .bk-compile-category-label {
    color: #1e293b;
}
[data-theme="light"] .bk-compile-contents-tree {
    border-color: #e2e8f0;
}
[data-theme="light"] .bk-compile-tree-row {
    color: #1e293b;
}
[data-theme="light"] .bk-compile-footer {
    border-color: #e2e8f0;
}
[data-theme="light"] .bk-compile-preview-outline {
    border-color: #e2e8f0;
}
[data-theme="light"] .bk-compile-preview-outline li {
    color: #1e293b;
}
[data-theme="light"] .bk-compile-overlay {
    background: rgba(0, 0, 0, 0.4);
}

/* ── Mobile: stack sidebar above content ── */
@media (max-width: 768px) {
    .bk-compile-body {
        flex-direction: column;
    }
    .bk-compile-sidebar {
        width: 100%;
        min-width: unset;
        flex-direction: row;
        overflow-x: auto;
        border-right: none;
        border-bottom: 1px solid var(--border, #334155);
        padding: 8px;
        gap: 4px;
    }
    .bk-compile-tab {
        white-space: nowrap;
        font-size: 0.8rem;
        padding: 6px 10px;
    }
    .bk-compile-content {
        padding: 16px;
    }
    .bk-compile-category-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .bk-compile-layout-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }
    .bk-compile-layout-label {
        width: auto;
        min-width: unset;
    }
    .bk-compile-panel {
        width: 98%;
        max-height: 90vh;
        border-radius: 12px;
    }
    .bk-compile-header-right {
        flex-wrap: wrap;
    }
}

/* ============================================
   iPHONE PRO MAX / LARGE PHONE OPTIMIZATIONS
   (430px - iPhone 15/16/17 Pro Max)
   ============================================ */
@media (max-width: 430px) {

    /* --- Top bar: compact for small screens --- */
    .top-bar-left {
        display: none !important;
    }

    .top-bar {
        padding: 0 10px !important;
    }

    .top-bar-right {
        gap: 6px !important;
    }

    /* Hide "Buy Credits" — redundant on mobile, accessible via More menu */
    .btn-buy-credits {
        display: none !important;
    }

    /* Compact screenshot / upload icon buttons */
    .top-bar-right .btn-icon,
    .top-bar-right .btn-small {
        padding: 6px 8px !important;
        font-size: 0.8rem !important;
    }

    /* --- Page sections: reduce horizontal padding --- */
    .page-section {
        padding: 12px !important;
    }

    .page-section-header,
    .section-header {
        padding: 10px 12px !important;
        margin-bottom: 10px !important;
    }

    .section-title,
    .page-section-title {
        font-size: 1rem !important;
    }

    /* --- Form groups: tighter spacing --- */
    .form-group {
        margin-bottom: 12px !important;
    }

    .form-label {
        font-size: 0.82rem !important;
    }

    /* --- Code Assistant: fit within mobile viewport --- */
    #page-code .code-assistant-container {
        padding: 0 8px 8px !important;
    }

    .goose-chat-history {
        /* bottom nav (64px) + safe area + top bar (56px) + input area (~120px) + controls (~40px) */
        max-height: calc(100dvh - 56px - 64px - env(safe-area-inset-bottom) - 180px) !important;
        min-height: 180px !important;
    }

    /* Fullscreen mode on mobile: account for safe areas */
    #page-code.code-fullscreen-mode {
        padding-bottom: calc(env(safe-area-inset-bottom)) !important;
    }

    #page-code.code-fullscreen-mode .goose-chat-history {
        max-height: none !important;
    }

    /* Stack goose controls vertically on very small screens */
    .goose-controls {
        flex-wrap: wrap !important;
        gap: 6px !important;
    }

    .goose-toolbar-right {
        flex-wrap: nowrap !important;
        gap: 4px !important;
    }

    .goose-tool-btn {
        padding: 6px 10px !important;
        font-size: 0.8rem !important;
        min-height: 36px !important;
    }

    /* --- Input textarea: taller touch area --- */
    #goose-input {
        min-height: 44px !important;
        font-size: 16px !important; /* prevent iOS auto-zoom */
    }

    /* --- Gallery / card grids: single column --- */
    .gallery-grid,
    .video-gallery,
    .image-gallery {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }

    /* --- Buttons: minimum touch target --- */
    .btn, button {
        min-height: 40px !important;
    }

    /* --- Code blocks in chat: horizontal scroll, don't overflow --- */
    .code-block {
        max-width: 100% !important;
        overflow-x: auto !important;
        font-size: 0.78rem !important;
    }

    /* --- Goose send button: bigger touch target --- */
    #goose-send {
        min-height: 44px !important;
        padding: 10px 16px !important;
    }

    /* --- Copy button: always visible on touch devices --- */
    .copy-msg-btn {
        opacity: 0.7 !important;
    }

    /* --- Stats strip: hide on 430px to save space --- */
    .stats-strip {
        display: none !important;
    }

    /* --- Dashboard gauges: smaller --- */
    .gauge {
        width: 48px !important;
        height: 48px !important;
    }

    .gauge-label {
        font-size: 0.65rem !important;
    }
}

/* ====================================================================
   BOOK STUDIO — WORKFLOW SELECTOR MODAL
   ==================================================================== */

.bk-workflow-modal {
    position: fixed;
    inset: 0;
    z-index: 2200;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.65);
    backdrop-filter: blur(4px);
    padding: 16px;
}

.bk-workflow-panel {
    background: var(--bg-secondary, #1e293b);
    border: 1px solid var(--border-color, #334155);
    border-radius: 12px;
    box-shadow: 0 24px 64px rgba(0,0,0,0.6);
    max-width: 860px;
    width: 100%;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.bk-workflow-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border-color, #334155);
    flex-shrink: 0;
}

.bk-workflow-header-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0 0 4px;
    color: var(--text-primary, #f1f5f9);
}

.bk-workflow-header-desc {
    font-size: 0.82rem;
    color: var(--text-muted, #64748b);
    margin: 0;
}

.bk-workflow-dismiss-btn {
    background: none;
    border: 1px solid var(--border-color, #334155);
    color: var(--text-muted, #64748b);
    border-radius: 6px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.85rem;
    flex-shrink: 0;
    margin-left: 12px;
    min-height: unset;
}

.bk-workflow-dismiss-btn:hover {
    background: var(--bg-hover, #2d3f52);
    color: var(--text-primary, #f1f5f9);
}

.bk-workflow-grid-wrap {
    flex: 1;
    overflow-y: auto;
    padding: 16px 24px;
}

.bk-workflow-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 14px;
}

.bk-workflow-card {
    border: 2px solid var(--border-color, #334155);
    border-radius: 10px;
    padding: 14px;
    cursor: pointer;
    background: #161f2e;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
    user-select: none;
}

.bk-workflow-card:hover {
    border-color: var(--primary, #a855f7);
    background: rgba(168,85,247,0.06);
}

.bk-workflow-card.selected {
    border-color: var(--primary, #a855f7);
    background: rgba(168,85,247,0.10);
    box-shadow: 0 0 0 3px rgba(168,85,247,0.18);
}

.bk-workflow-card-name {
    font-size: 0.92rem;
    font-weight: 600;
    color: #e2e8f0;
    margin: 0 0 4px;
}

.bk-workflow-card-desc {
    font-size: 0.78rem;
    color: #94a3b8;
    margin: 0 0 10px;
    line-height: 1.5;
}

.bk-workflow-example-tree {
    font-family: 'Fira Code', 'Courier New', monospace;
    font-size: 0.72rem;
    background: #0d1520;
    border: 1px solid #2d3f52;
    border-radius: 6px;
    padding: 8px 10px;
    margin: 0;
    white-space: pre;
    overflow-x: hidden;
    line-height: 1.7;
    color: #a8c0d6;
    list-style: none;
}

.bk-workflow-example-tree li {
    list-style: none;
    padding: 0;
    margin: 0;
}

.bk-workflow-custom-form {
    margin-top: 16px;
    background: var(--bg-primary, #0f172a);
    border: 1px solid var(--border-color, #334155);
    border-radius: 8px;
    padding: 16px;
}

.bk-workflow-custom-label {
    font-size: 0.82rem;
    color: var(--text-secondary, #94a3b8);
    margin: 0 0 12px;
    font-weight: 500;
}

.bk-workflow-custom-fields {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.bk-workflow-custom-field label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted, #64748b);
    margin-bottom: 4px;
}

.bk-workflow-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 24px;
    border-top: 1px solid var(--border-color, #334155);
    flex-shrink: 0;
}

.bk-workflow-hint {
    font-size: 0.8rem;
    color: var(--text-muted, #64748b);
    margin-right: auto;
}

/* === WORKFLOW BADGE === */
.bk-workflow-badge {
    display: inline-flex;
    align-items: center;
    font-size: 0.68rem;
    padding: 2px 8px;
    border-radius: 20px;
    cursor: pointer;
    border: 1px solid;
    font-weight: 500;
    line-height: 1.4;
    transition: opacity 0.15s;
    white-space: nowrap;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: unset;
}

.bk-workflow-badge:hover { opacity: 0.8; }

.bk-workflow-badge--set {
    background: rgba(168,85,247,0.12);
    border-color: rgba(168,85,247,0.4);
    color: var(--primary, #a855f7);
}

.bk-workflow-badge--unset {
    background: var(--bg-hover, rgba(255,255,255,0.05));
    border-color: var(--border-color, #334155);
    color: var(--text-muted, #64748b);
}

/* === IMPORT REVIEW PANEL === */
.bk-review-panel {
    margin: 10px 8px;
    border-left: 3px solid #f59e0b;
    background: rgba(245,158,11,0.06);
    border-radius: 6px;
    padding: 10px 12px;
}

.bk-review-panel-title {
    font-size: 0.75rem;
    font-weight: 700;
    color: #f59e0b;
    margin: 0 0 8px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.bk-review-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    border-bottom: 1px solid rgba(245,158,11,0.12);
    font-size: 0.72rem;
}

.bk-review-row:last-of-type {
    border-bottom: none;
}

.bk-review-source {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-secondary, #94a3b8);
}

.bk-review-confidence {
    font-size: 0.68rem;
    padding: 1px 6px;
    border-radius: 10px;
    font-weight: 600;
    flex-shrink: 0;
}

.bk-review-confidence--high {
    background: rgba(34,197,94,0.15);
    color: #4ade80;
}

.bk-review-confidence--med {
    background: rgba(245,158,11,0.15);
    color: #fbbf24;
}

.bk-review-confidence--low {
    background: rgba(239,68,68,0.15);
    color: #f87171;
}

.bk-review-level-select {
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 4px;
    color: #e2e8f0;
    font-size: 0.72rem;
    padding: 2px 6px;
    cursor: pointer;
    flex-shrink: 0;
    min-height: unset;
}

.bk-review-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    justify-content: flex-end;
}

/* Responsive: single-column grid at ≤600px */
@media (max-width: 600px) {
    .bk-workflow-grid {
        grid-template-columns: 1fr;
    }
    .bk-workflow-custom-fields {
        grid-template-columns: 1fr;
    }
}

/* ====================================================================
   BOOK STUDIO — HUMANIZE & EVALUATE MODALS
   ==================================================================== */

/* Toolbar button accents */
.bk-humanize-btn { color: #a78bfa; }
.bk-humanize-btn:hover:not(:disabled) { background: rgba(167,139,250,0.1); color: #c4b5fd; }
.bk-evaluate-btn { color: #38bdf8; }
.bk-evaluate-btn:hover:not(:disabled) { background: rgba(56,189,248,0.1); color: #7dd3fc; }
.bk-humanize-btn:disabled,
.bk-evaluate-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* Shared modal overlay */
.bk-he-modal {
    position: fixed;
    inset: 0;
    z-index: 2300;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.68);
    backdrop-filter: blur(4px);
    padding: 16px;
}

/* Panel container */
.bk-he-panel {
    background: #1a2535;
    border: 1px solid #2d3f52;
    border-radius: 12px;
    box-shadow: 0 24px 64px rgba(0,0,0,0.65);
    width: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-height: 90vh;
}

.bk-he-panel--humanize { max-width: 840px; }
.bk-he-panel--evaluate { max-width: 680px; }
.bk-he-panel--reword   { max-width: 680px; }
.bk-reword-preview {
    background: #0a1628;
    border: 1px solid #1e3a5f;
    border-radius: 4px;
    padding: 8px 10px;
    font-size: 0.82rem;
    color: #94a3b8;
    max-height: 120px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.6;
}
.bk-reword-preview--original { opacity: 0.7; }
.bk-reword-btn { color: #a78bfa; }
.bk-reword-btn:hover { color: #c4b5fd; background: rgba(167,139,250,0.08); }

/* Header */
.bk-he-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 18px 22px 14px;
    border-bottom: 1px solid #2d3f52;
    flex-shrink: 0;
}

.bk-he-title {
    font-size: 1.05rem;
    font-weight: 600;
    margin: 0 0 3px;
    color: #e2e8f0;
}

.bk-he-desc {
    font-size: 0.8rem;
    color: #94a3b8;
    margin: 0;
}

.bk-he-close-btn {
    background: none;
    border: 1px solid #334155;
    color: #94a3b8;
    border-radius: 6px;
    width: 28px;
    height: 28px;
    min-height: unset;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.85rem;
    flex-shrink: 0;
    margin-left: 12px;
}

.bk-he-close-btn:hover {
    background: #2d3f52;
    color: #e2e8f0;
}

/* Body */
.bk-he-body {
    flex: 1;
    overflow-y: auto;
    padding: 18px 22px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.bk-he-body--center {
    align-items: center;
    justify-content: center;
    min-height: 160px;
}

.bk-he-body--diff {
    min-height: 300px;
    max-height: 50vh;
    padding: 0;
}

/* Footer */
.bk-he-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 22px;
    border-top: 1px solid #2d3f52;
    flex-shrink: 0;
}

/* Config rows */
.bk-he-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.bk-he-row--col {
    flex-direction: column;
    align-items: stretch;
}

.bk-he-label {
    font-size: 0.82rem;
    font-weight: 500;
    color: #cbd5e1;
    min-width: 130px;
    flex-shrink: 0;
}

.bk-he-label-hint {
    font-size: 0.72rem;
    color: #94a3b8;
    font-weight: 400;
}

/* Radio intensity group */
.bk-he-radio-group {
    display: flex;
    gap: 16px;
}

.bk-he-radio {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.83rem;
    color: #cbd5e1;
    cursor: pointer;
}

.bk-he-radio input[type="radio"] { cursor: pointer; }

/* Toggle */
.bk-he-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.bk-he-toggle input[type="checkbox"] { display: none; }

.bk-he-toggle-track {
    width: 36px;
    height: 20px;
    border-radius: 10px;
    background: #334155;
    border: 1px solid #475569;
    position: relative;
    transition: background 0.2s, border-color 0.2s;
    flex-shrink: 0;
}

.bk-he-toggle-track::after {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #94a3b8;
    top: 2px;
    left: 2px;
    transition: transform 0.2s, background 0.2s;
}

.bk-he-toggle input:checked + .bk-he-toggle-track {
    background: rgba(167,139,250,0.25);
    border-color: rgba(167,139,250,0.5);
}

.bk-he-toggle input:checked + .bk-he-toggle-track::after {
    transform: translateX(16px);
    background: #a78bfa;
}

.bk-he-toggle-label {
    font-size: 0.8rem;
    color: #94a3b8;
}

/* Protected phrases textarea */
.bk-he-protected-input {
    font-family: 'Fira Code', 'Courier New', monospace;
    font-size: 0.78rem;
    resize: vertical;
    min-height: 80px;
}

/* Spinner */
.bk-he-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #334155;
    border-top-color: #a78bfa;
    border-radius: 50%;
    animation: bkHeSpin 0.8s linear infinite;
    margin-bottom: 12px;
}

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

.bk-he-progress-msg {
    font-size: 0.82rem;
    color: #94a3b8;
    text-align: center;
    margin: 0;
}

.bk-he-progress-hint {
    font-size: 0.73rem;
    color: #64748b;
    text-align: center;
    margin: 4px 0 0;
}

/* Warnings */
.bk-he-warnings {
    margin: 0 22px;
    padding: 10px 14px;
    border-left: 3px solid #f59e0b;
    background: rgba(245,158,11,0.07);
    border-radius: 6px;
    font-size: 0.78rem;
    color: #fbbf24;
}

.bk-he-warnings ul { margin: 4px 0 0; padding-left: 16px; }
.bk-he-warnings li { margin-bottom: 3px; }

/* Preview view toggle */
.bk-he-preview-mode-btns {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
    margin-left: 12px;
}

.bk-he-view-btn.active {
    background: rgba(167,139,250,0.15);
    color: #c4b5fd;
    border-color: rgba(167,139,250,0.4);
}

/* Diff view */
.bk-he-diff-wrap {
    display: grid;
    grid-template-columns: 1fr 1fr;
    height: 100%;
    overflow: hidden;
}

.bk-he-diff-pane {
    overflow-y: auto;
    padding: 16px;
    font-size: 0.82rem;
    line-height: 1.7;
    color: #cbd5e1;
    white-space: pre-wrap;
    word-break: break-word;
}

.bk-he-diff-pane:first-child {
    border-right: 1px solid #2d3f52;
    background: rgba(239,68,68,0.03);
}

.bk-he-diff-pane:last-child {
    background: rgba(34,197,94,0.03);
}

.bk-he-diff-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted, #64748b);
    margin-bottom: 10px;
    display: block;
}

/* Single-pane "after" view */
.bk-he-after-wrap {
    padding: 16px;
    font-size: 0.82rem;
    line-height: 1.7;
    color: var(--text-secondary, #94a3b8);
    white-space: pre-wrap;
    word-break: break-word;
    overflow-y: auto;
    height: 100%;
}

/* Evaluate: score cards */
.bk-eval-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.bk-eval-card {
    background: #111c2d;
    border: 1px solid #2d3f52;
    border-radius: 8px;
    padding: 14px 16px;
}

.bk-eval-card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.bk-eval-acronym {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    background: #1e3a5f;
    border: 1px solid #2d5a8e;
    border-radius: 4px;
    padding: 2px 7px;
    color: #93c5fd;
    flex-shrink: 0;
}

.bk-eval-label {
    font-size: 0.88rem;
    font-weight: 600;
    color: #e2e8f0;
    flex: 1;
}

.bk-eval-score {
    font-size: 0.92rem;
    font-weight: 700;
    flex-shrink: 0;
}

.bk-eval-score--na { color: #64748b; }

.bk-eval-bar-track {
    height: 6px;
    background: #1e293b;
    border-radius: 3px;
    margin-bottom: 10px;
    overflow: hidden;
}

.bk-eval-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s ease;
}

.bk-eval-notes {
    font-size: 0.80rem;
    color: #b0bfd0;
    line-height: 1.65;
}

.bk-eval-notes ul { margin: 0; padding-left: 18px; }
.bk-eval-notes li { margin-bottom: 4px; }

/* Score color helpers */
.bk-eval-score--good  { color: #4ade80; }
.bk-eval-score--ok    { color: #fbbf24; }
.bk-eval-score--warn  { color: #f87171; }
.bk-eval-bar--good  { background: #4ade80; }
.bk-eval-bar--ok    { background: #fbbf24; }
.bk-eval-bar--warn  { background: #f87171; }

/* =============================================================================
   Dev Cockpit — Cursor / VS Code-style IDE
   ============================================================================= */

/* Cursor colour tokens (independent of app theme) */
.dc-fullbleed,
.dc-layout,
.dc-left,
.dc-center,
.dc-right,
.dc-bottom {
  --dc-bg:        #1e1e1e;
  --dc-sidebar:   #252526;
  --dc-panel:     #1e1e1e;
  --dc-titlebar:  #323233;
  --dc-border:    #3c3c3c;
  --dc-hover:     rgba(255,255,255,0.06);
  --dc-active:    rgba(255,255,255,0.10);
  --dc-text:      #cccccc;
  --dc-text-dim:  #858585;
  --dc-accent:    #0098ff;
  --dc-accent2:   #c586c0;
  --dc-green:     #4ec9b0;
  --dc-yellow:    #dcdcaa;
  --dc-orange:    #ce9178;
  --dc-red:       #f44747;
}

/* Full-bleed: strip page padding, fill height */
.dc-fullbleed {
  padding: 0 !important;
  overflow: hidden !important;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--dc-bg);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

/* 4-panel grid — Explorer | Editor | Chat   /   Panel bar (resizable via CSS vars) */
.dc-layout {
  --dc-left-w: 240px;
  --dc-right-w: 320px;
  --dc-bottom-h: 200px;
  --dc-resizer-size: 4px;
  --dc-resizer-h-size: 10px;
  display: grid;
  grid-template-columns: var(--dc-left-w) var(--dc-resizer-size) 1fr var(--dc-resizer-size) var(--dc-right-w);
  grid-template-rows: minmax(0, 1fr) var(--dc-resizer-h-size) var(--dc-bottom-h);
  grid-template-areas:
    "left resizer-v1 center resizer-v2 right"
    "resizer-h resizer-h resizer-h resizer-h resizer-h"
    "bottom bottom bottom bottom bottom";
  flex: 1;
  min-height: 0;
  overflow: hidden;
  height: calc(100vh - 56px);
  max-height: calc(100vh - 56px);
}

/* Resizer strips — draggable */
.dc-resizer {
  background: var(--dc-border);
  z-index: 10;
  flex-shrink: 0;
  touch-action: none;  /* Prevent browser from stealing pointer events for scrolling */
}
.dc-resizer:hover,
.dc-resizer.dc-resizer-dragging {
  background: var(--dc-accent);
}
body.dc-resizer-dragging {
  user-select: none;
}
.dc-resizer-v {
  cursor: col-resize;
  width: var(--dc-resizer-size);
  min-width: var(--dc-resizer-size);
}
#dc-resizer-left  { grid-area: resizer-v1; }
#dc-resizer-right { grid-area: resizer-v2; }
.dc-resizer-h {
  grid-area: resizer-h;
  cursor: row-resize;
  height: var(--dc-resizer-h-size);
  min-height: var(--dc-resizer-h-size);
  position: relative;
}
/* Bottom resizer — thick enough to grab without pseudo-element tricks */
#dc-resizer-bottom {
  background: #555;
  position: relative;
  z-index: 10;
  background-image: radial-gradient(circle, #999 1.5px, transparent 1.5px);
  background-size: 12px 4px;
  background-repeat: repeat-x;
  background-position: center;
}

/* ----- Panel containers ----- */
.dc-left {
  grid-area: left;
  background: var(--dc-sidebar);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.dc-center {
  grid-area: center;
  background: var(--dc-bg);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.dc-right {
  grid-area: right;
  background: var(--dc-sidebar);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.dc-bottom {
  grid-area: bottom;
  background: var(--dc-panel);
  padding: 0;  /* Override global footer { padding: 24px 0 } */
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  text-align: left; /* Override footer { text-align: center } which bleeds into xterm rows */
}

/* ----- Explorer header ----- */
.dc-explorer-header {
  padding: 8px 12px 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--dc-text-dim);
  flex-shrink: 0;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.dc-refresh-btn {
  background: none;
  border: none;
  color: var(--dc-text-dim);
  font-size: 14px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  border-radius: 3px;
}
.dc-refresh-btn:hover {
  color: var(--dc-text);
  background: var(--dc-hover);
}

/* ----- Search bar (Explorer) ----- */
.dc-search-bar {
  padding: 4px 8px 6px;
  border-bottom: 1px solid var(--dc-border);
  flex-shrink: 0;
}
.dc-search-bar input {
  width: 100%;
  box-sizing: border-box;
  padding: 4px 8px;
  background: var(--dc-bg);
  border: 1px solid transparent;
  border-radius: 2px;
  color: var(--dc-text);
  font-size: 12px;
  font-family: inherit;
  outline: none;
}
.dc-search-bar input::placeholder { color: var(--dc-text-dim); }
.dc-search-bar input:focus { border-color: var(--dc-accent); }

/* ----- File tree ----- */
.dc-file-tree {
  flex: 1;
  min-height: 0;
  max-height: 100%;
  overflow-y: scroll !important;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}
/* Force scrollable file list in Code section — explicit height so scroll always works */
#page-code .dc-left .dc-file-tree {
  height: 100%;
  max-height: calc(100vh - 280px);
  overflow-y: scroll !important;
  overflow-x: hidden;
}
.dc-tree-list { list-style: none; margin: 0; padding: 0; }
.dc-tree-item { cursor: pointer; user-select: none; }

.dc-tree-label {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 0 2px 0;
  font-size: 13px;
  color: var(--dc-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 22px;
}
.dc-tree-label:hover { background: var(--dc-hover); }
.dc-tree-item.dc-tree-active > .dc-tree-label { background: var(--dc-active); }

.dc-tree-chevron {
  display: inline-block;
  width: 16px;
  text-align: center;
  font-size: 10px;
  color: var(--dc-text-dim);
  flex-shrink: 0;
  transition: transform .15s;
}
.dc-tree-icon   { flex-shrink: 0; font-size: 13px; }
.dc-tree-name   { overflow: hidden; text-overflow: ellipsis; }

/* Search results */
.dc-search-result { border-bottom: 1px solid var(--dc-border); }
.dc-result-file {
  display: block;
  padding: 4px 12px 1px;
  font-size: 11px;
  color: var(--dc-accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dc-result-line {
  display: block;
  padding: 1px 12px 4px;
  font-size: 11px;
  font-family: 'Consolas', 'Courier New', monospace;
  color: var(--dc-text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dc-search-result:hover .dc-result-line { color: var(--dc-text); }
.dc-search-truncated { padding: 4px 12px; font-size: 11px; color: var(--dc-text-dim); font-style: italic; }

/* ----- Editor tab bar ----- */
.dc-tabs {
  height: 35px;
  display: flex;
  align-items: stretch;
  background: var(--dc-titlebar);
  border-bottom: 1px solid var(--dc-border);
  overflow-x: auto;
  flex-shrink: 0;
}
.dc-tabs::-webkit-scrollbar { height: 2px; }
.dc-tabs::-webkit-scrollbar-thumb { background: var(--dc-border); }

.dc-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 16px;
  font-size: 12px;
  color: var(--dc-text-dim);
  white-space: nowrap;
  cursor: pointer;
  border-right: 1px solid var(--dc-border);
  background: var(--dc-titlebar);
  flex-shrink: 0;
  min-width: 80px;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dc-tab:hover { background: var(--dc-bg); color: var(--dc-text); }
.dc-tab-active {
  background: var(--dc-bg);
  color: var(--dc-text);
  border-top: 1px solid var(--dc-accent);
}
.dc-tab-empty {
  flex: 1;
  cursor: default;
}
.dc-tab-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--dc-text-dim);
  cursor: pointer;
  padding: 0 2px;
  font-size: 14px;
  line-height: 1;
  border-radius: 3px;
  opacity: 0;
  flex-shrink: 0;
}
.dc-tab:hover .dc-tab-close,
.dc-tab-active .dc-tab-close { opacity: 0.6; }
.dc-tab-close:hover { opacity: 1 !important; background: rgba(255,255,255,0.12); }

/* ----- Monaco container ----- */
.dc-editor-container {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: var(--dc-bg);
}
.dc-editor-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--dc-text-dim);
  font-size: 13px;
  flex-direction: column;
  gap: 8px;
}
.dc-editor-placeholder-icon { font-size: 48px; opacity: .3; }

/* ----- Chat panel (right) ----- */
.dc-chat-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--dc-border);
  background: var(--dc-titlebar);
  flex-shrink: 0;
}
.dc-chat-toolbar-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--dc-text-dim);
  flex: 1;
}
.dc-model-select {
  background: var(--dc-bg);
  border: 1px solid var(--dc-border);
  color: var(--dc-text);
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 2px;
  cursor: pointer;
  outline: none;
  max-width: 160px;
}
.dc-model-select:focus { border-color: var(--dc-accent); }

.dc-chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  background: var(--dc-sidebar);
}

.dc-chat-msg {
  padding: 8px 10px;
  border-radius: 3px;
  font-size: 12.5px;
  line-height: 1.5;
  word-wrap: break-word;
}
.dc-chat-user {
  background: rgba(0,152,255,.12);
  color: var(--dc-text);
  border-left: 2px solid var(--dc-accent);
}
.dc-chat-assistant {
  background: rgba(255,255,255,.04);
  color: var(--dc-text);
}

.dc-chat-input-wrap {
  padding: 8px;
  border-top: 1px solid var(--dc-border);
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
  background: var(--dc-sidebar);
}
.dc-chat-input-wrap textarea {
  width: 100%;
  box-sizing: border-box;
  background: var(--dc-bg);
  border: 1px solid var(--dc-border);
  border-radius: 3px;
  color: var(--dc-text);
  font-size: 12px;
  font-family: inherit;
  resize: none;
  padding: 7px 10px;
  outline: none;
}
.dc-chat-input-wrap textarea:focus { border-color: var(--dc-accent); }
.dc-chat-input-wrap textarea.dc-chat-drop-active {
  border-color: var(--dc-accent);
  background: rgba(0, 152, 255, 0.08);
}

/* @-mention autocomplete popup */
.dc-at-popup {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  max-height: 220px;
  overflow-y: auto;
  background: #252526;
  border: 1px solid var(--dc-border);
  border-radius: 4px;
  margin-bottom: 4px;
  z-index: 100;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.4);
}
.dc-at-item {
  padding: 6px 10px;
  cursor: pointer;
  font-size: 12px;
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dc-at-item:hover,
.dc-at-item.dc-at-selected {
  background: var(--dc-accent);
  color: #fff;
}
.dc-at-dir {
  color: var(--dc-text-dim);
}
.dc-at-item.dc-at-selected .dc-at-dir,
.dc-at-item:hover .dc-at-dir {
  color: rgba(255,255,255,0.7);
}
.dc-at-name {
  color: var(--dc-text);
}
.dc-at-item.dc-at-selected .dc-at-name,
.dc-at-item:hover .dc-at-name {
  color: #fff;
}
.dc-chat-input-wrap .btn {
  align-self: flex-end;
  font-size: 12px;
  padding: 5px 14px;
  background: var(--dc-accent);
  color: #fff;
  border: none;
  border-radius: 3px;
  cursor: pointer;
}
.dc-chat-input-wrap .btn:hover { filter: brightness(1.1); }
.dc-chat-input-wrap .btn:disabled { opacity: .5; cursor: default; }

/* ----- Step / agent cards ----- */
.dc-step-card {
  border-radius: 3px;
  border-left: 2px solid var(--dc-border);
  background: rgba(255,255,255,.03);
  padding: 7px 9px;
  font-size: 12px;
  color: var(--dc-text);
}
.dc-step-tool     { border-color: #dcdcaa; }   /* yellow */
.dc-step-proposal { border-color: #c586c0; }   /* purple */
.dc-step-final    { border-color: #4ec9b0; }   /* teal */
.dc-step-error    { border-color: #f44747; background: rgba(244,71,71,.08); color: #f97171; }
.dc-step-thinking { border-color: #0098ff; color: var(--dc-text-dim); font-style: italic; }
.dc-step-discarded { opacity: .35; pointer-events: none; }

.dc-step-header {
  cursor: pointer;
  display: flex;
  align-items: flex-start;
  gap: 6px;
  flex-wrap: wrap;
  color: var(--dc-text);
}
.dc-step-header code {
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 11px;
  background: rgba(0,0,0,.35);
  padding: 1px 4px;
  border-radius: 2px;
  word-break: break-all;
  color: var(--dc-orange);
}
.dc-step-icon { flex-shrink: 0; }
.dc-step-body {
  margin-top: 5px;
  white-space: pre-wrap;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 11px;
  color: var(--dc-text-dim);
  max-height: 180px;
  overflow-y: auto;
  background: rgba(0,0,0,.2);
  padding: 4px 6px;
  border-radius: 2px;
}
.dc-step-body-hidden { display: none; }

.dc-proposal-file {
  padding: 5px 0;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  border-bottom: 1px solid rgba(255,255,255,.05);
}
.dc-proposal-file code {
  flex: 1;
  font-size: 11px;
  font-family: 'Consolas', monospace;
  color: var(--dc-accent);
}
.dc-proposal-actions { display: flex; gap: 6px; margin-top: 7px; }

.dc-btn-diff, .dc-btn-apply, .dc-btn-discard {
  font-size: 11px;
  padding: 3px 10px;
  cursor: pointer;
  border-radius: 2px;
  border: 1px solid var(--dc-border);
  font-family: inherit;
  background: transparent;
  color: var(--dc-text-dim);
}
.dc-btn-apply   { background: var(--dc-accent); color: #fff; border-color: var(--dc-accent); }
.dc-btn-diff:hover    { color: var(--dc-text); border-color: #666; }
.dc-btn-apply:hover   { filter: brightness(1.12); }
.dc-btn-discard:hover { color: var(--dc-red); border-color: var(--dc-red); }

.dc-risk {
  padding: 1px 6px;
  border-radius: 2px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  flex-shrink: 0;
}
.dc-risk-low    { background: rgba(78,201,176,.15); color: #4ec9b0; }
.dc-risk-medium { background: rgba(220,220,170,.15); color: #dcdcaa; }
.dc-risk-high   { background: rgba(244,71,71,.15);   color: #f44747; }

.dc-verify-steps { margin: 6px 0 0 14px; padding: 0; color: var(--dc-text); }
.dc-verify-steps li { margin-bottom: 3px; font-size: 12px; }

/* ----- Bottom panel bar ----- */
.dc-bottom-tabs {
  display: flex;
  align-items: stretch;
  padding: 0;
  background: var(--dc-titlebar);
  border-bottom: 1px solid var(--dc-border);
  flex-shrink: 0;
}
.dc-btab {
  padding: 5px 14px;
  font-size: 12px;
  background: transparent;
  border: none;
  border-top: 1px solid transparent;
  color: var(--dc-text-dim);
  cursor: pointer;
  font-family: inherit;
  letter-spacing: .02em;
}
.dc-btab:hover { color: var(--dc-text); }
.dc-btab.active { color: var(--dc-text); border-top-color: var(--dc-accent); background: var(--dc-bg); }

.dc-panel { flex: 1; overflow-y: auto; min-height: 0; }
.dc-panel-hidden { display: none !important; }

/* Terminal */
.dc-term-toolbar {
  padding: 3px 8px;
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  background: var(--dc-titlebar);
  border-bottom: 1px solid var(--dc-border);
}
.dc-term-toolbar button {
  padding: 2px 10px;
  font-size: 11px;
  background: transparent;
  border: 1px solid var(--dc-border);
  border-radius: 2px;
  color: var(--dc-text-dim);
  cursor: pointer;
  font-family: inherit;
}
.dc-term-toolbar button:hover { color: var(--dc-text); border-color: #666; }
#dc-panel-terminal { display: flex; flex-direction: column; background: var(--dc-bg); min-width: 0; }
.dc-terminal-container {
  flex: 1;
  min-height: 0;
  min-width: 0;
  width: 100%;
  overflow: hidden;
  background: #1a1a1a;
  padding: 0;
  position: relative; /* Containing block for absolutely-positioned .xterm child */
}
/* Pin .xterm to all four edges of the container so it always fills the full area,
   bypassing any flex/block sizing quirks that might offset or shrink it. */
.dc-terminal-container .xterm {
  position: absolute !important;
  left: 0 !important;
  top: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: auto !important;
  height: auto !important;
}
.dc-terminal-container .xterm-viewport {
  overflow-y: hidden !important;
  overflow-x: hidden !important;
}
.dc-terminal-container .xterm-screen,
.dc-terminal-container .xterm-rows {
  width: 100% !important;
}

/* Logs */
.dc-log-row {
  display: flex;
  gap: 8px;
  padding: 2px 10px;
  font-size: 11.5px;
  font-family: 'Consolas', monospace;
  border-bottom: 1px solid rgba(60,60,60,.5);
}
.dc-log-row:hover { background: var(--dc-hover); }
.dc-log-ts  { color: var(--dc-text-dim); flex-shrink: 0; min-width: 62px; }
.dc-log-cat { color: #9cdcfe; flex-shrink: 0; min-width: 70px; }
.dc-log-msg { color: var(--dc-text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dc-log-error .dc-log-msg   { color: #f44747; }
.dc-log-warning .dc-log-msg { color: #dcdcaa; }
.dc-log-info .dc-log-msg    { color: var(--dc-text-dim); }

/* Jobs/Outputs */
.dc-job-card {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 7px 10px;
  border-bottom: 1px solid rgba(60,60,60,.5);
  font-size: 12px;
}
.dc-job-card:hover { background: var(--dc-hover); }
.dc-job-status {
  padding: 1px 7px;
  border-radius: 2px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  flex-shrink: 0;
  letter-spacing: .05em;
}
.dc-job-complete .dc-job-status { background: rgba(78,201,176,.15); color: #4ec9b0; }
.dc-job-error   .dc-job-status  { background: rgba(244,71,71,.15);  color: #f44747; }
.dc-job-stopped .dc-job-status  { background: rgba(220,220,170,.15); color: #dcdcaa; }
.dc-job-model { color: var(--dc-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dc-job-ts    { color: var(--dc-text-dim); font-size: 11px; margin-left: auto; flex-shrink: 0; }
.dc-job-dur   { color: var(--dc-text-dim); font-size: 11px; flex-shrink: 0; }
.dc-job-file  { color: var(--dc-accent); font-size: 11px; flex-shrink: 0; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Utility */
.dc-loading { padding: 24px; text-align: center; color: var(--dc-text-dim); font-size: 12px; }
.dc-empty   { padding: 24px; text-align: center; color: var(--dc-text-dim); font-size: 12px; }
.dc-error   { padding: 8px 12px; color: #f44747; font-size: 12px; }

/* Toasts */
.dc-toast {
  position: fixed;
  bottom: 28px;
  right: 28px;
  padding: 9px 16px;
  border-radius: 3px;
  font-size: 12.5px;
  z-index: 9999;
  transition: opacity .35s;
  box-shadow: 0 4px 14px rgba(0,0,0,.6);
  font-family: inherit;
}
.dc-toast-success { background: #1e3a2e; color: #4ec9b0; border: 1px solid #4ec9b0; }
.dc-toast-error   { background: #3a1e1e; color: #f44747; border: 1px solid #f44747; }
.dc-toast-info    { background: #1e2d3a; color: #9cdcfe; border: 1px solid #0098ff; }
.dc-toast-fade    { opacity: 0; }

/* Thin scrollbars — VS Code feel (file tree scrollbar visible) */
.dc-file-tree::-webkit-scrollbar,
.dc-chat-history::-webkit-scrollbar,
.dc-panel::-webkit-scrollbar,
.dc-step-body::-webkit-scrollbar { width: 10px; height: 10px; }
.dc-file-tree::-webkit-scrollbar-track,
.dc-chat-history::-webkit-scrollbar-track,
.dc-panel::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); }
.dc-file-tree::-webkit-scrollbar-thumb,
.dc-chat-history::-webkit-scrollbar-thumb,
.dc-panel::-webkit-scrollbar-thumb,
.dc-step-body::-webkit-scrollbar-thumb { background: #424242; border-radius: 5px; }
.dc-file-tree::-webkit-scrollbar-thumb:hover,
.dc-chat-history::-webkit-scrollbar-thumb:hover { background: #555; }

/* ================================================================
   TRAIN TAB - Dev Cockpit Training Panel
   ================================================================ */

/* ----- Keyframe animations ----- */
@keyframes train-status-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.4; }
}
@keyframes train-log-fadein {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ----- Train panel layout ----- */
#dc-panel-train {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto 1fr;
  gap: 0;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  background: var(--dc-bg);
  color: var(--dc-text);
}
#dc-panel-train .train-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  grid-template-areas:
    "terminal progress"
    "logs     reports";
  gap: 1px;
  min-height: 0;
  overflow: hidden;
  background: var(--dc-border);
}

/* ----- Training controls bar ----- */
.train-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  background: var(--dc-titlebar);
  border-bottom: 1px solid var(--dc-border);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.train-controls label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  color: var(--dc-text-dim);
  text-transform: uppercase;
}
.train-controls select {
  background: var(--dc-bg);
  border: 1px solid var(--dc-border);
  color: var(--dc-text);
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 3px;
  cursor: pointer;
  outline: none;
  font-family: inherit;
  min-width: 100px;
}
.train-controls select:focus {
  border-color: var(--dc-accent);
}
.train-controls select option {
  background: var(--dc-bg);
  color: var(--dc-text);
}

.train-btn-start,
.train-btn-stop {
  padding: 5px 16px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  letter-spacing: .03em;
  transition: filter 0.15s, opacity 0.15s;
}
.train-btn-start {
  background: #00ff88;
  color: #0a0a0a;
}
.train-btn-start:hover {
  filter: brightness(1.15);
}
.train-btn-start:disabled {
  opacity: 0.4;
  cursor: default;
  filter: none;
}
.train-btn-stop {
  background: #ff4444;
  color: #fff;
}
.train-btn-stop:hover {
  filter: brightness(1.15);
}
.train-btn-stop:disabled {
  opacity: 0.4;
  cursor: default;
  filter: none;
}
.train-btn-force-stop {
  background: #8b0000;
  color: #fff;
  font-size: 11px;
}
.train-btn-force-stop:hover {
  filter: brightness(1.2);
}
.train-btn-force-stop:disabled {
  opacity: 0.4;
  cursor: default;
  filter: none;
}

/* Cleanup button */
.train-btn-cleanup {
  background: #ff8800;
  color: #000;
  font-size: 12px;
  font-weight: 600;
}
.train-btn-cleanup:hover {
  filter: brightness(1.15);
}
.train-btn-cleanup:disabled {
  opacity: 0.5;
  cursor: default;
  filter: none;
}
.train-btn-cleanup #train-stale-count {
  font-weight: 700;
}

/* Confirmation overlay */
.train-confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 100000;
  background: rgba(0, 0, 0, 0);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.3s ease;
}
.train-confirm-overlay.train-confirm-visible {
  background: rgba(0, 0, 0, 0.75);
}
.train-confirm-dialog {
  background: #141422;
  border: 1px solid #333;
  border-radius: 12px;
  padding: 32px;
  max-width: 460px;
  width: 90%;
  text-align: center;
  transform: scale(0.9);
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
}
.train-confirm-visible .train-confirm-dialog {
  transform: scale(1);
  opacity: 1;
}
.train-confirm-icon {
  font-size: 48px;
  margin-bottom: 8px;
  line-height: 1;
}
.train-confirm-title {
  color: #fff;
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 12px 0;
}
.train-confirm-text {
  color: #aaa;
  font-size: 14px;
  line-height: 1.5;
  margin: 0 0 16px 0;
}
.train-confirm-text strong {
  color: #ff8844;
}
.train-confirm-summary {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  padding: 12px 16px;
  margin: 0 0 12px 0;
  display: flex;
  justify-content: space-around;
  gap: 12px;
  font-size: 13px;
  color: #ccc;
}
.train-confirm-summary strong {
  color: #00d4ff;
}
.train-confirm-warn {
  background: rgba(255, 136, 0, 0.1);
  border: 1px solid rgba(255, 136, 0, 0.25);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 12px;
  color: #ff8844;
  margin: 0 0 20px 0;
}
.train-confirm-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}
.train-confirm-actions .train-btn {
  min-width: 120px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: filter 0.15s;
}
.train-btn-cancel {
  background: #333;
  color: #ccc;
}
.train-btn-cancel:hover {
  filter: brightness(1.3);
}

/* Status indicator dot */
.train-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  background: #555;
  transition: background 0.3s;
}
.train-status-dot.running {
  background: #00ff88;
  animation: train-status-pulse 1.4s ease-in-out infinite;
}
.train-status-dot.stopped {
  background: #555;
  animation: none;
}
.train-status-dot.error {
  background: #ff4444;
  animation: train-status-pulse 0.8s ease-in-out infinite;
}

.train-status-label {
  font-size: 11px;
  color: var(--dc-text-dim);
  margin-left: -4px;
}

/* ----- Progress section ----- */
.train-progress {
  grid-area: progress;
  background: var(--dc-bg);
  padding: 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}
.train-progress-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.train-progress-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--dc-text-dim);
}
.train-progress-label span {
  color: var(--dc-text);
  font-variant-numeric: tabular-nums;
}
.train-progress-track {
  width: 100%;
  height: 8px;
  background: #1a1a2e;
  border-radius: 4px;
  overflow: hidden;
}
.train-progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
  width: 0%;
}
.train-progress-fill.phase {
  background: var(--dc-accent, #0098ff);
}
.train-progress-fill.epoch {
  background: #00ff88;
}

/* Loss display */
.train-loss-display {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.train-loss-value {
  font-size: 28px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--dc-text);
  letter-spacing: -0.02em;
}
.train-loss-label {
  font-size: 11px;
  color: var(--dc-text-dim);
  text-transform: uppercase;
  letter-spacing: .06em;
}

/* KPI cards grid */
.train-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
}
.train-kpi-card {
  background: rgba(255,255,255,.03);
  border: 1px solid var(--dc-border);
  border-radius: 4px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.train-kpi-card-value {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--dc-text);
}
.train-kpi-card-label {
  font-size: 10px;
  color: var(--dc-text-dim);
  text-transform: uppercase;
  letter-spacing: .06em;
}

/* ----- Terminal section ----- */
.train-terminal {
  grid-area: terminal;
  background: #1a1a1a;
  min-height: 300px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  resize: vertical;
}
.train-terminal-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: var(--dc-titlebar);
  border-bottom: 1px solid var(--dc-border);
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--dc-text-dim);
}
.train-terminal-body {
  flex: 1;
  min-height: 0;
  width: 100%;
  overflow: hidden;
  position: relative;
}
/* xterm.js container inside the train terminal */
.train-terminal-body .xterm {
  position: absolute !important;
  left: 0 !important;
  top: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: auto !important;
  height: auto !important;
}

/* ----- Log viewer ----- */
.train-logs {
  grid-area: logs;
  background: var(--dc-bg);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.train-logs-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: var(--dc-titlebar);
  border-bottom: 1px solid var(--dc-border);
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--dc-text-dim);
}
.train-logs-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 11.5px;
  line-height: 1.55;
}
.train-log-line {
  padding: 2px 10px;
  color: var(--dc-text-dim);
  border-bottom: 1px solid rgba(60,60,60,.35);
  white-space: pre-wrap;
  word-break: break-all;
  animation: train-log-fadein 0.25s ease;
}
.train-log-line:hover {
  background: var(--dc-hover);
  color: var(--dc-text);
}
.train-log-line.error {
  color: var(--dc-red);
}
.train-log-line.warn {
  color: var(--dc-yellow);
}
.train-log-line .log-ts {
  color: var(--dc-text-dim);
  margin-right: 8px;
  font-size: 10px;
}

/* Thin scrollbar for logs */
.train-logs-body::-webkit-scrollbar { width: 8px; }
.train-logs-body::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); }
.train-logs-body::-webkit-scrollbar-thumb { background: #424242; border-radius: 4px; }
.train-logs-body::-webkit-scrollbar-thumb:hover { background: #555; }

/* ----- Reports section ----- */
.train-reports {
  grid-area: reports;
  background: var(--dc-bg);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.train-reports-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: var(--dc-titlebar);
  border-bottom: 1px solid var(--dc-border);
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--dc-text-dim);
}
.train-reports-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0;
  margin: 0;
  list-style: none;
}
.train-report-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(60,60,60,.35);
  cursor: pointer;
  transition: background 0.15s;
  font-size: 12px;
}
.train-report-item:hover {
  background: var(--dc-hover);
}
.train-report-icon {
  flex-shrink: 0;
  font-size: 14px;
  color: var(--dc-accent);
}
.train-report-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.train-report-name {
  color: var(--dc-text);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.train-report-meta {
  font-size: 10px;
  color: var(--dc-text-dim);
  display: flex;
  gap: 10px;
}
.train-report-date,
.train-report-size {
  white-space: nowrap;
}

/* Thin scrollbar for reports */
.train-reports-list::-webkit-scrollbar { width: 8px; }
.train-reports-list::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); }
.train-reports-list::-webkit-scrollbar-thumb { background: #424242; border-radius: 4px; }
.train-reports-list::-webkit-scrollbar-thumb:hover { background: #555; }

/* ----- Mobile responsive (max-width: 768px) ----- */
@media (max-width: 768px) {
  #dc-panel-train .train-body {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto;
    grid-template-areas:
      "terminal"
      "progress"
      "logs"
      "reports";
    overflow-y: auto;
  }

  .train-controls {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
  }
  .train-controls select,
  .train-btn-start,
  .train-btn-stop {
    min-height: 44px;
    font-size: 14px;
    padding: 8px 16px;
  }
  .train-controls label {
    font-size: 12px;
    width: 100%;
  }

  .train-terminal {
    min-height: 250px;
    resize: none;
  }

  .train-progress {
    padding: 10px;
  }
  .train-loss-value {
    font-size: 22px;
  }
  .train-kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .train-kpi-card {
    padding: 8px;
  }
  .train-kpi-card-value {
    font-size: 15px;
  }

  .train-logs-body {
    max-height: 300px;
    font-size: 11px;
  }
  .train-log-line {
    padding: 4px 10px;
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .train-report-item {
    min-height: 44px;
    padding: 10px 12px;
  }
  .train-report-name {
    font-size: 13px;
  }
  .train-report-meta {
    font-size: 11px;
  }
}


/* ================================================================
   TRAIN PAGE — NVIDIA-style dashboard (3-row vertical layout)
   ================================================================ */

/* Main layout: vertical flex column */
.train-layout {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 56px);
  max-height: calc(100vh - 56px);
  overflow: hidden;
  background: #111122;
  color: #ccc;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  flex: 1;
  min-width: 0;
}

/* ---- ROW 1: Control Bar ---- */
.train-control-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  background: #151528;
  border-bottom: 1px solid #2a2a44;
  flex-shrink: 0;
  height: 56px;
  box-sizing: border-box;
}
.train-bar-title {
  font-size: 15px;
  font-weight: 700;
  color: #eee;
  margin: 0;
  white-space: nowrap;
}
.train-bar-select {
  padding: 6px 10px;
  background: #1a1a2e;
  border: 1px solid #2a2a44;
  border-radius: 4px;
  color: #ccc;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  min-width: 120px;
}
.train-bar-select:focus { border-color: #00d4ff; }
.train-bar-select:disabled { opacity: 0.5; cursor: default; }
.train-bar-spacer { flex: 1; }

/* Shared button base */
.train-layout .train-btn {
  padding: 6px 16px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  letter-spacing: .03em;
  transition: filter 0.15s, opacity 0.15s;
  white-space: nowrap;
}
.train-layout .train-btn-start { background: #00d4ff; color: #0a0a1a; }
.train-layout .train-btn-start:hover { filter: brightness(1.15); }
.train-layout .train-btn-start:disabled { opacity: 0.35; cursor: default; filter: none; }
.train-layout .train-btn-stop { background: #ff4455; color: #fff; }
.train-layout .train-btn-stop:hover { filter: brightness(1.15); }
.train-layout .train-btn-stop:disabled { opacity: 0.35; cursor: default; filter: none; }
.train-layout .train-btn-force-stop { background: #8b0000; color: #fff; font-size: 11px; }
.train-layout .train-btn-force-stop:hover { filter: brightness(1.2); }
.train-layout .train-btn-force-stop:disabled { opacity: 0.35; cursor: default; filter: none; }
.train-layout .train-btn-cleanup { background: #ff8800; color: #000; font-size: 12px; font-weight: 600; }
.train-layout .train-btn-cleanup:hover { filter: brightness(1.15); }
.train-layout .train-btn-cleanup:disabled { opacity: 0.5; cursor: default; filter: none; }
.train-layout .train-btn-cleanup #train-stale-count { font-weight: 700; }

/* Status badge */
.train-status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  flex-shrink: 0;
}
.train-badge-idle { background: rgba(255,255,255,0.08); color: #888; }
.train-badge-running { background: rgba(0,212,255,0.15); color: #00d4ff; animation: train-status-pulse 1.5s ease-in-out infinite; }
.train-badge-completed { background: rgba(78,201,176,0.15); color: #4ec9b0; }

/* ---- Time info strip ---- */
.train-time-strip {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 6px 20px;
  background: #12122a;
  border-bottom: 1px solid #2a2a44;
  flex-shrink: 0;
}
.train-time-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
}
.train-time-item:first-child { padding-left: 0; }
.train-time-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: #666;
}
.train-time-value {
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: #ccc;
  white-space: nowrap;
}
.train-time-value.train-time-active {
  color: #00d4ff;
}
.train-time-value.train-time-done {
  color: #4ec9b0;
}
.train-time-sep {
  width: 1px;
  height: 18px;
  background: #2a2a44;
  flex-shrink: 0;
}
/* Elapsed (used in time strip) */
.train-elapsed {
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: #ccc;
  white-space: nowrap;
}

/* ---- ROW 2: Dashboard Grid ---- */
.train-dashboard {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  padding: 20px;
  flex-shrink: 0;
  overflow: hidden;
  max-height: 420px;
  min-height: 220px;
}

/* Dashboard cards */
.train-dash-card {
  background: #141422;
  border: 1px solid #2a2a44;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
.train-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(42,42,68,0.4);
  flex-shrink: 0;
}
.train-card-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: #888;
}
.train-card-value {
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #eee;
}
.train-card-value.train-loss-val { color: #ff6b6b; }
.train-loss-good { color: #4ec9b0 !important; }
.train-loss-ok   { color: #dcdcaa !important; }
.train-loss-high { color: #f44747 !important; }

.train-card-body {
  flex: 1;
  min-height: 0;
  padding: 8px 12px;
  display: flex;
  align-items: stretch;
}
.train-card-body canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Gauge + sparkline layout inside card */
.train-card-gauge-body {
  display: flex;
  gap: 8px;
}
.train-gauge-wrap {
  flex: 0 0 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
}
.train-gauge {
  width: 100%;
  max-width: 160px;
}
.train-gauge-label {
  font-size: 10px;
  color: #666;
  text-align: center;
  margin-top: -4px;
}
.train-spark-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: stretch;
}
.train-spark-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Progress card: ring + bars */
.train-card-progress-body {
  display: flex;
  gap: 12px;
  align-items: center;
}
.train-ring-wrap {
  flex: 0 0 90px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.train-ring {
  width: 90px;
  height: 90px;
}
.train-ring-text {
  position: absolute;
  font-size: 16px;
  font-weight: 700;
  color: #00d4ff;
  font-variant-numeric: tabular-nums;
}
.train-bars-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  justify-content: center;
}
.train-minibar-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.train-minibar-label {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: #888;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.train-minibar-label span:last-child {
  font-variant-numeric: tabular-nums;
  color: #aaa;
}
.train-minibar-track {
  width: 100%;
  height: 6px;
  background: #1a1a2e;
  border-radius: 3px;
  overflow: hidden;
}
.train-minibar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
  width: 0%;
}
.train-minibar-fill.phase { background: #0098ff; }
.train-minibar-fill.epoch { background: #00ff88; }
.train-minibar-fill.step  { background: #facc15; }

/* ---- Resize handle ---- */
.train-resize-handle {
  height: 6px;
  background: #1a1a2e;
  cursor: ns-resize;
  flex-shrink: 0;
  position: relative;
  transition: background 0.15s;
}
.train-resize-handle:hover,
.train-resize-handle:active {
  background: #00d4ff;
}
.train-resize-handle::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 2px;
  background: #444;
  border-radius: 1px;
}
.train-resize-handle:hover::after { background: #111; }

/* ---- ROW 3: Bottom (terminal/logs/reports) ---- */
.train-bottom {
  flex: 1;
  min-height: 180px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #0d0d1a;
}

/* Output tab bar */
.train-output-tabs {
  display: flex;
  align-items: stretch;
  background: #1a1a2e;
  border-bottom: 1px solid #2a2a44;
  flex-shrink: 0;
  height: 34px;
}
.train-otab {
  display: inline-flex;
  align-items: center;
  padding: 0 16px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  color: #666;
  background: none;
  border: none;
  border-top: 2px solid transparent;
  cursor: pointer;
  letter-spacing: .03em;
  transition: color 0.15s;
}
.train-otab:hover { color: #aaa; }
.train-otab.active {
  color: #00d4ff;
  border-top-color: #00d4ff;
  background: #0d0d1a;
}

/* Output panels */
.train-output-panel {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.train-panel-hidden {
  display: none !important;
}

/* Terminal container */
.train-terminal-container {
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}
.train-terminal-container .xterm {
  width: 100% !important;
  height: 100% !important;
}
.train-terminal-container .xterm-viewport {
  overflow-y: auto !important;
}

/* Log viewer (HTML log display) */
.train-logs-viewer {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  padding: 0;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 11.5px;
  line-height: 1.55;
  background: #0d0d1a;
}
.train-logs-viewer .train-log-line {
  padding: 2px 10px;
  color: #888;
  border-bottom: 1px solid rgba(42,42,68,0.3);
  white-space: pre-wrap;
  word-break: break-all;
  animation: train-log-fadein 0.2s ease;
}
.train-logs-viewer .train-log-line:hover {
  background: rgba(255,255,255,0.03);
  color: #ccc;
}
.train-logs-viewer .train-log-error { color: #f44747; }
.train-logs-viewer .train-log-warn  { color: #dcdcaa; }
.train-logs-viewer .train-log-phase { color: #00d4ff; }
.train-logs-viewer::-webkit-scrollbar { width: 8px; }
.train-logs-viewer::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); }
.train-logs-viewer::-webkit-scrollbar-thumb { background: #333; border-radius: 4px; }
.train-logs-viewer::-webkit-scrollbar-thumb:hover { background: #444; }

/* Reports list */
.train-reports-list {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  padding: 0;
  background: #0d0d1a;
}
.train-report-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(42,42,68,0.4);
  color: #ccc;
  text-decoration: none;
  font-size: 12px;
  transition: background 0.15s;
}
.train-report-item:hover {
  background: rgba(0,212,255,0.06);
}
.train-report-item:last-child { border-bottom: none; }
.train-report-icon { color: #00d4ff; font-size: 14px; flex-shrink: 0; }
.train-report-name { color: #ccc; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.train-report-date { color: #666; font-size: 10px; white-space: nowrap; flex-shrink: 0; }

/* Early-stopped report styling */
.train-report-item--stopped .train-report-icon { color: #ff8800; }
.train-report-badge-stopped {
  display: inline-block;
  margin-left: 7px;
  padding: 1px 6px;
  background: #2a1500;
  border: 1px solid #ff8800;
  border-radius: 3px;
  color: #ff8800;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  vertical-align: middle;
  flex-shrink: 0;
}

.train-empty {
  color: #555;
  font-size: 12px;
  padding: 14px;
  display: block;
}
.train-reports-list::-webkit-scrollbar { width: 8px; }
.train-reports-list::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); }
.train-reports-list::-webkit-scrollbar-thumb { background: #333; border-radius: 4px; }
.train-reports-list::-webkit-scrollbar-thumb:hover { background: #444; }

/* Sort bar */
.train-reports-sort-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  background: rgba(0,0,0,0.15);
  flex-shrink: 0;
}
.train-sort-btn {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  color: #888;
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}
.train-sort-btn:hover { background: rgba(0,212,255,0.1); color: #aaa; }
.train-sort-btn.active { background: rgba(0,212,255,0.15); color: #00d4ff; border-color: rgba(0,212,255,0.3); }

/* Category breakdown button */
.train-cat-breakdown-btn {
  background: rgba(0,212,255,0.08);
  border: 1px solid rgba(0,212,255,0.2);
  color: #00d4ff;
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1;
}
.train-cat-breakdown-btn:hover { background: rgba(0,212,255,0.18); border-color: rgba(0,212,255,0.4); }

/* Category breakdown overlay */
.cat-breakdown-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 9999;
  align-items: center;
  justify-content: center;
}
.cat-breakdown-overlay.visible { display: flex; }
.cat-breakdown-dialog {
  background: #1a1d23;
  border: 1px solid rgba(0,212,255,0.15);
  border-radius: 10px;
  width: 640px;
  max-width: 95vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.cat-breakdown-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.cat-breakdown-header h3 { margin: 0; font-size: 14px; color: #eee; }
.cat-breakdown-close {
  background: none; border: none; color: #888; font-size: 20px; cursor: pointer; padding: 0 4px; line-height: 1;
}
.cat-breakdown-close:hover { color: #fff; }
.cat-breakdown-body {
  padding: 14px 18px;
  overflow-y: auto;
  flex: 1;
}
.cat-breakdown-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.cat-breakdown-body th {
  text-align: left;
  color: #888;
  font-weight: 600;
  padding: 6px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  white-space: nowrap;
}
.cat-breakdown-body th:nth-child(n+2) { text-align: right; }
.cat-breakdown-body td {
  padding: 5px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  color: #ccc;
}
.cat-breakdown-body td:nth-child(n+2) { text-align: right; font-variant-numeric: tabular-nums; }
.cat-breakdown-body tr.cat-row-zero td { color: #555; }
.cat-breakdown-body tr:hover td { background: rgba(0,212,255,0.04); }
.cat-breakdown-group-header td {
  color: #00d4ff;
  font-weight: 700;
  font-size: 11px;
  padding: 10px 8px 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid rgba(0,212,255,0.12);
}
.cat-breakdown-bar {
  display: inline-block;
  height: 6px;
  border-radius: 3px;
  vertical-align: middle;
  margin-right: 4px;
}
.cat-breakdown-summary {
  color: #888;
  font-size: 11px;
  padding: 10px 0 4px;
  border-top: 1px solid rgba(255,255,255,0.06);
  margin-top: 8px;
}

/* Confirmation overlay (unchanged) */
.train-confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 100000;
  background: rgba(0,0,0,0);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.3s ease;
}
.train-confirm-overlay.train-confirm-visible { background: rgba(0,0,0,0.75); }
.train-confirm-dialog {
  background: #141422;
  border: 1px solid #333;
  border-radius: 12px;
  padding: 32px;
  max-width: 460px;
  width: 90%;
  text-align: center;
  transform: scale(0.9);
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
}
.train-confirm-visible .train-confirm-dialog { transform: scale(1); opacity: 1; }
.train-confirm-icon { font-size: 48px; margin-bottom: 8px; line-height: 1; }
.train-confirm-title { color: #fff; font-size: 20px; font-weight: 600; margin: 0 0 12px 0; }
.train-confirm-text { color: #aaa; font-size: 14px; line-height: 1.5; margin: 0 0 16px 0; }
.train-confirm-text strong { color: #ff8844; }
.train-confirm-summary {
  background: rgba(255,255,255,0.05);
  border-radius: 8px;
  padding: 12px 16px;
  margin: 0 0 12px 0;
  display: flex;
  justify-content: space-around;
  gap: 12px;
  font-size: 13px;
  color: #ccc;
}
.train-confirm-summary strong { color: #00d4ff; }
.train-confirm-warn {
  background: rgba(255,136,0,0.1);
  border: 1px solid rgba(255,136,0,0.25);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 12px;
  color: #ff8844;
  margin: 0 0 20px 0;
}
.train-confirm-actions { display: flex; gap: 12px; justify-content: center; }
.train-confirm-actions .train-btn {
  min-width: 120px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: filter 0.15s;
}
.train-btn-cancel { background: #333; color: #ccc; }
.train-btn-cancel:hover { filter: brightness(1.3); }

/* ---- Responsive: 1200px → 2-col grid ---- */
@media (max-width: 1200px) {
  .train-dashboard {
    grid-template-columns: repeat(2, 1fr);
    max-height: 520px;
  }
  .train-control-bar {
    flex-wrap: wrap;
    height: auto;
    padding: 8px 16px;
  }
}

/* ---- Responsive: 768px → 1-col stacked (mobile) ---- */
@media (max-width: 768px) {
  .train-layout {
    height: auto;
    max-height: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 68px; /* space for mobile bottom nav */
  }

  /* Control bar: title + status on first line, buttons wrap below */
  .train-control-bar {
    flex-wrap: wrap;
    height: auto;
    gap: 8px;
    padding: 10px 12px;
  }
  .train-bar-title { font-size: 14px; flex: 0 0 auto; }
  .train-bar-spacer { flex: 1 1 0; min-width: 0; }
  .train-bar-select {
    min-height: 44px;
    font-size: 14px;
    flex: 1 1 100%;
    order: 10; /* push to new line */
  }
  .train-layout .train-btn {
    min-height: 44px;
    font-size: 14px;
    padding: 8px 18px;
    flex: 1 1 0;
  }
  .train-layout .train-btn-start,
  .train-layout .train-btn-stop,
  .train-layout .train-btn-force-stop {
    order: 11; /* after select */
  }
  .train-layout .train-btn-cleanup {
    order: 12;
    flex: 1 1 100%;
  }
  .train-status-badge {
    font-size: 10px;
    padding: 3px 8px;
  }

  /* Time strip: horizontal compact, hide separators */
  .train-time-strip {
    flex-wrap: wrap;
    gap: 4px 12px;
    padding: 8px 12px;
    justify-content: center;
  }
  .train-time-sep { display: none; }
  .train-time-item {
    padding: 2px 0;
    gap: 6px;
  }
  .train-time-label { font-size: 9px; }
  .train-time-value { font-size: 12px; }
  .train-elapsed { font-size: 12px; }

  /* Dashboard: 2-col grid on mobile (not 1-col — cards are small enough) */
  .train-dashboard {
    grid-template-columns: repeat(2, 1fr);
    max-height: none;
    overflow: visible;
    padding: 10px;
    gap: 10px;
  }
  .train-dash-card {
    min-height: 0;
  }
  .train-card-header {
    padding: 8px 10px;
  }
  .train-card-label { font-size: 10px; }
  .train-card-value { font-size: 12px; }

  /* Gauge cards: stack gauge above sparkline */
  .train-card-gauge-body {
    flex-direction: column;
    gap: 4px;
  }
  .train-gauge-wrap {
    flex: none;
    padding: 4px 0 0 0;
  }
  .train-gauge {
    max-width: 120px;
  }
  .train-gauge-label { font-size: 9px; }
  .train-spark-wrap {
    min-height: 50px;
    max-height: 60px;
  }

  /* Chart cards */
  .train-card-body {
    padding: 6px 8px;
    min-height: 70px;
  }

  /* Progress card: compact ring + bars */
  .train-card-progress-body {
    gap: 8px;
  }
  .train-ring-wrap {
    flex: 0 0 70px;
  }
  .train-ring {
    width: 70px;
    height: 70px;
  }
  .train-ring-text { font-size: 13px; }
  .train-minibar-label { font-size: 9px; }
  .train-minibar-track { height: 5px; }
  .train-bars-wrap { gap: 7px; }

  /* Hide resize handle on mobile (not useful with touch) */
  .train-resize-handle {
    display: none;
  }

  /* Bottom section: reasonable height on mobile */
  .train-bottom {
    min-height: 280px;
    flex: none;
    height: 320px;
  }

  /* Tab bar: taller touch targets */
  .train-output-tabs {
    height: 40px;
  }
  .train-otab {
    padding: 0 12px;
    font-size: 13px;
    min-height: 40px;
  }

  /* Terminal: limit height, improve scroll */
  .train-terminal-container {
    -webkit-overflow-scrolling: touch;
  }
  .train-logs-viewer {
    font-size: 10.5px;
    -webkit-overflow-scrolling: touch;
  }
  .train-logs-viewer .train-log-line {
    padding: 4px 8px;
    min-height: 32px;
    display: flex;
    align-items: center;
  }

  /* Reports: touch-friendly */
  .train-report-item {
    padding: 10px 12px;
    min-height: 44px;
  }
  .train-report-name { font-size: 12px; }
  .train-report-date { font-size: 9px; }

  /* Confirm dialog: full-width on mobile */
  .train-confirm-dialog {
    padding: 24px 16px;
    max-width: 95%;
    border-radius: 10px;
  }
  .train-confirm-title { font-size: 18px; }
  .train-confirm-text { font-size: 13px; }
  .train-confirm-actions {
    flex-direction: column;
    gap: 8px;
  }
  .train-confirm-actions .train-btn {
    min-width: 100%;
    min-height: 48px;
    font-size: 15px;
  }
}

/* ---- Responsive: 480px → very small phones ---- */
@media (max-width: 480px) {
  .train-dashboard {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 8px;
  }
  .train-card-gauge-body {
    flex-direction: row;
    gap: 6px;
  }
  .train-gauge-wrap {
    flex: 0 0 45%;
  }
  .train-gauge { max-width: 100px; }
  .train-spark-wrap {
    min-height: 60px;
    max-height: 70px;
  }
  .train-card-progress-body {
    gap: 6px;
  }
  .train-ring-wrap { flex: 0 0 60px; }
  .train-ring { width: 60px; height: 60px; }
  .train-ring-text { font-size: 11px; }
  .train-bottom {
    height: 260px;
    min-height: 240px;
  }
}

/* ==============================
   All Users Media Tree (Admin)
   ============================== */
.user-tree-node {
  border: 1px solid var(--border-color, rgba(255,255,255,0.08));
  border-radius: 10px;
  margin-bottom: 10px;
  overflow: hidden;
  background: var(--card-bg, rgba(15,20,35,0.5));
}
.user-tree-header {
  display: flex;
  align-items: center;
  padding: 14px 18px;
  cursor: pointer;
  transition: background 0.15s;
  gap: 12px;
}
.user-tree-header:hover {
  background: rgba(255,255,255,0.04);
}
.user-tree-arrow {
  font-size: 12px;
  color: rgba(255,255,255,0.5);
  transition: transform 0.2s ease;
  flex-shrink: 0;
  width: 16px;
  text-align: center;
}
.user-tree-arrow.expanded {
  transform: rotate(90deg);
}
.user-tree-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary, #e2e8f0);
}
.user-tree-email {
  font-size: 12px;
  color: var(--text-muted, rgba(255,255,255,0.4));
  margin-left: 8px;
}
.user-tree-counts {
  margin-left: auto;
  display: flex;
  gap: 10px;
  font-size: 11px;
  color: var(--text-muted, rgba(255,255,255,0.4));
}
.user-tree-counts .count-badge {
  background: rgba(255,255,255,0.06);
  padding: 2px 8px;
  border-radius: 10px;
}
.user-tree-body {
  display: none;
  padding: 0 18px 18px;
}
.user-tree-body.open {
  display: block;
}
.user-media-section {
  margin-top: 16px;
}
.user-media-section h4 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted, rgba(255,255,255,0.45));
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.user-media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
}
.user-media-thumb {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 16/9;
  cursor: pointer;
  background: rgba(0,0,0,0.3);
}
.user-media-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.user-media-thumb .thumb-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 4px 8px;
  background: linear-gradient(transparent, rgba(0,0,0,0.75));
  font-size: 10px;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-audio-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: rgba(255,255,255,0.03);
  border-radius: 8px;
  margin-bottom: 6px;
}
.user-audio-item .audio-icon {
  font-size: 18px;
  flex-shrink: 0;
}
.user-audio-item .audio-name {
  font-size: 12px;
  color: var(--text-primary, #e2e8f0);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-audio-item audio {
  height: 28px;
  flex-shrink: 0;
}
.prompt-card {
  background: rgba(255,255,255,0.03);
  padding: 14px 16px;
  border-radius: 8px;
  margin-bottom: 8px;
  border-left: 3px solid rgba(108,92,231,0.5);
}
.prompt-card .narrative {
  font-style: italic;
  font-size: 13px;
  color: var(--text-primary, #e2e8f0);
  max-height: 80px;
  overflow: hidden;
  line-height: 1.5;
}
.prompt-card .prompt-meta {
  font-size: 11px;
  color: var(--text-muted, rgba(255,255,255,0.4));
  margin-top: 8px;
  display: flex;
  gap: 12px;
}
.user-media-empty {
  font-size: 12px;
  color: var(--text-muted, rgba(255,255,255,0.3));
  padding: 8px 0;
}
