/* Payroll Audit Agent: an operator's console. Cool ledger neutrals, one deep-teal accent, semantic severity colors. */
:root {
  --bg: #F3F6F7; --surface: #FFFFFF; --surface-2: #EDF1F3; --ink: #14212B; --muted: #5A6A76; --line: #D9E1E6;
  --accent: #0F6E66; --accent-ink: #FFFFFF; --accent-soft: #E1F0EE;
  --crit: #B42318; --crit-bg: #FDECEA; --high: #A84B05; --high-bg: #FDEFE1; --med: #7D6200; --med-bg: #FAF2D3;
  --ok: #1D7646; --ok-bg: #E4F3EA; --info: #3A5A78; --info-bg: #E8EFF6;
  --f-display: "IBM Plex Sans Condensed", "Arial Narrow", system-ui, sans-serif;
  --f-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --r: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0D141A; --surface: #141F27; --surface-2: #1A2731; --ink: #E3EBF0; --muted: #93A3AF; --line: #263540;
    --accent: #4CBFB2; --accent-ink: #062521; --accent-soft: #143633;
    --crit: #F9786D; --crit-bg: #3A1B19; --high: #F8B04A; --high-bg: #382814; --med: #E6C653; --med-bg: #322B12;
    --ok: #4CCB8A; --ok-bg: #12301F; --info: #93B8DC; --info-bg: #182A3B;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--f-body); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4 { font-family: var(--f-display); margin: 0; text-wrap: balance; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: var(--accent); }
.mono, .n { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
button { font: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, a:focus-visible, summary:focus-visible, textarea:focus-visible, .dropzone:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.hint { font-size: 12.5px; color: var(--muted); }

/* Top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; padding-top: env(safe-area-inset-top, 0px); }
.topbar-inner { max-width: 1200px; margin: 0 auto; padding: 10px max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px)); display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--f-display); font-weight: 600; font-size: 16px; }
.mark { width: 18px; height: 18px; border-radius: 4px; background: linear-gradient(135deg, var(--accent) 0 50%, color-mix(in srgb, var(--accent) 45%, var(--surface)) 50% 100%); }
.pill { font-family: var(--f-mono); font-size: 11px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.session { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); }

.wrap { max-width: 1200px; margin: 0 auto; padding-block: 26px 48px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); display: grid; gap: 20px; }
.eyebrow { font-family: var(--f-mono); font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
h1 { font-size: clamp(26px, 4vw, 36px); font-weight: 700; line-height: 1.1; }
.lede { color: var(--muted); max-width: 72ch; margin-top: 8px; }

/* Buttons and fields */
.btn { border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 8px 14px; border-radius: 7px; font-size: 13.5px; font-weight: 500; display: inline-flex; gap: 6px; align-items: center; white-space: nowrap; }
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.06); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); padding: 6px 10px; }
.btn.small { padding: 4px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.field { display: grid; gap: 4px; }
.field label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.field input, textarea { padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); font: inherit; font-size: 13.5px; }
.field input[type="number"] { width: 110px; font-family: var(--f-mono); }

