:root {
    --bg: #fcfdfe;
    --bg-dark: #0b0d11;
    --panel: #ffffff;
    --panel-dark: #161920;
    --text: #0f172a;
    --text-dark: #e2e8f0;
    --muted: #64748b;
    --muted-dark: #94a3b8;
    --border: rgba(148, 163, 184, 0.3);
    --border-dark: rgba(255, 255, 255, 0.1);
    --danger: #ef4444;
    --vibrant: linear-gradient(135deg, #6366f1 0%, #3b82f6 50%, #2dd4bf 100%);
    --code-bg: #0b1020;
}

:root[data-theme='dark'] {
    --bg: var(--bg-dark);
    --panel: var(--panel-dark);
    --text: var(--text-dark);
    --muted: var(--muted-dark);
    --border: var(--border-dark);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Plus Jakarta Sans', sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 28px;
    position: relative;
    overflow: hidden;
    background:
        radial-gradient(850px 340px at 10% 0%, rgba(37, 99, 235, 0.15), transparent 70%),
        radial-gradient(760px 320px at 100% 100%, rgba(45, 212, 191, 0.14), transparent 70%),
        var(--bg);
}

.login-glow {
    position: absolute;
    border-radius: 999px;
    filter: blur(42px);
    pointer-events: none;
}

.login-glow-a {
    width: 280px;
    height: 280px;
    top: -80px;
    left: -60px;
    background: rgba(59, 130, 246, 0.22);
}

.login-glow-b {
    width: 280px;
    height: 280px;
    bottom: -90px;
    right: -70px;
    background: rgba(20, 184, 166, 0.22);
}

.login-card {
    width: min(520px, 100%);
    border: 1px solid var(--border);
    border-radius: 24px;
    background: color-mix(in srgb, var(--panel), transparent 5%);
    box-shadow: 0 30px 90px rgba(15, 23, 42, 0.17);
    padding: 24px;
    position: relative;
    z-index: 1;
}

.login-brand {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
    margin-bottom: 12px;
}

.login-logo-image {
    display: block;
    width: min(240px, 100%);
    height: auto;
}

.admin-login-logo {
    width: min(220px, 100%);
}

.login-brand h1 {
    margin: 2px 0 0;
    font-size: 22px;
    font-weight: 800;
}

.login-form {
    display: grid;
    gap: 10px;
    margin-top: 14px;
}

.login-submit {
    width: 100%;
    margin-top: 2px;
}

.login-switches {
    margin-top: 8px;
}

.material-symbols-outlined {
    font-variation-settings: 'FILL' 0, 'wght' 500, 'GRAD' 0, 'opsz' 24;
}

.app-shell {
    display: flex;
    width: 100%;
    height: 100vh;
    position: relative;
}

.sidebar {
    width: 300px;
    flex-shrink: 0;
    border-right: 1px solid var(--border);
    padding: 24px 18px;
    display: flex;
    flex-direction: column;
    background: color-mix(in srgb, var(--panel), transparent 20%);
    backdrop-filter: blur(14px);
}

.brand-row {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    margin-bottom: 20px;
}

.brand-logo-image {
    display: block;
    width: min(210px, 100%);
    height: auto;
}

.brand-icon {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    color: #fff;
    background: var(--vibrant);
    box-shadow: 0 8px 20px rgba(59, 130, 246, 0.32);
}

.brand-title {
    margin: 0;
    font-size: 18px;
    font-weight: 800;
}

.primary-btn {
    border: none;
    border-radius: 16px;
    background: var(--vibrant);
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    padding: 12px 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
}

.sidebar-heading {
    margin-top: 24px;
    margin-bottom: 12px;
    font-size: 10px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    font-weight: 800;
    color: var(--muted);
}

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

.history-item {
    border: 1px solid transparent;
    background: transparent;
    color: var(--text);
    border-radius: 14px;
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    cursor: pointer;
    display: block;
}

.history-item.active {
    border-color: var(--border);
    background: color-mix(in srgb, var(--panel), transparent 10%);
}

.history-item-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.history-item-title {
    display: block;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 165px;
}

.history-item-meta {
    display: block;
    font-size: 11px;
    color: var(--muted);
    margin-top: 4px;
}

.history-delete {
    border: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
    font-size: 10px;
    border-radius: 7px;
    padding: 3px 7px;
    line-height: 1;
}

.history-delete:hover {
    color: #fff;
    background: #ef4444;
    border-color: #ef4444;
}

.sidebar-footer {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
}

.account-card {
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 10px;
    background: color-mix(in srgb, var(--panel), transparent 8%);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.account-meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-height: 36px;
}

.account-meta strong {
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

.sidebar-actions #logout {
    flex: 1;
}

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-header {
    height: 74px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    background: color-mix(in srgb, var(--panel), transparent 35%);
    backdrop-filter: blur(8px);
}

.chat-title {
    margin: 0;
    font-size: 16px;
    font-weight: 800;
}

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

.chat-header-actions select {
    min-width: 220px;
}

.auth-panel {
    flex: 1;
    display: grid;
    place-items: center;
    padding: 20px;
}

.auth-card {
    width: min(460px, 100%);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 18px;
    background: var(--panel);
}

.auth-card h3 {
    margin: 0 0 12px;
}

.chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 16px 20px 18px;
    gap: 12px;
}

