/* === NAI Relay - Ultra Premium V3 Theme === */

:root {
    /* --- Core Palette (Deep Space / Dark Mode) --- */
    --bg-base: #0B0C10; /* Deepest black/blue */
    --bg-surface: rgba(22, 24, 32, 0.65); /* Glassmorphic dark */
    --bg-elevated: rgba(30, 33, 45, 0.85);
    --bg-input: rgba(14, 15, 20, 0.9);
    --bg-hover: rgba(43, 47, 65, 0.7);

    /* --- Text & Accents --- */
    --text-primary: #f0f0f5;
    --text-secondary: #9aa0a6;
    --text-muted: #626770;
    
    /* Vibrant Cyber Accents */
    --accent-glow: #6B21A8; /* Deep Purple */
    --accent-primary: #8B5CF6; /* Bright Purple */
    --accent-primary-hover: #A78BFA;
    --accent-gold: #F59E0B; /* Warm gold for Anlas */
    --accent-green: #10B981;
    --accent-red: #EF4444;

    /* --- Geometry & Effects --- */
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.15);
    --border-focus: rgba(139, 92, 246, 0.6);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --blur-strength: blur(20px);
    
    /* --- Layout Metrics --- */
    --topbar-height: 64px;
    --sidebar-width: 320px;
    --right-sidebar-width: 320px;
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* =========================================================
   RESET & FOUNDATION
   ========================================================= */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    background-color: var(--bg-base);
    background-image: 
        radial-gradient(circle at 15% 50%, rgba(107, 33, 168, 0.05), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(56, 189, 248, 0.03), transparent 25%);
    background-attachment: fixed;
    color: var(--text-primary);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-size: 14px;
    line-height: 1.5;
}

/* Scrollbars - Minimalist & Dark */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { 
    background: rgba(255, 255, 255, 0.1); 
    border-radius: 4px; 
}
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.2); }

/* Utility Classes */
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); font-size: 12px; }

/* =========================================================
   TOP NAVIGATION (GLASSMORPHIC)
   ========================================================= */
.top-bar {
    height: var(--topbar-height);
    background: var(--bg-surface);
    backdrop-filter: var(--blur-strength);
    -webkit-backdrop-filter: var(--blur-strength);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 100;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-glow));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: 0 4px 12px rgba(107, 33, 168, 0.3);
}

.logo-text {
    font-weight: 700;
    font-size: 18px;
    letter-spacing: -0.02em;
    background: linear-gradient(to right, #fff, #a1a1aa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.top-controls {
    display: flex;
    gap: 16px;
    align-items: center;
    flex: 1;
    justify-content: center;
}

.model-badge {
    background: var(--bg-input);
    border: 1px solid var(--border);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}
.model-badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-green);
    box-shadow: 0 0 8px var(--accent-green);
}

.top-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.anlas-display {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.2);
    color: var(--accent-gold);
    padding: 6px 16px;
    border-radius: 20px;
    font-weight: 700;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 2px 10px rgba(245, 158, 11, 0.05);
}

.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: color var(--transition-fast);
}
.nav-link:hover {
    color: var(--text-primary);
}

/* =========================================================
   MAIN LAYOUT (3 COLLUMNS)
   ========================================================= */
.main-container {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* =========================================================
   SIDEBARS (LEFT & RIGHT)
   ========================================================= */
.sidebar {
    background: var(--bg-surface);
    backdrop-filter: var(--blur-strength);
    -webkit-backdrop-filter: var(--blur-strength);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 50;
    position: relative;
    transition: transform var(--transition-smooth);
}

.left-sidebar { width: var(--sidebar-width); }
.right-sidebar { 
    width: var(--right-sidebar-width); 
    border-right: none;
    border-left: 1px solid var(--border);
    transform: translateX(0); /* For toggling */
}
.right-sidebar.collapsed { display: none; }

.scroll-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* --- Parameter / Tool Groups --- */
.param-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.group-header {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

.control-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    color: var(--text-secondary);
}

.control-row label { font-weight: 500; }
.control-row span {
    color: var(--text-primary);
    font-weight: 600;
    font-feature-settings: "tnum";
}

/* =========================================================
   FORM CONTROLS & INPUTS
   ========================================================= */
select, .dark-input, input[type="text"], input[type="number"], input[type="password"] {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 10px 14px;
    border-radius: var(--radius-md);
    outline: none;
    font-family: inherit;
    font-size: 13px;
    transition: all var(--transition-fast);
    width: 100%;
}

select:hover, .dark-input:hover, input[type="text"]:hover, input[type="number"]:hover {
    border-color: var(--border-strong);
}

select:focus, .dark-input:focus, input[type="text"]:focus, input[type="number"]:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.15);
}

