:root {
    color-scheme: dark;
    --background: #070A12;
    --surface: #101827;
    --card: #151F32;
    --card-soft: #1C2942;
    --card-hover: #22304B;
    --primary: #8B5CF6;
    --primary-hover: #A78BFA;
    --secondary: #06B6D4;
    --accent: #F59E0B;
    --text: #F8FAFC;
    --muted: #94A3B8;
    --border: rgba(255, 255, 255, 0.10);
    --success: #22C55E;
    --error: #EF4444;
    --info: #38BDF8;
    --warning: #F59E0B;
    --shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
    --soft-glow: 0 18px 48px rgba(139, 92, 246, 0.20);
}

html[data-theme="light"] {
    color-scheme: light;
    --background: #F8FAFC;
    --surface: #FFFFFF;
    --card: #FFFFFF;
    --card-soft: #F1F5F9;
    --card-hover: #E2E8F0;
    --primary: #7C3AED;
    --primary-hover: #6D28D9;
    --secondary: #0891B2;
    --accent: #F59E0B;
    --text: #0F172A;
    --muted: #64748B;
    --border: rgba(15, 23, 42, 0.10);
    --shadow: 0 24px 70px rgba(15, 23, 42, 0.10);
    --soft-glow: 0 18px 48px rgba(124, 58, 237, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: radial-gradient(circle at 18% 8%, rgba(139, 92, 246, 0.22), transparent 30%),
        radial-gradient(circle at 85% 10%, rgba(6, 182, 212, 0.15), transparent 28%),
        linear-gradient(180deg, var(--background) 0%, var(--surface) 100%);
    color: var(--text);
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    transition: background-color 0.2s ease, color 0.2s ease;
}

a {
    color: inherit;
    text-decoration: none;
}

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

.guest-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 28px 16px;
}

.guest-card {
    width: min(460px, 100%);
    padding: 30px;
}

.login-brand {
    margin-bottom: 26px;
}

.login-title {
    margin-bottom: 8px;
    font-size: 30px;
}

.login-kicker {
    margin-bottom: 22px;
}

.login-form {
    margin-top: 18px;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
    padding: 24px;
    border-right: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 78%, transparent);
    backdrop-filter: blur(18px);
}

.main-panel {
    min-width: 0;
    padding: 32px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 28px;
}

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

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-mark {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    box-shadow: var(--soft-glow);
    font-weight: 800;
}

.brand-title {
    margin: 0;
    font-size: 16px;
    line-height: 1.2;
}

.brand-subtitle,
.muted {
    color: var(--muted);
}

.brand-subtitle {
    margin-top: 3px;
    font-size: 12px;
}

.nav {
    display: grid;
    gap: 8px;
    margin-top: 34px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 0 12px;
    border: 1px solid transparent;
    border-radius: 14px;
    color: var(--muted);
}

.nav-link:hover,
.nav-link.active {
    color: var(--text);
    border-color: var(--border);
    background: color-mix(in srgb, var(--card-soft) 62%, transparent);
}

.icon {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
}

.button .icon,
.badge .icon,
.filter-link .icon,
.nav-link .icon,
.quota-list .icon {
    width: 16px;
    height: 16px;
}

.theme-toggle {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    cursor: pointer;
    color: var(--text);
    background: color-mix(in srgb, var(--card) 72%, transparent);
}

.theme-toggle:hover {
    background: var(--card-hover);
}

html[data-theme="dark"] .theme-sun,
html[data-theme="light"] .theme-moon {
    display: none;
}

.logout-form {
    margin-top: 28px;
}

.page-title {
    margin: 0;
    font-size: 34px;
    line-height: 1.1;
    letter-spacing: 0;
}

.page-kicker {
    margin: 8px 0 0;
    color: var(--muted);
    line-height: 1.6;
}

.card {
    border: 1px solid var(--border);
    border-radius: 20px;
    background: color-mix(in srgb, var(--card) 84%, transparent);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
}

.card-pad {
    padding: 24px;
}

.grid {
    display: grid;
    gap: 18px;
}

.stack {
    display: grid;
    gap: 18px;
}

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

.form {
    display: grid;
    gap: 18px;
}

.field {
    display: grid;
    gap: 8px;
}

.label {
    font-size: 13px;
    color: var(--muted);
}

.input {
    width: 100%;
    min-height: 48px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 14px;
    outline: none;
    background: color-mix(in srgb, var(--background) 72%, transparent);
    color: var(--text);
}

.textarea {
    min-height: 112px;
    padding: 14px;
    line-height: 1.6;
    resize: vertical;
}

.prompt-input {
    min-height: 230px;
}

.input:focus {
    border-color: rgba(124, 58, 237, 0.85);
    box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.16);
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 46px;
    padding: 0 16px;
    border: 0;
    border-radius: 14px;
    cursor: pointer;
    color: var(--text);
    font-weight: 700;
    transition: transform 0.16s ease, background-color 0.16s ease, border-color 0.16s ease, filter 0.16s ease;
}

.button:hover {
    transform: translateY(-1px);
}

.button-primary {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    box-shadow: 0 18px 45px rgba(6, 182, 212, 0.18);
}

.button-primary:hover {
    filter: brightness(1.08);
}

.button:disabled {
    cursor: not-allowed;
    filter: grayscale(0.45);
    opacity: 0.62;
}

.button-secondary {
    border: 1px solid var(--border);
    background: color-mix(in srgb, var(--card-soft) 54%, transparent);
    color: var(--muted);
}

.button-secondary:hover {
    background: var(--card-hover);
    color: var(--text);
}

.button-danger {
    border: 1px solid rgba(239, 68, 68, 0.32);
    background: rgba(239, 68, 68, 0.12);
    color: #FCA5A5;
}

.button-danger:hover {
    background: rgba(239, 68, 68, 0.2);
    color: var(--text);
}

.alert {
    padding: 12px 14px;
    border-radius: 14px;
    line-height: 1.5;
}

.alert-error {
    border: 1px solid rgba(239, 68, 68, 0.28);
    background: rgba(239, 68, 68, 0.12);
    color: #FCA5A5;
}

.alert-success {
    border: 1px solid rgba(34, 197, 94, 0.28);
    background: rgba(34, 197, 94, 0.12);
    color: #86EFAC;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 28px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--muted);
    font-size: 12px;
    background: color-mix(in srgb, var(--card-soft) 42%, transparent);
}

.loading-dot {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--info);
    box-shadow: 0 0 20px rgba(56, 189, 248, 0.7);
    animation: pulse 1.4s ease-in-out infinite;
}

.empty-state {
    display: grid;
    gap: 12px;
    place-items: center;
    min-height: 240px;
    padding: 28px;
    text-align: center;
}

.empty-icon {
    width: 54px;
    height: 54px;
    display: grid;
    place-items: center;
    border-radius: 18px;
    background: color-mix(in srgb, var(--card-soft) 68%, transparent);
    color: var(--secondary);
    font-size: 24px;
}

.empty-illustration {
    width: 88px;
    height: 88px;
    display: grid;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 28px;
    color: var(--secondary);
    background: linear-gradient(135deg, color-mix(in srgb, var(--primary) 20%, transparent), color-mix(in srgb, var(--secondary) 16%, transparent));
    box-shadow: var(--soft-glow);
}

.empty-illustration .icon {
    width: 42px;
    height: 42px;
}

.placeholder-block {
    min-height: 130px;
    border: 1px dashed rgba(255, 255, 255, 0.14);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.035);
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
}

.toolbar h2,
.model-card h3 {
    margin: 10px 0 8px;
}

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

.filter-link {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    min-height: 38px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--muted);
    background: color-mix(in srgb, var(--card) 58%, transparent);
}

.filter-link span {
    color: var(--text);
    font-weight: 700;
}

.filter-link:hover,
.filter-link.active {
    color: var(--text);
    border-color: rgba(6, 182, 212, 0.45);
    background: rgba(6, 182, 212, 0.10);
}

.model-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
    margin-top: 18px;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
    margin-top: 18px;
}

.model-card {
    overflow: hidden;
    transition: transform 0.18s ease, border-color 0.18s ease;
}

