/* crash-screener-core web UI.
 *
 * Direction-agnostic by construction: no `left`/`right` anywhere, only logical
 * properties (`margin-inline-start`, `padding-inline`, `text-align: start`,
 * `border-inline-start`, `border-start-end-radius`). The client bundle sets
 * `dir` on <html>, and the same sheet renders LTR and RTL without a mirrored
 * copy. The single rule that reads `dir` is the diff arrow, which has to point
 * the way the page reads and therefore cannot be expressed logically.
 *
 * Mobile-first: the base layer is the phone layout, and the single breakpoint
 * widens it. The target is a calm operational dashboard — one accent, generous
 * spacing, status carried by a tone token plus a word (never colour alone).
 */

:root {
  color-scheme: light dark;

  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --ink: #1b1f24;
  --ink-muted: #5d6672;
  --line: #dfe3e8;
  --accent: #2f5d8a;
  --accent-ink: #ffffff;

  --tone-neutral: #6b7280;
  --tone-info: #2f5d8a;
  --tone-good: #2f7a4f;
  --tone-warn: #8a6420;
  --tone-bad: #9c3535;

  --radius: 10px;
  --gap: 0.75rem;
  --pad: 1rem;
  --measure: 46rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a;
    --surface: #1c2024;
    --surface-2: #23282d;
    --ink: #e8eaed;
    --ink-muted: #9aa4b0;
    --line: #333a41;
    --accent: #7aa7d4;
    --accent-ink: #10171f;

    --tone-neutral: #98a2b0;
    --tone-info: #7aa7d4;
    --tone-good: #6fbb8c;
    --tone-warn: #d0a95c;
    --tone-bad: #e08585;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  text-align: start;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { line-height: 1.25; margin: 0; font-weight: 600; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.05rem; }
p { margin: 0.5rem 0; }

a { color: var(--accent); }
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.skip {
  position: absolute;
  inset-block-start: -3rem;
  inset-inline-start: 0;
  background: var(--surface);
  padding: 0.5rem 0.75rem;
  z-index: 10;
}
.skip:focus { inset-block-start: 0; }

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

.topbar {
  display: flex;
  align-items: center;
  gap: var(--gap);
  padding: 0.75rem var(--pad);
  background: var(--surface);
  border-block-end: 1px solid var(--line);
}

.brand { font-weight: 600; }
.topbar .logout { margin-inline-start: auto; }

.tabs {
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
  padding: 0.5rem var(--pad);
  background: var(--surface);
  border-block-end: 1px solid var(--line);
  scrollbar-width: thin;
}

.tab {
  flex: 0 0 auto;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  text-decoration: none;
  color: var(--ink-muted);
  white-space: nowrap;
}
.tab.is-current {
  background: var(--accent);
  color: var(--accent-ink);
}

.page {
  max-width: var(--measure);
  margin-inline: auto;
  padding: var(--pad);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.footer {
  max-width: var(--measure);
  margin-inline: auto;
  padding: 0 var(--pad) 2rem;
  color: var(--ink-muted);
  font-size: 0.85rem;
}

/* ----------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--pad);
}
.card.narrow { max-width: 24rem; margin-inline: auto; width: 100%; }
.card.secondary { background: var(--surface-2); }

.subcard {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin-block-start: 0.75rem;
}

.card-head {
  display: flex;
  align-items: center;
  gap: var(--gap);
  flex-wrap: wrap;
  margin-block-end: 0.5rem;
}
.card-head > :first-child { margin-inline-end: auto; }

/* ----------------------------------------------------------------- lists */

.list { list-style: none; margin: 0; padding: 0; }

.row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-block: 0.5rem;
  border-block-end: 1px solid var(--line);
  flex-wrap: nowrap;
}
.row.wrap { flex-wrap: wrap; }
.list > li:last-child .row,
.list > .row:last-child { border-block-end: none; }

/* break-word, not anywhere: it breaks a long word only where it would overflow
 * and leaves min-content alone, so a ticker beside a long company name keeps
 * its letters together instead of being squeezed to one per line. */
.grow { flex: 1 1 auto; min-width: 0; overflow-wrap: break-word; }
/* A row's trailing action stays one tap target on one line ("load into the
 * form"), however long the name beside it; the name wraps instead. */
.row > a.link { flex: 0 0 auto; white-space: nowrap; }
.symbol { display: flex; gap: 0.5rem; align-items: baseline; text-decoration: none; }
/* A company name is usually English: it runs in its own direction, so a
 * name too long for a phone loses its end ("Research Candidate Pharm…")
 * rather than its beginning. */
.symbol .muted {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  unicode-bidi: plaintext;
}
/* The list can abbreviate a company name; its detail page must show the whole
 * name. Give the name a separate line when it needs one. */
.event-title { min-inline-size: 0; flex-wrap: wrap; }
.event-title .muted { white-space: normal; overflow: visible; overflow-wrap: anywhere; }
.event-row { flex-wrap: wrap; }
.event-badges { display: contents; }
.event-meta { display: contents; }

.event-path {
  display: flex;
  flex: 1 1 100%;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.2rem 0.35rem;
  font-size: 0.85rem;
}
.event-path-step + .event-path-step::before {
  content: "\2192";
  color: var(--ink-muted);
  margin-inline-end: 0.35rem;
}
:root[dir="rtl"] .event-path-step + .event-path-step::before { content: "\2190"; }

@media (max-width: 39.99rem) {
  .event-row {
    align-items: flex-start;
    flex-wrap: wrap;
  }
  .event-row .symbol { flex: 1 1 100%; }
  .event-row .event-badges {
    display: flex;
    flex: 1 1 100%;
    gap: 0.35rem;
    flex-wrap: wrap;
  }
  .event-row .event-meta {
    display: flex;
    flex: 1 1 100%;
    align-items: baseline;
    gap: 0.35rem 0.6rem;
    flex-wrap: wrap;
  }
  .event-row .event-trigger { flex: 1 1 100%; }
  .event-row .stamp { margin-inline-start: auto; }
}

.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
/* A number reads left to right whatever the page does. Nothing in "-97.7" is a
 * strong character, so in an RTL page it took the page's direction and printed
 * as "97.7-". plaintext resolves each number's direction from its own content,
 * in isolation (LTR for digits; RTL for a Hebrew label that borrows the class);
 * block cells keep the page's alignment. Not a before/after pair: its arrow is
 * drawn for the page's direction and must stay in it. */
.num:not(.change) { unicode-bidi: plaintext; }
:root[dir="rtl"] td.num,
:root[dir="rtl"] dd.num:not(.change),
:root[dir="rtl"] .check-values dd { text-align: right; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; }
.muted { color: var(--ink-muted); }
.small { font-size: 0.85rem; }
.stamp { font-variant-numeric: tabular-nums; font-size: 0.85rem; }
.lede { font-size: 1.05rem; }
.excerpt {
  flex-basis: 100%;
  color: var(--ink-muted);
  font-size: 0.9rem;
  margin: 0.25rem 0 0;
  overflow-wrap: break-word;
}

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  display: flex;
  gap: 0.5rem;
  padding-block: 0.35rem;
  border-inline-start: 2px solid var(--line);
  padding-inline-start: 0.75rem;
}

