/* ==========================================================================
   Compass — design system
   ==========================================================================

   Structure: tokens, reset, typography, shell, then components. Components are
   written against role tokens, never raw hex, so the palette changes in one place.

   Two decisions that shape everything below:

   1. The surfaces are a WARM neutral (#1a1a19, #0d0d0d), not blue-tinted slate.
      Blue-grey surfaces under a cornflower accent is the default look of every
      generated dashboard; warm neutral under one cool accent reads deliberate,
      and it makes the status colours (which are warm) sit naturally rather than
      fighting a blue cast.

   2. Status colour is never the only signal. Every score carries a word as well
      as a hue — see `.stat` and `.judgement`. A reader with deuteranopia, or
      anyone glancing at a screenshot, gets the same information.

   Palette provenance: surfaces, ink and the status roles are the validated
   reference instance from the data-viz guidance. The accent is its categorical
   slot-1 blue, chosen because the status palette occupies green/yellow/red — blue
   is the only hue family left that cannot be mistaken for a severity. Verified on
   this surface: all four clear 3:1, worst adjacent CVD ΔE 11.3, normal-vision
   27.6. The meter's track/fill pair passes as a single-hue ordinal ramp.
   ========================================================================== */

:root {
  /* --- surfaces, back to front --- */
  --plane:        #0d0d0d;   /* the page behind everything */
  --surface:      #1a1a19;   /* panels, cards, the topbar */
  --raised:       #242422;   /* inputs, nested blocks, hover fills */
  --hairline:     #2c2c2a;   /* the default 1px separator */
  --hairline-firm:#383835;   /* where a division needs to be felt */

  /* --- ink ---
     Body text is a warm off-white rather than pure #fff: at 14.5px over a long
     gap report, pure white on near-black glares. Values and headings take the
     full white, so numbers stay the brightest thing on the page. */
  --ink:          #f2f2ee;
  --ink-strong:   #ffffff;
  --ink-soft:     #c3c2b7;
  --ink-muted:    #898781;

  /* --- accent, and its own ramp --- */
  --accent:       #3987e5;
  --accent-hover: #5598e7;
  --accent-deep:  #184f95;   /* meter tracks: tone-on-tone with the fill */
  --accent-wash:  rgba(57, 135, 229, .12);
  --on-accent:    #07131f;

  /* --- status: reserved roles, never reused as decoration --- */
  --good:         #0ca30c;
  --warn:         #fab219;
  --bad:          #d03b3b;
  --good-wash:    rgba(12, 163, 12, .12);
  --warn-wash:    rgba(250, 178, 25, .12);
  --bad-wash:     rgba(208, 59, 59, .12);

  /* --- space: a 4px rhythm, named so usage stays honest --- */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px;

  --r-sm: 6px;   /* inputs, buttons */
  --r-md: 10px;  /* panels */
  --r-full: 999px;

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;

  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.6);
}

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

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

body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font: 400 14.5px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Every animation in here is a 120–180ms opacity/colour change. Honour the
   preference rather than argue with it. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ==========================================================================
   Typography
   ========================================================================== */

h1, h2, h3, h4 { margin: 0; font-weight: 600; color: var(--ink-strong); }
h1 { font-size: 25px; letter-spacing: -.02em; line-height: 1.25; }
h3 { font-size: 14.5px; }
h4 { font-size: 13.5px; }

/* h2 is a section label, not a heading-shaped block of text: small, tracked,
   quiet, with a hairline running off to the right. It organises the page without
   competing with the data on it.

   The rule is drawn by the element itself rather than by a wrapper, so every
   plain `<h2>` in the templates gets it with no markup change — which is the
   only reason this was affordable to apply across twenty pages. */
h2 {
  display: flex; align-items: center; gap: var(--s3);
  margin: var(--s6) 0 var(--s3);
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--ink-muted);
}
h2::after { content: ""; flex: 1; height: 1px; background: var(--hairline); }
/* Inside a panel the panel's own edge already bounds the section. */
.card > h2, .panel > h2 { margin-top: 0; }
.card > h2::after, .panel > h2::after { display: none; }

