/* QueueRouter admin — self-contained, light/dark, mobile-first. */

:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --text: #17181c;
  --muted: #62666f;
  --border: #dfe1e6;
  --accent: #3355dd;
  --accent-text: #ffffff;
  --ok-bg: #e7f6ec;
  --ok-text: #155c2b;
  --err-bg: #fdecec;
  --err-text: #8a1c1c;
  --danger: #c62828;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111317;
    --surface: #1a1d23;
    --text: #e8e9ec;
    --muted: #9aa0ab;
    --border: #2c3039;
    --accent: #7d97ff;
    --accent-text: #0d1020;
    --ok-bg: #12301d;
    --ok-text: #9fe0b2;
    --err-bg: #3a1717;
    --err-text: #f4b4b4;
    --danger: #ff7a7a;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #111317;
  --surface: #1a1d23;
  --text: #e8e9ec;
  --muted: #9aa0ab;
  --border: #2c3039;
  --accent: #7d97ff;
  --accent-text: #0d1020;
  --ok-bg: #12301d;
  --ok-text: #9fe0b2;
  --err-bg: #3a1717;
  --err-text: #f4b4b4;
  --danger: #ff7a7a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); }
code, .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.92em; }
h1 { font-size: 1.5rem; margin: 0.4rem 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.6rem 0 0.6rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.wrap-any { overflow-wrap: anywhere; }
pre.wrap-any { white-space: pre-wrap; }

/* layout */
.container { width: 100%; margin: 0 auto; padding: 16px 24px; flex: 1; }  /* as wide as the window */
.narrow { width: 100%; max-width: 440px; margin: 6vh auto 0; padding: 16px; flex: 1; }
.footer { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 16px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.align-end { display: flex; align-items: flex-end; }
.inline { display: inline; margin: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
fieldset.card { margin: 0; }
legend { font-weight: 600; padding: 0 6px; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 8px 16px;
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; margin-right: 12px; }
.nav { display: flex; align-items: center; gap: 4px; flex: 1; }
.nav a { color: var(--text); text-decoration: none; padding: 6px 10px; border-radius: 8px; }
.nav a:hover { background: var(--bg); }
.nav a[aria-current="page"] { background: var(--bg); font-weight: 600; }
.nav-spacer { flex: 1; }
.nav-toggle, .nav-burger { display: none; }

@media (max-width: 1100px) {
  .nav-burger { display: block; margin-left: auto; font-size: 1.4rem; cursor: pointer; padding: 4px 8px; }
  .nav { display: none; flex-basis: 100%; flex-direction: column; align-items: stretch; }
  .nav-toggle:checked ~ .nav { display: flex; }
  .nav-spacer { display: none; }
}

/* forms */
label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
label.check { flex-direction: row; align-items: flex-start; gap: 8px; font-weight: 400; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-width: 0;
}
input[type="checkbox"] { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--accent); flex: none; } /* long label text must not squeeze it */
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button {
  font: inherit; cursor: pointer; border: 1px solid transparent; border-radius: 8px;
  padding: 8px 14px; background: var(--accent); color: var(--accent-text); font-weight: 600;
}
button.secondary { background: var(--bg); color: var(--text); border-color: var(--border); }
button.ghost { background: transparent; color: var(--text); font-weight: 400; padding: 6px 10px; }
button.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
button:hover { filter: brightness(1.08); }

/* notices and badges */
.notice { padding: 10px 14px; border-radius: var(--radius); margin: 0 0 16px; }
.notice.ok { background: var(--ok-bg); color: var(--ok-text); }
.notice.err { background: var(--err-bg); color: var(--err-text); }
.badge {
  display: inline-block; font-size: 0.75rem; padding: 1px 8px; border-radius: 99px;
  background: var(--bg); border: 1px solid var(--border); color: var(--muted); font-weight: 500;
}
.badge.high { color: var(--danger); border-color: var(--danger); }
.warn { color: var(--danger); }
.badge.low { opacity: 0.7; }
.secret {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  background: var(--bg); border: 1px dashed var(--accent); border-radius: 8px; padding: 10px;
}
.secret code { overflow-wrap: anywhere; flex: 1; }

/* tiles */
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.tile-label { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
.tile-value { font-size: 1.6rem; font-weight: 700; margin: 2px 0; font-variant-numeric: tabular-nums; }
meter { width: 100%; height: 10px; }

/* tables (become cards on phones) */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 0.8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
td { font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }

@media (max-width: 760px) {
  .container { padding: 16px; }
  table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; width: 100%; }
  table.cards thead { display: none; }
  table.cards tr { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; padding: 6px 0; }
  table.cards td { border: 0; padding: 3px 12px; }
  table.cards td[data-label]:not([data-label=""]) {
    display: flex; justify-content: space-between; align-items: baseline; gap: 12px; text-align: right;
  }
  table.cards td[data-label]:not([data-label=""])::before {
    content: attr(data-label); flex: none; font-size: 0.75rem; color: var(--muted); text-transform: uppercase;
    text-align: left;
  }
}

/* snippets */
pre { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px; overflow-x: auto; }
details.card { margin-bottom: 12px; }
details summary { cursor: pointer; }
details[open] summary { margin-bottom: 8px; }

/* compact inline fields in table forms */
label.inline-field { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; color: var(--muted); }
label.inline-field input { width: 7.5em; }
.grow { flex: 1 1 16em; }
.badge.ok { color: var(--ok-text); border-color: var(--ok-text); }
[hidden] { display: none !important; }

/* client limits and mode form */
details.policy { margin-top: 6px; }
details.policy form { margin-top: 8px; }
.grid.tight { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.span-all { grid-column: 1 / -1; }
.mode-form { margin-bottom: 16px; }

fieldset.plain { border: 0; padding: 0; margin: 0; }
ul.columns { columns: 16em; margin: 8px 0 0; padding-left: 18px; }
tr.policy-row td { padding-top: 0; }
tr:has(+ tr.policy-row) td { border-bottom: 0; }

input.price { width: 6.5em; }
.tile-value.good { color: var(--ok-text); }
textarea.rules { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.85rem; min-height: 2.4em; }

/* playground */
.chat { display: flex; flex-direction: column; gap: 8px; margin: 16px 0; max-height: 60vh; overflow-y: auto; }
.bubble { white-space: pre-wrap; overflow-wrap: anywhere; padding: 10px 14px; border-radius: var(--radius); max-width: 85%; }
.bubble.user { align-self: flex-end; background: var(--accent); color: var(--accent-text); }
.bubble.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); }
.bubble.error { border-color: var(--danger); color: var(--danger); }
a.button { display: inline-block; text-decoration: none; font-weight: 600; padding: 8px 14px; border-radius: 8px; }
a.button.secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.nav-count { display: inline-block; min-width: 1.4em; margin-left: 4px; padding: 0 5px; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: 0.75em; font-weight: 700; text-align: center; line-height: 1.5; }
.nav-count[hidden] { display: none; }
tr.unread td { background: color-mix(in srgb, var(--danger) 6%, transparent); }
/* charts */
.charts { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.chart-box { margin: 0; padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.chart-box figcaption { font-weight: 600; margin-bottom: 6px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.chart { display: block; width: 100%; height: auto; }
.chart .grid { stroke: var(--border); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart .axis { fill: var(--muted); font-size: 13px; }
.chart .hit { fill: transparent; }
.chart g:hover .hit { fill: color-mix(in srgb, var(--accent) 8%, transparent); }
.chart .s1, .legend.s1::before { fill: var(--accent); background: var(--accent); }
.chart .s2, .legend.s2::before { fill: color-mix(in srgb, var(--accent) 45%, var(--surface)); background: color-mix(in srgb, var(--accent) 45%, var(--surface)); }
.chart .s3, .legend.s3::before { fill: var(--danger); background: var(--danger); }
.chart .line { fill: none; stroke-width: 2; vector-effect: non-scaling-stroke; }
.chart .line.s1 { stroke: var(--accent); }
.chart .line.s3 { stroke: var(--danger); }
/* one color per line on the Response times chart */
.chart .l1, .legend.l1::before { --c: var(--accent); }
.chart .l2, .legend.l2::before { --c: #d9822b; }
.chart .l3, .legend.l3::before { --c: #2a9d8f; }
.chart .l4, .legend.l4::before { --c: #9b5de5; }
.chart .l5, .legend.l5::before { --c: #c2185b; }
.chart .line[class*=" l"] { stroke: var(--c); }
.chart .dot { fill: var(--c); }
.legend[class*=" l"]::before { background: var(--c); }
.legend { font-weight: 400; font-size: 0.85em; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.legend::before { content: ""; width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.qr svg { display: block; width: 220px; height: 220px; margin: 8px 0; border-radius: 6px; }
.content-view { max-height: 60vh; overflow: auto; padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); white-space: pre-wrap; }

/* Click-to-copy values (User-Agents on the Requests page) */
.copy-text { display: block; background: none; border: 0; padding: 0; margin: 0; color: inherit; font: inherit; text-align: left; cursor: copy; overflow-wrap: anywhere; }
.copy-text:hover { text-decoration: underline dotted; }
.copy-text.copied::after { content: " ✓ copied"; color: var(--accent); }
.copy-text.inline { display: inline; }
details.ids { margin-top: 2px; }
details.ids > div { overflow-wrap: anywhere; }
ul.picker { margin: 12px 0; padding: 0; list-style: none; }
ul.picker li[hidden] { display: none; }

/* Alias editor: search-and-pick chips */
.alias-editor fieldset.card { display: grid; gap: 12px; margin-bottom: 16px; }
.alias-editor legend { font-weight: 600; }
.picker { position: relative; }
.picker-box { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 6px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.picker-chips { display: contents; }
.picker-search { flex: 1 1 12em; min-width: 8em; border: 0; padding: 4px; background: transparent; }
.picker-search:focus { outline: none; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 8px; border: 1px solid var(--border); border-radius: 999px; font-size: 0.9em; cursor: default; }
.chip[draggable="true"] { cursor: grab; }
.chip.unknown { border-style: dashed; }
.chip button { border: 0; background: none; padding: 0 4px; color: var(--muted); cursor: pointer; font-size: 1.1em; line-height: 1; }
.picker-menu { position: absolute; z-index: 20; left: 0; right: 0; max-height: 18em; overflow-y: auto; margin: 4px 0 0; padding: 4px 0; list-style: none; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.picker-menu li { padding: 6px 10px; cursor: pointer; overflow-wrap: anywhere; }
.picker-menu li.active, .picker-menu li:hover { background: var(--bg); }

/* Requests and Usage: more on the screen */
.dense-page { padding: 10px 16px; }
.dense-page h1 { font-size: 1.2rem; margin: 0; }
.dense-page h2 { font-size: 0.95rem; margin: 10px 0 4px; }
.dense-page .small { font-size: 0.78rem; }
.dense-page p { margin: 4px 0; }
.dense-page select { padding: 2px 6px; font-size: 0.8rem; max-width: 15em; }
.dense-page form.row { gap: 6px; }
.dense-page .tiles { gap: 8px; margin-top: 8px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.dense-page .tile { padding: 6px 10px; min-width: 0; }
.dense-page .tile-label { font-size: 0.68rem; }
.dense-page .tile-value { font-size: 1.1rem; line-height: 1.3; margin: 0; overflow-wrap: anywhere; }
.dense-page .charts { gap: 8px; margin-top: 8px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.dense-page .chart-box { padding: 6px 8px; }
.dense-page .chart-box figcaption { font-size: 0.8rem; margin-bottom: 2px; }
.live-status { font-size: 0.75rem; color: var(--muted); }
.live-status[data-state="live"] { color: var(--ok-text); }
.live-status[data-state="down"] { color: var(--danger); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg a { padding: 1px 10px; font-size: 0.78rem; color: var(--muted); text-decoration: none; }
.seg a[aria-current="true"] { background: var(--accent); color: var(--accent-text); }

table.dense { font-size: 0.8rem; }
table.dense th, table.dense td { padding: 2px 6px; white-space: nowrap; line-height: 1.5; vertical-align: baseline; }
table.dense th { font-size: 0.72rem; text-transform: none; letter-spacing: 0; }
table.dense .wrap-any { white-space: normal; }
table.dense .badge { font-size: 0.68rem; padding: 0 5px; }
table.dense tr.total td { font-weight: 600; border-top: 1px solid var(--border); }
/* Usage: a row opens to what it's made of (a model's clients, a client's models) */
tr.opens { cursor: pointer; }
button.expand { background: none; border: 0; padding: 0; margin: 0; color: inherit; font: inherit; text-align: left; cursor: pointer; }
button.expand::before { content: "▸"; display: inline-block; width: 1.2em; color: var(--muted); }
button.expand[aria-expanded="true"]::before { content: "▾"; }
tr.part td { background: color-mix(in srgb, var(--accent) 5%, transparent); }
tr.part td.indent { padding-left: 2.2em; }
.share { display: inline-block; min-width: 4.5ch; margin-left: 0.7ch; text-align: right; color: var(--muted); }
#usage-custom input[type="date"] { padding: 1px 4px; font-size: 0.8rem; }
@media (max-width: 760px) {
  table.cards tr.part { margin-left: 16px; width: calc(100% - 16px); }
  table.cards tr.part td[data-label=""] { display: none; }
  tr.part td.indent { padding-left: 12px; }
}
.num, table.dense th.num { text-align: right; }
.price { display: inline-block; min-width: 7ch; margin-left: 0.7ch; text-align: right; color: var(--muted); }

.requests-table { table-layout: fixed; min-width: 1180px; }
.requests-table td { overflow: hidden; text-overflow: ellipsis; }
.requests-table col.c-time { width: 12ch; }
.requests-table col.c-client { width: 11ch; }
.requests-table col.c-outcome { width: 24ch; }
.requests-table col.c-ms { width: 8ch; }
.requests-table col.c-first { width: 9ch; }
.requests-table col.c-in { width: 20ch; }
.requests-table col.c-cached { width: 22ch; }
.requests-table col.c-out { width: 19ch; }
.requests-table col.c-speed { width: 7ch; }
.requests-table col.c-total { width: 10ch; }
.requests-table col.c-finish { width: 12ch; }
.requests-table tr.req { cursor: pointer; }
.requests-table tr.req:hover td, .requests-table tr.req.open td { background: var(--bg); }
.requests-table tr.req.live td { background: color-mix(in srgb, var(--accent) 5%, transparent); }
.requests-table tr.section td { font-weight: 600; font-size: 0.72rem; color: var(--muted); background: var(--bg); }
.requests-table tr.req td.bad { color: var(--danger); }
.requests-table tr.req-more td { white-space: normal; background: var(--bg); }
.row-toggle { background: none; border: 0; padding: 0 4px 0 0; color: var(--muted); font-size: 0.7rem; font-weight: 400; }
tr.open .row-toggle { display: inline-block; transform: rotate(90deg); padding: 0 0 0 4px; }
.req-details { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 0 16px; padding: 2px 0 4px 14px; overflow-wrap: anywhere; }
.new-rows { position: fixed; z-index: 9; bottom: 16px; left: 50%; transform: translateX(-50%); padding: 4px 14px; border-radius: 99px; box-shadow: var(--shadow); }
@keyframes row-in { from { background: color-mix(in srgb, var(--accent) 14%, transparent); } }
tr.fresh td { animation: row-in 1.2s ease-out; }
@media (prefers-reduced-motion: reduce) { tr.fresh td { animation: none; } }
@media (min-width: 1160px) { /* the table fits, so its header can stay in view under the top bar */
  .requests-wrap { overflow: visible; }
  .requests-table thead th { position: sticky; top: var(--topbar, 46px); z-index: 5; background: var(--surface); }
}
@media (max-width: 760px) {
  .requests-table { min-width: 0; }
  .requests-table colgroup { display: none; }
  .requests-table td { overflow: visible; }
  table.dense td { white-space: normal; }
  .price { min-width: 0; }
}

/* Prompt edits: changes highlighted (removed struck through, added marked), long unchanged runs folded */
.changes del, .hunk del { background: var(--err-bg); color: var(--err-text); text-decoration: line-through; }
.changes ins, .hunk ins { background: var(--ok-bg); color: var(--ok-text); text-decoration: none; }
.changes { max-height: 70vh; }
.fold-box { position: absolute; opacity: 0; pointer-events: none; }
.fold-note { display: inline; color: var(--muted); background: var(--bg); border: 1px dashed var(--border); border-radius: 6px; padding: 0 6px; cursor: pointer; font-size: 0.8em; }
.fold-mid { display: none; }
.fold-box:checked + .fold-note { display: none; }
.fold-box:checked + .fold-note + .fold-mid { display: inline; }
.fold-box:focus-visible + .fold-note { outline: 2px solid var(--accent); }
.hunk { margin: 4px 0; padding: 6px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; white-space: pre-wrap; font-size: 0.8rem; }
ol.by-edit { padding-left: 20px; }
ol.by-edit li { margin-bottom: 10px; }
table.made textarea { min-height: 2.4em; font-size: 0.8rem; }
.edits-table td { vertical-align: top; }
form.made-edit pre.seen { margin: 0; padding: 2px 8px; font-size: 0.75rem; color: var(--muted); white-space: pre-wrap; border: 0; border-left: 2px solid var(--border); border-radius: 0; background: none; }
.alias-editor fieldset.card > * { min-width: 0; } /* a long option or value mustn't widen the page on a phone */
select { max-width: 100%; }
@media (max-width: 760px) {
  table.cards.made td.made-what[data-label] { display: block; text-align: left; }
  table.cards.made td.made-what[data-label]::before { display: block; margin-bottom: 4px; }
}