.checks { list-style: none; padding: 0; margin: 0; }
.check-row { padding-block: 0.85rem; border-block-end: 1px solid var(--line); }
.check-row:last-child { border-block-end: none; }
.check-heading { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.4rem 0.6rem; }
.check-heading h3 { flex: 1 1 10rem; font-size: 0.95rem; }
.check-heading .pill { flex: 0 0 auto; }
/* Values have their own labelled space, so a long exchange list or halt rule
 * cannot take width from the criterion's name. Neither value is a no-wrap
 * number: these cells also carry sentences and lists. */
.check-values {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.5rem 1rem;
  margin: 0.5rem 0 0;
}
.check-values dt { color: var(--ink-muted); font-size: 0.8rem; }
.check-values dd {
  margin: 0.15rem 0 0;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
  unicode-bidi: plaintext;
}
@media (min-width: 24rem) {
  .check-values { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.check-audit > summary { cursor: pointer; padding-block: 0.65rem; color: var(--accent); }
.check-audit pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--surface-2);
  padding: 0.75rem;
  border-radius: var(--radius);
  font-size: 0.8rem;
  text-align: start;
}
.caveats li { padding-block: 0.2rem; border: none; }

.revision { padding-block: 0.5rem; border-block-end: 1px solid var(--line); }
.changes { margin-block-start: 0.35rem; font-size: 0.9rem; }

