:root {
    color-scheme: dark;
    --bg: #101114;
    --panel: #191b21;
    --panel-2: #21242c;
    --line: #333844;
    --text: #f4f6fa;
    --muted: #aab2c0;
    --accent: #38bdf8;
    --accent-2: #67e8f9;
    --danger: #fb7185;
    --warn: #fbbf24;
    --ok: #34d399;
    --shadow: 0 20px 70px rgba(0, 0, 0, .34);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    letter-spacing: 0;
}

body {
    min-width: 320px;
}

button,
input,
select,
textarea {
    font: inherit;
}

button,
select,
input,
textarea {
    border: 1px solid var(--line);
    background: #111318;
    color: var(--text);
    border-radius: 8px;
}

button {
    cursor: pointer;
    min-height: 42px;
    padding: 0 16px;
    font-weight: 700;
}

button:hover {
    border-color: var(--accent);
}

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

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at top left, rgba(56, 189, 248, .14), transparent 34%),
        linear-gradient(135deg, #101114 0%, #17191f 62%, #0d1117 100%);
}

.login-panel {
    width: min(440px, 100%);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 28px;
    box-shadow: var(--shadow);
}

.login-form,
.generator {
    display: grid;
    gap: 16px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 24px;
    border-bottom: 1px solid var(--line);
    background: rgba(16, 17, 20, .94);
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar h1,
.login-panel h1 {
    margin: 0;
    font-size: 24px;
    line-height: 1.1;
}

.eyebrow {
    color: var(--accent-2);
    margin: 0 0 6px;
    text-transform: uppercase;
    font-size: 12px;
    font-weight: 800;
}

.muted {
    color: var(--muted);
}

.studio {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(320px, .65fr);
    gap: 20px;
    padding: 22px;
}

.left-pane,
.right-pane,
.gallery-section {
    display: grid;
    gap: 18px;
}

.gallery-section {
    grid-column: 1 / -1;
}

.status-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.metric,
.preview-panel,
.settings-panel,
.queue-panel,
.gallery-section,
.generator,
.alert {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
}

.metric span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 8px;
}

.metric strong {
    font-size: 22px;
}

.alert-warning {
    border-color: rgba(251, 191, 36, .6);
    color: #fde68a;
    background: rgba(251, 191, 36, .08);
}

.alert-error {
    border-color: rgba(251, 113, 133, .65);
    color: #fecdd3;
    background: rgba(251, 113, 133, .08);
    margin: 18px 0;
}

.field {
    display: grid;
    gap: 8px;
    font-weight: 800;
}

label {
    color: #dfe5ef;
    font-size: 13px;
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    padding: 11px 12px;
    outline: none;
}

textarea {
    min-height: 118px;
    resize: vertical;
    line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, .15);
}

.control-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.wide-control {
    grid-column: span 3;
}

.model-hint {
    display: block;
    margin-top: 7px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
    font-weight: 600;
}

.model-hint.missing {
    color: #fecdd3;
}

.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.primary {
    background: var(--accent);
    color: #031018;
    border-color: transparent;
}

.secondary {
    background: #252a33;
}

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

.checkline input {
    width: 18px;
    height: 18px;
}

.section-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.section-head h2 {
    margin: 0;
    font-size: 18px;
}

.icon-btn {
    min-height: 34px;
    padding: 0 10px;
    font-size: 12px;
    background: #252a33;
}

.preview-stage {
    min-height: 330px;
    display: grid;
    place-items: center;
    border: 1px dashed var(--line);
    border-radius: 8px;
    background: #111318;
    padding: 16px;
}

.format-preview {
    width: min(100%, 340px);
    max-height: 300px;
    aspect-ratio: 1 / 1;
    border: 2px solid var(--accent);
    background:
        linear-gradient(90deg, rgba(255,255,255,.05) 1px, transparent 1px),
        linear-gradient(0deg, rgba(255,255,255,.05) 1px, transparent 1px),
        #171a20;
    background-size: 24px 24px;
    position: relative;
    display: grid;
    place-items: center;
    overflow: hidden;
}

.format-preview span {
    color: var(--accent-2);
    font-weight: 900;
    background: rgba(0, 0, 0, .35);
    padding: 6px 9px;
    border-radius: 6px;
}

.safe-overlay {
    position: absolute;
    border: 1px solid rgba(52, 211, 153, .95);
    background: rgba(52, 211, 153, .08);
    pointer-events: none;
}

.subprompt {
    margin: 8px 0 0;
    color: #d6f7ff;
    font-size: 13px;
    line-height: 1.45;
}

.settings-panel dl {
    margin: 0;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px 18px;
}

.settings-panel dt {
    color: var(--muted);
}

.settings-panel dd {
    margin: 0;
    font-weight: 800;
}

.jobs-list {
    display: grid;
    gap: 8px;
}

.job-row {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-2);
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 0 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 900;
    background: #303744;
}

.badge.done {
    color: #bbf7d0;
    background: rgba(52, 211, 153, .15);
}

.badge.failed {
    color: #fecdd3;
    background: rgba(251, 113, 133, .15);
}

.badge.running {
    color: #bae6fd;
    background: rgba(56, 189, 248, .15);
}

.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 14px;
}

.image-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}

.image-card img {
    display: block;
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    background: #111318;
}

.image-card-body {
    padding: 10px;
    display: grid;
    gap: 9px;
}

.image-card p {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
}

.card-actions {
    display: flex;
    gap: 8px;
}

.card-actions button,
.card-actions a {
    flex: 1;
    min-height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--text);
    background: #252a33;
    font-size: 12px;
    font-weight: 800;
}

.danger {
    color: #fecdd3 !important;
    border-color: rgba(251, 113, 133, .6) !important;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(0, 0, 0, .88);
    display: grid;
    place-items: center;
    padding: 60px 20px 20px;
}

.modal[hidden] {
    display: none;
}

.modal img {
    max-width: 96vw;
    max-height: 86vh;
    object-fit: contain;
    border: 1px solid var(--line);
    background: #111318;
}

.modal-close {
    position: fixed;
    right: 20px;
    top: 18px;
    background: #252a33;
}

@media (max-width: 1080px) {
    .studio {
        grid-template-columns: 1fr;
    }

    .status-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 720px) {
    .topbar {
        align-items: flex-start;
        padding: 14px;
    }

    .studio {
        padding: 12px;
    }

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

    .wide-control {
        grid-column: auto;
    }

    .button-row {
        display: grid;
    }

    .metric strong {
        font-size: 20px;
    }
}
