:root {
  --bg: #f6f7f5; --panel: #ffffff; --ink: #1d2320; --muted: #66706a; --line: #dde2dc; --accent: #2f6b4f; --accent-ink: #ffffff;
  --pass: #2f7d4f; --pass-bg: #e3f2e8; --flag: #9a6a00; --flag-bg: #fdf1d6; --fail: #b3261e; --fail-bg: #fbe3e1;
  --info: #3a5f8a; --info-bg: #e6eef8; --pick: #fff3a6; --hl: rgba(255, 214, 0, .45); --hl-token: rgba(255, 120, 0, .55);
  --confirmed: #1f5f3a;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 14px; color: var(--ink);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151917; --panel: #1e2421; --ink: #e6ebe7; --muted: #9aa59e; --line: #333b37; --accent: #5fb38a; --accent-ink: #0d1411;
    --pass: #7fd3a0; --pass-bg: #1d3327; --flag: #f0c35a; --flag-bg: #3a2f14; --fail: #ff9b92; --fail-bg: #3d1f1c;
    --info: #9cc0ea; --info-bg: #1d2a3a; --pick: #4a4320; --confirmed: #9fe0b8;
  }
}
:root[data-theme="dark"] {
  --bg: #151917; --panel: #1e2421; --ink: #e6ebe7; --muted: #9aa59e; --line: #333b37; --accent: #5fb38a; --accent-ink: #0d1411;
  --pass: #7fd3a0; --pass-bg: #1d3327; --flag: #f0c35a; --flag-bg: #3a2f14; --fail: #ff9b92; --fail-bg: #3d1f1c;
  --info: #9cc0ea; --info-bg: #1d2a3a; --pick: #4a4320; --confirmed: #9fe0b8;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--accent); }
button { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 6px; padding: 3px 9px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.small { padding: 1px 6px; font-size: 12px; }
button:disabled { opacity: .45; cursor: default; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 5px; padding: 3px 6px; }
textarea { width: 100%; min-height: 60px; }

.top { position: sticky; top: 0; z-index: 10; display: flex; gap: 16px; align-items: center; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; text-decoration: none; color: var(--ink); }
#crumbs { flex: 1; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who input { width: 150px; margin-left: 6px; }
.who input:placeholder-shown { border-color: var(--fail); }

/* Library */
.library { max-width: 1100px; margin: 20px auto; padding: 0 16px; }
table.list { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); }
table.list th, table.list td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }

/* Document workspace */
.work { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); height: calc(100vh - 45px); }
.viewer { overflow: auto; padding: 12px; background: #8a918d33; }
.page { position: relative; margin: 0 auto 12px; background: #fff; box-shadow: 0 1px 4px #0003; }
.page canvas { display: block; }
.page .pno { position: absolute; top: 4px; left: -2px; transform: translateX(-100%); font-size: 11px; color: var(--muted); padding-right: 6px; }
.textLayer span.hl, .textLayer br.hl { background: var(--hl); }
.textLayer span.hl-token { background: var(--hl-token); border-radius: 2px; }
.side { overflow: auto; background: var(--bg); border-left: 1px solid var(--line); display: flex; flex-direction: column; }
.tabs { display: flex; gap: 2px; padding: 8px 12px 0; position: sticky; top: 0; background: var(--bg); z-index: 5; }
.tabs button { border-radius: 6px 6px 0 0; border-bottom: none; }
.tabs button.on { background: var(--panel); font-weight: 600; }
.pane { padding: 12px; }

/* The selection bar */
.stick { position: sticky; top: 36px; z-index: 4; background: var(--bg); padding-bottom: 2px; }
.pickbar { background: var(--pick); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 0 12px 4px; }
.pickbar .q { font-family: ui-monospace, Consolas, monospace; font-size: 12px; word-break: break-word; }
.pickbar .chips { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px; }
.chip { border-radius: 12px; padding: 1px 8px; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.pickbar .hint { color: var(--muted); font-size: 12px; }

/* Cards and fields */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; }
.card h3 { margin: 0 0 8px; font-size: 14px; display: flex; gap: 8px; align-items: center; }
.card h3 .grow { flex: 1; }
.grade { font-weight: 700; border-radius: 5px; padding: 1px 7px; background: var(--info-bg); color: var(--info); font-size: 12px; }
.fields { display: grid; grid-template-columns: 150px 1fr auto; gap: 3px 8px; align-items: center; }
.fields .k { color: var(--muted); font-size: 12px; }
.fields .v { min-height: 22px; word-break: break-word; }
.fields .acts { display: flex; gap: 3px; justify-content: flex-end; }
.none { color: var(--muted); font-style: italic; }
.st { display: inline-block; min-width: 18px; text-align: center; border-radius: 4px; font-size: 11px; font-weight: 700; padding: 0 4px; margin-left: 4px; cursor: pointer; }
.st.pass { background: var(--pass-bg); color: var(--pass); }
.st.flag { background: var(--flag-bg); color: var(--flag); }
.st.fail { background: var(--fail-bg); color: var(--fail); }
.st.nosrc { background: var(--flag-bg); color: var(--flag); }
.st.ok { background: var(--confirmed); color: var(--panel); }
.sub { margin: 6px 0 0 12px; padding-left: 10px; border-left: 2px solid var(--line); }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

/* Value grid */
table.grid { border-collapse: collapse; margin: 4px 0 10px; font-size: 12.5px; }
table.grid th, table.grid td { border: 1px solid var(--line); padding: 2px 6px; text-align: right; }
table.grid th { background: var(--bg); font-weight: 600; color: var(--muted); }
table.grid th.l, table.grid td.l { text-align: left; }
table.grid td.cell { cursor: pointer; min-width: 52px; font-family: ui-monospace, Consolas, monospace; }
table.grid td.cell:hover { outline: 2px solid var(--accent); }
td.cell.pass { background: var(--pass-bg); } td.cell.flag { background: var(--flag-bg); } td.cell.fail { background: var(--fail-bg); }
td.cell.ok, td.cell.auto { box-shadow: inset 3px 0 0 var(--confirmed); }
.st.auto { background: var(--pass-bg); color: var(--confirmed); border: 1px solid var(--confirmed); }
td.cell.sel { outline: 2px solid var(--accent); }
.mname { font-weight: 600; margin-top: 8px; }

/* Inspector */
.inspect { background: var(--panel); border: 1px solid var(--accent); border-radius: 8px; padding: 10px; margin: 0 12px 10px; }
.inspect .q { font-family: ui-monospace, Consolas, monospace; font-size: 12px; background: var(--bg); padding: 4px 6px; border-radius: 4px; margin: 4px 0; word-break: break-word; }

/* Findings */
.finding { border: 1px solid var(--line); border-left-width: 5px; border-radius: 6px; padding: 7px 10px; margin-bottom: 7px; background: var(--panel); }
.finding.conflict { border-left-color: var(--fail); }
.finding.warning { border-left-color: var(--flag); }
.finding.info { border-left-color: var(--info); }
.finding.agrees { border-left-color: var(--pass); }
.finding .sev { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.finding.conflict .sev { color: var(--fail); } .finding.warning .sev { color: var(--flag); } .finding.info .sev { color: var(--info); } .finding.agrees .sev { color: var(--pass); }
.finding .res { color: var(--muted); font-size: 12px; margin-top: 4px; }
.counts { display: flex; gap: 10px; margin: 6px 0 10px; flex-wrap: wrap; }
.counts span { padding: 2px 8px; border-radius: 10px; font-size: 12px; }

#toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 80vw; }
#toast.on { opacity: .95; }
#toast.err { background: var(--fail); color: #fff; }

@media (max-width: 900px) {
  .work { grid-template-columns: 1fr; height: auto; }
  .viewer { height: 60vh; }
  .fields { grid-template-columns: 110px 1fr; }
  .fields .acts { grid-column: 1 / -1; justify-content: flex-start; }
}

/* ---------- Dashboard ---------- */
.navlink { color: var(--muted); text-decoration: none; font-size: 13px; }
.navlink:hover { color: var(--accent); }
.viz-root { --series-1: #2a78d6; --grid: #e4e6e1; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .viz-root { --series-1: #3987e5; --grid: #333b37; } }
:root[data-theme="dark"] .viz-root { --series-1: #3987e5; --grid: #333b37; }
.dash { max-width: 1200px; margin: 16px auto 48px; padding: 0 16px; }
.dash-top { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.dash-top h2 { margin: 0; }
.dash section { margin-top: 24px; }
.dash h3 { margin: 0 0 4px; font-size: 15px; }
.muted { color: var(--muted); }
.dash p.muted { margin: 0 0 8px; font-size: 13px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-top: 12px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.tile-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.tile-value { font-size: 24px; font-weight: 700; margin: 2px 0; font-variant-numeric: tabular-nums; }
.tile-sub { font-size: 12px; color: var(--muted); }
.filters { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; margin-bottom: 12px; font-size: 13px; }
.filters input:not([type]) { width: 120px; }
.seg { display: inline-flex; margin-left: auto; }
.seg button { border-radius: 0; } .seg button:first-child { border-radius: 6px 0 0 6px; } .seg button:last-child { border-radius: 0 6px 6px 0; }
.seg button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.res-head p { max-width: 900px; }
.bars { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px 12px; }
.bar-axis, .bar-row { display: grid; grid-template-columns: minmax(140px, 32%) 1fr; gap: 10px; align-items: center; }
.axis-track { position: relative; height: 18px; font-size: 11px; color: var(--muted); }
.axis-track .tick { position: absolute; transform: translateX(-50%); white-space: nowrap; font-variant-numeric: tabular-nums; }
.bar-group { display: flex; gap: 8px; align-items: baseline; margin: 10px 0 2px; font-size: 12px; font-weight: 600; color: var(--muted); }
.bar-row { min-height: 26px; border-radius: 4px; outline: none; }
.bar-row:hover, .bar-row:focus { background: var(--bg); }
.bar-label { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { position: relative; height: 26px; }
.bar-track .grid { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--grid); }
.bar-track .zero { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--muted); }
.bar { position: absolute; top: 6px; height: 14px; background: var(--series-1); }
.bar.pos { border-radius: 0 4px 4px 0; } .bar.neg { border-radius: 4px 0 0 4px; }
.bar-val { position: absolute; top: 5px; font-size: 11.5px; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--ink); }
.bar-val.pos { padding-left: 4px; } .bar-val.neg { padding-right: 4px; }
.viz-tip { position: fixed; z-index: 50; max-width: 290px; background: var(--panel); color: var(--ink); border: 1px solid var(--line); box-shadow: 0 4px 14px #0003; border-radius: 8px; padding: 8px 10px; font-size: 12.5px; pointer-events: none; opacity: 0; transition: opacity .1s; }
.viz-tip.on { opacity: 1; }
.viz-tip div { margin-top: 2px; }
.scroll { overflow-x: auto; }
table.list td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.list tr.dup td { color: var(--muted); }
.badge { display: inline-block; white-space: nowrap; border-radius: 10px; padding: 1px 8px; font-size: 12px; font-weight: 600; }
.badge.fail { background: var(--fail-bg); color: var(--fail); } .badge.flag { background: var(--flag-bg); color: var(--flag); }
.badge.pass { background: var(--pass-bg); color: var(--pass); } .badge.none { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
@media (max-width: 700px) {
  .bar-axis, .bar-row { grid-template-columns: 1fr; gap: 0; }
  .bar-axis > div:first-child { display: none; }
  .seg { margin-left: 0; }
}
.tile-value.small { font-size: 16px; line-height: 1.5; }
.bar.over.pos { border-radius: 0; background: linear-gradient(90deg, var(--series-1) calc(100% - 7px), transparent calc(100% - 7px), transparent calc(100% - 4px), var(--series-1) calc(100% - 4px)); }
.bar.over.neg { border-radius: 0; background: linear-gradient(90deg, var(--series-1) 4px, transparent 4px, transparent 7px, var(--series-1) 7px); }

/* ---------- Research summary ---------- */
.headline { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 4px 14px; margin-top: 12px; max-width: 980px; }
.headline p { margin: 10px 0; line-height: 1.5; }
.headline p.warn { border-left: 3px solid var(--flag); padding-left: 10px; }
.ask { display: flex; gap: 8px; margin: 8px 0; }
.ask-input { flex: 1; font-size: 15px; padding: 8px 10px; min-width: 0; }
.examples { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }
.examples .chip { font-family: inherit; }
.filters.read { margin-top: 8px; }
.answer-card { margin-top: 8px; }
.answer-card .big { font-size: 16px; line-height: 1.45; }
.caveats { margin: 6px 0 2px; padding-left: 18px; color: var(--muted); font-size: 13px; }
td.quote { font-family: ui-monospace, Consolas, monospace; font-size: 11.5px; color: var(--muted); min-width: 220px; }
table.matrix td.clickable { cursor: pointer; white-space: nowrap; }
table.matrix td.clickable:hover, table.matrix td.clickable:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
table.matrix td.empty { color: var(--muted); text-align: center; }
table.matrix .n { color: var(--muted); font-size: 12px; }
table.matrix th[scope="row"] { text-align: left; }
.cols { display: flex; align-items: flex-end; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; overflow-x: auto; }
.col { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 38px; }
.col-bar { width: 22px; background: var(--series-1); border-radius: 4px 4px 0 0; display: block; }
.col-bar.muted-bar { background: var(--grid); }
.col-val { font-size: 12px; font-variant-numeric: tabular-nums; }
.col-label { font-size: 11.5px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 3px; width: 100%; text-align: center; }
.top { flex-wrap: wrap; row-gap: 6px; }
#crumbs { min-width: 0; }
@media (max-width: 700px) { #crumbs { display: none; } .who input { width: 120px; } .top { gap: 6px 14px; } }
.by-outcome { margin: 6px 0 10px; padding-left: 18px; line-height: 1.6; }

/* ---------- Hosted portal (read-only) ---------- */
body.ro .row-actions button:not(.keep), body.ro .inspect .row-actions button:not(.keep) { display: none; }
.login { max-width: 380px; margin: 48px auto; padding: 0 16px; }
.login form { display: flex; flex-direction: column; gap: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px; margin-top: 12px; }
.login label { font-size: 13px; color: var(--muted); margin-top: 6px; }
.login input { font-size: 15px; padding: 7px 9px; }
.login button { margin-top: 12px; padding: 7px; }
.login-err { color: var(--fail); min-height: 1.2em; margin: 4px 0 0; font-size: 13px; }
.small-print { font-size: 12.5px; }
body.out .navlink { display: none; }
.who { display: flex; gap: 10px; align-items: center; }