p { margin: 0 0 var(--s3); }
p:last-child { margin-bottom: 0; }

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

strong { font-weight: 600; color: var(--ink-strong); }
code, .mono { font-family: var(--mono); font-size: .92em; }

.muted  { color: var(--ink-muted); }
.soft   { color: var(--ink-soft); }
.small  { font-size: 13px; }
.micro  { font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-muted); }
.good   { color: var(--good); }
.warn   { color: var(--warn); }
.bad    { color: var(--bad); }
.nowrap { white-space: nowrap; }

/* :focus-visible only — a mouse click should not draw a ring, a Tab should. */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* ==========================================================================
   Shell
   ========================================================================== */

.topbar {
  display: flex; align-items: center; gap: var(--s5);
  height: 56px; padding: 0 var(--s5);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--hairline);
  position: sticky; top: 0; z-index: 30;
}

.brand {
  display: flex; align-items: center; gap: var(--s2);
  font-size: 15px; font-weight: 600; letter-spacing: -.01em;
  color: var(--ink-strong);
}
.brand:hover { text-decoration: none; color: var(--ink-strong); }
.brand::before {
  content: ""; width: 7px; height: 7px; border-radius: var(--r-full);
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-wash);
}

.topbar nav { display: flex; gap: var(--s1); margin-left: var(--s3); }
.topbar nav a {
  position: relative;
  padding: var(--s2) var(--s3);
  font-size: 13.5px; color: var(--ink-muted);
  border-radius: var(--r-sm);
  transition: color .12s, background .12s;
}
.topbar nav a:hover { color: var(--ink); background: var(--raised); text-decoration: none; }
/* The active tab is marked by a rule under it, not by bold text — weight
   changes shift the nav's layout as you move between pages. */
.topbar nav a.active { color: var(--ink-strong); }
.topbar nav a.active::after {
  content: ""; position: absolute; left: var(--s3); right: var(--s3); bottom: -13px;
  height: 2px; background: var(--accent); border-radius: 2px 2px 0 0;
}

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: var(--s3); }

main { max-width: 1120px; margin: 0 auto; padding: var(--s6) var(--s5) var(--s8); }
main.narrow { max-width: 440px; }

footer {
  max-width: 1120px; margin: 0 auto; padding: var(--s5);
  border-top: 1px solid var(--hairline);
  color: var(--ink-muted); font-size: 12.5px;
}

/* --- auth pages ---------------------------------------------------------
   Sign-in, first-run setup and invite acceptance. Centred in the viewport
   rather than pinned to the top, and the footer narrowed to the same column:
   left at the app's 1120px it ran three times the width of the form it sat
   under, which read as a broken page rather than a quiet one. */
body:has(main.narrow) {
  display: flex; flex-direction: column; min-height: 100vh;
}
body:has(main.narrow) main { margin: auto; padding-top: var(--s6); }
body:has(main.narrow) footer { max-width: 440px; width: 100%; }

/* --- page header: one consistent block per view --------------------------- */

.page-head {
  display: flex; align-items: flex-start; gap: var(--s4);
  padding-bottom: var(--s4); margin-bottom: var(--s5);
  border-bottom: 1px solid var(--hairline);
}
.page-head .titles { min-width: 0; flex: 1; }
.page-head .actions { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; }
.sub { margin: var(--s1) 0 0; color: var(--ink-muted); font-size: 13.5px; max-width: 68ch; }

/* Pages that still open with a bare `h1` + `.sub` rather than a `.page-head`
   get the same rule and rhythm, so the two patterns look identical. */
main > h1:first-child,
main > .spread:first-child { margin-bottom: var(--s1); }
main > h1:first-child + .sub,
main > .spread:first-child + .sub {
  padding-bottom: var(--s4); margin-bottom: 0;
  border-bottom: 1px solid var(--hairline);
}