/* Stepper */
.stepper { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.step-btn { display: flex; gap: 10px; align-items: center; text-align: left; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); color: var(--muted); min-width: 0; }
.step-btn .n { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-family: var(--f-mono); font-size: 13px; border: 1.5px solid var(--line); background: var(--surface); }
.step-btn .t { display: grid; min-width: 0; }
.step-btn b { font-family: var(--f-display); font-size: 16px; font-weight: 600; color: var(--ink); }
.step-btn small { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.step-btn:disabled { cursor: default; opacity: .6; }
.step-btn.current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.step-btn.current .n { border-color: var(--accent); color: var(--accent); }
.step-btn.done .n { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* Stage */
.stage { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; display: grid; gap: 18px; }
.stage-head { display: flex; justify-content: space-between; gap: 16px 24px; align-items: flex-start; flex-wrap: wrap; }
.stage-head > div:first-child { flex: 1 1 420px; min-width: 0; }
.stage-head h2 { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.stage-head p { color: var(--muted); max-width: 75ch; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.stage-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 16px; }
.stage-foot .hint { flex: 1 1 300px; }
.stage h3 { font-size: 15px; font-weight: 600; }

/* Ingest */
.dropzone { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 22px; border: 1.5px dashed color-mix(in srgb, var(--accent) 45%, var(--line)); border-radius: var(--r); background: color-mix(in srgb, var(--accent-soft) 45%, var(--surface)); cursor: pointer; text-align: center; flex-wrap: wrap; }
.dropzone.over { background: var(--accent-soft); border-color: var(--accent); }
.dz-icon { width: 30px; height: 36px; border: 2px solid var(--accent); border-radius: 3px 10px 3px 3px; position: relative; flex: none; }
.dz-icon::after { content: "CSV"; position: absolute; inset: auto 0 4px 0; font: 600 8px var(--f-mono); color: var(--accent); text-align: center; }
.dz-text { color: var(--muted); }
.dz-text b { color: var(--ink); }
.samples { border: 1px solid var(--line); border-radius: var(--r); padding: 10px 14px; background: var(--surface-2); }
.samples summary { cursor: pointer; font-weight: 500; }
.samples p { color: var(--muted); margin: 8px 0; max-width: 80ch; }
.sample-links { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 6px 16px; }
.sample-links li { display: flex; justify-content: space-between; gap: 8px; }
.sample-links span { color: var(--muted); font-family: var(--f-mono); font-size: 12px; }
.slots { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; align-items: start; }
.slot { border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; display: grid; gap: 8px; align-content: start; min-width: 0; background: var(--surface); }
.slot.ready { border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); }
.slot.error { border-color: var(--crit); }
.slot-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.slot-head b { font-family: var(--f-display); font-size: 15px; font-weight: 600; }
.tag { font-family: var(--f-mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.slot .fname { font-family: var(--f-mono); font-size: 12px; word-break: break-all; }
.slot .meta { font-size: 12px; color: var(--muted); display: grid; gap: 1px; }
.slot .meta .mono { font-size: 11.5px; }
.slot .state { font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.slot .state.ok { color: var(--ok); }
.slot .state.err { color: var(--crit); }
.bar { height: 4px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .25s ease; }
.slot .empty-note { color: var(--muted); font-size: 12.5px; }
.slot-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.linkbtn { border: 0; background: none; color: var(--accent); padding: 0; font-size: 12.5px; text-decoration: underline; text-underline-offset: 2px; }
.mapping { width: 100%; font-size: 12px; border-collapse: collapse; }
.mapping td { padding: 3px 0; border-bottom: 1px dotted var(--line); vertical-align: top; }
.mapping td:last-child { text-align: right; color: var(--muted); }
.mapping .sens { color: var(--high); }
.checks { border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; display: grid; gap: 10px; }
.checks ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.checks li { display: flex; gap: 10px; align-items: baseline; animation: fadein .25s ease both; }
.checks li .ic { flex: none; width: 18px; height: 18px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 11px; font-weight: 700; transform: translateY(3px); }
.ic.ok { background: var(--ok-bg); color: var(--ok); }
.ic.warn { background: var(--med-bg); color: var(--med); }
.ic.lock { background: var(--info-bg); color: var(--info); }
.ic.err { background: var(--crit-bg); color: var(--crit); }
@keyframes fadein { from { opacity: .0; transform: translateY(2px); } to { opacity: 1; transform: none; } }

/* Reconcile */
.settings { border: 1px solid var(--line); border-radius: var(--r); padding: 10px 14px; }
.settings summary { cursor: pointer; font-weight: 500; }
.thresholds { display: flex; flex-wrap: wrap; gap: 12px 20px; margin: 12px 0 8px; }
.runlog { list-style: none; margin: 0; padding: 14px 16px; border-radius: var(--r); background: var(--surface-2); display: grid; gap: 9px; font-size: 13px; }
.runlog li { display: grid; grid-template-columns: 20px minmax(0, 1fr) auto; gap: 10px; align-items: start; }
.runlog .sp { width: 16px; height: 16px; border-radius: 50%; margin-top: 2px; }
.runlog li.pending .sp { border: 2px solid var(--line); }
.runlog li.running .sp { border: 2px solid var(--line); border-top-color: var(--accent); animation: spin .7s linear infinite; }
.runlog li.done .sp { background: var(--accent); position: relative; }
.runlog li.done .sp::after { content: ""; position: absolute; left: 5px; top: 2px; width: 4px; height: 8px; border: solid var(--accent-ink); border-width: 0 2px 2px 0; transform: rotate(45deg); }
.runlog li.pending { color: var(--muted); }
.runlog .ttl { font-weight: 500; }
.runlog .note { display: block; color: var(--muted); font-size: 12.5px; }
.runlog .cnt { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .runlog li.running .sp { animation: none; border-top-color: var(--accent); } .checks li { animation: none; } }

.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; display: grid; gap: 2px; min-width: 0; }
.kpi .label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.kpi .value { font-family: var(--f-mono); font-size: 21px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.kpi.alert .value { color: var(--crit); }
.kpi.good .value { color: var(--ok); }
.toolbar { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 6px 12px; color: var(--muted); font-size: 13px; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }

.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); background: var(--surface-2); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
th.n, td.n { text-align: right; white-space: nowrap; }
.findings td:first-child { border-left: 3px solid transparent; }
.findings tr[data-sev="critical"] td:first-child { border-left-color: var(--crit); }
.findings tr[data-sev="high"] td:first-child { border-left-color: var(--high); }
.findings tr[data-sev="medium"] td:first-child { border-left-color: var(--med); }
.findings tr[data-sev="info"] td:first-child { border-left-color: var(--ok); }
.emp { display: grid; min-width: 120px; }
.emp b { font-family: var(--f-mono); font-weight: 500; }
.emp span { color: var(--muted); font-size: 12px; white-space: nowrap; }
.check { font-weight: 600; display: grid; gap: 5px; justify-items: start; min-width: 150px; }
.detail { min-width: 240px; max-width: 50ch; }
.ev { display: block; margin-top: 3px; font-size: 12px; color: var(--muted); }
.delta { font-family: var(--f-mono); font-size: 12.5px; min-width: 120px; }
.delta span { white-space: nowrap; }
.delta .arrow { color: var(--muted); padding: 0 4px; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; font-family: var(--f-body); }
.chip.critical { background: var(--crit-bg); color: var(--crit); }
.chip.high { background: var(--high-bg); color: var(--high); }
.chip.medium { background: var(--med-bg); color: var(--med); }
.chip.info, .chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.hold { background: var(--crit-bg); color: var(--crit); }
.chip.neutral { background: var(--surface); color: var(--muted); border: 1px solid var(--line); }
.empty { padding: 24px; text-align: center; color: var(--muted); }

/* Explain */
.explain-grid { display: grid; grid-template-columns: minmax(0, 320px) minmax(0, 1fr); gap: 16px; align-items: start; }
.sendbox { border: 1px solid var(--line); border-radius: var(--r); padding: 14px; display: grid; gap: 10px; background: var(--surface-2); }
.sendbox ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: 13px; display: grid; gap: 4px; }
.sendbox summary { cursor: pointer; font-size: 13px; color: var(--accent); }
.sendbox pre { margin: 8px 0 0; max-height: 280px; overflow: auto; font-family: var(--f-mono); font-size: 11px; line-height: 1.45; padding: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; white-space: pre-wrap; word-break: break-word; }
.ai-status { font-size: 12.5px; display: flex; gap: 8px; align-items: baseline; }
.ai-status .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; transform: translateY(-1px); }
.dot.live { background: var(--ok); }
.dot.off { background: var(--med); }
.memo { border: 1px solid var(--line); border-radius: var(--r); padding: 18px 22px; min-height: 320px; display: grid; gap: 8px; align-content: start; }
.memo-meta { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; border-bottom: 1px solid var(--line); padding-bottom: 10px; margin-bottom: 4px; }
.memo .src { font-family: var(--f-mono); font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
#memo-body { display: grid; gap: 8px; max-width: 78ch; }
#memo-body h4 { font-size: 15px; margin-top: 8px; }
#memo-body ul { margin: 0; padding-left: 18px; display: grid; gap: 6px; }
.thinking { color: var(--muted); font-style: italic; }
.cursor::after { content: "▍"; color: var(--accent); animation: blink 1s steps(2) infinite; margin-left: 1px; }
@keyframes blink { 50% { opacity: 0; } }

/* Decide */
.reviewer input { width: 220px; }
.gate { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 14px 18px; border-radius: var(--r); border: 1px solid; }
.gate.hold { background: var(--crit-bg); border-color: color-mix(in srgb, var(--crit) 35%, transparent); }
.gate.clear { background: var(--ok-bg); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.gate.done { background: var(--info-bg); border-color: color-mix(in srgb, var(--info) 35%, transparent); }
.gate-badge { font-family: var(--f-display); font-weight: 700; font-size: 14px; letter-spacing: .06em; text-transform: uppercase; padding: 4px 10px; border-radius: 6px; color: var(--surface); }
.gate.hold .gate-badge { background: var(--crit); }
.gate.clear .gate-badge { background: var(--ok); }
.gate.done .gate-badge { background: var(--info); }
.gate-text { flex: 1 1 320px; min-width: 0; }
.gate-text strong { font-family: var(--f-display); font-size: 17px; font-weight: 600; display: block; }
.gate-text span { color: var(--muted); font-size: 13px; }
.gate-progress { font-family: var(--f-mono); font-size: 13px; color: var(--muted); }
.queue { display: grid; gap: 10px; }
.item { border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: var(--r); padding: 12px 14px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px 16px; align-items: start; }
.item[data-sev="critical"] { border-left-color: var(--crit); }
.item[data-sev="high"] { border-left-color: var(--high); }
.item[data-sev="medium"] { border-left-color: var(--med); }
.item.resolved { background: color-mix(in srgb, var(--surface-2) 60%, var(--surface)); }
.item-main { display: grid; gap: 4px; min-width: 0; }
.item-top { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.item-top b { font-family: var(--f-display); font-size: 15.5px; font-weight: 600; }
.item-top .who { color: var(--muted); font-size: 12.5px; }
.item-top .who .mono { color: var(--ink); }
.item-detail { color: var(--ink); }
.item-side { display: grid; justify-items: end; gap: 8px; }
.item-side .amt { font-family: var(--f-mono); font-size: 14px; }
.item-acts { display: flex; gap: 6px; }
.item-acts button { border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 5px 11px; border-radius: 6px; font-size: 12.5px; }
.item-acts button:hover { background: var(--surface-2); }
.item-acts button.hold-btn:hover { border-color: var(--crit); color: var(--crit); }
.item-acts button.ok-btn:hover { border-color: var(--ok); color: var(--ok); }
.item-note { grid-column: 1 / -1; display: grid; gap: 6px; }
.item-note textarea { width: 100%; min-height: 54px; resize: vertical; }
.item-note .row { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.decision { grid-column: 1 / -1; font-size: 12.5px; color: var(--muted); display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.decision .linkbtn { font-size: 12px; }
.signoff { border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: grid; gap: 12px; }
.signoff-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.signoff-grid div { display: grid; gap: 2px; }
.signoff-grid dt { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.signoff-grid dd { margin: 0; font-family: var(--f-mono); font-size: 16px; }
.signoff .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.cert { border: 1px dashed color-mix(in srgb, var(--ok) 55%, var(--line)); background: var(--ok-bg); border-radius: var(--r); padding: 14px 16px; display: grid; gap: 6px; }
.cert strong { font-family: var(--f-display); font-size: 17px; }
.cert .mono { font-size: 12px; color: var(--muted); word-break: break-all; }
.audit { display: grid; gap: 8px; }
.audit ol { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--line); display: grid; gap: 8px; }
.audit li { padding-left: 14px; position: relative; font-size: 13px; display: grid; grid-template-columns: 78px minmax(0, 1fr); gap: 10px; }
.audit li::before { content: ""; position: absolute; left: -5px; top: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.audit time { font-family: var(--f-mono); font-size: 12px; color: var(--muted); }
.audit .who { color: var(--muted); }

.page-foot { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 14px; }

@media (max-width: 980px) {
  .slots { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .explain-grid { grid-template-columns: minmax(0, 1fr); }
  .signoff-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stepper small { display: none; }
}
@media (max-width: 560px) {
  .slots, .kpis { grid-template-columns: minmax(0, 1fr); }
  .stepper { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
  .step-btn { flex-direction: column; gap: 4px; padding: 8px 4px; text-align: center; }
  .step-btn b { font-size: 13px; }
  .item { grid-template-columns: minmax(0, 1fr); }
  .item-side { justify-items: start; }
  .stage { padding: 14px; }
}

/* Grid children must be allowed to shrink so wide tables scroll inside their own container */
.wrap > *, .stage > *, #rec-results > * { min-width: 0; }