.member-bar {
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 10px 12px;
    background: var(--panel);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-window {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: color-mix(in srgb, var(--panel), transparent 5%);
    padding: 16px;
}

.msg {
    max-width: 86%;
    padding: 12px 14px;
    border-radius: 18px;
    margin-bottom: 12px;
    border: 1px solid var(--border);
    background: var(--panel);
    line-height: 1.6;
    box-shadow: 0 5px 22px rgba(15, 23, 42, 0.06);
}

.msg.user {
    margin-left: auto;
    background: var(--vibrant);
    color: #fff;
    border: none;
}

.msg strong {
    display: inline-block;
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    margin-bottom: 6px;
}

.msg.user .muted {
    color: rgba(255, 255, 255, 0.75);
}

.msg.assistant .message-content {
    color: var(--text);
}

.msg.assistant.streaming {
    border-style: dashed;
    border-color: color-mix(in srgb, #3b82f6, var(--border) 45%);
}

.msg.assistant .message-content img {
    max-width: min(560px, 100%);
    border-radius: 14px;
    border: 1px solid var(--border);
    margin-top: 8px;
    display: block;
    cursor: zoom-in;
}

.image-card {
    margin-top: 8px;
}

.image-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 6px;
}

.image-download-btn {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px 10px;
    color: var(--text);
    text-decoration: none;
    font-size: 11px;
    font-weight: 700;
    background: color-mix(in srgb, var(--panel), transparent 8%);
}

.image-download-btn:hover {
    border-color: color-mix(in srgb, #3b82f6, var(--border) 55%);
    color: #3b82f6;
}

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 1200;
    background: rgba(2, 6, 23, 0.86);
    display: grid;
    place-items: center;
    padding: 24px;
}

.lightbox-image {
    max-width: min(1200px, 94vw);
    max-height: 88vh;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
    object-fit: contain;
}

.lightbox-actions {
    position: fixed;
    top: 18px;
    right: 18px;
    display: flex;
    gap: 8px;
}

.lightbox-download {
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: rgba(15, 23, 42, 0.72);
    color: #fff;
    border-radius: 10px;
    padding: 7px 10px;
    font-size: 12px;
    font-weight: 700;
    text-decoration: none;
}

.lightbox-download:hover {
    border-color: rgba(96, 165, 250, 0.8);
    color: #93c5fd;
}

.lightbox-close {
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: rgba(15, 23, 42, 0.72);
    color: #fff;
    border-radius: 10px;
    padding: 7px 10px;
    font-size: 12px;
    font-weight: 700;
}

body.lightbox-open {
    overflow: hidden;
}

.code-block {
    margin-top: 10px;
    border-radius: 14px;
    overflow: hidden;
    border: 1px solid rgba(148, 163, 184, 0.3);
}

.code-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    font-size: 11px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    background: #111827;
    color: #cbd5e1;
}

