/* Arabic is the default, so the layout is RTL-first and mirrors for English
   rather than the other way round. Logical properties (inline-start/end) do the
   mirroring, so no direction-specific overrides are needed. */

:root {
  --bg: #12141a;
  --panel: #1a1d26;
  /* One step above --panel, for controls that sit inside a card and need to
     read as inset rather than as another card. */
  --sunken: #14171f;
  --line: #2a2f3d;
  --line-soft: #21252f;
  --ink: #e8eaf0;
  --muted: #8b93a7;
  --accent: #5b9dff;
  /* What goes ON the accent -- a primary button's own label. Part of the
     palette, not derived: a light theme needs white here and a dark one needs
     near-black, and getting it wrong is the one contrast failure a palette can
     produce on its most-pressed control. */
  --on-accent: #08101f;
  --ok: #3ec18c;
  --bad: #ef6b6b;
  --warn: #e0b341;

  /* Derived once, from whichever palette is in force. Mixing toward --ink
     lightens on a dark theme and darkens on a light one, so one formula gives
     a correct hover in both directions. */
  --accent-hover: color-mix(in srgb, var(--accent) 82%, var(--ink));
  --hover-line: color-mix(in srgb, var(--line) 70%, var(--ink));
  --hover-bg: color-mix(in srgb, var(--panel) 88%, var(--ink));

  /* Native controls -- scrollbars, number spinners, the file dialog -- follow
     this, not our tokens. A light palette without it keeps dark scrollbars. */
  color-scheme: dark;
  --radius: 10px;
  --radius-sm: 7px;

  /* One spacing scale, so vertical rhythm is a decision rather than whatever
     each block happened to be given. */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;

  /* Type scale. Arabic sits a little larger than Latin at the same nominal
     size would suggest, so body is 15px and steps are gentle. */
  --t-hint: 12.5px;
  --t-small: 13.5px;
  --t-body: 15px;
  --t-h2: 15px;
  --t-display: 34px;
}

/* --- palettes ---------------------------------------------------------
 *
 * A palette is the token block above, restated. Nothing else in this file
 * names a colour, so switching one changes the whole interface -- including
 * the tints, which are mixed from the accent rather than written out.
 *
 * Every one was measured before it shipped: the worst text-on-surface pair in
 * each is recorded in its comment, and none is below 4.85:1 against a WCAG AA
 * requirement of 4.5:1. If you edit one, re-measure it. A palette that looks
 * good and cannot be read is worse than one that does neither.
 */

/* No colour cast at all, so nothing competes with the numbers.
   Worst text contrast in this palette: 6.06:1 */
[data-theme="charcoal"] {
  color-scheme: dark;
  --bg: #141414;
  --panel: #1c1c1c;
  --sunken: #171717;
  --line: #333333;
  --line-soft: #282828;
  --ink: #ededed;
  --muted: #9a9a9a;
  --accent: #9fb4c9;
  --on-accent: #0d1114;
  --ok: #6fbf8f;
  --bad: #e88686;
  --warn: #d4ac52;
}

/* Warm blacks and amber, for reading transcripts at night.
   Worst text contrast in this palette: 6.27:1 */
[data-theme="warmink"] {
  color-scheme: dark;
  --bg: #17130f;
  --panel: #201a15;
  --sunken: #1a1511;
  --line: #3a3027;
  --line-soft: #2b241d;
  --ink: #f0e7dc;
  --muted: #a89a89;
  --accent: #e3a75c;
  --on-accent: #1a1208;
  --ok: #7fbf7a;
  --bad: #ec8073;
  --warn: #dfb457;
}

/* Green-black; the accent and the met-criterion tick share a colour.
   Worst text contrast in this palette: 6.34:1 */
[data-theme="forest"] {
  color-scheme: dark;
  --bg: #0f1613;
  --panel: #161f1b;
  --sunken: #121a17;
  --line: #27352e;
  --line-soft: #1d2823;
  --ink: #e6efe9;
  --muted: #8ea69a;
  --accent: #5ec99a;
  --on-accent: #06140e;
  --ok: #5ec99a;
  --bad: #ef7d7d;
  --warn: #dcb45c;
}

/* Indigo night, violet accent.
   Worst text contrast in this palette: 5.78:1 */
[data-theme="violet"] {
  color-scheme: dark;
  --bg: #131120;
  --panel: #1b1830;
  --sunken: #161327;
  --line: #2f2a4a;
  --line-soft: #241f3b;
  --ink: #e9e6f5;
  --muted: #9891b5;
  --accent: #a78bfa;
  --on-accent: #100b21;
  --ok: #5cc9a0;
  --bad: #f07a8f;
  --warn: #e0b158;
}

/* Slate with a teal accent, cooler than midnight.
   Worst text contrast in this palette: 6.18:1 */
