/* ============================================================
   The instrument — an app shell on top of system.css.
   Fixed chrome (view switch + territory filter + live readout),
   a color-coded pipeline board, and a right-rail inspector that
   stays visible as you click through referrals.

   The metric tiles are gone. Counts live where the work is:
   folded into the app-bar readout and onto the board columns.
   Same pathway color spine as the brief.
   ============================================================ */

/* ---- Utilities ---------------------------------------------- */
.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; }
.skip { position: absolute; left: 8px; top: -60px; z-index: 60; background: var(--ink); color: var(--paper);
  padding: 9px 16px; font-size: 13px; font-weight: 500; text-decoration: none; transition: top 120ms var(--ease); }
.skip:focus { top: 8px; }

/* ---- App chrome (sticky) ------------------------------------ */
.appchrome { position: sticky; top: 0; z-index: 40; background: var(--paper); }

.appbar { border-bottom: 2px solid var(--ink); }
.appbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 24px;
  padding: 12px var(--gut); max-width: var(--maxw); margin: 0 auto; }
.appbar-l { display: flex; align-items: baseline; gap: 16px; min-width: 0; }
.appbar-l .navback { padding-left: 16px; border-left: 1px solid var(--rule); }

/* segmented view control — obviously switchable */
.segmented { display: inline-flex; border: 1px solid var(--ink); flex-shrink: 0; }
.seg { padding: 8px 18px; font-size: 13px; font-weight: 500; color: var(--ink-2); white-space: nowrap; }
.seg + .seg { border-left: 1px solid var(--ink); }
.seg:hover { background: var(--paper-2); }
.seg.on { background: var(--ink); color: var(--paper); }
.seg.on:hover { background: var(--ink); }

/* live readout — the folded metrics, as text not tiles */
.readout { display: flex; align-items: baseline; gap: 18px; font-size: 12.5px; color: var(--ink-2);
  font-variant-numeric: tabular-nums; white-space: nowrap; }
.readout .ro b { font-weight: 600; font-size: 16px; color: var(--ink); letter-spacing: -0.02em; margin-right: 5px; }
.readout .ro.seam b { color: var(--seam); }
.readout .ro.treat b { color: var(--accent); }

/* control bar — territory filter + scope */
.controlbar { border-bottom: 1px solid var(--rule); background: var(--paper); }
.cb-inner { display: flex; align-items: center; justify-content: space-between; gap: 20px;
  padding: 10px var(--gut); max-width: var(--maxw); margin: 0 auto; flex-wrap: wrap; }
.regions { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.rlab { font-size: 11.5px; color: var(--ink-3); margin-right: 5px; }
.rg { font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--ink-2);
  padding: 4px 10px; border: 1px solid var(--rule); line-height: 1; }
.rg:hover { border-color: var(--ink-2); color: var(--ink); }
.rg.on { color: var(--paper); background: var(--accent); border-color: var(--accent); }
.scope { font-size: 12px; color: var(--ink-2); }
.scope b { font-weight: 500; color: var(--ink); }

/* ---- Workspace: board + inspector rail ---------------------- */
main.workspace-wrap { display: block; padding-top: 22px; }
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 40px; align-items: start; }

/* view header: compact strip, shared by the board and funnel views */
.viewhead { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px;
  padding-bottom: 15px; margin-bottom: 18px; border-bottom: 1px solid var(--rule); }
.vh-eyebrow { font-size: 11px; font-weight: 500; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-3); margin-bottom: 8px; }
.vh-eyebrow .vh-scope { color: var(--ink); font-weight: 600; }
.vh-line { font-size: 15px; line-height: 1.45; color: var(--ink-2); max-width: 66ch; text-wrap: pretty; }
.vh-note { font-size: 11px; font-weight: 500; letter-spacing: 0.05em; color: var(--ink-3);
  white-space: nowrap; padding-bottom: 3px; }
.vh-note.alarm { color: var(--seam); }

/* board: three stations, the seam gutter, the certified center */
.board { display: grid; grid-template-columns: 1fr 1fr 1fr 34px 1fr; border-top: 1px solid var(--ink); }
.col { position: relative; border-right: 1px solid var(--rule); border-top: 3px solid var(--bar, var(--rule));
  min-width: 0; --cardhover: var(--paper-2); }