/* Separators between two values (before/after, start/end). They live here
 * rather than in the markup for two reasons: an arrow is the one mark on these
 * pages that must follow the reading direction — a "→" between two numbers in
 * an RTL paragraph points back the way the eye came — and a glyph baked into a
 * template is core typography the client layer cannot restyle. */
.change .to::before,
.range .to::before {
  color: var(--ink-muted);
  margin-inline: 0.35em;
}
.change .to::before { content: "\2192"; }          /* → */
:root[dir="rtl"] .change .to::before { content: "\2190"; }  /* ← */
/* Each side of a before/after pair is its own bidi island. Two Latin values
 * ("NASDAQ, NYSE" and "NASDAQ") would otherwise pull the arrow between them
 * into one left-to-right run, which in an RTL page puts the new value on the
 * right and points the arrow back at the old one. */
.change .from,
.change .to { unicode-bidi: isolate; }
.range .to::before { content: "\2013"; }           /* – */
/* A date never breaks at its own hyphens; a range that does not fit breaks
 * between its two dates (the templates put a <wbr> there). */
.range .from,
.range .to { white-space: nowrap; }

/* --------------------------------------------------------------- badges */

.pill, .badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.8rem;
  white-space: nowrap;
  border: 1px solid currentColor;
}
.pill.big, .badge.big { font-size: 0.95rem; padding: 0.25rem 0.7rem; }
/* A badge naming a profile ("<name> · version 8 · live") can be longer than a
 * phone row allows: in a value cell or a card head it wraps rather than push
 * the page sideways. */
.kv dd .badge,
.card-head .badge { white-space: normal; }

.tone-neutral { color: var(--tone-neutral); }
.tone-info    { color: var(--tone-info); }
.tone-good    { color: var(--tone-good); }
.tone-warn    { color: var(--tone-warn); }
.tone-bad     { color: var(--tone-bad); }

.notice {
  border-inline-start: 3px solid currentColor;
  padding: 0.5rem 0.75rem;
  /* Logical corners, not the `border-radius` shorthand: the shorthand is
   * physical (top-left, top-right, ...), so in RTL the accent bar moves to the
   * inline-start edge while the square corners stay behind on the left. */
  border-start-end-radius: var(--radius);
  border-end-end-radius: var(--radius);
  background: var(--surface-2);
}

/* Profile variants. Which profile is which is the client layer's business;
 * core only guarantees that two variants cannot be mistaken for each other. */
.profile-default { color: var(--tone-neutral); }
.profile-alt     { color: var(--tone-info); border-style: dashed; }
.profile-accent  { color: var(--accent); border-width: 2px; }
.profile-warn    { color: var(--tone-warn); border-style: dashed; border-width: 2px; }
.profile-strong  { background: var(--tone-bad); color: var(--accent-ink); border-color: transparent; }

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

.stack { display: flex; flex-direction: column; gap: var(--gap); }

fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin: 0;
}
legend { padding-inline: 0.35rem; color: var(--ink-muted); font-size: 0.85rem; }
/* A form's secondary action (save as a test profile) sits apart from the
 * primary one on a quieter ground, the way a secondary card does. */
fieldset.secondary { background: var(--surface-2); }

.field { display: flex; flex-direction: column; gap: 0.25rem; margin-block-end: 0.6rem; }
.field:last-child { margin-block-end: 0; }
.label { font-size: 0.85rem; color: var(--ink-muted); }

input[type="text"],
input[type="password"],
input[type="date"],
select {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem;
  width: 100%;
  min-height: 2.75rem;
  text-align: start;
}
input[type="checkbox"] { inline-size: 1.25rem; block-size: 1.25rem; }

/* A question answered by picking one of a few spelled-out options (a client's
 * classification switch): the question, a line about it, then one tappable row
 * per option — the radio at the start of the line, the option's name, its
 * explanation and, for an option that needs one, a caution under it. The whole
 * row is the label, so a thumb anywhere on it chooses it; the chosen row is
 * outlined. Rows wrap their text; nothing pushes the page sideways. */
fieldset.options { border: none; padding: 0; margin: 0; min-width: 0; }
.option-question { padding: 0; font-size: 1rem; color: var(--ink); font-weight: 600; }
fieldset.options > .hint { margin-block-end: 0.35rem; }
.option {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.6rem 0.7rem;
  margin-block-start: 0.45rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
}
.option input[type="radio"] {
  flex: 0 0 auto;
  inline-size: 1.25rem;
  block-size: 1.25rem;
  margin: 0.1rem 0 0;
}
.option-text { display: flex; flex-direction: column; gap: 0.25rem; min-width: 0; }
.option-text .hint,
.option-text .notice { overflow-wrap: anywhere; }
.option-label { font-weight: 600; }
.option:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.field.has-error .option { border-color: var(--tone-bad); }

.field.has-error input,
.field.has-error select { border-color: var(--tone-bad); }
.error { color: var(--tone-bad); font-size: 0.85rem; margin: 0; }

/* A number and its unit on one line; the unit sits where the number ends in
 * the page's reading order, and the input takes the rest of the row. */
.unit-input { display: flex; align-items: center; gap: 0.5rem; }
.unit-input input { flex: 1 1 auto; min-width: 0; }
.unit-input .unit { flex: 0 0 auto; color: var(--ink-muted); }
/* The value read back under its input ("30,000,000 $ — 30 million dollars"),
 * and a field's how-to line. Either can be longer than a phone is wide: they
 * wrap, never push the page sideways. An empty reading (a field showing its
 * error instead) takes no room until the script fills it. */
.reading,
.hint { margin: 0; font-size: 0.85rem; color: var(--ink-muted); overflow-wrap: anywhere; }
.reading:empty { display: none; }

/* The preview's list of what the save will change: the field's name, then its
 * old and new values, then — for a tenfold move — the caution. */
.review h2 { margin-block-end: 0.35rem; }
.change-list li {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding-block: 0.5rem;
  border-block-end: 1px solid var(--line);
}
.change-list li:last-child { border-block-end: none; }
.change-list .change { overflow-wrap: anywhere; }
/* Old above new, each a whole line, the new one led by the arrow. Run on as
 * one line, a pair wider than a phone wrapped mid-value and interleaved the
 * two ("… 5 million / shares ← 50,000,000 …"). */
.change-list .from,
.change-list .to { display: block; }
.change-list .from { color: var(--ink-muted); }
.change-list .to::before { margin-inline-start: 0; }

.filters {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
  margin-block-end: var(--gap);
}

.range-summary {
  padding-block: 0.5rem 0.75rem;
  border-block-end: 1px solid var(--line);
  margin-block-end: 0.75rem;
}
.range-summary p { margin: 0; }

.filter-block { margin-block: 0.85rem; }
.filter-title {
  color: var(--ink-muted);
  font-size: 0.85rem;
  margin-block-end: 0.4rem;
}