[data-theme="slate"] {
  color-scheme: dark;
  --bg: #0f1719;
  --panel: #172124;
  --sunken: #131c1f;
  --line: #28383c;
  --line-soft: #1e2b2e;
  --ink: #e4eef0;
  --muted: #8ba3a8;
  --accent: #4fc3d4;
  --on-accent: #04161a;
  --ok: #54c79a;
  --bad: #ef7f7f;
  --warn: #dcb257;
}

/* Pure black, pure white, nothing subtle. For tired eyes.
   Worst text contrast in this palette: 9.18:1 */
[data-theme="contrast_dark"] {
  color-scheme: dark;
  --bg: #000000;
  --panel: #0d0d0d;
  --sunken: #080808;
  --line: #3d3d3d;
  --line-soft: #242424;
  --ink: #ffffff;
  --muted: #c4c4c4;
  --accent: #7cc4ff;
  --on-accent: #000000;
  --ok: #5ee0a4;
  --bad: #ff9494;
  --warn: #ffd166;
}

/* Daylight. Off-white page, blue accent.
   Worst text contrast in this palette: 4.85:1 */
[data-theme="paper"] {
  color-scheme: light;
  --bg: #f4f5f7;
  --panel: #ffffff;
  --sunken: #eef0f3;
  --line: #d3d8e0;
  --line-soft: #e4e8ee;
  --ink: #1b2130;
  --muted: #5a6474;
  --accent: #2563c9;
  --on-accent: #ffffff;
  --ok: #0c6a49;
  --bad: #c22e2e;
  --warn: #8a6100;
}

/* Daylight without the glare: cream page, brown accent.
   Worst text contrast in this palette: 5.02:1 */
[data-theme="warmpaper"] {
  color-scheme: light;
  --bg: #f6f1e7;
  --panel: #fffdf8;
  --sunken: #efe9dc;
  --line: #ddd3c1;
  --line-soft: #e8e1d2;
  --ink: #2a231a;
  --muted: #6b6153;
  --accent: #8a4f16;
  --on-accent: #ffffff;
  --ok: #186b47;
  --bad: #b52d2d;
  --warn: #7c5a00;
}

/* White page, near-black text, one strong blue.
   Worst text contrast in this palette: 5.99:1 */
[data-theme="contrast_light"] {
  color-scheme: light;
  --bg: #ffffff;
  --panel: #ffffff;
  --sunken: #f2f2f2;
  --line: #9a9a9a;
  --line-soft: #dcdcdc;
  --ink: #0a0a0a;
  --muted: #3f3f3f;
  --accent: #0b4fd0;
  --on-accent: #ffffff;
  --ok: #046a3c;
  --bad: #b40000;
  --warn: #6b4a00;
}

/* --- end palettes --- */

* { box-sizing: border-box; }

/* The `hidden` attribute is only a default of display:none, and any rule that
   sets display -- .session-banner is flex, progress.bar is block -- silently
   beats it. That left an empty bordered strip above the queue and a stub of a
   progress bar under every idle button. Stated once here rather than
   remembered at each of them. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  /* Segoe UI's Arabic coverage is thin; the Noto and Tahoma fallbacks ahead of
     it render Syrian dialect text with correct joining and better diacritic
     placement, which matters when the transcript IS the product. */
  font: var(--t-body)/1.6 "Segoe UI Variable Text", "Segoe UI", "Noto Sans Arabic",
        Tahoma, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* Arabic needs more line height: the ascenders and descenders overlap at 1.6. */
html[lang="ar"] body { line-height: 1.85; }

/* Focus is visible on every control rather than only where a browser decides.
   Keyboard use is not an edge case on a form this long. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
header h1 { font-size: 18px; margin: 0; font-weight: 600; }
.header-right { display: flex; align-items: center; gap: 10px; }

nav {
  display: flex;
  gap: 4px;
  padding: 10px 22px 0;
  border-bottom: 1px solid var(--line);
}
.tab {
  background: none;
  border: 1px solid transparent;
  border-bottom: none;
  color: var(--muted);
  padding: 8px 16px;
  border-radius: var(--radius) var(--radius) 0 0;
  cursor: pointer;
  font: inherit;
}
.tab.active { color: var(--ink); background: var(--panel); border-color: var(--line); }

main { max-width: 860px; margin: 0 auto; padding: 22px; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--s5);
  margin-bottom: var(--s4);
}
.card h2 {
  display: flex;
  align-items: center;
  gap: var(--s3);
  margin: 0 0 var(--s4);
  font-size: var(--t-h2);
  font-weight: 600;
  color: var(--ink);
}

/* --- steps --- */

/* The number was part of the heading string, which meant it could not carry
   state. As a badge it can: a step that is done says so, and one that cannot
   run yet looks like it. */
