:root {
    color-scheme: light;
    --bg: #f5f7fb;
    --panel: #ffffff;
    --text: #182033;
    --muted: #687086;
    --line: #dfe4ee;
    --accent: #126d63;
    --accent-strong: #0c4d46;
    --danger: #b42318;
    --warn: #a15c07;
    --code: #101828;
    --soft: #edf3f2;
    --toast-bg: #182033;
    --toast-text: #f5f7fb;
    --toast-error: #b42318;
    --skeleton: #e2e7f0;
    --sidebar-bg: #ffffff;
}

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
        --bg: #0a0c14;
        --panel: #12141e;
        --text: #d1d6e0;
        --muted: #6b748a;
        --line: #222639;
        --accent: #23b5a4;
        --accent-strong: #4dd4c4;
        --danger: #f04438;
        --warn: #f5a623;
        --code: #0d0f18;
        --soft: #181b28;
        --toast-bg: #d1d6e0;
        --toast-text: #0a0c14;
        --toast-error: #f04438;
        --skeleton: #1e2233;
        --sidebar-bg: #12141e;
    }

    .connection {
        background: #0e101b;
        border-color: var(--line);
    }

    .usage-stat {
        background: var(--panel);
        border-color: var(--line);
    }

    .usage-bar-row {
        background: var(--panel);
    }

    .usage-range-form input,
    .usage-range-form select {
        background: #0a0c14;
        color: var(--text);
    }

    .tag {
        background: #181b28;
        color: #9aa3b8;
    }

    .response-box {
        background: var(--panel);
        border-color: var(--line);
    }

    .request-section {
        background: var(--panel);
        border-color: var(--line);
    }

    .usage-card {
        background: #0e101b;
        border-color: var(--line);
    }

    .request-summary article {
        background: var(--panel);
        border-color: var(--line);
    }

    .request-summary article.good {
        border-color: #14383a;
        background: #0e1c1e;
    }

    .request-summary article.bad {
        border-color: #3a1a1a;
        background: #1e1010;
    }

    .image-preview {
        background: var(--panel);
    }

    .worker-card {
        background: var(--panel);
    }

    .worker-summary {
        background: #0e101b;
    }

    .api-card {
        background: var(--panel);
    }

    .overview-row {
        background: var(--panel);
        border-color: var(--line);
    }

    .overview-worker-card {
        border-color: var(--line);
    }

    .tab,
    .token-copy,
    .link-button {
        background: var(--panel);
        border-color: var(--line);
        color: var(--text);
    }

    .tab.active {
        border-color: #1d403a;
        background: #0e1c1e;
        color: var(--accent-strong);
    }

    .link-button {
        color: var(--accent-strong);
    }

    .usage-stat.good {
        border-color: #14383a;
        background: #0e1c1e;
    }

    .usage-stat.bad {
        border-color: #3a1a1a;
        background: #1e1010;
    }

    .usage-stat.stat-green {
        border-color: #14383a;
        background: #0e1c1e;
    }

    .usage-stat.stat-yellow {
        border-color: #3a2e14;
        background: #1e1a0e;
    }

    .usage-stat.stat-red {
        border-color: #3a1a1a;
        background: #1e1010;
    }

    .usage-stat.stat-gray {
        border-color: var(--line);
        background: var(--panel);
    }

    .worker-bar,
    .mini-bar-track,
    .share-track,
    .usage-row-track {
        background: #1e2233;
    }

    .login-card {
        background: var(--panel);
    }

    .pill {
        background: #1e2233;
    }

    .pill.admin {
        background: #0e1c1e;
        color: var(--accent-strong);
    }

    .pill.client {
        background: #1e1a0e;
        color: var(--warn);
    }

    .queue-card {
        border-color: var(--line);
        background: var(--panel);
    }

    .queue-row {
        border-color: var(--line);
    }

    .created-token {
        color: var(--accent-strong);
    }

    .muted-block {
        border-color: var(--line);
    }

    .list-empty {
        border-color: var(--line);
    }

    .queue-empty {
        border-color: var(--line);
    }

    .overview-worker-head span {
        background: #1e2233;
        color: var(--muted);
    }

    .usage-grid div {
        border-color: var(--line);
        background: var(--panel);
    }

    .request-row {
        border-color: var(--line);
    }

    .request-details {
        background: var(--panel);
        border-color: var(--line);
    }

    .request-details[open] summary {
        border-color: var(--line);
    }
}

