/* =============================================================================
   AI Image Server - Design System
   Apple-inspired minimal design
   ============================================================================= */

/* -----------------------------------------------------------------------------
   Design Tokens
   ----------------------------------------------------------------------------- */
:root {
    /* Colors — admin-panel system (per Daniel's standing OpenVAS-style spec):
       near-white page, white surfaces, near-black text, dark constant header */
    --color-bg: #ffffff;
    --color-bg-secondary: #f6f7f8;
    --color-bg-tertiary: #eef0f2;
    --color-text: #1c1e21;
    --color-text-secondary: #6b7280;
    --color-text-tertiary: #9096a0;
    --color-primary: #6366f1;
    --color-primary-hover: #575af5;
    --color-primary-active: #4f52e8;
    --color-border: #e2e5e9;
    --color-border-light: #edeef1;
    --color-success: #2e9e5b;
    --color-error: #d64545;
    --color-warning: #d98a16;
    --header-bg: #14161f;
    --header-text: #e8e9ee;

    /* Typography */
    --font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", sans-serif;
    --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    --font-size-xs: 11px;
    --font-size-sm: 13px;
    --font-size-base: 15px;
    --font-size-lg: 17px;
    --font-size-xl: 21px;
    --font-size-2xl: 28px;
    --font-size-3xl: 40px;
    --font-weight-regular: 400;
    --font-weight-medium: 500;
    --font-weight-semibold: 600;
    --font-weight-bold: 700;
    --line-height-tight: 1.2;
    --line-height-normal: 1.5;
    --line-height-relaxed: 1.7;

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

    /* Shadows — flat and quiet; depth comes from borders, not glow */
    --shadow-sm: 0 1px 2px rgba(20, 20, 24, 0.05);
    --shadow-md: 0 2px 8px rgba(20, 20, 24, 0.07);
    --shadow-lg: 0 8px 24px rgba(20, 20, 24, 0.10);
    --shadow-xl: 0 16px 40px rgba(20, 20, 24, 0.14);

    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --radius-full: 9999px;

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

    /* Layout */
    --container-max: 1440px;
    --sidebar-width: 340px;
    --nav-h: 56px;
    --tabbar-h: 60px;
}

/* -----------------------------------------------------------------------------
   Reset & Base
   ----------------------------------------------------------------------------- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-regular);
    line-height: var(--line-height-normal);
    color: var(--color-text);
    background: var(--color-bg-secondary);
    min-height: 100vh;
}

a {
    color: var(--color-primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

img {
    max-width: 100%;
    height: auto;
}

/* -----------------------------------------------------------------------------
   App shell — dark full-width topbar + light icon sidebar (admin-panel spec)
   ----------------------------------------------------------------------------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    gap: var(--space-4);
    height: 48px;
    padding: 0 var(--space-4);
    background: var(--header-bg);
    color: var(--header-text);
}

.topbar-brand {
    display: flex;
    align-items: baseline;
    gap: 8px;
    color: var(--header-text);
    text-decoration: none;
    font-size: 15px;
    font-weight: var(--font-weight-semibold);
    letter-spacing: 0.14em;
}

.topbar-brand:hover { text-decoration: none; color: #fff; }

.topbar-brand .brand-sub {
    font-size: 11px;
    font-weight: var(--font-weight-regular);
    letter-spacing: 0.02em;
    color: #8a8f9f;
}

.topbar-spacer { flex: 1; }

.topbar-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: none;
    color: #aeb2c0;
    font-family: inherit;
    font-size: var(--font-size-sm);
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-decoration: none;
    transition: color var(--transition-fast), background var(--transition-fast);
}

.topbar-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
    text-decoration: none;
}

.topbar-btn svg { width: 16px; height: 16px; }

/* App body: sidebar + content */
.app {
    display: flex;
    min-height: calc(100vh - 48px);
}

.side-nav {
    width: 200px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--color-bg);
    border-right: 1px solid var(--color-border);
    padding: var(--space-3) 0;
    position: sticky;
    top: 48px;
    height: calc(100vh - 48px);
    overflow-y: auto;
}

.side-group {
    padding: 0 var(--space-2);
    margin-bottom: var(--space-3);
}

.side-group-label {
    font-size: 11px;
    font-weight: var(--font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-tertiary);
    padding: var(--space-2) var(--space-2) 4px;
}

.side-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px var(--space-2);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    text-decoration: none;
    font-size: var(--font-size-sm);
    line-height: 1.2;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.side-item svg {
    width: 16px;
    height: 16px;
    color: var(--color-text-secondary);
    flex-shrink: 0;
}

.side-item:hover {
    background: var(--color-bg-secondary);
    text-decoration: none;
}

.side-item.active {
    background: color-mix(in srgb, var(--color-primary) 10%, transparent);
    color: var(--color-primary);
    font-weight: var(--font-weight-medium);
}

.side-item.active svg { color: var(--color-primary); }

.side-version {
    margin-top: auto;
    padding: var(--space-3) var(--space-4) var(--space-2);
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--color-text-tertiary);
}

/* Bottom tab bar — phones only */
.tabbar {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 200;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--color-bg);
    border-top: 1px solid var(--color-border);
}

.tabbar-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--color-text-tertiary);
    text-decoration: none;
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    background: none;
    border: none;
    font-family: inherit;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.tabbar-item svg { width: 20px; height: 20px; }
.tabbar-item:hover { text-decoration: none; }
.tabbar-item.active { color: var(--color-primary); }

/* Sheet menu for the mobile Tools/Account tabs */
.sheet-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 12, 0.4);
    z-index: 400;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-fast);
}

.sheet-backdrop.open { opacity: 1; visibility: visible; }

.sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 401;
    background: var(--color-bg);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: var(--space-3) var(--space-4) calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
    transform: translateY(100%);
    transition: transform var(--transition-normal);
}

.sheet-backdrop.open .sheet { transform: translateY(0); }

.sheet-handle {
    width: 36px;
    height: 4px;
    border-radius: var(--radius-full);
    background: var(--color-border);
    margin: 0 auto var(--space-3);
}

.sheet-title {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 0 var(--space-2) var(--space-2);
}

.sheet-item {
    display: block;
    padding: 11px var(--space-2);
    color: var(--color-text);
    text-decoration: none;
    font-size: var(--font-size-base);
    border-radius: var(--radius-sm);
}

.sheet-item:hover { background: var(--color-bg-secondary); text-decoration: none; }
.sheet-item.active { color: var(--color-primary); font-weight: var(--font-weight-medium); }

@media (max-width: 767px) {
    .side-nav { display: none; }
    .tabbar { display: flex; }
    body { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px)); }
    .g-search { flex-basis: 100%; max-width: none; }
    .g-toolbar { gap: var(--space-2); }
}

/* -----------------------------------------------------------------------------
   Main Content
   ----------------------------------------------------------------------------- */
.main-content {
    max-width: var(--container-max);
    margin: 0 auto;
    padding: var(--space-6);
}

/* -----------------------------------------------------------------------------
   Page Layout
   ----------------------------------------------------------------------------- */
.page-header {
    margin-bottom: var(--space-6);
}

.page-title {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    letter-spacing: -0.01em;
    color: var(--color-text);
    margin-bottom: 2px;
}

.page-subtitle {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

/* Flex header with status on right */
.page-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.page-header-left {
    flex-shrink: 0;
}

.page-header-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    min-height: 40px;
    min-width: 200px;
}

/* Inline progress/status (in header) */
.progress-inline {
    display: none;
    flex-direction: row;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--color-bg-secondary);
    border-radius: var(--radius-md);
}

.progress-inline.active {
    display: flex;
}

.progress-inline .spinner {
    width: 20px;
    height: 20px;
    border-width: 2px;
}

.progress-inline .progress-text {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

.status-inline {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
}

.status-inline.error {
    background: #fef2f2;
    color: #dc2626;
}

.status-inline.success {
    background: #f0fdf4;
    color: #16a34a;
}

.page-layout {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    gap: var(--space-6);
}

.page-layout--single {
    grid-template-columns: 1fr;
    max-width: 800px;
}

@media (max-width: 1024px) {
    .page-layout {
        grid-template-columns: 1fr;
    }
}

/* -----------------------------------------------------------------------------
   Cards & Panels
   ----------------------------------------------------------------------------- */
.card {
    background: var(--color-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.card-header {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--color-border-light);
}

.card-title {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text);
}

.card-body {
    padding: var(--space-5);
}

.card-footer {
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--color-border-light);
    background: var(--color-bg-tertiary);
}

/* Sidebar Panel */
.sidebar-panel {
    background: var(--color-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: var(--space-5);
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
    height: fit-content;
    position: sticky;
    top: var(--space-6);
}

/* Output Panel */
.output-panel {
    background: var(--color-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: var(--space-5);
    min-height: 500px;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Sticky on desktop so the preview stays in view while scrolling controls */
@media (min-width: 1025px) {
    .output-panel {
        position: sticky;
        top: calc(var(--nav-h) + var(--space-4));
        align-self: start;
        max-height: calc(100vh - var(--nav-h) - var(--space-8));
        overflow-y: auto;
    }
}

/* Status messages at top of output panel */
.output-status {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    margin-bottom: var(--space-4);
}

.output-status.error {
    background: #fef2f2;
    color: #dc2626;
}

.output-status.success {
    background: #f0fdf4;
    color: #16a34a;
}

/* Progress overlay - centered in output panel */
.output-progress {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    border-radius: var(--radius-lg);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-4);
    z-index: 10;
}

.output-progress.active {
    display: flex;
}

.output-progress .progress-text {
    font-size: var(--font-size-base);
    color: var(--color-text-secondary);
}

.output-placeholder {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--color-text-tertiary);
    text-align: center;
    padding: var(--space-8);
}

.output-placeholder-icon {
    font-size: 48px;
    margin-bottom: var(--space-4);
    opacity: 0.5;
}

/* Generated image preview: comfortably sized, never monitor-filling.
   Sits centered in a quiet well; click opens the full-size view. */
.output-image {
    display: block;
    max-width: 100%;
    max-height: min(62vh, 640px);
    width: auto;
    height: auto;
    margin: 0 auto;
    border-radius: var(--radius-md);
    cursor: zoom-in;
}

/* -----------------------------------------------------------------------------
   Form Elements
   ----------------------------------------------------------------------------- */
.form-container {
    max-width: 480px;
    margin: 0 auto;
}

.form-card {
    background: var(--color-bg);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.form-label {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text);
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

/* Info Tooltip */
.info-tooltip {
    position: relative;
    display: inline-flex;
    cursor: help;
}

.info-icon {
    color: var(--color-text-tertiary);
    transition: color var(--transition-fast);
}

.info-tooltip:hover .info-icon {
    color: var(--color-primary);
}

.info-tooltip-text {
    visibility: hidden;
    opacity: 0;
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-text);
    color: var(--color-bg);
    padding: var(--space-3);
    border-radius: var(--radius-md);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-normal);
    line-height: 1.5;
    width: 240px;
    text-align: left;
    z-index: 100;
    margin-bottom: var(--space-2);
    box-shadow: var(--shadow-lg);
    transition: opacity var(--transition-fast), visibility var(--transition-fast);
}

.info-tooltip-text::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--color-text);
}

.info-tooltip:hover .info-tooltip-text {
    visibility: visible;
    opacity: 1;
}

.form-hint {
    font-size: var(--font-size-xs);
    color: var(--color-text-tertiary);
}

/* Text Input */
.form-input {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    font-size: var(--font-size-base);
    font-family: var(--font-family);
    color: var(--color-text);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.form-input:hover {
    border-color: var(--color-text-tertiary);
}

.form-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15);
}

.form-input::placeholder {
    color: var(--color-text-tertiary);
}

/* Textarea */
.form-textarea {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    font-size: var(--font-size-base);
    font-family: var(--font-family);
    color: var(--color-text);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    resize: vertical;
    min-height: 100px;
    transition: all var(--transition-fast);
}

.form-textarea:hover {
    border-color: var(--color-text-tertiary);
}

.form-textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15);
}

/* Select */
.form-select {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    font-size: var(--font-size-base);
    font-family: var(--font-family);
    color: var(--color-text);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236e6e73' d='M6 8.5L1.5 4h9L6 8.5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-3) center;
    padding-right: var(--space-8);
}

