/* 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; }

/* ------------------------------------------------------------------ Lambert HR brand theme */
:root { --f-brand: var(--f-display); --topbar-bg: var(--surface); --topbar-ink: var(--ink); --topbar-line: var(--line); }
:root[data-brand="lambert"] {
  --bg: #F3F4F7; --surface: #FFFFFF; --surface-2: #ECEEF3; --ink: #1E2233; --muted: #5D6377; --line: #D9DCE5;
  --accent: #3A3F56; --accent-ink: #FFFFFF; --accent-soft: #E4E6EE;
  --topbar-bg: #2C3145; --topbar-ink: #FFFFFF; --topbar-line: #2C3145;
  --f-display: "Montserrat", "Helvetica Neue", Arial, sans-serif;
  --f-body: "Montserrat", "Helvetica Neue", Arial, sans-serif;
  --f-brand: "Cinzel", Georgia, "Times New Roman", serif;
}
@media (prefers-color-scheme: dark) {
  :root[data-brand="lambert"] {
    --bg: #11131C; --surface: #191C28; --surface-2: #212536; --ink: #E6E8F0; --muted: #9BA1B5; --line: #2B3043;
    --accent: #AEB5D1; --accent-ink: #151827; --accent-soft: #262B40;
    --topbar-bg: #1A1E2D; --topbar-ink: #FFFFFF; --topbar-line: #2B3043;
  }
}
.topbar { background: var(--topbar-bg); color: var(--topbar-ink); border-bottom-color: var(--topbar-line); }
.topbar .session { color: color-mix(in srgb, var(--topbar-ink) 70%, transparent); }
.topbar .btn.ghost { color: color-mix(in srgb, var(--topbar-ink) 80%, transparent); }
.topbar .btn.ghost:hover:not(:disabled) { background: color-mix(in srgb, var(--topbar-ink) 10%, transparent); }
.brand { color: var(--topbar-ink); min-width: 0; }
.brand-mark { width: 30px; height: 30px; flex: none; opacity: .95; }
.brand-word { display: grid; line-height: 1; font-family: var(--f-brand); text-transform: uppercase; letter-spacing: .06em; }
.brand-word b { font-weight: 600; font-size: 17px; }
.brand-word small { font-size: 10.5px; letter-spacing: .12em; margin-top: 2px; }
.brand-sep { width: 1px; height: 26px; background: color-mix(in srgb, var(--topbar-ink) 35%, transparent); margin: 0 4px; }
.brand-product { font-family: var(--f-body); font-weight: 500; font-size: 14px; letter-spacing: .02em; white-space: nowrap; }
:root[data-brand="lambert"] h1 { font-family: var(--f-brand); font-weight: 600; letter-spacing: .01em; }
:root[data-brand="lambert"] .stage-head h2, :root[data-brand="lambert"] .step-btn b { font-weight: 600; }
.ask-btn { background: transparent; color: var(--topbar-ink); border-color: color-mix(in srgb, var(--topbar-ink) 40%, transparent); }
.ask-btn:hover:not(:disabled) { background: color-mix(in srgb, var(--topbar-ink) 12%, transparent); }

/* Intro with client field */
.intro { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px 28px; flex-wrap: wrap; }
.intro-text { flex: 1 1 520px; min-width: 0; }
.client-field input { width: 240px; max-width: 100%; font-weight: 600; }
.settings-sub { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-top: 6px; font-family: var(--f-body); font-weight: 600; }