.gallery-card {
    overflow: hidden;
    transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.model-card:hover,
.gallery-card:hover {
    transform: translateY(-3px);
    border-color: color-mix(in srgb, var(--secondary) 44%, var(--border));
    box-shadow: var(--shadow), 0 18px 42px rgba(6, 182, 212, 0.10);
}

.gallery-media {
    position: relative;
    overflow: hidden;
    display: grid;
    place-items: center;
    aspect-ratio: 4 / 3;
    background: color-mix(in srgb, var(--card-soft) 68%, transparent);
}

.gallery-media img,
.gallery-media video {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

.media-play-badge {
    position: absolute;
    inset: auto 12px 12px auto;
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text);
    background: rgba(0, 0, 0, 0.46);
    backdrop-filter: blur(10px);
}

.card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.card-actions form {
    margin: 0;
}

.card-actions .button {
    min-height: 40px;
}

.model-thumb {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    background: color-mix(in srgb, var(--card-soft) 70%, transparent);
}

.model-thumb-empty {
    display: grid;
    place-items: center;
    color: var(--secondary);
    font-weight: 800;
}

.model-body {
    display: grid;
    gap: 10px;
    padding: 18px;
}

.model-meta,
.feature-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.feature-list span {
    padding: 5px 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--muted);
    font-size: 12px;
}

.home-workspace {
    display: grid;
    gap: 18px;
}

.studio-hero {
    position: relative;
    overflow: hidden;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 280px;
    gap: 24px;
    align-items: center;
    padding: 28px;
    border: 1px solid var(--border);
    border-radius: 24px;
    background: linear-gradient(135deg, color-mix(in srgb, var(--primary) 24%, var(--card)), color-mix(in srgb, var(--secondary) 18%, var(--card)));
    box-shadow: var(--shadow);
}

.studio-hero h2 {
    max-width: 780px;
    margin: 14px 0 10px;
    font-size: clamp(28px, 4vw, 54px);
    line-height: 1.02;
    letter-spacing: 0;
}

.studio-hero p {
    max-width: 690px;
    margin: 0;
    line-height: 1.7;
}

.hero-panel {
    min-height: 190px;
    border: 1px solid var(--border);
    border-radius: 24px;
    background: color-mix(in srgb, var(--background) 42%, transparent);
    display: grid;
    place-items: center;
}

.hero-panel-grid {
    display: grid;
    grid-template-columns: repeat(2, 72px);
    gap: 12px;
    transform: rotate(-4deg);
}

.hero-panel-grid span {
    min-height: 72px;
    display: grid;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: color-mix(in srgb, var(--card-soft) 70%, transparent);
}

.hero-panel-grid span:last-child {
    grid-column: 1 / -1;
}

.hero-panel-grid .icon {
    width: 30px;
    height: 30px;
}

.tool-switcher {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.tool-card {
    display: grid;
    gap: 8px;
    min-height: 118px;
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 22px;
    text-align: left;
    color: var(--muted);
    background: color-mix(in srgb, var(--card) 76%, transparent);
    cursor: pointer;
    transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.tool-card strong {
    color: var(--text);
    font-size: 18px;
}

.tool-card:hover,
.tool-card.active {
    transform: translateY(-2px);
    border-color: rgba(6, 182, 212, 0.46);
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.18), rgba(6, 182, 212, 0.12));
}

.tool-icon,
.quota-icon {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    color: var(--text);
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    box-shadow: var(--soft-glow);
}

.tool-icon .icon,
.quota-icon .icon {
    width: 20px;
    height: 20px;
}

.generator-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
    gap: 18px;
    align-items: start;
}

.generator-form {
    display: grid;
    gap: 18px;
}

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

.selected-model-card {
    display: grid;
    grid-template-columns: 112px minmax(0, 1fr);
    gap: 14px;
    align-items: center;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: color-mix(in srgb, var(--card-soft) 54%, transparent);
}

.selected-model-card .model-thumb {
    border-radius: 14px;
}

.selected-model-card strong {
    display: block;
    margin-bottom: 5px;
}

.selected-model-card p {
    margin: 0;
    line-height: 1.5;
}

.dynamic-settings {
    display: grid;
    gap: 14px;
}

.field-wide {
    grid-column: 1 / -1;
}

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

.aspect-option {
    min-height: 76px;
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: color-mix(in srgb, var(--background) 52%, transparent);
    color: var(--muted);
    cursor: pointer;
}

.aspect-option input {
    width: 16px;
    height: 16px;
    accent-color: var(--secondary);
}

.aspect-option:has(input:checked) {
    border-color: rgba(6, 182, 212, 0.52);
    background: rgba(6, 182, 212, 0.10);
    color: var(--text);
}

.aspect-preview {
    max-width: 100%;
    justify-self: center;
    display: block;
    border: 1px solid rgba(248, 250, 252, 0.68);
    border-radius: 4px;
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.46), rgba(6, 182, 212, 0.38));
}

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

.quota-summary-grid div {
    display: grid;
    gap: 4px;
    min-height: 82px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: color-mix(in srgb, var(--card-soft) 58%, transparent);
}

.quota-summary-grid strong {
    font-size: 26px;
}

.quota-summary-grid span {
    color: var(--muted);
    font-size: 12px;
}

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

.sync-summary-grid div,
.sync-current-panel {
    border: 1px solid var(--border);
    border-radius: 16px;
    background: color-mix(in srgb, var(--card-soft) 58%, transparent);
}

.sync-summary-grid div {
    display: grid;
    gap: 4px;
    min-height: 78px;
    padding: 14px;
}

.sync-summary-grid strong {
    font-size: 24px;
}

.sync-summary-grid span {
    color: var(--muted);
    font-size: 12px;
}

.sync-current-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(240px, 0.42fr);
    gap: 16px;
    padding: 16px;
}

.sync-current-panel h3 {
    margin: 10px 0 6px;
}

.model-sync-table-wrap {
    overflow-x: auto;
}

.model-sync-table {
    width: 100%;
    min-width: 760px;
    border-collapse: collapse;
}

.model-sync-table th,
.model-sync-table td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

.model-sync-table th {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.sync-status-success {
    border-color: rgba(34, 197, 94, 0.28);
    color: #86EFAC;
    background: rgba(34, 197, 94, 0.10);
}

.sync-status-failed {
    border-color: rgba(239, 68, 68, 0.28);
    color: #FCA5A5;
    background: rgba(239, 68, 68, 0.10);
}

.sync-status-syncing {
    border-color: rgba(56, 189, 248, 0.32);
    color: #BAE6FD;
    background: rgba(56, 189, 248, 0.10);
}

.sync-status-skipped {
    border-color: rgba(245, 158, 11, 0.32);
    color: #FCD34D;
    background: rgba(245, 158, 11, 0.10);
}

.generator-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.status-panel {
    display: grid;
    gap: 12px;
    padding: 14px;
    border: 1px solid rgba(56, 189, 248, 0.22);
    border-radius: 18px;
    background: rgba(56, 189, 248, 0.08);
}

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

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

.status-steps span {
    min-height: 34px;
    display: grid;
    place-items: center;
    padding: 0 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--muted);
    font-size: 12px;
    text-align: center;
}

.status-steps span.active {
    color: var(--text);
    background: rgba(6, 182, 212, 0.18);
}

.result-column {
    display: grid;
    gap: 18px;
}

.latest-result {
    min-height: 520px;
}

.result-preview {
    display: grid;
    gap: 16px;
    margin-top: 18px;
}

.result-frame {
    min-height: 310px;
    aspect-ratio: 4 / 3;
    overflow: hidden;
    display: grid;
    place-items: center;
    border: 1px dashed rgba(255, 255, 255, 0.16);
    border-radius: 20px;
    text-align: center;
    color: var(--muted);
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.12), rgba(6, 182, 212, 0.08));
}

.result-frame.prepared {
    color: #C4B5FD;
    border-color: rgba(124, 58, 237, 0.34);
}

.result-frame.failed {
    color: #FCA5A5;
    border-color: rgba(239, 68, 68, 0.34);
    background: rgba(239, 68, 68, 0.08);
}

.result-state {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 0 18px;
    line-height: 1.5;
}

.result-media {
    width: 100%;
    height: 100%;
    max-height: 430px;
    border-radius: 18px;
    object-fit: contain;
}

.result-details {
    display: grid;
    gap: 10px;
}

.result-details p {
    margin: 0;
    color: var(--muted);
    line-height: 1.6;
}

.state-card {
    display: grid;
    gap: 14px;
}

.state-list {
    display: grid;
    gap: 10px;
}

.state-list div {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
}

.state-dot {
    width: 10px;
    height: 10px;
    border-radius: 999px;
}

.state-dot.info {
    background: var(--info);
}

.state-dot.warning {
    background: var(--accent);
}

.state-dot.error {
    background: var(--error);
}

.provider-layout {
    margin-top: 18px;
}

.provider-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    margin-top: 18px;
}

