/* IQI - Imaging Queue Intelligence
   Design language: policy document meets precision instrument.
   Warm paper, ink text, serif display, one accent. WCAG 2.2 AA. */

:root {
  --paper: #f7f5f1;
  --paper-deep: #efece5;
  --ink: #1c2430;
  --muted: #5a6470;
  --line: #d9d4ca;
  --line-strong: #b9b2a4;
  --accent: #0e6a64;
  --accent-ink: #0a4a46;
  --accent-wash: #e3efee;
  --clear-bg: #e2f2e7; --clear-ink: #14532d;
  --cont-bg: #fbf0d9; --cont-ink: #713f12;
  --silent-bg: #f9e3e1; --silent-ink: #7f1d1d;
  --pub-bg: #e3efee; --pub-ink: #0a4a46;
  --der-bg: #e8e6f5; --der-ink: #37306b;
  --ass-bg: #f1e8da; --ass-ink: #6d4a12;
  --serif: Charter, "Iowan Old Style", Georgia, "Times New Roman", serif;
  --sans: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", Consolas, "Courier New", monospace;
  --max: 1180px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 1rem/1.65 var(--sans);
  -webkit-font-smoothing: antialiased;
}

/* ---------- skip link ---------- */
.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--ink); color: #fff; padding: .7rem 1.1rem; z-index: 100;
  font-weight: 600; text-decoration: none;
}
.skip-link:focus { left: .5rem; top: .5rem; }

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

/* ---------- masthead ---------- */
.masthead {
  border-bottom: 3px solid var(--ink);
  background: var(--paper);
}
.masthead-inner {
  max-width: var(--max); margin: 0 auto; padding: 1.4rem 1.5rem 1.1rem;
  display: flex; align-items: flex-end; gap: 1.2rem; flex-wrap: wrap;
}
.masthead img { height: 52px; width: auto; display: block; }
.masthead .titles { flex: 1 1 320px; min-width: 260px; }
.masthead h1 {
  font-family: var(--serif); font-size: clamp(1.5rem, 3.2vw, 2.15rem);
  line-height: 1.12; margin: 0; letter-spacing: -0.01em; font-weight: 650;
}
.masthead .org {
  font-size: .82rem; text-transform: uppercase; letter-spacing: .14em;
  color: var(--muted); font-weight: 600; margin: 0 0 .25rem;
}
.boundaries-strip {
  max-width: var(--max); margin: 0 auto; padding: 0 1.5rem .9rem;
}
.boundaries-strip p {
  margin: 0; font-size: .88rem; color: var(--accent-ink);
  background: var(--accent-wash); border: 1px solid var(--accent);
  border-left-width: 5px; padding: .55rem .85rem; font-weight: 600;
}

/* ---------- layout ---------- */
.shell {
  max-width: var(--max); margin: 0 auto;
  display: grid; grid-template-columns: 220px minmax(0, 1fr);
  gap: 0 2.2rem; padding: 0 1.5rem;
}
@media (max-width: 880px) {
  .shell { grid-template-columns: 1fr; gap: 0; }
}

/* ---------- nav (ARIA tabs) ---------- */
nav[role="tablist"] { position: sticky; top: 0; align-self: start; padding: 1.6rem 0 2rem; }
@media (max-width: 880px) {
  nav[role="tablist"] {
    position: static; display: flex; overflow-x: auto; gap: .2rem;
    padding: .8rem 0; border-bottom: 1px solid var(--line);
  }
}
nav[role="tablist"] button {
  display: block; width: 100%; text-align: left;
  background: none; border: 0; border-left: 4px solid transparent;
  padding: .62rem .8rem; font: 600 .95rem/1.3 var(--sans); color: var(--muted);
  cursor: pointer; min-height: 44px;
}
@media (max-width: 880px) {
  nav[role="tablist"] button { width: auto; border-left: 0; border-bottom: 4px solid transparent; white-space: nowrap; }
}
nav[role="tablist"] button:hover { color: var(--ink); }
nav[role="tablist"] button[aria-selected="true"] {
  color: var(--accent-ink); border-left-color: var(--accent);
  background: var(--accent-wash);
}
@media (max-width: 880px) {
  nav[role="tablist"] button[aria-selected="true"] { border-left-color: transparent; border-bottom-color: var(--accent); }
}
nav[role="tablist"] button .n {
  font-family: var(--mono); font-size: .72rem; color: var(--line-strong);
  display: block; letter-spacing: .08em;
}

