/* === Design System (matches ad-engine) === */
:root {
    --bg: #09090b;
    --surface: #131316;
    --surface-2: #1a1a1f;
    --border: #27272a;
    --text: #e4e4e7;
    --text-muted: #71717a;
    --accent: #a78bfa;
    --accent-hover: #c4b5fd;
    --accent-dim: rgba(167, 139, 250, 0.15);
    --success: #4ade80;
    --error: #f87171;
    --red: #ef4444;
    --red-dim: rgba(239, 68, 68, 0.12);
    --radius: 12px;
    --radius-sm: 8px;
}

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    line-height: 1.6;
    min-height: 100vh;
}

/* === Header === */
.header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px 32px;
    border-bottom: 1px solid var(--border);
}

.header__avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border);
    transform: rotate(90deg);
}

.header__title {
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.header__subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: block;
}

.header__models {
    margin-left: auto;
    display: flex;
    gap: 8px;
}

/* === Model Pills === */
.model-pill {
    font-size: 0.7rem;
    font-weight: 500;
    padding: 4px 10px;
    border-radius: 20px;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.model-pill--image {
    background: var(--accent-dim);
    color: var(--accent);
    border: 1px solid rgba(167, 139, 250, 0.3);
}

.model-pill--video {
    background: var(--red-dim);
    color: var(--red);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.model-pill--sm {
    font-size: 0.65rem;
    padding: 2px 8px;
}

/* === Page Layout === */
.page-layout {
    display: flex;
    margin: 0 auto;
    min-height: calc(100vh - 85px);
}

/* === Container === */
.container {
    flex: 3;
    min-width: 0;
    padding: 32px;
}

.section-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 16px;
}

/* === Info Bar (toggle buttons) === */
.info-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
}

.info-toggle {
    background: var(--surface);
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 6px 16px;
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s, background 0.2s;
}

.info-toggle:hover {
    border-color: var(--accent);
    color: var(--text);
}

.info-toggle--active {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
}