/* --- section: a labelled band of the page -------------------------------- */

.section { margin-top: var(--s6); }
.section > .section-head {
  display: flex; align-items: baseline; gap: var(--s3);
  margin-bottom: var(--s3);
}
.section > .section-head::after {
  content: ""; flex: 1; height: 1px; background: var(--hairline);
}
.section > .section-head .hint { font-size: 12.5px; color: var(--ink-muted); }

/* ==========================================================================
   Layout primitives
   ========================================================================== */

.grid { display: grid; gap: var(--s4); }
.grid.two   { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid.four  { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

.row    { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; }
/* `flex-wrap` matters as much here as on `.row`. Without it, a label-and-button
   pair has nowhere to go when the text is long: space-between keeps pushing the
   button right until it leaves the viewport. That was the last overflow on the
   application detail page — +17px at 320px, from the Re-score button. */
.spread { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.stack > * + * { margin-top: var(--s3); }

/* `min-width: 0` on grid and flex children is load-bearing, not tidying. Both
   default to `min-width: auto`, which refuses to shrink a box below its
   content's intrinsic width — so one wide table inside a card pushes the card,
   the grid and then the page wider, and no `max-width` on the table can stop it
   because the constraint it resolves against is the thing being widened.
   Measured: without this, the settings page overflowed 320px by 487px. */
.grid > *, .row > *, .spread > * { min-width: 0; }

.card, .panel {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  padding: var(--s4) var(--s5);
  min-width: 0;
}
.card.tight { padding: var(--s3) var(--s4); }
.card > h2:first-child, .panel > h2:first-child { margin-bottom: var(--s3); }

hr { border: none; border-top: 1px solid var(--hairline); margin: var(--s4) 0; }

pre.doc {
  background: var(--plane); border: 1px solid var(--hairline);
  border-radius: var(--r-sm); padding: var(--s3) var(--s4);
  white-space: pre-wrap; word-break: break-word;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.65;
  color: var(--ink-soft); margin: 0;
  max-height: 460px; overflow: auto;
}

/* ==========================================================================
   Figures — stat tiles, hero numbers, meters
   ==========================================================================
   Stat contract: label (sentence case) · value · meta. Large standalone values
   use the font's proportional figures; `tabular-nums` is reserved for columns
   that must align, because at 30px+ tabular digits make a number like 121 look
   gappy. */

.stat .label {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--ink-muted); margin-bottom: var(--s1);
}
.stat .value {
  font-size: 30px; font-weight: 600; line-height: 1.05;
  letter-spacing: -.02em; color: var(--ink-strong);
}
.stat .meta { margin-top: var(--s1); font-size: 12.5px; color: var(--ink-muted); }

/* Exactly one per view. It has to *read* as primary, not merely be bigger by a
   few pixels: a tinted plane and a visible accent edge do more of that work than
   type size alone, which is why the first attempt looked like one of four. */
.stat.hero {
  background: linear-gradient(160deg, var(--accent-wash), transparent 60%), var(--surface);
  border-color: rgba(57, 135, 229, .28);
  display: flex; flex-direction: column;
}
.stat.hero .value { font-size: 48px; margin-top: var(--s1); }
.stat.hero .bar { margin-top: var(--s4); }
.stat.hero .meta { margin-top: auto; padding-top: var(--s3); }

/* A status hue on the number is a supplement. `.judgement` below carries the
   word, and one of the two is always present. */
.stat .value.good { color: var(--good); }
.stat .value.warn { color: var(--warn); }
.stat .value.bad  { color: var(--bad); }

/* Legacy alias: `.metric` markup predates this file. */
.metric .value { font-size: 28px; font-weight: 600; line-height: 1.1; color: var(--ink-strong); letter-spacing: -.02em; }
.metric .label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-muted); }
.metric .value.good { color: var(--good); }
.metric .value.warn { color: var(--warn); }
.metric .value.bad  { color: var(--bad); }