* {
    box-sizing: border-box;
}

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

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

button {
    cursor: pointer;
}

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

.hidden {
    display: none !important;
}

/* ── Toast ── */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 9999;
    display: grid;
    gap: 8px;
    max-width: 420px;
    width: 100%;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 16px;
    border-radius: 8px;
    background: var(--toast-bg);
    color: var(--toast-text);
    font-size: 14px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    animation: toast-in 0.2s ease-out;
    word-break: break-word;
}

.toast.error {
    background: var(--toast-error);
    color: #fff;
}

.toast button {
    flex: 0 0 auto;
    background: transparent;
    border: 0;
    color: inherit;
    opacity: 0.7;
    font-size: 16px;
    padding: 2px 4px;
}

.toast button:hover {
    opacity: 1;
}

@keyframes toast-in {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes toast-out {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

.toast.dismissing {
    animation: toast-out 0.2s ease-in forwards;
}

/* ── Disconnect banner ── */
.disconnect-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    margin-bottom: 12px;
    border-radius: 8px;
    background: var(--danger);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
}

.disconnect-banner .small {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    border: 0;
}

/* ── Loading skeleton ── */
.loading-skeleton {
    margin-bottom: 16px;
}

.skeleton-metrics {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.skeleton {
    border-radius: 8px;
    background: var(--skeleton);
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}

.skeleton.metric {
    height: 82px;
}

.skeleton-panels {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.skeleton.panel-lg {
    height: 200px;
}

@keyframes skeleton-pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* ── Login ── */
.login-screen {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-card {
    width: min(100%, 440px);
    display: grid;
    gap: 22px;
    padding: 28px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.login-brand {
    padding-bottom: 4px;
}

.connection-details {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--soft);
    overflow: hidden;
}

.connection-details summary {
    padding: 10px 14px;
    cursor: pointer;
    font-size: 13px;
    color: var(--muted);
    font-weight: 600;
}

.connection-details[open] .connection {
    border-top: 1px solid var(--line);
    border-radius: 0;
}

.connection-details .connection {
    border: 0;
    border-radius: 0;
}

/* ── Sidebar ── */
.sidebar {
    border-right: 1px solid var(--line);
    background: var(--sidebar-bg);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 22px;
    transition: margin-left 0.2s ease;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.sidebar-toggle {
    flex: 0 0 auto;
}

.sidebar.collapsed {
    margin-left: -304px;
}

@media (max-width: 980px) {
    .sidebar {
        margin-left: 0;
    }
    .sidebar.collapsed {
        margin-left: -100%;
    }
}

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

.brand-mark {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-weight: 800;
}

.brand h1,
.brand p,
.topbar h2,
.panel h3 {
    margin: 0;
}

.brand h1 {
    font-size: 20px;
}

.brand p,
.connection span,
.metric span,
label {
    color: var(--muted);
    font-size: 13px;
}

.login-panel {
    display: grid;
    gap: 10px;
}

.token-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 40px;
    gap: 8px;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--text);
    background: #fff;
    padding: 10px 11px;
    outline: none;
}

@media (prefers-color-scheme: dark) {
    input,
    select,
    textarea {
        background: #0a0c14;
        color: var(--text);
        border-color: var(--line);
    }
}

textarea {
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(18, 109, 99, 0.14);
}

@media (prefers-color-scheme: dark) {
    input:focus,
    select:focus,
    textarea:focus {
        box-shadow: 0 0 0 3px rgba(35, 181, 164, 0.2);
    }
}

.primary,
.secondary,
.danger,
.small,
.icon-button,
.nav-button {
    border: 1px solid transparent;
    border-radius: 6px;
    min-height: 38px;
    padding: 8px 12px;
    background: #fff;
    color: var(--text);
}

@media (prefers-color-scheme: dark) {
    .primary,
    .secondary,
    .danger,
    .small,
    .icon-button,
    .nav-button {
        background: #1e2233;
        color: var(--text);
    }

    .primary {
        background: var(--accent);
        color: #fff;
    }

    .danger {
        background: var(--danger);
        color: #fff;
    }

    .nav-button.active {
        background: var(--soft);
    }
}

.primary {
    background: var(--accent);
    color: #fff;
}

.primary:hover {
    background: var(--accent-strong);
}

.primary:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    background: var(--accent);
}

.secondary,
.small,
.icon-button {
    border-color: var(--line);
}

.danger {
    background: var(--danger);
    color: #fff;
}

.danger:hover {
    opacity: 0.88;
}

.small {
    min-height: 32px;
    padding: 5px 9px;
    font-size: 13px;
}

.connection {
    display: grid;
    gap: 10px;
    padding: 14px;
    background: var(--soft);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.connection div {
    display: grid;
    gap: 3px;
}

code {
    overflow-wrap: anywhere;
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 12px;
}

nav {
    display: grid;
    gap: 6px;
}

.nav-button {
    text-align: left;
    color: var(--muted);
}

.nav-button.active {
    background: var(--soft);
    color: var(--accent-strong);
}

.nav-button::after {
    content: attr(data-shortcut);
    float: right;
    opacity: 0.4;
    font-size: 11px;
    font-weight: 600;
}

.admin-only.hidden,
.management-read.hidden,
.admin-write.hidden {
    display: none;
}

main {
    min-width: 0;
    padding: 24px;
}

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

.topbar h2 {
    margin-top: 6px;
    font-size: 28px;
}

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

.refresh-control {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
}

.refresh-control select {
    width: 96px;
    min-height: 38px;
}

.pill {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    min-height: 26px;
    margin: 0;
    border-radius: 999px;
    padding: 4px 10px;
    background: #edf0f5;
    color: var(--muted);
    font-size: 13px;
}

.pill.admin {
    background: #e7f8f5;
    color: var(--accent-strong);
}

.pill.client {
    background: #fff4e6;
    color: var(--warn);
}

@media (prefers-color-scheme: dark) {
    .pill {
        background: #1e2233;
    }
    .pill.admin {
        background: #14383a;
    }
    .pill.client {
        background: #3a2e14;
    }
}

.status-line {
    min-height: 40px;
    margin-bottom: 16px;
    padding: 11px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--muted);
}

.status-line.error {
    border-color: var(--danger);
    color: var(--danger);
}

.view {
    display: none;
}

.view.active {
    display: block;
}

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

.metric,
.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.metric {
    padding: 16px;
    display: grid;
    gap: 8px;
}

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

.panel {
    margin-top: 16px;
    padding: 16px;
    min-width: 0;
}

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

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

.compact-input {
    width: min(260px, 34vw);
    min-height: 32px;
    padding: 6px 9px;
    font-size: 13px;
}

.panel h3 {
    font-size: 16px;
}

.panel-subtitle {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.inline-status {
    margin: 4px 0 14px;
    color: var(--muted);
    font-size: 13px;
}

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

.overview-lower,
.model-console {
    margin-top: 16px;
}

.model-chat-grid {
    display: grid;
    grid-template-columns: minmax(280px, 1fr) minmax(0, 2fr);
    gap: 16px;
    align-items: start;
}

.chat-pane,
.request-pane {
    min-width: 0;
}

.request-pane {
    padding: 14px;
}

.request-pane-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--line);
}

.request-pane h3 {
    margin: 0;
    font-size: 15px;
}

.mini-pill {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    border-radius: 999px;
    padding: 3px 9px;
    background: var(--panel);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0;
}

.mini-pill.running {
    background: #fff4e6;
    color: var(--warn);
}

.mini-pill.done {
    background: #0e1c1e;
    color: var(--accent-strong);
}

.mini-pill.error {
    background: #1e1010;
    color: var(--danger);
}

.request-info {
    display: grid;
    gap: 14px;
}

.request-summary {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 8px;
}

.request-summary article {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 9px 10px;
}

.request-summary article.good {
    border-color: #addbd3;
    background: var(--panel);
}

.request-summary article.bad {
    border-color: #f0b8b3;
    background: var(--panel);
}

.request-summary span {
    display: block;
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
}

.request-summary strong {
    display: block;
    min-width: 0;
    margin-top: 4px;
    color: var(--text);
    font-size: 17px;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.request-card-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(180px, 1fr));
    gap: 10px;
    align-items: start;
}