.provider-card {
    display: grid;
    gap: 18px;
    padding: 20px;
}

.provider-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
}

.provider-head h3 {
    margin: 10px 0 6px;
}

.quota-list {
    display: grid;
    gap: 12px;
    color: var(--muted);
}

.quota-list span {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    line-height: 1.5;
}

.meter {
    height: 9px;
    overflow: hidden;
    margin-top: 7px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
}

.meter span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--secondary), var(--primary));
}

.detail-list {
    display: grid;
    gap: 8px;
    margin: 0;
}

.detail-list div {
    display: grid;
    grid-template-columns: 96px minmax(0, 1fr);
    gap: 10px;
}

.detail-list dt {
    color: var(--muted);
    font-size: 12px;
}

.detail-list dd {
    min-width: 0;
    margin: 0;
    overflow-wrap: anywhere;
    color: var(--text);
}

.status-active {
    border-color: rgba(34, 197, 94, 0.28);
    color: #86EFAC;
    background: rgba(34, 197, 94, 0.10);
}

.status-disabled,
.status-login_failed,
.status-registration_failed {
    border-color: rgba(239, 68, 68, 0.28);
    color: #FCA5A5;
    background: rgba(239, 68, 68, 0.10);
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    padding: 22px;
    background: rgba(0, 0, 0, 0.72);
    backdrop-filter: blur(10px);
}

.modal-card {
    width: min(980px, 100%);
    max-height: calc(100vh - 44px);
    overflow: auto;
    display: grid;
    gap: 18px;
    padding: 24px;
    border: 1px solid var(--border);
    border-radius: 22px;
    background: color-mix(in srgb, var(--surface) 96%, transparent);
    box-shadow: 0 28px 90px rgba(0, 0, 0, 0.48);
}

.modal-media {
    display: grid;
    place-items: center;
    min-height: 340px;
    overflow: hidden;
    border-radius: 18px;
    background: color-mix(in srgb, var(--card-soft) 72%, transparent);
}

.modal-media img,
.modal-media video {
    width: 100%;
    max-height: 70vh;
    object-fit: contain;
}

@keyframes pulse {
    0%,
    100% {
        opacity: 0.55;
        transform: scale(0.9);
    }

    50% {
        opacity: 1;
        transform: scale(1.14);
    }
}

.skeleton-bar {
    min-height: 14px;
    overflow: hidden;
    border-radius: 999px;
    background: linear-gradient(90deg, color-mix(in srgb, var(--card-soft) 70%, transparent), color-mix(in srgb, var(--secondary) 18%, transparent), color-mix(in srgb, var(--card-soft) 70%, transparent));
    background-size: 220% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
}

@keyframes shimmer {
    from {
        background-position: 220% 0;
    }

    to {
        background-position: -220% 0;
    }
}

.is-hidden {
    display: none !important;
}

@media (max-width: 860px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: sticky;
        top: 0;
        z-index: 5;
        padding: 16px;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .nav {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        margin-top: 16px;
    }

    .logout-form {
        margin-top: 12px;
    }

    .main-panel {
        padding: 22px 16px 32px;
    }

    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .topbar-actions {
        width: 100%;
        justify-content: space-between;
    }

    .grid-2 {
        grid-template-columns: 1fr;
    }

    .toolbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .model-grid,
    .gallery-grid,
    .provider-grid {
        grid-template-columns: 1fr;
    }

    .tool-switcher,
    .studio-hero,
    .generator-layout,
    .settings-grid,
    .aspect-options,
    .quota-summary-grid,
    .sync-summary-grid,
    .sync-current-panel,
    .status-steps {
        grid-template-columns: 1fr;
    }

    .hero-panel {
        min-height: 150px;
    }

    .selected-model-card {
        grid-template-columns: 1fr;
    }

    .latest-result {
        min-height: 0;
    }

    .detail-list div {
        grid-template-columns: 1fr;
    }

    .button {
        width: 100%;
    }

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

    .card-actions form,
    .card-actions a,
    .card-actions button {
        width: 100%;
    }
}

@media (min-width: 861px) and (max-width: 1180px) {
    .model-grid,
    .gallery-grid,
    .provider-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .generator-layout {
        grid-template-columns: 1fr;
    }
}

/* ============================================================
   Atelier port from design-reference
   Warm cream light theme by default, dark theme via data-theme.
   ============================================================ */

:root {
    color-scheme: light;
    --bg: #f7f2e8;
    --surface: #fffdf7;
    --surface-2: #fbf6ec;
    --surface-3: #f3ecdd;
    --ink: #1a1612;
    --ink-2: #45403a;
    --muted: #8a8276;
    --line: #e6dec9;
    --line-strong: #d6cbb0;
    --accent: #c8651a;
    --accent-hover: #a8500f;
    --accent-soft: #fbeada;
    --accent-tint: #f7ddbe;
    --ok: #4f7d3e;
    --ok-bg: #e8f0dd;
    --warn: #b06b14;
    --warn-bg: #faecd6;
    --err: #a13226;
    --err-bg: #f6dcd5;
    --font-sans: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    --r-sm: 6px;
    --r-md: 10px;
    --r-lg: 16px;
    --r-xl: 24px;
    --shadow-sm: 0 1px 0 rgba(40, 28, 10, 0.04), 0 1px 2px rgba(40, 28, 10, 0.04);
    --shadow-md: 0 1px 0 rgba(40, 28, 10, 0.04), 0 6px 16px -8px rgba(40, 28, 10, 0.08);
    --shadow-lg: 0 1px 0 rgba(40, 28, 10, 0.04), 0 18px 40px -20px rgba(40, 28, 10, 0.16);
    --background: var(--bg);
    --text: var(--ink);
    --card: var(--surface);
    --card-soft: var(--surface-2);
    --card-hover: var(--surface-3);
    --primary: var(--accent);
    --secondary: var(--accent);
    --border: var(--line);
    --success: var(--ok);
    --error: var(--err);
    --info: var(--accent);
    --warning: var(--warn);
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0f0d0a;
    --surface: #18140f;
    --surface-2: #1f1a13;
    --surface-3: #25201a;
    --ink: #f4ecdd;
    --ink-2: #c9bfae;
    --muted: #8a8170;
    --line: #2b251c;
    --line-strong: #3a3226;
    --accent: #e88c3f;
    --accent-hover: #f3a05d;
    --accent-soft: #2a1e10;
    --accent-tint: #3a2814;
    --ok: #92c178;
    --ok-bg: #1d2818;
    --warn: #e0a55a;
    --warn-bg: #2a200f;
    --err: #e08071;
    --err-bg: #2a1612;
    --shadow-sm: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 1px 0 rgba(0, 0, 0, 0.25), 0 6px 16px -8px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 1px 0 rgba(0, 0, 0, 0.3), 0 18px 40px -20px rgba(0, 0, 0, 0.7);
}

html,
body {
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
}

body {
    background: var(--bg);
}

.app-shell {
    display: grid;
    grid-template-columns: 248px 1fr;
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 28px;
    padding: 22px 16px;
    border-right: 1px solid var(--line);
    background: var(--surface);
    backdrop-filter: none;
}

.brand {
    gap: 12px;
    padding: 4px 6px;
}

.brand-mark {
    width: 36px;
    height: 36px;
    border-radius: var(--r-md);
    background: var(--ink);
    color: var(--surface);
    box-shadow: none;
    position: relative;
    overflow: hidden;
    font-size: 14px;
}

.brand-mark::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent 40%, var(--accent) 140%);
    opacity: 0.65;
}

.brand-mark span {
    position: relative;
    z-index: 1;
}

