:root {
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #f0f2f5; --fg: #18202e; --muted: #5d6879;
  --line: #e0e4ea; --accent: #2456c9; --accent-fg: #ffffff; --accent-soft: #e7edfb;
  --ok: #157347; --ok-soft: #e2f3e9; --bad: #b42318; --bad-soft: #fdecea; --warn: #9a6200;
  --warn-soft: #fbf1dc; --info: #0b6e8a; --info-soft: #e2f2f7; --mark: #fff3bf;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1218; --surface: #161b23; --surface-2: #1c222c; --fg: #e3e7ee; --muted: #97a2b4;
    --line: #283142; --accent: #7ea6ff; --accent-fg: #0e1218; --accent-soft: #1c2944;
    --ok: #5fd39a; --ok-soft: #14301f; --bad: #ff8a80; --bad-soft: #3a1714; --warn: #f0b85a;
    --warn-soft: #382a12; --info: #6fd0ea; --info-soft: #0f2c35; --mark: #4a3f10; --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1218; --surface: #161b23; --surface-2: #1c222c; --fg: #e3e7ee; --muted: #97a2b4;
  --line: #283142; --accent: #7ea6ff; --accent-fg: #0e1218; --accent-soft: #1c2944;
  --ok: #5fd39a; --ok-soft: #14301f; --bad: #ff8a80; --bad-soft: #3a1714; --warn: #f0b85a;
  --warn-soft: #382a12; --info: #6fd0ea; --info-soft: #0f2c35; --mark: #4a3f10; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--fg);
  font: 14.5px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 10px; }
h3 { font-size: 13.5px; margin: 14px 0 6px; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.hidden { display: none !important; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 10; background: var(--surface);
  border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 16px;
  padding: 10px 20px; flex-wrap: wrap;
}
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand .dot { width: 10px; height: 10px; border-radius: 3px; background: var(--accent); }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a { padding: 6px 10px; border-radius: 8px; color: var(--fg); }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.spacer { flex: 1; }
.who { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }

main.page { max-width: 1400px; margin: 0 auto; padding: 20px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }

/* cards and grids */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; min-width: 0;
}
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.stat { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; }
.stat b { display: block; font-size: 20px; margin-top: 2px; }
.sticky { position: sticky; top: 72px; }
@media (max-width: 1000px) {
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .sticky { position: static; }
  main.page { padding: 16px; }
  .topbar { padding: 10px 16px; }
}

/* buttons and forms */
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px;
  padding: 7px 12px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { border-color: var(--bad); color: var(--bad); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.sm { padding: 4px 9px; font-size: 13px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
input[type=text], input[type=password], input[type=number], select, textarea {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px;
  min-width: 0; width: 100%;
}
textarea { font-family: var(--mono); font-size: 12.5px; min-height: 160px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13.5px; }

/* drop zone */
.drop {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 26px; text-align: center;
  background: var(--surface-2); cursor: pointer; transition: border-color .15s, background .15s;
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.files { list-style: none; padding: 0; margin: 10px 0 0; }
.files li { display: flex; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.files li:last-child { border-bottom: 0; }

/* tables */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { text-align: left; padding: 7px 9px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12.5px; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
tr.selected td { background: var(--accent-soft); }
.jobs-table input { padding: 5px 6px; font-size: 13px; }
.jobs-table td { padding: 4px; }

/* pills */
.pill { display: inline-block; border-radius: 999px; padding: 1px 9px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.MATCH, .pill.done, .pill.pass, .pill.verified, .pill.agree { background: var(--ok-soft); color: var(--ok); }
.pill.MISMATCH, .pill.failed, .pill.fail, .pill.unverified, .pill.ours_match_only { background: var(--bad-soft); color: var(--bad); }
.pill.running, .pill.info { background: var(--info-soft); color: var(--info); }
.pill.warn, .pill.n8n_match_only, .pill.review { background: var(--warn-soft); color: var(--warn); }
.pill.queued, .pill.skipped, .pill.n\/a, .pill.neutral, .pill.ours_missing { background: var(--surface-2); color: var(--muted); }

/* result banner */
.banner { border-radius: var(--radius); padding: 16px 18px; display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.banner .big { font-size: 26px; font-weight: 800; letter-spacing: .5px; }
.banner.MATCH { background: var(--ok-soft); color: var(--ok); }
.banner.MISMATCH { background: var(--bad-soft); color: var(--bad); }
.banner.neutral { background: var(--surface-2); color: var(--fg); }
.banner ul { margin: 0; padding-left: 18px; color: var(--fg); }

/* stepper */
.steps { display: flex; gap: 0; list-style: none; padding: 0; margin: 0 0 16px; flex-wrap: wrap; }
.steps li { flex: 1 1 120px; display: flex; flex-direction: column; gap: 4px; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--line); margin-right: -1px; font-size: 13px; }
.steps li:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.steps li:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.steps li b { font-size: 13.5px; }
.steps li.done { background: var(--ok-soft); }
.steps li.active { background: var(--info-soft); }
.steps li.error { background: var(--bad-soft); }
.steps li .state { font-size: 12px; color: var(--muted); }
.spinner { display: inline-block; width: 11px; height: 11px; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

/* references and source */
.ref { font-family: var(--mono); font-size: 11.5px; border: 1px solid var(--line); background: var(--surface-2);
  border-radius: 6px; padding: 0 5px; cursor: pointer; color: var(--accent); white-space: nowrap; }
.ref:hover { border-color: var(--accent); }
.source { max-height: calc(100vh - 150px); overflow: auto; }
.source .part { font-size: 12.5px; color: var(--muted); margin: 10px 0 4px; font-weight: 600; }
.unit { display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: 8px; padding: 2px 6px; border-radius: 6px; font-size: 13px; }
.unit .uid { font-family: var(--mono); font-size: 11.5px; color: var(--muted); padding-top: 2px; overflow-wrap: anywhere; }
.unit .utext { white-space: pre-wrap; overflow-wrap: anywhere; }
.unit.used .uid { color: var(--accent); }
.unit.ocr .utext::after { content: " (scan)"; color: var(--muted); font-size: 11px; }
.unit.hl { background: var(--mark); outline: 1px solid var(--warn); }

.kv { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 4px 12px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.findings { list-style: none; padding: 0; margin: 0; }
.findings li { padding: 6px 0; border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: baseline; }
.findings li:last-child { border-bottom: 0; }

/* misc */
.empty { padding: 26px; text-align: center; color: var(--muted); }
.error-box { background: var(--bad-soft); color: var(--bad); border-radius: 8px; padding: 10px 12px; margin: 10px 0; }
.notice { background: var(--info-soft); color: var(--info); border-radius: 8px; padding: 10px 12px; margin: 10px 0; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.tabs button { border: 0; background: none; padding: 7px 12px; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
details > summary { cursor: pointer; color: var(--muted); }
pre.raw { max-height: 420px; overflow: auto; background: var(--surface-2); padding: 12px; border-radius: 8px; font-size: 12px; }
.bar { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }
.bar.warn > span { background: var(--warn); }
.bar.bad > span { background: var(--bad); }
.login { max-width: 420px; margin: 10vh auto; }
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--surface); border-radius: var(--radius); width: min(1100px, 100%); height: min(88vh, 900px); display: flex; flex-direction: column; overflow: hidden; }
.modal header { display: flex; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); gap: 10px; }
.modal iframe { border: 0; flex: 1; width: 100%; background: #fff; }
.toast { position: fixed; bottom: 16px; right: 16px; background: var(--fg); color: var(--bg); padding: 10px 14px; border-radius: 8px; z-index: 60; max-width: 420px; }