.copy-code-btn {
    border: 1px solid rgba(148, 163, 184, 0.35);
    border-radius: 8px;
    padding: 4px 8px;
    font-size: 10px;
    color: #e2e8f0;
    background: rgba(148, 163, 184, 0.15);
    cursor: pointer;
}

.copy-code-btn:hover {
    background: rgba(96, 165, 250, 0.22);
}

.code-block pre {
    margin: 0;
    padding: 14px;
    overflow-x: auto;
    background: var(--code-bg);
}

.code-block code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', monospace;
    font-size: 13px;
    color: #dbeafe;
    display: block;
    white-space: pre;
}

.code-block .token.keyword { color: #93c5fd; }
.code-block .token.string { color: #86efac; }
.code-block .token.number { color: #f9a8d4; }
.code-block .token.function { color: #fcd34d; }
.code-block .token.comment { color: #64748b; font-style: italic; }
.code-block .token.operator,
.code-block .token.punctuation { color: #c7d2fe; }
.code-block .token.boolean,
.code-block .token.constant,
.code-block .token.property { color: #fca5a5; }

.composer {
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 8px;
    background: var(--panel);
}

.composer textarea {
    width: 100%;
    min-height: 64px;
    max-height: 220px;
    resize: vertical;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text);
    font-size: 15px;
    line-height: 1.55;
    padding: 10px 12px;
}

.flux-controls {
    display: flex;
    gap: 8px;
    padding: 0 10px 8px;
}

.flux-controls select,
.flux-controls input {
    margin: 0;
}

.composer-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 0 8px 4px;
}

.composer-tools {
    display: flex;
    gap: 4px;
}

.send-btn {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    border: none;
    background: var(--vibrant);
    color: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
}

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

input,
select {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 9px 10px;
    background: transparent;
    color: var(--text);
}

button {
    cursor: pointer;
}

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

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

.error {
    margin-top: 8px;
    color: var(--danger);
}

.hidden { display: none !important; }

.ghost {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: transparent;
    color: var(--text);
    padding: 8px 10px;
}

.ghost.danger {
    color: var(--danger);
    border-color: color-mix(in srgb, var(--danger), var(--border) 65%);
}

.icon-btn {
    width: 38px;
    height: 38px;
    padding: 0;
    display: grid;
    place-items: center;
}

@media (max-width: 1100px) {
    .sidebar {
        width: 250px;
    }
}

@media (max-width: 900px) {
    .sidebar {
        display: none;
    }

    .chat-header {
        padding: 10px 12px;
        height: auto;
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .chat-header-actions {
        width: 100%;
        flex-wrap: wrap;
    }

    .chat-header-actions select {
        min-width: 0;
        flex: 1;
    }

    .chat-panel {
        padding: 10px;
    }

    .msg {
        max-width: 100%;
    }
}

/* Admin Dashboard */
.admin-body {
    font-family: 'Space Grotesk', 'Plus Jakarta Sans', sans-serif;
    background: var(--bg);
}

.admin-shell {
    display: flex;
    width: 100%;
    height: 100vh;
    overflow: hidden;
}

.admin-sidebar {
    width: 260px;
    flex-shrink: 0;
    border-right: 1px solid var(--border);
    background: var(--panel);
    display: flex;
    flex-direction: column;
    padding: 16px;
}

.admin-brand {
    display: block;
    padding: 8px;
}

.admin-logo-image {
    display: block;
    width: min(210px, 100%);
    height: auto;
}

.admin-brand h1 {
    font-size: 18px;
    margin: 0;
}

.admin-brand p {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
}

.admin-brand-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    color: #fff;
    background: #3c83f6;
}

.admin-nav {
    margin-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.admin-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    border: none;
    border-left: 4px solid transparent;
    background: transparent;
    color: var(--muted);
    font-weight: 600;
    padding: 12px;
    border-radius: 10px;
    text-align: left;
}

.admin-nav-item.active {
    color: #3c83f6;
    background: color-mix(in srgb, #3c83f6, transparent 85%);
    border-left-color: #3c83f6;
}

.admin-sidebar-footer {
    margin-top: auto;
    display: flex;
    gap: 8px;
}

.admin-sidebar-footer #admin-logout {
    flex: 1;
}

.admin-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.admin-header {
    height: 72px;
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: color-mix(in srgb, var(--panel), transparent 20%);
    backdrop-filter: blur(10px);
}

.admin-header h2 {
    margin: 0;
    font-size: 22px;
}

.admin-header-actions input {
    width: 280px;
    max-width: 42vw;
}

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

.admin-status {
    margin: 6px 0 0;
    font-size: 12px;
    min-height: 18px;
    color: var(--muted);
}

.admin-status[data-kind="success"] {
    color: #16a34a;
}

.admin-status[data-kind="error"] {
    color: var(--danger);
}

.admin-status[data-kind="info"] {
    color: #2563eb;
}

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

.admin-metric-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px;
}

.admin-metric-card p {
    margin: 6px 0;
    color: var(--muted);
    font-weight: 600;
    font-size: 13px;
}

.admin-metric-card h3 {
    margin: 0;
    font-size: 34px;
    line-height: 1.1;
}

.admin-metric-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.admin-chip {
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    padding: 4px 8px;
    color: #3c83f6;
    background: color-mix(in srgb, #3c83f6, transparent 85%);
}

.admin-grid {
    flex: 1;
    min-height: 0;
    padding: 18px 24px 24px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

.admin-grid.single-panel {
    grid-template-columns: 1fr;
}

.admin-panel {
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px;
}

.admin-panel h3,
.admin-panel h4 {
    margin: 0 0 10px;
}

.admin-section-card {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    background: color-mix(in srgb, var(--panel), transparent 4%);
    margin-top: 12px;
}

.admin-section-card h4 {
    margin: 0 0 10px;
}

.admin-form {
    display: grid;
    gap: 8px;
}

.admin-scroll {
    min-height: 120px;
    max-height: 260px;
    overflow: auto;
    margin-bottom: 10px;
}

.admin-panel .card {
    margin: 0 0 8px;
    box-shadow: none;
}

.admin-log-card {
    margin-top: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    background: color-mix(in srgb, var(--panel), transparent 4%);
}

.admin-log-card h4 {
    margin: 0 0 10px;
}

.overview-log-list .card {
    border-radius: 10px;
    padding: 10px 12px;
}

.overview-log-list .card strong {
    font-size: 13px;
}

#models-list .card {
    border: none;
    border-radius: 0;
    background: transparent;
    padding: 10px 0;
    margin: 0;
}

#models-list .card:not(:last-child) {
    border-bottom: 1px dashed color-mix(in srgb, var(--text), transparent 76%);
}

.admin-panel.is-loading {
    opacity: 0.65;
    pointer-events: none;
}

.small-btn {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 600;
}

.small-btn.delete,
.small-btn.model-delete {
    color: var(--danger);
    border-color: color-mix(in srgb, var(--danger), var(--border) 60%);
}

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

.inline-edit-form {
    margin-top: 10px;
    border: 1px dashed var(--border);
    border-radius: 10px;
    padding: 10px;
    display: grid;
    gap: 8px;
    background: color-mix(in srgb, var(--panel), transparent 6%);
}

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

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

@media (max-width: 900px) {
    .admin-sidebar {
        display: none;
    }

    .admin-header {
        height: auto;
        padding: 14px;
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .admin-header-actions input {
        width: 100%;
        max-width: 100%;
    }

    .admin-grid {
        grid-template-columns: 1fr;
        padding-left: 12px;
        padding-right: 12px;
    }

    .admin-metrics {
        grid-template-columns: 1fr;
    }
}