.form-select:hover {
    border-color: var(--color-text-tertiary);
}

.form-select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15);
}

.form-select optgroup {
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-secondary);
    background: var(--color-bg-secondary);
    padding: var(--space-2) 0;
}

.form-select option {
    font-weight: var(--font-weight-regular);
    color: var(--color-text);
    background: var(--color-bg);
    padding: var(--space-2);
}

/* Range Slider */
.form-range {
    width: 100%;
    height: 4px;
    background: var(--color-border);
    border-radius: var(--radius-full);
    appearance: none;
    cursor: pointer;
}

.form-range::-webkit-slider-thumb {
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--color-primary);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    transition: transform var(--transition-fast);
}

.form-range::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.form-range::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--color-primary);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    border: none;
}

.range-wrapper {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.range-value {
    min-width: 50px;
    text-align: right;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text);
}

/* Checkbox */
.form-checkbox-wrapper {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    cursor: pointer;
}

.form-checkbox {
    width: 18px;
    height: 18px;
    accent-color: var(--color-primary);
    cursor: pointer;
}

/* Number Input */
.form-number {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-size-base);
    font-family: var(--font-family);
    color: var(--color-text);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    text-align: center;
}

.form-number:focus {
    outline: none;
    border-color: var(--color-primary);
}

/* Form Details (Collapsible) */
.form-details {
    margin-top: var(--space-4);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    background: var(--color-bg-tertiary);
}

.form-details-summary {
    padding: var(--space-3) var(--space-4);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-secondary);
    cursor: pointer;
    user-select: none;
    list-style: none;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.form-details-summary::-webkit-details-marker {
    display: none;
}

.form-details-summary::before {
    content: '';
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 5px solid var(--color-text-tertiary);
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    transition: transform var(--transition-fast);
}

.form-details[open] .form-details-summary::before {
    transform: rotate(90deg);
}

.form-details-summary:hover {
    color: var(--color-text);
}

.form-details-content {
    padding: 0 var(--space-4) var(--space-4);
}

/* Small Image Upload */
.image-upload-small {
    padding: var(--space-4);
}

.image-upload-small .image-upload-icon {
    font-size: 24px;
    margin-bottom: var(--space-1);
}

.image-upload-small .image-upload-text {
    font-size: var(--font-size-sm);
}

.image-upload-small .image-upload-hint {
    display: none;
}

/* Small Image Preview */
.image-preview-small {
    max-width: 120px;
}

.image-preview-small img {
    width: 100%;
    height: auto;
    border-radius: var(--radius-md);
}

/* -----------------------------------------------------------------------------
   Buttons
   ----------------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5);
    font-size: var(--font-size-base);
    font-family: var(--font-family);
    font-weight: var(--font-weight-medium);
    color: var(--color-text);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
}

.btn:hover {
    background: var(--color-bg-tertiary);
    border-color: var(--color-text-tertiary);
    text-decoration: none;
}

.btn:active {
    transform: scale(0.98);
}

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

/* Primary Button */
.btn-primary {
    color: var(--color-bg);
    background: var(--color-primary);
    border-color: var(--color-primary);
}

.btn-primary:hover {
    background: var(--color-primary-hover);
    border-color: var(--color-primary-hover);
}

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

/* Large Button */
.btn-lg {
    padding: var(--space-4) var(--space-8);
    font-size: var(--font-size-lg);
    border-radius: var(--radius-lg);
}

/* Small Button */
.btn-sm {
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-size-sm);
    border-radius: var(--radius-sm);
}

/* Full Width Button */
.btn-block {
    width: 100%;
}

/* Icon Button */
.btn-icon {
    padding: var(--space-2);
    border-radius: var(--radius-sm);
}

/* Danger Button */
.btn-danger {
    color: var(--color-error);
    border-color: var(--color-error);
}

.btn-danger:hover {
    color: var(--color-bg);
    background: var(--color-error);
    border-color: var(--color-error);
}

/* -----------------------------------------------------------------------------
   Accordion
   ----------------------------------------------------------------------------- */
.accordion {
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.accordion-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-4);
    background: var(--color-bg-tertiary);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.accordion-header:hover {
    background: var(--color-bg-secondary);
}

.accordion-title {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
}

.accordion-icon {
    transition: transform var(--transition-normal);
}

.accordion.open .accordion-icon {
    transform: rotate(180deg);
}

.accordion-content {
    display: none;
    padding: var(--space-4);
    border-top: 1px solid var(--color-border-light);
}

.accordion.open .accordion-content {
    display: block;
}

/* -----------------------------------------------------------------------------
   Image Upload
   ----------------------------------------------------------------------------- */
.image-upload {
    border: 2px dashed var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-8);
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    background: var(--color-bg-tertiary);
}

.image-upload:hover {
    border-color: var(--color-primary);
    background: #f0f4ff;
}

.image-upload.dragover {
    border-color: var(--color-primary);
    background: #e8f0ff;
}

.image-upload-icon {
    font-size: 48px;
    color: var(--color-text-tertiary);
    margin-bottom: var(--space-3);
}

.image-upload-text {
    font-size: var(--font-size-base);
    color: var(--color-text-secondary);
}

.image-upload-hint {
    font-size: var(--font-size-sm);
    color: var(--color-text-tertiary);
    margin-top: var(--space-2);
}

.image-upload input[type="file"] {
    display: none;
}

.image-upload-sm {
    padding: var(--space-4);
}

.image-upload-sm .image-upload-icon {
    font-size: 24px;
    margin-bottom: var(--space-2);
}

.image-upload-sm .image-upload-text {
    font-size: var(--font-size-sm);
}

.image-upload-sm .image-upload-hint {
    font-size: var(--font-size-xs);
}

.image-preview {
    position: relative;
    border-radius: var(--radius-lg);
    overflow: hidden;
}

/* Mask Preview */
.mask-preview {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3);
    background: var(--color-bg-secondary);
    border-radius: var(--radius-md);
    margin-top: var(--space-2);
}

.mask-preview img {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border-light);
}

.form-label-optional {
    font-weight: var(--font-weight-regular);
    color: var(--color-text-tertiary);
    font-size: var(--font-size-sm);
}

.image-preview img {
    width: 100%;
    height: auto;
    display: block;
}

.image-preview-remove {
    position: absolute;
    top: var(--space-2);
    right: var(--space-2);
    width: 28px;
    height: 28px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast);
}

.image-preview-remove:hover {
    background: rgba(0, 0, 0, 0.8);
}

/* -----------------------------------------------------------------------------
   Progress
   ----------------------------------------------------------------------------- */
.progress-container {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4);
}

.progress-container.active {
    display: flex;
}

.progress-bar {
    width: 100%;
    height: 4px;
    background: var(--color-border);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--color-primary);
    border-radius: var(--radius-full);
    transition: width var(--transition-normal);
    width: 0%;
}

.progress-text {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

/* Spinner */
.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.spinner-sm {
    width: 14px;
    height: 14px;
    border: 2px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Model Status Row */
.model-status-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 24px;
    margin-top: var(--space-2);
}

.model-loading {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-size-sm);
    color: var(--color-warning);
}

.model-loading.hidden {
    display: none;
}

/* Requirements Checklist */
.requirements-checklist {
    display: flex;
    gap: var(--space-4);
    padding: var(--space-3) var(--space-4);
    background: var(--color-bg-secondary);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-4);
}

.requirements-checklist.hidden {
    display: none;
}

.requirement {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-size-sm);
    color: var(--color-text-tertiary);
}

.requirement.met {
    color: var(--color-success);
}

.requirement.met .requirement-icon {
    color: var(--color-success);
}

.requirement-icon {
    font-size: 14px;
    width: 16px;
    text-align: center;
}

/* -----------------------------------------------------------------------------
   Gallery Grid
   ----------------------------------------------------------------------------- */
/* Photo library: images grouped by day in justified rows that keep each
   image's aspect ratio. Each item carries --ar (width/height) inline; a
   huge-flex ::after keeps the last row from over-stretching. */
.g-library {
    display: flex;
    flex-direction: column;
    gap: var(--space-8);
}

.g-day-label {
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-secondary);
    letter-spacing: 0.04em;
    margin-bottom: var(--space-3);
}

.g-day-label .count {
    color: var(--color-text-tertiary);
}

.g-flow {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.g-flow::after {
    content: '';
    flex-grow: 1000000;
}

.gallery-item {
    position: relative;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--color-bg-tertiary);
    cursor: pointer;
    flex-grow: calc(var(--ar, 1) * 100);
    flex-basis: calc(var(--ar, 1) * 190px);
    aspect-ratio: var(--ar, 1);
    max-width: 100%;
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform var(--transition-normal);
}

.gallery-item:hover img {
    transform: scale(1.025);
}

.gallery-item-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(transparent 50%, rgba(0, 0, 0, 0.7));
    opacity: 0;
    transition: opacity var(--transition-fast);
    display: flex;
    align-items: flex-end;
    padding: var(--space-3);
}

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

.gallery-item-actions {
    display: flex;
    gap: var(--space-2);
}

.gallery-item-action {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text);
    transition: all var(--transition-fast);
}

.gallery-item-action:hover {
    background: var(--color-bg);
    transform: scale(1.1);
}

/* Gallery Select Mode */
.gallery-item-checkbox {
    position: absolute;
    top: var(--space-2);
    left: var(--space-2);
    z-index: 10;
}

.gallery-item-checkbox.hidden {
    display: none;
}

.gallery-item-checkbox input[type="checkbox"] {
    width: 22px;
    height: 22px;
    cursor: pointer;
    accent-color: var(--color-primary);
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.gallery-item.selected {
    outline: 3px solid var(--color-primary);
    outline-offset: -3px;
}

.gallery-item.selected::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(14, 117, 104, 0.12);
    pointer-events: none;
}

/* -----------------------------------------------------------------------------
   Modal
   ----------------------------------------------------------------------------- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-backdrop.active {
    display: flex;
}

.modal-backdrop .modal {
    background: var(--color-bg);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    max-width: 90vw;
    max-height: 90vh;
}

/* Only add overflow to small modals (confirm dialogs, etc), not image detail */
.modal-backdrop .modal:not(.modal-image-detail) {
    overflow: auto;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--color-border-light);
}

.modal-title {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
}

.modal-close {
    width: 32px;
    height: 32px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-tertiary);
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
}

.modal-close:hover {
    background: var(--color-bg-secondary);
    color: var(--color-text);
}

.modal-body {
    padding: var(--space-5);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--color-border-light);
}

/* Image Modal */
.modal-image {
    max-width: 1200px;
}

.modal-image img {
    width: 100%;
    height: auto;
    display: block;
}

.modal-image-info {
    padding: var(--space-4);
    background: var(--color-bg-tertiary);
}

/* Image Detail Modal with Sidebar */
.modal-image-detail {
    /* Definite size so the image area is a real box: the image scales down
       to fit and the letterbox fills the remaining ratio. */
    width: min(1200px, 95vw);
    height: min(840px, 92vh);
    max-width: 95vw;
    max-height: 92vh;
    padding: 0;
    position: relative;
    overflow: hidden; /* Preserve rounded corners */
}

.modal-image-detail .modal-close {
    position: absolute;
    top: var(--space-3);
    right: var(--space-3);
    z-index: 10;
    background: rgba(0, 0, 0, 0.5);
    color: white;
}

.modal-image-detail .modal-close:hover {
    background: rgba(0, 0, 0, 0.7);
    color: white;
}

.modal-image-layout {
    display: flex;
    height: 100%;
}

.modal-image-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #75787e; /* medium gray letterbox */
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.modal-image-container img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
}

/* Stack image over details on phones */
@media (max-width: 767px) {
    .modal-image-layout { flex-direction: column; }
    .modal-image-container { min-height: 40vh; }
    .modal-image-sidebar {
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--color-border-light);
        min-height: 0;
    }
}

.modal-image-sidebar {
    width: 320px;
    flex-shrink: 0;
    background: var(--color-bg);
    display: flex;
    flex-direction: column;
    border-left: 1px solid var(--color-border-light);
}

.modal-image-sidebar-header {
    padding: var(--space-4);
    border-bottom: 1px solid var(--color-border-light);
}

