* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg: #ffffff;
    --bg-soft: #fafafa;
    --surface: #ffffff;
    --surface-2: #f5f5f5;
    --border: #e5e5e5;
    --border-hover: #d4d4d4;
    --text: #171717;
    --text-secondary: #525252;
    --text-muted: #a3a3a3;
    --accent: #7C3AED;
    --accent-hover: #6D28D9;
    --gradient: linear-gradient(135deg, #facc15, #ec4899, #8b5cf6);
    --gradient-subtle: linear-gradient(135deg, rgba(250,204,21,0.1), rgba(236,72,153,0.1), rgba(139,92,246,0.1));
    --success: #16a34a;
    --success-bg: rgba(22, 163, 74, 0.08);
    --error: #dc2626;
    --error-bg: rgba(220, 38, 38, 0.08);
    --radius: 16px;
    --radius-sm: 10px;
    --radius-xs: 6px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.04), 0 2px 4px rgba(0,0,0,0.03);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-soft);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ─── Nav ─── */
.nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 32px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
    background: rgba(255,255,255,0.85);
}
.nav-brand {
    font-size: 17px;
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
    letter-spacing: -0.3px;
}
.nav-links { display: flex; gap: 4px; align-items: center; }
.nav-links a, .nav-links .nav-dropdown-trigger {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    padding: 6px 14px;
    border-radius: var(--radius-xs);
    transition: all 0.15s;
    cursor: pointer;
}
.nav-links a:hover, .nav-links .nav-dropdown-trigger:hover { color: var(--text); background: var(--surface-2); }
.nav-links a.active { color: var(--text); background: var(--surface-2); }

/* ─── Nav Dropdown ─── */
.nav-dropdown {
    position: relative;
}
.nav-dropdown-trigger {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    user-select: none;
}
.nav-dropdown-trigger .chevron {
    font-size: 10px;
    transition: transform 0.15s;
}
.nav-dropdown:hover .chevron { transform: rotate(180deg); }
.nav-dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    min-width: 180px;
    padding: 4px;
    margin-top: 4px;
    z-index: 200;
}
/* Invisible bridge so the cursor doesn't fall into a gap between trigger and menu */
.nav-dropdown-menu::before {
    content: "";
    position: absolute;
    top: -8px;
    left: 0;
    right: 0;
    height: 8px;
}
.nav-dropdown:hover .nav-dropdown-menu,
.nav-dropdown:focus-within .nav-dropdown-menu { display: block; }
.nav-dropdown-menu a {
    display: block;
    padding: 8px 14px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    border-radius: var(--radius-xs);
    transition: all 0.15s;
}
.nav-dropdown-menu a:hover { color: var(--text); background: var(--surface-2); }
.nav-dropdown-menu a.active { color: var(--text); background: var(--surface-2); }
.nav-dropdown-trigger.has-active { color: var(--text); background: var(--surface-2); }

/* ─── Container ─── */
.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 40px 24px;
}

/* ─── Page header ─── */
.page-header {
    margin-bottom: 36px;
}
.page-header h1 {
    font-size: 30px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.5px;
    margin-bottom: 6px;
}
.page-header p {
    color: var(--text-muted);
    font-size: 15px;
    font-weight: 400;
}

/* ─── Cards ─── */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    transition: all 0.2s;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    display: block;
    box-shadow: var(--shadow-sm);
}
.card:hover {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}
.card h3 {
    font-size: 17px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 10px;
    text-transform: capitalize;
    letter-spacing: -0.2px;
}
.card-meta {
    display: flex;
    gap: 16px;
    font-size: 13px;
    color: var(--text-muted);
    flex-wrap: wrap;
}
.card-meta span { display: flex; align-items: center; gap: 4px; }

