/* === NAI Relay - Official NovelAI-Style Theme === */

:root {
    /* Background Palette - Official NAI Navy/Dark */
    --bg-base: #131420;
    --bg-surface: #1b1d2e;
    --bg-elevated: #232538;
    --bg-input: #181a2a;
    --bg-hover: #2a2d44;

    /* Text */
    --text-primary: #e8e6e0;
    --text-secondary: #9b99a5;
    --text-tertiary: #6c6a78;

    /* Accent Colors - NAI Gold/Tan */
    --accent-gold: #d4cfbf;
    --accent-gold-dim: #a09b8d;
    --accent-purple: #8b5cf6;
    --accent-purple-hover: #a17dfc;

    /* Functional */
    --accent-green: #4caf50;
    --accent-orange: #ff9800;
    --accent-red: #ef4444;

    /* Border */
    --border: #2a2c3e;
    --border-focus: #4a4c6e;

    /* Sizing */
    --radius: 8px;
    --radius-lg: 12px;
    --sidebar-width: 420px;

    /* Transition */
    --transition: 0.2s ease;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

body {
    background-color: var(--bg-base);
    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;
}

/* ============================================
   TOP BAR - Matches Official NAI Header
   ============================================ */
.top-bar {
    height: 52px;
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 16px;
    justify-content: space-between;
    flex-shrink: 0;
    z-index: 100;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.logo-icon svg,
.logo-icon img {
    width: 28px;
    height: 28px;
}

.logo-text {
    font-weight: 600;
    font-size: 16px;
    color: var(--text-primary);
    letter-spacing: 0.5px;
}

.top-controls {
    display: flex;
    gap: 12px;
    align-items: center;
}

/* Anlas Display - Official Gold Pill */
.anlas-display {
    background: var(--bg-elevated);
    color: var(--accent-gold);
    padding: 6px 14px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--border);
}

.anlas-display small {
    font-size: 11px;
    opacity: 0.7;
}

.top-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.settings-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 20px;
    padding: 4px;
    transition: color var(--transition);
}

.settings-btn:hover {
    color: var(--text-primary);
}

/* ============================================
   MAIN LAYOUT - 3-Column
   ============================================ */
.main-container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ============================================
   LEFT SIDEBAR - Settings Panel
   ============================================ */
.left-sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
}

.scroll-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0;
    overflow-y: auto;
    padding: 16px;
    padding-bottom: 0;
}

/* --- Parameter Groups --- */
.param-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}

.param-group:first-child {
    padding-top: 0;
}

.param-group:last-child {
    border-bottom: none;
}

.group-header {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-tertiary);
    font-weight: 700;
    margin-bottom: 2px;
}

.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-size: 14px;
}

/* --- Form Inputs --- */
select {
    background-color: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 8px 12px;
    border-radius: var(--radius);
    outline: none;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: border-color var(--transition);
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239b99a5' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 30px;
}

select:hover {
    border-color: var(--border-focus);
}

select:focus {
    border-color: var(--accent-purple);
}

.dark-input,
input[type="text"],
input[type="number"],
input[type="password"] {
    background-color: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: var(--radius);
    outline: none;
    font-family: inherit;
    font-size: 13px;
    transition: border-color var(--transition);
    width: 100%;
}

.dark-input:focus,
input[type="text"]:focus,
input[type="number"]:focus,
input[type="password"]:focus {
    border-color: var(--accent-purple);
}

/* --- Sliders - NAI Style Purple --- */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: linear-gradient(to right, var(--accent-purple) 0%, var(--accent-purple) var(--progress, 50%), var(--border) var(--progress, 50%), var(--border) 100%);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
    border: none;
}

input[type="range"]::-webkit-slider-runnable-track {
    height: 6px;
    background: transparent;
    border-radius: 3px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent-purple);
    cursor: grab;
    border: 2px solid var(--bg-surface);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
    transition: transform var(--transition);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

input[type="range"]:active::-webkit-slider-thumb {
    cursor: grabbing;
    transform: scale(1.1);
}

/* Seed Input */
.seed-input-row {
    display: flex;
    gap: 6px;
}

.seed-input-row input {
    flex: 1;
}

.seed-input-row button {
    min-width: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    padding: 0;
}

.seed-info {
    font-size: 11px;
    color: var(--text-tertiary);
    text-align: right;
}

/* --- Buttons --- */
button {
    background-color: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 8px 14px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    transition: all var(--transition);
}

button:hover {
    background-color: var(--bg-hover);
    border-color: var(--border-focus);
}

/* Size Presets */
.size-presets {
    display: flex;
    gap: 6px;
}

.size-presets button {
    flex: 1;
    font-size: 12px;
    padding: 6px 10px;
    text-align: center;
}

.size-presets button:hover {
    background-color: var(--accent-purple);
    border-color: var(--accent-purple);
    color: #fff;
}

