:root {
    --bg: #f4f6fa;
    --surface: #ffffff;
    --border: #e1e6ee;
    --border-strong: #cbd3df;
    --text: #1d2633;
    --muted: #6b7686;
    --accent: #2457c5;
    --accent-soft: #e8efff;
    --bad: #c92a2a;
    --bad-soft: #ffe3e3;
    --bad-cell: #ffd8d8;
    --ok: #2b8a3e;
    --ok-soft: #e3f6e8;
    --warn-soft: #fff4d6;
    --mono: "Cascadia Mono", Consolas, "SFMono-Regular", Menlo, monospace;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
    /* one colour per distinct OrderType value */
    --ot0: #2457c5;
    --ot1: #d9480f;
    --ot2: #2b8a3e;
    --ot3: #9c36b5;
    --ot4: #0b7285;
    --ot5: #e67700;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
    background: var(--bg);
    color: var(--text);
    font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 22px; margin: 2px 0 4px; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0; font-family: var(--mono); }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.text-bad { color: var(--bad); }

/* ---------- top bar ---------- */
.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 28px;
    padding: 0 28px; height: 56px;
    background: #111a2b; color: #dfe6f2;
}
.brand { color: #fff; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.brand:hover { text-decoration: none; }
.brand-mark {
    display: inline-grid; place-items: center; width: 28px; height: 28px;
    border-radius: 7px; background: var(--bad); color: #fff; font-weight: 700;
}
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { color: #b9c4d6; padding: 6px 12px; border-radius: 6px; }
.topbar nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.topbar nav a.active { color: #fff; background: rgba(255,255,255,.12); }
.monitor-pill { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 12px; color: #b9c4d6; }
.monitor-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: #51cf66; box-shadow: 0 0 0 3px rgba(81,207,102,.2); }
.monitor-pill.is-error .dot { background: #ff6b6b; box-shadow: 0 0 0 3px rgba(255,107,107,.25); }

.user-box { display: flex; align-items: center; gap: 10px; margin-left: 8px; padding-left: 16px; border-left: 1px solid rgba(255,255,255,.15); }
.user-name { font-size: 12.5px; color: #dfe6f2; }
.btn-signout { background: transparent; border: 1px solid rgba(255,255,255,.25); color: #dfe6f2; border-radius: 6px; padding: 4px 10px; font: inherit; font-size: 12px; cursor: pointer; }
.btn-signout:hover { background: rgba(255,255,255,.1); }

/* sign-in page */
.login-wrap { display: grid; place-items: center; min-height: calc(100vh - 160px); }
.login-card { width: 100%; max-width: 400px; padding: 28px; }
.login-brand { display: flex; gap: 14px; align-items: center; margin-bottom: 22px; }
.login-brand .brand-mark { width: 40px; height: 40px; font-size: 20px; border-radius: 10px; flex: none; }
.login-brand h1 { font-size: 19px; margin: 0; }
.login-brand p { margin: 2px 0 0; font-size: 13px; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.login-form label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-weight: 500; }
.login-form input:not([type=checkbox]) { font: inherit; font-size: 14px; padding: 9px 11px; border: 1px solid var(--border-strong); border-radius: 7px; color: var(--text); }
.login-form input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.btn-block { width: 100%; padding: 10px; margin-top: 4px; }
code { font-family: var(--mono); font-size: 12px; background: #f1f3f5; padding: 1px 5px; border-radius: 4px; }

.container { max-width: 1440px; margin: 0 auto; padding: 24px 28px 60px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; }
.page-head p { margin: 0; }
.head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form { display: flex; gap: 6px; align-items: center; }
.inline-form input { font: inherit; padding: 7px 9px; border: 1px solid var(--border-strong); border-radius: 7px; }
.back { font-size: 12px; }

/* ---------- buttons, tags ---------- */
.btn {
    display: inline-block; border: 1px solid var(--accent); background: var(--accent); color: #fff;
    border-radius: 7px; padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { filter: brightness(1.07); text-decoration: none; }
.btn-light { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-small { padding: 4px 10px; font-size: 12px; }
.btn-link { align-self: center; font-size: 13px; }

.tag {
    display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
    background: #edf0f5; color: var(--muted);
}
.tag-ok { background: var(--ok-soft); color: var(--ok); }
.tag-bad { background: var(--bad-soft); color: var(--bad); }

.badge {
    display: inline-block; min-width: 22px; text-align: center;
    padding: 2px 9px; border-radius: 6px; font-weight: 700; font-size: 12.5px; color: #fff;
    background: var(--ot0); margin-right: 4px;
}
.badge-xs { padding: 0 5px; font-size: 10.5px; min-width: 0; margin-left: 4px; vertical-align: 1px; }
.ot-0 { background: var(--ot0); }
.ot-1 { background: var(--ot1); }
.ot-2 { background: var(--ot2); }
.ot-3 { background: var(--ot3); }
.ot-4 { background: var(--ot4); }
.ot-5 { background: var(--ot5); }

.flag { font-weight: 600; padding: 1px 8px; border-radius: 6px; }
.flag-on { background: var(--warn-soft); color: #8a5a00; }
.flag-off { background: #edf0f5; color: var(--muted); }

.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 7px; vertical-align: 0; }

.flash { background: var(--accent-soft); border: 1px solid #c6d6fb; padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.alert { background: var(--bad-soft); border: 1px solid #ffc9c9; color: #7d1a1a; padding: 12px 14px; border-radius: 8px; margin-bottom: 16px; }
.notice { background: var(--warn-soft); border: 1px solid #ffe08a; padding: 12px 14px; border-radius: 8px; margin-bottom: 16px; }

/* ---------- cards, KPIs ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 16px; }
.card.no-pad { padding: 0; overflow: hidden; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); border-top: 3px solid var(--border-strong); }
.kpi-wide { grid-column: span 2; }
.kpi-ok { border-top-color: var(--ok); }
.kpi-bad { border-top-color: var(--bad); }
.kpi-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.kpi-value { font-size: 26px; font-weight: 700; line-height: 1.1; }
.kpi-value-sm { font-size: 15px; line-height: 1.4; }
.kpi-of { font-size: 15px; color: var(--muted); font-weight: 500; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* ---------- filters ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; padding: 14px 18px; }
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.filters label.check { flex-direction: row; align-items: center; gap: 6px; padding-bottom: 8px; color: var(--text); }
.filters input, .filters select { font: inherit; padding: 7px 9px; border: 1px solid var(--border-strong); border-radius: 7px; background: #fff; min-width: 150px; }

/* ---------- tables ---------- */
.grid { width: 100%; border-collapse: separate; border-spacing: 0; }
.grid th, .grid td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; white-space: nowrap; }
.grid thead th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #f8f9fc; font-weight: 600; }
.grid tbody tr:last-child > * { border-bottom: none; }
.grid.list tbody tr:hover { background: #fafbfe; }
.grid .empty { text-align: center; color: var(--muted); padding: 28px; }
.grid .actions { display: flex; gap: 6px; }
.row-bad td:first-child { box-shadow: inset 3px 0 0 var(--bad); }

.scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
.scroll .grid th.sticky { position: sticky; left: 0; z-index: 1; background: #fbfcfe; box-shadow: 1px 0 0 var(--border); }
.scroll .grid thead th.sticky { background: #f8f9fc; }

.matrix td { text-align: right; }
.matrix th.col-diff { color: var(--bad); }
.matrix tr.majority > * { background: #f8f9fc; color: var(--muted); font-style: italic; }

.cell-diff { background: var(--bad-cell) !important; color: #8b0f0f; font-weight: 700; }
.cell-missing { color: #98a2b3; background: repeating-linear-gradient(45deg, #fafafa, #fafafa 4px, #f0f1f4 4px, #f0f1f4 8px); }
.cell-ignored { background: #f1f3f5; color: #868e96; text-decoration: line-through dotted; }

.meter { display: inline-block; width: 80px; height: 7px; border-radius: 4px; background: #edf0f5; vertical-align: middle; margin-right: 6px; overflow: hidden; }
.meter-wide { width: 160px; }
.meter-fill { height: 100%; background: linear-gradient(90deg, #ff8787, var(--bad)); border-radius: 4px; }

/* ---------- report ---------- */
.results td:first-child { font-size: 14px; }
.ot-groups { display: flex; flex-wrap: wrap; gap: 10px 24px; margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--border); }
.ot-group { display: flex; align-items: center; gap: 4px; font-size: 13px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 18px; align-items: center; justify-content: space-between; margin: 22px 0 10px; }
.switch { display: flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; }
.switch input { width: 16px; height: 16px; accent-color: var(--accent); }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); }
.lg { display: inline-block; width: 14px; height: 14px; border-radius: 3px; vertical-align: -2px; margin-right: 4px; border: 1px solid var(--border-strong); }
.lg-diff { background: var(--bad-cell); border-color: #ffa8a8; }
.lg-missing { background: repeating-linear-gradient(45deg, #fafafa, #fafafa 3px, #e5e7eb 3px, #e5e7eb 6px); }
.lg-ignored { background: #f1f3f5; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.chip {
    display: inline-flex; gap: 6px; align-items: center;
    padding: 4px 10px; border-radius: 999px; font-family: var(--mono); font-size: 12px;
    border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
}
.chip:hover { text-decoration: none; border-color: var(--accent); }
.chip b { background: var(--bad); color: #fff; border-radius: 999px; padding: 0 6px; font-size: 11px; }
.chip-bad { border-color: #ffa8a8; background: #fff5f5; }
.chip-ok span { color: var(--ok); }
.chip-ignored { color: var(--muted); border-style: dashed; }

.section { scroll-margin-top: 70px; }
.section-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.section-head .kind { font-size: 12px; color: var(--muted); }
.section-mismatch { border-left: 4px solid var(--bad); }
.section-ignored { opacity: .75; }

.chart-wrap { position: relative; height: 260px; margin-top: 14px; }

.raw { border-top: 1px solid var(--border); padding: 8px 0; }
.raw:first-of-type { border-top: none; }
.raw summary { cursor: pointer; font-weight: 600; }
.raw pre { font-family: var(--mono); font-size: 12px; background: #0f1724; color: #d6e2f5; padding: 14px; border-radius: 8px; overflow: auto; max-height: 420px; }

/* expression blocks (matched by statisticsMathExpression) */
.center { text-align: center !important; }
.cell-same { color: var(--ok); font-weight: 700; }
.overview td { min-width: 90px; }
.overview th.sticky { white-space: normal; min-width: 280px; max-width: 460px; overflow-wrap: anywhere; }
.expr-key { overflow-wrap: anywhere; }
.expr-head { align-items: baseline; }
.expr { margin: 0 0 18px; border: 1px solid var(--border); border-radius: var(--radius); background: #eef1f6; padding: 0 14px 2px; }
.expr[open] { padding-bottom: 6px; }
.expr-mismatch { border-color: #ffc9c9; background: #fbf1f1; }
.expr-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; cursor: pointer; padding: 14px 2px; list-style: none; }
.expr-head::-webkit-details-marker { display: none; }
.expr-head::before { content: "▸"; color: var(--muted); transition: transform .15s; }
.expr[open] > .expr-head::before { transform: rotate(90deg); }
.expr-key-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.expr-key { font-size: 16px; font-weight: 700; }
.expr .card { margin-bottom: 12px; }

/* "Show only differences" */
.report.only-mismatch .section-match { display: none; }
.report.only-mismatch .expr-match { display: none; }
.report.only-mismatch .chip-ok { opacity: .45; }
.report.only-mismatch .row-match { display: none; }

.pager { display: flex; gap: 18px; justify-content: center; align-items: center; color: var(--muted); }

@media (max-width: 760px) {
    .topbar { padding: 0 14px; gap: 12px; }
    .monitor-pill span:not(.dot) { display: none; }
    .container { padding: 16px 12px 40px; }
    .page-head { flex-direction: column; align-items: flex-start; }
    .kpi-wide { grid-column: auto; }
}
