
/* Layout: one working column, app bar on top; results = summary strip, product ledger, evidence drawer on the right */
:root {
  --bg: #f3f4f1;
  --surface: #ffffff;
  --surface-2: #eceee9;
  --line: #d7dbd3;
  --fg: #1b2420;
  --muted: #5d6862;
  --accent: #0f5c57;
  --accent-fg: #ffffff;
  --accent-soft: #dcebe8;
  --good: #1f7a3f;
  --good-soft: #def0e3;
  --warn: #9a6200;
  --warn-soft: #f7ead0;
  --bad: #b23a2c;
  --bad-soft: #f6dfdb;
  --na: #6f7a74;
  --na-soft: #e6e9e5;
  --redact: #1b2420;
  --display: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --body: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --radius: 6px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121816; --surface: #1a2220; --surface-2: #222c29; --line: #33403b;
    --fg: #e4ebe7; --muted: #9aa8a1; --accent: #4fb3a9; --accent-fg: #0c1513; --accent-soft: #1d3633;
    --good: #5cc283; --good-soft: #1b3324; --warn: #e0a84a; --warn-soft: #3a2e17;
    --bad: #ec7b6b; --bad-soft: #3d221e; --na: #8e9a94; --na-soft: #29312e; --redact: #e4ebe7;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121816; --surface: #1a2220; --surface-2: #222c29; --line: #33403b;
  --fg: #e4ebe7; --muted: #9aa8a1; --accent: #4fb3a9; --accent-fg: #0c1513; --accent-soft: #1d3633;
  --good: #5cc283; --good-soft: #1b3324; --warn: #e0a84a; --warn-soft: #3a2e17;
  --bad: #ec7b6b; --bad-soft: #3d221e; --na: #8e9a94; --na-soft: #29312e; --redact: #e4ebe7;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body { background: var(--bg); color: var(--fg); font-family: var(--body); font-size: 15px; line-height: 1.5; }
h1, h2, h3 { font-family: var(--display); margin: 0; text-wrap: balance; letter-spacing: -0.01em; }
.mono { font-family: var(--mono); font-size: 0.86em; }
.muted { color: var(--muted); }
.eyebrow { font-family: var(--display); font-size: 11px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted); }
button { font: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* app bar */
.appbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--display); font-weight: 800; font-size: 17px; }
.brand-mark { width: 26px; height: 26px; border-radius: 5px; background: var(--accent); color: var(--accent-fg); display: grid; place-items: center; font-size: 12px; font-weight: 800; letter-spacing: 0.02em; }
.poc-tag { font-family: var(--mono); font-size: 11px; color: var(--warn); background: var(--warn-soft); padding: 2px 8px; border-radius: 4px; }
.user { display: flex; gap: 10px; align-items: center; font-size: 14px; color: var(--muted); }
.linkbtn { background: none; border: 0; color: var(--accent); padding: 0; font-weight: 600; }

main { padding-inline: 16px; padding-block: 24px 48px; max-width: 1180px; margin: 0 auto; }