.modal-image-sidebar-header h3 {
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    margin: 0 0 var(--space-1) 0;
    word-break: break-all;
}

.modal-image-metadata {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-4);
}

.metadata-empty {
    color: var(--color-text-tertiary);
    font-size: var(--font-size-sm);
    text-align: center;
    padding: var(--space-4);
}

.metadata-section {
    margin-bottom: var(--space-4);
}

.metadata-section:last-child {
    margin-bottom: 0;
}

.metadata-label {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: var(--space-1);
}

.metadata-value {
    font-size: var(--font-size-sm);
    color: var(--color-text);
    word-break: break-word;
}

.metadata-value.prompt {
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    background: var(--color-bg-secondary);
    padding: var(--space-2);
    border-radius: var(--radius-sm);
    max-height: 240px;
    overflow-y: auto;
}

.metadata-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-3);
}

.modal-image-sidebar-footer {
    padding: var(--space-3);
    border-top: 1px solid var(--color-border-light);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-2);
}

.modal-image-sidebar-footer .btn {
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-size-sm);
}

@media (max-width: 768px) {
    /* Full-screen modal on mobile */
    .modal-image-detail {
        max-width: 100vw;
        max-height: 100dvh;
        width: 100vw;
        border-radius: 0;
    }

    .modal-image-layout {
        flex-direction: column;
        height: 100dvh;
        max-height: 100dvh;
    }

    .modal-image-container {
        flex: 0 0 auto;
    }

    .modal-image-container img {
        max-height: 42dvh;
        width: 100%;
        object-fit: contain;
    }

    /* Sidebar fills remaining height with proper flex chain */
    .modal-image-sidebar {
        width: 100%;
        flex: 1 1 0;
        min-height: 0;
        max-height: none;
        display: flex;
        flex-direction: column;
    }

    /* Metadata scrolls inside available space */
    .modal-image-metadata {
        flex: 1 1 0;
        min-height: 0;
        overflow-y: auto;
    }

    /* Footer always visible */
    .modal-image-sidebar-footer {
        flex-shrink: 0;
        grid-template-columns: repeat(4, 1fr);
        padding: var(--space-2) var(--space-3);
    }

    .modal-image-sidebar-footer .btn {
        padding: var(--space-2) var(--space-1);
        font-size: 12px;
        text-align: center;
    }

    .modal-image-detail .modal-close {
        top: var(--space-2);
        right: var(--space-2);
    }
}

/* -----------------------------------------------------------------------------
   Prompt Helper / Chat
   ----------------------------------------------------------------------------- */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 300px;
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-3);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.chat-message {
    max-width: 85%;
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-lg);
    font-size: var(--font-size-sm);
    line-height: var(--line-height-relaxed);
}

.chat-message.user {
    align-self: flex-end;
    background: var(--color-primary);
    color: var(--color-bg);
    border-bottom-right-radius: var(--radius-sm);
}

.chat-message.assistant {
    align-self: flex-start;
    background: var(--color-bg-secondary);
    color: var(--color-text);
    border-bottom-left-radius: var(--radius-sm);
}

.chat-input-area {
    display: flex;
    gap: var(--space-2);
    padding: var(--space-3);
    border-top: 1px solid var(--color-border-light);
    background: var(--color-bg-tertiary);
}

.chat-input {
    flex: 1;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    font-family: var(--font-family);
}

.chat-input:focus {
    outline: none;
    border-color: var(--color-primary);
}

/* -----------------------------------------------------------------------------
   Aspect Ratio Buttons
   ----------------------------------------------------------------------------- */
.aspect-ratio-group {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.aspect-ratio-btn {
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-secondary);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.aspect-ratio-btn:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.aspect-ratio-btn.active {
    background: var(--color-primary);
    color: var(--color-bg);
    border-color: var(--color-primary);
}

/* -----------------------------------------------------------------------------
   LoRA Multi-Select
   ----------------------------------------------------------------------------- */
.lora-multiselect {
    position: relative;
}

.lora-multiselect-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-4);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.lora-multiselect-trigger:hover {
    border-color: var(--color-text-tertiary);
}

.lora-multiselect-placeholder {
    color: var(--color-text-tertiary);
    font-size: var(--font-size-base);
}

.lora-multiselect-placeholder.has-selection {
    color: var(--color-text);
    font-weight: var(--font-weight-medium);
}

.lora-multiselect-arrow {
    width: 16px;
    height: 16px;
    color: var(--color-text-tertiary);
    transition: transform var(--transition-fast);
}

.lora-multiselect-dropdown.open + .lora-multiselect-arrow,
.lora-multiselect-dropdown.open ~ .lora-multiselect-trigger .lora-multiselect-arrow {
    transform: rotate(180deg);
}

.lora-multiselect-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 100;
    display: none;
    max-height: 300px;
    overflow: hidden;
}

.lora-multiselect-dropdown.open {
    display: block;
}

.lora-multiselect-search {
    padding: var(--space-2);
    border-bottom: 1px solid var(--color-border-light);
}

.lora-multiselect-search input {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
    font-family: var(--font-family);
}

.lora-multiselect-search input:focus {
    outline: none;
    border-color: var(--color-primary);
}

.lora-multiselect-list {
    max-height: 350px;
    overflow-y: auto;
    padding: var(--space-1);
}

.lora-category {
    margin-bottom: var(--space-2);
}

.lora-category:last-child {
    margin-bottom: 0;
}

.lora-category-header {
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--color-border);
    margin-bottom: var(--space-1);
    position: sticky;
    top: 0;
    background: var(--color-bg);
    z-index: 1;
}

.lora-multiselect-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.lora-multiselect-item:hover {
    background: var(--color-bg-secondary);
}

.lora-multiselect-item.selected {
    background: rgba(0, 113, 227, 0.08);
}

.lora-multiselect-item input[type="checkbox"] {
    display: none;
}

.lora-multiselect-checkbox {
    width: 18px;
    height: 18px;
    border: 2px solid var(--color-border);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.lora-multiselect-item.selected .lora-multiselect-checkbox {
    background: linear-gradient(135deg, #0071e3 0%, #34c759 100%);
    border-color: transparent;
}

.lora-multiselect-item.selected .lora-multiselect-checkbox::after {
    content: '';
    width: 6px;
    height: 10px;
    border: 2px solid white;
    border-top: none;
    border-left: none;
    transform: rotate(45deg) translateY(-1px);
}

.lora-multiselect-info {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex: 1;
    min-width: 0;
}

.lora-multiselect-title {
    font-size: var(--font-size-sm);
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lora-base-tag {
    font-size: 10px;
    padding: 2px 6px;
    background: var(--color-bg-tertiary);
    color: var(--color-text-secondary);
    border-radius: var(--radius-xs);
    white-space: nowrap;
    flex-shrink: 0;
}

.lora-multiselect-name {
    font-size: var(--font-size-sm);
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lora-multiselect-empty,
.lora-multiselect-loading {
    padding: var(--space-4);
    text-align: center;
    color: var(--color-text-tertiary);
    font-size: var(--font-size-sm);
}

/* Selected LoRAs List */
.lora-selected-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    margin-top: var(--space-3);
}

.lora-selected-item .form-label {
    display: block;
    margin-bottom: var(--space-2);
}

.lora-selected-item .range-wrapper {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
}

.lora-selected-item .form-range {
    flex: 1;
}

.lora-selected-remove {
    float: right;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-tertiary);
    font-size: 14px;
    line-height: 1;
    padding: 0;
    transition: color var(--transition-fast);
}

.lora-selected-remove:hover {
    color: var(--color-error);
}

/* -----------------------------------------------------------------------------
   Status Messages
   ----------------------------------------------------------------------------- */
.status {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.status-success {
    background: rgba(52, 199, 89, 0.1);
    color: var(--color-success);
    border: 1px solid rgba(52, 199, 89, 0.3);
}

.status-error {
    background: rgba(255, 59, 48, 0.1);
    color: var(--color-error);
    border: 1px solid rgba(255, 59, 48, 0.3);
}

.status-info {
    background: rgba(0, 113, 227, 0.1);
    color: var(--color-primary);
    border: 1px solid rgba(0, 113, 227, 0.3);
}

/* -----------------------------------------------------------------------------
   Login Page
   ----------------------------------------------------------------------------- */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg-secondary);
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: var(--space-4);
}

.login-card {
    background: var(--color-bg);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    padding: var(--space-8);
    text-align: center;
}

.login-logo {
    width: 240px;
    height: auto;
    margin-bottom: var(--space-6);
}

.login-title {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    margin-bottom: var(--space-2);
}

.login-subtitle {
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    margin-bottom: var(--space-6);
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.login-error {
    color: var(--color-error);
    font-size: var(--font-size-sm);
    margin-bottom: var(--space-2);
}

/* -----------------------------------------------------------------------------
   Canvas Editor (for Inpainting)
   ----------------------------------------------------------------------------- */
.canvas-editor {
    position: relative;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: #1a1a1a;
}

.canvas-editor canvas {
    display: block;
    cursor: crosshair;
    touch-action: none;
    margin: 0 auto;
}

.canvas-tools {
    display: flex;
    gap: var(--space-2);
    padding: var(--space-3);
    background: var(--color-bg-tertiary);
    border-bottom: 1px solid var(--color-border-light);
}

.canvas-tool {
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-secondary);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.canvas-tool:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.canvas-tool.active {
    background: var(--color-primary);
    color: var(--color-bg);
    border-color: var(--color-primary);
}

.brush-size-control {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-left: auto;
}

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

.brush-size-control input[type="range"] {
    width: 80px;
}

.canvas-container {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: var(--space-4);
    background: #1a1a1a;
    min-height: 400px;
}

/* -----------------------------------------------------------------------------
   Modal
   ----------------------------------------------------------------------------- */

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
}

.modal-content {
    position: relative;
    background: var(--color-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    z-index: 1001;
}

.modal-large {
    width: 1200px;
    max-width: 95vw;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--color-border);
}

.modal-header h2 {
    margin: 0;
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
}

.modal-close {
    background: none;
    border: none;
    font-size: 32px;
    line-height: 1;
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color var(--transition-fast);
}

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

.modal-body {
    flex: 1;
    overflow: auto;
    padding: var(--space-5);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--color-border);
}

/* -----------------------------------------------------------------------------
   Utility Classes
   ----------------------------------------------------------------------------- */
.hidden {
    display: none !important;
}

.flex {
    display: flex;
}

.flex-col {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.gap-2 {
    gap: var(--space-2);
}

.gap-3 {
    gap: var(--space-3);
}

.gap-4 {
    gap: var(--space-4);
}

.mt-2 {
    margin-top: var(--space-2);
}

.mt-4 {
    margin-top: var(--space-4);
}

.mb-2 {
    margin-bottom: var(--space-2);
}

.mb-4 {
    margin-bottom: var(--space-4);
}

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

.text-sm {
    font-size: var(--font-size-sm);
}

.text-secondary {
    color: var(--color-text-secondary);
}

.w-full {
    width: 100%;
}

/* -----------------------------------------------------------------------------
   Responsive Adjustments
   ----------------------------------------------------------------------------- */
@media (max-width: 768px) {
    .main-content {
        padding: var(--space-4);
    }

    .sidebar-panel {
        position: static;
    }

    .gallery-item {
        flex-basis: calc(var(--ar, 1) * 118px);
        border-radius: 4px;
    }
    .g-flow { gap: 4px; }
}

/* -----------------------------------------------------------------------------
   Floating Chat Widget
   ----------------------------------------------------------------------------- */
.chat-widget {
    position: fixed;
    bottom: var(--space-6);
    right: var(--space-6);
    z-index: 1000;
    font-family: var(--font-family);
    display: flex;
    flex-direction: row-reverse;
    align-items: flex-end;
    gap: var(--space-3);
}

.chat-widget-toggle {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--color-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
    transition: all var(--transition-normal);
}

.chat-widget-toggle:hover {
    transform: scale(1.05);
    background: var(--color-primary-hover);
}

.chat-widget-toggle svg {
    width: 24px;
    height: 24px;
    color: white;
    transition: all var(--transition-normal);
}

.chat-widget-toggle .close-icon {
    display: none;
}

.chat-widget.open .chat-widget-toggle .chat-icon {
    display: none;
}

.chat-widget.open .chat-widget-toggle .close-icon {
    display: block;
}

.chat-widget-window {
    position: relative;
    bottom: 0;
    left: 0;
    width: 360px;
    max-width: calc(100vw - 100px);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    display: none;
    flex-direction: column;
    animation: chatSlideIn 0.3s ease;
}

@keyframes chatSlideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.chat-widget.open .chat-widget-window {
    display: flex;
}

.chat-widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) var(--space-3) var(--space-2) var(--space-4);
    background: var(--header-bg);
    color: var(--header-text);
}

