/* ============================================================================
   llm.kezu.co — design system
   ----------------------------------------------------------------------------
   Surface: OPERATE / MONITOR (an API console). Not a marketing page.
   So: density and glanceable hierarchy beat decoration. No hero, no feature
   tiles, no gradients, no icon-toppers. Numbers get tabular figures and tight
   vertical rhythm; state gets pills; one accent per page.

   Theme: light default (docs/console convention), dark via [data-theme=dark].
   Fonts are SELF-HOSTED variable woff2 — no CDN, no Google request, no FOUT.
   ========================================================================== */

/* ---------------------------------------------------------------- fonts --- */
@font-face {
  font-family: 'Instrument Sans';
  src: url('/static/fonts/InstrumentSans-VF.woff2') format('woff2-variations');
  font-weight: 400 700;
  font-display: swap;
  font-style: normal;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('/static/fonts/JetBrainsMono-VF.woff2') format('woff2-variations');
  font-weight: 400 500;
  font-display: swap;
  font-style: normal;
}

/* ---------------------------------------------------------------- tokens -- */
:root {
  /* surfaces */
  --bg:        #fbfbfa;
  --surface:   #ffffff;
  --sunken:    #f5f5f3;
  --raised:    #ffffff;
  --line:      #e7e7e3;
  --line-soft: #f0f0ec;
  --line-2:    #d8d8d2;   /* stronger hairline (reveal dividers) */

  /* ink
     Contrast-checked against the WORST surface each colour is used on (--sunken,
     not --surface) because --muted/--faint legitimately appear on table headers,
     KPI labels and card headings:
        #191919 16.1:1   #4a4a4d 8.1:1   #5f5f66 5.8:1   #6b6b72 4.8:1
     The previous --muted (4.25:1) / --faint (2.50:1) failed AA for small text,
     which showed up as 308 failing nodes on /admin/audit alone. */
  --fg:     #191919;
  --fg-2:   #4a4a4d;
  --muted:  #5f5f66;
  --faint:  #6b6b72;

  /* one accent, used for links / focus / active only */
  --accent:      #955020;   /* copper — see DESIGN.md; system.css overrides */
  --accent-soft: #FBF3EA;
  --accent-line: #E8D3BC;

  /* semantic */
  --ok:        #0f7a3d;
  --ok-bg:     #eaf7ef;
  --ok-line:   #c3e6d1;
  --warn:      #96620a;
  --warn-bg:   #fdf5e5;
  --warn-line: #f0dfb5;
  --bad:       #b3261e;
  --bad-bg:    #fdeceb;
  --bad-line:  #f4cbc7;

  /* primary button = near-black (premium, low colour noise) */
  --btn:      #1c1c1f;
  --btn-hov:  #000000;
  --btn-fg:   #ffffff;

  /* geometry */
  --r-sm: 6px;
  --r:    9px;
  --r-lg: 12px;
  --shadow: 0 1px 2px rgba(16,16,20,.04), 0 1px 1px rgba(16,16,20,.03);
  --shadow-pop: 0 8px 28px rgba(16,16,20,.10), 0 1px 3px rgba(16,16,20,.06);

  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: 'Instrument Sans', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  color-scheme: light;
}

[data-theme="dark"] {
  --bg:        #0c0c0e;
  --surface:   #141416;
  --sunken:    #0a0a0b;
  --raised:    #191a1d;
  --line:      #26262a;
  --line-soft: #1e1e21;
  --line-2:    #34343a;

  /* same rule: #ececef 16.8:1  #b9b9c0 10.1:1  #9a9aa2 7.1:1  #8e8e96 6.1:1
     on --sunken. The old --faint (#6a6a72, 3.69:1) failed AA. */
  --fg:    #ececef;
  --fg-2:  #b9b9c0;
  --muted: #9a9aa2;
  --faint: #8e8e96;

  --accent:      #E09A5C;   /* copper (dark) */
  --accent-soft: #2A1F14;
  --accent-line: #4A3520;

  --ok:        #4fbe7f;
  --ok-bg:     #0e1c14;
  --ok-line:   #1d3a28;
  --warn:      #e0b155;
  --warn-bg:   #1d1810;
  --warn-line: #3a2f18;
  --bad:       #f08a80;
  --bad-bg:    #1e1113;
  --bad-line:  #3d2124;

  --btn:     #f2f2f4;
  --btn-hov: #ffffff;
  --btn-fg:  #111113;

  --shadow: 0 1px 2px rgba(0,0,0,.4);
  --shadow-pop: 0 10px 32px rgba(0,0,0,.55);

  color-scheme: dark;
}