.brand-title,
.brand-name {
    margin: 0;
    color: var(--ink);
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.brand-subtitle,
.brand-sub,
.muted {
    color: var(--muted);
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 0;
}

.nav-label {
    margin-bottom: 6px;
    padding: 0 10px;
    color: var(--muted);
    font-size: 10px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.nav-item,
.nav-link {
    width: 100%;
    min-height: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 10px;
    border: 1px solid transparent;
    border-radius: var(--r-md);
    background: transparent;
    color: var(--ink-2);
    font-size: 13.5px;
    font-weight: 500;
    text-align: left;
}

.nav-item:hover,
.nav-link:hover,
.nav-item.active,
.nav-link.active {
    background: var(--surface-2);
    color: var(--ink);
    border-color: var(--line);
    box-shadow: var(--shadow-sm);
}

.nav-item .icon,
.nav-link .icon {
    color: var(--muted);
    width: 16px;
    height: 16px;
}

.nav-item.active .icon,
.nav-link.active .icon {
    color: var(--accent);
}

.sidebar-foot,
.logout-form {
    margin-top: auto;
}

.main-panel {
    min-width: 0;
    padding: 0;
}

.topbar {
    margin: 0;
    padding: 22px 40px 0;
}

.page-title {
    margin: 0;
    color: var(--ink);
    font-size: 12px;
    font-weight: 500;
}

.page-kicker {
    display: none;
}

.topbar > div:first-child {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 12px;
}

.topbar > div:first-child::before {
    content: "Workspace";
}

.topbar > div:first-child::after {
    content: "";
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: var(--muted);
    opacity: 0.5;
    order: 1;
}

.topbar .page-title {
    order: 2;
}

.topbar-actions,
.top-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.workspace-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px 7px 10px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    color: var(--ink-2);
    font-size: 12px;
    box-shadow: var(--shadow-sm);
}

.workspace-pill .pulse {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--ok);
    box-shadow: 0 0 0 3px var(--ok-bg);
}

.icon-btn {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--surface);
    color: var(--ink-2);
    box-shadow: var(--shadow-sm);
}

.icon-btn:hover {
    color: var(--ink);
    border-color: var(--line-strong);
    background: var(--surface);
}

:root:not([data-theme="dark"]) .theme-sun,
:root[data-theme="dark"] .theme-moon {
    display: none;
}

.home-workspace,
.page,
section.card.card-pad.stack:first-child,
.provider-layout,
.provider-grid,
.gallery-grid,
.model-grid,
[data-ui-config-sync] {
    max-width: 1400px;
}

.home-workspace,
.gallery-grid,
.model-grid,
.provider-grid,
[data-ui-config-sync],
section.card.card-pad.stack:first-child {
    margin-left: 40px;
    margin-right: 40px;
}

.home-workspace {
    padding: 28px 0 60px;
}

.page {
    width: 100%;
    max-width: 1400px;
    padding: 28px 40px 60px;
}

.page .gallery-grid,
.page .model-grid,
.page .provider-grid,
.page [data-ui-config-sync] {
    margin-left: 0;
    margin-right: 0;
}

.card {
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    backdrop-filter: none;
}

.card-pad {
    padding: 22px;
}

.studio-hero,
.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 40px;
    margin-bottom: 32px;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
}

.studio-hero .badge,
.eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    color: var(--accent);
    font-size: 11px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.studio-hero .badge::before,
.eyebrow::before {
    content: "";
    width: 16px;
    height: 1px;
    background: var(--accent);
}

.studio-hero h2,
.page-head h1 {
    margin: 0;
    color: var(--ink);
    font-size: 38px;
    font-weight: 600;
    line-height: 1.05;
    letter-spacing: -0.025em;
}

.studio-hero p,
.page-head .sub {
    max-width: 540px;
    margin: 10px 0 0;
    color: var(--muted);
}

.hero-panel {
    display: none;
}

.tool-switcher,
.studios {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-bottom: 24px;
}

.tool-card,
.studio-card {
    position: relative;
    min-height: 132px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 18px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    background: var(--surface);
    color: var(--ink-2);
    text-align: left;
    box-shadow: none;
    transition: border-color 120ms, transform 200ms;
}

.tool-card:hover,
.tool-card.active {
    transform: none;
    border-color: var(--accent-tint);
    background: var(--surface);
}

.tool-card::after {
    content: "◳";
    position: absolute;
    right: -10px;
    bottom: -16px;
    color: var(--surface-3);
    font-size: 96px;
    line-height: 1;
    font-weight: 600;
    opacity: 0.9;
}

.tool-card:nth-child(2)::after {
    content: "▶";
}

.tool-card .badge {
    width: fit-content;
    margin-bottom: auto;
    color: var(--muted);
    background: transparent;
    border: 0;
    padding: 0;
    font-size: 11px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.tool-card strong {
    position: relative;
    z-index: 1;
    color: var(--ink);
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.tool-card > span:last-child {
    width: fit-content;
    padding: 3px 8px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--ink-2);
    font-family: var(--font-mono);
    font-size: 11px;
}

.tool-icon {
    display: none;
}

.generator-layout,
.home-grid {
    display: grid;
    grid-template-columns: 1.6fr 1fr;
    gap: 24px;
    align-items: start;
}

.generator-form,
.prompt-card {
    display: grid;
    gap: 18px;
    padding: 20px;
    overflow: hidden;
}

.label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.input,
.select,
.textarea {
    width: 100%;
    min-height: 0;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    outline: none;
    background: var(--surface);
    color: var(--ink);
    font-size: 14px;
    transition: border 120ms, box-shadow 120ms;
}

.input:focus,
.select:focus,
.textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.textarea,
.prompt-input {
    min-height: 150px;
    line-height: 1.55;
}

.selected-model-card,
.model-pick {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--surface-2);
}

.selected-model-card .model-thumb {
    width: 64px;
    height: 48px;
    flex: 0 0 64px;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--surface);
    object-fit: cover;
}

.selected-model-card .model-thumb-empty {
    display: grid;
    place-items: center;
    color: var(--ink);
    font-weight: 600;
}

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

.aspect-options,
.ratio-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.aspect-option,
.ratio {
    min-height: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--surface);
    color: var(--ink-2);
    cursor: pointer;
}

.aspect-option:has(input:checked),
.ratio.active {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--ink);
}

.aspect-preview {
    border: 1px solid var(--line-strong);
    border-radius: 3px;
    background: var(--surface-3);
}

.aspect-option:has(input:checked) .aspect-preview {
    border-color: var(--accent);
    background: var(--accent-tint);
}

.button,
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 0;
    padding: 9px 14px;
    border: 1px solid transparent;
    border-radius: var(--r-md);
    color: var(--ink);
    font-size: 13.5px;
    font-weight: 500;
    box-shadow: none;
}

.button:hover,
.btn:hover {
    transform: none;
}

.button-primary,
.btn-primary {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.button-primary:hover,
.btn-primary:hover {
    border-color: var(--accent-hover);
    background: var(--accent-hover);
    filter: none;
}

.button-secondary,
.btn-ghost {
    border-color: var(--line);
    background: var(--surface);
    color: var(--ink);
}

.button-secondary:hover,
.btn-ghost:hover {
    border-color: var(--line-strong);
    background: var(--surface-2);
}

.button-danger,
.btn-danger {
    border-color: color-mix(in oklab, var(--err) 30%, var(--line));
    background: transparent;
    color: var(--err);
}

.button-danger:hover,
.btn-danger:hover {
    background: var(--err-bg);
    color: var(--err);
}

.full {
    width: 100%;
}

.badge,
.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 0;
    padding: 4px 9px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--ink-2);
    font-size: 11.5px;
    font-weight: 500;
    text-transform: none;
}

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

.status-active,
.sync-status-success,
.badge.ok {
    border-color: transparent;
    background: var(--ok-bg);
    color: var(--ok);
}

.status-login_failed,
.sync-status-skipped,
.sync-status-syncing,
.badge.warn {
    border-color: transparent;
    background: var(--warn-bg);
    color: var(--warn);
}

.status-disabled,
.status-registration_failed,
.sync-status-failed,
.badge.err {
    border-color: transparent;
    background: var(--err-bg);
    color: var(--err);
}

.result-frame,
.preview-frame {
    aspect-ratio: 16 / 9;
    min-height: 0;
    margin-top: 14px;
    overflow: hidden;
    border: 1px dashed var(--line-strong);
    border-radius: var(--r-md);
    background: repeating-linear-gradient(135deg, var(--surface-2) 0 12px, var(--surface-3) 12px 24px);
    color: var(--muted);
}

.result-media {
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: 0;
    object-fit: cover;
}

.result-details p {
    color: var(--muted);
}

.quota-summary-grid,
.quota-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 14px;
}

.quota-summary-grid div,
.quota-tile {
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--surface-2);
}

.quota-summary-grid strong,
.quota-tile .qt-num {
    color: var(--ink);
    font-size: 24px;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.quota-summary-grid span,
.quota-tile .qt-top {
    color: var(--muted);
    font-size: 11px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.quota-icon {
    width: auto;
    height: auto;
    display: inline-flex;
    border-radius: 0;
    background: transparent;
    color: var(--muted);
    box-shadow: none;
}

.filter-row,
.tabs {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--surface);
}

.filter-link,
.tab {
    min-height: 0;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 6px 12px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--muted);
    font-size: 13px;
}