.request-section {
    display: grid;
    gap: 7px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 10px;
}

.request-section h4 {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

.request-row {
    display: grid;
    grid-template-columns: minmax(72px, 0.42fr) minmax(0, 1fr);
    gap: 10px;
    align-items: baseline;
    min-height: 26px;
    border-top: 1px solid var(--line);
    padding-top: 7px;
    font-size: 13px;
}

.request-row:first-of-type {
    border-top: 0;
    padding-top: 0;
}

.request-row span {
    color: var(--muted);
}

.request-row strong {
    min-width: 0;
    overflow-wrap: anywhere;
    font-weight: 600;
}

.usage-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 12px;
}

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

.usage-head h4 {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

.usage-head strong {
    color: var(--accent-strong);
    font-size: 20px;
}

.usage-bar {
    height: 12px;
    display: flex;
    overflow: hidden;
    border-radius: 999px;
    background: var(--line);
}

.usage-bar span {
    display: block;
    min-width: 2px;
    background: var(--accent);
}

.usage-bar .prompt {
    background: #126d63;
}

.usage-bar .completion {
    background: #6a5acd;
}

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

.usage-grid div {
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel);
    padding: 8px;
}

.usage-grid span {
    display: block;
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
}

.usage-grid strong {
    display: block;
    margin-top: 3px;
    font-size: 15px;
}