/* ─── Buttons ─── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    letter-spacing: -0.1px;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary {
    background: var(--gradient);
    color: #fff;
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.25);
}
.btn-primary:hover {
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.35);
}
.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.btn-secondary:hover {
    background: var(--surface-2);
    border-color: var(--border-hover);
}
.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

/* ─── Forms ─── */
input, textarea, select {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    width: 100%;
    transition: border-color 0.15s;
}
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.08);
}
textarea { resize: vertical; min-height: 120px; }
label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    font-weight: 600;
    letter-spacing: -0.1px;
}
.form-group { margin-bottom: 20px; }

/* ─── Control row (aligned form controls in a horizontal strip) ─── */
.control-row {
    display: flex;
    gap: 20px;
    align-items: flex-end;
    flex-wrap: wrap;
}
.control-row .control-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.control-row .control-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

/* ─── Backend toggle (Higgsfield / Direct API) ─── */
.backend-toggle {
    display: inline-flex;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.backend-toggle button {
    padding: 10px 20px;
    font-size: 14px;
    font-family: inherit;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
    background: var(--surface);
    color: var(--text-muted);
    -webkit-appearance: none;
    appearance: none;
    line-height: 1.2;
}
.backend-toggle button + button {
    border-left: 1px solid var(--border);
}
.backend-toggle button.active-hf {
    background: #caf61a;
    color: #1a1a1a;
}
.backend-toggle button.active-api {
    background: var(--text);
    color: white;
}

.btn-hf {
    background: #caf61a !important;
    color: #1a1a1a !important;
    font-weight: 600;
}

/* ─── Drop zone ─── */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 48px 24px;
    text-align: center;
    color: var(--text-muted);
    transition: all 0.2s;
    cursor: pointer;
    background: var(--surface);
}
.drop-zone:hover, .drop-zone.drag-over {
    border-color: var(--accent);
    background: rgba(124, 58, 237, 0.03);
}
.drop-zone p { margin-bottom: 8px; font-weight: 500; }
.drop-zone .hint { font-size: 13px; font-weight: 400; }
.drop-zone-sm { padding: 20px 16px; }
.drop-zone-sm p { margin-bottom: 0; font-size: 13px; }

/* ─── Character reference grid ─── */
.char-ref-grid {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.char-ref-thumb {
    width: 72px;
    height: 72px;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid var(--border);
    transition: border-color 0.2s;
}
.char-ref-thumb:hover {
    border-color: var(--accent);
}
.char-ref-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ─── Template grid ─── */
.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 14px;
}
.template-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    box-shadow: var(--shadow-sm);
}
.template-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}
.template-card.selected {
    border-color: var(--accent);
    border-width: 2px;
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1);
}
.template-card img {
    width: 100%;
    aspect-ratio: 1/1;
    object-fit: cover;
}
.template-card .template-label {
    padding: 10px 12px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: capitalize;
}
.template-card .check {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    box-shadow: 0 2px 4px rgba(124, 58, 237, 0.3);
}
.template-card.selected .check { display: flex; }

/* ─── Image grid (gallery) ─── */
.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
}
.image-card {
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
    transition: all 0.2s;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
}
.image-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}
.image-card img {
    width: 100%;
    height: auto;
    display: block;
}

/* ─── Progress ─── */
.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--surface-2);
    border-radius: 3px;
    overflow: hidden;
    margin: 12px 0;
}
.progress-fill {
    height: 100%;
    background: var(--gradient);
    border-radius: 3px;
    transition: width 0.3s ease;
}
.progress-text {
    font-size: 13px;
    color: var(--text-muted);
}

/* ─── Section ─── */
.section {
    margin-bottom: 40px;
}
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.section-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.2px;
}