.filter-link.active,
.filter-link:hover,
.tab.active {
    background: var(--surface-2);
    color: var(--ink);
    box-shadow: var(--shadow-sm);
}

.gallery-grid,
.gal-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin-top: 22px;
}

.gallery-card,
.gal-tile {
    position: relative;
    aspect-ratio: 4 / 5;
    overflow: hidden;
    border-radius: var(--r-lg);
    background: var(--surface-2);
    border: 1px solid var(--line);
    transition: transform 200ms, box-shadow 200ms;
}

.gallery-card:hover {
    transform: none;
    box-shadow: var(--shadow-md);
}

.gallery-media {
    position: absolute;
    inset: 0;
    aspect-ratio: auto;
    background: var(--surface-2);
}

.gallery-media img,
.gallery-media video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gallery-card .model-body {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px;
    color: #fff;
    background: linear-gradient(180deg, transparent 0%, rgba(10, 8, 6, 0) 40%, rgba(10, 8, 6, 0.85) 100%);
    opacity: 0;
    transition: opacity 220ms;
}

.gallery-card:hover .model-body {
    opacity: 1;
}

.gallery-card .model-meta {
    position: absolute;
    top: 12px;
    left: 12px;
}

.gallery-card .model-meta .badge {
    border-color: rgba(255, 255, 255, 0.18);
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    backdrop-filter: blur(8px);
}

.gallery-card .muted {
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
    color: #fff;
    font-size: 12.5px;
    line-height: 1.45;
}

.gallery-card .feature-list span {
    background: transparent;
    color: rgba(255, 255, 255, 0.72);
}

.gallery-card .button {
    flex: 1;
    padding: 7px 10px;
    border-color: rgba(255, 255, 255, 0.22);
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    font-size: 12px;
}

.gallery-card .button-danger {
    background: rgba(180, 40, 30, 0.4);
    border-color: rgba(220, 90, 80, 0.5);
}

.media-play-badge {
    top: 12px;
    right: 12px;
    bottom: auto;
    width: 30px;
    height: 30px;
}

.provider-layout,
.split {
    display: grid;
    grid-template-columns: 1fr 1.6fr;
    gap: 24px;
    margin-top: 22px;
}

.stats-row {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}

.stat-card {
    padding: 18px 20px;
}

.stat-label {
    color: var(--muted);
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.stat-value {
    margin-top: 4px;
    color: var(--ink);
    font-size: 30px;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.stat-sub {
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
}

.stat-ok {
    color: var(--ok);
}

.stat-warn {
    color: var(--warn);
}

.stat-err {
    color: var(--err);
}

.provider-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    background: var(--surface);
}

.provider-card {
    display: grid;
    gap: 14px;
    padding: 18px 20px;
    border: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    box-shadow: none;
}

.provider-card:last-child {
    border-bottom: 0;
}

.provider-head h3 {
    margin: 8px 0 2px;
    color: var(--ink);
    font-size: 15px;
}

.meter {
    height: 4px;
    background: var(--surface-3);
}

.meter span {
    background: var(--accent);
}

.detail-list dt {
    color: var(--muted);
}

.detail-list dd {
    color: var(--ink);
    font-family: var(--font-mono);
    font-size: 11.5px;
}

.model-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin-top: 22px;
}

.model-card {
    padding: 0;
    overflow: hidden;
    border-radius: var(--r-lg);
    transition: border-color 120ms, transform 200ms;
}

.model-card:hover {
    transform: none;
    border-color: var(--accent-tint);
    box-shadow: var(--shadow-sm);
}

.model-thumb {
    aspect-ratio: 16 / 9;
    border-bottom: 1px solid var(--line);
    background: radial-gradient(60% 80% at 50% 100%, var(--accent-soft), transparent 70%), var(--surface-2);
}

.model-thumb-empty {
    color: var(--ink);
    font-size: 34px;
}

.model-body {
    padding: 16px 18px 18px;
}

.model-body h3 {
    color: var(--ink);
    font-size: 15px;
    font-weight: 600;
}

.feature-list span {
    border: 1px solid var(--line);
    background: var(--surface-2);
    color: var(--ink-2);
}

.sync-summary-grid,
.sync-strip {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    background: var(--surface);
}

.sync-summary-grid div {
    min-height: 0;
    padding: 16px 20px;
    border: 0;
    border-right: 1px solid var(--line);
    border-radius: 0;
    background: transparent;
}

.sync-summary-grid div:last-child {
    border-right: 0;
}

.sync-summary-grid strong {
    color: var(--ink);
    font-size: 22px;
    font-weight: 600;
}

.sync-current-panel,
.model-sync-table-wrap,
.table-wrap {
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    background: var(--surface);
    overflow: hidden;
}

.model-sync-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.model-sync-table th,
.model-sync-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
}

.model-sync-table th {
    background: var(--surface-2);
    color: var(--muted);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.modal-card {
    border-color: var(--line);
    border-radius: var(--r-lg);
    background: var(--surface);
    color: var(--ink);
}

.modal-backdrop {
    background: rgba(10, 8, 6, 0.72);
}

.modal-media {
    background: var(--surface-2);
}

.empty-state {
    min-height: 260px;
    margin: 22px 40px 0;
    border-style: dashed;
    background: var(--surface);
}

.page .empty-state {
    margin: 22px 0 0;
}

.empty-illustration,
.empty-icon {
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    background: var(--surface-2);
    color: var(--accent);
    box-shadow: none;
}

.guest-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: radial-gradient(circle at 50% 0%, var(--accent-soft), transparent 42%), var(--bg);
}

.guest-card {
    width: min(460px, 100%);
    padding: 28px;
}

.login-head {
    display: block;
    margin: 22px 0;
}

.login-head h1 {
    font-size: 34px;
}

.alert {
    border-radius: var(--r-md);
}

.alert-error {
    border-color: transparent;
    background: var(--err-bg);
    color: var(--err);
}

.alert-success {
    border-color: transparent;
    background: var(--ok-bg);
    color: var(--ok);
}

.tiny-icon {
    width: 12px;
    height: 12px;
}

@media (max-width: 1200px) {
    .gallery-grid,
    .model-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .generator-layout,
    .provider-layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 860px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

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

    .nav-label {
        grid-column: 1 / -1;
    }

    .topbar,
    .page,
    .home-workspace,
    .gallery-grid,
    .model-grid,
    .provider-grid,
    [data-ui-config-sync],
    section.card.card-pad.stack:first-child {
        margin-left: 16px;
        margin-right: 16px;
        padding-left: 0;
        padding-right: 0;
    }

    .topbar {
        padding-top: 18px;
        flex-direction: column;
        align-items: flex-start;
    }

    .studio-hero h2,
    .page-head h1 {
        font-size: 32px;
    }

    .tool-switcher,
    .generator-layout,
    .settings-grid,
    .aspect-options,
    .quota-summary-grid,
    .sync-summary-grid,
    .stats-row,
    .provider-layout,
    .gallery-grid,
    .model-grid {
        grid-template-columns: 1fr;
    }

    .gallery-card {
        aspect-ratio: 4 / 5;
    }
}

/* Reference parity overrides for the PHP port. */
.topbar > .crumbs::before,
.topbar > .crumbs::after {
    content: none;
}

.page-title {
    color: var(--ink);
    font-size: 12px;
    font-weight: 500;
}

.home-page {
    padding: 28px 40px 60px;
    max-width: 1400px;
    width: 100%;
}

.home-page .result-column {
    display: block;
}

.home-page .latest-result {
    min-height: 0;
}

.home-page .toolbar h2,
.preview-card h3 {
    margin: 4px 0 0;
    font-size: 16px;
    letter-spacing: -0.01em;
}

.home-page .toolbar .badge:first-child {
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 11px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.prompt-head .muted {
    font-size: 12px;
    margin-top: 2px;
}

.generator-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.generator-actions .row {
    margin-left: auto;
}

.status-panel {
    margin: 0 20px 20px;
    border-color: var(--line);
    background: var(--surface-2);
}

.gallery-page .gal-grid,
.gallery-page .gallery-grid {
    margin: 0;
}

.gal-tile .gallery-media {
    position: absolute;
    inset: 0;
    display: block;
}

.gal-tile .empty-icon {
    position: absolute;
    inset: 0;
    width: auto;
    height: auto;
    border: 0;
    border-radius: 0;
}

.gal-tile .corner {
    position: absolute;
    top: 12px;
    left: 12px;
    display: inline-flex;
    gap: 6px;
    z-index: 2;
}

.gal-tile .play {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(8px);
    display: grid;
    place-items: center;
    color: #fff;
    z-index: 2;
}

.gal-tile .overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, transparent 0%, rgba(10, 8, 6, 0) 40%, rgba(10, 8, 6, 0.85) 100%);
    opacity: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 16px;
    gap: 12px;
    color: #fff;
    transition: opacity 220ms;
}