select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%239aa0a6' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 32px;
    cursor: pointer;
}

/* Buttons */
.btn-glass {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.btn-glass:hover {
    background: var(--bg-hover);
    border-color: var(--border-strong);
}

/* Custom Sliders */
input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    outline: none;
    position: relative;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
    height: 4px;
    background: linear-gradient(to right, var(--accent-primary) 0%, var(--accent-primary) var(--progress, 50%), transparent var(--progress, 50%));
    border-radius: 2px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    margin-top: -6px;
    background: var(--text-primary);
    border-radius: 50%;
    border: 2px solid var(--bg-base);
    box-shadow: 0 2px 6px rgba(0,0,0,0.4);
    transition: transform var(--transition-fast);
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); }

/* Seed Box */
.seed-row { display: flex; gap: 8px; }
.seed-row input { flex: 1; font-family: 'SF Mono', Consolas, monospace; }
.seed-row button { width: 40px; padding: 0; font-size: 16px; }

/* Size Presets Grid */
.size-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}
.size-grid button {
    padding: 6px;
    font-size: 11px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
}
.size-grid button:hover {
    color: white;
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

/* Details/Summary */
details summary {
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-top: 1px solid var(--border);
}
details summary::-webkit-details-marker { display: none; }
details summary::after {
    content: '';
    width: 16px; height: 16px;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%23f0f0f5' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    transition: transform var(--transition-fast);
}
details[open] summary::after { transform: rotate(180deg); }
.details-content { display: flex; flex-direction: column; gap: 12px; padding-bottom: 16px; }

/* Checkboxes */
.checkbox-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.checkbox-label {
    display: flex; align-items: center; gap: 8px; cursor: pointer;
    font-size: 13px; color: var(--text-secondary);
}
.checkbox-label input {
    appearance: none; width: 16px; height: 16px;
    border: 1.5px solid var(--border-strong);
    border-radius: 4px; background: rgba(0,0,0,0.2);
    position: relative; transition: all 0.2s;
}
.checkbox-label input:checked {
    background: var(--accent-primary); border-color: var(--accent-primary);
}
.checkbox-label input:checked::after {
    content: ''; position: absolute; left: 4px; top: 1px;
    width: 4px; height: 8px; border: solid white;
    border-width: 0 2px 2px 0; transform: rotate(45deg);
}

/* =========================================================
   GENERATE BUTTON (ULTRA PREMIUM)
   ========================================================= */
.generate-wrapper {
    padding: 20px 24px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    backdrop-filter: var(--blur-strength);
    -webkit-backdrop-filter: var(--blur-strength);
}

.gen-btn {
    width: 100%;
    height: 56px;
    border-radius: var(--radius-lg);
    border: none;
    background: linear-gradient(135deg, #6366f1, #a855f7);
    color: white;
    font-weight: 700;
    font-size: 16px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    box-shadow: 0 4px 20px rgba(168, 85, 247, 0.4);
    transition: transform 0.1s, box-shadow 0.2s;
}
.gen-btn::before {
    content: '';
    position: absolute; top: 0; left: -100%; width: 50%; height: 100%;
    background: linear-gradient(to right, transparent, rgba(255,255,255,0.2), transparent);
    transform: skewX(-20deg);
}
.gen-btn:hover:not(:disabled) {
    box-shadow: 0 6px 24px rgba(168, 85, 247, 0.6);
    transform: translateY(-1px);
}
.gen-btn:hover:not(:disabled)::before {
    left: 150%; transition: left 0.7s ease;
}
.gen-btn:active:not(:disabled) { transform: translateY(1px); }
.gen-btn:disabled {
    background: var(--bg-elevated);
    color: var(--text-muted);
    box-shadow: none;
    cursor: not-allowed;
    border: 1px solid var(--border);
}
.gen-cost-pill {
    background: rgba(0,0,0,0.2);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 600;
}

/* =========================================================
   CENTER AREA: Cinematic Display
   ========================================================= */
.center-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 24px;
    gap: 20px;
    position: relative;
    min-width: 0;
}

/* Prompts */
.prompt-zone {
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex-shrink: 0;
    z-index: 10;
}
.prompt-box {
    position: relative;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    backdrop-filter: var(--blur-strength);
}
.prompt-box:focus-within {
    border-color: var(--border-focus);
    box-shadow: 0 4px 24px rgba(0,0,0,0.2);
}
.prompt-box.negative:focus-within { border-color: rgba(239, 68, 68, 0.5); }

.prompt-box textarea {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-primary);
    padding: 16px 20px 16px 20px;
    font-family: inherit;
    font-size: 15px;
    line-height: 1.5;
    resize: vertical;
    outline: none;
    min-height: 90px;
}
.prompt-box.negative textarea { 
    min-height: 60px; 
    color: #fca5a5;
}