/* --- judgement: the word beside the number ------------------------------ */

.judgement {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 500; color: var(--ink-soft);
}
.judgement::before {
  content: ""; width: 7px; height: 7px; border-radius: var(--r-full);
  background: currentColor; flex: none;
}
.judgement.good { color: var(--good); }
.judgement.warn { color: var(--warn); }
.judgement.bad  { color: var(--bad); }

/* --- meter: fill carries severity, track is tone-on-tone ---------------- */

.bar {
  height: 5px; border-radius: var(--r-full); overflow: hidden;
  background: var(--accent-deep); margin-top: var(--s2);
}
.bar > span {
  display: block; height: 100%; background: var(--accent);
  border-radius: var(--r-full);
  transition: width .3s ease-out;
}
.bar > span.good { background: var(--good); }
.bar > span.warn { background: var(--warn); }
.bar > span.bad  { background: var(--bad); }
/* Severity states re-tone the track so the whole bar reads as one state. */
.bar:has(> span.good) { background: rgba(12,163,12,.2); }
.bar:has(> span.warn) { background: rgba(250,178,25,.2); }
.bar:has(> span.bad)  { background: rgba(208,59,59,.2); }

/* ==========================================================================
   Pills & tags
   ========================================================================== */

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: var(--r-full);
  font-size: 11.5px; font-weight: 500; line-height: 1.7;
  border: 1px solid var(--hairline); background: var(--raised);
  color: var(--ink-soft); white-space: nowrap;
}
.pill.good   { color: var(--good);   background: var(--good-wash);   border-color: rgba(12,163,12,.3); }
.pill.warn   { color: var(--warn);   background: var(--warn-wash);   border-color: rgba(250,178,25,.3); }
.pill.bad    { color: var(--bad);    background: var(--bad-wash);    border-color: rgba(208,59,59,.3); }
.pill.accent { color: var(--accent); background: var(--accent-wash); border-color: rgba(57,135,229,.3); }

.tags { display: flex; flex-wrap: wrap; gap: 5px; }

/* ==========================================================================
   Banners
   ==========================================================================
   Tinted wash + a 2px left edge rather than a full coloured border: the edge
   is what the eye catches, and the body text stays in ink so it remains
   readable at length. */

.banner {
  position: relative;
  padding: var(--s3) var(--s4); padding-left: var(--s4);
  margin-bottom: var(--s4);
  border: 1px solid var(--hairline);
  border-left: 2px solid var(--ink-muted);
  border-radius: var(--r-sm);
  background: var(--surface);
  font-size: 13.5px; color: var(--ink-soft);
}
.banner strong { color: var(--ink-strong); }
.banner.success { border-left-color: var(--good);   background: var(--good-wash); }
.banner.warn    { border-left-color: var(--warn);   background: var(--warn-wash); }
.banner.error,
.banner.bad     { border-left-color: var(--bad);    background: var(--bad-wash); }
.banner.info    { border-left-color: var(--accent); background: var(--accent-wash); }
.banner.small   { font-size: 12.5px; padding: var(--s2) var(--s3); }

/* ==========================================================================
   Forms
   ========================================================================== */

label {
  display: block; margin-bottom: 5px;
  font-size: 12px; font-weight: 500; color: var(--ink-soft);
}

input[type=text], input[type=number], input[type=url], input[type=email],
input[type=password], input[type=datetime-local], input[type=search],
select, textarea {
  width: 100%; padding: 8px 11px;
  background: var(--raised); color: var(--ink);
  border: 1px solid var(--hairline-firm); border-radius: var(--r-sm);
  font: inherit; font-size: 14px;
  transition: border-color .12s, box-shadow .12s;
}
input::placeholder, textarea::placeholder { color: var(--ink-muted); }
input:hover, select:hover, textarea:hover { border-color: #46463f; }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-wash);
}
textarea { resize: vertical; min-height: 78px; line-height: 1.6; }
input[type=file] { padding: 7px 9px; font-size: 13px; }

