/* catgw control: an operations console. Quiet neutrals, one teal accent for "act here",
   separate state colors, tabular figures, rows instead of cards. */
:root {
  color-scheme: light dark;
  --bg: #f4f3ef; --surface: #fff; --ink: #1c1d1f; --muted: #5a5e63;
  --line: #d9d6cd; --line-strong: #8a877d;
  --accent: #0b6b5f; --accent-ink: #fff; --accent-soft: #dcefeb;
  --ok: #146c43; --ok-bg: #e1f1e8; --warn: #7a4b00; --warn-bg: #fbefd3;
  --bad: #a4231b; --bad-bg: #fbe3e0; --info: #1f4e8c; --info-bg: #e1ebf8;
  --c-in: #2f6fa8; --c-cache: #a5701a; --c-out: #0b6b5f;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --gutter: clamp(1rem, 4vw, 2rem);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121413; --surface: #1a1d1c; --ink: #ecece8; --muted: #a3a8a5;
    --line: #2d3230; --line-strong: #6f7673;
    --accent: #4cc2ad; --accent-ink: #06211c; --accent-soft: #16312c;
    --ok: #6fd09a; --ok-bg: #14301f; --warn: #f0b44c; --warn-bg: #3a2a0c;
    --bad: #ff8f86; --bad-bg: #3d1714; --info: #8db8ee; --info-bg: #15283f;
    --c-in: #6aa6e0; --c-cache: #e0a64a; --c-out: #4cc2ad;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 1rem/1.5 var(--sans); font-variant-numeric: tabular-nums; }
a { color: var(--accent); text-underline-offset: .15em; }
a:hover { text-decoration-thickness: 2px; }
h1 { font-size: 1.6rem; line-height: 1.2; margin: 0 0 1rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; margin: 2rem 0 .75rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }
p { margin: 0 0 1rem; max-width: 70ch; }
small { color: var(--muted); font-size: .8125rem; }
code, pre, .code { font-family: var(--mono); font-size: .875em; }
.muted { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; left: .5rem; top: -4rem; background: var(--surface); color: var(--ink); padding: .6rem 1rem; border: 2px solid var(--accent); border-radius: 6px; z-index: 10; }
.skip:focus { top: .5rem; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
main:focus { outline: none; }
[hidden] { display: none !important; }

/* Shell: sidebar on wide screens, top bar on narrow ones. */
.app { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; }
.bar { background: var(--surface); border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; align-items: center; gap: .25rem 1rem; padding: .5rem var(--gutter); }
.brand { font-weight: 700; text-decoration: none; color: var(--ink); letter-spacing: -.01em; padding: .5rem 0; }
.brand span { color: var(--accent); margin-left: .35em; font-weight: 500; }
.bar nav { order: 3; flex: 1 0 100%; overflow-x: auto; }
.bar nav ul { list-style: none; margin: 0; padding: 0; display: flex; gap: .25rem; }
.bar nav a { display: block; padding: .6rem .75rem; min-height: 44px; border-radius: 6px; color: var(--ink); text-decoration: none; white-space: nowrap; }
.bar nav a:hover { background: var(--bg); }
.bar nav a[aria-current="page"] { background: var(--accent-soft); color: var(--ink); box-shadow: inset 0 -3px 0 var(--accent); font-weight: 600; }
.who { margin-left: auto; display: flex; align-items: center; gap: .75rem; font-size: .875rem; line-height: 1.3; }
.who form { margin: 0; }
main { padding: 1.5rem var(--gutter) 4rem; min-width: 0; max-width: 78rem; width: 100%; }
main.solo { max-width: 26rem; margin: 0 auto; padding-top: 12vh; }
@media (min-width: 60rem) {
  .app { grid-template-columns: 15rem minmax(0, 1fr); }
  .bar { flex-direction: column; align-items: stretch; flex-wrap: nowrap; gap: 1rem; border-bottom: 0; border-right: 1px solid var(--line); padding: 1.25rem .75rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
  .bar nav { order: 0; flex: 1; overflow: visible; }
  .bar nav ul { flex-direction: column; }
  .bar nav a[aria-current="page"] { box-shadow: inset 3px 0 0 var(--accent); }
  .who { margin: 0; border-top: 1px solid var(--line); padding: .75rem .25rem 0; justify-content: space-between; }
}

/* Controls */
button, .btn { font: inherit; min-height: 44px; padding: .55rem 1rem; border-radius: 6px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: .5rem; }
button:hover, .btn:hover { border-color: var(--ink); }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.primary:hover, .btn.primary:hover { filter: brightness(.92); }
button.danger { color: var(--bad); border-color: var(--bad); }
button.quiet, .btn.quiet { border-color: transparent; background: transparent; color: var(--accent); padding-inline: .5rem; text-decoration: underline; text-underline-offset: .15em; }
button.quiet.danger { color: var(--bad); }
button.wide { width: 100%; }
button:disabled { opacity: .55; cursor: not-allowed; }
input:not([type="checkbox"]), select, textarea { font: inherit; font-size: 1rem; width: 100%; min-height: 44px; padding: .5rem .65rem; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); color: var(--ink); }
textarea { font-family: var(--mono); font-size: .9rem; line-height: 1.45; resize: vertical; min-height: 12rem; white-space: pre; overflow: auto; }
input[type="checkbox"] { width: 1.25rem; height: 1.25rem; accent-color: var(--accent); vertical-align: -.2em; margin-right: .35rem; }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field label, legend { font-weight: 600; font-size: .9rem; }
.check { display: flex; flex-direction: column; gap: .2rem; padding: .35rem 0; }
.check label { display: inline-flex; align-items: flex-start; min-height: 32px; font-weight: 600; }
.check small { margin-left: 1.6rem; max-width: 62ch; }
.check small:has(+ *), .check small { line-height: 1.4; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 1rem; margin: 0; min-width: 0; background: var(--surface); }
legend { padding: 0 .4rem; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.narrow { max-width: 34rem; }
.row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; }
.grid4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: 1rem; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: .75rem 1rem; align-items: end; margin-bottom: 1.25rem; padding: 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.filters .row, .filters .check { grid-column: 1 / -1; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); }
.or { text-align: center; color: var(--muted); margin: 1rem 0; display: flex; align-items: center; gap: .75rem; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

/* Notices and secrets */
.notice { padding: .75rem 1rem; border-radius: 6px; border: 1px solid var(--line); border-left-width: 4px; background: var(--surface); max-width: 70ch; margin: 0 0 1rem; }
.notice.ok { border-color: var(--ok); background: var(--ok-bg); }
.notice.warn { border-color: var(--warn); background: var(--warn-bg); }
.notice.bad { border-color: var(--bad); background: var(--bad-bg); }
.errors { margin: 0; padding-left: 1.25rem; font-family: var(--mono); font-size: .875rem; }
.secret { border: 2px solid var(--accent); background: var(--accent-soft); border-radius: 8px; padding: 1rem; margin: 0 0 1.5rem; max-width: 46rem; }
.token, .fp { display: block; font-family: var(--mono); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 6px; padding: .75rem; overflow-wrap: anywhere; user-select: all; }
.fp { line-height: 1.7; letter-spacing: .02em; }
.empty { color: var(--muted); padding: 1.25rem 0; }

/* Lists, tables */
.scroll { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; margin: 0 0 1.5rem; max-width: 100%; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: left; padding: .6rem .75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); white-space: nowrap; background: var(--bg); position: sticky; top: 0; }
tbody th { font-weight: 600; }
tbody tr:last-child > * { border-bottom: 0; }
td.n, th.n { text-align: right; white-space: nowrap; }
td.act { text-align: right; white-space: nowrap; }
td.bar { min-width: 6rem; vertical-align: middle; }
tr.sub td { background: var(--bad-bg); color: var(--ink); }
tr.grp th { background: var(--accent-soft); font-size: .9rem; text-transform: none; letter-spacing: 0; color: var(--ink); }
td form, th form { margin: 0; }
.links { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; margin: 0 0 1rem; }
.links a { display: inline-block; padding: .5rem 0; }
.quick a { display: inline-block; padding: .5rem .75rem 0 0; }
dl.facts { display: grid; grid-template-columns: minmax(8rem, 14rem) minmax(0, 1fr); gap: .5rem 1.25rem; margin: 0 0 1.5rem; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 36rem) { dl.facts { grid-template-columns: 1fr; gap: .1rem; } dl.facts dd { margin-bottom: .6rem; } }
dl.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); gap: .75rem; margin: 0 0 1.5rem; }
dl.tiles > div { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .75rem 1rem; }
dl.tiles dt { font-size: .8125rem; color: var(--muted); }
dl.tiles dd { margin: 0; font-size: 1.6rem; font-weight: 650; line-height: 1.2; }
details { margin: 0 0 1.5rem; }
summary { cursor: pointer; padding: .5rem 0; min-height: 44px; }
pre.code { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 1rem; overflow: auto; max-height: 32rem; margin: 0 0 1.5rem; white-space: pre-wrap; overflow-wrap: anywhere; }