.btn { border: 1px solid var(--accent); background: var(--accent); color: var(--accent-fg); border-radius: var(--radius); padding: 9px 16px; font-weight: 600; }
.btn.secondary { background: var(--surface); color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* login */
.login-wrap { display: grid; place-items: center; min-height: 70vh; }
.login { width: 100%; max-width: 340px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 24px; display: grid; gap: 14px; }
.login h1 { font-size: 20px; }
.field { display: grid; gap: 4px; }
.field label { font-weight: 600; font-size: 14px; }
.field select, .field textarea { border: 1px solid var(--line); background: var(--bg); color: var(--fg); border-radius: var(--radius); padding: 8px 10px; font: inherit; width: 100%; }
.field textarea { min-height: 84px; resize: vertical; line-height: 1.45; }
.field input { border: 1px solid var(--line); background: var(--bg); color: var(--fg); border-radius: var(--radius); padding: 9px 11px; font: inherit; }
.notice { border-radius: var(--radius); padding: 10px 12px; font-size: 14px; }
.notice.bad { background: var(--bad-soft); color: var(--bad); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.info { background: var(--accent-soft); color: var(--accent); }
.fineprint { font-size: 12.5px; color: var(--muted); }

/* upload */
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: end; gap: 12px; margin-bottom: 20px; }
.page-head h1 { font-size: 26px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 20px; }
@media (max-width: 860px) { .grid-2 { grid-template-columns: 1fr; } }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 20px; min-width: 0; }
.panel h2 { font-size: 16px; margin-bottom: 12px; }
.drop { border: 2px dashed var(--line); border-radius: 10px; padding: 36px 20px; text-align: center; display: grid; gap: 10px; justify-items: center; background: var(--bg); transition: border-color .15s, background .15s; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop .big { font-family: var(--display); font-weight: 700; font-size: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.chip { font-size: 12px; border: 1px solid var(--line); border-radius: 999px; padding: 1px 9px; color: var(--muted); background: var(--surface); }
.samples { display: grid; gap: 8px; margin-top: 16px; }
.sample { display: flex; justify-content: space-between; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; background: var(--surface); text-align: left; color: var(--fg); }
.sample:hover { border-color: var(--accent); }
.sample small { color: var(--muted); display: block; }
.history { width: 100%; border-collapse: collapse; font-size: 14px; }
.history th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.history td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.history tr.clickable { cursor: pointer; }
.history tr.clickable:hover td { background: var(--surface-2); }
.tablewrap { overflow-x: auto; }
.num { font-variant-numeric: tabular-nums; }
.scorepill { font-family: var(--mono); font-weight: 500; padding: 1px 7px; border-radius: 4px; }
.s-good { background: var(--good-soft); color: var(--good); }
.s-warn { background: var(--warn-soft); color: var(--warn); }
.s-bad { background: var(--bad-soft); color: var(--bad); }

/* processing */
.proc { max-width: 640px; margin: 0 auto; }
.steps { list-style: none; padding: 0; margin: 16px 0 0; display: grid; gap: 2px; }
.step { display: grid; grid-template-columns: 28px 1fr auto; gap: 10px; align-items: start; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.step .dot { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--line); margin-top: 2px; display: grid; place-items: center; font-size: 11px; color: var(--accent-fg); }
.step.done .dot { background: var(--accent); border-color: var(--accent); }
.step.active .dot { border-color: var(--accent); border-top-color: transparent; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .step.active .dot { animation: none; border-top-color: var(--accent); } }
.step .label { font-weight: 600; }
.step .detail { font-size: 13px; color: var(--muted); }
.step.pending { opacity: 0.55; }
.step .t { font-family: var(--mono); font-size: 12px; color: var(--muted); }

/* results */
.deal-head { display: flex; flex-wrap: wrap; gap: 16px 28px; align-items: end; justify-content: space-between; margin-bottom: 18px; }
.deal-head h1 { font-size: 24px; }
.facts { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 14px; color: var(--muted); margin-top: 6px; }
.facts b { color: var(--fg); font-weight: 600; }
.summary { display: grid; grid-template-columns: 1.3fr 1fr 1fr 1fr; gap: 12px; margin-bottom: 18px; }
@media (max-width: 900px) { .summary { grid-template-columns: 1fr 1fr; } }
@media (max-width: 480px) { .summary { grid-template-columns: 1fr; } }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; display: grid; gap: 4px; align-content: start; }
.tile .val { font-family: var(--display); font-weight: 800; font-size: 34px; line-height: 1.05; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 13px; color: var(--muted); }
.tile.main { display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center; }
.ring { width: 92px; height: 92px; }
.ring circle { fill: none; stroke-width: 10; }
.ring .track { stroke: var(--surface-2); }
.ring .arc { stroke: var(--warn); stroke-linecap: round; transform: rotate(-90deg); transform-origin: 50% 50%; transition: stroke-dashoffset .6s; }
.ring text { font-family: var(--display); font-weight: 800; font-size: 22px; fill: var(--fg); }
.meter { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.meter > i { display: block; height: 100%; background: var(--accent); }
.basis { display: flex; gap: 10px; align-items: start; margin-bottom: 18px; }

.results { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 20px; align-items: start; }
@media (max-width: 1000px) { .results { grid-template-columns: 1fr; } }
.ledger { width: 100%; border-collapse: collapse; font-size: 14px; }
.ledger th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.ledger td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.ledger tbody tr { cursor: pointer; }
.ledger tbody tr:hover td { background: var(--surface-2); }
.ledger tbody tr[aria-selected="true"] td { background: var(--accent-soft); }
.ledger tbody tr[aria-selected="true"] td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.prod { font-weight: 600; }
.codes { display: flex; flex-wrap: wrap; gap: 4px; }
.code { font-family: var(--mono); font-size: 11px; background: var(--surface-2); padding: 1px 6px; border-radius: 3px; color: var(--muted); white-space: nowrap; }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 600; padding: 2px 8px; border-radius: 4px; white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.b-hit { background: var(--good-soft); color: var(--good); }
.b-miss { background: var(--bad-soft); color: var(--bad); }
.b-na { background: var(--na-soft); color: var(--na); }
.b-sold { background: var(--accent-soft); color: var(--accent); }
.b-pilot { background: var(--warn-soft); color: var(--warn); }

.drawer { position: sticky; top: 16px; display: grid; gap: 14px; }
.drawer h2 { font-size: 18px; }
.trig { display: grid; gap: 8px; }
.trig-row { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; display: grid; gap: 4px; background: var(--bg); }
.trig-row .top { display: flex; justify-content: space-between; gap: 8px; align-items: start; }
.trig-row .what { font-weight: 600; font-size: 14px; }
.st { font-size: 11px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; padding: 1px 6px; border-radius: 3px; white-space: nowrap; }
.st-known { background: var(--good-soft); color: var(--good); }
.st-inferred { background: var(--accent-soft); color: var(--accent); }
.st-ambiguous { background: var(--warn-soft); color: var(--warn); }
.st-unknown { background: var(--na-soft); color: var(--na); }
.src { font-size: 12.5px; color: var(--muted); }
.src a { color: var(--accent); }
.explain { font-size: 14.5px; line-height: 1.6; }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--accent); }