.stats-head {
    align-items: end;
}

.usage-range-form {
    display: grid;
    grid-template-columns: 140px 150px 150px auto;
    gap: 8px;
    align-items: end;
}

.usage-range-form input,
.usage-range-form select {
    min-height: 38px;
}

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

.usage-stat {
    min-width: 0;
    display: grid;
    gap: 5px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 12px;
}

.usage-stat.good {
    border-color: #addbd3;
    background: var(--panel);
}

.usage-stat.bad {
    border-color: #f0b8b3;
    background: var(--panel);
}

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

.usage-stat span {
    text-transform: uppercase;
    font-weight: 700;
}

.usage-stat strong {
    min-width: 0;
    color: var(--text);
    font-size: 24px;
    line-height: 1.15;
    overflow-wrap: anywhere;
}

.my-limits-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.usage-stat.stat-green {
    border-color: #addbd3;
    background: var(--panel);
}

.usage-stat.stat-yellow {
    border-color: #f3d188;
    background: var(--panel);
}

.usage-stat.stat-red {
    border-color: #f0b8b3;
    background: var(--panel);
}

.usage-stat.stat-gray {
    border-color: var(--line);
    background: var(--panel);
}

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

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

.chart-panel {
    min-height: 250px;
}

.chart-box {
    min-height: 140px;
}

.mini-bars {
    height: 150px;
    display: flex;
    align-items: stretch;
    justify-content: center;
    gap: 7px;
    padding-top: 4px;
}

.mini-bar-item {
    min-width: 0;
    flex: 0 1 34px;
    max-width: 42px;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 7px;
}

.mini-bar-track {
    position: relative;
    min-height: 0;
    overflow: hidden;
    border-radius: 6px;
    background: var(--line);
}

.mini-bar-fill,
.mini-bar-error {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    border-radius: 6px 6px 0 0;
}

.mini-bar-fill {
    background: var(--accent);
}

.mini-bar-error {
    background: var(--danger);
    opacity: 0.88;
}

.mini-bar-item small {
    min-width: 0;
    color: var(--muted);
    font-size: 11px;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
}

.share-list {
    display: grid;
    gap: 9px;
}

.share-row {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(90px, 1fr) 44px;
    gap: 10px;
    align-items: center;
}

.share-row div:first-child {
    min-width: 0;
    display: grid;
    gap: 2px;
}