.gal-tile:hover .overlay {
    opacity: 1;
}

.gal-tile .corner .chip {
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(8px);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.18);
    font-size: 11px;
}

.gal-tile .ov-prompt {
    font-size: 12.5px;
    line-height: 1.45;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.gal-tile .ov-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.7);
}

.gal-tile .ov-actions {
    display: flex;
    gap: 8px;
}

.gal-tile .ov-actions form {
    flex: 1;
}

.gal-tile .ov-actions .obtn {
    width: 100%;
    min-height: 0;
    padding: 7px 10px;
    border-radius: var(--r-md);
    border: 1px solid rgba(255, 255, 255, 0.22);
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    font-size: 12px;
}

.gal-tile .ov-actions .obtn:hover {
    background: rgba(255, 255, 255, 0.22);
}

.gal-tile .ov-actions .obtn.danger {
    background: rgba(180, 40, 30, 0.4);
    border-color: rgba(220, 90, 80, 0.5);
}

.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13px;
}

.table th,
.table td {
    text-align: left;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}

.table th {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--muted);
    font-weight: 500;
    background: var(--surface-2);
    position: sticky;
    top: 0;
}

.table tr:hover td {
    background: var(--surface-2);
}

.table tr:last-child td {
    border-bottom: none;
}

.table .acc-name {
    font-weight: 600;
    font-size: 13px;
}

.table .acc-email {
    font-family: var(--font-mono);
    font-size: 11.5px;
    color: var(--muted);
}

.quota-mini {
    display: flex;
    align-items: center;
    gap: 6px;
}

.quota-mini .qb {
    width: 38px;
    height: 4px;
    border-radius: 2px;
    background: var(--surface-3);
    position: relative;
    overflow: hidden;
}

.quota-mini .qb > span {
    display: block;
    height: 100%;
    border-radius: 2px;
    background: var(--accent);
}

.quota-mini .qt {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--muted);
}

.provider-table-wrap {
    min-width: 0;
}

.provider-table {
    min-width: 1040px;
}

.secret-cell span {
    font-size: 10.5px;
}

.row-actions form {
    margin: 0;
}

.status-active .dot,
.sync-status-success .dot,
.badge.ok .dot {
    background: var(--ok);
}

.status-login_failed .dot,
.sync-status-syncing .dot,
.sync-status-skipped .dot,
.badge.warn .dot {
    background: var(--warn);
}

.status-registration_failed .dot,
.status-disabled .dot,
.sync-status-failed .dot,
.badge.err .dot {
    background: var(--err);
}

.model-sync-section {
    margin-bottom: 22px;
}

.model-sync-section .sync-current-panel {
    margin: 16px 20px;
}

.model-sync-section .sync-strip {
    margin: 0;
    border-left: 0;
    border-right: 0;
    border-radius: 0;
}

.model-card .hero {
    aspect-ratio: 16 / 9;
    background: var(--surface-2);
    border-bottom: 1px solid var(--line);
    display: grid;
    place-items: center;
    position: relative;
    overflow: hidden;
}

.model-card .hero .bg {
    position: absolute;
    inset: 0;
    background: radial-gradient(60% 80% at 50% 100%, var(--accent-soft), transparent 70%);
    opacity: 0.7;
}

.model-card .hero .model-thumb {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    object-fit: cover;
}

.model-card .hero .glyph {
    position: relative;
    z-index: 1;
    font-weight: 600;
    font-size: 56px;
    letter-spacing: -0.04em;
    color: var(--ink);
}

.model-card .hero .corner {
    position: absolute;
    top: 12px;
    left: 12px;
    display: inline-flex;
    gap: 6px;
    z-index: 2;
}

.model-card .hero .corner .chip {
    background: rgba(255, 253, 247, 0.7);
    backdrop-filter: blur(6px);
}

:root[data-theme="dark"] .model-card .hero .corner .chip {
    background: rgba(15, 13, 10, 0.72);
}

.model-card .body {
    padding: 16px 18px 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.model-card .name {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.model-card .desc {
    font-size: 12.5px;
    color: var(--muted);
    line-height: 1.5;
    min-height: 36px;
}

.model-card .tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
}

.model-card .specs {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-top: 10px;
    padding-top: 12px;
    border-top: 1px dashed var(--line);
    font-size: 11.5px;
    color: var(--muted);
}

.model-card .specs .item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.model-card .specs .v {
    color: var(--ink);
    font-weight: 500;
    font-family: var(--font-mono);
}

.model-card .sync-item {
    margin-left: auto;
}

@media (max-width: 860px) {
    .home-page {
        padding: 28px 16px 60px;
    }

    .quota-strip,
    .field-row {
        grid-template-columns: 1fr;
    }

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

    .generator-actions .row {
        width: 100%;
        margin-left: 0;
        flex-direction: column;
    }

    .gal-tile .overlay {
        opacity: 1;
    }
}

/* ============================================================
   Final Atelier parity layer
   Keeps backend markup stable while matching design-reference.
   ============================================================ */

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    background:
        radial-gradient(circle at 88% -10%, rgba(200, 101, 26, 0.08), transparent 34rem),
        linear-gradient(180deg, var(--bg), var(--bg));
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: 14px;
}

a {
    color: inherit;
    text-decoration: none;
}

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

.app,
.app-shell {
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr);
    min-height: 100vh;
    background: var(--bg);
}

.sidebar {
    position: sticky;
    top: 0;
    z-index: 20;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 28px;
    padding: 22px 16px;
    border-right: 1px solid var(--line);
    background: var(--surface);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 6px;
}

.brand-mark {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    flex: 0 0 36px;
    border-radius: var(--r-md);
    background: var(--ink);
    color: var(--surface);
    font-weight: 700;
    overflow: hidden;
    position: relative;
}

.brand-mark::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent 36%, var(--accent) 150%);
    opacity: 0.72;
}

.brand-mark span {
    position: relative;
    z-index: 1;
}

.brand-name,
.brand-title {
    color: var(--ink);
    font-size: 14px;
    font-weight: 650;
    letter-spacing: -0.01em;
}

.brand-sub,
.brand-subtitle {
    color: var(--muted);
    font-size: 12px;
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-label {
    margin: 0 0 6px;
    padding: 0 10px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.nav-item,
.nav-link {
    width: 100%;
    min-height: 38px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 10px;
    border: 1px solid transparent;
    border-radius: var(--r-md);
    background: transparent;
    color: var(--ink-2);
    font-size: 13.5px;
    font-weight: 550;
    cursor: pointer;
}

.nav-item:hover,
.nav-link:hover,
.nav-item.active,
.nav-link.active {
    border-color: var(--line);
    background: var(--surface-2);
    color: var(--ink);
    box-shadow: var(--shadow-sm);
}

.nav-item .icon,
.nav-link .icon {
    width: 16px;
    height: 16px;
    color: var(--muted);
}

.nav-item.active .icon,
.nav-link.active .icon {
    color: var(--accent);
}

.sidebar-foot,
.logout-form {
    margin-top: auto;
}

.main,
.main-panel {
    min-width: 0;
}

.topbar {
    min-height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 22px 40px 0;
}

.crumbs {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 12px;
}

.topbar > .crumbs::before,
.topbar > .crumbs::after {
    content: none !important;
}

.crumbs .dot {
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.55;
}

.page-title {
    color: var(--ink);
    font-size: 12px;
    font-weight: 550;
}

.top-actions,
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.workspace-pill {
    min-height: 34px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px 7px 10px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    color: var(--ink-2);
    font-size: 12px;
    box-shadow: var(--shadow-sm);
}

.workspace-pill .pulse {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--ok);
    box-shadow: 0 0 0 3px var(--ok-bg);
}

.icon-btn {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--surface);
    color: var(--ink-2);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
}

.icon-btn:hover {
    border-color: var(--line-strong);
    color: var(--ink);
}

:root:not([data-theme="dark"]) .theme-sun,
:root[data-theme="dark"] .theme-moon {
    display: none;
}

.page {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 28px 40px 60px;
}

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 22px;
}