/* A control sitting directly in a `.row` is part of an inline control group -
   a stage picker beside its Move button, a note field beside Add - not a form
   field in a column. `width: 100%` there makes the row's intrinsic width the
   sum of several full-width controls, which is what pushed the application
   detail header 17px past a 320px viewport. */
.row > input, .row > select, .row > form > input, .row > form > select { width: auto; }
.row > input[style*="flex"] { min-width: 0; }

.field { margin-bottom: var(--s3); }
.inline-fields { display: grid; gap: var(--s3); grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.check {
  display: flex; align-items: flex-start; gap: var(--s2);
  font-size: 13.5px; color: var(--ink); cursor: pointer;
}
.check input { width: auto; margin-top: 3px; accent-color: var(--accent); flex: none; }

/* ==========================================================================
   Buttons
   ========================================================================== */

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--r-sm); cursor: pointer;
  background: var(--accent); color: var(--on-accent);
  border: 1px solid transparent;
  font: inherit; font-size: 13.5px; font-weight: 600;
  white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s, opacity .12s;
}
button:hover, .btn:hover { background: var(--accent-hover); text-decoration: none; color: var(--on-accent); }
button:active, .btn:active { transform: translateY(.5px); }

button.ghost, .btn.ghost {
  background: transparent; color: var(--ink);
  border-color: var(--hairline-firm); font-weight: 500;
}
button.ghost:hover, .btn.ghost:hover { background: var(--raised); color: var(--ink-strong); border-color: #46463f; }

button.danger, .btn.danger {
  background: transparent; color: var(--bad);
  border-color: rgba(208,59,59,.35); font-weight: 500;
}
button.danger:hover, .btn.danger:hover { background: var(--bad-wash); color: var(--bad); border-color: rgba(208,59,59,.55); }

button.small, .btn.small { padding: 5px 10px; font-size: 12.5px; }

/* A disabled button is doing its job — it means a request is in flight. */
button:disabled, button[disabled] { opacity: .55; cursor: progress; }

/* ==========================================================================
   Tables & lists
   ========================================================================== */

/* A table gets its own horizontal scroller at every width, not just on a phone.
   Measured: with the scroller behind a `max-width: 720px` query, the discover
   page still overflowed by 83px at 768px — a seven-column table is wider than a
   tablet too, and "wider than its container" is not a phone-specific condition.

   `width: 100%` with `min-width: max-content` on the sections resolves to
   max(container, content): the table fills its card when it fits and scrolls
   when it does not, with no breakpoint involved. `display: block` is what makes
   the table itself a scroll container; the cost is that it no longer
   participates in its parent's layout as a table, which nothing here relies on. */
table {
  display: block; width: 100%; overflow-x: auto;
  border-collapse: collapse; font-size: 13.5px;
}
table > thead, table > tbody { display: table; width: 100%; min-width: max-content; }
th, td { text-align: left; padding: 9px var(--s3); vertical-align: top; }
th {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em;
  color: var(--ink-muted); border-bottom: 1px solid var(--hairline-firm);
  white-space: nowrap;
}
/* Hairlines between rows only — a border under the last row duplicates the
   panel's own edge. */
td { border-bottom: 1px solid var(--hairline); }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: rgba(255,255,255,.015); }
/* Columns of numbers align; standalone figures do not. */
td.mono, th.mono, td .mono { font-variant-numeric: tabular-nums; }

ul.clean { list-style: none; padding: 0; margin: 0; }
ul.clean li { padding: var(--s2) 0; border-bottom: 1px solid var(--hairline); }
ul.clean li:last-child { border-bottom: none; padding-bottom: 0; }
ul.clean li:first-child { padding-top: 0; }

/* ==========================================================================
   Findings & signals
   ========================================================================== */

