/* Nib — staff. One stylesheet, no framework, no build step.
 *
 * Dense and quiet on purpose: this is the fifth will of the morning, not a landing
 * page. Colour is never the only carrier of meaning (WCAG 2.2 SC 1.4.1) — every
 * provenance marker and every severity carries an icon and a word as well as a
 * tint, and the focus ring is visible on every interactive thing because a
 * keyboard-first tool that loses focus is unusable. */

:root {
  color-scheme: light dark;

  --ink: #10151b;
  --ink-2: #40505f;
  --ink-3: #586a7c;      /* 5:1 or better on every ground it is used on */
  --paper: #f7f8f9;
  --card: #ffffff;
  --line: #d9dee3;
  --line-2: #eceff1;

  --tint: #1f5fd0;          /* from the CRM */
  --tint-bg: #eef4fe;
  --amber: #8a5200;         /* edited, escalation */
  --amber-bg: #fdf3e3;
  --red: #a4162c;           /* refusal */
  --red-bg: #fdeef0;
  --green: #0d6b47;         /* assembled, cleared */
  --green-bg: #eaf6f0;
  --violet: #5b3ec8;        /* derived */
  --violet-bg: #f1eefc;

  --radius: 6px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e8edf2; --ink-2: #a9b8c6; --ink-3: #7f8fa0;
    --paper: #0e1216; --card: #151b21; --line: #2a333c; --line-2: #1d242b;
    --tint: #7aa8f5; --tint-bg: #14233c;
    --amber: #e8b169; --amber-bg: #2e2211;
    --red: #f19aa6; --red-bg: #331519;
    --green: #7fd6ae; --green-bg: #10281f;
    --violet: #b9a7f7; --violet-bg: #201b38;
  }
}

* { box-sizing: border-box; }

/* The header is sticky and 56px tall. Without this, moving focus to a control near
 * the top of the page scrolls it to y=0, under the header, where it cannot be seen
 * (SC 2.4.11). */
html { scroll-padding-top: 64px; }

body {
  margin: 0;
  font: 14px/1.5 var(--sans);
  color: var(--ink);
  background: var(--paper);
  -webkit-text-size-adjust: 100%;
}

a { color: var(--tint); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; letter-spacing: -0.01em; }
h1 { font-size: 20px; }
/* Focus lands on the heading after each render so it is announced; a heading is not
 * a control, so it gets no ring. */
h1[tabindex="-1"]:focus, h2[tabindex="-1"]:focus { outline: none; }

/* Read by a screen reader, invisible on the screen: "(opens in a new tab)" after a
 * link that does. */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p { margin: 0 0 .7em; }

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

.skip {
  position: absolute; left: -9999px; top: 0; background: var(--card);
  padding: 8px 12px; z-index: 10;
}
.skip:focus { left: 8px; top: 8px; }

/* --- the specimen banner ------------------------------------------------- */
/* Loud on purpose. A consultant who cannot tell specimen prefill from CRM
 * prefill has no provenance at all. */
#specimen-banner {
  background: repeating-linear-gradient(135deg, var(--amber-bg) 0 12px, transparent 12px 24px);
  border-bottom: 2px solid var(--amber);
  color: var(--amber);
  font-weight: 650;
  padding: 7px 16px;
  display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap;
}
#specimen-banner span { font-weight: 400; color: var(--ink-2); }