.chat-widget-title {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-weight: var(--font-weight-semibold);
    font-size: var(--font-size-base);
}

.chat-widget-icon {
    font-size: 18px;
}

.chat-widget-minimize {
    width: 28px;
    height: 28px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast);
}

.chat-widget-minimize:hover {
    background: rgba(255, 255, 255, 0.3);
}

.chat-widget-controls {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.chat-model-select {
    padding: 4px 8px;
    font-size: 11px;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: var(--radius-sm);
    color: white;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 8 8'%3E%3Cpath fill='white' d='M4 6L0 2h8L4 6z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 6px center;
    padding-right: 20px;
}

.chat-model-select:hover {
    background-color: rgba(255, 255, 255, 0.3);
}

.chat-model-select:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.5);
}

.chat-model-select option {
    background: var(--color-bg);
    color: var(--color-text);
}

.chat-widget-body {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.chat-widget-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-3);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    max-height: 340px;
    min-height: 180px;
}

.chat-widget-messages .chat-message {
    max-width: 90%;
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-lg);
    font-size: var(--font-size-sm);
    line-height: var(--line-height-relaxed);
    word-wrap: break-word;
}

.chat-widget-messages .chat-message.user {
    align-self: flex-end;
    background: var(--color-primary);
    color: var(--color-bg);
    border-bottom-right-radius: var(--radius-sm);
}

.chat-widget-messages .chat-message.assistant {
    align-self: flex-start;
    background: var(--color-bg-secondary);
    color: var(--color-text);
    border-bottom-left-radius: var(--radius-sm);
}

.chat-widget-messages .chat-message.typing {
    background: var(--color-bg-secondary);
    color: var(--color-text-tertiary);
}

.chat-widget-messages .chat-message.typing::after {
    content: '';
    animation: typingDots 1.5s infinite;
}

@keyframes typingDots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* Structured Response Sections */
.response-intro {
    margin-bottom: var(--space-3);
    white-space: pre-wrap;
}

.response-section {
    margin: var(--space-3) 0;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--color-border-light);
}

.response-section .section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-2) var(--space-3);
    background: var(--color-bg-tertiary);
    border-bottom: 1px solid var(--color-border-light);
}

.response-section .section-label {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-secondary);
}

.response-section .section-content {
    padding: var(--space-3);
    font-size: var(--font-size-sm);
    line-height: var(--line-height-relaxed);
    white-space: pre-wrap;
    word-break: break-word;
    background: var(--color-bg);
}

.response-section.prompt-section .section-label {
    color: var(--color-primary);
}

.response-section.negative-section .section-label {
    color: var(--color-error);
}

.response-section.settings-section .section-label {
    color: var(--color-success);
}

.copy-section-btn {
    padding: var(--space-1) var(--space-2);
    font-size: var(--font-size-xs);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--color-text-secondary);
    transition: all var(--transition-fast);
}

.copy-section-btn:hover {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

.chat-widget-footer {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3);
    border-top: 1px solid var(--color-border-light);
    background: var(--color-bg);
}

.chat-widget-input {
    flex: 1;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-sm);
    font-family: var(--font-family);
    background: var(--color-bg);
    color: var(--color-text);
    resize: none;
    transition: all var(--transition-fast);
}

.chat-widget-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 20%, transparent);
}

.chat-widget-send {
    width: 40px;
    height: 40px;
    background: var(--color-primary);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.chat-widget-send:hover {
    transform: scale(1.05);
}

.chat-widget-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.chat-widget-send svg {
    width: 18px;
    height: 18px;
    color: white;
}

.chat-widget-actions {
    display: flex;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-top: 1px solid var(--color-border-light);
    background: var(--color-bg-secondary);
}

.chat-widget-actions .btn {
    flex: 1;
}

/* Mobile adjustments for chat widget */
@media (max-width: 600px) {
    .chat-widget {
        bottom: var(--space-4);
        right: var(--space-4);
        flex-direction: column-reverse;
        align-items: flex-end;
    }

    .chat-widget-window {
        position: absolute;
        bottom: 60px;
        right: 0;
        width: calc(100vw - 32px);
        max-width: none;
    }

    .chat-widget-toggle {
        width: 50px;
        height: 50px;
    }
}

/* -----------------------------------------------------------------------------
   Guide Page
   ----------------------------------------------------------------------------- */

.guide-layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: var(--space-8);
    max-width: 1200px;
    margin: 0 auto;
}

/* Table of Contents */
.guide-toc {
    position: sticky;
    top: var(--space-6);
    align-self: start;
    background: var(--color-bg);
    border-radius: var(--radius-md);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
}

.guide-toc-title {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: var(--space-4);
}

.guide-toc-list {
    list-style: none;
}

.guide-toc-list li {
    margin-bottom: var(--space-2);
}

.guide-toc-list a {
    display: block;
    padding: var(--space-2) var(--space-3);
    color: var(--color-text-secondary);
    text-decoration: none;
    font-size: var(--font-size-sm);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.guide-toc-list a:hover {
    color: var(--color-text);
    background: var(--color-bg-secondary);
}

.guide-toc-list a.active {
    color: var(--color-primary);
    background: rgba(0, 113, 227, 0.08);
    font-weight: var(--font-weight-medium);
}

/* Main Content */
.guide-content {
    min-width: 0;
}

.guide-section {
    background: var(--color-bg);
    border-radius: var(--radius-lg);
    padding: var(--space-8);
    margin-bottom: var(--space-6);
    box-shadow: var(--shadow-sm);
}

.guide-section-title {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-bold);
    margin-bottom: var(--space-3);
    color: var(--color-text);
}

.guide-intro {
    font-size: var(--font-size-lg);
    color: var(--color-text-secondary);
    margin-bottom: var(--space-6);
}

.guide-subsection-title {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    margin-top: var(--space-8);
    margin-bottom: var(--space-4);
    color: var(--color-text);
}

/* Cards */
.guide-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--space-5);
}

.guide-card-grid.two-col {
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.guide-card {
    background: var(--color-bg-secondary);
    border-radius: var(--radius-md);
    padding: var(--space-5);
}

.guide-card.highlight {
    background: linear-gradient(135deg, rgba(0, 113, 227, 0.05) 0%, rgba(52, 199, 89, 0.05) 100%);
    border: 1px solid rgba(0, 113, 227, 0.15);
}

.guide-card-header {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-3);
}

.guide-card h3 {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    margin: 0;
}

.guide-card p {
    color: var(--color-text-secondary);
    margin-bottom: var(--space-3);
}

.guide-card p:last-child {
    margin-bottom: 0;
}

/* Badges */
.guide-badge {
    display: inline-block;
    padding: var(--space-1) var(--space-3);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-radius: var(--radius-full);
}

.badge-fast {
    background: rgba(52, 199, 89, 0.15);
    color: #28a745;
}

.badge-balanced {
    background: rgba(255, 149, 0, 0.15);
    color: #e68a00;
}

.badge-quality {
    background: rgba(0, 113, 227, 0.15);
    color: var(--color-primary);
}

.badge-special {
    background: linear-gradient(135deg, rgba(0, 113, 227, 0.2) 0%, rgba(52, 199, 89, 0.2) 100%);
    color: var(--color-primary);
}

.badge-recommended {
    background: rgba(52, 199, 89, 0.15);
    color: #28a745;
    margin-top: var(--space-2);
}

/* Lists */
.guide-list {
    list-style: none;
    margin: var(--space-3) 0;
}

.guide-list li {
    position: relative;
    padding-left: var(--space-5);
    margin-bottom: var(--space-2);
    color: var(--color-text-secondary);
}

.guide-list li::before {
    content: "";
    position: absolute;
    left: 0;
    top: 8px;
    width: 6px;
    height: 6px;
    background: var(--color-primary);
    border-radius: 50%;
}

.guide-list.numbered {
    counter-reset: item;
}

.guide-list.numbered li::before {
    content: counter(item);
    counter-increment: item;
    width: 20px;
    height: 20px;
    background: var(--color-primary);
    color: white;
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    display: flex;
    align-items: center;
    justify-content: center;
    top: 2px;
}

.guide-list li strong {
    color: var(--color-text);
}

/* Examples */
.guide-example {
    background: var(--color-bg-secondary);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    margin: var(--space-4) 0;
}

.guide-example-label {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: var(--space-2);
}

.guide-prompt {
    display: block;
    font-family: "SF Mono", Monaco, "Cascadia Code", monospace;
    font-size: var(--font-size-sm);
    color: var(--color-text);
    line-height: var(--line-height-relaxed);
    word-break: break-word;
    white-space: pre-wrap;
}

.guide-code {
    display: block;
    font-family: "SF Mono", Monaco, "Cascadia Code", monospace;
    font-size: var(--font-size-xs);
    color: var(--color-text);
    background: var(--color-bg-secondary);
    padding: var(--space-4);
    border-radius: var(--radius-md);
    overflow-x: auto;
    white-space: pre;
    margin-top: var(--space-3);
}

/* Tags */
.guide-tags {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-top: var(--space-3);
}

.guide-tag {
    display: inline-block;
    padding: var(--space-1) var(--space-3);
    background: var(--color-bg);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-full);
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

/* Table */
.guide-table {
    width: 100%;
    margin: var(--space-4) 0;
    border-collapse: collapse;
}

.guide-table td {
    padding: var(--space-3);
    border-bottom: 1px solid var(--color-border-light);
}

.guide-table td:first-child {
    color: var(--color-text-secondary);
    width: 40%;
}

.guide-table code {
    background: var(--color-bg);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    font-family: "SF Mono", Monaco, monospace;
    font-size: var(--font-size-sm);
}

/* Notes */
.guide-note {
    font-size: var(--font-size-sm);
    color: var(--color-text-tertiary);
    font-style: italic;
    margin-top: var(--space-3);
}

/* Recipes */
.guide-recipe {
    background: var(--color-bg-secondary);
    border-radius: var(--radius-md);
    padding: var(--space-6);
    margin-bottom: var(--space-5);
}

.guide-recipe-title {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    margin-bottom: var(--space-4);
    color: var(--color-text);
}

.guide-recipe-content {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.guide-recipe-settings {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
}

.guide-recipe-setting {
    display: flex;
    flex-direction: column;
    background: var(--color-bg);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-sm);
}