main { padding: 1.6rem 0 3rem; min-width: 0; }
section[role="tabpanel"][hidden] { display: none; }

/* ---------- typography ---------- */
h2 {
  font-family: var(--serif); font-size: 1.62rem; line-height: 1.22;
  margin: 0 0 .3rem; letter-spacing: -0.01em; font-weight: 650;
}
.lede { font-size: 1.06rem; color: var(--muted); margin: 0 0 1.4rem; max-width: 62ch; }
h3 { font-family: var(--serif); font-size: 1.18rem; margin: 2rem 0 .4rem; }
.kicker {
  font-size: .74rem; font-weight: 700; letter-spacing: .16em; text-transform: uppercase;
  color: var(--accent-ink); margin: 2.2rem 0 .4rem;
}
p { max-width: 70ch; }
.note { font-size: .88rem; color: var(--muted); }
.serif-quote {
  font-family: var(--serif); font-size: 1.12rem; line-height: 1.5;
  border-left: 4px solid var(--accent); margin: 1.2rem 0; padding: .3rem 0 .3rem 1.1rem;
  max-width: 66ch;
}

/* ---------- panels & cards ---------- */
.panel {
  background: #fffdf9; border: 1px solid var(--line); padding: 1.2rem 1.3rem;
  margin: 1.1rem 0;
}
.panel.accent { border-left: 5px solid var(--accent); background: var(--accent-wash); }
.grid { display: grid; gap: .9rem; }
.grid.cols3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid.cols2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.stat {
  background: #fffdf9; border: 1px solid var(--line); border-top: 4px solid var(--accent);
  padding: .9rem 1rem .8rem;
}
.stat .v { font-family: var(--serif); font-size: 2rem; font-weight: 650; line-height: 1.05; font-variant-numeric: tabular-nums; }
.stat .l { font-size: .84rem; color: var(--muted); margin-top: .15rem; }
.stat.warn { border-top-color: var(--silent-ink); }
.stat.warn .v { color: var(--silent-ink); }