/* ============================================
   GENERATE BUTTON - Official NAI Gold/Tan
   ============================================ */
.main-gen-btn {
    background: var(--accent-gold);
    color: #1a1a2e;
    border: none;
    height: 50px;
    font-weight: 700;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    font-size: 15px;
    transition: all var(--transition);
    border-radius: 0;
    margin: 0;
    flex-shrink: 0;
    letter-spacing: 0.3px;
}

.main-gen-btn:hover:not(:disabled) {
    background: #e0dbd0;
    color: #1a1a2e;
    border-color: transparent;
}

.main-gen-btn:active:not(:disabled) {
    background: #c8c3b5;
}

.main-gen-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: var(--accent-gold-dim);
}

.btn-text {
    font-size: 14px;
}

.btn-cost {
    background: rgba(0, 0, 0, 0.15);
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Seed Input */
.seed-input-row {
    display: flex;
    gap: 6px;
    align-items: center;
}

.seed-input-row input {
    flex: 1;
}

.seed-input-row button {
    min-width: 32px;
    padding: 6px 8px;
    font-size: 16px;
    line-height: 1;
}

.seed-info {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 2px;
}

/* ============================================
   ADVANCED SETTINGS - Collapsible
   ============================================ */
details {
    border-bottom: 1px solid var(--border);
}

details summary {
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 600;
    list-style: none;
    user-select: none;
    padding: 12px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: color var(--transition);
}

details summary:hover {
    color: var(--text-primary);
}

details summary::-webkit-details-marker {
    display: none;
}

details summary::after {
    content: "▼";
    font-size: 9px;
    color: var(--text-tertiary);
    transition: transform var(--transition);
}

details[open] summary::after {
    transform: rotate(180deg);
}

.advanced-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 4px 0 16px;
}

.advanced-content label {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.advanced-content select {
    width: 100%;
}

.checkbox-row {
    display: flex;
    gap: 16px;
    font-size: 13px;
    flex-wrap: wrap;
}

.checkbox-row label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 13px;
    text-transform: none;
    letter-spacing: 0;
    font-weight: 400;
    color: var(--text-secondary);
    transition: color var(--transition);
}

.checkbox-row label:hover {
    color: var(--text-primary);
}

/* Custom Checkbox */
.checkbox-row input[type="checkbox"] {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border: 1.5px solid var(--border);
    border-radius: 3px;
    background: var(--bg-input);
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    transition: all var(--transition);
}

.checkbox-row input[type="checkbox"]:checked {
    background: var(--accent-purple);
    border-color: var(--accent-purple);
}

.checkbox-row input[type="checkbox"]:checked::after {
    content: "✓";
    position: absolute;
    top: -1px;
    left: 2px;
    color: #fff;
    font-size: 11px;
    font-weight: bold;
}

/* ============================================
   CENTER AREA - Canvas & Prompts
   ============================================ */
.center-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-base);
    position: relative;
    padding: 20px;
    gap: 16px;
    min-width: 0;
}

/* --- Prompt Section --- */
.prompt-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.prompt-box {
    background-color: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    min-height: 80px;
    position: relative;
    transition: border-color var(--transition);
}

.prompt-box:focus-within {
    border-color: var(--accent-purple);
}

.prompt-box.negative {
    min-height: 60px;
    border-color: #3a2a2e;
    background-color: #1f1820;
}

.prompt-box.negative:focus-within {
    border-color: var(--accent-red);
}

.prompt-box textarea {
    width: 100%;
    height: 100%;
    min-height: inherit;
    background: none;
    border: none;
    color: var(--text-primary);
    padding: 14px 16px;
    resize: vertical;
    outline: none;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.6;
}

.prompt-label {
    position: absolute;
    top: -8px;
    left: 14px;
    background: var(--bg-surface);
    padding: 0 6px;
    font-size: 11px;
    color: var(--text-tertiary);
    font-weight: 600;
    letter-spacing: 0.5px;
}

.prompt-box.negative .prompt-label {
    background: #1f1820;
    color: var(--accent-red);
}

/* --- Canvas Area --- */
.canvas-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    position: relative;
    overflow: hidden;
    min-height: 200px;
}

.image-viewer {
    max-width: 100%;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.image-viewer img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

.placeholder-text {
    text-align: center;
    color: var(--text-tertiary);
    user-select: none;
}

.placeholder-text .icon {
    font-size: 56px;
    margin-bottom: 12px;
    opacity: 0.2;
}

.placeholder-text div:last-child {
    font-size: 14px;
    letter-spacing: 0.5px;
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(19, 20, 32, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
    border-radius: var(--radius-lg);
    backdrop-filter: blur(4px);
}

#loading-text {
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: 4px;
}

.hidden {
    display: none !important;
}

/* Bottom Actions */
.bottom-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    flex-shrink: 0;
}

.bottom-actions button {
    padding: 8px 16px;
}