/* --- top bar ------------------------------------------------------------- */
.top {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; text-decoration: none; color: var(--ink); display: flex; gap: 8px; align-items: center; }
.brand .mark {
  display: grid; place-items: center; width: 22px; height: 22px;
  background: var(--ink); color: var(--card); border-radius: 5px; font-size: 13px;
}
.muted { color: var(--ink-3); font-weight: 400; }
.back { color: var(--ink-2); font-size: 13px; font-weight: 600; text-decoration: none; padding: 4px 8px; border: 1px solid var(--line); border-radius: var(--radius); }
.back:hover { border-color: var(--ink-3); color: var(--ink); }
.back::before { content: "\2190\00a0"; }
.crumbs { color: var(--ink-2); font-size: 13px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.crumbs a { color: var(--ink-2); }
.top-right { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.who { font-size: 12px; color: var(--ink-3); border-left: 1px solid var(--line); padding-left: 10px; }
.who b { color: var(--ink-2); font-weight: 600; }

kbd {
  font: 11px/1 var(--mono);
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px;
  padding: 2px 4px; margin-left: 6px; color: var(--ink-3); background: var(--paper);
}

button, .btn {
  font: inherit; font-weight: 600;
  border: 1px solid var(--ink); background: var(--ink); color: var(--card);
  padding: 6px 12px; border-radius: var(--radius); cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
button.ghost, .btn.ghost {
  background: var(--card); color: var(--ink-2); border-color: var(--line);
}
button.ghost:hover { border-color: var(--ink-3); color: var(--ink); }
button[disabled] { opacity: .5; cursor: not-allowed; }
button.small { padding: 2px 8px; font-size: 12px; }
button.danger { background: var(--red-bg); border-color: var(--red); color: var(--red); }

main { padding: 18px 16px 64px; max-width: 1180px; margin: 0 auto; }
main > .loading { color: var(--ink-3); }

/* --- cards and rows ------------------------------------------------------ */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin: 0 0 14px;
}
.card > h2 { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.card.attn { border-left: 3px solid var(--amber); }
.card.stop { border-left: 3px solid var(--red); }
.card.good { border-left: 3px solid var(--green); }
.grid2 { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
@media (max-width: 900px) { .grid2 { grid-template-columns: minmax(0, 1fr); } }

.rows { list-style: none; margin: 0; padding: 0; }
.rows li {
  border-top: 1px solid var(--line-2); padding: 8px 6px;
  display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap;
}
.rows li:first-child { border-top: 0; }
.rows li[aria-current="true"], .rows li:focus { background: var(--tint-bg); box-shadow: inset 3px 0 0 var(--tint); }
.rows a { text-decoration: none; color: var(--ink); font-weight: 600; }
.rows .meta { color: var(--ink-3); font-size: 12px; }
.spacer { margin-left: auto; }

table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 7px 8px; border-top: 1px solid var(--line-2); vertical-align: top; overflow-wrap: anywhere; }
th { color: var(--ink-3); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.scroll { overflow-x: auto; }

/* --- provenance ---------------------------------------------------------- */
/* Icon + word + tint, never tint alone. The provenance line is RENDERED, not
 * hidden behind a hover: a tooltip nobody opens is a record nobody keeps. */
.field { border-left: 3px solid transparent; padding: 7px 10px; border-top: 1px solid var(--line-2); }
.field:first-child { border-top: 0; }
.field.crm { border-left-color: var(--tint); background: linear-gradient(90deg, var(--tint-bg), transparent 40%); }
.field.crm-edited { border-left-color: var(--amber); background: linear-gradient(90deg, var(--amber-bg), transparent 40%); }
.field.derived { border-left-color: var(--violet); }
.field.unmapped { border-left-color: var(--red); background: linear-gradient(90deg, var(--red-bg), transparent 40%); }
.field .head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.field .name { font: 12px/1.4 var(--mono); color: var(--ink-3); }
.field .label { color: var(--ink-2); flex: 1 1 260px; }
/* A 200-character URL typed as an answer must wrap, not push the row to 2000px. */
.field .value { font-weight: 600; overflow-wrap: anywhere; }
.field form.edit { display: grid; gap: 6px; max-width: 560px; margin: 4px 0; }
.field form.edit label { margin: 0; }
.field form.edit .actions { margin-top: 2px; }
.field .value.none { font-weight: 400; color: var(--ink-3); font-style: italic; }
.field .english { color: var(--ink-2); }
.field .prov {
  font-size: 12px; color: var(--ink-3); margin-top: 2px;
  display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap;
}
.field .prov .rule { font-style: italic; }

.chip {
  font-size: 11px; font-weight: 700; letter-spacing: .03em;
  border: 1px solid currentColor; border-radius: 999px; padding: 1px 7px;
  display: inline-flex; gap: 4px; align-items: center; white-space: nowrap;
}
.chip.crm { color: var(--tint); background: var(--tint-bg); }
.chip.crm-edited { color: var(--amber); background: var(--amber-bg); }
.chip.derived { color: var(--violet); background: var(--violet-bg); }
.chip.unmapped { color: var(--red); background: var(--red-bg); }
.chip.ok { color: var(--green); background: var(--green-bg); }
.chip.plain { color: var(--ink-3); background: var(--paper); }
.chip.typed-over { color: var(--amber); background: var(--amber-bg); }

/* --- findings ------------------------------------------------------------ */
.finding { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin: 0 0 12px; }
.finding.refuse { border-color: var(--red); background: var(--red-bg); }
.finding.escalate { border-color: var(--amber); background: var(--amber-bg); }
.finding.warn { border-left: 3px solid var(--amber); }
.finding.cleared { border-color: var(--green); background: var(--green-bg); }
.finding h3 { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.finding .id { font: 11px/1.4 var(--mono); color: var(--ink-3); }
.finding .because { margin: 6px 0; }
.finding .remedy { border-left: 3px solid var(--ink-3); padding-left: 10px; margin: 8px 0; color: var(--ink); }
.finding .remedy > b { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); }
.finding .remedy p { margin: 0 0 .5em; }
.finding .remedy p:last-child { margin-bottom: 0; }
.finding .when { font-size: 12px; color: var(--ink-2); }
.authorities { list-style: none; margin: 8px 0 0; padding: 0; font-size: 13px; }
.authorities li { border-top: 1px dotted var(--line); padding: 6px 0; }
.authorities .cite { font-weight: 650; }
.authorities .why { color: var(--ink-2); }

.banner {
  border: 1px solid var(--red); background: var(--red-bg); color: var(--red);
  border-radius: var(--radius); padding: 12px 14px; margin: 0 0 16px; font-weight: 600;
}
.banner.good { border-color: var(--green); background: var(--green-bg); color: var(--green); }
.banner.attn { border-color: var(--amber); background: var(--amber-bg); color: var(--amber); }
.banner p { font-weight: 400; color: var(--ink-2); margin: .4em 0 0; }
.banner p.announce { font-weight: 600; }

/* --- the document -------------------------------------------------------- */
/* One paragraph per clause block. The plain-text renderer's numbering and hanging
 * indents are spaces, so each paragraph keeps pre-wrap and the monospace face; a
 * reader gets paragraphs, the eye gets the same alignment. */
.document {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 22px; font: 13px/1.65 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere;
  max-height: 70vh; overflow: auto;
}
.document p { margin: 0 0 1.65em; }
.document p:last-child { margin-bottom: 0; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.hash { font: 11px/1.4 var(--mono); color: var(--ink-3); word-break: break-all; }

/* --- mirror -------------------------------------------------------------- */
.diff { width: 100%; }
.diff th { width: 50%; }
.diff td { font-weight: 600; }
.diff .side-a { border-left: 3px solid var(--tint); }
.diff .side-b { border-left: 3px solid var(--violet); }
.scopes { display: flex; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--ink-3); }

/* --- forms --------------------------------------------------------------- */
label { display: block; font-weight: 600; margin: 10px 0 4px; }
textarea, input[type="text"], input[type="search"], select {
  font: inherit; width: 100%; padding: 7px 9px;
  /* 3:1 against the card, so the box has an edge before it is focused (SC 1.4.11). */
  border: 1px solid var(--ink-3); border-radius: var(--radius);
  background: var(--card); color: var(--ink);
}
[aria-invalid="true"] { border-color: var(--red); box-shadow: 0 0 0 1px var(--red); }
.toggle { display: flex; gap: 8px; align-items: center; font-weight: 600; margin: 0 0 6px; }
.toggle input { accent-color: var(--tint); width: 16px; height: 16px; }
textarea { min-height: 74px; resize: vertical; }
.hint { font-size: 12px; color: var(--ink-3); }
.actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; align-items: center; }
.err { color: var(--red); font-weight: 600; }

dialog {
  border: 1px solid var(--line); border-radius: 10px; padding: 16px;
  background: var(--card); color: var(--ink); max-width: 560px; width: calc(100% - 32px);
}
dialog::backdrop { background: rgb(0 0 0 / .35); }
#palette-results { list-style: none; margin: 10px 0 0; padding: 0; }
#palette-results li { padding: 7px 8px; border-radius: var(--radius); cursor: pointer; }
#palette-results li[aria-selected="true"] { background: var(--tint-bg); }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
.keys dt { text-align: right; }
.keys dd { margin: 0; color: var(--ink-2); }

details { border-top: 1px solid var(--line-2); padding: 8px 0 2px; }
details:first-of-type { border-top: 0; }
/* The folded-away identifiers: rule ids, record numbers, hashes. In the DOM, off the
 * eye, one click away. */
details.tech, details.why { border-top: 0; padding: 2px 0; font-size: 12px; color: var(--ink-3); }
details.tech summary, details.why summary { display: inline-flex; padding: 2px 0; color: var(--ink-3); font-size: 12px; }
details.why { font-size: 13px; color: var(--ink); }
details.why summary { font-size: 13px; color: var(--ink-2); font-weight: 600; }
details.tech .name, details.tech code { font: 12px/1.5 var(--mono); word-break: break-all; }
details.tech div { margin: 2px 0 0 12px; }
summary { cursor: pointer; padding: 4px 2px; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
summary::marker { color: var(--ink-3); }
summary b { font-size: 13px; }
summary .hint { flex: 1 1 320px; }

.rows li[data-selected="true"] { background: var(--tint-bg); }
/* A 24px target (SC 2.5.8), not the browser's 13px box. */
.rows input[type="checkbox"] { width: 24px; height: 24px; margin: 0 2px 0 0; padding: 2px; flex: none; align-self: center; accent-color: var(--tint); }

/* --- the client's contact line ------------------------------------------ */
.contacts { display: flex; gap: 18px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); margin: -4px 0 10px; }
.contacts b { color: var(--ink); font-weight: 600; }
.chip.matched { color: var(--amber); background: var(--amber-bg); }

/* --- next steps ---------------------------------------------------------- */
.next .actions .btn, .next .actions button { min-height: 36px; }

/* --- print --------------------------------------------------------------- */
/* "Print" is a real route out for a consultant: the draft, the findings and the
 * file note, without the chrome. */
@media print {
  header.top, dialog, #specimen-banner, .actions, .skip, details.tech, button { display: none !important; }
  main { max-width: none; padding: 0; }
  .document { max-height: none; overflow: visible; border: 0; padding: 0; }
  .card, .finding { break-inside: avoid; border-color: #999; }
}

/* --- opening a matter (the queue's two cards) ------------------------------ */
fieldset { border: 1px solid var(--line-2); border-radius: 6px; padding: 6px 10px 8px; margin: 10px 0; }
legend { font-weight: 600; padding: 0 4px; }
label.check { display: flex; gap: 6px; align-items: center; font-weight: 400; margin: 4px 0; }
label.check input { width: 18px; height: 18px; }
form.open-by-number input { max-width: 160px; }