.guide-recipe-setting .label {
    font-size: var(--font-size-xs);
    color: var(--color-text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.guide-recipe-setting .value {
    font-weight: var(--font-weight-medium);
    color: var(--color-text);
}

.guide-recipe .guide-example {
    background: var(--color-bg);
}

/* Mobile */
@media (max-width: 900px) {
    .guide-layout {
        grid-template-columns: 1fr;
    }

    .guide-toc {
        position: relative;
        top: 0;
        margin-bottom: var(--space-4);
    }

    .guide-toc-list {
        display: flex;
        flex-wrap: wrap;
        gap: var(--space-2);
    }

    .guide-toc-list li {
        margin: 0;
    }

    .guide-section {
        padding: var(--space-5);
    }

    .guide-card-grid,
    .guide-card-grid.two-col {
        grid-template-columns: 1fr;
    }

    .guide-recipe-settings {
        flex-direction: column;
    }

    .guide-recipe-setting {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
}

/* -----------------------------------------------------------------------------
   AI Chat Page
   ----------------------------------------------------------------------------- */
.chat-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: var(--space-5);
    height: calc(100vh - 140px);
    min-height: 500px;
}

.chat-layout-full {
    height: calc(100vh - 90px);
}

/* Sidebar */
.chat-sidebar {
    background: var(--color-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-sidebar-header {
    padding: var(--space-4);
    border-bottom: 1px solid var(--color-border-light);
}

.chat-sidebar-header .btn {
    width: 100%;
}

.chat-sidebar-empty {
    padding: var(--space-6) var(--space-4);
    text-align: center;
    color: var(--color-text-tertiary);
    font-size: var(--font-size-sm);
}

.chat-projects {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-2);
}

/* Project Item */
.chat-project {
    margin-bottom: var(--space-1);
}

.chat-project-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.chat-project-header:hover {
    background: var(--color-bg-secondary);
}

.chat-project.active > .chat-project-header {
    background: rgba(0, 113, 227, 0.08);
}

.chat-project-toggle {
    width: 20px;
    height: 20px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--transition-fast);
    flex-shrink: 0;
}

.chat-project-toggle.expanded {
    transform: rotate(90deg);
}

.chat-project-name {
    flex: 1;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-project-actions {
    display: none;
    gap: var(--space-1);
}

.chat-project-header:hover .chat-project-actions {
    display: flex;
}

/* Thread List */
.chat-threads {
    display: none;
    padding-left: var(--space-6);
    padding-top: var(--space-1);
    padding-bottom: var(--space-2);
    margin-left: var(--space-3);
    border-left: 1px solid var(--color-border-light);
}

.chat-threads.expanded {
    display: block;
}

.chat-threads-empty {
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-size-sm);
    color: var(--color-text-tertiary);
}

/* Thread Item */
.chat-thread {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-1) var(--space-3);
    margin-bottom: 2px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.chat-thread:hover {
    background: var(--color-bg-secondary);
}

.chat-thread.active {
    background: rgba(0, 113, 227, 0.08);
}

.chat-thread-title {
    flex: 1;
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-thread.active .chat-thread-title {
    color: var(--color-text);
    font-weight: var(--font-weight-medium);
}

.chat-thread-delete {
    display: none;
}

.chat-thread:hover .chat-thread-delete {
    display: flex;
}

/* Main Chat Area */
.chat-main {
    background: var(--color-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Empty State */
.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--color-text-tertiary);
    text-align: center;
    padding: var(--space-8);
}

.chat-empty-icon {
    margin-bottom: var(--space-4);
    opacity: 0.5;
}

.chat-empty h2 {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-secondary);
    margin-bottom: var(--space-2);
}

.chat-empty p {
    font-size: var(--font-size-sm);
}

/* Chat Content */
.chat-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Chat Header */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--color-border-light);
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.chat-header-title {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text);
}

.btn-edit-title {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-tertiary);
    padding: var(--space-1);
    border-radius: var(--radius-sm);
}

.btn-edit-title:hover {
    color: var(--color-text);
    background: var(--color-bg-secondary);
}

.chat-header-controls {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

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

.form-select-sm {
    padding: var(--space-2) var(--space-6) var(--space-2) var(--space-3);
    font-size: var(--font-size-sm);
}

/* Chat Messages */
.chat-main .chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-5);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    max-height: none;
    min-height: 0;
}

.chat-main .chat-message {
    max-width: 75%;
}

.chat-main .chat-message-user {
    align-self: flex-end;
    background: var(--color-primary);
    color: white;
    border-radius: var(--radius-lg);
    border-bottom-right-radius: var(--radius-sm);
}

.chat-main .chat-message-assistant {
    align-self: flex-start;
    background: var(--color-bg-secondary);
    color: var(--color-text);
    border-radius: var(--radius-lg);
    border-bottom-left-radius: var(--radius-sm);
}

.chat-message-content {
    padding: var(--space-3) var(--space-4);
    font-size: var(--font-size-base);
    line-height: var(--line-height-relaxed);
    word-wrap: break-word;
}

.chat-message-content code {
    background: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-family: "SF Mono", Monaco, monospace;
    font-size: 0.9em;
}

.chat-message-user .chat-message-content code {
    background: rgba(255, 255, 255, 0.2);
}

.chat-message-content pre {
    background: rgba(0, 0, 0, 0.05);
    padding: var(--space-3);
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: var(--space-2) 0;
}

.chat-message-user .chat-message-content pre {
    background: rgba(255, 255, 255, 0.1);
}

.chat-message-content pre code {
    background: none;
    padding: 0;
}

/* Typing Indicator */
.chat-typing .chat-message-content {
    padding: var(--space-3) var(--space-4);
}

.chat-typing-indicator {
    display: flex;
    gap: 4px;
}

.chat-typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--color-text-tertiary);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.chat-typing-indicator span:nth-child(1) {
    animation-delay: -0.32s;
}

.chat-typing-indicator span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Chat Input Area - Improved Design */
.chat-input-container {
    padding: var(--space-4) var(--space-5);
    background: var(--color-bg);
}

.chat-input-box {
    display: flex;
    align-items: flex-end;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    transition: all var(--transition-fast);
}

.chat-input-box:focus-within {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.1);
    background: var(--color-bg);
}

.chat-input-field {
    flex: 1;
    padding: var(--space-2) 0;
    border: none;
    background: transparent;
    font-size: var(--font-size-base);
    font-family: var(--font-family);
    color: var(--color-text);
    resize: none;
    min-height: 24px;
    max-height: 200px;
    line-height: var(--line-height-normal);
}

.chat-input-field:focus {
    outline: none;
}

.chat-input-field::placeholder {
    color: var(--color-text-tertiary);
}

.chat-send-button {
    width: 40px;
    height: 40px;
    padding: 0;
    border: none;
    border-radius: var(--radius-md);
    background: var(--color-primary);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.chat-send-button:hover:not(:disabled) {
    background: var(--color-primary-hover);
    transform: scale(1.05);
}

.chat-send-button:disabled {
    background: var(--color-border);
    cursor: not-allowed;
}

.chat-input-hint {
    text-align: center;
    font-size: var(--font-size-xs);
    color: var(--color-text-tertiary);
    margin-top: var(--space-2);
}

/* Legacy input area support */
.chat-main .chat-input-area {
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--color-border-light);
    background: var(--color-bg);
}

.chat-input-wrapper {
    display: flex;
    gap: var(--space-3);
    align-items: flex-end;
}

.chat-main .chat-input {
    flex: 1;
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    font-size: var(--font-size-base);
    font-family: var(--font-family);
    resize: none;
    min-height: 44px;
    max-height: 200px;
    line-height: var(--line-height-normal);
}

.chat-main .chat-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15);
}

.chat-send-btn {
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: var(--radius-md);
    flex-shrink: 0;
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-overlay.open {
    display: flex;
}

.modal-overlay .modal {
    width: 100%;
    max-width: 400px;
    margin: var(--space-4);
}

.modal-overlay .modal.modal-md {
    max-width: 500px;
}

.form-label-hint {
    font-weight: var(--font-weight-regular);
    color: var(--color-text-tertiary);
    font-size: var(--font-size-sm);
}

/* Secondary Button */
.btn-secondary {
    background: var(--color-bg-secondary);
    border-color: var(--color-border);
    color: var(--color-text);
}

.btn-secondary:hover {
    background: var(--color-bg-tertiary);
}

/* Icon Button Styles */
.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-tertiary);
    padding: var(--space-1);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.btn-icon:hover {
    color: var(--color-text);
    background: var(--color-bg-secondary);
}

.btn-icon.btn-danger:hover {
    color: var(--color-error);
    background: rgba(255, 59, 48, 0.1);
}

/* Text Utilities */
.text-error {
    color: var(--color-error);
}

/* Chat Mobile Responsive */
@media (max-width: 768px) {
    .chat-layout {
        grid-template-columns: 1fr;
        height: auto;
        min-height: calc(100vh - 200px);
    }

    .chat-sidebar {
        max-height: 200px;
    }

    .chat-main {
        min-height: 400px;
    }

    .chat-main .chat-message {
        max-width: 90%;
    }
}

.page-description {
    font-size: var(--font-size-base);
    color: var(--color-text-secondary);
}

/* -----------------------------------------------------------------------------
   Integrations Settings Page
   ----------------------------------------------------------------------------- */
.integrations-layout {
    display: flex;
    flex-direction: column;
    gap: var(--space-8);
    max-width: 900px;
}

.integration-section {
    background: var(--color-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--color-border-light);
    background: var(--color-bg-tertiary);
}

.section-title {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text);
    margin: 0;
}

.integration-list {
    padding: var(--space-4);
}

.integration-loading,
.integration-empty,
.integration-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-8);
    color: var(--color-text-tertiary);
    text-align: center;
    gap: var(--space-3);
}

.integration-error {
    color: var(--color-error);
}

/* Storage Cards */
.storage-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--space-4);
    padding: var(--space-4);
}

.storage-card {
    background: var(--color-bg);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    padding: var(--space-4);
}

.storage-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-2);
}

.storage-card-header h3 {
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    margin: 0;
}

.storage-size {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-bold);
    color: var(--color-primary);
}

.storage-desc {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    margin-bottom: var(--space-3);
    line-height: 1.5;
}

/* Integration Card */
.integration-card {
    background: var(--color-bg);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-3);
    transition: all var(--transition-fast);
}

.integration-card:last-child {
    margin-bottom: 0;
}

.integration-card:hover {
    border-color: var(--color-border);
    box-shadow: var(--shadow-sm);
}

.integration-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4);
    gap: var(--space-4);
}

.integration-info {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    flex: 1;
    min-width: 0;
}

.integration-icon {
    width: 40px;
    height: 40px;
    background: var(--color-bg-secondary);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.integration-icon svg {
    width: 24px;
    height: 24px;
    color: var(--color-text-secondary);
}

.integration-details {
    flex: 1;
    min-width: 0;
}

.integration-name {
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text);
    margin: 0 0 var(--space-1) 0;
}

.integration-description {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mcp-command {
    font-family: "SF Mono", Monaco, monospace;
    font-size: var(--font-size-xs);
}

.integration-card-footer {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--color-bg-secondary);
    border-top: 1px solid var(--color-border-light);
}

.integration-status {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
}

.integration-status.status-connected {
    background: rgba(52, 199, 89, 0.1);
    color: var(--color-success);
}

.integration-status.status-enabled {
    background: rgba(255, 149, 0, 0.1);
    color: var(--color-warning);
}

.integration-status.status-disabled {
    background: var(--color-bg-tertiary);
    color: var(--color-text-tertiary);
}

.integration-tools {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    margin-left: auto;
}

.integration-card-footer .btn {
    margin-left: var(--space-2);
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

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

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--color-border);
    transition: var(--transition-fast);
    border-radius: 24px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: var(--transition-fast);
    border-radius: 50%;
    box-shadow: var(--shadow-sm);
}

.toggle-switch input:checked + .toggle-slider {
    background-color: var(--color-success);
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(20px);
}

.toggle-switch input:focus + .toggle-slider {
    box-shadow: 0 0 0 3px rgba(52, 199, 89, 0.15);
}

/* Button Success/Danger States */
.btn-success {
    background: var(--color-success);
    border-color: var(--color-success);
    color: white;
}

.btn-success:hover {
    background: #2db84d;
    border-color: #2db84d;
}

/* -----------------------------------------------------------------------------
   Site Footer
   ----------------------------------------------------------------------------- */
.site-footer {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: var(--space-8) var(--space-6) var(--space-6);
    margin-top: var(--space-8);
    max-width: var(--container-max);
    margin-left: auto;
    margin-right: auto;
    opacity: 0.75;
    transition: opacity var(--transition-fast);
}

.site-footer:hover { opacity: 1; }

.footer-creature {
    width: 140px;
    height: auto;
}

.footer-nav {
    display: flex;
    align-items: center;
    gap: var(--space-5);
}

.footer-nav-title {
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text);
    margin: 0;
    margin-right: var(--space-3);
}

.footer-nav a {
    color: var(--color-text-secondary);
    text-decoration: none;
    font-size: var(--font-size-base);
    transition: color var(--transition-fast);
}

.footer-nav a:hover {
    color: var(--color-text);
}

/* -----------------------------------------------------------------------------
   Documentation Layout
   ----------------------------------------------------------------------------- */
.docs-layout {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: var(--space-6);
    max-width: 1200px;
    margin: 0 auto;
}

.docs-sidebar {
    position: sticky;
    top: var(--space-4);
    height: fit-content;
    max-height: calc(100vh - var(--space-8));
    overflow-y: auto;
}

.docs-search {
    margin-bottom: var(--space-4);
}