.step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  flex: none;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--sunken);
  color: var(--muted);
  font-size: var(--t-hint);
  font-weight: 600;
  /* Arabic-Indic numerals reorder inside a circle without this. */
  direction: ltr;
  unicode-bidi: isolate;
}
.step.done .step-badge {
  border-color: var(--ok);
  color: var(--ok);
  background: color-mix(in srgb, var(--ok) 12%, transparent);
}
.step.active .step-badge {
  border-color: var(--accent);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.step.active { border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
/* A step that cannot run yet is marked on its BADGE, not by fading the card.
   opacity: 0.55 took the hints from 5.5:1 down to 2.6:1 -- unreadable, and by
   WCAG a failure -- while also dimming the one button on the page now that the
   run action lives in step three. State is worth showing; illegibility is not
   how to show it. */
.step.blocked .step-badge { border-style: dashed; color: var(--muted); }
.step.done h2 { color: var(--muted); }

/* --- fields --- */

.field { display: block; margin: 0 0 var(--s4); }
.field > span {
  display: block;
  margin-bottom: var(--s2);
  font-size: var(--t-small);
  color: var(--ink);
}
.field > .hint,
.hint {
  display: block;
  margin-top: var(--s1);
  font-size: var(--t-hint);
  line-height: 1.5;
  color: var(--muted);
  font-weight: 400;
}
.field.inline { display: flex; align-items: center; gap: var(--s3); }
.field.inline > span { margin: 0; }

/* Two short numeric fields side by side rather than stacked full width, which
   made a 2-character answer look like a 60-character one. */
.field-row { display: flex; gap: var(--s4); flex-wrap: wrap; }
.field-row > .field { flex: 1; min-width: 150px; margin-bottom: var(--s4); }

input, select, textarea {
  background: var(--sunken);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  font: inherit;
  width: 100%;
  transition: border-color 0.12s ease;
}
input:hover, select:hover, textarea:hover { border-color: color-mix(in srgb, var(--line) 60%, var(--ink) 15%); }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
.field.inline input { width: 70px; }
/* Numeric answers are digits: keep them LTR whatever the interface language. */
input[type=number] { direction: ltr; text-align: start; }

/* --- file picker --- */

/* The native control renders "Choose File / No file chosen" in English, left
   aligned, inside an otherwise Arabic right-to-left page. This replaces it
   without losing the real input, which still does the work. */
.filepick {
  display: flex;
  align-items: center;
  gap: var(--s3);
  padding: var(--s2);
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  background: var(--sunken);
  cursor: pointer;
  transition: border-color 0.12s ease;
}
.filepick:hover { border-color: var(--accent); }
.filepick input[type=file] {
  /* Not display:none: that removes it from the tab order and from screen
     readers. Clipped instead, so the label still activates it. */
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.filepick-btn {
  flex: none;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  background: var(--line);
  color: var(--ink);
  font-size: var(--t-small);
  font-weight: 600;
}
.filepick-name {
  color: var(--muted);
  font-size: var(--t-small);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.filepick.has-file { border-style: solid; border-color: var(--line); }
.filepick.has-file .filepick-name { color: var(--ink); direction: ltr; text-align: start; }

/* --- buttons --- */

button {
  font: inherit;
  cursor: pointer;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  border: 1px solid var(--line);
  background: var(--sunken);
  color: var(--ink);
  transition: background 0.12s ease, border-color 0.12s ease;
}
button:hover:not(:disabled) { border-color: var(--hover-line); background: var(--hover-bg); }
/* Not opacity on top of the recoloured disabled states below: the two stack,
   and a disabled primary ended up at 2.5:1 against its own background. */
button:disabled { cursor: not-allowed; opacity: 0.75; }
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}
button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
button.primary:disabled {
  background: var(--line);
  border-color: var(--line);
  /* --ink rather than --muted: a disabled button still has to be readable to
     be understood, and the hint under it explains why it is disabled. */
  color: var(--ink);
  opacity: 0.6;
}
button.ghost { background: none; color: var(--muted); padding: 5px 10px; }

/* A button and the status it produces belong on one line: the status used to
   sit in a block below, so the eye had to travel to find out what happened. */
.actions {
  display: flex;
  align-items: center;
  gap: var(--s3);
  flex-wrap: wrap;
  margin-top: var(--s4);
}
.actions .status { margin: 0; }

.muted { color: var(--muted); }
.small { font-size: var(--t-small); }
.hidden { display: none; }

.goal-desc {
  margin-top: var(--s2);
  font-size: var(--t-small);
  color: var(--muted);
  line-height: 1.6;
}

.note {
  font-size: var(--t-hint);
  color: var(--muted);
  border-inline-start: 2px solid var(--line);
  padding-inline-start: var(--s3);
  margin: var(--s4) 0 0;
  line-height: 1.6;
}

.status { margin-top: var(--s3); font-size: var(--t-small); min-height: 20px; color: var(--muted); }
.status.err { color: var(--bad); }
.status.ok { color: var(--ok); }

.pill { padding: 3px 10px; border-radius: 20px; font-size: 12px; }
.pill-ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.pill-bad { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.pill-muted { background: var(--line); color: var(--muted); }

.metrics { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.metric {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 11px;
  font-size: 13px;
}
.metric b { color: var(--accent); font-weight: 600; }

.transcript { max-height: 340px; overflow-y: auto; margin-top: 10px; }
.utt { padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.utt .who { color: var(--accent); font-size: 12px; }
.utt .time { color: var(--muted); font-size: 12px; }
/* Timestamps and numbers stay LTR even inside RTL text. */
.time, .num { direction: ltr; display: inline-block; unicode-bidi: embed; }
.utt.low { border-inline-start: 3px solid var(--warn); padding-inline-start: 8px; }

.score {
  font-size: var(--t-display);
  font-weight: 700;
  margin: var(--s2) 0 var(--s5);
  line-height: 1.1;
  direction: ltr;
  text-align: start;
}

.findings { width: 100%; border-collapse: collapse; font-size: 14px; }
.findings td {
  padding: var(--s3) var(--s2);
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}
.findings tr:last-child td { border-bottom: none; }
/* A failed criterion is what the report is for. Tinting the row makes the
   three or four that matter findable without reading all fifteen. */
.findings tr.missed { background: color-mix(in srgb, var(--bad) 6%, transparent); }
.findings .mark {
  width: 28px;
  font-weight: 700;
  text-align: center;
  direction: ltr;
}
.findings .met .mark { color: var(--ok); }
.findings .missed .mark { color: var(--bad); }
.findings .unknown .mark { color: var(--warn); }
.findings .evidence {
  color: var(--muted);
  font-size: var(--t-small);
  /* Metric names and numbers are Latin and must not reorder inside an Arabic
     row: "talk_ratio = 0.62, target < 0.45" reverses without this. */
  direction: ltr;
  text-align: start;
  unicode-bidi: isolate;
}
/* The criterion id is a handle, not prose. Monospace says so and stops it
   being read as a word in the surrounding language. */
/* The cell holds an Arabic name over a Latin identifier, so direction is set
   per line rather than on the cell: forcing the whole cell LTR reordered the
   Arabic label, and leaving it RTL moved the identifier's underscores around. */
.findings .criterion { font-size: var(--t-small); }
.findings .criterion-name { font-weight: 600; }
.findings .criterion .mono {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  direction: ltr;
  unicode-bidi: isolate;
  margin-top: 2px;
}

/* --- the inferred tier, visually separated from the measured one --- */

/* A dashed edge and no accent colour: everything above this line came from the
   waveform, everything below is a model's reading. The distinction is the
   whole architecture, so it is visible before anything is read. */
.qualitative {
  margin-top: var(--s5);
  padding-top: var(--s4);
  border-top: 1px dashed var(--line);
  font-size: var(--t-small);
  color: var(--muted);
}
.qualitative h3 { margin: 0 0 var(--s1); font-size: 14px; color: var(--ink); }
.qualitative li { margin: var(--s1) 0; }

.session {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.session .meta { font-size: 13px; color: var(--muted); }
.session button { padding: 5px 11px; font-size: 13px; }

/* --- moments: where a metric actually happened --- */

.moments { margin-top: 7px; }
.moment {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 3px 0;
  font-size: 12.5px;
}
/* Timestamps stay LTR inside RTL text, or mm:ss reorders into ss:mm. */
.moment .ts { direction: ltr; unicode-bidi: isolate; color: var(--accent); flex: none; }
.moment .excerpt { color: var(--ink); opacity: 0.82; }

/* --- prosodic arc and trends --- */

.arc, .responsiveness { margin-top: 18px; }
.arc h3, .responsiveness h3 { margin: 0 0 3px; font-size: 14px; }

.spark {
  width: 100%;
  height: 90px;
  margin-top: 8px;
  color: var(--accent);
  display: block;
}
.spark circle { fill: var(--accent); }

.trend { margin: 16px 0; }
.trend-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.trend .spark { height: 60px; }

/* --- inferred, never measured --- */

/* Deliberately not accent-coloured: this is the one value on screen that did
   not come from the waveform, and it should not look like the ones that did. */
.tag.inferred {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--warn);
  color: var(--warn);
  vertical-align: middle;
}
.responsiveness .big { font-size: 26px; font-weight: 700; margin: 6px 0 0; }

/* --- playable spans --- */

.playable { cursor: pointer; }
.playable:hover { background: color-mix(in srgb, var(--accent) 9%, transparent); border-radius: 6px; }

/* --- conversation phases --- */

.segments { margin-top: 18px; }
.segs { display: flex; gap: 6px; align-items: flex-end; margin-top: 8px; direction: ltr; }
.seg { flex: 1; text-align: center; }
.seg-bar {
  height: 70px;
  background: var(--line);
  border-radius: 4px;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
}
.seg-fill { width: 100%; background: var(--accent); }
.seg-label, .seg-val { font-size: 11px; color: var(--muted); margin-top: 3px; }

/* --- the other person --- */

.counterpart { margin-top: 18px; }
/* Deliberately quieter than your own metrics: this is context, not a verdict.
   The rubric judges you, not them. */
.counterpart .metric { opacity: 0.85; }

/* --- commitment --- */

.commitment { margin: 12px 0; padding: 9px 12px; border-radius: var(--radius); font-size: 13px; }
.commitment.met { border: 1px solid var(--ok); color: var(--ok); }
.commitment.missed { border: 1px solid var(--warn); color: var(--warn); }
.commitment-pick { margin-top: 18px; }
.commitment-pick select { margin: 6px 8px 6px 0; }

/* --- attribution coverage warning --- */

/* Warn-coloured, not error: a low coverage does not invalidate the session, it
   tells you the talk ratio is standing on less evidence than usual. */
.coverage-warn {
  margin: 10px 0;
  padding: 8px 11px;
  border: 1px solid var(--warn);
  border-radius: var(--radius);
  color: var(--warn);
  font-size: 12.5px;
}

textarea {
  width: 100%;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  font: inherit;
  resize: vertical;
}

/* A thin identification margin is not cosmetic: everything below it depends
   on the right speaker having been picked. */
.margin-thin { color: var(--warn); font-weight: 600; }

/* --- job cancel button --- */

button.secondary.small {
  padding: 4px 10px;
  font-size: 12px;
  margin-inline-start: 8px;
}

/* --- transcript line linked from a segment/moment click --- */

.utt.jump {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  border-radius: 6px;
  transition: background 2.4s ease-out;
}

/* --- vocal cue tags in the transcript, inferred not measured --- */

.tag.inferred.small {
  font-size: 10px;
  padding: 0 5px;
}

/* --- session note quoted in history --- */

.note-quote {
  font-size: 12.5px;
  color: var(--muted);
  font-style: italic;
  margin-top: 3px;
}

/* --- recurring cross-session pattern --- */

.pattern { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.pattern h3 { margin: 0 0 3px; font-size: 14px; }

/* --- batch: several recordings, queued --- */

.batch { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 13px; }
.batch td { padding: 6px 8px; border-top: 1px solid var(--line); vertical-align: middle; }
.batch td.name { max-width: 240px; overflow-wrap: anywhere; }
.batch td.name .muted { display: block; }
.batch select, .batch input { width: 100%; min-width: 70px; }

/* A checkbox column, not a dropdown: the batch row offers the same choice the
   analyse tab does, so it has to show the same thing -- every category at
   once, with the ticked ones visibly ticked. */
.batch td.batch-goals {
  min-width: 150px;
  white-space: normal;
}
.batch-goal {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  line-height: 1.5;
  cursor: pointer;
}
.batch-goal input {
  width: auto;
  min-width: 0;
  cursor: pointer;
}
.batch td.st { white-space: normal; color: var(--muted); }
.batch td.st.done { color: var(--ok); }
.batch td.st.failed { color: var(--bad); }
.row { display: flex; gap: 8px; align-items: center; }
.grow { flex: 1; min-width: 0; }

/* --- switching between judged categories --- */

.goal-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.goal-tab {
  padding: 4px 10px;
  font-size: 12.5px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
}
.goal-tab.active {
  color: var(--ink);
  border-color: var(--ink);
}

/* Every category visible at once, each with its own box. A multi-select hid
   this: unticked options looked the same as ones scrolled out of view. */
.goal-picker {
  display: grid;
  gap: var(--s2);
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}

/* A card, not a line of text. A bare list of names meant the only way to find
   out what a category measures was to open another tab and read its YAML. */
.goal-option {
  display: flex;
  align-items: flex-start;
  gap: var(--s3);
  padding: var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--sunken);
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.goal-option:hover { border-color: color-mix(in srgb, var(--line) 60%, var(--ink) 15%); }
/* :has is what makes the whole card show selection rather than only the box. */
.goal-option:has(input:checked) {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 7%, transparent);
}
.goal-option input { cursor: pointer; margin-top: 3px; flex: none; width: auto; }
.goal-body { min-width: 0; }
.goal-name { font-weight: 600; font-size: var(--t-small); }
.goal-sub {
  margin-top: 2px;
  font-size: var(--t-hint);
  line-height: 1.5;
  color: var(--muted);
}
.goal-counts {
  margin-top: var(--s1);
  font-size: var(--t-hint);
  color: var(--muted);
  opacity: 0.8;
}

/* The summary of what pressing Analyse will do. */
.goal-desc {
  margin-top: var(--s3);
  padding: var(--s3);
  border-radius: var(--radius-sm);
  background: var(--sunken);
  font-size: var(--t-small);
  color: var(--muted);
}
.goal-desc b { color: var(--ink); }
.goal-cost { display: block; margin-top: var(--s1); font-size: var(--t-hint); opacity: 0.75; }
.warn-text { color: var(--warn); }

/* --- restoring a backup --- */

.restore-plan {
  margin-top: var(--s4);
  padding: var(--s4);
  border: 1px solid var(--warn);
  border-radius: var(--radius-sm);
  /* Warm-bordered on purpose: this is the one panel in the app whose button
     rewrites data that already exists. */
  background: color-mix(in srgb, var(--warn) 6%, transparent);
}
.restore-lines {
  margin: var(--s2) 0;
  padding-inline-start: var(--s4);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: var(--t-hint);
  color: var(--muted);
  direction: ltr;
  text-align: start;
}

/* --- secondary buttons --- */

/* Used in eleven places and styled nowhere: every button marked secondary
   rendered identically to a default one, so the distinction the markup was
   making did not reach the screen. */
button.secondary {
  background: transparent;
  color: var(--muted);
}
button.secondary:hover:not(:disabled) { background: var(--sunken); color: var(--ink); }

/* --- about --- */

#about h3 { margin: var(--s4) 0 var(--s1); font-size: var(--t-small); color: var(--ink); }
#about p { margin: 0; line-height: 1.7; }

/* The one line that stops the wrong secret being pasted into the gate. */
.gate-warn {
  margin-bottom: var(--s4);
  padding: var(--s3);
  border-inline-start: 3px solid var(--warn);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--warn) 8%, transparent);
  font-size: var(--t-hint);
  line-height: 1.6;
  color: var(--ink);
}

/* A URL is Latin and must not reorder inside an Arabic page. */
#appUrl {
  direction: ltr;
  text-align: start;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: var(--t-hint);
}

.gap-retry {
  display: flex;
  align-items: center;
  gap: var(--s3);
  flex-wrap: wrap;
  margin-top: var(--s3);
}

/* --- settings --- */

.setting {
  padding: var(--s4) 0;
  border-bottom: 1px solid var(--line-soft);
}
.setting:last-of-type { border-bottom: none; }
.setting-head {
  display: flex;
  align-items: center;
  gap: var(--s3);
  margin-bottom: var(--s1);
}
/* Keys and tokens are Latin: keep them LTR whatever the interface language,
   or a pasted key renders reversed and looks wrong when it is not. */
#geminiKey, #hfKey { direction: ltr; text-align: start; }

/* --- the token gate --- */

/* Covers the page rather than sitting in it: with no token nothing behind it
   works, and letting the user tab through five broken panels to find the one
   explanation would be worse than blocking them. */
/* The `hidden` attribute is not enough on its own here. A browser hides it with
   `[hidden] { display: none }` from the user-agent sheet, and ANY author rule
   setting display beats that -- so `.gate { display: flex }` kept a full-screen
   92%-opaque overlay on top of the app at all times, empty and invisible,
   swallowing every click. The app looked dimmed and completely dead. */
.gate[hidden] { display: none; }

.gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s4);
  background: rgba(18, 20, 26, 0.92);
}
.gate-box {
  width: min(460px, 100%);
  padding: var(--s5);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.gate-box h2 { margin: 0 0 var(--s2); font-size: 16px; }
.gate-box p { margin: 0 0 var(--s4); line-height: 1.6; }

/* What the conversation was about, on each row of the history.
   Muted and set below the filename: this is what identifies a session, but it
   is inferred, and it must not read with the same authority as the measured
   numbers beside it. The pill says so outright. */
.session-summary {
  margin-top: var(--s2);
  max-width: 70ch;
  font-size: var(--t-hint);
  line-height: 1.6;
  color: var(--ink-dim, var(--ink));
}
.session-summary .pill { margin-inline-start: var(--s2); vertical-align: middle; }

/* "Use a recovery code instead". A button because it acts like one, styled
   like a link because a second primary-looking control next to Sign in would
   read as an alternative way to log in rather than a change of method. */
.linkish {
  margin-top: var(--s3);
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: var(--t-hint);
  text-decoration: underline;
  cursor: pointer;
}
.linkish:hover { color: var(--ink); }

/* The enrolment QR. White always, in every theme: a dark-themed QR with an
   inverted or tinted background is one a camera will not read, and the whole
   point of it is being scanned. */
.qr-box {
  display: flex;
  justify-content: center;
  margin: var(--s4) 0;
  padding: var(--s4);
  border-radius: var(--radius-sm);
  background: #fff;
}
.qr-box svg { width: min(220px, 60vw); height: auto; }

/* Recovery codes are read off a screen and typed onto paper, so they are
   monospaced and spaced out rather than packed into a paragraph. */
.recovery-codes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--s2);
  margin: var(--s3) 0 var(--s4);
  padding: 0;
  list-style: none;
}
.recovery-codes code {
  display: block;
  padding: var(--s2) var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-2, var(--panel));
  font-size: var(--t-hint);
  letter-spacing: 0.05em;
  /* Latin codes inside an Arabic page must not reorder. */
  direction: ltr;
  text-align: center;
}