/* Value calculator */
div.value { border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: grid; gap: 14px; background: color-mix(in srgb, var(--accent-soft) 35%, var(--surface)); }
.value-head { display: flex; justify-content: space-between; gap: 12px 24px; align-items: flex-start; flex-wrap: wrap; }
.value-head > div:first-child { flex: 1 1 300px; min-width: 0; }
.value-hero { display: grid; justify-items: end; text-align: right; }
.value-hero .big { font-family: var(--f-mono); font-size: 28px; font-weight: 500; color: var(--crit); line-height: 1.1; }
.value-hero span:last-child { color: var(--muted); font-size: 13px; }
.value-inputs { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.value-inputs .field input { width: 100%; font-family: var(--f-mono); }
.value-out { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.value-out .kpi { background: var(--surface); }

/* Ask the agent drawer */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100%); z-index: 40; background: var(--surface); border-left: 1px solid var(--line); box-shadow: -12px 0 32px rgba(10, 14, 30, .18); display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto auto auto; padding: calc(14px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) calc(14px + env(safe-area-inset-bottom, 0px)) 16px; gap: 10px; }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.drawer-head h3 { font-size: 17px; }
.chat { overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px 2px; }
.chat-empty { color: var(--muted); font-size: 13.5px; padding: 8px 2px; }
.bubble { max-width: 92%; padding: 10px 12px; border-radius: 12px; font-size: 13.5px; display: grid; gap: 6px; }
.bubble.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.bubble.agent { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 4px; }
.bubble.agent ul { margin: 0; padding-left: 18px; display: grid; gap: 4px; }
.bubble.agent h4 { font-size: 13.5px; }
.bubble.err { background: var(--crit-bg); color: var(--crit); }
.suggest { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-btn { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px; padding: 5px 11px; font-size: 12.5px; }
.chip-btn:hover { border-color: var(--accent); color: var(--accent); }
.ask-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: end; }
.ask-form textarea { resize: none; min-height: 44px; font: inherit; font-size: 13.5px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 980px) {
  .value-inputs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .brand-product, .brand-sep, .run-id { display: none; }
  .value-inputs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .value-out { grid-template-columns: minmax(0, 1fr); }
  .value-hero { justify-items: start; text-align: left; }
  .client-field input { width: 100%; }
  .client-field { flex: 1 1 100%; }
}