.choice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.choice-row.compact { margin-block: 0.65rem; }
.more-filters { margin-block: 0.65rem; }
.more-filters > summary {
  cursor: pointer;
  min-block-size: 44px;
  display: flex;
  align-items: center;
  color: var(--accent);
  text-decoration: underline;
}
.more-filters[open] > summary { margin-block-end: 0.5rem; }
.choice-chip,
.lane-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  background: var(--surface);
  text-decoration: none;
  line-height: 1.2;
}
.choice-chip { padding: 0.55rem 0.8rem; }
.choice-chip.is-selected,
.lane-chip.is-selected {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}

.lane-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}
.lane-chip {
  flex: 1 1 9rem;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem;
  border-radius: 9px;
}
.lane-chip strong {
  min-inline-size: 2ch;
  text-align: end;
}

.event-fact {
  margin-block: 0.75rem;
  padding: 0.65rem 0.75rem;
  border-inline-start: 3px solid var(--line);
  background: var(--surface-2);
  border-start-end-radius: var(--radius);
  border-end-end-radius: var(--radius);
}
.event-fact h2 { font-size: 0.95rem; }
.event-fact p:last-child { margin-block-end: 0; }
.compact-list { margin: 0.35rem 0 0; padding-inline-start: 1.25rem; }
.compact-list li { padding-block: 0.15rem; }

.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

button {
  font: inherit;
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  min-height: 2.75rem;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: inherit;
  cursor: pointer;
}
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
button.danger { border-color: var(--tone-bad); color: var(--tone-bad); background: transparent; }
button.link {
  background: none;
  border: none;
  color: var(--accent);
  padding: 0;
  min-height: 0;
  text-decoration: underline;
}

/* ------------------------------------------------------------ key/value */

/* The label column fits its labels but never takes more than half the row:
 * an `auto` column is grown to its widest label before a `1fr` column gets
 * anything, which on a phone squeezed long values to one character a line. */
.kv {
  display: grid;
  grid-template-columns: fit-content(50%) minmax(0, 1fr);
  gap: 0.25rem 0.75rem;
  margin: 0;
}
.kv dt { color: var(--ink-muted); font-size: 0.9rem; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
/* A value can be a list of numbers ("1d=1, 1w=5, 1m=21, ..."): it wraps
 * between items rather than pushing a phone page sideways. */
.kv dd.num { white-space: normal; }

.payload dt.depth-1 { padding-inline-start: 0.75rem; }
.payload dt.depth-2 { padding-inline-start: 1.5rem; }
.payload dt.depth-3 { padding-inline-start: 2.25rem; }
/* Findings are prose, often with nested labels and source references. On a
 * phone each label sits above its full-width text, preserving readable lines. */
@media (max-width: 39.99rem) {
  .payload { grid-template-columns: minmax(0, 1fr); }
  .payload dt[class] { margin-block-start: 0.45rem; padding-inline-start: 0; }
}

/* --------------------------------------------------------------- tables */

.scroll { overflow-x: auto; }

.grid { border-collapse: collapse; inline-size: 100%; }
.grid th, .grid td {
  text-align: start;
  padding: 0.4rem 0.5rem;
  border-block-end: 1px solid var(--line);
  white-space: nowrap;
}
.grid th { color: var(--ink-muted); font-weight: 600; font-size: 0.85rem; }
.grid td.num { font-variant-numeric: tabular-nums; }

.pager { display: flex; gap: var(--gap); align-items: center; padding-block-start: 0.75rem; }

/* ----------------------------------------------------------- breakpoint */

@media (min-width: 40rem) {
  .filters { grid-template-columns: repeat(3, 1fr); }
  .filters .actions { grid-column: 1 / -1; }
  h1 { font-size: 1.5rem; }
  .check-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 1rem; }
  .check-heading { align-content: start; }
  .check-values { margin: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