/* --- narrow windows --- */

/* Not a phone layout: this runs on a desktop. Enough that a half-width window
   does not push the tab bar and the two-column fields off the edge. */
@media (max-width: 620px) {
  main { padding: var(--s3); }
  nav { padding: var(--s2) var(--s3) 0; overflow-x: auto; }
  .card { padding: var(--s4); }
  .field-row { flex-direction: column; gap: 0; }
  .goal-picker { grid-template-columns: 1fr; }
}

/* --- adopting criteria from a new paste --- */

.diff {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
}
.diff h3 { margin: 10px 0 4px; font-size: 13px; }
.diff ul { margin: 0; padding-inline-start: 18px; }
.diff-row label {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* --- choosing what to follow --- */

.tracking {
  padding: 10px 12px;
  margin: 8px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  /* Long enough to need scrolling: there are more measured metrics than fit
     on a screen, and paging them would hide the one being looked for. */
  max-height: 320px;
  overflow-y: auto;
}
.track-row { padding: 2px 0; }
.track-row label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: ui-monospace, "Cascadia Mono", "Consolas", monospace;
  font-size: 12.5px;
}
.rank-input { width: 56px; }

/* --- asking about a stored session --- */

.chat {
  padding: 10px 12px 12px;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
}
.chat-turns { margin: 8px 0; }
.chat-turn { padding: 8px 0; border-bottom: 1px solid var(--line); }
.chat-turn:last-child { border-bottom: none; }
.chat-q { font-weight: 600; }
.chat-a {
  margin-top: 4px;
  /* An answer can be several sentences and may contain newlines the model
     wrote; collapsing them would run its paragraphs together. */
  white-space: pre-wrap;
  color: var(--muted);
}