.fields { width: 100%; border-collapse: collapse; font-size: 14px; }
.fields td, .fields th { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.fields th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.fields input { width: 100%; min-width: 90px; border: 1px solid var(--accent); border-radius: 4px; padding: 4px 6px; font: inherit; background: var(--bg); color: var(--fg); }
.conf { font-family: var(--mono); font-size: 12px; }
.edited td { background: var(--warn-soft); }

.pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.pagecard { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 10px; display: grid; gap: 6px; font-size: 13px; }
.thumb { aspect-ratio: 8.5 / 11; max-width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 3px; padding: 8px; display: grid; gap: 4px; align-content: start; }
.thumb i { display: block; height: 4px; background: var(--line); border-radius: 2px; }
.thumb i.r { background: var(--redact); height: 6px; }
.thumb.dropped { background: repeating-linear-gradient(45deg, var(--bad-soft), var(--bad-soft) 6px, var(--bg) 6px, var(--bg) 12px); }
.redact { background: var(--redact); color: transparent; border-radius: 2px; user-select: none; padding: 0 2px; }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 14px; max-width: calc(100% - 32px); }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.versions { display: flex; flex-wrap: wrap; gap: 6px; }

/* rules */
.flow { list-style: none; padding: 0; margin: 0 0 20px; display: flex; flex-wrap: wrap; gap: 6px; counter-reset: f; }
.flow li { counter-increment: f; display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); font-size: 13.5px; font-weight: 600; color: var(--muted); }
.flow li::before { content: counter(f); width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); font-size: 12px; }
.flow li.done { color: var(--fg); }
.flow li.done::before { content: "✓"; background: var(--accent); color: var(--accent-fg); }
.flow li.now { color: var(--fg); border-color: var(--accent); }
.flow li.now::before { background: var(--accent-soft); color: var(--accent); }
.stack { display: grid; gap: 16px; align-content: start; min-width: 0; }
.panel h2 .n { font-family: var(--mono); font-size: 12px; color: var(--muted); font-weight: 500; margin-right: 6px; }
.diff { width: 100%; border-collapse: collapse; font-size: 14px; }
.diff th, .diff td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.diff th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.diff tr.add td { background: var(--good-soft); }
.diff tr.add td:first-child::before { content: "+ "; color: var(--good); font-weight: 700; }
.attr { border: 1px solid var(--good); border-radius: var(--radius); padding: 14px; display: grid; gap: 10px; background: var(--bg); margin-top: 14px; }
.checks { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; font-size: 14px; }
.checks li { display: grid; grid-template-columns: 22px 1fr; gap: 8px; }
.checks .ok { color: var(--good); font-weight: 700; }
.checks .hold { color: var(--warn); font-weight: 700; }
.kpis { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 10px; margin: 12px 0; }
.kpis div { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.kpis b { display: block; font-family: var(--display); font-size: 19px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.kpis span { font-size: 12.5px; color: var(--muted); }
.delta-up { color: var(--good); font-family: var(--mono); }
.delta-down { color: var(--bad); font-family: var(--mono); }
.hist { list-style: none; padding: 0; margin: 0; display: grid; }
.hist li { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; align-items: start; }
.hist li:last-child { border-bottom: 0; }
.ver { font-family: var(--mono); font-size: 12.5px; font-weight: 500; padding: 1px 6px; border-radius: 3px; background: var(--surface-2); white-space: nowrap; }
.ver.live { background: var(--good-soft); color: var(--good); }
.ver.draft { background: var(--warn-soft); color: var(--warn); }

/* ---- app additions ---- */
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; }
[hidden] { display: none !important; }
.ring .arc.good { stroke: var(--good); }
.ring .arc.warn { stroke: var(--warn); }
.ring .arc.bad { stroke: var(--bad); }
.ring .arc.na { stroke: var(--na); }
.val.bad { color: var(--bad); }
.val.good { color: var(--good); }
.pagetext { white-space: pre-wrap; font-family: var(--mono); font-size: 12.5px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; max-height: 420px; overflow: auto; margin-top: 12px; }
.pagecard.clickable { cursor: pointer; }
.pagecard.clickable:hover { border-color: var(--accent); }
.timer { font-family: var(--mono); font-size: 13px; color: var(--muted); }
.big-time { font-family: var(--display); font-weight: 800; font-size: 28px; font-variant-numeric: tabular-nums; }
.st-fired { background: var(--good-soft); color: var(--good); }
.st-not_fired { background: var(--na-soft); color: var(--na); }
.st-excluded { background: var(--warn-soft); color: var(--warn); }
.st-pilot, .st-pilot_would_fire { background: var(--warn-soft); color: var(--warn); }
.st-low_confidence { background: var(--warn-soft); color: var(--warn); }
.cond { font-size: 13px; display: grid; gap: 2px; }
.cond .src { font-size: 12px; }
.inline-input { border: 1px solid var(--line); background: var(--bg); color: var(--fg); border-radius: 4px; padding: 3px 6px; font: inherit; font-size: 13px; width: 90px; }
.wide-input { width: 100%; }
.trow-actions { display: flex; gap: 8px; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; display: inline-block; vertical-align: -2px; animation: spin .8s linear infinite; }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
.banner-poc { font-size: 13px; }
.empty { color: var(--muted); padding: 16px 8px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.questions { margin: 8px 0 0; padding-left: 18px; font-size: 14px; }
.danger { color: var(--bad); }
a.btn, a.linkbtn { text-decoration: none; display: inline-block; }
a.linkbtn:hover { text-decoration: underline; }

.gen { display: grid; gap: 14px; justify-items: center; text-align: center; padding: 28px 12px; border: 1px dashed var(--line); border-radius: 10px; background: var(--bg); }
.gen p { margin: 0; max-width: 46ch; color: var(--muted); }
.btn-lg { font-size: 17px; padding: 12px 24px; }
#explainText > .btn { margin-top: 6px; }

.user { flex-wrap: wrap; justify-content: flex-end; }
.nav-upload { padding: 6px 12px; font-size: 14px; }
.user a.active { color: var(--fg); text-decoration: underline; text-underline-offset: 4px; }
@media (max-width: 640px) { .appbar { flex-wrap: wrap; } .poc-tag { display: none; } }

.upload-strip { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 16px; align-items: end; margin-bottom: 16px; }
@media (max-width: 760px) { .upload-strip { grid-template-columns: 1fr; } }
.drop-compact { display: flex; align-items: center; justify-content: space-between; gap: 16px; text-align: left; padding: 18px 20px; cursor: pointer; }
.drop-compact .big { font-size: 17px; }
.drop-compact .muted { font-size: 13.5px; }
.ruleset-field { align-self: end; }
.list-panel { padding: 12px; margin-bottom: 20px; }
.list-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; margin: 2px 4px 10px; }
.list-head h2 { margin: 0; font-size: 16px; }
.filter { border: 1px solid var(--line); background: var(--bg); color: var(--fg); border-radius: var(--radius); padding: 7px 10px; font: inherit; font-size: 14px; width: min(320px, 100%); }
.list-scroll { max-height: 300px; overflow-y: auto; }
.history tr[aria-selected="true"] td { background: var(--accent-soft); }
.history tr[aria-selected="true"] td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
#dealPane { scroll-margin-top: 12px; }