/* ---------- badges: text + glyph, never colour alone ---------- */
.badge {
  display: inline-flex; align-items: center; gap: .38rem;
  padding: .1rem .55rem .1rem .4rem; font-size: .8rem; font-weight: 700;
  white-space: nowrap;
}
.badge .glyph { width: .72rem; height: .72rem; flex: none; display: inline-block; }
.b-clear { background: var(--clear-bg); color: var(--clear-ink); }
.b-clear .glyph { background: var(--clear-ink); }
.b-contested { background: var(--cont-bg); color: var(--cont-ink); }
.b-contested .glyph {
  background: linear-gradient(90deg, var(--cont-ink) 50%, transparent 50%);
  border: 1.5px solid var(--cont-ink); box-sizing: border-box;
}
.b-silent { background: var(--silent-bg); color: var(--silent-ink); }
.b-silent .glyph { border: 1.5px solid var(--silent-ink); box-sizing: border-box; }
.b-published { background: var(--pub-bg); color: var(--pub-ink); }
.b-derived { background: var(--der-bg); color: var(--der-ink); }
.b-assumption { background: var(--ass-bg); color: var(--ass-ink); }
.b-open { background: var(--silent-bg); color: var(--silent-ink); }
.b-closed { background: var(--clear-bg); color: var(--clear-ink); }
.b-verified { background: var(--clear-bg); color: var(--clear-ink); }
.b-unverified { background: var(--cont-bg); color: var(--cont-ink); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 1rem 0 1.4rem; border: 1px solid var(--line); }
table { border-collapse: collapse; width: 100%; font-size: .9rem; background: #fffdf9; }
caption {
  caption-side: top; text-align: left; font-weight: 700; font-size: .9rem;
  padding: .6rem .2rem .4rem; color: var(--ink);
}
th, td { border: 1px solid var(--line); padding: .5rem .65rem; text-align: left; vertical-align: top; }
thead th { background: var(--paper-deep); font-size: .8rem; letter-spacing: .03em; }
tbody tr:nth-child(even) { background: #f6f4ef; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
thead th[scope="col"] { position: sticky; top: 0; }

/* ---------- forms ---------- */
form .fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: .8rem 1.1rem; }
.field label { display: block; font-weight: 600; font-size: .86rem; margin-bottom: .25rem; }
.field .src { display: block; font-weight: 400; font-size: .74rem; color: var(--muted); margin-top: .15rem; }
.field input[type="number"] {
  width: 100%; padding: .5rem .6rem; font: 1rem var(--sans);
  border: 1.5px solid var(--line-strong); background: #fff; color: var(--ink);
  border-radius: 2px; min-height: 44px; font-variant-numeric: tabular-nums;
}
button.primary {
  background: var(--accent); color: #fff; border: 0; padding: .7rem 1.5rem;
  font: 700 .98rem var(--sans); cursor: pointer; border-radius: 2px; min-height: 44px;
}
button.primary:hover { background: var(--accent-ink); }
button.secondary {
  background: #fff; color: var(--accent-ink); border: 1.5px solid var(--accent);
  padding: .5rem 1rem; font: 600 .9rem var(--sans); cursor: pointer; border-radius: 2px; min-height: 44px;
}
button.secondary[aria-pressed="true"] { background: var(--accent-wash); border-width: 2px; }
.buttonrow { display: flex; gap: .6rem; flex-wrap: wrap; margin: .8rem 0; }

/* ---------- details / accordion ---------- */
details { border: 1px solid var(--line); background: #fffdf9; margin: .5rem 0; }
details summary {
  cursor: pointer; padding: .7rem .9rem; font-weight: 700; font-size: .93rem;
  min-height: 44px; display: flex; align-items: center;
}
details[open] summary { border-bottom: 1px solid var(--line); }
details .inner { padding: .8rem 1rem; }
details .inner p { margin: .4rem 0; font-size: .9rem; }
details .inner .clause {
  font-family: var(--serif); font-size: .95rem; border-left: 3px solid var(--line-strong);
  padding-left: .9rem; margin: .6rem 0;
}

/* ---------- simulator results ---------- */
#sim-status { margin: .8rem 0; font-weight: 600; }
.spinner {
  display: inline-block; width: 1rem; height: 1rem; border: 3px solid var(--line);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 1s linear infinite; vertical-align: -2px; margin-right: .4rem;
}
@keyframes spin { to { transform: rotate(360deg); } }
.chart { width: 100%; height: auto; display: block; margin: 1rem 0; }
.chart .bar-tp { fill: var(--accent); }
.chart .bar-rtn { fill: #b08968; }
.chart text { font: 12px var(--sans); fill: var(--ink); }
.chart .tick { stroke: var(--line-strong); }
.iv { color: var(--muted); font-size: .78rem; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- governance steps ---------- */
ol.steps { list-style: none; margin: 1rem 0; padding: 0; counter-reset: step; }
ol.steps li {
  border: 1px solid var(--line); border-left: 5px solid var(--line-strong);
  background: #fffdf9; padding: .75rem 1rem; margin-bottom: .55rem; counter-increment: step;
}
ol.steps li::before {
  content: counter(step, decimal-leading-zero);
  font-family: var(--mono); font-size: .74rem; color: var(--muted); display: block;
}
ol.steps li .name { font-weight: 700; display: block; margin: .1rem 0 .2rem; }
ol.steps li .meta { font-size: .85rem; color: var(--muted); display: block; }

/* ---------- footer ---------- */
footer.site {
  border-top: 3px solid var(--ink); margin-top: 3rem; background: var(--paper-deep);
}
footer.site .inner {
  max-width: var(--max); margin: 0 auto; padding: 1.6rem 1.5rem 2.2rem;
}
footer.site h2 { font-size: 1.1rem; }
footer.site p { font-size: .86rem; color: var(--muted); }
footer.site img { height: 34px; opacity: .85; }
.no-patient {
  font-family: var(--serif); font-size: 1.02rem; color: var(--ink);
  border-left: 4px solid var(--accent); padding-left: 1rem; margin: 1rem 0;
}

/* a11y helpers */
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; margin: -1px;
}
@media print {
  nav[role="tablist"] { display: none; }
  .shell { grid-template-columns: 1fr; }
  section[role="tabpanel"][hidden] { display: block !important; }
}
@media (forced-colors: active) {
  .badge { border: 1px solid CanvasText; }
  .stat { border: 1px solid CanvasText; }
}