/* --- qualitative assessment (inferred tier) --- */

.assess {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.assess:last-child { border-bottom: none; }
.assess-q { font-weight: 600; }

.assess-verdict {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  /* Deliberately not the green/red used for measured findings: these are
     opinions, and colouring them like a passed criterion would say otherwise. */
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--muted);
}
.assess-verdict.v-unclear { font-style: italic; }

.assess-note {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

/* --- goal categories --- */

.category-row {
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.category-row:last-child { border-bottom: none; }

/* Monospace because this is authored YAML: indentation is load-bearing, and a
   proportional font hides a criterion nested one level too deep. */
#categoryYaml {
  font-family: ui-monospace, "Cascadia Mono", "Consolas", monospace;
  font-size: 12.5px;
  line-height: 1.5;
  /* YAML is written left-to-right even when the interface is mirrored, and the
     Arabic display_name lines render right-to-left inside it regardless. */
  direction: ltr;
  text-align: left;
}

#categoryMetrics {
  font-family: ui-monospace, "Cascadia Mono", "Consolas", monospace;
  direction: ltr;
  text-align: left;
  padding-top: 6px;
  line-height: 1.8;
}

/* --- the queue, and how far along it is --- */

/* Its own card at the top, not a table tucked under the file picker: what is
   running and what is waiting is the thing you come back to the screen to
   check, and it was previously below the fold. */