.finding {
  padding: var(--s2) 0 var(--s2) var(--s3);
  border-left: 2px solid var(--hairline-firm);
  margin-bottom: var(--s3);
}
.finding:last-child { margin-bottom: 0; }
.finding.critical, .finding.high { border-left-color: var(--bad); }
.finding.medium { border-left-color: var(--warn); }
.finding.low    { border-left-color: var(--ink-muted); }
.finding .t { font-weight: 500; color: var(--ink-strong); font-size: 13.5px; }
.finding .d { color: var(--ink-muted); font-size: 13px; margin-top: 3px; }
.finding .f { font-size: 13px; margin-top: 5px; color: var(--ink-soft); }
.finding .f::before {
  content: "Fix"; display: inline-block; margin-right: 6px;
  font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em;
  color: var(--accent);
}

.signal { padding: var(--s3) 0; border-bottom: 1px solid var(--hairline); }
.signal:first-child { padding-top: 0; }
.signal:last-child { border-bottom: none; padding-bottom: 0; }
.signal .head { display: flex; justify-content: space-between; gap: var(--s3); align-items: baseline; flex-wrap: wrap; }
.signal .name { font-weight: 500; font-size: 13.5px; color: var(--ink-strong); }
.signal .detail { color: var(--ink-muted); font-size: 13px; margin-top: 3px; }

/* ==========================================================================
   Tracker board
   ========================================================================== */

.board {
  display: grid; gap: var(--s3);
  grid-template-columns: repeat(6, minmax(168px, 1fr));
  overflow-x: auto; padding-bottom: var(--s2);
}
.col {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--r-md); padding: var(--s3); min-height: 140px;
}
.col > h3 {
  margin: 0 0 var(--s2);
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em;
  color: var(--ink-muted);
}
.mini {
  background: var(--raised); border: 1px solid var(--hairline);
  border-radius: var(--r-sm); padding: var(--s2) var(--s3);
  margin-bottom: var(--s2); font-size: 13px;
  transition: border-color .12s;
}
.mini:hover { border-color: var(--hairline-firm); }
.mini .co { font-weight: 500; color: var(--ink-strong); }
.mini .ti { color: var(--ink-muted); font-size: 12px; margin-top: 1px; }
.mini form { margin-top: var(--s2); }
.mini select { padding: 3px 6px; font-size: 11.5px; }
.mini.stale { border-color: rgba(250,178,25,.45); }

/* ==========================================================================
   Discover
   ========================================================================== */

.discovered { transition: opacity .15s, border-color .12s; }
.discovered:hover { border-color: var(--hairline-firm); }
.discovered.is-dismissed { opacity: .42; }
.discovered summary { cursor: pointer; font-weight: 400; }

/* ==========================================================================
   Chat
   ========================================================================== */

.chat {
  max-height: 460px; overflow-y: auto;
  display: flex; flex-direction: column; gap: var(--s3);
  scrollbar-width: thin;
}
.msg {
  padding: var(--s2) var(--s3); border-radius: var(--r-md);
  max-width: 82%; font-size: 13.5px; line-height: 1.6; white-space: pre-wrap;
}
.msg.assistant { background: var(--raised); border: 1px solid var(--hairline); align-self: flex-start; }
.msg.user { background: var(--accent-wash); border: 1px solid rgba(57,135,229,.28); align-self: flex-end; }

/* ==========================================================================
   Disclosure
   ========================================================================== */

details {
  border: 1px solid var(--hairline); border-radius: var(--r-sm);
  padding: var(--s2) var(--s3); background: var(--surface);
}
details + details { margin-top: var(--s2); }
summary {
  cursor: pointer; font-weight: 500; font-size: 13.5px; color: var(--ink);
  list-style: none;
}
summary::-webkit-details-marker { display: none; }
summary::before {
  content: "›"; display: inline-block; width: 14px;
  color: var(--ink-muted); font-size: 15px;
  transition: transform .15s;
}
details[open] > summary { margin-bottom: var(--s3); color: var(--ink-strong); }
details[open] > summary::before { transform: rotate(90deg); }