/* ─── Tabs ─── */
.tabs {
    display: flex;
    gap: 4px;
    background: var(--surface-2);
    padding: 4px;
    border-radius: var(--radius-sm);
    margin-bottom: 28px;
    width: fit-content;
}
.tab {
    padding: 8px 18px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-xs);
    transition: all 0.15s;
    background: none;
    border: none;
}
.tab:hover { color: var(--text-secondary); }
.tab.active {
    color: var(--text);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

/* ─── Badge ─── */
.badge {
    display: inline-flex;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.2px;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-error { background: var(--error-bg); color: var(--error); }
.badge-warning { background: rgba(234, 179, 8, 0.12); color: #b45309; }
.badge-pending { background: rgba(124, 58, 237, 0.08); color: var(--accent); }

/* ─── Toast ─── */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 20px;
    font-size: 14px;
    z-index: 1000;
    box-shadow: var(--shadow-md);
    animation: slideIn 0.3s ease;
}
@keyframes slideIn {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ─── Lightbox ─── */
.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    cursor: pointer;
}
.lightbox img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

/* ─── Utility ─── */
.flex { display: flex; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }
.gap-24 { gap: 24px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 13px; }
.hidden { display: none !important; }

/* ─── Activity tray (global) ─── */
.activity-tray-wrap {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9000;
    font-family: inherit;
}
.activity-fab {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all 0.15s;
}
.activity-fab:hover {
    transform: translateY(-1px);
    border-color: var(--border-hover);
    box-shadow: 0 6px 16px rgba(0,0,0,0.10);
}
.activity-fab.has-active {
    background: var(--gradient);
    color: #fff;
    border-color: transparent;
    box-shadow: 0 6px 18px rgba(139, 92, 246, 0.35);
}
.activity-fab-icon { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; }
.activity-fab-spinner {
    width: 14px; height: 14px;
    border: 2px solid rgba(255,255,255,0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
.activity-panel {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 360px;
    max-height: 70vh;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 12px 40px rgba(0,0,0,0.16);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.activity-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    font-size: 14px;
}
.activity-panel-header strong { font-weight: 600; }
.activity-panel-body {
    overflow-y: auto;
    padding: 8px;
    flex: 1;
}
.activity-empty {
    padding: 24px 12px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}
.activity-item {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    margin-bottom: 6px;
    background: var(--surface);
    transition: background 0.15s;
}
.activity-item.status-running { background: rgba(124, 58, 237, 0.04); }
.activity-item.status-done { background: rgba(22, 163, 74, 0.04); }
.activity-item.status-failed { background: rgba(220, 38, 38, 0.04); }
.activity-item-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.activity-status-dot {
    flex: 0 0 22px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    background: var(--surface-2);
    color: var(--text-muted);
}
.activity-status-dot.status-running { background: rgba(124, 58, 237, 0.10); color: var(--accent); }
.activity-status-dot.status-done    { background: var(--success-bg); color: var(--success); }
.activity-status-dot.status-failed  { background: var(--error-bg); color: var(--error); }
.activity-spinner {
    width: 12px; height: 12px;
    border: 2px solid rgba(124,58,237,0.25);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
.activity-item-text { flex: 1; min-width: 0; }
.activity-item-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.activity-item-meta {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: capitalize;
    margin-top: 2px;
}
.activity-progress {
    height: 3px;
    background: var(--surface-2);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 8px;
}
.activity-progress-fill {
    height: 100%;
    background: var(--gradient);
    transition: width 0.3s ease;
}
.activity-thumbs {
    display: flex;
    gap: 4px;
    margin-top: 8px;
    flex-wrap: wrap;
}
.activity-thumbs img {
    width: 56px;
    height: 56px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border);
    display: block;
}
.btn-link {
    background: none;
    border: none;
    color: var(--accent);
    text-decoration: none;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    padding: 2px 6px;
}
.btn-link:hover { text-decoration: underline; }

/* ─── Spinner ─── */
.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ─── Image upload preview grid ─── */
.image-preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 8px;
    margin-top: 12px;
}
.image-preview {
    position: relative;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border);
}
.image-preview img {
    width: 100%;
    aspect-ratio: 1/1;
    object-fit: cover;
    display: block;
}
.image-preview .delete-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(0,0,0,0.6);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s;
}
.image-preview:hover .delete-btn,
.image-preview:hover .rembg-btn { opacity: 1; }
.rembg-btn {
    position: absolute;
    bottom: 4px;
    left: 4px;
    padding: 3px 8px;
    border-radius: 4px;
    background: rgba(124, 58, 237, 0.85);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 10px;
    font-weight: 600;
    opacity: 0;
    transition: opacity 0.15s;
    white-space: nowrap;
}
.rembg-btn:hover { background: var(--accent); }

/* ─── Analysis cards (clone) ─── */
.analysis-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-bottom: 12px;
}
.analysis-card h4 {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 600;
    margin-bottom: 6px;
}
.analysis-card p {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-secondary);
}

