:root { color-scheme: light dark; --bg: #f7f7f5; --fg: #1d1d1b; --muted: #6b6b66; --line: #d8d8d3; --card: #fff; --ok: #1a7f37; --bad: #b42318; --accent: #2b5fd9; --edge: rgba(0, 0, 0, .34); }
@media (prefers-color-scheme: dark) { :root { --bg: #131313; --fg: #e8e8e4; --muted: #9a9a94; --line: #2c2c2a; --card: #1c1c1b; --accent: #7aa2ff; --bad: #ff6b5e; --ok: #4ac26b; --edge: rgba(0, 0, 0, .8); } }
* { box-sizing: border-box; }
/* No system scrollbar anywhere: every scroller in the panel gets this thin one, drawn from the
   panel's own tokens so it is right in both themes. Firefox takes the two scrollbar-* properties,
   WebKit and Blink the pseudo-elements; between them that is every browser this panel meets. */
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 9px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; }
::-webkit-scrollbar-corner { background: transparent; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.45 system-ui, sans-serif; }
header { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--line); }
h1 { font-size: 18px; margin: 0; } h2 { font-size: 15px; margin: 18px 0 8px; }
main { padding: 4px 20px 40px; max-width: 1400px; }
.muted { color: var(--muted); font-weight: normal; }
.cards { display: flex; flex-wrap: wrap; gap: 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; min-width: 150px; }
.card b { display: block; font-size: 18px; }
.card small { color: var(--muted); }
table { border-collapse: collapse; width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 8px; }
th, td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--line); vertical-align: top; font-variant-numeric: tabular-nums; }
th { color: var(--muted); font-weight: 600; font-size: 12px; user-select: none; white-space: nowrap; }
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--fg); }
th[data-dir="asc"]::after { content: " \25B2"; }
th[data-dir="desc"]::after { content: " \25BC"; }
td.edit { cursor: text; } td.edit:hover { outline: 1px dashed var(--accent); }
input, button, select { font: inherit; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--fg); }
button { cursor: pointer; } button.danger { color: var(--bad); }
button.primary { border-color: var(--accent); color: var(--accent); }
button:disabled { opacity: .45; cursor: default; }
form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
label { display: inline-flex; gap: 4px; align-items: center; color: var(--muted); }
.secret { margin: 8px 0; padding: 10px 14px; border: 1px solid var(--ok); border-radius: 8px; }
.secretline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.secretline code { font-family: ui-monospace, monospace; word-break: break-all; flex: 1 1 260px; }
.ok { color: var(--ok); } .bad { color: var(--bad); }
.row { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.revoked td { opacity: .55; }
.limits .lim { display: inline-block; white-space: nowrap; margin-right: 10px; }
#requests td:nth-child(n+4), #requests th:nth-child(n+4),
#usage td:nth-child(n+3), #usage th:nth-child(n+3) { text-align: right; font-variant-numeric: tabular-nums; }
/* The same thing said by name, for tables built after this rule was written: a figure column
   carries .num on its header and its cells and lines up on the right in both layouts. */
.num { text-align: right; font-variant-numeric: tabular-nums; }
/* Last-resort guard: a table that still does not fit scrolls inside its own box rather than
   being clipped at the screen edge, which is what a phone does otherwise. */
.tablewrap { overflow-x: auto; overscroll-behavior-x: contain; }

/* tabs
   #tabstrip is the frame, #tabs the scroller inside it. Seven tabs do not fit on a phone, and a
   strip that just ends flush at the screen edge reads as "that is all the tabs there are" - which
   is how the first tab, Overview, went missing for a week. So the side that still has tabs behind
   it is shaded: the shading belongs to the frame, not the scroller, so it stays at the edge while
   the tabs slide under it. panel.js sets .more-left / .more-right from the scroll position. */
#tabstrip { position: relative; margin: 10px 0 0; }
#tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto;
        overscroll-behavior-x: contain; scroll-padding: 0 28px; }
#tabs button { display: inline-flex; align-items: center; gap: 7px;
               border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none;
               color: var(--muted); padding: 8px 12px; white-space: nowrap; }
#tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }
#tabs svg { flex: none; width: 18px; height: 18px; pointer-events: none;
            fill: none; stroke: currentColor; stroke-width: 1.7;
            stroke-linecap: round; stroke-linejoin: round; }