/* ------------------------------------------------------------------ Toolkit shared additions */
.brand-home { display: inline-flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.brand-link { color: inherit; text-decoration: none; opacity: .85; }
.brand-link:hover { opacity: 1; text-decoration: underline; text-underline-offset: 3px; }
.brand-crumb { opacity: .5; padding: 0 2px; }
.stepper { grid-template-columns: repeat(var(--steps, 4), minmax(0, 1fr)); }
@media (max-width: 560px) { .stepper { grid-template-columns: repeat(var(--steps, 4), minmax(0, 1fr)); } }

/* Chart tokens: categorical slots validated for light and dark (dataviz reference palette) */
:root { --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --viz-grid: color-mix(in srgb, var(--line) 70%, transparent); }
@media (prefers-color-scheme: dark) { :root { --s1: #3987e5; --s2: #d95926; --s3: #199e70; } }
.viz { margin: 0; display: grid; gap: 6px; min-width: 0; }
.viz svg { width: 100%; height: auto; display: block; overflow: visible; }
.viz-grid { stroke: var(--viz-grid); stroke-width: 1; }
.viz-base { stroke: var(--muted); stroke-width: 1; opacity: .6; }
.viz-axis { font: 11px var(--f-mono); fill: var(--muted); }
.viz-mark.s1, .hb-bar.s1, .viz-legend i.s1 { fill: var(--s1); background: var(--s1); }
.viz-mark.s2, .hb-bar.s2, .viz-legend i.s2 { fill: var(--s2); background: var(--s2); }
.viz-mark.s3, .hb-bar.s3, .viz-legend i.s3 { fill: var(--s3); background: var(--s3); }
.hb-bar.crit { background: var(--crit); } .hb-bar.high { background: var(--high); } .hb-bar.med { background: var(--med); } .hb-bar.ok { background: var(--ok); } .hb-bar.muted { background: color-mix(in srgb, var(--muted) 55%, var(--surface)); }
.viz-mark.em { stroke: var(--ink); stroke-width: 1.5; }
.viz-hit { fill: transparent; cursor: default; outline: none; }
.viz-hit.hot, .viz-hit:focus-visible { fill: color-mix(in srgb, var(--ink) 6%, transparent); }
.viz-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.viz-legend span { display: inline-flex; align-items: center; gap: 6px; }
.viz-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.viz-legend i.marker { width: 2px; height: 12px; border-radius: 0; background: var(--ink); }
.hbars { gap: 4px; }
.hb-row { display: grid; grid-template-columns: minmax(90px, 30%) minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 3px 4px; border-radius: 6px; outline: none; }
.hb-row.hot, .hb-row:focus-visible { background: var(--surface-2); }
.hb-label { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hb-track { position: relative; height: 14px; }
.hb-bar { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 0 4px 4px 0; min-width: 2px; }
.hb-marker { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink); opacity: .7; }
.hb-val { font-family: var(--f-mono); font-size: 12.5px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.hb-val small { color: var(--muted); font-family: var(--f-body); }
.viz-tip { position: fixed; z-index: 60; pointer-events: none; background: var(--ink); color: var(--surface); font-size: 12px; line-height: 1.4; padding: 6px 9px; border-radius: 6px; max-width: 280px; box-shadow: 0 6px 18px rgba(0,0,0,.18); }
.meter { display: inline-flex; width: 120px; height: 8px; border-radius: 6px; background: var(--surface-2); overflow: hidden; vertical-align: middle; gap: 2px; outline: none; }
.meter i { display: block; height: 100%; }
.meter i.ok { background: var(--ok); }
.meter i.bad { background: var(--crit); }

/* Panels, tabs, flags */
.panel { border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; display: grid; gap: 12px; min-width: 0; align-content: start; }
.panel-head { display: flex; justify-content: space-between; gap: 8px 16px; align-items: baseline; flex-wrap: wrap; }
.panel-head h3 { font-size: 15px; }
.panel-head .hint { margin: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.grid-2 > *, .grid-3 > * { min-width: 0; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 9px 14px; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.tabpanel { display: grid; gap: 14px; padding-top: 4px; }
.flags { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.flag { border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: var(--r); padding: 10px 14px; display: grid; gap: 3px; }
.flag[data-sev="critical"] { border-left-color: var(--crit); }
.flag[data-sev="high"] { border-left-color: var(--high); }
.flag[data-sev="medium"] { border-left-color: var(--med); }
.flag[data-sev="good"], .flag[data-sev="info"] { border-left-color: var(--ok); }
.flag-top { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.flag-top b { font-family: var(--f-display); font-size: 15px; font-weight: 600; }
.flag p { color: var(--ink); }
.flag .ev { margin: 0; }
.kpi .delta-up { color: var(--crit); } .kpi .delta-down { color: var(--ok); } .kpi .delta-flat { color: var(--muted); }
.kpis.k4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpis.k5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.value-inputs { grid-template-columns: repeat(var(--cols, 5), minmax(0, 1fr)); }
.banner { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: var(--r); background: var(--info-bg); color: var(--ink); border: 1px solid color-mix(in srgb, var(--info) 30%, transparent); font-size: 13px; }
.banner b { color: var(--info); }
.banner.warn { background: var(--med-bg); border-color: color-mix(in srgb, var(--med) 35%, transparent); }
.banner.warn b { color: var(--med); }
.doc-edit { width: 100%; min-height: 260px; font: 13.5px/1.55 var(--f-body); padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); color: var(--ink); resize: vertical; }
.doc-view { display: grid; gap: 8px; max-width: 80ch; }
.doc-view h4 { font-size: 15px; margin-top: 8px; }
.doc-view ul { margin: 0; padding-left: 18px; display: grid; gap: 5px; }
.status-line { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 16px; }
.form-grid .field input, .form-grid .field select, .form-grid .field textarea, .field select { width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); font: inherit; font-size: 13.5px; }
.form-grid .wide { grid-column: span 2; }
.form-grid .full { grid-column: 1 / -1; }
.field textarea { min-height: 84px; resize: vertical; }
.lint { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 13px; }
.lint li { display: flex; gap: 8px; align-items: baseline; }
.cand { border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; display: grid; gap: 10px; min-width: 0; }
.cand-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.cand-head b { font-family: var(--f-display); font-size: 16px; }
.cand pre { margin: 0; white-space: pre-wrap; font: 12px/1.5 var(--f-mono); max-height: 220px; overflow: auto; background: var(--surface-2); padding: 10px; border-radius: 6px; }
.small-table td, .small-table th { padding: 6px 8px; }
.mini { font-size: 12px; color: var(--muted); }
td .chip { vertical-align: middle; }
.pos { color: var(--crit); } .neg { color: var(--ok); }

@media (max-width: 980px) {
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis.k4, .kpis.k5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .value-inputs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid .wide { grid-column: auto; }
  .value-inputs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hb-row { grid-template-columns: minmax(70px, 34%) minmax(0, 1fr) auto; }
}
@media (max-width: 560px) { .kpis.k4, .kpis.k5 { grid-template-columns: minmax(0, 1fr); } }

/* ------------------------------------------------------------------ Hub */
.hub-hero { display: grid; gap: 10px; padding: 8px 0 4px; }
.hub-hero .tagline { font-family: var(--f-brand); letter-spacing: .14em; text-transform: uppercase; font-size: 12px; color: var(--muted); }
.hub-hero h1 { font-size: clamp(30px, 5vw, 46px); }
.principles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.principle { border: 1px solid var(--line); background: var(--surface); border-radius: var(--r); padding: 12px 14px; display: grid; gap: 3px; }
.principle b { font-family: var(--f-display); font-size: 14.5px; }
.principle span { color: var(--muted); font-size: 13px; }
.modules { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.module { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 18px; display: grid; gap: 12px; grid-template-rows: auto auto 1fr auto; min-width: 0; }
.module-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.module-icon { width: 38px; height: 38px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.module-icon svg { width: 22px; height: 22px; }
.module h2 { font-size: 19px; }
.module p { color: var(--muted); }
.module ul { margin: 0; padding-left: 18px; display: grid; gap: 4px; font-size: 13px; }
.module .value-line { font-size: 13px; border-top: 1px solid var(--line); padding-top: 10px; }
.module .value-line b { color: var(--ink); }
.module-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.module .story { font-size: 12.5px; color: var(--muted); }
.hub-settings { display: flex; gap: 14px 24px; align-items: flex-end; flex-wrap: wrap; border: 1px solid var(--line); background: var(--surface); border-radius: var(--r); padding: 14px 16px; }
.hub-settings .hint { flex: 1 1 280px; }
@media (max-width: 860px) { .principles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 480px) { .principles { grid-template-columns: minmax(0, 1fr); } }

/* ------------------------------------------------------------------ Printable report */
.report-doc { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 26px 30px; display: grid; gap: 18px; }
.report-doc header { display: flex; justify-content: space-between; gap: 12px; align-items: flex-end; border-bottom: 2px solid var(--accent); padding-bottom: 12px; flex-wrap: wrap; }
.report-doc h2 { font-family: var(--f-brand); font-size: 24px; }
.report-doc h3 { font-size: 15px; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.report-doc section { display: grid; gap: 10px; break-inside: avoid; }
.report-doc .approved { font-size: 12.5px; color: var(--muted); }
@media print {
  @page { margin: 14mm; }
  body { background: #fff; color: #111; font-size: 11.5px; }
  body.printing > *:not(.print-root) { display: none !important; }
  .print-root { display: block !important; }
  .report-doc { border: 0; padding: 0; }
  .viz-tip, .drawer { display: none !important; }
  .kpi { break-inside: avoid; }
}
.print-root { display: none; }
.module-foot-wrap { display: grid; gap: 10px; align-self: end; }
.topbar .ai-status { color: inherit; }
.slots.auto { grid-template-columns: repeat(var(--slot-cols, 4), minmax(0, 1fr)); }
@media (max-width: 1100px) { .slots.auto { grid-template-columns: repeat(min(var(--slot-cols, 4), 3), minmax(0, 1fr)); } }
@media (max-width: 760px) { .slots.auto { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 480px) { .slots.auto { grid-template-columns: minmax(0, 1fr); } }
.module ul { align-content: start; }
a.btn { text-decoration: none; }
.value-hero .big.good { color: var(--ok); }
.rate-in { padding: 4px 6px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); color: var(--ink); font: 12.5px var(--f-mono); }
.intro-fields { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.intro-fields .client-field input { width: 200px; }
.ai-row { display: flex; gap: 10px 20px; align-items: flex-end; flex-wrap: wrap; }
.ai-row .ai-status { flex: 1 1 300px; }
.grid-2.wide-left { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.src { font-family: var(--f-mono); font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.redacted-list { margin: 0; padding-left: 18px; font-size: 12.5px; color: var(--muted); display: grid; gap: 2px; }
.seg.small button { padding: 4px 10px; font-size: 12px; }
.invite { border: 1px dashed var(--line); border-radius: var(--r); padding: 10px 12px; font-size: 13px; display: grid; gap: 4px; }
@media (max-width: 700px) { .grid-2.wide-left { grid-template-columns: minmax(0, 1fr); } .intro-fields .client-field input { width: 100%; } .intro-fields { flex: 1 1 100%; } }
.audit li > span { min-width: 0; overflow-wrap: anywhere; }
.banner > b { flex: none; }
.flag p, .item-detail, .detail { overflow-wrap: anywhere; }
.small-table td.mono, .small-table td .mini { white-space: nowrap; }
.file-slots { display: grid; gap: 12px; }