/* ─── Details/accordion ─── */
details {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin-bottom: 8px;
}
details summary {
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    list-style: none;
}
details summary::-webkit-details-marker { display: none; }
details pre {
    margin-top: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    padding: 14px;
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 200px;
    overflow-y: auto;
}

/* ─── Gradient text ─── */
.gradient-text {
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ─── Card variants ─── */
.card-static {
    cursor: default;
}
.card-static:hover {
    border-color: var(--border);
    box-shadow: var(--shadow-sm);
    transform: none;
}
.card-sm {
    padding: 16px;
}
.card-accent-left {
    border-left: 3px solid var(--accent);
}
.card-status-success { border-left: 3px solid var(--success); }
.card-status-active { border-left: 3px solid var(--accent); }
.card-status-failed { border-left: 3px solid var(--error); }
.card-title {
    font-size: 18px;
    font-weight: 700;
}

/* ─── Review layout (sidebar + main) ─── */
.review-layout {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 24px;
}

/* ─── Analysis grid ─── */
.analysis-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* ─── Scene / item list ─── */
.scene-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.scene-list-compact {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ─── Field label (reusable outside control-row) ─── */
.field-label {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 600;
    display: block;
    margin-bottom: 2px;
}

/* ─── Category heading ─── */
.category-heading {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

/* ─── Badge variants ─── */
.badge-accent { background: var(--accent); color: white; }

/* ─── Spinner sizes ─── */
.spinner-sm { width: 14px; height: 14px; }
.spinner-lg { width: 40px; height: 40px; }

/* ─── Control-row: auto-width selects ─── */
.control-row select {
    width: auto;
}

/* ─── Additional utilities ─── */
.mb-0 { margin-bottom: 0; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-24 { margin-bottom: 24px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-20 { margin-top: 20px; }
.w-auto { width: auto; }
.flex-col { display: flex; flex-direction: column; }
.flex-1 { flex: 1; }
.text-xs { font-size: 12px; }
.text-error { color: var(--error); }
.text-center { text-align: center; }
.flex-wrap { flex-wrap: wrap; }
.uppercase { text-transform: uppercase; }

/* ─── Worker status indicator ─── */
.worker-wrap {
    position: relative;
}
.worker-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.worker-pill:hover {
    border-color: var(--border-hover);
    background: var(--surface-2);
}
.worker-pill-active {
    background: #caf61a;
    color: #1a1a1a;
    border-color: #b8e016;
}
.worker-pill-active:hover {
    background: #b8e016;
    border-color: #a6c914;
}
.worker-pill-busy {
    cursor: default;
    background: rgba(124, 58, 237, 0.08);
    color: var(--accent);
    border-color: rgba(124, 58, 237, 0.2);
}
.worker-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #1a1a1a;
    animation: pulse 2s infinite;
}
.worker-tooltip {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    width: 320px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    padding: 12px 14px;
    z-index: 200;
}
.worker-tooltip::before {
    content: "";
    position: absolute;
    top: -8px;
    left: 0;
    right: 0;
    height: 8px;
}
.worker-tooltip p {
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-secondary);
    margin: 0;
}
.worker-tooltip strong {
    color: var(--text);
}
.worker-tooltip p + .worker-tooltip-detail {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}
.worker-tooltip-detail {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
}
.worker-tooltip-detail + .worker-tooltip-detail {
    margin-top: 8px;
}
.worker-wrap:hover .worker-tooltip {
    display: block;
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
    .container {
        padding: 24px 16px;
    }
    .page-header h1 {
        font-size: 24px;
    }
    .control-row {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }
    .control-row .control-group {
        width: 100%;
    }
    .control-row select {
        width: 100%;
    }
    .review-layout {
        grid-template-columns: 1fr;
    }
    .analysis-grid {
        grid-template-columns: 1fr;
    }
    .template-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }
    .image-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    }
    .tabs {
        width: 100%;
        overflow-x: auto;
    }
    .nav-links {
        gap: 2px;
    }
    .nav-links a, .nav-links .nav-dropdown-trigger {
        padding: 6px 8px;
        font-size: 13px;
    }
}

@media (max-width: 480px) {
    input, select, textarea {
        font-size: 16px;
    }
}

/* ═══════════════════════════════════════════════════════════
   Only Bean Ad Studio — theme override + new components
   ═══════════════════════════════════════════════════════════ */

:root {
    /* The Only Bean: minimalist black/white with edamame green accent */
    --accent: #3d7a3d;
    --accent-hover: #2f6130;
    --gradient: linear-gradient(135deg, #a8d977, #3d7a3d, #1f3d1f);
    --gradient-subtle: linear-gradient(135deg, rgba(168,217,119,0.12), rgba(61,122,61,0.08));
}

[x-cloak] { display: none !important; }

.nav-brand-sub { color: var(--text-muted); font-weight: 400; font-size: 13px; margin-left: 4px; }

/* ─── Nav user menu ─── */
.nav-user { position: relative; }
.nav-user-btn {
    display: flex; align-items: center; gap: 8px;
    background: none; border: 1px solid var(--border); border-radius: 999px;
    padding: 4px 12px 4px 4px; cursor: pointer; font-size: 13px; color: var(--text);
}
.nav-user-btn:hover { border-color: var(--border-hover); background: var(--surface-2); }
.nav-user-avatar {
    width: 26px; height: 26px; border-radius: 50%;
    background: var(--accent); color: #fff; font-weight: 600; font-size: 12px;
    display: flex; align-items: center; justify-content: center;
}
.nav-user-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-user-menu {
    position: absolute; right: 0; top: calc(100% + 8px); z-index: 60;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md); min-width: 180px; overflow: hidden; padding: 4px;
}
.nav-user-menu a, .nav-user-menu button {
    display: block; width: 100%; text-align: left; padding: 8px 12px;
    font-size: 13px; color: var(--text); text-decoration: none;
    background: none; border: none; cursor: pointer; border-radius: var(--radius-xs);
}
.nav-user-menu a:hover, .nav-user-menu button:hover { background: var(--surface-2); }

/* ─── Auth pages ─── */
.auth-wrap { display: flex; justify-content: center; padding: 60px 16px; }
.auth-card {
    width: 100%; max-width: 400px; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius);
    padding: 32px; box-shadow: var(--shadow);
}
.auth-logo { font-size: 40px; text-align: center; margin-bottom: 8px; }
.auth-title { font-size: 22px; text-align: center; margin-bottom: 4px; }
.auth-sub { text-align: center; color: var(--text-secondary); font-size: 14px; margin-bottom: 24px; }
.auth-field { margin-bottom: 16px; }
.auth-field label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.auth-field input {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border);
    border-radius: var(--radius-xs); font-size: 14px; background: var(--surface);
}
.auth-field input:focus { outline: none; border-color: var(--accent); }
.auth-hint { color: var(--text-muted); font-weight: 400; font-size: 12px; }
.auth-error { color: var(--error); background: var(--error-bg); border-radius: var(--radius-xs); padding: 10px 12px; font-size: 13px; margin: 12px 0; }
.auth-success { color: var(--success); background: var(--success-bg); border-radius: var(--radius-xs); padding: 10px 12px; font-size: 13px; margin: 12px 0; }
.auth-alt { text-align: center; font-size: 13px; color: var(--text-secondary); margin-top: 20px; }
.auth-alt a { color: var(--accent); }
.btn-block { width: 100%; justify-content: center; }
.btn-danger-ghost { color: var(--error); border-color: rgba(220,38,38,0.3); }
.btn-danger-ghost:hover { background: var(--error-bg); }