.share-row strong,
.share-row span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.share-row span {
    color: var(--muted);
    font-size: 12px;
}

.share-row b {
    text-align: right;
}

.share-track {
    height: 9px;
    overflow: hidden;
    border-radius: 999px;
    background: var(--line);
}

.share-track span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
}

.usage-bars {
    display: grid;
    gap: 10px;
}

.usage-bar-row {
    display: grid;
    gap: 8px;
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 10px;
}

.usage-bar-row div:first-child {
    min-width: 0;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: baseline;
}

.usage-bar-row strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.usage-bar-row span {
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 12px;
}

.usage-row-track {
    height: 9px;
    overflow: hidden;
    border-radius: 999px;
    background: var(--line);
}

.usage-row-track span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
}

.error-text {
    color: var(--danger);
    font-weight: 700;
}

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

.request-details summary {
    min-height: 38px;
    display: flex;
    align-items: center;
    padding: 9px 10px;
    color: var(--muted);
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

.request-details[open] summary {
    border-bottom: 1px solid var(--line);
}

.request-json {
    max-height: 240px;
    min-height: 0;
    margin: 0;
    overflow: auto;
    border-radius: 0;
    background: var(--code);
    color: #e6edf3;
    padding: 12px;
    font-size: 12px;
    line-height: 1.45;
    white-space: pre-wrap;
}

.compact-empty {
    min-height: 86px;
}

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

.overview-worker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 10px;
}

.overview-worker-card {
    display: grid;
    gap: 10px;
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 12px;
}

.overview-worker-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.overview-worker-head strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.overview-worker-head span {
    flex: 0 0 auto;
    border-radius: 999px;
    padding: 3px 8px;
    background: var(--panel);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.overview-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    min-height: 34px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel);
}

.overview-row span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.overview-row strong {
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}

.muted-block {
    min-height: 88px;
    display: grid;
    place-items: center;
    color: var(--muted);
    border: 1px dashed var(--line);
    border-radius: 8px;
}

.json-box,
.stream-box {
    margin: 0;
    min-height: 220px;
    max-height: 460px;
    overflow: auto;
    border-radius: 6px;
    padding: 12px;
    background: var(--code);
    color: #e6edf3;
    font-size: 12px;
    line-height: 1.5;
    white-space: pre-wrap;
}

/* ── Response box ── */
.response-wrap {
    display: grid;
    gap: 6px;
}

.response-head {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 28px;
}

.response-head-label {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

.response-box {
    min-height: 180px;
    max-height: 440px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
    background: var(--panel);
    color: var(--text);
    font-size: 14px;
    line-height: 1.6;
    white-space: pre-wrap;
    box-shadow: inset 3px 0 0 var(--accent);
}

.response-box.empty {
    display: grid;
    place-items: center;
    align-content: center;
    justify-items: center;
    text-align: center;
    color: var(--muted);
    box-shadow: none;
    border-style: dashed;
}

/* ── Spinner ── */
.button-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

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

/* ── Model mode group ── */
.model-mode-group {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.model-mode-group select {
    width: auto;
    min-width: 140px;
}

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

.prompt-form {
    display: grid;
    gap: 12px;
    margin-bottom: 12px;
}

.image-upload {
    display: grid;
    gap: 8px;
}

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

.image-upload-button {
    width: fit-content;
    min-height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel);
    color: var(--accent-strong);
    padding: 6px 10px;
    cursor: pointer;
}

.image-upload-button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.visually-hidden-file {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

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

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

.image-preview {
    min-width: 0;
    display: grid;
    grid-template-columns: 56px minmax(0, 1fr) 32px;
    gap: 10px;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 7px;
}

.image-preview img {
    width: 56px;
    height: 44px;
    object-fit: cover;
    border-radius: 6px;
    background: var(--panel);
}

.image-preview div {
    min-width: 0;
    display: grid;
    gap: 2px;
}

.image-preview strong,
.image-preview span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.image-preview strong {
    font-size: 13px;
}

.image-preview span {
    color: var(--muted);
    font-size: 12px;
}

.prompt-actions,
.inline-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
}

.inline-form {
    grid-template-columns: 1.1fr 120px 100px 1.2fr 1.2fr 110px auto;
    margin-bottom: 12px;
}

.inline-form.compact {
    grid-template-columns: minmax(0, 1fr) 180px auto;
    margin-bottom: 0;
}

.check {
    display: flex;
    align-items: center;
    gap: 7px;
    color: var(--text);
}

.check input {
    width: auto;
}

.table-wrap {
    overflow: auto;
}

/* ── Queue view ── */
.queue-view {
    display: grid;
    gap: 8px;
}

.queue-empty {
    min-height: 88px;
    display: grid;
    place-items: center;
    color: var(--muted);
    border: 1px dashed var(--line);
    border-radius: 8px;
}

.queue-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 12px;
    display: grid;
    gap: 10px;
}