.docs-nav-section {
    margin-bottom: var(--space-4);
}

.docs-nav-title {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: var(--space-2);
}

.docs-nav-link {
    display: block;
    padding: var(--space-1) var(--space-2);
    margin-left: calc(-1 * var(--space-2));
    color: var(--color-text-secondary);
    text-decoration: none;
    font-size: var(--font-size-sm);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.docs-nav-link:hover {
    color: var(--color-text);
    background: var(--color-bg-secondary);
    text-decoration: none;
}

.docs-nav-link.active {
    color: var(--color-primary);
    background: rgba(0, 113, 227, 0.08);
    font-weight: var(--font-weight-medium);
}

.docs-content {
    min-width: 0;
}

.docs-header {
    margin-bottom: var(--space-6);
}

.docs-header h1 {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-semibold);
    margin-bottom: var(--space-2);
}

.docs-subtitle {
    color: var(--color-text-secondary);
    font-size: var(--font-size-lg);
}

.docs-breadcrumb {
    font-size: var(--font-size-sm);
    color: var(--color-text-tertiary);
    margin-bottom: var(--space-4);
}

.docs-breadcrumb a {
    color: var(--color-text-secondary);
}

.docs-breadcrumb a:hover {
    color: var(--color-primary);
}

.docs-intro {
    font-size: var(--font-size-lg);
    color: var(--color-text-secondary);
    margin-bottom: var(--space-6);
    line-height: var(--line-height-relaxed);
}

/* Docs Cards */
.docs-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-4);
    margin-bottom: var(--space-8);
}

.docs-card {
    display: block;
    padding: var(--space-5);
    background: var(--color-bg);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-lg);
    text-decoration: none;
    transition: all var(--transition-fast);
}

.docs-card:hover {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-md);
    text-decoration: none;
    transform: translateY(-2px);
}

.docs-card-icon {
    width: 40px;
    height: 40px;
    margin-bottom: var(--space-3);
    color: var(--color-primary);
}

.docs-card-icon svg {
    width: 100%;
    height: 100%;
}

.docs-card h3 {
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text);
    margin-bottom: var(--space-2);
}

.docs-card p {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    margin: 0;
}

/* Docs Sections */
.docs-section {
    margin-bottom: var(--space-8);
}

.docs-section h2 {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-2);
    border-bottom: 1px solid var(--color-border-light);
}

.docs-section h3 {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-medium);
    margin: var(--space-5) 0 var(--space-3) 0;
}

/* Docs Lists */
.docs-list {
    margin: var(--space-3) 0;
    padding-left: var(--space-6);
}

.docs-list li {
    margin-bottom: var(--space-2);
    line-height: var(--line-height-relaxed);
}

.docs-list.numbered {
    list-style-type: decimal;
}

/* Docs Table */
.docs-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-sm);
    margin: var(--space-4) 0;
}

.docs-table th,
.docs-table td {
    padding: var(--space-3);
    text-align: left;
    border-bottom: 1px solid var(--color-border-light);
}

.docs-table th {
    font-weight: var(--font-weight-semibold);
    color: var(--color-text);
    background: var(--color-bg-secondary);
}

.docs-table tr:hover {
    background: var(--color-bg-tertiary);
}

/* Base Model Tags */
.base-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
}

.base-tag.sd15 {
    background: #e8f5e9;
    color: #2e7d32;
}

.base-tag.sdxl {
    background: #e3f2fd;
    color: #1565c0;
}

.base-tag.illxl {
    background: #fce4ec;
    color: #c2185b;
}

.base-tag.flux {
    background: #fff3e0;
    color: #e65100;
}

/* Docs Filter */
.docs-filter {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
    padding: var(--space-3);
    background: var(--color-bg-secondary);
    border-radius: var(--radius-md);
}

.docs-filter label {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
}

.docs-filter .form-select {
    width: auto;
    min-width: 150px;
}

/* Docs Code */
.docs-code {
    display: block;
    padding: var(--space-4);
    background: #1e1e1e;
    color: #d4d4d4;
    border-radius: var(--radius-md);
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    font-size: var(--font-size-sm);
    overflow-x: auto;
    white-space: pre;
}

/* Docs Tip */
.docs-tip {
    padding: var(--space-3) var(--space-4);
    background: rgba(0, 113, 227, 0.08);
    border-left: 3px solid var(--color-primary);
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    font-size: var(--font-size-sm);
    color: var(--color-text);
    margin: var(--space-4) 0;
}

/* Search Results */
.docs-search-results {
    padding: var(--space-4);
    background: var(--color-bg);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-lg);
}

.docs-search-results.hidden {
    display: none;
}

/* Responsive */
@media (max-width: 768px) {
    .docs-layout {
        grid-template-columns: 1fr;
    }

    .docs-sidebar {
        position: static;
        max-height: none;
        border-bottom: 1px solid var(--color-border-light);
        padding-bottom: var(--space-4);
        margin-bottom: var(--space-4);
    }

    .docs-nav {
        display: flex;
        flex-wrap: wrap;
        gap: var(--space-2);
    }

    .docs-nav-section {
        margin-bottom: 0;
    }

    .docs-nav-title {
        display: none;
    }
}

/* =============================================================================
   Health Page
   ============================================================================= */

.health-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: var(--space-6);
    margin-bottom: var(--space-8);
}

.health-card {
    background: var(--color-bg);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.health-card-header {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--color-border-light);
    background: var(--color-bg-tertiary);
}

.health-card-title {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text);
    margin: 0;
}

.health-card-body {
    padding: var(--space-5);
}

.health-metric {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--color-border-light);
}

.health-metric:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.health-metric:first-child {
    padding-top: 0;
}

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

.health-metric-value {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text);
}

.health-metric-percent {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
    min-width: 40px;
    text-align: right;
}

.health-progress {
    flex: 1;
    height: 8px;
    background: var(--color-bg-secondary);
    border-radius: var(--radius-full);
    margin: 0 var(--space-3);
    overflow: hidden;
}

.health-progress-bar {
    height: 100%;
    background: var(--color-success);
    border-radius: var(--radius-full);
    transition: width var(--transition-normal), background-color var(--transition-normal);
}

.health-status {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.health-status-dot {
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    background: var(--color-text-tertiary);
}

.health-status-dot.online {
    background: var(--color-success);
}

.health-status-dot.offline {
    background: var(--color-error);
}

.health-status-text {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
}

/* Health Section */
.health-section {
    margin-bottom: var(--space-8);
}

/* Health Actions */
.health-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--space-5);
    margin-bottom: var(--space-8);
}

.health-action-card {
    padding: var(--space-5);
    background: var(--color-bg);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-lg);
}

.health-action-title {
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    margin-bottom: var(--space-2);
}

.health-action-description {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    margin-bottom: var(--space-4);
    line-height: var(--line-height-relaxed);
}

/* Health Commands */
.health-commands {
    background: var(--color-bg);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
}

.health-commands-title {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    margin-bottom: var(--space-2);
}

.health-command {
    margin-bottom: var(--space-4);
}

.health-command:last-child {
    margin-bottom: 0;
}

.health-command-label {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    margin-bottom: var(--space-2);
}

.health-command-code {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3);
    background: #1e1e1e;
    border-radius: var(--radius-md);
}

.health-command-code code {
    flex: 1;
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    font-size: var(--font-size-sm);
    color: #d4d4d4;
    overflow-x: auto;
    white-space: nowrap;
}

.health-command-copy {
    flex-shrink: 0;
    padding: var(--space-1) var(--space-3);
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: var(--radius-sm);
    color: #d4d4d4;
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.health-command-copy:hover {
    background: rgba(255, 255, 255, 0.2);
}

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

    .health-actions {
        grid-template-columns: 1fr;
    }

    .health-command-code {
        flex-direction: column;
        align-items: stretch;
    }

    .health-command-code code {
        padding-bottom: var(--space-2);
    }

    .health-command-copy {
        align-self: flex-end;
    }
}

/* =============================================================================
   Health Dashboard - Gauges & Streaming
   ============================================================================= */

/* Live Indicator */
.health-live-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    background: var(--color-bg);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-full);
    font-size: var(--font-size-sm);
}

.health-live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-text-tertiary);
    transition: background var(--transition-fast);
}

.health-live-dot.connecting {
    background: var(--color-warning);
    animation: pulse 1s infinite;
}

.health-live-dot.connected {
    background: var(--color-success);
    animation: pulse 2s infinite;
}

.health-live-dot.disconnected {
    background: var(--color-error);
}

.health-live-dot.polling {
    background: var(--color-primary);
    animation: pulse 3s infinite;
}

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

.health-live-text {
    color: var(--color-text-secondary);
}

/* Dashboard Layout */
.dashboard {
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
}

/* Gauge Row */
.gauge-row {
    display: flex;
    justify-content: center;
    gap: var(--space-8);
    padding: var(--space-6);
    background: var(--color-bg);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-lg);
}

.gauge-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
}

.gauge {
    position: relative;
    width: 120px;
    height: 120px;
}

.gauge svg {
    transform: rotate(-90deg);
    width: 100%;
    height: 100%;
}

.gauge-bg {
    fill: none;
    stroke: var(--color-bg-secondary);
    stroke-width: 8;
}

.gauge-fill {
    fill: none;
    stroke: var(--color-success);
    stroke-width: 8;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.5s ease, stroke 0.3s ease;
}

.gauge-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: baseline;
    gap: 2px;
}

.gauge-value {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-bold);
    color: var(--color-text);
    line-height: 1;
}

.gauge-unit {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

.gauge-label {
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-medium);
    color: var(--color-text);
}

.gauge-sublabel {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

/* Status Row */
.status-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--space-5);
}

.status-card {
    background: var(--color-bg);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.status-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-3) var(--space-4);
    background: var(--color-bg-tertiary);
    border-bottom: 1px solid var(--color-border-light);
}

.status-card-title {
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    margin: 0;
}

.status-card-body {
    padding: var(--space-4);
}

.status-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-2) 0;
}

.status-item:not(:last-child) {
    border-bottom: 1px solid var(--color-border-light);
}

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

.status-item-value {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text);
    text-align: right;
    max-width: 60%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Status Badge */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-full);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    background: var(--color-bg-secondary);
}

.status-badge.online {
    background: rgba(52, 199, 89, 0.15);
    color: #248a3d;
}

.status-badge.offline {
    background: rgba(255, 59, 48, 0.15);
    color: #d70015;
}

.status-badge.loading {
    background: rgba(255, 149, 0, 0.15);
    color: #c93400;
}

.status-badge-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.status-badge.loading .status-badge-dot {
    animation: pulse 1s infinite;
}

/* Actions Row */
.actions-row {
    padding: var(--space-5);
    background: var(--color-bg);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-lg);
}

.actions-row .section-title {
    margin-bottom: var(--space-4);
    font-size: var(--font-size-base);
}

.action-buttons {
    display: flex;
    gap: var(--space-3);
    flex-wrap: wrap;
}

/* Commands Section */
.commands-section {
    background: var(--color-bg);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.commands-summary {
    padding: var(--space-4) var(--space-5);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    user-select: none;
    list-style: none;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.commands-summary::-webkit-details-marker {
    display: none;
}

.commands-summary::before {
    content: '';
    width: 0;
    height: 0;
    border-left: 5px solid var(--color-text-secondary);
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    transition: transform var(--transition-fast);
}

details[open] .commands-summary::before {
    transform: rotate(90deg);
}

.commands-content {
    padding: 0 var(--space-5) var(--space-5);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.command-item {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.command-label {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text);
}

.command-code {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3);
    background: #1e1e1e;
    border-radius: var(--radius-md);
}

.command-code code {
    flex: 1;
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    font-size: var(--font-size-xs);
    color: #d4d4d4;
    overflow-x: auto;
    white-space: nowrap;
}

.command-copy {
    flex-shrink: 0;
    padding: var(--space-1) var(--space-3);
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: var(--radius-sm);
    color: #d4d4d4;
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.command-copy:hover {
    background: rgba(255, 255, 255, 0.2);
}

.command-copy.copied {
    background: var(--color-success);
    color: white;
}

/* Responsive */
@media (max-width: 768px) {
    .gauge-row {
        flex-direction: column;
        align-items: center;
        gap: var(--space-6);
    }

    .status-row {
        grid-template-columns: 1fr;
    }

    .command-code {
        flex-direction: column;
        align-items: stretch;
    }

    .command-code code {
        padding-bottom: var(--space-2);
    }

    .command-copy {
        align-self: flex-end;
    }
}

/* -----------------------------------------------------------------------------
   Keyword Popup
   ----------------------------------------------------------------------------- */
.keyword-popup {
    position: fixed;
    width: 320px;
    max-height: 400px;
    background: #ffffff;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all var(--transition-fast);
    display: flex;
    flex-direction: column;
}

.keyword-popup.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.keyword-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border-light);
}

.keyword-popup-title {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text);
}