/* ─── Generic page helpers ─── */
.page-narrow { max-width: 760px; margin: 0 auto; }
.page-narrow h1 { margin-bottom: 20px; }
.section-hint { color: var(--text-secondary); font-size: 13px; margin-bottom: 16px; line-height: 1.6; }
.section-title { font-size: 18px; margin: 28px 0 14px; }
.welcome-banner { border-left: 3px solid var(--accent); margin-bottom: 20px; }
.welcome-banner p { color: var(--text-secondary); font-size: 14px; margin-top: 6px; }
.welcome-banner a { color: var(--accent); }
.card-static + .card-static, .page-narrow section + section { margin-top: 20px; }
.card-static h2 { font-size: 17px; margin-bottom: 10px; }

/* ─── Settings: API keys ─── */
.key-row {
    display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
    padding: 14px 0; border-bottom: 1px solid var(--border);
}
.key-row:last-of-type { border-bottom: none; }
.key-info { flex: 1; min-width: 180px; }
.key-name { font-weight: 600; font-size: 14px; }
.key-desc { color: var(--text-secondary); font-size: 12px; margin-top: 2px; }
.key-badge {
    display: inline-flex; align-items: center; gap: 4px;
    font-size: 12px; padding: 3px 10px; border-radius: 999px;
    background: var(--surface-2); color: var(--text-secondary);
}
.key-badge-set { background: var(--success-bg); color: var(--success); }
.key-badge-danger { background: var(--error-bg); color: var(--error); }
.key-input { padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius-xs); font-size: 13px; width: 220px; }
.key-help { margin-top: 18px; font-size: 13px; color: var(--text-secondary); }
.key-help ul { margin: 8px 0 0 18px; line-height: 1.9; }
.key-help a { color: var(--accent); }