/* Icons alone once the seven names stop fitting - panel.js measures and sets this class, so the
   labels survive wherever there is room for them and no width is hardcoded. The glyph carries the
   accent colour of the active tab, which is what says where you are when the name is gone.
   They grow but never shrink: spread across the strip they are a fat thumb target, and if even
   the icons do not fit they keep their size and the strip scrolls with the shading to say so. */
#tabs.icons button { flex: 1 0 auto; justify-content: center; padding: 8px 9px; }
#tabs.icons .tab-label { display: none; }
#tabs.icons svg { width: 20px; height: 20px; }
/* The strip's own scrollbar would sit on top of the tab labels, and the owner reads the shading,
   not a scrollbar, as the sign that there is more. It is the one scroller drawn without one. */
#tabs { scrollbar-width: none; }
#tabs::-webkit-scrollbar { display: none; }
#tabstrip::before, #tabstrip::after {
  content: ""; position: absolute; top: 0; bottom: 1px; width: 38px; pointer-events: none;
  opacity: 0; }   /* no transition: it must be there the instant the thumb moves, and a
                     half-faded edge is impossible to screenshot or to check */
/* Black, not var(--bg): a gradient the colour of the background is invisible against it, and
   what has to be visible is the edge itself, not just the half-tab under it. Over the dark
   theme this is a vignette; over the light one it reads as the shadow of content passing under. */
#tabstrip::before { left: 0; background: linear-gradient(to right, var(--edge), transparent); }
#tabstrip::after { right: 0; background: linear-gradient(to left, var(--edge), transparent); }
#tabstrip.more-left::before, #tabstrip.more-right::after { opacity: 1; }

/* filter + sort row above each table */
.filter { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0 8px; }
.filter input[data-filter] { flex: 0 1 220px; min-width: 0; }
.filter button[data-dir] { min-width: 42px; }

/* the new-key modal: three labelled groups, one grid, every control the same width */
dialog { border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--fg);
         padding: 16px 18px; width: min(760px, calc(100% - 24px)); max-height: 86vh; overflow: auto; }
dialog::backdrop { background: rgba(0, 0, 0, .5); }
dialog h2 { margin: 0 0 12px; font-size: 16px; }
.dlggrid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
           gap: 4px 26px; align-items: start; }
#g-identity { grid-column: 1; grid-row: 1; }
#g-limits { grid-column: 2; grid-row: 1 / span 2; }
.dlggroup { border-top: 1px solid var(--line); padding-top: 4px; margin-bottom: 14px; }
.dlggroup h3 { margin: 6px 0 8px; }
.field { display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: 10px;
         align-items: center; margin-bottom: 7px; color: var(--muted); }
.field > span { font-size: 13px; }
.field input { width: 100%; min-width: 0; }
.dlggroup.nums .field { grid-template-columns: 104px 110px; }
.pickernote { margin: 6px 0 2px; font-size: 12px; }
#dlgmsg { margin: 8px 0 0; }
.dlgactions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; }

/* chips: the one control used wherever a set of server-side names is chosen - the scopes and
   models of a key, in the modal and in the keys table. Typing those names by hand is a trap:
   a misspelt model silently makes a key that can reach nothing. */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 7px; padding: 5px 11px; cursor: pointer;
        border: 1px solid var(--line); border-radius: 999px; background: var(--card);
        color: var(--fg); font-size: 13px; line-height: 1.3; user-select: none; }
.chip input { appearance: none; -webkit-appearance: none; flex: none; width: 13px; height: 13px;
              margin: 0; padding: 0; border: 1px solid var(--muted); border-radius: 4px;
              background: transparent; }
.chip.on { border-color: var(--accent); color: var(--accent); }
.chip.on input { background: var(--accent); border-color: var(--accent); }
.chip:hover { border-color: var(--accent); }
.chip.all.on { border-style: dashed; }