.keyword-popup-close {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    font-size: 18px;
    color: var(--color-text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.keyword-popup-close:hover {
    background: var(--color-bg-secondary);
    color: var(--color-text);
}

.keyword-popup-body {
    padding: var(--space-3) var(--space-4);
    overflow-y: auto;
    flex: 1;
}

.keyword-chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.keyword-chip {
    display: inline-flex;
    align-items: center;
    padding: var(--space-1) var(--space-3);
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-full);
    font-size: var(--font-size-xs);
    color: var(--color-text);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.keyword-chip:hover {
    background: var(--color-bg-tertiary);
    border-color: var(--color-border);
}

.keyword-chip.selected {
    background: #0071e3;
    border-color: #0071e3;
    color: #ffffff;
}

.keyword-chip.selected:hover {
    background: #0077ed;
    border-color: #0077ed;
}

.keyword-popup-footer {
    padding: var(--space-2) var(--space-4);
    border-top: 1px solid var(--color-border-light);
    text-align: center;
}

.keyword-popup-settings {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
    text-decoration: none;
}

.keyword-popup-settings:hover {
    color: #0071e3;
}

/* Keyword trigger button */
.keyword-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: var(--color-bg-secondary);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.keyword-trigger:hover {
    background: var(--color-bg-tertiary);
    border-color: var(--color-border);
    color: #0071e3;
}

/* Form label with keyword trigger */
.form-label-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-2);
}

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

.form-label-row .keyword-trigger {
    margin-left: 0;
}


/* -----------------------------------------------------------------------------
   Vault Styles
   ----------------------------------------------------------------------------- */
.vault-state {
    display: flex;
    justify-content: center;
    padding: var(--space-8) var(--space-4);
}

.vault-card {
    background: var(--color-bg);
    border-radius: var(--radius-lg);
    padding: var(--space-8);
    max-width: 480px;
    width: 100%;
    text-align: center;
    box-shadow: var(--shadow-md);
}

.vault-card-sm {
    max-width: 360px;
    padding: var(--space-6);
}

.vault-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    background: var(--color-bg-secondary);
    border-radius: var(--radius-full);
    margin-bottom: var(--space-5);
    color: var(--color-text-secondary);
}

.vault-icon-locked {
    background: #fef3cd;
    color: #856404;
}

.vault-card h2 {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    margin-bottom: var(--space-3);
}

.vault-description {
    color: var(--color-text-secondary);
    margin-bottom: var(--space-5);
    line-height: var(--line-height-relaxed);
}

.vault-warning {
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: var(--radius-md);
    padding: var(--space-4);
    margin-bottom: var(--space-6);
    text-align: left;
    font-size: var(--font-size-sm);
    color: #664d03;
}

.vault-form {
    text-align: left;
}

.vault-form .form-group {
    margin-bottom: var(--space-4);
}

.vault-file-count {
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
    margin-bottom: var(--space-4);
}

.vault-password-prompt {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.vault-item-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    min-height: 180px;
    background: var(--color-bg-secondary);
    color: var(--color-text-tertiary);
    gap: var(--space-2);
}

.vault-item-date {
    font-size: var(--font-size-xs);
}

.vault-item {
    border: 2px dashed var(--color-border-light);
}

.vault-item:hover {
    border-color: var(--color-primary);
}

/* -----------------------------------------------------------------------------
   LoRA Modal Selector
   ----------------------------------------------------------------------------- */
.lora-selector {
    margin-bottom: var(--space-2);
}

.lora-select-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
}

.lora-select-btn-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 var(--space-2);
    background: var(--color-primary);
    color: white;
    border-radius: var(--radius-full);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
}

.lora-modal {
    width: 80%;
    max-width: 1200px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

/* LoRA modal needs higher z-index to appear over other modals */
#loraModal {
    z-index: 1100;
}

.lora-modal-search {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border-light);
}

.lora-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-4);
}

.lora-loading,
.lora-empty {
    text-align: center;
    padding: var(--space-8);
    color: var(--color-text-secondary);
}

.lora-category {
    margin-bottom: var(--space-6);
}

.lora-category:last-child {
    margin-bottom: 0;
}

.lora-category-header {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-secondary);
    margin-bottom: var(--space-3);
    padding-bottom: var(--space-2);
    border-bottom: 1px solid var(--color-border-light);
}

.lora-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--space-2);
}

.lora-card {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-3);
    background: var(--color-bg);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.lora-card:hover {
    border-color: var(--color-primary);
    background: var(--color-bg-secondary);
}

.lora-card.selected {
    border-color: var(--color-primary);
    background: rgba(0, 113, 227, 0.05);
}

.lora-card.incompatible {
    opacity: 0.5;
}

.lora-card.incompatible:hover {
    opacity: 0.7;
}

.lora-card-checkbox {
    flex-shrink: 0;
    padding-top: 2px;
}

.lora-checkbox {
    display: block;
    width: 18px;
    height: 18px;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.lora-checkbox.checked {
    background: var(--color-primary);
    border-color: var(--color-primary);
    position: relative;
}

.lora-checkbox.checked::after {
    content: '';
    position: absolute;
    left: 5px;
    top: 2px;
    width: 4px;
    height: 8px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.lora-card-info {
    flex: 1;
    min-width: 0;
}

.lora-card-title {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lora-card-base {
    font-size: var(--font-size-xs);
    color: var(--color-text-tertiary);
    margin-top: 2px;
}

/* Selected LoRA items with sliders */
.lora-selected-item {
    background: var(--color-bg);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    padding: var(--space-3);
    margin-bottom: var(--space-2);
}

.lora-selected-item.incompatible {
    border-color: var(--color-warning);
    background: rgba(255, 149, 0, 0.05);
}

.lora-selected-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-2);
}

.lora-selected-title {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text);
}

.lora-selected-remove {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    background: none;
    border: none;
    color: var(--color-text-tertiary);
    font-size: 18px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.lora-selected-remove:hover {
    background: var(--color-error);
    color: white;
}

/* ── Health page: two-machine layout ─────────────────── */
.health-machine {
    background: var(--color-bg);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}
.health-machine-offline {
    opacity: 0.55;
}
.health-machine-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3);
}
.health-machine-name {
    display: block;
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--color-text);
}
.health-machine-role {
    display: block;
    font-size: 0.78rem;
    color: var(--color-text-secondary);
    margin-top: 2px;
}
.services-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-2) var(--space-4);
}
.service-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 0.85rem;
    color: var(--color-text-secondary);
}
.service-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--color-text-secondary);
}
.service-dot.up   { background: #34c759; }
.service-dot.down { background: #ff3b30; }

/* =============================================================================
   Dark Mode
   ============================================================================= */

[data-theme="dark"] {
    --color-bg: #1b1c21;
    --color-bg-secondary: #131418;
    --color-bg-tertiary: #26272d;
    --color-text: #e9eaee;
    --color-text-secondary: #9aa0aa;
    --color-text-tertiary: #737984;
    --color-primary: #8b8ffb;
    --color-primary-hover: #9b9efc;
    --color-primary-active: #7c80f9;
    --color-border: #2c2e35;
    --color-border-light: #24262c;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea {
    background: var(--color-bg-tertiary);
    color: var(--color-text);
    border-color: var(--color-border);
}

[data-theme="dark"] input::placeholder,
[data-theme="dark"] textarea::placeholder {
    color: var(--color-text-tertiary);
}

[data-theme="dark"] .btn {
    background: var(--color-bg-tertiary);
    border-color: var(--color-border);
    color: var(--color-text);
}

[data-theme="dark"] .btn:hover {
    background: var(--color-bg-secondary);
}

[data-theme="dark"] .btn-primary {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #14161f;
}

[data-theme="dark"] .output-placeholder {
    background: var(--color-bg-tertiary);
    border-color: var(--color-border);
}

/* Dark mode toggle button */
.dark-mode-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: var(--radius-full);
    background: transparent;
    cursor: pointer;
    color: var(--color-text-secondary);
    transition: color var(--transition-fast), background var(--transition-fast);
    flex-shrink: 0;
}

.dark-mode-toggle:hover {
    background: var(--color-bg-secondary);
    color: var(--color-text);
}

.dark-mode-toggle .icon-sun { display: none; }
.dark-mode-toggle .icon-moon { display: block; }

[data-theme="dark"] .dark-mode-toggle .icon-sun { display: block; }
[data-theme="dark"] .dark-mode-toggle .icon-moon { display: none; }

/* =============================================================================
   Advanced Settings Collapsible
   ============================================================================= */

.advanced-settings {
    margin-bottom: var(--space-4);
}

.advanced-settings[open] .advanced-toggle {
    color: var(--color-primary);
}

.advanced-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-secondary);
    cursor: pointer;
    user-select: none;
    padding: var(--space-2) 0;
    list-style: none;
    transition: color var(--transition-fast);
}

.advanced-toggle::-webkit-details-marker { display: none; }

.advanced-toggle::before {
    content: '';
    display: inline-block;
    width: 0;
    height: 0;
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    border-left: 6px solid currentColor;
    transition: transform var(--transition-fast);
    flex-shrink: 0;
}

.advanced-settings[open] .advanced-toggle::before {
    transform: rotate(90deg);
}

.advanced-content {
    padding-top: var(--space-3);
    border-top: 1px solid var(--color-border-light);
    margin-top: var(--space-2);
}

/* =============================================================================
   Quick Presets
   ============================================================================= */

.presets-section {
    margin-bottom: var(--space-5);
}

.presets-label {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-tertiary);
    margin-bottom: var(--space-2);
}

.preset-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-2);
}

.preset-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-3) var(--space-2);
    background: var(--color-bg);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: inherit;
}

.preset-card:hover {
    border-color: var(--color-primary);
    background: rgba(0, 113, 227, 0.04);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.preset-card.active {
    border-color: var(--color-primary);
    background: rgba(0, 113, 227, 0.08);
}

.preset-icon {
    font-size: 18px;
    line-height: 1;
}

.preset-name {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    color: var(--color-text-secondary);
    white-space: nowrap;
}

/* =============================================================================
   Model Card Picker
   ============================================================================= */

.model-picker {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.model-search {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-size-sm);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-bg);
    color: var(--color-text);
    outline: none;
    transition: border-color var(--transition-fast);
}

.model-search:focus {
    border-color: var(--color-primary);
}

.model-search::placeholder {
    color: var(--color-text-tertiary);
}

.model-card-list {
    max-height: 260px;
    overflow-y: auto;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-bg);
    scroll-behavior: smooth;
}

.model-card-list::-webkit-scrollbar {
    width: 4px;
}

.model-card-list::-webkit-scrollbar-track {
    background: transparent;
}

.model-card-list::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 2px;
}

.model-group-label {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-tertiary);
    padding: var(--space-2) var(--space-3) var(--space-1);
    position: sticky;
    top: 0;
    background: var(--color-bg-secondary);
    border-bottom: 1px solid var(--color-border-light);
    z-index: 1;
}

.model-card-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    padding: 7px var(--space-3);
    cursor: pointer;
    transition: background var(--transition-fast);
    border-left: 3px solid transparent;
    user-select: none;
}

.model-card-item:hover {
    background: var(--color-bg-secondary);
}

.model-card-item.selected {
    background: rgba(0, 113, 227, 0.07);
    border-left-color: var(--color-primary);
}

