/*
 * A utility-light stylesheet, hand-written (plan §7.4: no design system).
 *
 * The one place design carries weight is the coverage pill. Coverage is four-valued, and a
 * reader who takes `covered_subject_to_conditions` for `covered` has made the mistake the
 * whole system exists to prevent — so the conditional status is amber and visually distinct
 * from the green, never a lighter shade of it.
 */

:root {
  --ink: #16181d;
  --muted: #5f6672;
  --line: #dfe3e9;
  --bg: #fbfbfc;
  --panel: #ffffff;
  --accent: #1f4e79;
  --accent-soft: #eaf1f8;

  --covered: #1a7f45;
  --covered-bg: #e8f5ee;
  --conditions: #9a6205;
  --conditions-bg: #fdf3e1;
  --not-covered: #a32020;
  --not-covered-bg: #fbeaea;
  --unknown: #5f6672;
  --unknown-bg: #eef0f3;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.92em; }

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

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; height: 52px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 650; letter-spacing: -0.01em; color: var(--accent); text-decoration: none; font-size: 17px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.who { color: var(--muted); font-size: 14px; }

.shell { display: grid; grid-template-columns: 208px 1fr; min-height: calc(100vh - 52px); }
.sidebar { border-right: 1px solid var(--line); background: var(--panel); padding: 14px 0; }
.sidebar a {
  display: block; padding: 7px 20px; color: var(--ink); text-decoration: none; font-size: 14px;
  border-left: 3px solid transparent;
}
.sidebar a:hover { background: var(--bg); }
.sidebar a.active { border-left-color: var(--accent); background: var(--accent-soft); font-weight: 550; }

main { padding: 26px 30px 60px; max-width: 1180px; }
main.centred { max-width: 460px; margin: 8vh auto; padding: 0 20px; }

h1 { font-size: 24px; margin: 0 0 6px; letter-spacing: -0.015em; }
h2 { font-size: 17px; margin: 32px 0 10px; letter-spacing: -0.01em; }
h3 { font-size: 15px; margin: 0 0 6px; }
.lede { font-size: 16px; color: var(--muted); max-width: 62ch; margin: 0 0 24px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
p { max-width: 78ch; }

/* ---------------------------------------------------------------- blocks */

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 18px 20px; margin: 14px 0; max-width: 640px;
}
.card.narrow { max-width: 100%; }
a.card.link { display: block; text-decoration: none; color: inherit; max-width: none; }
a.card.link:hover { border-color: var(--accent); }
a.card.link p { color: var(--muted); font-size: 14px; margin: 0; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin-top: 20px; }

.banner { padding: 10px 14px; border-radius: 6px; margin-bottom: 18px; font-size: 14px; overflow-wrap: anywhere; }
.banner.info { background: var(--accent-soft); border: 1px solid #c3d7ea; }
.banner.error { background: var(--not-covered-bg); border: 1px solid #f0c3c3; }
.banner.success { background: var(--covered-bg); border: 1px solid #bfe3ce; }

/* Per-user spend, on the Users screen: the limits and the boxes that set them, compact enough
   to live in a table cell. */
.budget-form { display: flex; gap: 6px; align-items: center; margin-top: 4px; }
.budget-form input { width: 78px; margin: 0; padding: 4px 6px; font-size: 12.5px; }
.budget-form button { padding: 4px 8px; font-size: 12.5px; }
.spend-blocked { color: var(--not-covered); font-weight: 550; }

/* Column filters: a plain GET form, so they bookmark and survive a reload. Laid out as one
   row of small fields that wraps, rather than a panel, so the table stays the page. */
.filters {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 14px;
  padding: 12px 14px; margin: 14px 0 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
}
.filters label { margin: 0; font-size: 12.5px; }
.filters input, .filters select { margin-top: 3px; padding: 5px 8px; font-size: 13.5px; min-width: 150px; }
.filters input[type="date"] { min-width: 140px; }
.filters-actions { display: flex; align-items: center; gap: 12px; margin-left: auto; }

/* The Explain dialog: online help, so it reads as an aside to the record rather than as part
   of it — inset, quieter, and carrying its disclaimer where it cannot be missed. */
/* The island's wrapper element is taken out of the layout so the button sits in the sentence
   that introduces it, and the panel it opens still lays out as a block. */
.explain-intro > [data-island] { display: contents; }
.explain-open { font-weight: 550; }
.explain {
  border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px;
  background: var(--panel); margin: 10px 0 18px; max-width: 780px;
}
.explain-head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 10px 14px; border-bottom: 1px solid var(--line);
}
.explain-body { padding: 12px 14px; max-height: 460px; overflow-y: auto; }
.explain-turn { margin-bottom: 12px; font-size: 14px; }
.explain-turn p { margin: 0 0 8px; max-width: 68ch; }
.explain-turn p:last-child { margin-bottom: 0; }
.explain-thinking { font-size: 14px; margin-bottom: 12px; }
.explain-turn.user {
  color: var(--muted); border-left: 2px solid var(--line); padding-left: 10px; font-style: italic;
}
.explain-suggestions {
  display: flex; flex-wrap: wrap; gap: 10px; padding: 0 14px 10px; border-top: 1px solid var(--line);
  padding-top: 10px;
}
.explain-ask { display: flex; gap: 8px; padding: 0 14px 12px; }
.explain-ask input { flex: 1; }
.explain-disclaimer {
  margin: 0; padding: 10px 14px; border-top: 1px solid var(--line);
  background: var(--bg); color: var(--muted); border-radius: 0 0 8px 8px; max-width: none;
}

/* A carve-out the registered facts say describes this counterparty. The one check on the list
   that is not a check but a finding, so it does not look like the others. */
.engaged-carveout {
  background: var(--not-covered-bg); border: 1px solid #f0c3c3; border-radius: 6px;
  padding: 8px 10px; margin: 0 0 8px;
}
.engaged-carveout .muted { margin-top: 4px; }

/* Which build is running: findable when someone asks, invisible until then. */
.build-stamp { margin-top: 28px; font-size: 12px; opacity: 0.65; }
.build-stamp code { font-size: 12px; background: none; padding: 0; }

.disclaimer {
  border-top: 1px solid var(--line); padding: 14px 30px; color: var(--muted);
  font-size: 12.5px; background: var(--panel);
}

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

table { border-collapse: collapse; width: 100%; margin: 10px 0 4px; font-size: 14px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.04em; }
tbody tr:hover { background: var(--panel); }

dl.fields { display: grid; grid-template-columns: max-content 1fr; gap: 5px 18px; margin: 12px 0; font-size: 14px; }
dl.fields dt { color: var(--muted); }
dl.fields dd { margin: 0; }

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

label { display: block; margin: 0 0 12px; font-size: 13.5px; color: var(--muted); }
fieldset { border: 1px solid var(--line); border-radius: 5px; margin: 0 0 12px; padding: 8px 12px; }
fieldset legend { font-size: 13.5px; color: var(--muted); padding: 0 4px; }
label.inline { display: inline-flex; align-items: center; gap: 6px; margin: 0 14px 4px 0; }
label.inline input[type="checkbox"] { display: inline-block; width: auto; margin: 0; }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 7px 9px;
  font: inherit; color: var(--ink);
  border: 1px solid var(--line); border-radius: 5px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { min-height: 90px; resize: vertical; }

button {
  font: inherit; font-size: 14px; padding: 7px 14px; border-radius: 5px; cursor: pointer;
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
}
button:hover { filter: brightness(1.08); }
button[disabled] { opacity: 0.45; cursor: not-allowed; }
button.danger { background: #fff; color: var(--not-covered); border-color: #e2b6b6; }
button.linkish { background: none; border: none; color: var(--muted); padding: 0; text-decoration: underline; }

form.inline { display: inline; }
form.inline.actions { display: inline-flex; gap: 5px; flex-wrap: wrap; }
form.inline button { padding: 3px 8px; font-size: 12.5px; }
form.filters { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin: 14px 0; }
form.filters label { margin: 0; }
form.filters input { width: 190px; }

/* ---------------------------------------------------------------- pills */

.pill {
  display: inline-block; padding: 1px 8px; border-radius: 10px;
  font-size: 12px; font-weight: 550; white-space: nowrap;
  background: var(--unknown-bg); color: var(--unknown);
}
.pill.covered, .pill.active, .pill.approved, .pill.signed_off { background: var(--covered-bg); color: var(--covered); }
.pill.draft { background: var(--unknown-bg); color: var(--unknown); }
/* Amber, not a paler green: mistaking this for `covered` is the error that matters. */
.pill.covered_subject_to_conditions,
.pill.covered_with_qualification,
.pill.invited { background: var(--conditions-bg); color: var(--conditions); }
.pill.not_covered, .pill.deactivated { background: var(--not-covered-bg); color: var(--not-covered); }
.pill.not_addressed, .pill.undetermined { background: var(--unknown-bg); color: var(--unknown); }

.tag {
  display: inline-block; padding: 0 6px; border-radius: 3px; font-size: 11.5px;
  background: var(--accent-soft); color: var(--accent); border: 1px solid #cfdff0;
}

details { margin: 14px 0; }
summary { cursor: pointer; color: var(--accent); font-size: 14px; }

/* ---------------------------------------------------------------- islands */

kbd {
  font: 11px ui-monospace, monospace; padding: 1px 4px; border-radius: 3px;
  border: 1px solid var(--line); background: var(--bg);
}

.review-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.review-body { display: grid; grid-template-columns: 300px 1fr; gap: 20px; align-items: start; }

.review-list { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--panel); }
.review-item {
  display: block; width: 100%; text-align: left; padding: 7px 10px; font-size: 13px;
  background: none; border: none; border-bottom: 1px solid var(--line); color: var(--ink);
  border-radius: 0; cursor: pointer;
}
.review-item:hover { background: var(--bg); }
.review-item.active { background: var(--accent-soft); }
.review-item.decided { opacity: 0.5; }
.review-item-name { display: block; margin-top: 2px; }

.review-detail { border: 1px solid var(--line); border-radius: 8px; padding: 18px 20px; background: var(--panel); }
.review-status-row { display: flex; gap: 12px; align-items: center; margin: 8px 0 16px; }
.review-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line); }

.quote { margin: 12px 0; }
.quote blockquote {
  margin: 0; padding: 8px 12px; border-left: 3px solid var(--accent);
  background: var(--bg); font-size: 14px;
}
.quote figcaption { margin-top: 3px; }

/* The reviewer draws a rectangle over a server-rendered page image — no PDF in the browser. */
.raster { position: relative; display: inline-block; max-width: 100%; margin-top: 8px; }
.raster img { max-width: 100%; border: 1px solid var(--line); }
.highlight { position: absolute; background: rgba(255, 214, 0, 0.35); outline: 2px solid #d9a300; pointer-events: none; }

.matrix-controls { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin: 14px 0; }
.matrix-controls input { width: 320px; margin: 0; }
.matrix-counts { display: flex; gap: 6px; flex-wrap: wrap; }
.matrix-counts .pill { cursor: pointer; border: 1px solid transparent; }
.matrix-counts .pill.selected { border-color: currentColor; }
.matrix-table tbody tr { cursor: pointer; }
.matrix-table tbody tr.selected { background: var(--accent-soft); }
.tag.warn { background: var(--conditions-bg); color: var(--conditions); border-color: #e8ce9a; }

pre { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 12px; overflow-x: auto; }

.workbench .card { max-width: 780px; }
/* The two acts are numbered, and the numbering is the instruction. */
.workbench .card h3 { margin: 0 0 4px; font-size: 15px; }
.workbench .card h4 { margin: 18px 0 4px; font-size: 14px; color: var(--muted); }
.workbench .card > p:first-of-type { margin-top: 0; }
.workbench .card table { font-size: 13px; }
ul.progress { list-style: none; padding: 0; margin: 0; font-size: 13.5px; }
ul.progress li { padding: 3px 0; border-bottom: 1px solid var(--line); }
ul.progress li.done { color: var(--covered); font-weight: 550; }
ul.progress li.error { color: var(--not-covered); }

/* ---------------------------------------------------------------- review filters */
.review-filters { display: grid; gap: 6px; margin-bottom: 10px; }
.review-filters select { width: 100%; }

/* ---------------------------------------------------------------- segmented toggle */
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.segmented label {
  display: inline-flex; align-items: center; gap: 5px; margin: 0; padding: 3px 10px;
  font-size: 12.5px; cursor: pointer; color: var(--muted); background: var(--panel);
}
.segmented label + label { border-left: 1px solid var(--line); }
.segmented label:has(input:checked) { background: var(--accent-soft); color: var(--accent); font-weight: 550; }
.segmented input[type="radio"] { display: none; width: auto; margin: 0; }

/* Multi-column key–value layout for tall detail pages. */
dl.fields.cols2 { grid-template-columns: repeat(2, max-content 1fr); }
dl.fields.cols3 { grid-template-columns: repeat(3, max-content 1fr); }
dl.fields dd { overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- tabs */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--line); margin: 22px 0 14px; }
.tabs button {
  background: none; border: none; border-bottom: 2px solid transparent; margin-bottom: -2px;
  color: var(--muted); font-size: 15px; padding: 8px 16px; cursor: pointer; border-radius: 0;
}
.tabs button:hover { color: var(--ink); filter: none; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* ---------------------------------------------------------------- the graph window */

main.chromeless { max-width: none; padding: 0; height: 100vh; }

.graph-wrap { position: relative; display: flex; flex-direction: column; height: 100vh; }
.graph-bar {
  display: flex; justify-content: space-between; align-items: baseline; gap: 16px;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.graph-actions { display: flex; gap: 14px; white-space: nowrap; }
.graph-legend {
  display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 8px 16px;
  border-bottom: 1px solid var(--line); background: var(--bg); font-size: 12.5px;
}
.graph-key {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: none; padding: 2px 4px; color: var(--ink); cursor: pointer;
  border-radius: 4px; font-size: 12.5px;
}
.graph-key:hover { background: var(--accent-soft); }
.graph-key.off { opacity: 0.4; text-decoration: line-through; }

.graph-canvas { flex: 1; width: 100%; background: var(--bg); touch-action: none; cursor: grab; }
.graph-canvas:active { cursor: grabbing; }

.graph-node { cursor: grab; }
.graph-node.clickable { cursor: pointer; }
.graph-node.dim { opacity: 0.12; }
.graph-edge.dim { opacity: 0.06; }
.graph-label {
  font-size: 11px; fill: var(--ink); paint-order: stroke;
  stroke: var(--bg); stroke-width: 3px; stroke-linejoin: round;
}
.graph-node.dim .graph-label { opacity: 0.4; }

/* The tooltip is a div, not an SVG title: it appears immediately and can hold a quote. */
.graph-tip {
  position: absolute; z-index: 20; max-width: 460px; pointer-events: none;
  background: rgba(17, 24, 33, 0.95); color: #fff; border-radius: 6px;
  padding: 8px 11px; font-size: 12.5px; line-height: 1.45;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.28); white-space: pre-wrap;
}
.graph-tip strong { display: block; margin-bottom: 4px; }
