/*
 * The console's appearance.
 *
 * This is an operator tool. It is SCANNED, not read: somebody submits a scenario, glances at nine
 * rows, and needs to know within a second which of them stopped something. So the design budget
 * goes to the reading order and to making a verdict legible at a glance, and nowhere else. There
 * is no illustration, no gradient for its own sake and no animation that carries no information.
 *
 * ── Severity is encoded in FORM, not only in colour ─────────────────────────
 *
 * Three states matter — something is blocked, something is waiting, something is clear — and each
 * gets a distinct SHAPE as well as a distinct hue:
 *
 *   blocked   a solid stripe running the full height of the row, and a square mark
 *   waiting   a hatched stripe, and a diamond mark
 *   clear     a short centred stripe, and a round mark
 *
 * Printed in greyscale, seen by somebody with deuteranopia, or rendered on a projector that has
 * eaten the reds, the three are still three. Colour is the fast channel; shape is the one that
 * cannot be lost.
 *
 * ── Semantic colour is separate from accent ─────────────────────────────────
 *
 * `--accent` is the product's own hue and is used for interactive chrome only: focus rings, the
 * primary button, links. The severity tokens are a different family and never borrow from it, so
 * changing the brand cannot change what "blocked" looks like, and an accent that happens to be red
 * cannot come to mean "stopped".
 *
 * ── Both themes, twice over ─────────────────────────────────────────────────
 *
 * `prefers-color-scheme` is the default signal. `:root[data-theme="dark"|"light"]` overrides it,
 * because the toggle in the header has to win in BOTH directions — a viewer in a dark OS asking
 * for light gets light.
 */

/* ── tokens ──────────────────────────────────────────────────────────────── */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --line: #d8dde4;
  --line-strong: #b9c1cc;
  --ink: #14181f;
  --ink-2: #4b5563;
  --ink-3: #6f7887;

  --accent: #3f4bd8;
  --accent-ink: #ffffff;
  --accent-soft: #e8eaff;

  --sev-block: #ad2318;
  --sev-block-bg: #fceeec;
  --sev-wait: #855100;
  --sev-wait-bg: #fbf2e0;
  --sev-clear: #1a6a45;
  --sev-clear-bg: #e7f4ed;

  /* The header's height, so the sticky column below it can be sized from one number rather than
     from two hand-copied ones that drift apart the first time the header changes. */
  --bar: 58px;
  --radius: 10px;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1015;
    --surface: #161a21;
    --surface-2: #1c212a;
    --line: #2a313c;
    --line-strong: #3b4453;
    --ink: #e9ecf1;
    --ink-2: #a7b0bd;
    --ink-3: #7d8695;

    --accent: #8f97ff;
    --accent-ink: #10131a;
    --accent-soft: #23283c;

    --sev-block: #ff9c92;
    --sev-block-bg: #331f1d;
    --sev-wait: #ecc078;
    --sev-wait-bg: #2c2517;
    --sev-clear: #78d6a4;
    --sev-clear-bg: #16281f;
  }
}

:root[data-theme="light"] {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --line: #d8dde4;
  --line-strong: #b9c1cc;
  --ink: #14181f;
  --ink-2: #4b5563;
  --ink-3: #6f7887;
  --accent: #3f4bd8;
  --accent-ink: #ffffff;
  --accent-soft: #e8eaff;
  --sev-block: #ad2318;
  --sev-block-bg: #fceeec;
  --sev-wait: #855100;
  --sev-wait-bg: #fbf2e0;
  --sev-clear: #1a6a45;
  --sev-clear-bg: #e7f4ed;
}

:root[data-theme="dark"] {
  --bg: #0d1015;
  --surface: #161a21;
  --surface-2: #1c212a;
  --line: #2a313c;
  --line-strong: #3b4453;
  --ink: #e9ecf1;
  --ink-2: #a7b0bd;
  --ink-3: #7d8695;
  --accent: #8f97ff;
  --accent-ink: #10131a;
  --accent-soft: #23283c;
  --sev-block: #ff9c92;
  --sev-block-bg: #331f1d;
  --sev-wait: #ecc078;
  --sev-wait-bg: #2c2517;
  --sev-clear: #78d6a4;
  --sev-clear-bg: #16281f;
}

/* ── base ────────────────────────────────────────────────────────────────── */

* { box-sizing: border-box; }

/*
 * `hidden` has to beat a layout class, and by default it does not.
 *
 * This page is three screens in one document — sign in, register, console — and each is switched
 * with the `hidden` attribute. The browser's own `[hidden] { display: none }` lives in the user-
 * agent stylesheet, so ANY author rule that sets `display` wins over it: `.gate { display: flex }`
 * and `.console { display: grid }` both do, and the result is all three screens stacked down the
 * page at once. Found by rendering the page rather than by reading it.
 */
[hidden] { display: none !important; }