.bottom-actions button:not(:disabled):hover {
    background: var(--accent-purple);
    border-color: var(--accent-purple);
    color: white;
}

/* ============================================
   RIGHT SIDEBAR - Tool Panels
   ============================================ */
.right-sidebar {
    width: 300px;
    background-color: var(--bg-surface);
    border-left: 1px solid var(--border);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    flex-shrink: 0;
}

.right-sidebar:empty {
    display: none;
}

.tool-panel {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.panel-header {
    font-weight: 600;
    font-size: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}

/* Upload Zones */
.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    height: 140px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    overflow: hidden;
    position: relative;
    transition: all var(--transition);
    background: var(--bg-input);
}

.upload-zone:hover {
    border-color: var(--accent-purple);
    background: rgba(139, 92, 246, 0.05);
}

.upload-zone.small {
    height: 80px;
}

.upload-placeholder {
    color: var(--text-tertiary);
    font-size: 13px;
    pointer-events: none;
}

.upload-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
    margin-bottom: 4px;
}

.preview-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: var(--bg-base);
}

.info-text {
    font-size: 12px;
    color: var(--text-tertiary);
    line-height: 1.5;
}

/* ============================================
   SPINNER - NAI Style
   ============================================ */
.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(139, 92, 246, 0.15);
    border-radius: 50%;
    border-top-color: var(--accent-purple);
    animation: spin 0.8s linear infinite;
    margin-bottom: 12px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* ============================================
   MODEL / ACTION SELECTORS in Top Bar
   ============================================ */
.model-selector select,
.action-selector select {
    background-color: var(--bg-elevated);
    border: 1px solid var(--border);
    font-weight: 500;
}

/* ============================================
   VIBE TRANSFER - Multi-Vibe Cards
   ============================================ */
.vibe-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 8px;
}

.vibe-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
}

.vibe-remove-btn {
    background: none;
    border: none;
    color: var(--accent-red);
    cursor: pointer;
    font-size: 14px;
    padding: 2px 6px;
    min-width: unset;
    line-height: 1;
    border-radius: 4px;
}

.vibe-remove-btn:hover {
    background: rgba(239, 68, 68, 0.15);
}

.add-vibe-btn {
    width: 100%;
    padding: 8px;
    font-size: 13px;
    text-align: center;
    color: var(--accent-purple);
    border: 1px dashed var(--border);
    background: var(--bg-input);
    transition: all var(--transition);
}

.add-vibe-btn:hover {
    border-color: var(--accent-purple);
    background: rgba(139, 92, 246, 0.08);
}

.vibe-upload {
    height: 70px !important;
}

/* ============================================
   INPAINT MASK CANVAS
   ============================================ */
.mask-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 0;
    flex-wrap: wrap;
}

.mask-tool-btn {
    padding: 4px 8px;
    font-size: 14px;
    min-width: 32px;
    text-align: center;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-input);
}

.mask-tool-btn.active {
    background: var(--accent-purple);
    border-color: var(--accent-purple);
    color: white;
}

.brush-size-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    margin-left: auto;
}

.inpaint-canvas-container {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg-base);
    display: flex;
    align-items: center;
    justify-content: center;
}

#inpaint-canvas {
    cursor: crosshair;
    display: block;
}

.mask-upload-fallback {
    border: none;
    margin-top: 4px;
}

.mask-upload-fallback summary {
    font-size: 12px;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 4px 0;
}

/* ============================================
   DIRECTOR TOOL SUB-PANELS
   ============================================ */
#director-emotion-controls,
#director-colorize-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-top: 4px;
}

/* ============================================
   RESOLUTION PRESETS - Expanded Grid
   ============================================ */
.preset-details {
    border: none;
    margin-top: -4px;
}

.preset-details summary {
    font-size: 11px;
    color: var(--text-tertiary);
    padding: 4px 0;
}

.preset-details summary::after {
    font-size: 8px;
}

.size-presets-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    padding: 4px 0;
}

.size-presets-grid button {
    font-size: 11px;
    padding: 5px 8px;
    text-align: center;
    white-space: nowrap;
}

.size-presets-grid button:hover {
    background-color: var(--accent-purple);
    border-color: var(--accent-purple);
    color: #fff;
}

/* ============================================
   USE LAST IMAGE BUTTON
   ============================================ */
#use-last-btn {
    padding: 8px 14px;
    font-size: 13px;
}

#use-last-btn:not(:disabled):hover {
    background: var(--accent-purple);
    border-color: var(--accent-purple);
    color: white;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 1200px) {
    .right-sidebar {
        width: 260px;
    }

    .left-sidebar {
        width: 360px;
    }
}

@media (max-width: 900px) {
    .main-container {
        flex-direction: column;
    }

    .left-sidebar,
    .right-sidebar {
        width: 100%;
        border: none;
        border-bottom: 1px solid var(--border);
        max-height: 40vh;
    }

    .right-sidebar {
        border-top: 1px solid var(--border);
    }
}