/* Ludus operator panel.
 *
 * Constraints that shaped this: no JavaScript is served at all (the panel is
 * forms and links, so the CSP has no script-src), and the theme is decided
 * server-side from a cookie. That rules out anything that needs measurement or
 * runtime state, and it turns out to rule out very little worth having.
 *
 * The visual language is a dense reading surface, not a dashboard: hairline
 * rules instead of cards, one accent used only where a decision is being
 * offered, and monospace reserved for the things an operator copies — ids,
 * keys, timestamps. Numbers are tabular so columns line up when scanned. */

/* ---------- tokens ---------------------------------------------------- */

:root {
  --bg:        #fbfbfa;   /* warm off-white; pure white reads as unfinished */
  --surface:   #ffffff;
  --sunken:    #f4f4f2;
  --text:      #16161a;
  --text-2:    #46464f;
  --muted:     #74747f;
  --line:      #e5e5e1;
  --line-2:    #d3d3ce;
  --accent:    #1f5fa8;
  --accent-fg: #ffffff;
  --accent-sunken: #eef3fa;
  --danger:    #a3302b;
  --danger-sunken: #fbf0ef;
  --ok:        #2e6b46;

  --r:      6px;
  --r-sm:   4px;
  --pad:    clamp(1rem, 4vw, 2rem);

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #0f1012;
    --surface:   #16181b;
    --sunken:    #1b1e22;
    --text:      #e9e9ec;
    --text-2:    #b6b8c0;
    --muted:     #868892;
    --line:      #24262b;
    --line-2:    #33363d;
    --accent:    #7fa9dd;
    --accent-fg: #0f1012;
    --accent-sunken: #182430;
    --danger:    #dd9089;
    --danger-sunken: #2a1c1b;
    --ok:        #82bd9c;
  }
}

:root[data-theme="dark"] {
  --bg:        #0f1012;
  --surface:   #16181b;
  --sunken:    #1b1e22;
  --text:      #e9e9ec;
  --text-2:    #b6b8c0;
  --muted:     #868892;
  --line:      #24262b;
  --line-2:    #33363d;
  --accent:    #7fa9dd;
  --accent-fg: #0f1012;
  --accent-sunken: #182430;
  --danger:    #dd9089;
  --danger-sunken: #2a1c1b;
  --ok:        #82bd9c;
}

/* ---------- base ------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 var(--sans);
  font-feature-settings: "tnum" 1, "cv05" 1;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

code, .mono, time { font-family: var(--mono); font-size: .92em; }

/* ---------- chrome ----------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  height: 52px;
  padding: 0 var(--pad);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 2;
}

.wordmark {
  font-weight: 620;
  letter-spacing: -0.01em;
  font-size: 14px;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: .5rem;
}
.wordmark::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 2px;
  background: var(--accent);
}

.topnav { display: flex; gap: 1.25rem; margin-right: auto; }
.topnav a {
  color: var(--text-2);
  font-size: 13px;
  padding: 4px 0;
  border-bottom: 2px solid transparent;
}
.topnav a:hover { color: var(--text); text-decoration: none; }
.topnav a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }

.identity {
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 22ch;
}

main { max-width: 68rem; margin: 0 auto; padding: 2.25rem var(--pad) 6rem; }

/* ---------- typography ------------------------------------------------- */

h1 {
  font-size: 20px;
  font-weight: 620;
  letter-spacing: -0.015em;
  margin: 0 0 .25rem;
}
h1 .qualifier { font-weight: 400; color: var(--muted); font-family: var(--mono); font-size: 14px; }

.lede { color: var(--muted); margin: 0 0 2rem; max-width: 60ch; font-size: 13px; }

h2 {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 2.5rem 0 .75rem;
  padding-bottom: .5rem;
  border-bottom: 1px solid var(--line);
}

p { margin: 0 0 1rem; }
.hint { color: var(--muted); font-size: 12.5px; max-width: 62ch; }

/* ---------- data ------------------------------------------------------- */

.scroller { overflow-x: auto; margin: 0 calc(var(--pad) * -0.5); padding: 0 calc(var(--pad) * 0.5); }

table { width: 100%; border-collapse: collapse; }

/* Column headers: a micro-label above the data, with the only heavier rule in
   the table. */
thead th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 1rem .5rem 0;
  border-bottom: 1px solid var(--line-2);
  white-space: nowrap;
}

/* Row headers (the label column of a definition table) share the data rhythm,
   so the hairline runs the full width of the row instead of breaking at the
   column boundary. */
tbody th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
}
tbody th, td {
  padding: .7rem 1rem .7rem 0;
  border-bottom: 1px solid var(--line);
  vertical-align: baseline;
}
tbody tr:last-child > * { border-bottom: 0; }
th:last-child, td:last-child { padding-right: 0; }

td.num { font-variant-numeric: tabular-nums; }
td.quiet, .quiet { color: var(--muted); }
td.id { font-family: var(--mono); font-size: 12.5px; }

.empty { color: var(--muted); padding: 1.5rem 0; font-size: 13px; }

/* ---------- figures ---------------------------------------------------- */