.queue-card { border-color: var(--accent); }

.queue-row {
  padding: var(--s3) 0;
  border-top: 1px solid var(--line-soft);
}
.queue-row:first-child { border-top: none; }

.queue-head {
  display: flex;
  align-items: center;
  gap: var(--s2);
  flex-wrap: wrap;
}
.queue-name { overflow-wrap: anywhere; }
.queue-state {
  padding: 1px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: var(--t-hint);
}
.queue-state.running { color: var(--accent); border-color: var(--accent); }
.queue-state.done { color: var(--ok); border-color: var(--ok); }
.queue-state.failed { color: var(--bad); border-color: var(--bad); }
.queue-pct { margin-inline-start: auto; }
.queue-buttons { display: flex; gap: var(--s2); margin-inline-start: auto; }
.queue-pct + .queue-buttons { margin-inline-start: 0; }

.queue-detail {
  margin-top: var(--s1);
  color: var(--muted);
  font-size: var(--t-small);
}
.queue-error { margin-top: var(--s1); color: var(--bad); font-size: var(--t-small); }
/* Which entry the panels below are describing. Without it, a finished queue of
   four looks like four results and shows one. */
.queue-row.viewing { background: var(--sunken); }

/* One action, so it reads as one. Everything above it is a choice. */
button.primary.big {
  font-size: 16px;
  padding: 11px 26px;
}
.run-actions { margin-top: var(--s4); }