/* Status chips: the word carries the meaning, color reinforces it */
.chip { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 600; border: 1px solid currentColor; white-space: nowrap; margin: 0 .25rem .15rem 0; }
.chip.ok { color: var(--ok); background: var(--ok-bg); }
.chip.warn { color: var(--warn); background: var(--warn-bg); }
.chip.bad { color: var(--bad); background: var(--bad-bg); }
.chip.info { color: var(--info); background: var(--info-bg); }
.chip.mute { color: var(--muted); background: transparent; }

/* The fallback chain: one hop per upstream attempt, left to right */
.chain { list-style: none; margin: 0 0 1rem; padding: 0; display: flex; flex-wrap: wrap; gap: .25rem; align-items: center; }
td .chain { margin: 0; }
.hop { display: inline-flex; align-items: baseline; gap: .35rem; border: 1px solid var(--line-strong); border-radius: 6px; padding: .15rem .5rem; font-size: .8rem; background: var(--surface); white-space: nowrap; }
.hop + .hop::before { content: "\2192"; color: var(--muted); }
.hop-n { font-weight: 700; }
.hop-st { font-family: var(--mono); }
.hop.ok { border-color: var(--ok); }
.hop.fail { border-color: var(--bad); background: var(--bad-bg); }
.hop.fail .hop-st { color: var(--bad); font-weight: 700; }
.hop.ok .hop-st { color: var(--ok); font-weight: 700; }