.col.last { border-right: 0; }
.col.s1 { --bar: var(--st1); --hue: var(--st1); --cardhover: var(--st1-wash); }
.col.s2 { --bar: var(--st2); --hue: var(--st2); --cardhover: var(--st2-wash); }
.col.s3 { --bar: var(--st3); --hue: var(--st3); --cardhover: var(--st3-wash); }
.col.last { --bar: var(--st4); --hue: var(--st4); --cardhover: var(--st4-wash); }
.colhead { background: linear-gradient(color-mix(in srgb, var(--cardhover) 80%, transparent), transparent);
  padding: 12px 14px 10px; }
.colhead .crow { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.colhead .ck { font-family: "IBM Plex Mono", monospace; font-size: 11px; font-weight: 500; color: var(--hue, var(--ink-3)); }
.colhead .ccount { font-family: "IBM Plex Mono", monospace; font-size: 15px; font-weight: 600;
  color: var(--hue, var(--ink)); font-variant-numeric: tabular-nums; }
.colhead .cname { font-size: 15px; font-weight: 600; letter-spacing: -0.02em; margin-top: 5px; color: var(--ink); }
.colhead .cnote { font-family: "Newsreader", serif; font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.colbody { padding: 6px 8px 26px; }

/* the seam gutter — rust, same device as the brief */
.seamcol { position: relative; border-top: 3px solid var(--seam);
  background: linear-gradient(var(--seam-wash), transparent 140px); }
.seamcol::before, .seamcol::after { content: ""; position: absolute; top: 0; bottom: 26px; width: 1px;
  background: repeating-linear-gradient(to bottom, var(--seam) 0 3px, transparent 3px 8px); }
.seamcol::before { left: 0; } .seamcol::after { right: 0; }
.seamlab { position: absolute; top: 84px; left: 50%; transform: translateX(-50%);
  writing-mode: vertical-rl; text-orientation: mixed;
  font-family: "Newsreader", serif; font-style: italic; font-size: 15px; color: var(--seam); white-space: nowrap; }

/* ---- Cards: clearly clickable ------------------------------- */
/* Each card holds two real buttons as siblings, never nested: a
   full-bleed face button (cface) that selects the referral, and the
   Advance button floating above it. Keyboard and touch both work,
   and there is no interactive-inside-interactive markup. */
.card { position: relative; width: 100%; text-align: left; display: block;
  padding: 9px 22px 10px 10px; border-bottom: 1px solid var(--rule-2);
  transition: background 120ms var(--ease); }
.cface { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1;
  background: transparent; border: 0; padding: 0; margin: 0; cursor: pointer; }
.cface:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.card::after { content: "\203A"; position: absolute; right: 9px; top: 9px; z-index: 3;
  pointer-events: none; font-size: 15px; color: var(--ink-3); opacity: 0; transition: opacity 120ms; }
.card:hover { background: var(--cardhover); }
.card:hover::after { opacity: 1; }
.card.sel { background: var(--cardhover); box-shadow: inset 3px 0 0 var(--accent); }
.card.sel::after { opacity: 1; color: var(--accent); }
.cardtop { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; line-height: 1.2; }
.cid { font-family: "IBM Plex Mono", monospace; font-size: 13px; font-weight: 500; }
.card.sel .cid { color: var(--accent); }
.creg { font-family: "IBM Plex Mono", monospace; font-size: 11px; color: var(--ink-3); }
.cardsub { font-size: 12.5px; line-height: 1.3; color: var(--ink-2); margin-top: 3px; }
.cardsub .st3 { color: var(--accent); font-weight: 500; }
.cardfoot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 5px; line-height: 1.2; }
.cdays { font-family: "IBM Plex Mono", monospace; font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.card.isstall .cdays { color: var(--seam); font-weight: 600; }
.card.isstall .cid::before { content: ""; display: inline-block; width: 6px; height: 6px;
  background: var(--seam); margin-right: 6px; vertical-align: middle; }
.adv { position: relative; z-index: 2; font-size: 11px; font-weight: 500; color: var(--accent);
  padding: 8px 6px; margin: -8px -6px -8px 0; }
.adv:hover { text-decoration: underline; text-underline-offset: 2px; }
.donetag { font-size: 11px; color: var(--ink-3); }
.empty { font-size: 12px; color: var(--ink-3); padding: 12px 4px; }

/* ---- Inspector rail (selected referral) --------------------- */
.inspector { position: sticky; top: 108px; border: 1px solid var(--rule); background: var(--paper); }
.inhead { padding: 13px 16px; background: var(--st4-wash); border-bottom: 1px solid var(--rule); }
.inhead .rid { font-family: "IBM Plex Mono", monospace; font-size: 17px; font-weight: 600; }
.inhead .rmeta { font-size: 11.5px; color: var(--ink-2); margin-top: 3px; }
.inbody { padding: 16px; }

/* vertical stepper with the seam between 03 and 04 */
.vstep { display: block; }
.vs { display: grid; grid-template-columns: 20px 1fr; gap: 11px; align-items: start;
  padding: 8px 0; position: relative; }
.vs .dot { width: 11px; height: 11px; border-radius: 50%; border: 1.5px solid var(--rule);
  margin-top: 3px; margin-left: 3px; background: var(--paper); }
.vs.done .dot { background: var(--accent-2, #2f7c91); border-color: var(--accent-2, #2f7c91); }
.vs.cur .dot { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 3px var(--st4-wash); }
.vs .vk { font-family: "IBM Plex Mono", monospace; font-size: 11px; color: var(--ink-3); }
.vs .vn { font-size: 13.5px; color: var(--ink-3); line-height: 1.2; margin-top: 1px; }
.vs.done .vn { color: var(--ink-2); }
.vs.cur .vn { color: var(--ink); font-weight: 600; }
.vs .vstat { font-family: "IBM Plex Mono", monospace; font-size: 11px; margin-top: 3px; color: var(--ink-3); }
.vs.done .vstat { color: var(--accent-2, #2f7c91); }
.vs.cur .vstat { color: var(--accent); }
.vsubs { display: flex; gap: 5px; align-items: baseline; margin-top: 6px; flex-wrap: wrap; }
.vsubs .sb { font-family: "IBM Plex Mono", monospace; font-size: 11px; color: var(--ink-3); }
.vsubs .sb.done { color: var(--accent-2, #2f7c91); }
.vsubs .sb.cur { color: var(--accent); font-weight: 600; border-bottom: 1px solid var(--accent); }
.vsubs .sarw { font-size: 11px; color: var(--rule); }
/* the seam divider inside the stepper */
.vseam { display: grid; grid-template-columns: 20px 1fr; gap: 11px; align-items: center; padding: 6px 0; }
.vseam .sline { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px;
  font-family: "Newsreader", serif; font-style: italic; font-size: 12.5px; color: var(--seam); }
.vseam .sline::before, .vseam .sline::after { content: ""; height: 1px; flex: 1;
  background: repeating-linear-gradient(to right, var(--seam) 0 3px, transparent 3px 7px); }

.instat { display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--rule); }
.instat .dd { font-family: "IBM Plex Mono", monospace; font-size: 11.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.instat .ok { font-size: 11.5px; font-weight: 500; color: var(--accent-2, #2f7c91); }
.instat .bad { font-size: 11.5px; font-weight: 600; color: var(--seam); }
.nalab { font-size: 11px; color: var(--ink-3); margin-top: 14px; text-transform: uppercase; letter-spacing: 0.06em; }
.na { font-family: "Newsreader", serif; font-size: 15.5px; line-height: 1.42; margin-top: 6px; text-wrap: pretty; color: var(--ink); }
.inbtns { display: flex; flex-direction: column; gap: 9px; margin-top: 18px; }
.btn { font-size: 13px; font-weight: 500; padding: 10px 16px; border: 1px solid var(--ink); color: var(--ink); text-align: center; }
.btn:hover { background: var(--ink); color: var(--paper); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--paper); }
.btn.primary:hover { background: var(--accent-dk); }
.btn[disabled] { border-color: var(--rule); color: var(--ink-3); cursor: default; }
.btn[disabled]:hover { background: none; color: var(--ink-3); }
.inempty { padding: 30px 16px; font-family: "Newsreader", serif; font-size: 15px; color: var(--ink-2); line-height: 1.45; }

/* ---- Funnel view -------------------------------------------- */
.funnel { padding-top: 6px; }
.fbars { display: grid; grid-template-columns: repeat(3, 1fr); gap: 40px;
  margin-top: 28px; padding-top: 18px; border-top: 2px solid var(--ink); }
.fbar .fl { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.fbar .fn { font-weight: 600; font-size: 38px; letter-spacing: -0.045em; line-height: 1; font-variant-numeric: tabular-nums; }
.fbar.b-eval .fn { color: var(--st3); }
.fbar.b-treat .fn { color: var(--accent); }
.fbar .fc { font-family: "IBM Plex Mono", monospace; font-size: 11px; color: var(--ink-2); }
.fbar .ftrack { height: 7px; background: var(--paper-2); margin-top: 12px; }
.fbar .ffill { height: 7px; background: var(--ink); transition: width 320ms var(--ease); }
.fbar.b-eval .ffill { background: var(--st3); }
.fbar.b-treat .ffill { background: var(--accent); }
.fbar .flab { font-size: 12.5px; color: var(--ink-2); margin-top: 10px; max-width: 30ch; }

.ftablewrap { margin-top: 40px; overflow-x: auto; }
.ftable { width: 100%; border-collapse: collapse; font-size: 13px; }
.ftable th { text-align: right; font-weight: 500; font-size: 11.5px; color: var(--ink-2);
  padding: 0 0 9px; border-bottom: 1px solid var(--ink); white-space: nowrap; }
.ftable th:first-child, .ftable td:first-child { text-align: left; }
.ftable td { text-align: right; padding: 10px 0; border-bottom: 1px solid var(--rule);
  font-variant-numeric: tabular-nums; color: var(--ink-2); }
.ftable td:first-child { color: var(--ink); }
.ftable th + th, .ftable td + td { padding-left: 18px; }
.ftable tbody tr { cursor: pointer; }
.ftable tbody tr:hover td { background: var(--paper-2); }
.ftable tbody tr.sel td { background: var(--st4-wash); color: var(--ink); }
.ftable tbody tr.sel td:first-child { color: var(--accent); font-weight: 500; }
.ftable td.pc { font-family: "IBM Plex Mono", monospace; font-size: 12px; }
.ftable tbody tr.weak td.last { color: var(--seam); font-weight: 600; }
.flagmark { color: var(--seam); font-weight: 700; font-size: 11px; }
.fnote { font-size: 12px; color: var(--ink-2); margin-top: 14px; max-width: 76ch; line-height: 1.5; }

/* ---- Responsive --------------------------------------------- */
@media (max-width: 1080px) {
  .workspace { grid-template-columns: 1fr; gap: 26px; }
  .inspector { position: static; }
  /* keep the live readout — it is the point of the tool — as a full-width strip
     instead of hiding it; it drops to its own row under the view switch */
  .appbar-inner { flex-wrap: wrap; }
  .appbar-l { order: 1; } .segmented { order: 2; }
  .readout { order: 3; flex-basis: 100%; flex-wrap: wrap; white-space: normal;
    gap: 8px 16px; margin-top: 4px; padding-top: 9px; border-top: 1px solid var(--rule-2); }
  .readout .ro { white-space: nowrap; }
  .readout .ro b { font-size: 15px; }
}
@media (max-width: 720px) {
  .board { grid-template-columns: 1fr; }
  .col { border-right: 0; border-bottom: 1px solid var(--rule); }
  .seamcol { min-height: 50px; border-bottom: 1px solid var(--rule); }
  .seamcol::before { left: 0; } .seamcol::after { left: 22px; right: auto; }
  .seamlab { position: static; transform: none; writing-mode: horizontal-tb; padding: 14px 0 0 40px; }
  .fbars { grid-template-columns: 1fr; gap: 24px; }
  .segmented .seg { padding: 8px 12px; }
  .appbar-inner { flex-wrap: wrap; gap: 12px; }
  .viewhead { flex-direction: column; align-items: flex-start; gap: 8px; }
  .vh-note { padding-bottom: 0; }

  /* funnel table stacks into per-territory key-value cards; nothing clips */
  .ftablewrap { overflow-x: visible; }
  .ftable, .ftable tbody, .ftable tr, .ftable td { display: block; width: 100%; }
  .ftable thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .ftable tr { border: 1px solid var(--rule); margin-bottom: 12px; padding: 4px 13px 9px; }
  .ftable tbody tr.sel { border-color: var(--accent); background: var(--st4-wash); }
  .ftable tbody tr.sel td { background: none; }
  .ftable td { display: flex; justify-content: space-between; align-items: baseline; gap: 16px;
    text-align: right; border: 0; padding: 6px 0; }
  .ftable td + td { padding-left: 0; }
  .ftable td::before { content: attr(data-label); color: var(--ink-3); font-weight: 500; text-align: left; }
  .ftable td:first-child { text-align: left; font-weight: 600; font-size: 14px; color: var(--ink);
    border-bottom: 1px solid var(--rule); padding-bottom: 7px; margin-bottom: 3px; }
  .ftable td:first-child::before { content: none; }
}

@media print { .appchrome { position: static; } .inbtns, .adv { display: none; } }
