:root {
  /* Petroleum-ink chrome + pale drafting workspace */
  --ink:        #15201d;
  --ink-2:      #1f2c28;
  --ink-3:      #2b3a35;
  --ground:     #e7e9e4;
  --surface:    #ffffff;
  --surface-2:  #f4f5f2;
  --text:       #19211e;
  --text-dim:   #5c6862;
  --text-faint: #8a958f;
  --line:       #d3d7d0;
  --line-soft:  #e4e7e1;

  /* Confidence heat — the one place color runs bold */
  --high:       #2f7d6b;
  --high-tint:  #e3efeb;
  --mid:        #b9801f;
  --mid-tint:   #f6ebd4;
  --low:        #b0472c;
  --low-tint:   #f3e0d8;

  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;

  --rail-w: 290px;
  --drawer-w: 420px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--text);
  background: var(--ground);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
::selection { background: var(--high-tint); }

.app {
  display: grid;
  grid-template-rows: 56px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Shared atoms ---------- */
.eyebrow {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.mono { font-family: var(--font-mono); }

.btn {
  border: 1px solid var(--line); background: var(--surface);
  color: var(--text); padding: 8px 13px; border-radius: 6px;
  font-size: 12.5px; font-weight: 500; display: inline-flex; align-items: center; gap: 7px;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--high); border-color: var(--high); color: #fff; }
.btn-primary:hover { background: #28695a; }
.btn-primary .n { font-family: var(--font-mono); }
.btn:disabled { background: var(--line); border-color: var(--line); color: var(--text-faint); cursor: default; }
.btn-ghost { background: none; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-flag { color: var(--low); border-color: #e3c2b6; }
.btn-flag:hover { background: var(--low-tint); }
.btn-lg { padding: 11px 20px; font-size: 13.5px; }

/* ---------- Top bar: brand · stepper · gauges ---------- */
.topbar {
  background: var(--ink); color: #cdd6d1;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; gap: 24px;
}
.brand { display: flex; align-items: center; gap: 9px; flex-shrink: 0; }
.brand .mark {
  width: 18px; height: 18px; border-radius: 3px;
  background: linear-gradient(160deg, var(--high) 0%, var(--mid) 100%);
}
.brand h1 { margin: 0; font-size: 16px; letter-spacing: -0.01em; color: #fff; }
.brand .sub { font-family: var(--font-mono); font-size: 9.5px; letter-spacing: .1em; color: #79857f; }

/* stepper */
.stepper { display: flex; align-items: center; gap: 2px; flex: 1; justify-content: center; min-width: 0; }
.step {
  display: flex; align-items: center; gap: 7px; white-space: nowrap;
  padding: 7px 11px; border-radius: 7px; cursor: pointer;
  color: #8a958f; font-size: 12.5px; transition: background .12s, color .12s;
  border: none; background: none;
}
.step:hover:not(.locked) { background: var(--ink-2); color: #cdd6d1; }
.step.active { background: var(--ink-2); color: #fff; }
.step.locked { opacity: .4; cursor: not-allowed; }
.step .num {
  width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center;
  font-family: var(--font-mono); font-size: 10px;
  border: 1px solid #3a4a44; flex-shrink: 0;
}
.step.active .num { background: var(--high); border-color: var(--high); color: #fff; }
.step.done .num { background: var(--ink-3); border-color: var(--ink-3); color: var(--high); }
.step-sep { width: 14px; height: 1px; background: #3a4a44; }

.gauges { display: flex; align-items: stretch; flex-shrink: 0; }
.gauge { padding: 0 13px; text-align: right; border-left: 1px solid var(--ink-3);
  display: flex; flex-direction: column; justify-content: center; white-space: nowrap; }
.gauge .val { font-family: var(--font-mono); font-size: 15px; font-weight: 600; line-height: 1; color: #eef2f0; }
.gauge .lbl { font-family: var(--font-mono); font-size: 9px; letter-spacing: .12em;
  text-transform: uppercase; color: #79857f; margin-top: 4px; }
.gauge.filed .val { color: var(--high); }
.gauge.review .val { color: var(--mid); }
.gauge.quarantine .val { color: var(--low); }

/* ---------- Stage host ---------- */
#stage { overflow: hidden; position: relative; }
.stage-pad { overflow-y: auto; height: 100%; padding: 28px 32px 80px; }
.stage-narrow { max-width: 1080px; margin: 0 auto; }

.stage-title { font-size: 26px; letter-spacing: -0.02em; margin: 4px 0 6px; }
.stage-lead { color: var(--text-dim); font-size: 14px; max-width: 640px; margin: 0 0 24px; }

.stage-foot {
  position: sticky; bottom: 0; margin: 28px -32px -80px;
  padding: 16px 32px; background: linear-gradient(transparent, var(--ground) 30%);
  display: flex; justify-content: space-between; align-items: center;
}

/* ---------- Card primitives ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 18px;
}
.grid-auto { display: grid; gap: 14px; }

/* ============================================================
   INGEST stage
   ============================================================ */
.pipe { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; margin-bottom: 24px; }
.pipe-step {
  background: var(--surface); border: 1px solid var(--line); padding: 16px 18px;
  position: relative;
}
.pipe-step:first-child { border-radius: 9px 0 0 9px; }
.pipe-step:last-child { border-radius: 0 9px 9px 0; }
.pipe-step + .pipe-step { border-left: none; }
.pipe-step .eyebrow { display: block; margin-bottom: 10px; }
.pipe-step .big { font-family: var(--font-mono); font-size: 24px; font-weight: 600; line-height: 1; }
.pipe-step .note { font-size: 11.5px; color: var(--text-dim); margin-top: 7px; min-height: 30px; }
.pipe-step .bar { height: 3px; background: var(--line-soft); border-radius: 2px; margin-top: 12px; overflow: hidden; }
.pipe-step .bar i { display: block; height: 100%; background: var(--high); width: 0; transition: width .8s ease; }
.pipe-step.working .bar i { background: var(--mid); }
.pipe-arrow { position: absolute; right: -9px; top: 50%; transform: translateY(-50%); z-index: 2;
  width: 18px; height: 18px; background: var(--ground); border-radius: 50%; display: grid; place-items: center;
  color: var(--text-faint); font-size: 11px; }

.split-2 { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; }
.bars-row { display: flex; align-items: center; gap: 12px; margin: 11px 0; font-size: 12.5px; }
.bars-row .label { width: 130px; flex-shrink: 0; color: var(--text-dim); }
.bars-row .track { flex: 1; height: 9px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.bars-row .track i { display: block; height: 100%; border-radius: 5px; }
.bars-row .pct { width: 70px; text-align: right; font-family: var(--font-mono); font-size: 12px; }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; background: var(--line-soft);
  border: 1px solid var(--line-soft); border-radius: 8px; overflow: hidden; }
.stat-cell { background: var(--surface); padding: 14px 16px; }
.stat-cell .v { font-family: var(--font-mono); font-size: 20px; font-weight: 600; }
.stat-cell .v.warn { color: var(--mid); } .stat-cell .v.bad { color: var(--low); } .stat-cell .v.good { color: var(--high); }
.stat-cell .k { font-size: 11px; color: var(--text-dim); margin-top: 3px; }

/* ============================================================
   TAXONOMY stage
   ============================================================ */
.tax-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.tax-tree { display: flex; flex-direction: column; gap: 8px; }
.tax-node {
  background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 14px 16px;
  cursor: pointer; transition: border-color .12s, box-shadow .12s;
}
.tax-node:hover { border-color: var(--ink-3); }
.tax-node.active { border-color: var(--high); box-shadow: 0 0 0 1px var(--high); }
.tax-node.accepted { background: var(--high-tint); border-color: #c4ddd5; }
.tax-node.rejected { opacity: .5; }
.tax-child { margin-left: 26px; }
.tax-branch { color: var(--text-faint); margin-right: 6px; }
.tax-sub-note { font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); margin-top: 10px; }
.tax-add { width: 100%; padding: 12px; border: 1px dashed var(--line); border-radius: 9px;
  background: none; color: var(--text-dim); font-size: 13px; font-weight: 500; transition: all .12s; }
.tax-add:hover { border-color: var(--high); color: var(--high); background: var(--high-tint); }
.tax-node-top { display: flex; align-items: center; gap: 10px; }
.tax-node-name { font-weight: 600; font-size: 14px; flex: 1; }
.tax-node-name input { font: inherit; border: 1px solid var(--high); border-radius: 5px; padding: 3px 6px; width: 100%; }
.tax-badge { font-family: var(--font-mono); font-size: 10px; padding: 2px 7px; border-radius: 20px; }
.tax-badge.accepted { background: var(--high); color: #fff; }
.tax-count { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-dim); }
.coh-line { display: flex; align-items: center; gap: 8px; margin-top: 9px; font-size: 12px; color: var(--text-dim); }
.coh-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.tax-types { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 11px; }
.tax-type { font-family: var(--font-mono); font-size: 10px; background: var(--surface-2);
  border: 1px solid var(--line-soft); color: var(--text-dim); padding: 2px 7px; border-radius: 4px; }

.tax-detail { align-self: start; }
.tax-detail .placement { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.tax-detail .ai-why { font-size: 13px; color: var(--text-dim); line-height: 1.55; margin: 8px 0 0; }
.sample-doc { display: flex; gap: 10px; align-items: baseline; padding: 8px 0; border-bottom: 1px solid var(--line-soft); font-size: 12.5px; }
.sample-doc:last-child { border-bottom: none; }
.sample-doc .sd-id { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-faint); flex-shrink: 0; width: 96px; }
.tax-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

/* ============================================================
   REVIEW stage (internal three-pane)
   ============================================================ */
.review-stage { display: grid; grid-template-columns: var(--rail-w) 1fr; height: 100%; overflow: hidden; }
.review-stage.with-drawer { grid-template-columns: var(--rail-w) 1fr var(--drawer-w); }

.rev-rail { background: var(--surface-2); border-right: 1px solid var(--line); overflow-y: auto; padding: 10px 0 20px; }
.rev-rail-label { padding: 16px 18px 8px; display: flex; justify-content: space-between; align-items: baseline; }
.node {
  padding: 10px 18px 10px 15px; border-left: 3px solid transparent; cursor: pointer; transition: background .12s;
}
.node:hover { background: #eceee9; }
.node.active { background: #e4ebe7; border-left-color: var(--high); }
.node-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.node-name { font-size: 13px; font-weight: 500; }
.node-parent .node-name { font-weight: 600; }
.node-child { padding-left: 30px; }
.node-child .node-name { font-size: 12.5px; }
.caret { display: inline-block; font-size: 9px; color: var(--text-faint); margin-right: 6px; transition: transform .15s; }
.node-parent.open .caret { transform: rotate(90deg); }
.node-count { font-family: var(--font-mono); font-size: 11px; color: var(--text-dim); flex-shrink: 0; }
.heat { margin-top: 7px; height: 4px; border-radius: 2px; overflow: hidden; display: flex; background: var(--line); }
.heat span { display: block; height: 100%; }
.heat .s-high { background: var(--high); } .heat .s-mid { background: var(--mid); } .heat .s-low { background: var(--low); }

.workspace { overflow-y: auto; padding: 22px 24px 80px; }
.batch-head { margin-bottom: 14px; }
.crumb { color: var(--text-dim); }
.crumb b { color: var(--text); }
.batch-head h2 { margin: 6px 0 6px; font-size: 22px; letter-spacing: -0.02em; }
.coherence { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-dim);
  background: var(--surface); border: 1px solid var(--line); padding: 5px 10px; border-radius: 5px; }
.coherence .dot { width: 7px; height: 7px; border-radius: 50%; }

.controls { position: sticky; top: -22px; z-index: 5; background: var(--ground); padding: 12px 0 14px;
  margin-bottom: 6px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.slider-wrap { display: flex; align-items: center; gap: 10px; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 150px; height: 4px; border-radius: 3px;
  background: linear-gradient(90deg, var(--high), var(--mid), var(--low)); outline: none; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 16px; height: 16px;
  border-radius: 50%; background: var(--surface); border: 2px solid var(--ink); cursor: pointer; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
input[type=range]:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--high); outline-offset: 2px; }
.thresh-val { font-family: var(--font-mono); font-size: 12px; min-width: 34px; }

.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-dim); user-select: none; cursor: pointer; }
.switch { width: 34px; height: 19px; border-radius: 10px; background: var(--line); position: relative; transition: background .15s; flex-shrink: 0; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 15px; height: 15px; border-radius: 50%;
  background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.toggle.on .switch { background: var(--high); }
.toggle.on .switch::after { transform: translateX(15px); }
.toggle.on { color: var(--text); font-weight: 500; }
.controls .btn-primary { margin-left: auto; }

/* info tooltip */
.info-tip { position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 50%; border: 1px solid var(--line); color: var(--text-faint);
  font-family: var(--font-mono); font-size: 10px; font-style: italic; cursor: help; flex-shrink: 0; margin-left: -10px; }
.info-tip:hover, .info-tip:focus-visible { color: var(--text); border-color: var(--text-dim); outline: none; }
.tip-bubble { position: absolute; top: calc(100% + 9px); left: 50%; transform: translateX(-50%);
  width: 270px; background: var(--ink); color: #e7ece9; font-family: var(--font-ui); font-size: 12px; font-style: normal;
  font-weight: 400; line-height: 1.5; letter-spacing: normal; text-transform: none; text-align: left;
  padding: 11px 13px; border-radius: 8px; box-shadow: 0 6px 20px rgba(21,32,29,.28);
  opacity: 0; visibility: hidden; transition: opacity .12s; z-index: 20; pointer-events: none; }
.tip-bubble b { color: #fff; font-weight: 600; }
.tip-bubble::after { content: ""; position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  border: 6px solid transparent; border-bottom-color: var(--ink); }
.info-tip:hover .tip-bubble, .info-tip:focus .tip-bubble, .info-tip:focus-visible .tip-bubble { opacity: 1; visibility: visible; }

.group-label { display: flex; align-items: center; gap: 10px; margin: 18px 2px 9px; }
.group-label .eyebrow { white-space: nowrap; }
.group-label .rule { flex: 1; height: 1px; background: var(--line); }
.group-label .pill { font-family: var(--font-mono); font-size: 10px; padding: 2px 7px; border-radius: 20px; }
.pill-mid { background: var(--mid-tint); color: #8a5e10; }
.pill-high { background: var(--high-tint); color: #205c4e; }

.doc { background: var(--surface); border: 1px solid var(--line); border-radius: 7px; padding: 12px 14px; margin-bottom: 8px;
  display: grid; grid-template-columns: 52px 1fr auto; gap: 14px; align-items: center; cursor: pointer;
  transition: border-color .12s, box-shadow .12s, opacity .2s, transform .2s; }
.doc:hover { border-color: var(--ink-3); box-shadow: 0 2px 8px rgba(21,32,29,.06); }
.doc.selected { border-color: var(--high); box-shadow: 0 0 0 1px var(--high); }
.doc.filing { opacity: 0; transform: translateX(16px); }
.conf { text-align: center; }
.conf .score { font-family: var(--font-mono); font-size: 15px; font-weight: 600; line-height: 1; }
.conf .tier { font-family: var(--font-mono); font-size: 8.5px; letter-spacing: .1em; text-transform: uppercase; margin-top: 3px; }
.t-high .score, .t-high .tier { color: var(--high); }
.t-mid .score, .t-mid .tier { color: var(--mid); }
.t-low .score, .t-low .tier { color: var(--low); }
.doc-body { min-width: 0; }
.doc-title { font-weight: 600; font-size: 13.5px; margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-meta { font-family: var(--font-mono); font-size: 11px; color: var(--text-dim); display: flex; flex-wrap: wrap; }
.doc-meta span { white-space: nowrap; }
.doc-meta span + span::before { content: "·"; margin: 0 7px; color: var(--text-faint); }
.doc-type { display: inline-block; font-family: var(--font-mono); font-size: 10px; background: var(--surface-2);
  border: 1px solid var(--line-soft); color: var(--text-dim); padding: 1px 6px; border-radius: 4px; margin-bottom: 5px; }
.doc-why { font-size: 12px; color: var(--text-dim); margin-top: 5px; line-height: 1.4; }
.doc-why b { color: var(--text); font-weight: 500; }
.flag-tag { font-family: var(--font-mono); font-size: 9.5px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--low); background: var(--low-tint); padding: 1px 6px; border-radius: 4px; margin-left: 6px; }
.flag-tag.ocr { color: #8a5e10; background: var(--mid-tint); }
.doc-actions { display: flex; gap: 6px; }
.icon-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; width: 32px; height: 32px;
  display: grid; place-items: center; color: var(--text-dim); font-size: 14px; transition: all .12s; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.approve:hover { background: var(--high); border-color: var(--high); color: #fff; }
.icon-btn.flag:hover { background: var(--low); border-color: var(--low); color: #fff; }
.showing-note { text-align: center; color: var(--text-faint); font-family: var(--font-mono); font-size: 11px; margin: 18px 0 0; }

/* drawer — shown only when the stage is in with-drawer mode (single source of truth) */
.drawer { border-left: 1px solid var(--line); background: var(--surface); overflow-y: auto; display: none; flex-direction: column; }
.review-stage.with-drawer .drawer { display: flex; }
.drawer-head { padding: 16px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.drawer-head .close { float: right; border: none; background: none; font-size: 20px; color: var(--text-faint); line-height: 1; padding: 0; }
.drawer-head h3 { margin: 8px 0 0; font-size: 16px; letter-spacing: -.01em; padding-right: 20px; }
.drawer-sec { padding: 16px 18px; border-bottom: 1px solid var(--line-soft); }
.drawer-sec .eyebrow { display: block; margin-bottom: 10px; }
.field-row { display: grid; grid-template-columns: 110px 1fr; gap: 10px; padding: 5px 0; font-size: 12.5px; align-items: baseline; }
.field-row .k { font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--text-faint); }
.field-row .v { font-family: var(--font-mono); font-size: 12px; }
.field-row .v.low-conf { color: var(--mid); }
.field-row .v .conf-flag { font-size: 9.5px; color: var(--mid); margin-left: 6px; background: var(--mid-tint); padding: 0 5px; border-radius: 3px; }
.placement { background: var(--high-tint); border: 1px solid #c4ddd5; border-radius: 7px; padding: 12px; }
.placement.t-mid { background: var(--mid-tint); border-color: #e6d3a6; }
.placement.t-low { background: var(--low-tint); border-color: #e3c2b6; }
.placement .path { font-weight: 600; font-size: 13px; }
.placement .why { font-size: 12.5px; color: var(--text-dim); margin-top: 6px; line-height: 1.5; }
.preview { font-family: var(--font-mono); font-size: 11.5px; line-height: 1.6; color: var(--text-dim);
  background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: 6px; padding: 12px;
  max-height: 200px; overflow: hidden; position: relative; white-space: pre-wrap; }
.preview::after { content: ""; position: absolute; bottom: 0; left: 0; right: 0; height: 48px; background: linear-gradient(transparent, var(--surface-2)); }
.reclass-row { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
select { font-family: var(--font-mono); font-size: 12px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); flex: 1; }
.drawer-foot { margin-top: auto; padding: 14px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; position: sticky; bottom: 0; background: var(--surface); }
.drawer-foot .btn { flex: 1; justify-content: center; }

/* ============================================================
   QUARANTINE stage
   ============================================================ */
.q-table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.q-table th { text-align: left; font-family: var(--font-mono); font-size: 10px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--text-faint); padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 600; }
.q-table td { padding: 13px 16px; border-bottom: 1px solid var(--line-soft); font-size: 13px; vertical-align: middle; }
.q-table tr:last-child td { border-bottom: none; }
.q-table .q-id { font-family: var(--font-mono); font-size: 11px; color: var(--text-dim); }
.q-reason { display: inline-flex; align-items: center; gap: 7px; font-family: var(--font-mono); font-size: 11px; }
.q-reason .d { width: 8px; height: 8px; border-radius: 50%; }
.q-actions { display: flex; gap: 6px; justify-content: flex-end; }
.q-table tr.q-resolved { opacity: .45; }
.q-table tr.q-resolved .q-actions { visibility: hidden; }

/* ============================================================
   SUMMARY stage
   ============================================================ */
.sum-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin: 8px 0 28px; }
.sum-cell { background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 18px; text-align: center; }
.sum-cell .v { font-family: var(--font-mono); font-size: 28px; font-weight: 600; }
.sum-cell .k { font-size: 11.5px; color: var(--text-dim); margin-top: 6px; }
.sum-cell.good .v { color: var(--high); } .sum-cell.warn .v { color: var(--mid); } .sum-cell.bad .v { color: var(--low); }

/* ---------- Toast ---------- */
.toast-stack { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 10px; z-index: 50; align-items: center; }
.toast { background: var(--ink); color: #eef2f0; border-radius: 9px; padding: 12px 16px; display: flex; align-items: center; gap: 16px;
  box-shadow: 0 8px 28px rgba(21,32,29,.28); font-size: 13px; max-width: 560px; animation: rise .25s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.toast .ico { width: 22px; height: 22px; border-radius: 50%; background: var(--high); display: grid; place-items: center; color: #fff; font-size: 12px; flex-shrink: 0; }
.toast b { font-family: var(--font-mono); }
.toast .undo { background: none; border: 1px solid #3a4a44; color: #cdd6d1; padding: 5px 11px; border-radius: 6px; font-size: 12px; white-space: nowrap; }
.toast .undo:hover { background: var(--ink-2); }

/* ---------- Modal ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(21,32,29,.45); display: grid; place-items: center;
  z-index: 100; padding: 24px; animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal { background: var(--surface); border-radius: 12px; max-width: 470px; width: 100%; padding: 24px 26px;
  box-shadow: 0 20px 60px rgba(21,32,29,.32); position: relative; animation: rise .2s ease; }
.modal-close { position: absolute; top: 14px; right: 16px; border: none; background: none; font-size: 22px;
  color: var(--text-faint); line-height: 1; padding: 0; }
.modal-close:hover { color: var(--text); }
.modal-title { margin: 0 0 12px; font-size: 18px; letter-spacing: -.01em; padding-right: 24px; }
.modal-body { font-size: 13.5px; color: var(--text-dim); line-height: 1.6; }
.modal-body ul { margin: 12px 0 0; padding: 0; list-style: none; }
.modal-body li { position: relative; padding: 4px 0 4px 18px; }
.modal-body li::before { content: ""; position: absolute; left: 2px; top: 11px; width: 5px; height: 5px;
  border-radius: 50%; background: var(--high); }
.modal-body .mono, .modal-body code { font-family: var(--font-mono); font-size: 12px; background: var(--surface-2);
  padding: 1px 5px; border-radius: 4px; color: var(--text); }
.modal-note { margin-top: 16px; font-size: 12px; color: var(--text-faint); border-top: 1px solid var(--line-soft); padding-top: 12px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* ============================================================
   Mobile
   ============================================================ */
@media (max-width: 720px) {
  /* Let the document scroll naturally instead of nested 100vh panes */
  html, body { height: auto; }
  .app { display: block; height: auto; overflow: visible; }
  #stage { overflow: visible; }
  .stage-pad { height: auto; overflow: visible; padding: 18px 16px 32px; }

  /* Top bar: keep brand + stepper, drop the gauges, collapse step labels */
  .topbar { position: sticky; top: 0; z-index: 40; padding: 0 12px; gap: 8px; height: 52px; }
  .brand .sub { display: none; }
  .brand h1 { font-size: 15px; }
  .gauges { display: none; }
  .stepper { gap: 2px; justify-content: flex-start; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .stepper::-webkit-scrollbar { display: none; }
  .step-sep { display: none; }
  .step { padding: 6px 8px; }
  .step-label { display: none; }
  .step.active .step-label { display: inline; }

  /* Stage chrome */
  .stage-title { font-size: 21px; }
  .stage-foot { position: static; flex-direction: column; align-items: stretch; gap: 10px;
    margin: 22px 0 0; padding: 16px 0 0; background: none; border-top: 1px solid var(--line); }
  .stage-foot .btn-lg { width: 100%; justify-content: center; }
  .stage-foot > div { display: flex; flex-direction: column; gap: 10px; }

  /* Ingest */
  .pipe { grid-template-columns: 1fr 1fr; }
  .pipe-step { border-radius: 0 !important; }
  .pipe-arrow { display: none; }
  .split-2 { grid-template-columns: 1fr; }

  /* Taxonomy */
  .tax-layout { grid-template-columns: 1fr; }
  .tax-detail { order: -1; }            /* show the detail above the long tree */
  .tax-child { margin-left: 16px; }

  /* Summary */
  .sum-grid { grid-template-columns: 1fr 1fr; }

  /* Review: stack rail over workspace; drawer becomes a full-screen sheet */
  .review-stage, .review-stage.with-drawer { display: block; height: auto; overflow: visible; }
  .rev-rail { border-right: none; border-bottom: 1px solid var(--line); max-height: 230px; }
  .workspace { padding: 18px 16px 32px; }
  .controls { position: static; }
  .doc { grid-template-columns: 44px 1fr; }
  .doc-actions { grid-column: 1 / -1; justify-content: flex-end; margin-top: 4px; }
  .drawer { position: fixed; inset: 0; z-index: 60; border-left: none; }

  /* Quarantine: turn the table into stacked cards */
  .q-table, .q-table tbody, .q-table tr, .q-table td { display: block; width: 100%; }
  .q-table thead { display: none; }
  .q-table tr { padding: 14px 16px; border-bottom: 1px solid var(--line-soft); }
  .q-table tr:last-child { border-bottom: none; }
  .q-table td { padding: 3px 0; border: none; }
  .q-actions { justify-content: flex-start; margin-top: 10px; }

  /* Modal */
  .modal { padding: 20px; }
}

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