/* === Info Panels (collapsible) === */
.info-panel {
    display: none;
    margin-bottom: 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

.info-panel--visible {
    display: block;
}

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

/* Character panel */
.info-panel__grid {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 20px;
    align-items: start;
}

.info-panel__image img {
    width: 100%;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.info-panel__details h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 12px;
}

.trait {
    font-size: 0.78rem;
    color: var(--text);
    margin-bottom: 6px;
    line-height: 1.4;
}

.trait__label {
    display: inline-block;
    width: 80px;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* Models panel */
.model-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.model-card {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
}

.model-card__label {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.model-card__name {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 2px;
}

.model-card__via {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.model-card__desc {
    font-size: 0.72rem;
    color: var(--text-muted);
    line-height: 1.5;
}

/* Reference panel */
.reference-panel {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 20px;
    align-items: center;
}

.reference-panel__img {
    width: 100%;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.reference-panel__path {
    font-family: "SF Mono", "Fira Code", monospace;
    font-size: 0.78rem;
    color: var(--accent);
    margin-bottom: 10px;
}

.reference-panel__note {
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.5;
}

/* === Scene Selection === */
.input-section {
    margin-bottom: 40px;
}

.scene-grid {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.scene-option {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.scene-option:hover { border-color: var(--accent); }

.scene-option--selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent), 0 0 20px var(--accent-dim);
}

.scene-option__header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.scene-option__ref-thumb {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    object-fit: cover;
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.scene-option__name {
    font-size: 0.9rem;
    font-weight: 600;
}

.scene-option__chevron {
    margin-left: auto;
    width: 8px;
    height: 8px;
    border-right: 2px solid var(--text-muted);
    border-bottom: 2px solid var(--text-muted);
    transform: rotate(45deg);
    flex-shrink: 0;
    transition: transform 0.2s;
}

.scene-option--expanded .scene-option__chevron {
    transform: rotate(-135deg);
}

/* Collapsible detail */
.scene-option__detail {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.25s ease;
}

.scene-option--expanded .scene-option__detail {
    grid-template-rows: 1fr;
}

.scene-option__detail-inner {
    overflow: hidden;
}

.scene-option__subtitle {
    font-size: 0.72rem;
    color: var(--accent);
    font-weight: 500;
    margin-top: 10px;
    margin-bottom: 4px;
}

.scene-option__desc {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.scene-option__shots {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 10px;
    padding-bottom: 2px;
}

.scene-option__shot-tag {
    font-size: 0.65rem;
    color: var(--text-muted);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 6px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    user-select: none;
    transition: border-color 0.2s, color 0.2s;
}

.scene-option__shot-tag:has(.shot-select-check:not(:checked)) {
    opacity: 0.4;
}

.shot-select-check {
    accent-color: var(--accent);
    width: 12px;
    height: 12px;
    cursor: pointer;
    margin: 0;
}

/* Shot count badge */
.shot-badge {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-dim);
    border: 1px solid rgba(167, 139, 250, 0.3);
    border-radius: 10px;
    padding: 1px 8px;
    white-space: nowrap;
}

/* === Generate Row === */
.generate-row {
    display: flex;
    align-items: center;
    gap: 16px;
}

.auto-mode-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
}

.auto-mode-toggle input[type="checkbox"] {
    accent-color: var(--accent);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

/* === Generate Button === */
.generate-btn {
    width: 100%;
    background: var(--accent);
    color: var(--bg);
    border: none;
    border-radius: var(--radius-sm);
    padding: 14px 32px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
}

.generate-btn:hover { background: var(--accent-hover); }
.generate-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* === Pipeline (single scene) === */
.pipeline-section {
    display: none;
    margin-bottom: 40px;
}

.pipeline-section--visible { display: block; }

.pipeline {
    display: flex;
    align-items: stretch;
    gap: 0;
}

.pipeline__step {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0;
}

.node {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    flex: 1;
    min-width: 160px;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.node__header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 4px;
}

.node__status-dot {
    width: 10px;
    height: 10px;
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    background: var(--border);
    flex-shrink: 0;
    transition: background 0.3s;
}

.node__name {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.node__number {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-left: auto;
}

.node__meta {
    font-size: 0.68rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    font-style: italic;
}

.node__output {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.5;
    min-height: 32px;
    word-break: break-word;
}

/* Node states */
.node--processing {
    border-color: var(--accent);
    box-shadow: 0 0 20px var(--accent-dim);
}

.node--processing .node__status-dot {
    background: var(--accent);
    animation: pulse 1.5s ease-in-out infinite;
}

.node--done { border-color: var(--success); }
.node--done .node__status-dot { background: var(--success); }
.node--error { border-color: var(--error); }
.node--error .node__status-dot { background: var(--error); }

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

/* Connectors */
.connector {
    width: 32px;
    min-width: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.connector__line {
    width: 100%;
    height: 2px;
    background: var(--border);
    transition: background 0.3s;
}

.connector--active .connector__line { background: var(--accent); }
.connector--done .connector__line { background: var(--success); }

/* === Concept Section (multi-shot) === */
.concept-section {
    display: none;
    margin-bottom: 40px;
}

.concept-section--visible { display: block; }

.concept-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 4px;
}

.concept-header .section-label { margin-bottom: 0; }

.concept-progress {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 16px;
    display: block;
}

/* Shot Grid */
.shot-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

/* Shot Card */
.shot-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    transition: border-color 0.3s, box-shadow 0.3s;
    cursor: default;
}

.shot-card__header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.shot-card__number {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
    background: var(--surface-2);
    border-radius: 4px;
    padding: 2px 6px;
    min-width: 24px;
    text-align: center;
}

.shot-card__label {
    font-size: 0.8rem;
    font-weight: 600;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.shot-card__status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--border);
    flex-shrink: 0;
    transition: background 0.3s;
}

.shot-card__image {
    width: 100%;
    aspect-ratio: 9/16;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.shot-card__image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: none;
    cursor: zoom-in;
}

.shot-card__image-placeholder {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.shot-card__actions {
    display: none;
    gap: 6px;
}

/* Shot card states */
.shot-card--pending .shot-card__status-dot { background: var(--border); }

.shot-card--generating {
    border-color: var(--accent);
    box-shadow: 0 0 16px var(--accent-dim);
}

.shot-card--generating .shot-card__status-dot {
    background: var(--accent);
    animation: pulse 1.5s ease-in-out infinite;
}

.shot-card--generating .shot-card__image-placeholder {
    color: var(--accent);
}

.shot-card--done {
    border-color: var(--success);
}

.shot-card--done .shot-card__status-dot { background: var(--success); }

.shot-card--done .shot-card__image img { display: block; }
.shot-card--done .shot-card__image-placeholder { display: none; }
.shot-card--done .shot-card__actions { display: flex; }
.shot-card--done { cursor: pointer; }

.shot-card--approved {
    border-color: var(--success);
    box-shadow: 0 0 12px rgba(74, 222, 128, 0.15);
}

.shot-card--approved .shot-card__status-dot { background: var(--success); }
.shot-card--approved .shot-card__image img { display: block; }
.shot-card--approved .shot-card__image-placeholder { display: none; }
.shot-card--approved .shot-card__actions { display: none; }
.shot-card--approved { cursor: pointer; }

.shot-card--error {
    border-color: var(--error);
}

.shot-card--error .shot-card__status-dot { background: var(--error); }

.shot-card--skipped {
    opacity: 0.5;
}

.shot-card--skipped .shot-card__status-dot { background: var(--text-muted); }

/* Shot action buttons */
.btn-approve, .btn-regenerate, .btn-skip {
    flex: 1;
    border: none;
    border-radius: 4px;
    padding: 6px 8px;
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}

.btn-approve {
    background: rgba(74, 222, 128, 0.15);
    color: var(--success);
    border: 1px solid rgba(74, 222, 128, 0.3);
}

.btn-approve:hover { opacity: 0.8; }

.btn-regenerate {
    background: var(--accent-dim);
    color: var(--accent);
    border: 1px solid rgba(167, 139, 250, 0.3);
}

.btn-regenerate:hover { opacity: 0.8; }

.btn-skip {
    background: var(--surface-2);
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.btn-skip:hover { opacity: 0.8; }

/* Shot Detail Panel */
.shot-detail-panel {
    display: none;
    margin-bottom: 40px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

.shot-detail-panel--visible {
    display: block;
}

.shot-detail-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.shot-detail-panel__title {
    font-size: 0.9rem;
    font-weight: 600;
}

.btn-close-detail {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 4px;
    width: 28px;
    height: 28px;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.2s, color 0.2s;
}

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

.shot-detail-panel__content {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* === Results === */
.results-section {
    display: none;
    gap: 32px;
    margin-bottom: 40px;
}

.results-section--visible {
    display: grid;
    grid-template-columns: 1fr 1fr;
}

/* Start frame image */
.result-image__header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 0;
}

.result-image__header .section-label {
    margin-bottom: 0;
}

.result-image__header .model-pill {
    margin-bottom: 16px;
}

.result-image img {
    width: 100%;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    display: block;
}

.result-image__actions {
    margin-top: 12px;
    display: flex;
    gap: 8px;
}

/* Prompt panels */
.prompts-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.prompts-panel__header {
    display: flex;
    align-items: center;
    gap: 10px;
}

.prompts-panel__header .section-label {
    margin-bottom: 0;
}

.prompts-panel__header .model-pill {
    margin-bottom: 16px;
}

.prompt-block {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.prompt-block__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.prompt-block__text {
    padding: 14px;
    font-size: 0.78rem;
    line-height: 1.6;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-word;
    font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
    max-height: 200px;
    overflow-y: auto;
    margin: 0;
}

.btn-copy {
    background: var(--surface-2);
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 3px 10px;
    font-size: 0.7rem;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}

.btn-copy:hover {
    border-color: var(--accent);
    color: var(--text);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 16px;
    font-size: 0.8rem;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    transition: border-color 0.2s;
}

.btn-secondary:hover { border-color: var(--accent); }

/* Details/collapsible */
.prompt-details {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.prompt-details summary {
    padding: 10px 14px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    cursor: pointer;
    background: var(--surface);
    transition: color 0.2s;
}

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

.prompt-details .prompt-block {
    border: none;
    border-radius: 0;
    border-top: 1px solid var(--border);
}

/* === Reset === */
.reset-section {
    display: none;
    text-align: center;
    margin-top: 24px;
}

.reset-section--visible { display: block; }

.btn-reset {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 24px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}

.btn-reset:hover {
    border-color: var(--accent);
    color: var(--text);
}

/* === Toast === */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--surface-2);
    border: 1px solid var(--success);
    color: var(--text);
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
    z-index: 100;
}

.toast--visible {
    opacity: 1;
    transform: translateY(0);
}

/* === Lightbox (fullscreen image preview) === */
.lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.92);
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
}

.lightbox--visible {
    display: flex;
}

.lightbox__img {
    max-width: 94vw;
    max-height: 94vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.6);
    animation: lightboxIn 0.2s ease;
}

@keyframes lightboxIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.lightbox__close {
    position: absolute;
    top: 20px;
    right: 24px;
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.4rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.2s, background 0.2s;
    z-index: 1001;
}

.lightbox__close:hover {
    border-color: rgba(255, 255, 255, 0.5);
    background: rgba(255, 255, 255, 0.1);
}

/* Lightbox navigation arrows */
.lightbox__nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #fff;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1001;
    transition: background 0.2s, border-color 0.2s;
}

.lightbox__nav:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
}

.lightbox__nav--prev { left: 20px; }
.lightbox__nav--next { right: 20px; }

/* Chevron icons via CSS */
.lightbox__nav::before {
    content: '';
    display: block;
    width: 12px;
    height: 12px;
    border-top: 2px solid #fff;
    border-right: 2px solid #fff;
}

.lightbox__nav--prev::before {
    transform: rotate(-135deg);
    margin-left: 3px;
}

.lightbox__nav--next::before {
    transform: rotate(45deg);
    margin-right: 3px;
}

/* Position counter */
.lightbox__counter {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.6);
    z-index: 1001;
    pointer-events: none;
    user-select: none;
}

/* === Gallery Panel (right side) === */
.gallery-panel {
    flex: 2;
    min-width: 0;
    border-left: 1px solid var(--border);
    background: var(--surface);
    height: calc(100vh - 85px);
    position: sticky;
    top: 85px;
    display: flex;
    flex-direction: column;
}

.gallery__header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px 16px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.gallery__header .section-label {
    margin-bottom: 0;
}

.gallery__count {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.gallery__grid {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
    align-content: start;
}

.gallery__empty {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.78rem;
    padding: 48px 0;
}

/* Gallery Item */
.gallery-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.gallery-item:hover {
    border-color: var(--accent);
    box-shadow: 0 0 12px var(--accent-dim);
}

.gallery-item__img-wrap {
    position: relative;
    overflow: hidden;
    cursor: zoom-in;
    background: var(--bg);
    border-radius: 7px 7px 0 0;
}

.gallery-item__img-wrap img {
    width: 100%;
    aspect-ratio: 1/1;
    object-fit: cover;
    display: block;
}

.gallery-item__info {
    padding: 5px 8px;
}

.gallery-item__label {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gallery-item__concept {
    font-size: 0.6rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gallery-item__prompts {
    display: none;
    padding: 8px;
    border-top: 1px solid var(--border);
}

.gallery-item__prompts--visible {
    display: block;
}

.gallery-item__prompt-text {
    font-size: 0.62rem;
    line-height: 1.5;
    color: var(--text-muted);
    font-family: "SF Mono", "Fira Code", monospace;
    word-break: break-word;
    white-space: pre-wrap;
    max-height: 120px;
    overflow-y: auto;
}

.gallery-item__prompt-label {
    font-size: 0.58rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-top: 4px;
    margin-bottom: 2px;
}

.gallery-item__prompt-label:first-child {
    margin-top: 0;
}

/* === Freestyle Generation === */
.freestyle-section {
    margin-bottom: 40px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.freestyle-section--generating {
    border-color: var(--accent);
    box-shadow: 0 0 20px var(--accent-dim);
}

.freestyle-section--generating .freestyle-generate-btn {
    animation: pulse 1.5s ease-in-out infinite;
}

.freestyle-section .section-label {
    margin-bottom: 16px;
}

.freestyle-layout {
    display: flex;
    gap: 16px;
    align-items: flex-start;
}

.freestyle-ref {
    flex-shrink: 0;
    width: 120px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.freestyle-ref__img-wrap {
    width: 120px;
    height: 120px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    overflow: hidden;
    background: var(--surface-2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.freestyle-ref__img-wrap img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
}

.freestyle-ref__img-wrap img:not([src]),
.freestyle-ref__img-wrap img[src=""] {
    display: none;
}

.freestyle-ref__placeholder {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: center;
    padding: 8px;
}

.freestyle-ref__img-wrap img[src]:not([src=""]) ~ .freestyle-ref__placeholder {
    display: none;
}

.freestyle-ref__buttons {
    display: flex;
    gap: 4px;
}

.freestyle-ref__change-btn,
.freestyle-ref__upload-btn {
    flex: 1;
    background: var(--surface-2);
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.65rem;
    cursor: pointer;
    text-align: center;
    transition: border-color 0.2s, color 0.2s;
}

.freestyle-ref__change-btn:hover,
.freestyle-ref__upload-btn:hover {
    border-color: var(--accent);
    color: var(--text);
}

.freestyle-controls {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.freestyle-prompt {
    width: 100%;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    font-size: 0.85rem;
    font-family: inherit;
    line-height: 1.5;
    resize: vertical;
    min-height: 80px;
    transition: border-color 0.2s;
}

.freestyle-prompt:focus {
    outline: none;
    border-color: var(--accent);
}

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

.freestyle-options {
    display: flex;
    align-items: center;
    gap: 16px;
}

.freestyle-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}

.freestyle-toggle input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.freestyle-toggle__slider {
    width: 36px;
    height: 20px;
    background: var(--border);
    border-radius: 10px;
    position: relative;
    transition: background 0.2s;
    flex-shrink: 0;
}

.freestyle-toggle__slider::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--text-muted);
    top: 2px;
    left: 2px;
    transition: transform 0.2s, background 0.2s;
}

.freestyle-toggle input:checked + .freestyle-toggle__slider {
    background: var(--accent-dim);
}

.freestyle-toggle input:checked + .freestyle-toggle__slider::after {
    transform: translateX(16px);
    background: var(--accent);
}

.freestyle-toggle__label {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.freestyle-toggle__tooltip {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    color: var(--text-muted);
    cursor: help;
    flex-shrink: 0;
}

.freestyle-generate-btn {
    margin-left: auto;
    background: var(--accent);
    color: var(--bg);
    border: none;
    border-radius: var(--radius-sm);
    padding: 10px 24px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
    white-space: nowrap;
}

.freestyle-generate-btn:hover { background: var(--accent-hover); }
.freestyle-generate-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Freestyle Result */
.freestyle-result {
    display: none;
    margin-top: 20px;
    gap: 16px;
}

.freestyle-result--visible {
    display: grid;
    grid-template-columns: 1fr 1fr;
}

.freestyle-result__image img {
    width: 100%;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    cursor: zoom-in;
}

.freestyle-result__prompt {
    min-width: 0;
}

/* Gallery "Use" button — overlay on image */
.gallery-item__use-btn {
    position: absolute;
    bottom: 6px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(167, 139, 250, 0.85);
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 0.6rem;
    font-weight: 600;
    padding: 3px 12px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 2;
}

.gallery-item:hover .gallery-item__use-btn {
    opacity: 1;
}

.gallery-item__use-btn:hover {
    background: rgba(196, 181, 253, 0.9);
}

/* Gallery download button — overlay on image */
.gallery-item__dl-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 0.85rem;
    line-height: 1;
    padding: 3px 6px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 2;
    text-decoration: none;
}

.gallery-item:hover .gallery-item__dl-btn {
    opacity: 1;
}

.gallery-item__dl-btn:hover {
    background: rgba(167, 139, 250, 0.85);
}

.gallery-item__prompt-toggle {
    display: none;
    width: 100%;
    background: none;
    border: none;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.6rem;
    padding: 4px 8px;
    cursor: pointer;
    text-align: left;
    transition: color 0.2s;
}

.gallery-item:hover .gallery-item__prompt-toggle {
    display: block;
}

.gallery-item__prompt-toggle:hover {
    color: var(--accent);
}

/* Lightbox "Use as Reference" button */
.lightbox__use-ref {
    position: absolute;
    bottom: 24px;
    right: 24px;
    background: rgba(167, 139, 250, 0.9);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    padding: 10px 20px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    z-index: 1001;
    transition: background 0.2s;
}

.lightbox__use-ref:hover {
    background: rgba(196, 181, 253, 0.9);
}

/* === Scrollbar === */
::-webkit-scrollbar { height: 6px; width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* === Responsive === */
@media (max-width: 1100px) {
    .page-layout {
        flex-direction: column;
    }

    .gallery-panel {
        height: auto;
        max-height: 50vh;
        position: static;
        border-left: none;
        border-top: 1px solid var(--border);
    }
}

@media (max-width: 768px) {
    .header { padding: 16px 20px; }
    .header__models { display: none; }
    .container { padding: 20px; }

    .info-panel__grid { grid-template-columns: 80px 1fr; }
    .model-cards { grid-template-columns: 1fr; }
    .reference-panel { grid-template-columns: 120px 1fr; }

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

    .connector {
        width: auto;
        height: 24px;
        min-width: unset;
    }

    .connector__line {
        width: 2px;
        height: 100%;
    }

    .node { min-width: unset; }

    .results-section--visible {
        grid-template-columns: 1fr;
    }

    .freestyle-layout {
        flex-direction: column;
    }

    .freestyle-ref {
        width: 100%;
        flex-direction: row;
        align-items: center;
    }

    .freestyle-ref__img-wrap {
        width: 80px;
        height: 80px;
    }

    .freestyle-options {
        flex-wrap: wrap;
    }

    .freestyle-result--visible {
        grid-template-columns: 1fr;
    }

    .shot-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }

    .gallery__grid {
        grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    }
}

/* === Auth Overlay === */
.auth-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}
.auth-overlay.hidden { display: none; }

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px;
    width: 340px;
    text-align: center;
}

.auth-logo {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 16px;
    border: 2px solid var(--border);
    transform: rotate(90deg);
}

.auth-title {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 4px;
    color: var(--text);
}

.auth-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 24px;
}

.auth-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.95rem;
    outline: none;
    box-sizing: border-box;
}
.auth-input:focus { border-color: var(--accent); }
.auth-input::placeholder { color: var(--text-muted); }

.auth-error {
    font-size: 0.8rem;
    color: #f87171;
    margin-top: 8px;
    min-height: 1.2em;
    display: none;
}
.auth-error.active { display: block; }

.auth-btn {
    width: 100%;
    padding: 10px;
    margin-top: 16px;
    background: var(--accent);
    color: #000;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: background 0.15s;
}
.auth-btn:hover:not(:disabled) { background: var(--accent-hover); }
.auth-btn:disabled { opacity: 0.5; cursor: not-allowed; }