.prompt-badge {
    position: absolute;
    top: -10px; left: 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.prompt-box.negative .prompt-badge { color: var(--accent-red); }

/* Canvas Display */
.stage {
    flex: 1;
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 0 40px rgba(0,0,0,0.5);
}

.stage-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    z-index: 2;
    transition: opacity 0.3s;
}

.stage-empty {
    text-align: center;
    color: var(--text-muted);
}
.stage-empty svg { width: 48px; height: 48px; opacity: 0.3; margin-bottom: 12px; }

/* Loading State Overlay */
.loading-curtain {
    position: absolute; inset: 0;
    background: rgba(11, 12, 16, 0.8);
    backdrop-filter: blur(8px);
    z-index: 20;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}
.loading-curtain.active { opacity: 1; pointer-events: all; }

.spinner {
    width: 40px; height: 40px;
    border: 3px solid rgba(139, 92, 246, 0.2);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Stage Actions (Bottom right floating) */
.stage-actions {
    position: absolute;
    bottom: 20px; right: 20px;
    display: flex; gap: 10px;
    z-index: 10;
}
.stage-actions button {
    background: rgba(30, 33, 45, 0.9);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: var(--radius-lg);
    padding: 10px 20px;
    color: white;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    transition: all var(--transition-fast);
}
.stage-actions button:not(:disabled):hover {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    transform: translateY(-2px);
}
.stage-actions button:disabled { opacity: 0; pointer-events: none; }

/* =========================================================
   RIGHT SIDEBAR: Tools (Img2Img, Inpaint, Director)
   ========================================================= */
.upload-zone {
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius-lg);
    background: rgba(0,0,0,0.2);
    height: 160px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
    color: var(--text-muted);
}
.upload-zone:hover {
    border-color: var(--accent-primary);
    background: rgba(139, 92, 246, 0.05);
    color: var(--accent-primary);
}
.upload-zone img {
    position: absolute; inset: 0;
    width: 100%; height: 100%; object-fit: contain;
    background: #000; z-index: 5;
}

/* Inpaint specific */
.inpaint-stage {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    background: #000;
    border-radius: var(--radius-md);
    overflow: hidden;
    margin-top: 10px;
}
.inpaint-stage canvas {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    cursor: crosshair;
}
.toolbar {
    display: flex; gap: 8px; margin-top: 8px;
}
.toolbar button {
    flex: 1; padding: 6px;
}

/* Initial Full Screen Gate (If needed, managed by JS totally) */
#splash-auth {
    position: fixed; inset: 0; z-index: 9999;
    background: var(--bg-base);
    display: flex; align-items: center; justify-content: center;
}

/* =========================================================
   MOBILE RESPONSIVENESS (Ultra-Important)
   ========================================================= */
.mobile-nav-toggle { display: none; }

@media (max-width: 1024px) {
    /* Switch to 1-column layout with bottom sheets for settings */
    body { font-size: 16px; overflow: auto; }
    
    .top-bar { padding: 0 16px; }
    .model-badge { display: none; } /* Hide on mobile to save space */
    
    .main-container {
        flex-direction: column;
        overflow: visible;
    }
    
    .center-area {
        order: 1;
        min-height: 80vh;
        padding: 16px;
    }
    
    .left-sidebar {
        order: 2;
        width: 100%;
        border-right: none;
        border-top: 1px solid var(--border);
    }
    
    .right-sidebar {
        order: 3;
        width: 100%;
        border-right: none;
        border-left: none;
        border-top: 1px solid var(--border);
        transform: none;
    }
    
    .scroll-content { padding: 16px; overflow: visible; }
    
    /* Make stage scale better */
    .stage { border-radius: var(--radius-md); }
    .stage-actions { bottom: 12px; right: 12px; }
    
    /* Bigger tap targets */
    select, .dark-input, input[type="text"], input[type="number"], .btn-glass {
        padding: 12px 16px;
        font-size: 16px;
    }
    
    input[type="range"]::-webkit-slider-thumb {
        width: 24px; height: 24px; margin-top: -10px;
    }
}