.model-card-name {
    font-size: var(--font-size-sm);
    color: var(--color-text);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.model-card-item.selected .model-card-name {
    font-weight: var(--font-weight-medium);
    color: var(--color-primary);
}

.model-card-tag {
    font-size: 10px;
    font-weight: var(--font-weight-semibold);
    padding: 2px 6px;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    flex-shrink: 0;
}

.model-card-tag--photo   { background: #dbeafe; color: #1e40af; }
.model-card-tag--anime   { background: #fce7f3; color: #9d174d; }
.model-card-tag--art     { background: #ede9fe; color: #6b21a8; }
.model-card-tag--pony    { background: #ffedd5; color: #c2410c; }
.model-card-tag--horror  { background: #f0fdf4; color: #166534; }
.model-card-tag--inpaint { background: #f0f9ff; color: #0369a1; }

[data-theme="dark"] .model-card-tag--photo   { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .model-card-tag--anime   { background: #4a1530; color: #f9a8d4; }
[data-theme="dark"] .model-card-tag--art     { background: #2e1a54; color: #c4b5fd; }
[data-theme="dark"] .model-card-tag--pony    { background: #431407; color: #fed7aa; }
[data-theme="dark"] .model-card-tag--horror  { background: #052e16; color: #86efac; }
[data-theme="dark"] .model-card-tag--inpaint { background: #0c2a3e; color: #7dd3fc; }

.model-group.hidden { display: none; }
.model-card-item.hidden { display: none; }

/* =============================================================================
   Prompt Library Modal
   ============================================================================= */

.btn-link {
    background: none;
    border: none;
    padding: 0;
    font-size: var(--font-size-sm);
    color: var(--color-primary);
    cursor: pointer;
    font-family: inherit;
    transition: opacity var(--transition-fast);
}
.btn-link:hover { opacity: 0.75; text-decoration: none; }

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    backdrop-filter: blur(4px);
}

.modal-overlay.hidden { display: none; }

.modal-panel {
    background: var(--color-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 640px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-panel--sm { max-width: 440px; }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-5) var(--space-6);
    border-bottom: 1px solid var(--color-border-light);
    flex-shrink: 0;
}

.modal-title {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text);
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    line-height: 1;
    color: var(--color-text-tertiary);
    cursor: pointer;
    padding: 0 var(--space-1);
    transition: color var(--transition-fast);
}
.modal-close:hover { color: var(--color-text); }

.modal-toolbar {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-6);
    border-bottom: 1px solid var(--color-border-light);
    flex-shrink: 0;
}

.modal-search {
    flex: 1;
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-size-sm);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-bg-secondary);
    color: var(--color-text);
    outline: none;
    font-family: inherit;
}
.modal-search:focus { border-color: var(--color-primary); }
.modal-search::placeholder { color: var(--color-text-tertiary); }

.library-list {
    overflow-y: auto;
    flex: 1;
    padding: var(--space-3) var(--space-4);
}

.library-empty {
    text-align: center;
    color: var(--color-text-tertiary);
    padding: var(--space-10);
    font-size: var(--font-size-sm);
}

.library-category {
    margin-bottom: var(--space-4);
}

.library-category-label {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-tertiary);
    padding: var(--space-1) var(--space-2);
    margin-bottom: var(--space-2);
}

.library-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-3);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition-fast);
    border: 1px solid transparent;
}

.library-item:hover {
    background: var(--color-bg-secondary);
    border-color: var(--color-border-light);
}

.library-item-text { flex: 1; min-width: 0; }

.library-item-name {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-text);
    margin-bottom: 2px;
}

.library-item-preview {
    font-size: var(--font-size-xs);
    color: var(--color-text-tertiary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 460px;
}

.library-item-actions {
    display: flex;
    gap: var(--space-2);
    opacity: 0;
    transition: opacity var(--transition-fast);
    flex-shrink: 0;
}

.library-item:hover .library-item-actions { opacity: 1; }

.library-action-btn {
    background: none;
    border: none;
    padding: var(--space-1) var(--space-2);
    font-size: var(--font-size-xs);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition-fast);
    color: var(--color-text-secondary);
    font-family: inherit;
}
.library-action-btn:hover { background: var(--color-border-light); }
.library-action-btn.delete:hover { background: #fee2e2; color: var(--color-error); }

.save-preview {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
    background: var(--color-bg-secondary);
    border-radius: var(--radius-sm);
    padding: var(--space-2) var(--space-3);
    max-height: 72px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    word-break: break-word;
}

[data-theme="dark"] .modal-overlay { background: rgba(0,0,0,0.65); }
[data-theme="dark"] .library-action-btn.delete:hover { background: #3b1111; }

/* =============================================================================
   2026 refresh — studio components
   (recipe strip, session filmstrip, stage, gallery toolbar, quality floor)
   ============================================================================= */

/* Recipe strip: every image ships with its settings, set in mono. */
.recipe-strip {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px 10px;
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
    padding: var(--space-2) var(--space-3);
    background: var(--color-bg-secondary);
    border-radius: var(--radius-sm);
    min-width: 0;
}

.recipe-strip .sep { color: var(--color-border); }

.recipe-strip .r-prompt {
    flex-basis: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--color-text);
}

/* Stage: where the generated image lives on Create/Transform/etc. */
.stage {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    min-height: 0;
}

.stage-well {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg-secondary);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    min-height: 320px;
}

/* Session filmstrip: everything generated this session, newest first. */
.filmstrip {
    display: flex;
    gap: var(--space-2);
    overflow-x: auto;
    padding: 2px;
    scrollbar-width: thin;
}

.filmstrip:empty { display: none; }

.filmstrip-item {
    flex-shrink: 0;
    width: 64px;
    height: 64px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    padding: 0;
    background: var(--color-bg-tertiary);
}

.filmstrip-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.filmstrip-item.active {
    border-color: var(--color-primary);
}

/* Gallery toolbar: search + filters left, actions right. */
.g-toolbar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
    margin-bottom: var(--space-5);
}

.g-search {
    flex: 1 1 220px;
    max-width: 360px;
    padding: 8px 14px;
    font-size: var(--font-size-sm);
    font-family: var(--font-family);
    color: var(--color-text);
    background: var(--color-bg-secondary);
    border: 1px solid transparent;
    border-radius: var(--radius-full);
    transition: all var(--transition-fast);
}

.g-search:focus {
    outline: none;
    background: var(--color-bg);
    border-color: var(--color-primary);
}

.g-filter {
    padding: 8px 32px 8px 14px;
    font-size: var(--font-size-sm);
    font-family: var(--font-family);
    color: var(--color-text);
    background: var(--color-bg-secondary);
    border: 1px solid transparent;
    border-radius: var(--radius-full);
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='%23888890'%3E%3Cpath d='M2 4l4 4 4-4z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 10px 10px;
    cursor: pointer;
}

.g-count {
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    color: var(--color-text-tertiary);
    white-space: nowrap;
}

/* Overflow menu (⋯) — destructive actions live here, not in the toolbar. */
.menu-wrap { position: relative; }

.menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    background: var(--color-bg);
    color: var(--color-text-secondary);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    transition: all var(--transition-fast);
}

.menu-btn:hover {
    color: var(--color-text);
    background: var(--color-bg-secondary);
}

.menu-pop {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    min-width: 180px;
    background: var(--color-bg);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 6px;
    z-index: 300;
    display: none;
}

.menu-pop.open { display: block; }

.menu-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px 10px;
    font-size: var(--font-size-sm);
    font-family: var(--font-family);
    color: var(--color-text);
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.menu-item:hover { background: var(--color-bg-secondary); }

.menu-item.danger { color: var(--color-error); }

.menu-item.danger:hover { background: rgba(214, 69, 69, 0.08); }

/* Lightbox: full-size view on top of everything, click anywhere to close. */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 1200;
    background: rgba(8, 8, 10, 0.92);
    display: none;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
    padding: var(--space-4);
}

.lightbox.open { display: flex; }

.lightbox img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Infinite-scroll sentinel + load state */
.g-sentinel {
    height: 1px;
}

.g-loading-more {
    display: flex;
    justify-content: center;
    padding: var(--space-6);
}

/* Quality floor */
:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

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


/* =============================================================================
   Density pass — compact admin-panel spacing (fonts stay comfortable,
   the padding does the shrinking)
   ============================================================================= */
.main-content {
    max-width: 1500px;
    margin: 0;
    padding: var(--space-5);
    flex: 1;
    min-width: 0;
}

.page-header { margin-bottom: var(--space-4); }

.page-title { font-size: var(--font-size-lg); }

.sidebar-panel,
.output-panel {
    padding: var(--space-4);
    border: 1px solid var(--color-border);
    box-shadow: none;
    border-radius: var(--radius-md);
}

.output-panel { min-height: 380px; }

.btn {
    padding: 7px 14px;
    font-size: var(--font-size-sm);
    border-radius: var(--radius-sm);
}

.btn-sm { padding: 4px 10px; font-size: var(--font-size-xs); }
.btn-lg { padding: 10px 16px; font-size: var(--font-size-base); }

.form-group { margin-bottom: var(--space-3); }

.form-label { font-size: var(--font-size-xs); margin-bottom: 4px; }

.form-input, .form-select, .form-textarea, .form-number {
    padding: 7px 10px;
    font-size: var(--font-size-sm);
    border-radius: var(--radius-sm);
}

.presets-section { margin-bottom: var(--space-3); }

.preset-card {
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-xs);
}

.advanced-settings { margin-bottom: var(--space-3); }

.requirements-checklist {
    padding: var(--space-2) var(--space-3);
    margin-bottom: var(--space-3);
}

.stage-well { min-height: 260px; padding: var(--space-3); }

/* Create controls: pinned on desktop; compact enough not to need scrolling,
   with internal scroll as the fallback rather than the design */
@media (min-width: 1025px) {
    .page-layout .sidebar-panel {
        position: sticky;
        top: calc(48px + var(--space-4));
        align-self: start;
        max-height: calc(100vh - 48px - var(--space-6));
        overflow-y: auto;
    }
    .output-panel {
        top: calc(48px + var(--space-4));
        max-height: calc(100vh - 48px - var(--space-6));
    }
}

/* Model modal: give the list room to breathe inside the panel */
.model-card-list--modal {
    max-height: min(55vh, 480px);
    border: none;
    border-top: 1px solid var(--color-border-light);
    border-radius: 0;
}

.form-textarea { padding: 8px 10px; font-size: var(--font-size-sm); }

/* Create column: tighter vertical rhythm so the whole stack fits unscrolled */
.sidebar-panel .form-group { margin-bottom: var(--space-2); }
.sidebar-panel .advanced-settings { margin-bottom: var(--space-2); }
.sidebar-panel .form-label-row { margin-bottom: 2px; }
.sidebar-panel .model-status-row { margin-top: 4px !important; }
.sidebar-panel .requirements-checklist { margin: var(--space-2) 0; }

.sidebar-panel .advanced-toggle { padding: 4px 0; }


/* Prompt modals: textarea left, keyword examples right */
.modal-panel--wide { max-width: 720px; width: 92vw; }

.prompt-modal-layout {
    display: flex;
    gap: var(--space-4);
    align-items: stretch;
}

.prompt-modal-left {
    flex: 1.2;
    display: flex;
}

.prompt-modal-left .form-textarea {
    flex: 1;
    min-height: 280px;
    resize: none;
}

.prompt-modal-right {
    flex: 1;
    max-height: 280px;
    overflow-y: auto;
    border-left: 1px solid var(--color-border-light);
    padding-left: var(--space-4);
}

.prompt-examples-title {
    font-size: 11px;
    font-weight: var(--font-weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-tertiary);
    margin-bottom: var(--space-2);
}

.prompt-btn {
    justify-content: flex-start;
    text-align: left;
    font-weight: var(--font-weight-regular);
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

@media (max-width: 640px) {
    .prompt-modal-layout { flex-direction: column; }
    .prompt-modal-right {
        border-left: none;
        padding-left: 0;
        border-top: 1px solid var(--color-border-light);
        padding-top: var(--space-3);
        max-height: 180px;
    }
    .prompt-modal-left .form-textarea { min-height: 160px; }
}

/* Hi-res fix toggle row: label left, switch right */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
}
.toggle-row .form-label { display: flex; align-items: center; gap: 4px; }

/* Recommended model marker in the picker */
.rec-star { color: var(--color-warning); font-size: 12px; line-height: 1; }
.model-card-item--rec .model-card-name { font-weight: var(--font-weight-medium); }