.figures { display: flex; gap: 2.5rem; flex-wrap: wrap; margin: 0 0 .5rem; }
.figure .value {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.figure .caption {
  font-size: 11px;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: .2rem;
}

/* ---------- status ----------------------------------------------------- */

.pill {
  display: inline-block;
  font-size: 11px;
  letter-spacing: .04em;
  padding: .1rem .45rem;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  color: var(--muted);
  white-space: nowrap;
}
.pill.live { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.pill.off  { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }

.notice {
  border: 1px solid var(--line-2);
  border-left: 2px solid var(--accent);
  background: var(--accent-sunken);
  border-radius: var(--r-sm);
  padding: .8rem 1rem;
  margin: 0 0 1.5rem;
  font-size: 13px;
}
.notice.warn { border-left-color: var(--danger); background: var(--danger-sunken); }
.notice strong { display: block; margin-bottom: .2rem; }

.secret {
  font-family: var(--mono);
  font-size: 13px;
  word-break: break-all;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  padding: .7rem .8rem;
  margin: .6rem 0;
  user-select: all;
}

/* ---------- forms ------------------------------------------------------ */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 1.25rem;
  margin: 0 0 1.25rem;
}
.panel > :last-child { margin-bottom: 0; }

.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.field > label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}

.controls { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; }
.controls .field { flex: 1 1 12rem; }

/* A checkbox sits beside its label rather than under it, and must escape the
   width:100% that every other input wants. */
label.inline {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  cursor: pointer;
}
label.inline input[type="checkbox"] {
  width: auto;
  min-width: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  padding: .45rem .6rem;
  min-width: 0;
  width: 100%;
}
input:hover, select:hover, textarea:hover { border-color: var(--muted); }
input::placeholder { color: var(--muted); }

textarea {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
  min-height: 22rem;
  resize: vertical;
  tab-size: 2;
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: auto;
}

button {
  font: inherit;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  padding: .45rem .85rem;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { border-color: var(--muted); background: var(--sunken); }
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
button.danger:hover { background: var(--danger-sunken); border-color: var(--danger); }
button.link {
  border: 0; background: none; padding: 0;
  color: var(--accent); font-weight: 400;
}
button.link:hover { background: none; text-decoration: underline; text-underline-offset: 2px; }

/* ---------- theme switch ----------------------------------------------- */

/* Three radio-like submits. There is no JavaScript, so the choice round-trips
   through a cookie and the page re-renders with the new token set. */
.theme { display: flex; border: 1px solid var(--line-2); border-radius: 999px; overflow: hidden; }
.theme button {
  border: 0;
  border-radius: 0;
  padding: .2rem .6rem;
  font-size: 11px;
  letter-spacing: .04em;
  color: var(--muted);
  background: transparent;
}
.theme button + button { border-left: 1px solid var(--line); }
.theme button:hover { background: var(--sunken); color: var(--text); }
.theme button[aria-pressed="true"] { background: var(--sunken); color: var(--text); font-weight: 600; }

/* ---------- pagination -------------------------------------------------- */

.pager {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1.25rem;
  font-size: 12.5px;
  color: var(--muted);
}
.pager .spacer { flex: 1; }

/* ---------- sign-in ---------------------------------------------------- */

.signin {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--pad);
}
.signin-card { width: min(21rem, 100%); text-align: left; }
.signin-card h1 { margin-bottom: .35rem; }
.signin-card .lede { margin-bottom: 2rem; }
.signin-card form { display: flex; flex-direction: column; gap: 1.1rem; }
.signin-card .field { gap: .4rem; }
.signin-card input { padding: .55rem .7rem; }
.signin-card button { width: 100%; padding: .6rem 1rem; }
.signin-card .aside { margin-top: 1rem; font-size: 12px; color: var(--muted); }
.signin-card .notice { margin-bottom: 1.25rem; }

/* A hairline with a word on it, for the "or Google" seam. */
.divider {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin: 1.25rem 0;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

/* ---------- small screens ---------------------------------------------- */

@media (max-width: 40rem) {
  .topbar { gap: 1rem; height: auto; padding: .6rem var(--pad); flex-wrap: wrap; }
  .identity { max-width: 14ch; }
  main { padding-top: 1.5rem; }
  .figures { gap: 1.5rem; }
}

/* --- reference page ------------------------------------------------------ */

/* A jump list rather than a sidebar: the page is long but linear, and a
   sidebar would cost horizontal room the code blocks want. */
.toc {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem .9rem;
  padding: .8rem 1rem;
  margin: 1.2rem 0 2rem;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  font-size: 13px;
}

/* Code samples scroll on their own. The page body must never scroll
   sideways — a horizontal scrollbar under the whole document makes every
   other section harder to read. */
pre.code {
  margin: .9rem 0 0;
  padding: .85rem 1rem;
  overflow-x: auto;
  background: var(--bg);
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.65;
  tab-size: 2;
}
pre.code code { white-space: pre; }

.endpoint { margin-bottom: 1rem; }

.endpoint-head {
  display: flex;
  align-items: center;
  gap: .6rem;
  flex-wrap: wrap;
}

/* The method is the first thing you scan for, so it gets the colour and a
   fixed width — a ragged left edge makes a long list much slower to read. */
.method {
  display: inline-block;
  min-width: 4.2rem;
  text-align: center;
  padding: .15rem .45rem;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-2);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--muted);
}
.method-GET    { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.method-POST   { color: var(--ok);     border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.method-PUT    { color: var(--ok);     border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.method-DELETE { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }

.endpoint-head .path {
  font-family: var(--mono);
  font-size: 13px;
  word-break: break-all;
}

table.params {
  margin: .7rem 0 0;
  font-size: 12.5px;
}
table.params td { padding: .25rem .7rem .25rem 0; vertical-align: top; }

ul.errors { margin: .7rem 0 0; padding-left: 1.1rem; }
ul.errors li { margin: .2rem 0; }