/* --------------------------------------------------------------- reset ---- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  font-feature-settings: "cv05" 1;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.011em; }
p { margin: 0 0 10px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
img, svg { max-width: 100%; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* --------------------------------------------------------------- layout --- */
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 24px; }
main { padding: 30px 0 72px; }

.topbar {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-in {
  display: flex; align-items: center; gap: 6px;
  max-width: 1180px; margin: 0 auto; padding: 0 24px; height: 56px;
}
.brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 600; letter-spacing: -0.015em; font-size: 14.5px;
  color: var(--fg); margin-right: 14px; white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand .dot {
  width: 20px; height: 20px; border-radius: 6px; flex: none;
  background: var(--fg); color: var(--bg);
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700; letter-spacing: -0.03em;
}
.brand .tag {
  font-size: 10.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); border: 1px solid var(--line); border-radius: 999px;
  padding: 1.5px 7px; background: var(--sunken);
}
.nav { display: flex; align-items: center; gap: 2px; }
.nav a {
  color: var(--muted); font-size: 13.5px; font-weight: 500;
  padding: 6px 11px; border-radius: var(--r-sm);
}
.nav a:hover { color: var(--fg); background: var(--sunken); text-decoration: none; }
.nav a.active { color: var(--fg); background: var(--sunken); font-weight: 600; }
.topbar .spacer { flex: 1; }
.topbar .actions { display: flex; align-items: center; gap: 8px; }

/* mobile nav */
.nav-toggle { display: none; }
@media (max-width: 860px) {
  .topbar-in { flex-wrap: wrap; height: auto; padding: 10px 18px; }
  .nav { width: 100%; flex-wrap: wrap; gap: 2px; padding-bottom: 6px; }
  .nav a { padding: 5px 9px; font-size: 13px; }
  .wrap { padding: 0 18px; }
}

/* ------------------------------------------------------------ typography -- */
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 20px; flex-wrap: wrap; margin-bottom: 24px;
}
.page-head h1 { font-size: 23px; letter-spacing: -0.022em; }
.page-head .sub { color: var(--muted); margin: 5px 0 0; font-size: 13.5px; max-width: 68ch; }
h2 {
  font-size: 13px; font-weight: 600; color: var(--fg-2);
  text-transform: uppercase; letter-spacing: .07em;
  margin: 32px 0 12px;
}
h2:first-child { margin-top: 0; }
.eyebrow {
  font-size: 11px; font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: var(--faint);
}
.lead { font-size: 15px; color: var(--fg-2); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }

/* ---------------------------------------------------------------- cards --- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 18px;
}
.card + .card { margin-top: 14px; }
.card h3 {
  margin: 0 0 12px; font-size: 11.5px; font-weight: 600;
  letter-spacing: .07em; text-transform: uppercase; color: var(--faint);
}
.card.flush { padding: 0; overflow: hidden; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.card-head h3 { margin: 0; }
.card-body { padding: 18px; }

/* KPI strip — a divided row, deliberately NOT a row of cards */
.kpis {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); overflow: hidden;
}
.kpi { padding: 16px 18px; border-right: 1px solid var(--line-soft); }
.kpi:last-child { border-right: 0; }
.kpi .k {
  font-size: 11px; font-weight: 600; letter-spacing: .075em;
  text-transform: uppercase; color: var(--faint); margin-bottom: 7px;
}
.kpi .v {
  font-size: 26px; font-weight: 600; letter-spacing: -0.03em;
  line-height: 1.05; font-variant-numeric: tabular-nums;
}
.kpi .v small { font-size: 14px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.kpi .n { font-size: 12.5px; color: var(--muted); margin-top: 5px; }
@media (max-width: 640px) {
  .kpi { border-right: 0; border-bottom: 1px solid var(--line-soft); }
  .kpi:last-child { border-bottom: 0; }
}

.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

/* --------------------------------------------------------------- tables --- */
.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left; padding: 11px 18px;
  border-bottom: 1px solid var(--line-soft); vertical-align: middle;
}
th {
  font-size: 11px; font-weight: 600; letter-spacing: .075em;
  text-transform: uppercase; color: var(--faint);
  background: var(--sunken); border-bottom: 1px solid var(--line);
  white-space: nowrap; position: sticky; top: 0;
}
td { font-size: 13.5px; }
tbody tr:last-child td, tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--sunken); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.mono, .mono { font-family: var(--mono); font-size: 12.5px; }
td .row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.overflow-cell { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

code {
  font-family: var(--mono); font-size: 12.5px; overflow-wrap: anywhere;
  background: var(--sunken); border: 1px solid var(--line-soft);
  padding: 1.5px 5px; border-radius: var(--r-sm); color: var(--fg-2);
  overflow-wrap: anywhere;
}
pre {
  font-family: var(--mono); font-size: 12.5px; line-height: 1.7;
  background: var(--sunken); border: 1px solid var(--line);
  border-radius: var(--r); padding: 14px; overflow: auto;
  margin: 0; color: var(--fg-2);
  /* A long URL or model id in a code block would otherwise force the block wider than
     its card and push the page sideways on mobile (measured: 436px block in a 375px
     viewport). Break long tokens rather than overflowing; `pre` stays monospace. */
  max-width: 100%;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
pre code { background: none; border: 0; padding: 0; }

/* ---------------------------------------------------------------- forms --- */
label {
  display: block; margin: 0 0 6px;
  font-size: 12.5px; font-weight: 500; color: var(--fg-2);
}
label .opt { color: var(--faint); font-weight: 400; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 13.5px;
  background: var(--surface); color: var(--fg);
  border: 1px solid var(--line); border-radius: var(--r);
  padding: 9px 11px; transition: border-color .12s, box-shadow .12s;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; min-height: 76px; line-height: 1.6; }
.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 5px; }
.check { display: flex; align-items: flex-start; gap: 9px; margin: 0; cursor: pointer; }
.check input[type=checkbox] { width: auto; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.check span { font-size: 13.5px; color: var(--fg-2); font-weight: 400; }
.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }

/* -------------------------------------------------------------- buttons --- */
.btn, button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-size: 13.5px; font-weight: 500;
  padding: 9px 15px; min-height: 38px;
  border-radius: var(--r); border: 1px solid transparent; cursor: pointer;
  background: var(--btn); color: var(--btn-fg);
  transition: background .12s, border-color .12s, opacity .12s;
  text-decoration: none; white-space: nowrap;
}
.btn:hover, button:hover { background: var(--btn-hov); text-decoration: none; }
.btn:disabled, button:disabled { opacity: .5; cursor: not-allowed; }
.btn.sec, button.sec {
  background: var(--surface); color: var(--fg); border-color: var(--line);
}
.btn.sec:hover, button.sec:hover { background: var(--sunken); border-color: var(--faint); }
.btn.ghost, button.ghost { background: transparent; color: var(--muted); border-color: transparent; }
.btn.ghost:hover, button.ghost:hover { background: var(--sunken); color: var(--fg); }
.btn.danger, button.danger {
  background: var(--surface); color: var(--bad); border-color: var(--bad-line);
}
.btn.danger:hover, button.danger:hover { background: var(--bad-bg); }
.btn.sm, button.sm { padding: 5px 10px; min-height: 30px; font-size: 12.5px; border-radius: var(--r-sm); }
.btn.block { width: 100%; }
.btn[aria-disabled=true] { opacity: .5; pointer-events: none; }
@media (max-width: 640px) { .btn, button { min-height: 44px; } .btn.sm, button.sm { min-height: 34px; } }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.stack { display: flex; flex-direction: column; gap: 10px; }

/* --------------------------------------------------------------- pills ---- */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 500; line-height: 1;
  padding: 4px 8px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--sunken); color: var(--muted);
  white-space: nowrap;
}
.pill.ok   { color: var(--ok);   background: var(--ok-bg);   border-color: var(--ok-line); }
.pill.warn { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-line); }
.pill.bad  { color: var(--bad);  background: var(--bad-bg);  border-color: var(--bad-line); }
.pill.accent { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-line); }
.pill.mono { font-family: var(--mono); font-size: 11.5px; font-weight: 400; letter-spacing: -0.02em; }