/* A bar rather than a percentage inside a sentence: the point of the number is
   the shape of the wait, and a bar carries that at a glance. */
progress.bar {
  display: block;
  width: 100%;
  height: 6px;
  margin-top: var(--s2);
  border: none;
  border-radius: 3px;
  background: var(--sunken);
  appearance: none;
}
progress.bar::-webkit-progress-bar { background: var(--sunken); border-radius: 3px; }
progress.bar::-webkit-progress-value { background: var(--accent); border-radius: 3px; }
progress.bar::-moz-progress-bar { background: var(--accent); border-radius: 3px; }

/* --- missing stretches --- */

.gap-total { margin-top: var(--s2); }
.gap-spans {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
  margin-top: var(--s2);
}
.gap-span {
  font-variant-numeric: tabular-nums;
  direction: ltr;
  unicode-bidi: isolate;
  padding: 2px 7px;
  border: 1px solid var(--warn);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--warn);
  font-size: var(--t-hint);
}
button.gap-span { cursor: pointer; }
button.gap-span:hover { background: color-mix(in srgb, var(--warn) 12%, transparent); }

/* --- what a metric means --- */

.info {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  margin-inline-start: 5px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  line-height: 1;
  cursor: help;
  vertical-align: middle;
}
.info:hover { color: var(--ink); border-color: var(--accent); }