.queue-card h4 {
    margin: 0;
    font-size: 14px;
    color: var(--muted);
    text-transform: uppercase;
}

.queue-rows {
    display: grid;
    gap: 6px;
}

.queue-row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: center;
    padding: 6px 8px;
    border: 1px solid var(--line);
    border-radius: 6px;
    font-size: 13px;
}

.queue-row strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.queue-row span {
    flex: 0 0 auto;
    font-weight: 600;
    color: var(--accent-strong);
}

.queue-row .queue-count-idle {
    color: var(--muted);
}

.worker-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

.worker-summary,
.worker-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.worker-summary {
    grid-column: 1 / -1;
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 12px 14px;
    background: var(--soft);
}

.worker-summary strong {
    color: var(--accent-strong);
    font-size: 22px;
}

.worker-summary span {
    color: var(--muted);
}

.worker-card {
    padding: 14px;
    display: grid;
    gap: 10px;
}

#workers-view .worker-card {
    grid-template-columns: 1.4fr 1fr 1fr;
    align-items: start;
}

#workers-view .worker-card-head,
#workers-view .worker-bar,
#workers-view .worker-foot,
#workers-view .worker-models {
    grid-column: 1 / -1;
}

.worker-card.load-red,
.overview-worker-card.load-red {
    border-color: #ef9a9a;
}

.worker-card.load-yellow,
.overview-worker-card.load-yellow {
    border-color: #f3d188;
}

.worker-card.load-green,
.overview-worker-card.load-green {
    border-color: #9bd5c9;
}

.worker-card.load-gray,
.overview-worker-card.load-gray {
    border-color: #e2e7f0;
}

.worker-card-head,
.worker-meta,
.worker-foot {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: center;
}

.worker-card-head strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.worker-card-head span {
    padding: 0;
    background: transparent;
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
}

.worker-meta span,
.worker-foot {
    color: var(--muted);
    font-size: 12px;
}

.worker-bar {
    height: 10px;
    overflow: hidden;
    border-radius: 999px;
    background: var(--line);
}

.worker-bar span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
}

.load-gray .worker-bar span {
    background: #a3adbd;
}

.load-green .worker-bar span {
    background: #12836f;
}

.load-yellow .worker-bar span {
    background: #d89a00;
}