.eyebrow {
    margin-bottom: 8px;
    color: var(--accent);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.page-head h1 {
    max-width: 840px;
    margin: 0;
    color: var(--ink);
    font-size: clamp(34px, 4.2vw, 58px);
    font-weight: 680;
    line-height: 0.98;
    letter-spacing: -0.035em;
}

.page-head .sub,
.sub {
    max-width: 620px;
    margin-top: 12px;
    color: var(--muted);
    font-size: 15px;
    line-height: 1.6;
}

.card,
.table-wrap,
.model-sync-section {
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.card-pad {
    padding: 22px;
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.mt-16 {
    margin-top: 16px;
}

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

.mono {
    font-family: var(--font-mono);
}

.icon {
    width: 16px;
    height: 16px;
    flex: 0 0 auto;
}

.button,
.btn {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 13px;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--surface);
    color: var(--ink);
    font-size: 13px;
    font-weight: 650;
    line-height: 1;
    cursor: pointer;
    transition: transform 150ms, border-color 150ms, background 150ms, color 150ms;
}

.button:hover,
.btn:hover {
    transform: translateY(-1px);
    border-color: var(--line-strong);
}

.button-primary,
.btn-primary {
    border-color: var(--accent);
    background: var(--accent);
    color: #fffdf7;
}

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

.button-secondary,
.btn-ghost {
    background: var(--surface-2);
}

.button-danger,
.btn-danger {
    border-color: rgba(161, 50, 38, 0.28);
    background: var(--err-bg);
    color: var(--err);
}

.btn-sm {
    min-height: 32px;
    padding: 7px 10px;
    font-size: 12px;
}

.button:disabled,
.btn:disabled {
    opacity: 0.58;
    cursor: not-allowed;
    transform: none;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.input,
.select,
.textarea {
    width: 100%;
    min-height: 42px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    outline: none;
    background: var(--surface);
    color: var(--ink);
    font-size: 14px;
    transition: border-color 150ms, box-shadow 150ms;
}

.textarea,
.prompt-input {
    min-height: 160px;
    resize: vertical;
    line-height: 1.55;
}

.input:focus,
.select:focus,
.textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.chip,
.badge {
    min-height: 24px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    width: fit-content;
    padding: 4px 8px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--ink-2);
    font-size: 11px;
    font-weight: 650;
    line-height: 1;
}

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

.badge.ok,
.status-active,
.sync-status-success {
    border-color: rgba(79, 125, 62, 0.24);
    background: var(--ok-bg);
    color: var(--ok);
}

.badge.warn,
.status-login_failed,
.sync-status-syncing,
.sync-status-skipped,
.sync-status-pending {
    border-color: rgba(176, 107, 20, 0.25);
    background: var(--warn-bg);
    color: var(--warn);
}

.badge.err,
.status-registration_failed,
.status-disabled,
.status-failed,
.sync-status-failed {
    border-color: rgba(161, 50, 38, 0.25);
    background: var(--err-bg);
    color: var(--err);
}

.alert {
    margin-bottom: 16px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--surface);
}

.alert-error {
    border-color: rgba(161, 50, 38, 0.22);
    background: var(--err-bg);
    color: var(--err);
}

.alert-success {
    border-color: rgba(79, 125, 62, 0.22);
    background: var(--ok-bg);
    color: var(--ok);
}

.is-hidden {
    display: none !important;
}

/* Home */
.quota-strip {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin: 0 0 22px;
}

.quota-pill {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    background: linear-gradient(180deg, var(--surface), var(--surface-2));
    box-shadow: var(--shadow-sm);
}

.qp-icon {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    flex: 0 0 40px;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--accent-soft);
    color: var(--accent);
}

.qp-meta {
    min-width: 0;
    flex: 1;
}

.qp-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

.qp-label {
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.qp-num {
    color: var(--ink);
    font-family: var(--font-mono);
    font-size: 22px;
    font-weight: 700;
}

.qp-bar,
.qb {
    height: 5px;
    overflow: hidden;
    border-radius: 999px;
    background: var(--surface-3);
}

.qp-bar span,
.qb span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--accent), var(--warn));
}

.home-grid,
.generator-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.75fr);
    gap: 22px;
    align-items: start;
}

.prompt-card {
    overflow: hidden;
    padding: 0;
}

.prompt-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 20px;
    border-bottom: 1px solid var(--line);
    background:
        radial-gradient(circle at 100% 0, var(--accent-soft), transparent 18rem),
        var(--surface);
}

.prompt-head h3,
.toolbar h2,
.table-head h2,
.table-head h3,
.card h2 {
    margin: 0;
    color: var(--ink);
    font-size: 18px;
    font-weight: 680;
    letter-spacing: -0.02em;
}

.prompt-body {
    display: grid;
    gap: 16px;
    padding: 20px;
}

.seg {
    display: inline-grid;
    grid-template-columns: repeat(2, minmax(88px, 1fr));
    gap: 4px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface-2);
}

.seg-btn {
    appearance: none;
    min-height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 7px 13px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--ink-2);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}

.seg-btn.active {
    background: var(--accent);
    color: #fffdf7;
    box-shadow: var(--shadow-sm);
}

.selected-model-card {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-top: 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--surface-2);
}

.selected-model-card strong {
    display: block;
    margin-bottom: 3px;
    color: var(--ink);
}

.model-thumb {
    width: 66px;
    height: 50px;
    flex: 0 0 66px;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    object-fit: cover;
    background: var(--surface);
}

.model-thumb-empty {
    display: grid;
    place-items: center;
    color: var(--accent);
    background: var(--accent-soft);
}

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

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

.aspect-option {
    position: relative;
    min-height: 58px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--surface);
    color: var(--ink-2);
    cursor: pointer;
}

.aspect-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.ratio {
    min-height: 58px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--surface);
    color: var(--ink-2);
    cursor: pointer;
}

.aspect-option > span:not(.aspect-preview) {
    color: inherit;
    font-size: 12px;
    font-weight: 650;
}

.aspect-option:has(input:checked),
.ratio.active {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--ink);
}

.aspect-preview {
    width: var(--ratio-width, 34px);
    height: var(--ratio-height, 24px);
    max-width: 50px;
    max-height: 38px;
    min-width: 10px;
    min-height: 10px;
    border: 2px solid var(--accent);
    border-radius: 5px;
    background: var(--accent-tint);
}

.prompt-foot,
.generator-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 20px;
    border-top: 1px solid var(--line);
    background: var(--surface-2);
}

.hint {
    color: var(--muted);
    font-size: 12px;
}

.row {
    display: flex;
    align-items: center;
}

.gap-sm {
    gap: 10px;
}

.status-panel {
    margin: 0 20px 20px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--surface-2);
}

.status-line {
    display: flex;
    align-items: center;
    gap: 8px;
}

.loading-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    animation: aipPulse 1.15s infinite ease-in-out;
}

@keyframes aipPulse {
    0%, 100% { opacity: 0.35; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1); }
}

.status-steps {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.status-steps span {
    padding: 5px 8px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    font-size: 11px;
}

.status-steps span.active {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
}

.result-column {
    position: sticky;
    top: 84px;
}

.latest-result {
    min-height: 520px;
}

.toolbar,
.table-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
}

.result-preview {
    display: grid;
    gap: 16px;
    margin-top: 18px;
}

.result-frame {
    aspect-ratio: 4 / 5;
    display: grid;
    place-items: center;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    background:
        radial-gradient(circle at 50% 100%, var(--accent-soft), transparent 68%),
        var(--surface-2);
    color: var(--muted);
}

.result-media,
.modal-media img,
.modal-media video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.empty-illustration,
.empty-icon {
    width: 58px;
    height: 58px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    background: var(--accent-soft);
    color: var(--accent);
}

.result-details p {
    margin: 6px 0 0;
    color: var(--muted);
    line-height: 1.5;
}

.feature-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.feature-list span {
    display: inline-flex;
    align-items: center;
    padding: 4px 7px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--muted);
    font-size: 11px;
}

.card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
}

/* Gallery */
.gal-toolbar,
.models-toolbar {
    margin-bottom: 18px;
}

.tabs,
.filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tab,
.filter-link {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    color: var(--ink-2);
    font-size: 13px;
    font-weight: 650;
}

.tab.active,
.filter-link.active {
    border-color: var(--accent);
    background: var(--accent);
    color: #fffdf7;
}

.tab span {
    font-family: var(--font-mono);
    opacity: 0.8;
}

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

.gal-tile,
.gallery-card {
    position: relative;
    min-height: 0;
    aspect-ratio: 4 / 5;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    background: var(--surface-2);
    box-shadow: var(--shadow-sm);
}

.gallery-media {
    position: absolute;
    inset: 0;
}