html { color-scheme: light dark; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
p { margin: 0; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ── header ──────────────────────────────────────────────────────────────── */

.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.bar-name { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.mark {
  width: 12px; height: 12px; border-radius: 3px;
  background: var(--accent); align-self: center; flex: none;
}
.wordmark { font-weight: 640; letter-spacing: -0.015em; }
.bar-sub { color: var(--ink-3); font-size: 13px; }
.bar-right { display: flex; align-items: center; gap: 8px; }
.who { color: var(--ink-2); font-size: 13px; }

/* ── controls ────────────────────────────────────────────────────────────── */

button { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid transparent; }
button:disabled { cursor: default; opacity: 0.55; }

.primary { background: var(--accent); color: var(--accent-ink); padding: 10px 16px; font-weight: 560; }
.secondary { background: var(--surface-2); color: var(--ink); border-color: var(--line-strong); padding: 10px 16px; }
.ghost { background: transparent; color: var(--ink-2); border-color: var(--line); padding: 6px 12px; font-size: 13px; }
.ghost:hover, .secondary:hover { border-color: var(--ink-3); color: var(--ink); }
.wide { width: 100%; }

input, textarea {
  font: inherit; width: 100%; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px;
}
textarea { resize: vertical; line-height: 1.45; }
textarea.mono { font-family: var(--mono); font-size: 13px; }
input::placeholder { color: var(--ink-3); }

/* ── sign in / enrol ─────────────────────────────────────────────────────── */

.gate { display: flex; justify-content: center; padding: 56px 20px; }
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 28px;
}
.gate-card { width: 100%; max-width: 460px; }
.gate-title { font-size: 22px; margin-bottom: 8px; }
.gate-sub { font-size: 15px; margin-bottom: 6px; }
.gate-lede { color: var(--ink-2); font-size: 14px; margin-bottom: 18px; }
.rule { border: 0; border-top: 1px solid var(--line); margin: 26px 0 20px; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; }
.note { margin-top: 12px; font-size: 13px; color: var(--ink-2); }
.error { margin-top: 12px; font-size: 13px; color: var(--sev-block); }

/* ── console layout ──────────────────────────────────────────────────────── */

.console {
  display: grid; gap: 20px; padding: 20px;
  grid-template-columns: minmax(0, 1fr);
  max-width: 1500px; margin: 0 auto;
}
/*
 * Two columns once there is room: the scenario stays put and the results scroll beside it.
 *
 * `--bar` is the header's measured height. The scenario panel is pinned just below it and given
 * the rest of the viewport, so it scrolls INSIDE itself — the form is 2,500px tall by design,
 * it is the whole scenario, and a page that scrolls as one would take the results off screen
 * every time somebody edited a field.
 */
@media (min-width: 1040px) {
  .console { grid-template-columns: minmax(360px, 30rem) minmax(0, 1fr); align-items: start; }
  .scenario {
    position: sticky;
    top: calc(var(--bar) + 20px);
    max-height: calc(100vh - var(--bar) - 40px);
    overflow-y: auto;
  }
  /* And the primary action is pinned to the foot of that scroll rather than living at the end of
     it. An operator should never have to hunt for "run". */
  .scenario .actions {
    position: sticky;
    bottom: -20px;
    margin: 22px -20px -20px;
    padding: 14px 20px 20px;
    background: var(--surface);
    border-top: 1px solid var(--line);
  }
}

.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px;
}
.panel-title { font-size: 16px; }
.panel-lede { color: var(--ink-2); font-size: 13.5px; margin-top: 6px; }
.section-title { font-size: 15px; }
.section-lede { color: var(--ink-3); font-size: 13px; margin-top: 4px; }

/* ── the scenario form ───────────────────────────────────────────────────── */

.group { border: 0; border-top: 1px solid var(--line); margin: 20px 0 0; padding: 16px 0 0; }
.group legend {
  padding: 0 8px 0 0; font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-3);
}
.field { display: block; margin-top: 12px; }
.field:first-child { margin-top: 0; }
.label { display: block; font-size: 13px; font-weight: 550; margin-bottom: 5px; }
.hint { font-weight: 400; color: var(--ink-3); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.grid-2 .field { margin-top: 0; }
.check { display: flex; gap: 8px; align-items: center; margin-top: 10px; font-size: 13.5px; }
.check input { width: auto; }

.channels { display: grid; gap: 2px; }
.channel {
  display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: baseline;
  padding: 7px 8px; border-radius: 7px;
}
.channel:hover { background: var(--surface-2); }
.channel input { width: auto; align-self: center; }
.channel-name { font-weight: 560; font-size: 13.5px; }
.channel-label { display: block; color: var(--ink-3); font-size: 12.5px; }

.actions { margin-top: 22px; }

/* ── progress ────────────────────────────────────────────────────────────── */

.progress { margin-bottom: 18px; }
.progress-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink-2); margin-bottom: 6px; }
.meter { height: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.meter-fill { height: 100%; width: 0%; background: var(--accent); transition: width 140ms linear; }

.empty { padding: 8px 0 4px; }

/* ── what still needs a human — the point of the page ────────────────────── */

.human {
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 22px;
  background: var(--surface);
}
.human-title { font-size: 21px; letter-spacing: -0.02em; }
.human-lede { color: var(--ink-2); font-size: 13.5px; margin-top: 8px; max-width: 62ch; }
.human-list { list-style: none; margin: 18px 0 0; padding: 0; counter-reset: human; }
.human-list li {
  counter-increment: human;
  display: grid; grid-template-columns: 2.1rem minmax(6.5rem, auto) 1fr; gap: 12px;
  padding: 11px 0; border-top: 1px solid var(--line); align-items: baseline;
}
.human-list li::before {
  content: counter(human, decimal-leading-zero);
  font-family: var(--mono); font-size: 12px; color: var(--ink-3);
}
.human-dept { font-weight: 600; font-size: 14px; }
.human-authority { color: var(--ink); font-size: 14.5px; }

/* ── held at the gate ────────────────────────────────────────────────────── */

.held { margin-bottom: 22px; }
.held-list { list-style: none; margin: 12px 0 0; padding: 0; }
.held-list li {
  display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: baseline;
  padding: 10px 12px; margin-top: 6px;
  background: var(--sev-wait-bg); border: 1px solid var(--sev-wait);
  border-radius: 8px; font-size: 13.5px;
}
.held-dept { font-weight: 600; }
.held-action { font-family: var(--mono); font-size: 12.5px; }
.held-why { color: var(--ink-2); flex-basis: 100%; font-size: 12.5px; }
.oneway {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--sev-wait); border: 1px solid var(--sev-wait); border-radius: 999px; padding: 1px 8px;
}