/* Charts */
.chart { width: 100%; height: auto; max-width: 46rem; display: block; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .ax { fill: var(--muted); font-size: 10px; font-family: var(--sans); }
.s-in { fill: var(--c-in); } .s-cache { fill: var(--c-cache); } .s-out { fill: var(--c-out); }
.line { fill: none; stroke-width: 2; stroke-linejoin: round; }
.l-50 { stroke: var(--c-out); } .l-95 { stroke: var(--c-cache); stroke-dasharray: 6 3; } .l-99 { stroke: var(--bad); stroke-dasharray: 2 3; }
.legend { font-size: .8125rem; color: var(--muted); margin: .5rem 0 1.5rem; }
.legend .key { display: inline-block; width: .8rem; height: .8rem; border-radius: 2px; margin: 0 .3rem 0 .75rem; vertical-align: -.1em; }
.legend .key.s-in { background: var(--c-in); } .legend .key.s-cache { background: var(--c-cache); } .legend .key.s-out { background: var(--c-out); }
.legend .key.l-50 { background: var(--c-out); } .legend .key.l-95 { background: var(--c-cache); } .legend .key.l-99 { background: var(--bad); }
.hbar { width: 100%; height: .5rem; display: block; }
.hbar .track { fill: var(--line); } .hbar .fill { fill: var(--accent); }

@media (prefers-reduced-motion: no-preference) { button, .btn, a { transition: background-color .12s, border-color .12s; } }
@media print { .bar, .skip { display: none; } .app { display: block; } }