/* ─── Admin ─── */
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th {
    text-align: left; padding: 8px 10px; color: var(--text-muted);
    font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px;
    border-bottom: 1px solid var(--border);
}
.admin-table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-td-muted { color: var(--text-muted); }
.admin-td-actions { text-align: right; white-space: nowrap; }
.admin-td-actions .btn + .btn { margin-left: 6px; }
.row-inactive td { opacity: 0.5; }
.invite-fresh {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    background: var(--success-bg); border-radius: var(--radius-sm);
    padding: 12px 16px; margin-bottom: 16px; font-size: 13px;
}
.invite-link { color: var(--text-secondary); font-size: 12px; margin-top: 4px; word-break: break-all; }

/* ─── Dashboard ─── */
.dash-hero { margin: 12px 0 28px; }
.dash-hero h1 { font-size: 28px; }
.dash-sub { color: var(--text-secondary); margin-top: 4px; }
.dash-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 28px; }
.dash-card {
    display: block; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px; text-decoration: none; color: var(--text);
    transition: border-color 0.15s ease, transform 0.15s ease;
}
.dash-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.dash-card-icon { font-size: 26px; margin-bottom: 10px; }
.dash-card-title { font-weight: 600; font-size: 15px; margin-bottom: 4px; }
.dash-card-desc { color: var(--text-secondary); font-size: 12.5px; line-height: 1.5; }
.dash-recent { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; }
.dash-thumb { display: block; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--border); }
.dash-thumb img { width: 100%; aspect-ratio: 1/1; object-fit: cover; display: block; }