/* ── board packet ────────────────────────────────────────────────────────── */

.packet-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.summary { color: var(--ink-3); font-size: 12.5px; }
.verdicts { list-style: none; margin: 12px 0 0; padding: 0; }

.verdict {
  position: relative;
  display: grid;
  grid-template-columns: minmax(7.5rem, auto) minmax(6rem, auto) 1fr;
  gap: 6px 14px;
  align-items: baseline;
  padding: 12px 14px 12px 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 6px;
  background: var(--surface);
}
/* The stripe. Its FORM differs by severity, so the state survives greyscale. */
.verdict::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px;
  border-radius: 8px 0 0 8px;
}
.verdict[data-severity="blocked"] { border-color: var(--sev-block); background: var(--sev-block-bg); }
.verdict[data-severity="blocked"]::before { background: var(--sev-block); }
.verdict[data-severity="waiting"] { border-color: var(--sev-wait); }
.verdict[data-severity="waiting"]::before {
  background: repeating-linear-gradient(
    -45deg, var(--sev-wait) 0 3px, transparent 3px 6px
  );
}
.verdict[data-severity="clear"]::before {
  top: 30%; bottom: 30%; background: var(--sev-clear); border-radius: 0 3px 3px 0;
}

.chip {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--mono); font-size: 11.5px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase;
  padding: 3px 9px; border-radius: 5px; border: 1px solid currentColor;
  white-space: nowrap;
}
.chip::before { content: ""; width: 8px; height: 8px; background: currentColor; flex: none; }
.verdict[data-severity="blocked"] .chip { color: var(--sev-block); }
.verdict[data-severity="blocked"] .chip::before { border-radius: 1px; }              /* square */
.verdict[data-severity="waiting"] .chip { color: var(--sev-wait); }
.verdict[data-severity="waiting"] .chip::before { transform: rotate(45deg); }        /* diamond */
.verdict[data-severity="clear"] .chip { color: var(--sev-clear); }
.verdict[data-severity="clear"] .chip::before { border-radius: 50%; }                /* circle */

.verdict-dept { font-weight: 620; font-size: 14px; }
.verdict-detail { grid-column: 1 / -1; color: var(--ink-2); font-size: 13.5px; }
.verdict-effect {
  grid-column: 1 / -1; font-family: var(--mono); font-size: 11.5px; color: var(--ink-3);
}

/* ── raw request ─────────────────────────────────────────────────────────── */

.raw { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 14px; }
.raw summary { cursor: pointer; font-size: 13px; color: var(--ink-2); }
.raw pre {
  margin: 12px 0 0; padding: 14px; background: var(--surface-2);
  border-radius: 8px; overflow-x: auto; font-size: 12px; line-height: 1.55;
}

/* ── footer ──────────────────────────────────────────────────────────────── */

.foot {
  padding: 22px 20px 34px; text-align: center;
  color: var(--ink-3); font-size: 12.5px;
}