/* ==========================================================================
   Busy indicator
   ========================================================================== */

.busy {
  position: fixed; right: var(--s5); bottom: var(--s5); z-index: 50;
  display: flex; align-items: center; gap: var(--s2);
  background: var(--surface); color: var(--ink-strong);
  border: 1px solid var(--hairline-firm);
  box-shadow: var(--shadow);
  padding: 9px var(--s4); border-radius: var(--r-full);
  font-size: 13px; font-weight: 500;
}
.busy::before {
  content: ""; width: 7px; height: 7px; border-radius: var(--r-full);
  background: var(--accent); animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: flex; }

/* ==========================================================================
   Empty states
   ========================================================================== */

.empty {
  padding: var(--s6) var(--s5); text-align: center;
  color: var(--ink-muted); font-size: 13.5px;
}
.empty strong { display: block; margin-bottom: var(--s1); color: var(--ink); font-weight: 500; }

/* ==========================================================================
   Narrow screens
   ========================================================================== */

/* --------------------------------------------------------------------------
   Narrow screens

   Measured with `scripts/check_responsive.py`, which drives Chrome over CDP so
   the layout viewport is really the width asked for. Before these rules, six of
   nine pages overflowed at 360px — the worst by 284px. Each rule below fixes a
   cause the script named.
   -------------------------------------------------------------------------- */

@media (max-width: 720px) {
  .topbar { height: auto; flex-wrap: wrap; padding: var(--s3) var(--s4); gap: var(--s3); }
  .topbar nav { order: 3; width: 100%; margin-left: 0; overflow-x: auto; scrollbar-width: none; }
  .topbar nav::-webkit-scrollbar { display: none; }
  .topbar nav a { flex: none; }
  .topbar nav a.active::after { bottom: -2px; }
  .topbar-right { margin-left: auto; }

  main { padding: var(--s4) var(--s4) var(--s7); }
  .page-head { flex-direction: column; gap: var(--s3); }
  .msg { max-width: 92%; }

  /* Every multi-column grid becomes one column. `minmax(300px, 1fr)` was the
     cause of the profile page's 21px overflow at 320px: 300px cannot fit a
     320px viewport once the 16px gutters are taken. auto-fit does not help,
     because the minimum is a floor, not a suggestion. */
  .grid.two, .grid.three, .grid.four { grid-template-columns: 1fr; }
  .inline-fields { grid-template-columns: 1fr; }

  /* Tables scroll inside their own box instead of widening the page. The
     applications table is 603px of nowrap headers and seven columns; nothing
     short of a horizontal scroller or a full card-per-row restyle fixes that.
     `display: block` is the CSS-only way to get one without wrapping every
     table in a div across eight templates. The cost is that the table stops
     distributing column widths to fill 100%, which at this width is the better
     trade — and `min-width: max-content` keeps the columns from collapsing into
     each other inside the scroller. */
  /* Tables already scroll at every width — see the `table` rule above. */

  /* Unbreakable strings — a database URL, an invite link, an API model id.
     The settings page overflowed by 371px on one `span.mono`. */
  .mono, code { overflow-wrap: anywhere; word-break: break-word; }
  pre.doc { font-size: 11.5px; }

  /* The board is a deliberate horizontal scroller: six stages will never fit a
     phone, and stacking them loses the one thing a kanban is for. */
  .board { grid-template-columns: repeat(6, 78vw); }
}

/* The hero stat sits beside the three smaller tiles on a wide screen and above
   them on a narrow one. This was an inline `grid-template-columns` on the
   dashboard, which no media query could override — it held a 220px minimum
   column and overflowed every phone width by ~112px. */
.stat-band { display: grid; gap: var(--s4); grid-template-columns: minmax(220px, .9fr) 2fr; }
@media (max-width: 860px) {
  .stat-band { grid-template-columns: 1fr; }
}