/* Model ids are path-like and long ("mestrator/deepseek-deepseek-v4.1-flash"). A nowrap
   pill inside a narrow KPI cell overflows its column (measured: 273px pill in a 246px
   parent). Let path-like pills wrap and break mid-token, while ordinary short pills
   keep the single-line chip look. */
.pill.wrap { white-space: normal; overflow-wrap: anywhere; max-width: 100%; }
.kpi .pill { max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
.dot-ok { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }

/* ---------------------------------------------------------------- meter --- */
.meter { height: 6px; border-radius: 999px; background: var(--sunken); overflow: hidden; margin: 10px 0; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s; }
.meter.warn > span { background: var(--warn); }
.meter.bad  > span { background: var(--bad); }

/* --------------------------------------------------------------- alerts --- */
.alert {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--r);
  border: 1px solid var(--line); background: var(--sunken); color: var(--fg-2);
  font-size: 13.5px; margin-bottom: 14px;
}
.alert:last-child { margin-bottom: 0; }
.alert .ic { flex: none; font-weight: 700; font-size: 13px; line-height: 1.5; }
.alert strong { color: var(--fg); font-weight: 600; }
.alert.ok   { background: var(--ok-bg);   border-color: var(--ok-line);   color: var(--fg-2); }
.alert.ok .ic   { color: var(--ok); }
.alert.warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--fg-2); }
.alert.warn .ic { color: var(--warn); }
.alert.err  { background: var(--bad-bg);  border-color: var(--bad-line);  color: var(--fg-2); }
.alert.err .ic  { color: var(--bad); }
.alert a { font-weight: 500; }

/* --------------------------------------------------------------- lists ---- */
ul.notes { margin: 0; padding-left: 18px; color: var(--muted); font-size: 13.5px; }
ul.notes li { margin-bottom: 7px; }
ul.notes li:last-child { margin-bottom: 0; }
ul.notes strong { color: var(--fg); font-weight: 600; }
dl.deflist { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 8px 18px; font-size: 13.5px; }
dl.deflist dt { color: var(--muted); }
dl.deflist dd { margin: 0; font-variant-numeric: tabular-nums; }

/* empty state */
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .t { font-weight: 600; color: var(--fg); margin-bottom: 5px; font-size: 14px; }
.empty .d { font-size: 13.5px; margin-bottom: 16px; }

/* ---------------------------------------------------------------- login --- */
.auth {
  min-height: 100vh; display: grid; place-items: center; padding: 32px 20px;
  background:
    radial-gradient(880px 420px at 50% -8%, var(--accent-soft), transparent 70%),
    var(--bg);
}
.auth-card { width: 100%; max-width: 396px; }
.auth-brand {
  display: flex; align-items: center; gap: 9px; justify-content: center;
  margin-bottom: 22px;
}
.auth-brand .dot {
  width: 26px; height: 26px; border-radius: 8px; background: var(--fg); color: var(--bg);
  display: grid; place-items: center; font-size: 13px; font-weight: 700;
}
.auth-brand .nm { font-weight: 600; font-size: 15px; letter-spacing: -0.015em; }
.auth-card .card { padding: 24px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 19px; letter-spacing: -0.02em; margin-bottom: 5px; }
.auth-card .sub { margin-bottom: 20px; }
.auth-foot { text-align: center; margin-top: 18px; font-size: 12.5px; color: var(--faint); }

/* ---------------------------------------------------------------- misc ---- */
.copied { color: var(--ok) !important; border-color: var(--ok-line) !important; }
.sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.divider { height: 1px; background: var(--line); margin: 20px 0; }

@media print {
  .topbar, .btn, button { display: none !important; }
  body { background: #fff; }
  .card { break-inside: avoid; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}


/* API key reveal: a <details> so the full key is available without embedding it in
   the default render. Owner-only page, so this is not a public disclosure. */
.keyreveal > summary {
  cursor: pointer; color: var(--fg-2); list-style: none;
  border-bottom: 1px dashed var(--line-2); padding-bottom: 1px;
}
.keyreveal > summary::-webkit-details-marker { display: none; }
.keyreveal > summary:hover { color: var(--fg); }
.keyreveal code { font-size: 12px; color: var(--fg-2); }