/* ─── Gallery ─── */
.gallery-tabs { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 1px solid var(--border); }
.gallery-tabs button {
    background: none; border: none; padding: 10px 16px; font-size: 14px;
    color: var(--text-secondary); cursor: pointer; border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}
.gallery-tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.gallery-layout { display: flex; gap: 24px; align-items: flex-start; }
.folder-sidebar {
    width: 220px; flex-shrink: 0; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius); padding: 12px;
    position: sticky; top: 16px;
}
.folder-sidebar-header {
    display: flex; justify-content: space-between; align-items: center;
    font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px;
    color: var(--text-muted); margin-bottom: 8px; padding: 0 6px;
}
.folder-item {
    display: flex; justify-content: space-between; align-items: center; gap: 6px;
    width: 100%; text-align: left; background: none; border: none;
    padding: 8px 10px; font-size: 13px; color: var(--text); cursor: pointer;
    border-radius: var(--radius-xs);
}
.folder-item:hover { background: var(--surface-2); }
.folder-item.active { background: var(--gradient-subtle); font-weight: 600; }
.folder-item-wrap { display: flex; align-items: center; }
.folder-item-wrap .folder-item { flex: 1; }
.folder-item-menu { position: relative; }
.folder-menu {
    position: absolute; right: 0; top: 100%; z-index: 50;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xs);
    box-shadow: var(--shadow-md); min-width: 160px; padding: 4px;
}
.folder-menu button {
    display: block; width: 100%; text-align: left; padding: 7px 10px;
    font-size: 12.5px; background: none; border: none; cursor: pointer; border-radius: 4px;
    color: var(--text);
}
.folder-menu button:hover { background: var(--surface-2); }
.folder-menu button.danger { color: var(--error); }
.folder-count { color: var(--text-muted); font-size: 11px; }
.folder-badges { display: flex; align-items: center; gap: 4px; }
.folder-shared-badge { font-size: 11px; }
.gallery-main { flex: 1; min-width: 0; }
.gallery-toolbar {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 10px 14px; margin-bottom: 16px;
    position: sticky; top: 12px; z-index: 30; box-shadow: var(--shadow);
}
.toolbar-select { padding: 6px 8px; font-size: 12.5px; border: 1px solid var(--border); border-radius: var(--radius-xs); }
.gallery-empty { text-align: center; padding: 60px 20px; color: var(--text-secondary); font-size: 14px; }
.gallery-empty a { color: var(--accent); }
.gallery-card { position: relative; }
.gallery-select {
    position: absolute; top: 8px; left: 8px; width: 24px; height: 24px;
    border-radius: 6px; border: 2px solid #fff; background: rgba(0,0,0,0.35);
    color: #fff; font-size: 13px; cursor: pointer; display: flex;
    align-items: center; justify-content: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.gallery-card.selected .gallery-select { background: var(--accent); border-color: var(--accent); }
.gallery-card.selected img { outline: 3px solid var(--accent); outline-offset: -3px; }
.gallery-card-meta {
    display: flex; justify-content: space-between; align-items: center; gap: 6px;
    padding: 6px 8px; font-size: 11.5px; color: var(--text-secondary);
}
.gallery-card-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gallery-card-badges { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.gallery-owner { color: var(--text-muted); }

/* ─── Lightbox detail (gallery) ─── */
.lightbox-detail { align-items: center; justify-content: center; }
.lightbox-panel {
    display: flex; gap: 0; background: var(--surface); border-radius: var(--radius);
    max-width: 1100px; width: calc(100vw - 48px); max-height: calc(100vh - 48px);
    overflow: hidden;
}
.lightbox-img-wrap {
    flex: 1.4; background: #0a0a0a; display: flex; align-items: center; justify-content: center;
    min-width: 0;
}
.lightbox-img-wrap img { max-width: 100%; max-height: calc(100vh - 48px); object-fit: contain; }
.lightbox-side { flex: 1; min-width: 300px; max-width: 400px; padding: 20px; overflow-y: auto; }
.lightbox-side-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.lightbox-side-header .btn-link { font-size: 22px; }
.lightbox-meta { font-size: 13px; line-height: 2; margin-bottom: 14px; }
.lightbox-meta .text-muted { display: inline-block; width: 70px; }
.lightbox-prompt { margin-bottom: 18px; font-size: 13px; }
.lightbox-prompt summary { cursor: pointer; color: var(--text-secondary); }
.lightbox-prompt pre {
    white-space: pre-wrap; word-break: break-word; background: var(--surface-2);
    border-radius: var(--radius-xs); padding: 10px; margin-top: 8px;
    font-size: 12px; max-height: 220px; overflow-y: auto;
}
.lightbox-edit h3 { font-size: 14px; margin-bottom: 8px; }
.lightbox-edit textarea {
    width: 100%; border: 1px solid var(--border); border-radius: var(--radius-xs);
    padding: 8px 10px; font-size: 13px; margin-bottom: 8px; font-family: inherit;
}

/* ─── Brand admin page ─── */
.brand-cat { margin-bottom: 22px; }
.brand-cat-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.brand-cat-header h3 { font-size: 14px; text-transform: capitalize; }
.brand-cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.brand-thumb { position: relative; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.brand-thumb img { width: 100%; aspect-ratio: 1/1; object-fit: contain; background: var(--surface-2); display: block; }
.brand-thumb-delete {
    position: absolute; top: 4px; right: 4px; width: 22px; height: 22px;
    border-radius: 50%; border: none; background: rgba(0,0,0,0.55); color: #fff;
    font-size: 14px; cursor: pointer; line-height: 1;
}
.brand-thumb-delete:hover { background: var(--error); }
.dna-view {
    white-space: pre-wrap; word-break: break-word; background: var(--surface-2);
    border-radius: var(--radius-sm); padding: 16px; font-size: 12.5px;
    max-height: 420px; overflow-y: auto; font-family: ui-monospace, monospace;
}
.dna-editor {
    width: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 14px; font-size: 12.5px; font-family: ui-monospace, monospace; line-height: 1.6;
}
.dna-ai-edit { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.dna-ai-edit h3 { font-size: 14px; margin-bottom: 4px; }
.dna-ai-edit textarea {
    width: 100%; border: 1px solid var(--border); border-radius: var(--radius-xs);
    padding: 8px 10px; font-size: 13px; font-family: inherit;
}

/* ─── Responsive ─── */
@media (max-width: 900px) {
    .dash-actions { grid-template-columns: repeat(2, 1fr); }
    .dash-recent { grid-template-columns: repeat(4, 1fr); }
    .lightbox-panel { flex-direction: column; overflow-y: auto; }
    .lightbox-img-wrap img { max-height: 50vh; }
    .lightbox-side { max-width: none; }
}
@media (max-width: 768px) {
    .gallery-layout { flex-direction: column; }
    .folder-sidebar { width: 100%; position: static; }
    .dash-actions { gap: 12px; }
    .auth-card { padding: 24px 20px; }
    .nav-user-name { display: none; }
    .key-row { align-items: flex-start; flex-direction: column; gap: 8px; }
    .key-input { width: 100%; }
}
@media (max-width: 480px) {
    .dash-actions { grid-template-columns: 1fr; }
    .dash-recent { grid-template-columns: repeat(3, 1fr); }
}

/* Mobile nav: keep brand on one line, let links scroll */
.nav-brand { white-space: nowrap; }
@media (max-width: 768px) {
    .nav { flex-wrap: nowrap; gap: 8px; overflow: hidden; }
    .nav-brand-sub { display: none; }
    .nav-links { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; flex: 1; }
    .nav-links::-webkit-scrollbar { display: none; }
    .nav-links a { white-space: nowrap; }
}