.gal-tile .img,
.gallery-media img,
.gallery-media video {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

.gal-tile .empty-icon {
    position: absolute;
    inset: 0;
    width: auto;
    height: auto;
    border: 0;
    border-radius: 0;
}

.gal-tile .corner {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 2;
    display: flex;
    gap: 6px;
}

.gal-tile .corner .chip {
    border-color: rgba(255, 255, 255, 0.18);
    background: rgba(10, 8, 6, 0.55);
    color: #fff;
    backdrop-filter: blur(8px);
}

.gal-tile .play {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 2;
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    border-radius: 999px;
    background: rgba(10, 8, 6, 0.56);
    color: #fff;
    backdrop-filter: blur(8px);
}

.gal-tile .overlay {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px;
    background: linear-gradient(180deg, transparent 0%, rgba(10, 8, 6, 0.03) 38%, rgba(10, 8, 6, 0.88) 100%);
    color: #fff;
    opacity: 0;
    transition: opacity 180ms;
}

.gal-tile:hover .overlay,
.gal-tile:focus-within .overlay {
    opacity: 1;
}

.gal-tile .overlay .corner {
    position: static;
}

.ov-prompt {
    margin: 0;
    color: #fff;
    font-size: 12.5px;
    line-height: 1.45;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.ov-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    color: rgba(255, 255, 255, 0.76);
    font-size: 11px;
}

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

.ov-actions form {
    flex: 1;
    margin: 0;
}

.obtn {
    width: 100%;
    min-height: 34px;
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    backdrop-filter: blur(8px);
}

.obtn:hover {
    background: rgba(255, 255, 255, 0.22);
}

.obtn.danger {
    border-color: rgba(224, 128, 113, 0.5);
    background: rgba(161, 50, 38, 0.45);
}

.empty-state {
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 24px;
}

/* Provider accounts */
.stats-row {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    padding: 16px;
}

.stat-label {
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.stat-value {
    margin-top: 6px;
    color: var(--ink);
    font-family: var(--font-mono);
    font-size: 30px;
    font-weight: 750;
    line-height: 1;
}

.stat-sub {
    margin-top: 8px;
    color: var(--muted);
    font-size: 12px;
}

.stat-ok {
    color: var(--ok);
}

.stat-warn {
    color: var(--warn);
}

.stat-err {
    color: var(--err);
}

.split,
.provider-layout {
    display: grid;
    grid-template-columns: minmax(300px, 0.58fr) minmax(0, 1.42fr);
    gap: 18px;
    align-items: start;
}

.register-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.divider {
    width: 100%;
    border: 0;
    border-top: 1px solid var(--line);
}

.info-row {
    display: grid;
    grid-template-columns: 130px minmax(0, 1fr);
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}

.info-row:last-child {
    border-bottom: 0;
}

.info-key {
    color: var(--ink);
    font-weight: 650;
}

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

.table-wrap {
    min-width: 0;
    overflow: hidden;
}

.table-head {
    padding: 18px 20px;
    border-bottom: 1px solid var(--line);
}

.table-head p,
.table-head .muted {
    margin: 4px 0 0;
}

.table-scroll {
    max-width: 100%;
    overflow: auto;
}

.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13px;
}

.provider-table {
    min-width: 980px;
}

.table th,
.table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}

.table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--surface-2);
    color: var(--muted);
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.table tr:last-child td {
    border-bottom: 0;
}

.table tr:hover td {
    background: var(--surface-2);
}

.acc-name {
    color: var(--ink);
    font-weight: 700;
}

.acc-email {
    margin-top: 2px;
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 11.5px;
}

.quota-mini {
    min-width: 72px;
    display: grid;
    gap: 5px;
}

.quota-mini .qt {
    color: var(--muted);
    font-family: var(--font-mono);
    font-size: 11px;
}

.quota-mini .qb {
    width: 58px;
}

.secret-cell {
    max-width: 140px;
    overflow-wrap: anywhere;
    font-size: 11px;
}

.secret-cell span {
    font-size: 10px;
}

.row-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.row-actions form {
    margin: 0;
}

/* Models */
.model-sync-section {
    margin-bottom: 22px;
    overflow: hidden;
}

.sync-strip {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    background: var(--surface-2);
}

.sync-strip .cell {
    padding: 14px 18px;
    border-right: 1px solid var(--line);
}

.sync-strip .cell:last-child {
    border-right: 0;
}

.sync-strip .k {
    color: var(--muted);
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.sync-strip .v {
    margin-top: 5px;
    color: var(--ink);
    font-family: var(--font-mono);
    font-size: 22px;
    font-weight: 700;
}

.sync-current-panel {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin: 18px 20px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    background: var(--surface-2);
}

.sync-current-panel h3 {
    margin: 8px 0 4px;
}

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

.detail-list div {
    display: grid;
    grid-template-columns: 92px minmax(0, 1fr);
    gap: 10px;
}

.detail-list dt {
    color: var(--muted);
    font-size: 11px;
}

.detail-list dd {
    margin: 0;
    color: var(--ink);
    font-family: var(--font-mono);
    font-size: 11px;
}

.model-sync-table {
    min-width: 760px;
}

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

.model-card {
    overflow: hidden;
}

.model-card .hero {
    position: relative;
    display: grid;
    place-items: center;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    border-bottom: 1px solid var(--line);
    background: var(--surface-2);
}

.model-card .hero .bg {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 20% 20%, var(--accent-tint), transparent 35%),
        radial-gradient(circle at 85% 80%, var(--accent-soft), transparent 42%),
        var(--surface-2);
}

.model-card .hero .model-thumb {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 0;
    object-fit: cover;
}

.model-card .hero .glyph {
    position: relative;
    z-index: 1;
    color: var(--ink);
    font-size: 56px;
    font-weight: 750;
    letter-spacing: -0.04em;
}

.model-card .hero .corner {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 2;
    display: flex;
    gap: 6px;
}

.model-card .hero .corner .chip {
    background: rgba(255, 253, 247, 0.72);
    backdrop-filter: blur(8px);
}

:root[data-theme="dark"] .model-card .hero .corner .chip {
    background: rgba(15, 13, 10, 0.72);
}

.model-card .body {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 16px 18px 18px;
}

.model-card .name {
    color: var(--ink);
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.model-card .desc {
    min-height: 38px;
    color: var(--muted);
    font-size: 12.5px;
    line-height: 1.5;
}

.model-card .tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.model-card .specs {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-top: 8px;
    padding-top: 12px;
    border-top: 1px dashed var(--line);
    color: var(--muted);
    font-size: 11.5px;
}

.model-card .specs .item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.model-card .specs .v {
    color: var(--ink);
    font-family: var(--font-mono);
    font-weight: 700;
}

.model-card .sync-item {
    margin-left: auto;
}

/* Modal and login */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(10, 8, 6, 0.62);
    backdrop-filter: blur(8px);
}

.modal-card {
    width: min(920px, 100%);
    max-height: 92vh;
    overflow: auto;
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
}

.modal-media {
    width: 100%;
    aspect-ratio: 16 / 10;
    overflow: hidden;
    margin: 18px 0;
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    background: var(--surface-2);
}

.guest-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at 20% 10%, var(--accent-soft), transparent 24rem),
        var(--bg);
}

.guest-card {
    width: min(440px, 100%);
}

/* Responsive */
@media (max-width: 1180px) {
    .stats-row {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .home-grid,
    .generator-layout,
    .split,
    .provider-layout {
        grid-template-columns: 1fr;
    }

    .result-column {
        position: static;
    }

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

@media (max-width: 860px) {
    .app,
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

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

    .topbar {
        padding: 18px 16px 0;
    }

    .workspace-pill {
        display: none;
    }

    .page {
        padding: 24px 16px 48px;
    }

    .page-head {
        flex-direction: column;
    }

    .page-head h1 {
        font-size: 38px;
    }

    .quota-strip,
    .stats-row,
    .settings-grid,
    .aspect-options,
    .sync-strip {
        grid-template-columns: 1fr;
    }

    .prompt-head,
    .prompt-foot,
    .sync-current-panel {
        flex-direction: column;
        align-items: stretch;
    }

    .seg {
        width: 100%;
    }

    .row.gap-sm {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
    }

    .gal-grid,
    .gallery-grid,
    .model-grid {
        grid-template-columns: 1fr;
    }

    .gal-tile .overlay {
        opacity: 1;
    }

    .ov-actions {
        flex-direction: column;
    }

    .table-head {
        flex-direction: column;
    }
}
