:root {
  --bg: #f6f7f9; --fg: #16181d; --muted: #646b78; --card: #fff; --line: #dfe2e8; --field-line: #868e9c;
  --accent: #3a5bd9; --accent-fg: #fff; --accent-soft: #eaeefc; --danger: #b83434; --code: #eef0f4;
  --ok-bg: #e6f4ec; --ok-fg: #1e7a45; --ok-line: #9bd3b0;
  --warn-bg: #fdf1dc; --warn-fg: #8a5300; --warn-line: #e8c27e;
  --err-bg: #fbeaea; --err-fg: #b42f2f; --err-line: #e6a5a5;
  --info-bg: #eaeefc; --info-line: #b5c3f3;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318; --fg: #e7e9ee; --muted: #9aa1ad; --card: #1a1d24; --line: #2c313b; --field-line: #6b7383;
    --accent: #7891f0; --accent-fg: #0d0f14; --accent-soft: #232a45; --danger: #ef7b7b; --code: #232731;
    --ok-bg: #16291e; --ok-fg: #6fd39a; --ok-line: #2f6b46;
    --warn-bg: #2e2410; --warn-fg: #f0b65a; --warn-line: #6b5320;
    --err-bg: #2d1717; --err-fg: #f08a8a; --err-line: #7a3434;
    --info-bg: #1b2140; --info-line: #3a4a8a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }  /* rules like input { display: block } must not reveal it */
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--fg); }
main { margin: 36px auto 64px; padding: 0 16px; }
main.narrow { max-width: 440px; }
main.wide { max-width: 1000px; }
h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 6px; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; margin: 40px 0 12px; }
h3 { font-size: 1rem; margin: 24px 0 8px; }
p { margin: 0 0 12px; }
a { color: var(--accent); text-underline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 16px; top: 8px; z-index: 10; background: var(--card); padding: 6px 10px; border-radius: 6px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus-visible { outline-offset: 0; border-color: var(--accent); }

/* ---- header */
.top { display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 56px; border-bottom: 1px solid var(--line); background: var(--card); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; color: var(--fg); text-decoration: none; white-space: nowrap; }
.logo { width: 22px; height: 22px; border-radius: 6px; background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M18 4 8 18h7l-2 10 11-15h-7z' fill='%23fff'/%3E%3C/svg%3E") center / 16px no-repeat; }
.top nav { display: flex; gap: 4px; height: 100%; }
.top nav a { display: flex; align-items: center; padding: 0 10px; color: var(--muted); text-decoration: none; font-weight: 550; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.top nav a:hover { color: var(--fg); }
.top nav a[aria-current="page"] { color: var(--fg); border-bottom-color: var(--accent); }
.signout { margin: 0 0 0 auto; display: flex; align-items: center; gap: 12px; }
.who { color: var(--muted); font-size: 0.9rem; max-width: 16ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- cards, forms */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 20px; margin: 16px 0; box-shadow: var(--shadow); }
.card.tight { padding: 6px 16px; }
.card-title { margin: 0 0 14px; font-size: 1.05rem; }
label { display: block; margin: 0 0 6px; font-weight: 550; }
input { display: block; width: 100%; margin: 0 0 16px; padding: 10px 12px; font: inherit; color: var(--fg); background: var(--card); border: 1px solid var(--field-line); border-radius: 8px; }
input::placeholder { color: var(--muted); opacity: 0.85; }
input[aria-invalid="true"] { border-color: var(--danger); }
.hint { margin: -10px 0 16px; font-size: 0.82rem; color: var(--muted); }
input.code { font-size: 1.7rem; letter-spacing: 0.45em; padding-left: calc(12px + 0.45em); text-align: center; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
button, .button { display: inline-block; font: inherit; font-weight: 600; padding: 10px 16px; border: 1px solid transparent; border-radius: 8px; background: var(--accent); color: var(--accent-fg); cursor: pointer; text-decoration: none; line-height: 1.3; }
button:hover, .button:hover { filter: brightness(1.08); }
button:active { filter: brightness(0.95); }
button:disabled { opacity: 0.55; cursor: default; filter: none; }
form.card > button, .full, .card form > button:last-child { width: 100%; }
button.secondary { background: var(--code); color: var(--fg); border-color: var(--line); }
button.ghost { background: transparent; color: var(--fg); border-color: var(--field-line); }
button.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
button.small { padding: 4px 10px; font-size: 0.85rem; width: auto !important; }
button.link { background: none; border: 0; color: var(--accent); padding: 0; font-weight: 550; width: auto !important; }
button.link:disabled { color: var(--muted); opacity: 1; }
.row { display: flex; gap: 10px; align-items: center; }
.row input { margin: 0; flex: 1; min-width: 0; }
.row > button { white-space: nowrap; width: auto !important; }

/* ---- alerts, chips */
.alerts:empty { display: none; }
.alert { border-radius: 10px; padding: 12px 14px; margin: 16px 0; border: 1px solid; }
.alert p:last-child { margin-bottom: 0; }
.alert.error { background: var(--err-bg); border-color: var(--err-line); }
.alert.success { background: var(--ok-bg); border-color: var(--ok-line); }
.alert.info { background: var(--info-bg); border-color: var(--info-line); }
.chip { display: inline-block; font-size: 0.75rem; font-weight: 600; line-height: 1.5; padding: 0 8px; border-radius: 999px; background: var(--code); color: var(--muted); white-space: nowrap; vertical-align: 1px; }
.chip.ok { background: var(--ok-bg); color: var(--ok-fg); }
.chip.warn { background: var(--warn-bg); color: var(--warn-fg); }
.chip.err { background: var(--err-bg); color: var(--err-fg); }
.chip.wrap { white-space: normal; overflow-wrap: anywhere; border-radius: 9px; }  /* switch chips: may hold long HF-style ids */
.alert { overflow-wrap: anywhere; }  /* announcements name model ids, some very long */
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; background: var(--muted); flex: none; }
.dot.up { background: #2f9e5b; }
.dot.down { background: var(--danger); }
.dot.switching { background: var(--warn-fg); }

/* ---- code */
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.88em; background: var(--code); padding: 1px 5px; border-radius: 4px; overflow-wrap: anywhere; }
pre { background: var(--code); padding: 14px 16px; border-radius: 0 0 10px 10px; overflow-x: auto; margin: 0; font-size: 0.92em; line-height: 1.45; }
pre:focus-visible { outline-offset: -2px; }  /* focusable so keyboards can scroll it */
pre code { padding: 0; background: none; overflow-wrap: normal; }
pre.plain { border-radius: 6px; margin-top: 8px; white-space: pre-wrap; background: transparent; padding: 0; }
.snippet { border: 1px solid var(--line); border-radius: 10px; margin: 12px 0; overflow: hidden; }
.snippet-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px; font-size: 0.8rem; color: var(--muted); background: var(--card); border-bottom: 1px solid var(--line); }
.copyfield { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.copyfield code { background: none; padding: 0; flex: 1; font-size: 0.95em; }
.keybox { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.keybox code { flex: 1; padding: 8px 10px; background: var(--card); border: 1px solid var(--ok-line); }

/* ---- layout bits */
.page-head { margin-bottom: 8px; }
.page-head p { margin: 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 40px 0 12px; }
.section-head h2 { margin: 0; }
.section-head form { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; margin-bottom: 24px; }
.grid-2 .card { margin: 16px 0 0; }
.push { margin-left: auto; }
.empty { margin: 16px 0 0; }

/* ---- tables */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: top; }
th { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap, .errors td { white-space: normal; }
.errors td:nth-child(2) code { white-space: nowrap; }
td.actions { text-align: right; width: 1%; }
/* A down backend's error and URL wrap instead of pushing the Drain buttons out of view. */
.engines-table td[data-label="Status"] { white-space: normal; min-width: 11ch; max-width: 26ch; }
.engines-table td:first-child { white-space: normal; max-width: 28ch; }
td.actions form { margin: 0; }
td .small { margin-top: 2px; }
table.small td { padding: 7px 14px; }
.keys-table { margin-top: 16px; border-top: 1px solid var(--line); }
.keys-table th:first-child, .keys-table td:first-child { padding-left: 0; }
.keys-table th:last-child, .keys-table td:last-child { padding-right: 0; }
.keys-table tbody tr:last-child td { padding-bottom: 0; }
.reqid code { display: inline-block; max-width: 13ch; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; font-size: 0.78em; color: var(--muted); background: none; padding: 0; }

/* ---- steps */
.steps { display: flex; gap: 6px; list-style: none; padding: 0; margin: 0 0 28px; counter-reset: s; font-size: 0.82rem; color: var(--muted); }
.steps li { flex: 1; border-top: 3px solid var(--line); padding-top: 6px; counter-increment: s; }
.steps li::before { content: counter(s) ". "; }
.steps li.on { border-color: var(--accent); color: var(--fg); font-weight: 600; }
.steps li.done { border-color: var(--accent); opacity: 0.75; }
.steps li.done::before { content: "✓ "; }
.otp-actions { display: flex; justify-content: space-between; align-items: center; font-size: 0.9rem; margin: -4px 2px 18px; }
.otp-actions form { margin: 0; }
.userid { font-size: 1.05rem; padding: 10px 12px; margin-bottom: 18px; background: var(--accent-soft); border-radius: 8px; }

/* ---- stats */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 14px; }
.stats.summary { grid-template-columns: repeat(4, 1fr); margin-top: 20px; }
.stats div { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; color: var(--muted); font-size: 0.85rem; box-shadow: var(--shadow); }
.stats span { display: block; font-size: 1.55rem; font-weight: 650; color: var(--fg); font-variant-numeric: tabular-nums; line-height: 1.3; }
.stats small { font-size: 0.9rem; color: var(--muted); font-weight: 500; }
.stats .bad span { color: var(--err-fg); }

/* ---- models / serving */
.models { list-style: none; padding: 0; margin: 0; }
.models li { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 0; border-bottom: 1px solid var(--line); }
.models li:last-child { border-bottom: 0; }
.model-name { display: inline-flex; align-items: center; gap: 6px; }
.model-name code { font-size: 0.95em; }
.live::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: #2f9e5b; margin-right: 6px; vertical-align: 2px; }
.live.stale::before { background: var(--muted); }
details.engines { margin-top: 10px; }
details.engines summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; padding: 4px 0; width: fit-content; }
details.engines[open] summary { margin-bottom: 8px; }
.aliases, .sessions, .invites { list-style: none; padding: 0; margin: 0; }
.aliases li { padding: 3px 0; }
.sessions li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.sessions li:last-child { border-bottom: 0; margin-bottom: 10px; }
.invites li { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 0; border-top: 1px solid var(--line); }
.invites li form { margin: 0 0 0 auto; }
.invites { margin-top: 12px; }
.card.tight form.row { margin: 10px 0; }
.model-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.model-card.card { margin: 0; padding: 16px; }
.model-card .spark-head { flex-wrap: wrap; }
.model-card .facts { margin-bottom: 8px; }
.notes { white-space: pre-line; overflow-wrap: anywhere; border-top: 1px solid var(--line); padding-top: 8px; }

/* ---- docs */
.toc { display: flex; flex-wrap: wrap; gap: 4px 18px; padding: 10px 16px; font-size: 0.9rem; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; margin: 0 0 14px; }
.facts dt { color: var(--muted); font-weight: 550; }
.facts dd { margin: 0; }
.steps-list { padding-left: 20px; }
.steps-list li { margin-bottom: 6px; }
.matrix td, .matrix th { text-align: center; }
.matrix td:first-child, .matrix th:first-child { text-align: left; }
section[id] { scroll-margin-top: 16px; }

/* ---- admin */
.fleet { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.spark.card { margin: 0; padding: 16px; }
.spark-head { display: flex; align-items: center; gap: 4px; margin-bottom: 10px; }
.spark-head .chip { margin-left: 6px; }
.gauges { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; font-size: 0.75rem; color: var(--muted); }
.gauges span { display: block; font-size: 1.05rem; font-weight: 650; color: var(--fg); }
.engine { border-top: 1px solid var(--line); padding-top: 8px; margin-top: 8px; font-size: 0.9rem; }
.errorpage { text-align: center; padding: 32px 24px; }
.errorpage .status { font-size: 0.85rem; font-weight: 700; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 4px; }
.errorpage .button { margin-top: 8px; }

/* ---- phones: tables become stacked cards */
@media (max-width: 760px) {
  .grid-2 { grid-template-columns: 1fr; }
  .stats.summary { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  main { margin-top: 24px; }
  .top { gap: 8px; padding: 10px 12px 0; height: auto; min-height: 52px; flex-wrap: wrap; }
  .top:not(:has(nav)) { padding-bottom: 10px; }
  .top nav { order: 3; width: 100%; height: 40px; overflow-x: auto; margin: 0 -4px; }
  .top nav a { padding: 0 8px; }
  .who { display: none; }
  .stats { gap: 8px; }
  .stats div { padding: 10px 12px; font-size: 0.78rem; }
  .stats span { font-size: 1.15rem; }
  .row { flex-direction: column; align-items: stretch; }
  .row > button { width: 100% !important; }
  .facts { grid-template-columns: 1fr; gap: 2px; }
  .facts dd { margin-bottom: 10px; }
  table.stack, table.stack tbody { display: block; }
  table.stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.stack tr { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
  table.stack tbody tr:last-child { border-bottom: 0; }
  table.stack td { display: block; padding: 0; border: 0; white-space: normal; text-align: left; min-width: 0; max-width: none; }
  table.stack td[data-label]::before { content: attr(data-label); display: block; font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
  table.stack td:first-child { grid-column: 1 / -1; }
  table.stack td:first-child::before { display: none !important; }
  table.stack td.actions::before { display: none !important; }  /* labelled for AT; the buttons say what they do */
  table.stack.engines-table tr { grid-template-columns: 1fr 1fr 1fr; }
  table.stack.engines-table td:first-child { grid-column: 1 / 3; grid-row: 1; }
  table.stack.engines-table td.actions { grid-column: 3; grid-row: 1; text-align: right; }
  table.stack.engines-table td.actions button { width: auto !important; padding: 4px 10px; }
  table.stack.engines-table td[data-label="Engine"] { grid-row: 2; grid-column: 1; }
  table.stack.engines-table td[data-label="Status"] { grid-row: 2; grid-column: 2; }
  table.stack.engines-table td[data-label="Load"] { grid-row: 2; grid-column: 3; }
  table.stack.engines-table td[data-label="Serving"] { grid-row: 3; grid-column: 1 / 3; }
  table.stack.engines-table td[data-label="Since"] { grid-row: 3; grid-column: 3; }
  table.stack td.actions { grid-column: 1 / -1; width: auto; text-align: left; }
  table.stack td.actions button { width: 100% !important; padding: 7px 10px; }
  table.stack td.reqid { grid-column: 1 / -1; }
  .keys-table { border-top: 0; }
  table.stack.keys-table tr { grid-template-columns: 1.25fr 1fr 1fr; padding-left: 0; padding-right: 0; }
  table.stack.keys-table td:first-child { grid-column: 1 / 3; grid-row: 1; align-self: center; }
  table.stack.keys-table td.actions { grid-column: 3; grid-row: 1; text-align: right; }
  table.stack.keys-table td.actions button { width: auto !important; padding: 4px 10px; }
  table.stack td code { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
  table.stack.usage tr { grid-template-columns: 1fr 1fr 1fr; gap: 6px 12px; }
  table.stack.usage td[data-label="Time"] { grid-column: 1 / 3; grid-row: 1; }
  table.stack.usage td[data-label="Status"] { grid-column: 3; grid-row: 1; text-align: right; }
  table.stack.usage td[data-label="Model"] { grid-column: 1 / -1; grid-row: 2; }
  table.stack.usage td[data-label="Time"]::before, table.stack.usage td[data-label="Status"]::before,
  table.stack.usage td[data-label="Model"]::before { display: none; }
  table.stack.usage td.reqid { display: none; }
  table.stack.errors td:nth-child(2), table.stack.errors td:nth-child(3) { grid-column: 1 / -1; }
  table.stack.errors td code { overflow: visible; white-space: normal; overflow-wrap: anywhere; }
  .matrix td, .matrix th { text-align: left; }
}