.load-red .worker-bar span {
    background: var(--danger);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

th,
td {
    padding: 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

.tier-select {
    width: auto;
    min-width: 90px;
    padding: 4px 6px;
    font-size: 13px;
}

.sort-button {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 24px;
    border: 0;
    background: transparent;
    color: inherit;
    padding: 0;
    font: inherit;
    font-weight: inherit;
    text-transform: inherit;
}

.sort-button span {
    min-width: 10px;
    color: var(--accent);
}

.sort-button.active {
    color: var(--accent-strong);
}

.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tag {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 2px 7px;
    border-radius: 999px;
    background: var(--panel);
    color: var(--text);
    font-size: 12px;
}

.list-empty {
    min-height: 120px;
    display: grid;
    place-items: center;
    color: var(--muted);
    border: 1px dashed var(--line);
    border-radius: 8px;
}

.created-token {
    margin-bottom: 12px;
    color: var(--accent-strong);
    overflow-wrap: anywhere;
}

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.tab,
.link-button,
.token-copy {
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel);
    color: var(--text);
}

.tab {
    min-height: 34px;
    padding: 6px 11px;
}

.tab.active {
    border-color: var(--accent);
    background: var(--soft);
    color: var(--accent-strong);
}

.link-button {
    max-width: 100%;
    padding: 6px 8px;
    color: var(--accent-strong);
    text-align: left;
    overflow-wrap: anywhere;
}

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

.token-copy {
    max-width: 180px;
    padding: 6px 8px;
    color: var(--accent-strong);
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.token-copy:hover {
    border-color: var(--accent);
    background: var(--soft);
}

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

.api-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
}

.api-card h3 {
    margin: 0 0 10px;
    font-size: 15px;
}

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

.endpoint {
    display: grid;
    grid-template-columns: 64px minmax(0, 1fr);
    gap: 8px;
    align-items: start;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: background 0.1s;
}

.endpoint:hover {
    background: var(--soft);
}

.method {
    font-size: 11px;
    font-weight: 800;
    color: #fff;
    border-radius: 5px;
    padding: 3px 5px;
    text-align: center;
    background: #667085;
}

.method.post {
    background: #126d63;
}

.method.delete {
    background: #b42318;
}

.method.patch {
    background: #6941c6;
}

.path {
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 12px;
    overflow-wrap: anywhere;
}

.scope {
    color: var(--muted);
    font-size: 12px;
    margin-top: 2px;
}

/* ── API Play Button ── */
.api-play-btn {
    justify-self: end;
    align-self: center;
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, transform 0.1s;
    flex-shrink: 0;
    line-height: 1;
}
.api-play-btn:hover {
    background: var(--accent-strong);
    transform: scale(1.1);
}
.endpoint {
    grid-template-columns: 64px minmax(0, 1fr) auto;
}

/* ── API Play Modal ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-content {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    width: min(700px, 90vw);
    max-height: 85vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--line);
}
.modal-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 600;
    overflow: hidden;
}
.modal-title .method {
    flex-shrink: 0;
}
.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--muted);
    padding: 0 4px;
    line-height: 1;
}
.modal-close:hover {
    color: var(--text);
}
.modal-body {
    padding: 20px;
}
.modal-body .form-group {
    margin-bottom: 12px;
}
.modal-body .form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text);
}
.code-textarea {
    width: 100%;
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 13px;
    padding: 10px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 6px;
    resize: vertical;
    tab-size: 2;
    box-sizing: border-box;
}
.code-textarea.readonly {
    opacity: 0.7;
    cursor: default;
}
.code-block {
    width: 100%;
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 13px;
    padding: 12px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 6px;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
    box-sizing: border-box;
}
.modal-response-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}
.modal-response-meta strong {
    font-family: monospace;
}
#api-play-send {
    margin-bottom: 16px;
}

.api-play-field {
    margin-bottom: 10px;
}
.api-play-field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text);
}
.api-play-field input[type="text"] {
    width: 100%;
    box-sizing: border-box;
}
.api-play-field input[type="checkbox"] {
    margin: 6px 0;
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}
.preview-body {
    max-height: 200px;
    overflow-y: auto;
    font-size: 12px;
}
.body-preview-label {
    color: var(--muted);
    font-weight: 400;
    font-size: 12px;
}
.no-body-note {
    color: var(--muted);
    font-style: italic;
    padding: 8px 0;
}

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

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

    .sidebar.collapsed {
        margin-left: -100%;
    }

    nav {
        grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
    }

    .model-chat-grid,
    .metric-grid,
    .request-summary,
    .request-card-grid,
    .usage-grid,
    .usage-summary-grid,
    .usage-range-form,
    .stats-layout,
    .chart-grid,
    .donut-wrap,
    .panel-grid,
    .split,
    .api-grid {
        grid-template-columns: 1fr;
    }

    .inline-form,
    .inline-form.compact,
    .prompt-actions,
    #workers-view .worker-card {
        grid-template-columns: 1fr;
    }

    .panel-actions {
        width: 100%;
        align-items: stretch;
        flex-direction: column;
    }

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

    .compact-input {
        width: 100%;
    }
}