.modal { position: fixed; inset: 0; z-index: 50; }
.modal-back { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.55); }
.modal-box {
  position: relative;
  max-width: 520px;
  margin: 12vh auto 0;
  padding: var(--s5);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  max-height: 70vh;
  overflow-y: auto;
}
.modal-box h3 { margin-top: 0; }
.modal-box h4 { margin: var(--s4) 0 var(--s1); font-size: var(--t-small); color: var(--muted); }
.modal-box p { margin: 0; }
.modal-close {
  position: absolute;
  inset-inline-end: var(--s3);
  inset-block-start: var(--s3);
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.mono { font-family: ui-monospace, Consolas, monospace; margin-top: var(--s4); }

/* --- a key that does not work, and a session that is not this one --- */

.key-banner {
  margin: 0 auto;
  max-width: 900px;
  padding: var(--s3) var(--s4);
  border: 1px solid var(--bad);
  border-radius: var(--radius);
  color: var(--bad);
  font-size: var(--t-small);
}
.key-line { color: var(--ink); }
.key-actions { display: flex; gap: var(--s2); margin-top: var(--s2); }

.session-banner {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s3);
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--s4);
  padding: var(--s3) var(--s4);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--sunken);
}


/* --- target sizes --- */

/* WCAG 2.5.8 asks for 24x24 CSS pixels of pointer target. Most buttons here
   clear it on padding alone; the small and ghost variants did not, and the
   help mark was 15x15. Stated as a floor rather than fixed per control, so a
   new small button cannot quietly fall under it. */
button,
.filepick-btn {
  min-height: 36px;
}
button.small,
button.ghost {
  min-height: 28px;
}
.info {
  width: 24px;
  height: 24px;
  /* Against the 36px floor above: this one sits INSIDE a line of text, and a
     36px-tall inline element pushes that line apart. 24px is the WCAG 2.5.8
     minimum and the most a help mark may take from the line it annotates. */
  min-height: 24px;
  /* The MARK stays small; the target does not. The ring is drawn by ::before
     inside a box that is comfortably clickable. */
  background: transparent;
  border: none;
  position: relative;
}
.info::before {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid var(--line);
  border-radius: 50%;
}
.info:hover::before { border-color: var(--accent); }

/* --- motion --- */

/* Every transition here is 120ms and carries meaning -- a border responding to
   focus, a line marking where a moment is. Under a reduced-motion preference
   the meaning is kept and the movement is not: colours still change, the
   transcript still jumps to the right line, but nothing slides or eases. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Announced, never drawn. Not display:none, which would take it out of the
   accessibility tree along with the screen. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* --- choosing a palette --- */

.theme-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: var(--s3);
  margin-top: var(--s4);
}

/* Each card renders in the palette it offers, by carrying that palette's own
   attribute. A hand-drawn swatch would be a second copy of the colours and
   would drift from the CSS the first time one was edited. */
.theme-card {
  display: block;
  padding: var(--s3);
  text-align: start;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--ink);
  min-height: 0;
}
.theme-card:hover:not(:disabled) { border-color: var(--accent); background: var(--bg); }
.theme-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.theme-swatch {
  display: flex;
  height: 26px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--line);
}
.theme-swatch .sw { flex: 1; }
.sw-bg { background: var(--bg); }
.sw-panel { background: var(--panel); }
.sw-accent { background: var(--accent); }
.sw-ink { background: var(--ink); }
.theme-name { display: block; margin-top: var(--s2); font-weight: 600; }
.theme-note { display: block; line-height: 1.5; }

/* The enrolment screen carries a QR, a secret, ten recovery codes and a
   confirmation field. The standard gate box is sized for a password prompt. */
.gate-box.gate-wide {
  width: min(560px, 100%);
  max-height: 90vh;
  overflow-y: auto;
}
.gate-box h3 { margin: var(--s4) 0 var(--s2); font-size: 14px; }