/* pause rows and the runtime-settings form */
h3 { font-size: 12px; margin: 14px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.pauserow { display: flex; gap: 10px; align-items: center; padding: 8px 12px; background: var(--card);
            border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; }
.pausename { flex: 0 0 230px; display: flex; flex-direction: column; }
.pausename small { color: var(--muted); }
.pausereason { flex: 1 1 200px; min-width: 0; }
.pauserow .bad { flex: 1 1 auto; }
.setgroup { margin-bottom: 12px; }
.setrow { display: grid; grid-template-columns: 300px 1fr; gap: 6px 18px; align-items: baseline;
          padding: 7px 12px; background: var(--card); border: 1px solid var(--line);
          border-radius: 8px; margin-bottom: 6px; }
.setrow label { display: flex; gap: 8px; align-items: center; color: var(--fg); }
/* A knob's name was its variable name until card d83, and a monospace face is what a
   variable wants. It is a phrase now, so it reads in the page's own face and may wrap. */
.setname { font-size: 13px; flex: 1 1 auto; min-width: 0; overflow-wrap: break-word; }
.setrow input { width: 108px; }
.setunit { color: var(--muted); font-size: 12px; flex: 0 0 46px; }
.setmeta { display: flex; flex-direction: column; gap: 2px; font-size: 12px; }
/* A setting that is a yes/no is a switch, not a box with a 1 in it. The value behind it is still
   a number - gpulm has one kind of knob - and this is only how it reads. Written as
   `.setrow .setswitch` so it out-ranks the width every other box in a row gets. */
.setrow .setswitch { appearance: none; -webkit-appearance: none; position: relative; flex: none;
                     width: 42px; height: 24px; padding: 0; border-radius: 999px;
                     border: 1px solid var(--line); background: var(--bg); cursor: pointer; }
.setrow .setswitch::after { content: ""; position: absolute; top: 2px; left: 2px;
                            width: 18px; height: 18px; border-radius: 50%; background: var(--muted); }
.setrow .setswitch:checked { background: var(--accent); border-color: var(--accent); }
.setrow .setswitch:checked::after { left: auto; right: 2px; background: var(--card); }
.setrow .setswitch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* A knob that is a choice of three is a picker of WORDS. The value behind it is still a number,
   like every knob here; what the picker shows is what the number means, which a box with a 0 in
   it and a sentence underneath cannot say. It needs the width of its longest step, so it does not
   take the 108px every typed box gets. */
.setrow .setpick { flex: 1 1 auto; min-width: 0; max-width: 100%; font: inherit; padding: 4px 6px;
                   border: 1px solid var(--line); border-radius: 6px;
                   background: var(--card); color: var(--fg); min-height: 30px; }
/* A step is a sentence, not a figure: it gets the width of the row rather than the 108px a typed
   box takes, so "grace period, then stop" is read rather than guessed at. */
.setrow.haspick label { flex-wrap: wrap; }
.setrow.haspick .setname { flex: 1 0 100%; }
.setrow .setpick:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* charts and memory maps */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); gap: 12px; margin-top: 10px; }
.charts.maps { grid-template-columns: repeat(auto-fit, minmax(min(380px, 100%), 1fr)); }
figure { margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
figcaption { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.now { color: var(--fg); font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.chart { height: 110px; }
.chart svg, .map svg { width: 100%; height: 100%; display: block; overflow: visible; }
.map { height: auto; }   /* panel.js gives the box the grid's own proportions */
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 8px; font-size: 12px; }
.legend span.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.legend span.amount { color: var(--muted); font-variant-numeric: tabular-nums; }
#spanctl button, #rangectl button { font-size: 12px; padding: 2px 8px; margin-left: 4px; }
#spanctl button.on, #rangectl button.on, #usagectl button.on { border-color: var(--accent); color: var(--accent); }

/* ---------------------------------------------------------------- phone layout
   Under 720px the wide tables stop being tables: every row becomes a card of
   label/value pairs, using the <th> text that panel.js copies onto each cell as
   data-label. Controls grow to touch size and inputs go to 16px, which is what
   stops iOS Safari zooming the page when a field takes focus. */
@media (max-width: 720px) {
  body { font-size: 15px; }
  header { padding: 10px 12px; gap: 8px 12px; }
  h1 { font-size: 16px; flex-basis: 100%; }
  main { padding: 0 12px 40px; }
  #auth { display: flex; flex-wrap: wrap; gap: 8px; width: 100%; }
  #adminkey { flex: 1 1 100%; min-width: 0; }
  /* 16px keeps iOS Safari from zooming the page when a field takes focus */
  input, button, select { font-size: 16px; }
  button { padding: 9px 14px; min-height: 40px; }

  /* The tab strip stays reachable while a long list scrolls under it. The frame is what sticks -
     a sticky element that is also its own scroll container is a bad bet on a phone - and the
     scroller inside it runs edge to edge so a half-tab under the shading is a real, tappable tab. */
  #tabstrip { position: sticky; top: 0; z-index: 5; background: var(--bg); margin: 0 -12px; }
  #tabs { padding: 0 12px; gap: 0; }
  #tabs button { padding: 11px 12px; min-height: 44px; font-size: 14px; }
  #spanctl button, #rangectl button { font-size: 13px; padding: 6px 12px; min-height: 34px; }

  /* A heading that only repeats the tab name is pure vertical cost on a phone; one that names a
     second block inside a panel (Refused requests, Idle release) has to stay. */
  h2.tabname { display: none; }                 /* the tab strip already says which panel this is */
  section#overview > h2 { margin-top: 12px; }   /* kept: the 30 min / 24 h control lives in it */

  .filter { gap: 8px; margin-top: 12px; }
  .filter > span.muted { white-space: nowrap; }
  .filter > * { flex: 1 1 calc(50% - 4px); min-width: 0; }
  .filter input[data-filter], .filter #newkeybtn { flex-basis: 100%; }
  .filter select { width: 100%; }
  .filter button[data-dir] { flex: 0 0 56px; }
  .filter > span.muted { flex: 1 1 auto; text-align: right; }

  .cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .card { min-width: 0; }
  .card b { font-size: 16px; overflow-wrap: anywhere; }

  figcaption { display: grid; gap: 0; }
  .now { text-align: left; }
  .chart { height: 96px; }

  table { border: none; background: none; }
  table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  table tbody, table tr, table td { display: block; }
  table tr { background: var(--card); border: 1px solid var(--line); border-radius: 8px;
             padding: 6px 10px; margin-bottom: 8px; }
  table td { border: none; padding: 3px 0; }
  table td[data-label] { display: grid; grid-template-columns: 96px 1fr; gap: 10px; align-items: baseline; }
  table td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: 12px; }
  /* Must out-rank the rule above, which ties on specificity: a blank cell would
     otherwise render as a label with nothing beside it. */
  table td[data-label]:empty, table td:empty { display: none; }
  tr.revoked { opacity: .55; } .revoked td { opacity: 1; }
  td.edit:hover { outline: none; }
  td.edit { min-height: 24px; }
  .limits .lim { margin: 0 6px 4px 0; }
  .limits span.edit { display: inline-block; padding: 3px 8px;
                      border: 1px dashed var(--line); border-radius: 5px; }
  td[data-label] > input { width: 100%; }   /* the cell editor; chips inside .limits keep their own size */

  /* the modal becomes a bottom sheet: thumb-reachable, and it can scroll */
  dialog { width: 100%; max-width: none; margin: auto 0 0; border-radius: 14px 14px 0 0;
           max-height: 90vh; padding: 14px 14px calc(14px + env(safe-area-inset-bottom)); }
  /* One column: identity, then the numbers - the order the questions come in. The limits stay
     two across, label left and value right, which is the one part of this form that was already
     right on a phone. */
  .dlggrid { grid-template-columns: 1fr; gap: 0; }
  #g-identity, #g-limits { grid-column: 1; grid-row: auto; }
  .field { grid-template-columns: 1fr; gap: 3px; margin-bottom: 9px; }
  .dlggroup.nums { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
  .dlggroup.nums h3 { grid-column: 1 / -1; }
  .dlggroup.nums .field { grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; }
  .dlggroup.nums .field input { width: 80px; justify-self: end; }
  .chip { padding: 9px 14px; font-size: 14px; }     /* a chip is a thumb target here */
  .dlgactions { margin-left: 0; }
  .dlgactions button { flex: 1 1 50%; }
  .secretline code { flex-basis: 100%; }

  /* The requests table is eleven columns of numbers; as stacked cards it would be unreadable.
     It stays a real table at a small size, keeps only the columns worth reading on a phone, and
     pins its header under the tab strip (44px of button plus its 1px rule). */
  /* Requests and Usage are numbers, many columns wide. As stacked cards they are unreadable, so
     they stay real tables: small type, one line per row, header pinned under the tab strip
     (44px of button plus its 1px rule). Keys and Queue keep the card layout - they are mostly
     text, and their rows are things you act on rather than compare.
     .numtable is the same treatment by name rather than by id: the client panel (/me/) has two
     tables of exactly this shape, and they get it from here rather than from a second copy. */
  #requests, #usage, .numtable { display: table; width: 100%; background: var(--card);
                      border: 1px solid var(--line); border-radius: 8px; }
  #requests thead, #usage thead, .numtable thead { display: table-header-group; position: static; width: auto;
                                  height: auto; overflow: visible; clip-path: none; }
  #requests tbody, #usage tbody, .numtable tbody { display: table-row-group; }
  #requests tr, #usage tr, .numtable tr { display: table-row; background: none; border: 0; border-radius: 0;
                            padding: 0; margin: 0; }
  #requests th, #requests td, #usage th, #usage td,
  .numtable th, .numtable td { display: table-cell; border: 0;
                               padding: 5px 4px; white-space: nowrap; }
  /* The cells still carry data-label for the card layout the other tables use; here the real
     <thead> is on screen, so the generated label would print the column name into every cell. */
  #requests td::before, #usage td::before, .numtable td::before { content: none; }
  #requests td, #requests td:empty, #usage td, #usage td:empty,
  .numtable td, .numtable td:empty { display: table-cell; font-size: 12px; }
  /* top: 0 and nothing else. .tablewrap has overflow-x, which makes IT the scrollport this
     header sticks inside - not the window - so any offset here just pushes the header down the
     table, over its own first rows. */
  #requests th, #usage th, .numtable th { position: sticky; top: 0; z-index: 4; font-size: 10px;
                            font-weight: 600; background: var(--card);
                            box-shadow: inset 0 -1px 0 var(--line); }
  #requests tbody td, #usage tbody td, .numtable tbody td { box-shadow: inset 0 -1px 0 var(--line); }
  #requests tbody tr:last-child td, #usage tbody tr:last-child td,
  .numtable tbody tr:last-child td { box-shadow: none; }
  #requests th:first-child, #requests td:first-child,
  #usage th:first-child, #usage td:first-child,
  .numtable th:first-child, .numtable td:first-child { padding-left: 8px; }
  #requests th:last-child, #requests td:last-child,
  #usage th:last-child, #usage td:last-child,
  .numtable th:last-child, .numtable td:last-child { padding-right: 8px; }
  #usage td:first-child { color: var(--muted); }
  /* model, start, prompt and cached and total fold away: the phone keeps when, who, the wait,
     time to first token, tokens out and the rate. The desktop table still shows everything. */
  #requests th:nth-child(3), #requests td:nth-child(3),
  #requests th:nth-child(5), #requests td:nth-child(5),
  #requests th:nth-child(7), #requests td:nth-child(7),
  #requests th:nth-child(8), #requests td:nth-child(8),
  #requests th:nth-child(11), #requests td:nth-child(11) { display: none; }
  /* The name is the one elastic column; every number column stays as wide as its digits, so
     nothing wraps and nothing is clipped mid-number. */
  #requests td:nth-child(2) { max-width: 0; width: 100%; overflow: hidden; text-overflow: ellipsis; }
  /* Usage is six numbers wide and its names are short ("friend", "studio"). Given all the slack
     the name column took two thirds of the row and squeezed the figures the tab exists for, so
     here it is capped instead and the numbers get the rest; the full name stays in the title. */
  /* width 1%: the column takes what the name needs and no more, so the slack in the row goes to
     the six number columns instead of to a name that had already finished drawing. 76px is
     eleven characters at this size - past that the name ellipses and the title has it whole. */
  #usage th:nth-child(2), #usage td:nth-child(2) { width: 1%; }
  #usage td:nth-child(2) .clip { display: block; max-width: 76px; overflow: hidden;
                                 text-overflow: ellipsis; white-space: nowrap; }

  .pauserow { flex-wrap: wrap; gap: 8px; }
  .pausename, .pausereason, .pauserow button, .pauserow .bad { flex: 1 1 100%; }
  .setrow { grid-template-columns: 1fr; gap: 4px; }
  .setrow label { justify-content: space-between; }
  .setname { flex: 1 1 auto; font-size: 13px; }
  .setrow input { width: 120px; }
  .setunit { flex: 0 0 auto; text-align: right; }
}
