/* ==========================================================================
   CAL tiuv web UI - Datamedia internal. White theme tuned for data.
   Tokens and rules are documented in docs/brandbook.md. No inline styles are
   used anywhere (strict CSP), so every visual rule lives here.
   ========================================================================== */

/* ---------- 1. Tokens ---------- */
:root {
  /* Neutrals */
  --c-bg: #ffffff;
  --c-surface: #ffffff;
  --c-surface-2: #f8fafc;      /* table header, zebra, page tint */
  --c-border: #e2e8f0;
  --c-border-strong: #cbd5e1;
  --c-text: #0f172a;           /* 17.8:1 on white */
  --c-text-muted: #475569;     /* 7.6:1 on white */
  --c-text-faint: #64748b;     /* 4.8:1 on white (large/secondary only) */

  /* Brand (DataMedia navy + amber accent, see brandbook "Brand colours") */
  --c-brand: #1b3a6b;          /* 11.2:1 on white */
  --c-brand-hover: #142c52;
  --c-brand-tint: #eaf0f9;
  --c-accent: #b45309;         /* 5.0:1 on white, text-safe amber */
  --c-accent-bright: #f59e0b;  /* decorative only (never text on white) */
  --c-focus: #1d4ed8;

  /* Semantic */
  --c-success: #15803d;  --c-success-tint: #dcfce7;
  --c-warning: #b45309;  --c-warning-tint: #fef3c7;
  --c-danger:  #b91c1c;  --c-danger-tint:  #fee2e2;
  --c-info:    #475569;  --c-info-tint:    #f1f5f9;

  /* Event categories (colour + icon + label, never colour alone) */
  --cat-sftp: #0b5cad;        --cat-sftp-tint: #e3effb;
  --cat-processing: #6d28d9;  --cat-processing-tint: #efe8fc;
  --cat-delivery: #15803d;    --cat-delivery-tint: #dcfce7;
  --cat-mail: #0e7490;        --cat-mail-tint: #dff4f9;
  --cat-alert: #c2410c;       --cat-alert-tint: #ffedd5;
  --cat-security: #475569;    --cat-security-tint: #eef2f6;
  --cat-accounting: #4338ca;  --cat-accounting-tint: #e8e8fb;

  /* Fair-usage bands */
  --band-within: #15803d;  --band-within-tint: #dcfce7;
  --band-watch: #b45309;   --band-watch-tint: #fef3c7;
  --band-review: #c2410c;  --band-review-tint: #ffedd5;
  --band-spike: #b91c1c;   --band-spike-tint: #fee2e2;

  /* Chart series (Okabe-Ito derived, colour-blind safe) */
  --chart-1: #1b3a6b;
  --chart-2: #e69f00;
  --chart-3: #009e73;
  --chart-4: #cc79a7;
  --chart-5: #56b4e9;
  --chart-grid: #e2e8f0;
  --chart-text: #475569;

  /* Type */
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Noto Sans Hebrew", sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --fs-xs: 0.75rem; --fs-sm: 0.8125rem; --fs-base: 0.9375rem; --fs-md: 1.0625rem;
  --fs-lg: 1.25rem; --fs-xl: 1.625rem; --fs-kpi: 1.875rem;

  /* Space (4px base) */
  --s-1: 0.25rem; --s-2: 0.5rem; --s-3: 0.75rem; --s-4: 1rem;
  --s-5: 1.5rem; --s-6: 2rem; --s-7: 3rem;

  --radius: 8px; --radius-sm: 5px;
  --shadow-1: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-2: 0 8px 24px rgba(15, 23, 42, 0.12);
  --sidebar-w: 15rem;
  --header-h: 3.5rem;
  --ease: 150ms ease;
}

/* ---------- 2. Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--c-bg); color: var(--c-text);
  font-family: var(--font-sans); font-size: var(--fs-base); line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.25; margin: 0; font-weight: 650; }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-md); }
h3 { font-size: var(--fs-base); }
p { margin: 0 0 var(--s-3); }
a { color: var(--c-brand); text-underline-offset: 2px; }
a:hover { color: var(--c-brand-hover); }
code, kbd, pre { font-family: var(--font-mono); font-size: 0.92em; }
img, svg { max-width: 100%; }
[hidden] { display: none !important; }
.num, td.num, th.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); }
.muted { color: var(--c-text-muted); }
.small { font-size: var(--fs-sm); }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}
:focus-visible { outline: 3px solid var(--c-focus); outline-offset: 2px; border-radius: 3px; }
.skip-link {
  position: absolute; left: var(--s-3); top: -4rem; z-index: 100; background: var(--c-brand);
  color: #fff; padding: var(--s-2) var(--s-4); border-radius: var(--radius-sm); text-decoration: none;
}
.skip-link:focus { top: var(--s-3); color: #fff; }
.icon { width: 1.125rem; height: 1.125rem; flex: none; fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -0.2em; }
.icon--lg { width: 1.5rem; height: 1.5rem; }

/* ---------- 3. Buttons and form controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 2.5rem; padding: 0 var(--s-4); border-radius: var(--radius-sm);
  border: 1px solid var(--c-border-strong); background: var(--c-surface); color: var(--c-text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  transition: background var(--ease), border-color var(--ease);
}
.btn:hover { background: var(--c-surface-2); border-color: var(--c-text-faint); color: var(--c-text); }
.btn--primary { background: var(--c-brand); border-color: var(--c-brand); color: #fff; }
.btn--primary:hover { background: var(--c-brand-hover); border-color: var(--c-brand-hover); color: #fff; }
.btn--block { width: 100%; }
.btn--sm { min-height: 2rem; padding: 0 var(--s-3); font-size: var(--fs-sm); }
.btn--ghost { border-color: transparent; background: transparent; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; pointer-events: none; }

.field { display: flex; flex-direction: column; gap: var(--s-1); margin-bottom: var(--s-4); min-width: 0; }
.field label, .field__label { font-weight: 600; font-size: var(--fs-sm); }
.field__hint { color: var(--c-text-muted); font-size: var(--fs-sm); }
.input, select.input, textarea.input {
  width: 100%; min-height: 2.5rem; padding: 0.45rem var(--s-3); font: inherit; color: var(--c-text);
  background: #fff; border: 1px solid var(--c-border-strong); border-radius: var(--radius-sm);
}
textarea.input { min-height: 5rem; resize: vertical; }
.input:hover { border-color: var(--c-text-faint); }
.input:focus-visible { outline-offset: 0; border-color: var(--c-focus); }
.input[aria-invalid="true"] { border-color: var(--c-danger); }
.input-group { position: relative; display: flex; }
.input-group .input { padding-right: 3rem; }
.input-group__btn {
  position: absolute; right: 0.25rem; top: 50%; transform: translateY(-50%);
  min-width: 2.25rem; height: 2.25rem; display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 0; border-radius: var(--radius-sm); color: var(--c-text-muted); cursor: pointer;
}
.input-group__btn:hover { background: var(--c-surface-2); color: var(--c-text); }
.check { display: inline-flex; align-items: center; gap: var(--s-2); cursor: pointer; }
.check input { width: 1.1rem; height: 1.1rem; accent-color: var(--c-brand); }

/* ---------- 4. Alerts and flash ---------- */
.alert {
  display: flex; gap: var(--s-3); align-items: flex-start; padding: var(--s-3) var(--s-4);
  border-radius: var(--radius); border: 1px solid; margin-bottom: var(--s-4); font-size: var(--fs-sm);
}
.alert__body { flex: 1; min-width: 0; }
.alert__body ul { margin: var(--s-1) 0 0; padding-left: 1.2rem; }
.alert--info    { background: var(--c-info-tint);    border-color: var(--c-border-strong); color: var(--c-text); }
.alert--success { background: var(--c-success-tint); border-color: #86efac; color: #14532d; }
.alert--warning { background: var(--c-warning-tint); border-color: #fcd34d; color: #78350f; }
.alert--error, .alert--danger, .alert--alert
                { background: var(--c-danger-tint);  border-color: #fca5a5; color: #7f1d1d; }
.alert__close { background: transparent; border: 0; cursor: pointer; color: inherit; padding: 0 var(--s-1);
  font-size: 1.25rem; line-height: 1; border-radius: 3px; }
.flash-stack { margin-bottom: var(--s-2); }

/* ---------- 5. App shell ---------- */
.shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  background: var(--c-surface-2); border-right: 1px solid var(--c-border); padding: var(--s-4);
}
.brand { display: inline-flex; align-items: center; gap: var(--s-2); text-decoration: none; color: var(--c-brand); }
.brand:hover { color: var(--c-brand); }
.brand__mark { width: 2rem; height: 2rem; flex: none; }
.brand__text { font-weight: 750; font-size: var(--fs-md); letter-spacing: -0.01em; }
.brand__text b { color: var(--c-accent); font-weight: 750; }
.brand__sub { display: block; font-size: var(--fs-xs); font-weight: 500; color: var(--c-text-muted); letter-spacing: 0.02em; }
.sidebar__nav { margin: var(--s-5) 0; display: flex; flex-direction: column; gap: var(--s-1); }
.nav-link {
  display: flex; align-items: center; gap: var(--s-3); padding: 0.6rem var(--s-3);
  border-radius: var(--radius-sm); color: var(--c-text-muted); text-decoration: none; font-weight: 600;
  border-left: 3px solid transparent;
}
.nav-link:hover { background: var(--c-border); color: var(--c-text); }
.nav-link[aria-current="page"] { background: var(--c-brand-tint); color: var(--c-brand); border-left-color: var(--c-brand); }
.sidebar__user { margin-top: auto; padding-top: var(--s-4); border-top: 1px solid var(--c-border); font-size: var(--fs-sm); }
.sidebar__user-name { font-weight: 650; overflow-wrap: anywhere; }
.badge-role { display: inline-block; margin: var(--s-1) 0 var(--s-3); padding: 0 var(--s-2); border-radius: 99px;
  background: var(--c-border); color: var(--c-text); font-size: var(--fs-xs); font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; }
.sidebar__links { display: flex; flex-direction: column; gap: var(--s-2); align-items: flex-start; }
.topbar { display: none; }
.main { min-width: 0; display: flex; flex-direction: column; }
.page-header {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s-3);
  padding: var(--s-5) var(--s-6) var(--s-4); border-bottom: 1px solid var(--c-border);
}
.page-header__sub { margin: var(--s-1) 0 0; color: var(--c-text-muted); font-size: var(--fs-sm); }
.page-header__actions { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }
.content { padding: var(--s-5) var(--s-6) var(--s-7); width: 100%; max-width: 90rem; }

/* ---------- 6. Cards, grids, KPI ---------- */
.card { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); box-shadow: var(--shadow-1); padding: var(--s-5); min-width: 0; }
.card__head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--s-3); margin-bottom: var(--s-4); flex-wrap: wrap; }
.card__title { font-size: var(--fs-md); }
.card__sub { color: var(--c-text-muted); font-size: var(--fs-sm); margin: var(--s-1) 0 0; }
.grid { display: grid; gap: var(--s-4); margin-bottom: var(--s-4); }
.grid--kpi { grid-template-columns: repeat(auto-fit, minmax(11.5rem, 1fr)); }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--wide-narrow { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.kpi { padding: var(--s-4); }
.kpi__label { color: var(--c-text-muted); font-size: var(--fs-sm); font-weight: 600; margin: 0; }
.kpi__value { font-size: var(--fs-kpi); font-weight: 700; line-height: 1.2; margin: var(--s-1) 0; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.kpi__note { color: var(--c-text-muted); font-size: var(--fs-xs); margin: 0; }
.kpi__value.is-loading, .skeleton {
  color: transparent; background: linear-gradient(90deg, var(--c-border) 25%, var(--c-surface-2) 50%, var(--c-border) 75%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite linear; border-radius: var(--radius-sm); min-width: 4rem; display: inline-block;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.dl { display: grid; grid-template-columns: max-content 1fr; gap: var(--s-2) var(--s-4); margin: 0; font-size: var(--fs-sm); }
.dl dt { color: var(--c-text-muted); }
.dl dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }

/* ---------- 7. Segmented control, chips, status ---------- */
.segmented { display: inline-flex; border: 1px solid var(--c-border-strong); border-radius: var(--radius-sm); overflow: hidden; background: #fff; }
.segmented button { border: 0; background: transparent; padding: 0.4rem var(--s-4); font: inherit; font-weight: 600; color: var(--c-text-muted); cursor: pointer; min-height: 2.25rem; }
.segmented button + button { border-left: 1px solid var(--c-border-strong); }
.segmented button:hover { background: var(--c-surface-2); color: var(--c-text); }
.segmented button[aria-pressed="true"] { background: var(--c-brand); color: #fff; }
.segmented button:focus-visible { outline-offset: -3px; }

.status-chip {
  display: inline-flex; align-items: center; gap: var(--s-1); padding: 0.1rem var(--s-3); border-radius: 99px;
  font-size: var(--fs-sm); font-weight: 650; border: 1px solid transparent; white-space: nowrap;
}
.status-chip--ok, .status-chip--within, .status-chip--success { background: var(--band-within-tint); color: #14532d; border-color: #86efac; }
.status-chip--watch, .status-chip--warning { background: var(--band-watch-tint); color: #78350f; border-color: #fcd34d; }
.status-chip--review { background: var(--band-review-tint); color: #7c2d12; border-color: #fdba74; }
.status-chip--spike, .status-chip--error { background: var(--band-spike-tint); color: #7f1d1d; border-color: #fca5a5; }
.status-chip--none, .status-chip--neutral { background: var(--c-info-tint); color: var(--c-text); border-color: var(--c-border-strong); }

.dot { display: inline-block; width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--c-text-faint); flex: none; }
.dot--success { background: var(--c-success); }
.dot--warning { background: var(--c-warning); border-radius: 2px; transform: rotate(45deg); }
.dot--error { background: var(--c-danger); border-radius: 1px; }
.dot--info { background: var(--c-text-faint); }

.badge {
  display: inline-flex; align-items: center; gap: var(--s-1); padding: 0.05rem var(--s-2); border-radius: var(--radius-sm);
  font-size: var(--fs-xs); font-weight: 650; white-space: nowrap; background: var(--c-info-tint); color: var(--c-text);
}
.cat-sftp       { --cat: var(--cat-sftp);       --cat-tint: var(--cat-sftp-tint); }
.cat-processing { --cat: var(--cat-processing); --cat-tint: var(--cat-processing-tint); }
.cat-delivery   { --cat: var(--cat-delivery);   --cat-tint: var(--cat-delivery-tint); }
.cat-mail       { --cat: var(--cat-mail);       --cat-tint: var(--cat-mail-tint); }
.cat-alert      { --cat: var(--cat-alert);      --cat-tint: var(--cat-alert-tint); }
.cat-security   { --cat: var(--cat-security);   --cat-tint: var(--cat-security-tint); }
.cat-accounting { --cat: var(--cat-accounting); --cat-tint: var(--cat-accounting-tint); }
.badge--cat { background: var(--cat-tint); color: var(--cat); border: 1px solid var(--cat); }

/* ---------- 8. Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--c-border); border-radius: var(--radius); background: #fff; }
.table-wrap--scroll { max-height: 28rem; overflow: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-sm); }
.table th, .table td { padding: 0.55rem var(--s-3); text-align: left; vertical-align: top; border-bottom: 1px solid var(--c-border); }
.table th { position: sticky; top: 0; z-index: 1; background: var(--c-surface-2); color: var(--c-text-muted); font-weight: 650; white-space: nowrap; }
.table th.num, .table td.num { text-align: right; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--c-surface-2); }
.table caption { text-align: left; padding: var(--s-3); font-weight: 650; }
.table tr.is-flagged td { background: var(--c-danger-tint); }
.table tr.is-partial td { background: var(--c-surface-2); }
.empty { text-align: center; color: var(--c-text-muted); padding: var(--s-6) var(--s-4); }

/* ---------- 9. Charts ---------- */
.chart { position: relative; height: 20rem; }
.chart--sm { height: 16rem; }
.chart canvas { display: block; }
.chart__state {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--s-2); text-align: center; color: var(--c-text-muted); background: rgba(255, 255, 255, 0.92); padding: var(--s-4); font-size: var(--fs-sm);
}
.chart__state--error { color: var(--c-danger); }
.spinner { width: 1.5rem; height: 1.5rem; border: 3px solid var(--c-border); border-top-color: var(--c-brand); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.legend { display: flex; flex-wrap: wrap; gap: var(--s-2) var(--s-4); margin: var(--s-3) 0 0; padding: 0; list-style: none; font-size: var(--fs-sm); color: var(--c-text-muted); }
.legend li { display: inline-flex; align-items: center; gap: var(--s-2); }
.swatch { width: 0.9rem; height: 0.9rem; border-radius: 2px; flex: none; }
.swatch--within { background: var(--band-within-tint); border: 1px solid var(--band-within); }
.swatch--watch { background: var(--band-watch-tint); border: 1px solid var(--band-watch); }
.swatch--review { background: var(--band-review-tint); border: 1px solid var(--band-review); }
.swatch--spike { background: var(--band-spike-tint); border: 1px solid var(--band-spike); }
.swatch--line { height: 0; border-top: 3px dashed var(--c-text); border-radius: 0; width: 1.2rem; }
details.data-table { margin-top: var(--s-3); font-size: var(--fs-sm); }
details.data-table summary { cursor: pointer; color: var(--c-brand); font-weight: 600; }

/* ---------- 10. Meter (accounting hero) ---------- */
.hero { display: grid; gap: var(--s-5); grid-template-columns: minmax(0, 1fr); }
.hero__top { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--s-4); align-items: flex-end; }
.hero__figure { font-size: 2.5rem; font-weight: 750; font-variant-numeric: tabular-nums; line-height: 1.1; letter-spacing: -0.02em; }
.hero__figure small { font-size: var(--fs-md); font-weight: 500; color: var(--c-text-muted); letter-spacing: 0; }
.meter { position: relative; padding-top: 1.6rem; }
.meter__bands { display: flex; height: 1.25rem; border-radius: 99px; overflow: hidden; border: 1px solid var(--c-border-strong); }
.meter__band { height: 100%; }
.meter__band--within { background: var(--band-within-tint); }
.meter__band--watch { background: var(--band-watch-tint); }
.meter__band--review { background: var(--band-review-tint); }
.meter__band--spike { background: var(--band-spike-tint); }
.meter__fill { position: absolute; left: 0; top: 1.6rem; height: 1.25rem; border-radius: 99px 0 0 99px; background: var(--c-brand); opacity: 0.9; min-width: 2px; }
.meter__marker { position: absolute; top: 0.2rem; bottom: -0.3rem; width: 0; border-left: 2px dashed var(--c-text); transform: translateX(-1px); }
.meter__marker span { position: absolute; top: -0.1rem; left: 50%; transform: translateX(-50%); background: var(--c-text); color: #fff; font-size: var(--fs-xs); padding: 0 var(--s-2); border-radius: 3px; white-space: nowrap; font-weight: 650; }
.meter__scale { position: relative; height: 2.5rem; margin-top: var(--s-2); font-size: var(--fs-xs); color: var(--c-text-muted); }
.meter__tick { position: absolute; top: 0; transform: translateX(-50%); text-align: center; white-space: nowrap; }
.meter__tick:first-child { transform: none; text-align: left; }
.meter__tick b { display: block; color: var(--c-text); font-weight: 650; }

/* ---------- 11. Insights ---------- */
.insights { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-2); }
.insight { display: flex; gap: var(--s-3); padding: var(--s-3) var(--s-4); border-radius: var(--radius-sm); border-left: 4px solid; font-size: var(--fs-sm); }
.insight--info { background: var(--c-info-tint); border-color: var(--c-text-faint); }
.insight--warning { background: var(--c-warning-tint); border-color: var(--c-warning); }
.insight--alert { background: var(--c-danger-tint); border-color: var(--c-danger); }
.insight__label { font-weight: 700; text-transform: uppercase; font-size: var(--fs-xs); letter-spacing: 0.04em; min-width: 4.5rem; }

/* ---------- 12. Filter bar and logs ---------- */
.filters { display: grid; gap: var(--s-4); margin-bottom: var(--s-4); }
.filters__row { display: flex; flex-wrap: wrap; gap: var(--s-4); align-items: flex-end; }
.filters__row .field { margin-bottom: 0; }
.filters__row .field--grow { flex: 1 1 14rem; }
.quick-ranges { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.chip-groups { display: grid; gap: var(--s-3); border: 0; padding: 0; margin: 0; }
.chip-group { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }
.chip-group__title { display: inline-flex; align-items: center; gap: var(--s-1); min-width: 8rem; font-weight: 650; font-size: var(--fs-sm); color: var(--cat); }
.chip-group__tools { display: inline-flex; gap: var(--s-1); }
.link-btn { background: none; border: 0; color: var(--c-brand); font: inherit; font-size: var(--fs-xs); text-decoration: underline; cursor: pointer; padding: 0.15rem 0.25rem; }
.chip { position: relative; display: inline-flex; }
.chip input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.chip span { display: inline-flex; align-items: center; gap: var(--s-1); padding: 0.25rem var(--s-3); border: 1px solid var(--c-border-strong); border-radius: 99px; font-size: var(--fs-sm); background: #fff; color: var(--c-text-muted); }
.chip input:checked + span { background: var(--cat-tint); border-color: var(--cat); color: var(--cat); font-weight: 650; }
.chip input:checked + span::before { content: "\2713"; font-weight: 700; }
.chip input:focus-visible + span { outline: 3px solid var(--c-focus); outline-offset: 2px; }
.result-bar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: var(--s-3); margin-bottom: var(--s-3); }
.log-table td { vertical-align: top; }
.log-row > td:first-child { border-left: 4px solid var(--cat); }
.log-table .ts { font-family: var(--font-mono); font-size: var(--fs-xs); white-space: nowrap; }
.log-level { display: inline-flex; align-items: center; gap: var(--s-2); }
.log-summary { min-width: 14rem; }
.log-meta { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-top: var(--s-1); font-size: var(--fs-xs); color: var(--c-text-muted); }
.log-meta a { font-family: var(--font-mono); }
.log-detail { margin-top: var(--s-2); }
.log-detail summary { cursor: pointer; color: var(--c-brand); font-size: var(--fs-xs); font-weight: 600; }
.log-detail pre { margin: var(--s-2) 0 0; padding: var(--s-3); background: var(--c-surface-2); border: 1px solid var(--c-border); border-radius: var(--radius-sm); overflow-x: auto; max-height: 20rem; white-space: pre-wrap; overflow-wrap: anywhere; font-size: var(--fs-xs); }
.pagination { display: flex; justify-content: space-between; align-items: center; gap: var(--s-3); margin-top: var(--s-4); flex-wrap: wrap; }

/* ---------- 13. Auth pages ---------- */
.auth-body { min-height: 100vh; display: flex; flex-direction: column; background: var(--c-surface-2); }
.auth-main { flex: 1; display: flex; align-items: center; justify-content: center; padding: var(--s-5) var(--s-4); }
.auth-wrap { width: 100%; display: flex; justify-content: center; }
.auth-card { width: 100%; max-width: 26rem; background: #fff; border: 1px solid var(--c-border); border-top: 4px solid var(--c-brand); border-radius: var(--radius); box-shadow: var(--shadow-2); padding: var(--s-6); }
.auth-card--wide { max-width: 32rem; }
.auth-brand { display: flex; justify-content: center; margin-bottom: var(--s-5); }
.auth-brand .brand__mark { width: 2.5rem; height: 2.5rem; }
.auth-brand .brand__text { font-size: var(--fs-lg); }
.auth-title { display: flex; align-items: center; justify-content: center; gap: var(--s-2); font-size: var(--fs-lg); margin-bottom: var(--s-1); text-align: center; }
.auth-sub { text-align: center; color: var(--c-text-muted); font-size: var(--fs-sm); margin-bottom: var(--s-5); }
.auth-notes { margin: var(--s-5) 0 0; padding: var(--s-3) var(--s-4); background: var(--c-surface-2); border-radius: var(--radius-sm); font-size: var(--fs-xs); color: var(--c-text-muted); display: grid; gap: var(--s-2); }
.auth-notes p { margin: 0; display: flex; gap: var(--s-2); align-items: flex-start; }
.auth-footer { text-align: center; padding: var(--s-4); font-size: var(--fs-xs); color: var(--c-text-muted); }
.caps-hint { display: flex; gap: var(--s-2); align-items: center; font-size: var(--fs-sm); color: #78350f; background: var(--c-warning-tint); border-radius: var(--radius-sm); padding: var(--s-1) var(--s-3); }
.rules { margin: 0 0 var(--s-4); padding: var(--s-3) var(--s-4) var(--s-3) var(--s-6); background: var(--c-surface-2); border-radius: var(--radius-sm); font-size: var(--fs-sm); }
.strength { margin-top: var(--s-1); }
.strength__bar { height: 6px; border-radius: 99px; background: var(--c-border); overflow: hidden; }
.strength__bar span { display: block; height: 100%; width: 0; background: var(--c-danger); transition: width var(--ease); }
.strength[data-level="1"] .strength__bar span { width: 25%; }
.strength[data-level="2"] .strength__bar span { width: 50%; background: var(--c-warning); }
.strength[data-level="3"] .strength__bar span { width: 75%; background: var(--c-success); }
.strength[data-level="4"] .strength__bar span { width: 100%; background: var(--c-success); }
.strength__text { font-size: var(--fs-xs); color: var(--c-text-muted); margin-top: var(--s-1); }

/* ---------- 14. Plan form ---------- */
.form-grid { display: grid; gap: var(--s-4); grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); }
.form-grid .field { margin-bottom: 0; }
.form-grid .field--full { grid-column: 1 / -1; }
.export-form { display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: flex-end; }
.export-form .field { margin-bottom: 0; }

/* ---------- 14b. Layout helpers ---------- */
.acc-gap { margin-top: var(--s-4); }
section.card + section.card, section.grid + section.card, section.card + .grid { margin-top: var(--s-4); }
.grid--wide-narrow > div > .card { margin-bottom: var(--s-4); }
.grid--wide-narrow > div > .grid { margin-bottom: 0; }
.card .kpi__value small { font-size: var(--fs-sm); font-weight: 500; color: var(--c-text-muted); }

/* ---------- 15. Statement ---------- */
.statement-body { background: var(--c-surface-2); }
.statement-toolbar { max-width: 50rem; margin: var(--s-4) auto; padding: 0 var(--s-4); display: flex; gap: var(--s-2); justify-content: space-between; flex-wrap: wrap; }
.statement { max-width: 50rem; margin: 0 auto var(--s-6); background: #fff; border: 1px solid var(--c-border); padding: var(--s-6); }
.statement__head { display: flex; justify-content: space-between; gap: var(--s-4); border-bottom: 2px solid var(--c-brand); padding-bottom: var(--s-4); margin-bottom: var(--s-5); flex-wrap: wrap; }
.statement h1 { font-size: var(--fs-lg); }
.statement h2 { margin: var(--s-5) 0 var(--s-2); }
.statement__note { margin-top: var(--s-5); font-size: var(--fs-sm); color: var(--c-text-muted); border-top: 1px solid var(--c-border); padding-top: var(--s-3); }

/* ---------- 16. Responsive ---------- */
@media (max-width: 1100px) {
  .grid--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid--wide-narrow { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .shell { display: block; }
  .topbar {
    position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between;
    height: var(--header-h); padding: 0 var(--s-4); background: #fff; border-bottom: 1px solid var(--c-border);
  }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--c-border); padding: var(--s-3) var(--s-4); }
  .sidebar .brand { display: none; }
  .sidebar__nav { margin: 0 0 var(--s-3); }
  .js .sidebar { position: fixed; z-index: 40; top: var(--header-h); left: 0; right: 0; max-height: calc(100vh - var(--header-h)); overflow-y: auto; box-shadow: var(--shadow-2); display: none; }
  .js.nav-open .sidebar { display: flex; }
  .page-header, .content { padding-left: var(--s-4); padding-right: var(--s-4); }
  .grid--2, .grid--3 { grid-template-columns: minmax(0, 1fr); }
  .chart { height: 17rem; }
}
@media (max-width: 480px) {
  :root { --fs-xl: 1.375rem; --fs-kpi: 1.5rem; }
  .card { padding: var(--s-4); }
  .auth-card { padding: var(--s-5) var(--s-4); }
  .hero__figure { font-size: 2rem; }
  .chip-group__title { min-width: 100%; }
  .dl { grid-template-columns: 1fr; gap: 0; }
  .dl dd { margin-bottom: var(--s-2); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

/* ---------- 17. Print (statement and general) ---------- */
@media print {
  @page { size: A4; margin: 14mm; }
  body, .statement-body { background: #fff; color: #000; font-size: 10.5pt; }
  .sidebar, .topbar, .no-print, .statement-toolbar, .flash-stack, .skip-link { display: none !important; }
  .shell { display: block; }
  .content, .page-header { padding: 0; }
  .statement { border: 0; padding: 0; margin: 0; max-width: none; }
  .card { box-shadow: none; break-inside: avoid; }
  .table th { position: static; background: #f1f5f9 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .table tr { break-inside: avoid; }
  .status-chip { border-color: #000; background: #fff !important; color: #000 !important; }
  a { color: #000; text-decoration: none; }
}

/* ==========================================================================
   18. Release 2: Review category, Corrections, Explorer
   (documented in docs/brandbook.md sections 2 and 5)
   ========================================================================== */
:root {
  --cat-review: #be123c;       /* rose, 6.3:1 on white */
  --cat-review-tint: #ffe4e6;  /* 5.3:1 with --cat-review text */
}
.cat-review { --cat: var(--cat-review); --cat-tint: var(--cat-review-tint); }

/* Brand-coloured variant of the filter chips (issue types are not event categories) */
.chip-group--brand { --cat: var(--c-brand); --cat-tint: var(--c-brand-tint); }

/* Sidebar badge (open issues) */
.nav-badge {
  margin-left: auto; min-width: 1.4rem; padding: 0 0.4rem; border-radius: 99px; background: var(--cat-review);
  color: #fff; font-size: var(--fs-xs); font-weight: 700; text-align: center; line-height: 1.4rem;
  font-variant-numeric: tabular-nums;
}

/* Badge colour variants (always paired with a symbol and a word) */
.badge--danger  { background: var(--c-danger-tint);  color: #7f1d1d; border: 1px solid #fca5a5; }
.badge--warning { background: var(--c-warning-tint); color: #78350f; border: 1px solid #fcd34d; }
.badge--ok      { background: var(--c-success-tint); color: #14532d; border: 1px solid #86efac; }
.badge--neutral { background: var(--c-info-tint);    color: var(--c-text); border: 1px solid var(--c-border-strong); }
.badge--review  { background: var(--cat-review-tint); color: var(--cat-review); border: 1px solid var(--cat-review); }

/* KPI card that is a link */
.kpi--link { display: block; text-decoration: none; color: inherit; }
.kpi--link:hover { border-color: var(--c-brand); color: inherit; }
.kpi--link .kpi__note::after { content: " \2192"; }

/* Tabs (links; the active one carries aria-current="page") */
.tabs { display: flex; gap: var(--s-1); border-bottom: 1px solid var(--c-border); margin: 0 0 var(--s-4); overflow-x: auto; }
.tab {
  display: inline-flex; align-items: center; gap: var(--s-2); padding: 0.65rem var(--s-4); white-space: nowrap;
  font-weight: 650; color: var(--c-text-muted); text-decoration: none; border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--c-text); background: var(--c-surface-2); }
.tab[aria-current="page"] { color: var(--c-brand); border-bottom-color: var(--c-brand); }
.tab:focus-visible { outline-offset: -3px; }
.tab__count {
  min-width: 1.5rem; padding: 0 var(--s-2); border-radius: 99px; background: var(--c-border); color: var(--c-text);
  font-size: var(--fs-xs); font-weight: 700; text-align: center; font-variant-numeric: tabular-nums;
}
.tab[aria-current="page"] .tab__count { background: var(--c-brand-tint); color: var(--c-brand); }

/* Loading / empty / error block for lists */
.state {
  display: flex; flex-direction: column; align-items: center; gap: var(--s-2); padding: var(--s-6) var(--s-4);
  text-align: center; color: var(--c-text-muted); border: 1px dashed var(--c-border-strong); border-radius: var(--radius);
}
.state--error { color: #7f1d1d; background: var(--c-danger-tint); border-color: #fca5a5; border-style: solid; }

/* Issue list (Addresses tab) */
.issue-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-2); }
.issue { border: 1px solid var(--c-border); border-left: 4px solid var(--cat-review); border-radius: var(--radius); background: #fff; }
.issue__btn {
  display: grid; gap: var(--s-2); width: 100%; text-align: left; background: transparent; border: 0;
  padding: var(--s-3) var(--s-4); font: inherit; color: inherit; cursor: pointer; border-radius: var(--radius);
}
.issue__btn:hover { background: var(--c-surface-2); }
.issue__btn:focus-visible { outline-offset: -3px; }
.issue__address { font-weight: 650; font-size: var(--fs-md); overflow-wrap: anywhere; white-space: pre-line; }
.issue__tags, .issue__meta { display: flex; flex-wrap: wrap; gap: var(--s-1) var(--s-4); align-items: center; font-size: var(--fs-sm); color: var(--c-text-muted); }
.issue__tags { gap: var(--s-2); }
.issue__go { margin-left: auto; color: var(--c-brand); font-weight: 650; }

/* Drawer (Resolve) */
.drawer-backdrop { position: fixed; inset: 0; z-index: 60; background: rgba(15, 23, 42, 0.4); }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 70; width: min(32rem, 100%); display: flex; flex-direction: column;
  background: #fff; border-left: 1px solid var(--c-border); box-shadow: var(--shadow-2); animation: drawer-in 180ms ease-out;
}
@keyframes drawer-in { from { transform: translateX(2rem); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer:focus { outline: none; }
.drawer__head {
  display: flex; justify-content: space-between; align-items: center; gap: var(--s-3);
  padding: var(--s-4) var(--s-5); border-bottom: 1px solid var(--c-border); border-top: 4px solid var(--cat-review);
}
.drawer__body { flex: 1; overflow-y: auto; padding: var(--s-5); }
.drawer__foot { display: flex; flex-wrap: wrap; gap: var(--s-2); padding: var(--s-4) var(--s-5); border-top: 1px solid var(--c-border); background: var(--c-surface-2); }
.drawer__foot .spacer { margin-left: auto; }
.drawer__h { margin: var(--s-4) 0 var(--s-1); }
.drawer__address {
  margin: 0 0 var(--s-3); padding: var(--s-3); background: var(--c-surface-2); border: 1px solid var(--c-border);
  border-radius: var(--radius-sm); font-size: var(--fs-md); font-weight: 650; overflow-wrap: anywhere; white-space: pre-line;
}
.drawer__tags { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-bottom: var(--s-3); }
.drawer__parsed { margin-bottom: var(--s-4); padding-bottom: var(--s-4); border-bottom: 1px solid var(--c-border); }
body.drawer-open { overflow: hidden; }

/* Suggestion chips (one-click buttons) */
.suggest { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-bottom: var(--s-4); }
.suggest__btn {
  display: inline-flex; align-items: center; gap: var(--s-2); min-height: 2.25rem; padding: 0.2rem var(--s-3); border-radius: 99px;
  border: 1px solid var(--c-border-strong); background: #fff; color: var(--c-text); font: inherit; font-size: var(--fs-sm); font-weight: 600; cursor: pointer;
}
.suggest__btn:hover { background: var(--c-brand-tint); border-color: var(--c-brand); }
.suggest__btn[aria-pressed="true"] { background: var(--c-brand); border-color: var(--c-brand); color: #fff; }
.suggest__score { font-weight: 500; opacity: 0.85; font-variant-numeric: tabular-nums; }

/* Typeahead (ARIA combobox) */
.typeahead { position: relative; }
.typeahead__list {
  position: absolute; left: 0; right: 0; top: calc(100% + 2px); z-index: 20; margin: 0; padding: var(--s-1); list-style: none;
  background: #fff; border: 1px solid var(--c-border-strong); border-radius: var(--radius-sm); box-shadow: var(--shadow-2);
  max-height: 16rem; overflow-y: auto;
}
.typeahead__opt { display: grid; gap: 2px; padding: 0.45rem var(--s-3); border-radius: var(--radius-sm); cursor: pointer; }
.typeahead__opt:hover, .typeahead__opt.is-active { background: var(--c-brand-tint); }
.typeahead__opt[aria-selected="true"] { outline: 2px solid var(--c-focus); outline-offset: -2px; }
.typeahead__main { font-weight: 650; overflow-wrap: anywhere; }
.typeahead__sub { font-size: var(--fs-xs); color: var(--c-text-muted); overflow-wrap: anywhere; }
.selection {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2); margin-top: var(--s-2); padding: 0.25rem var(--s-3);
  background: var(--c-success-tint); border: 1px solid #86efac; border-radius: var(--radius-sm); color: #14532d; font-size: var(--fs-sm);
}
.selection .link-btn { color: #14532d; margin-left: auto; }

/* Toasts (aria-live region) */
.toast-region { position: fixed; right: var(--s-4); bottom: var(--s-4); z-index: 90; display: grid; gap: var(--s-2); width: min(26rem, calc(100% - 2 * var(--s-4))); pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: flex-start; gap: var(--s-3); padding: var(--s-3) var(--s-4); background: #fff;
  border: 1px solid var(--c-border-strong); border-left: 4px solid var(--c-success); border-radius: var(--radius);
  box-shadow: var(--shadow-2); font-size: var(--fs-sm); animation: drawer-in 180ms ease-out;
}
.toast--error { border-left-color: var(--c-danger); }
.toast__msg { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast .link-btn { font-size: var(--fs-sm); font-weight: 700; white-space: nowrap; }

/* English names table */
.input--sm { min-height: 2rem; padding: 0.2rem var(--s-2); font-size: var(--fs-sm); }
.en-input { min-width: 14rem; }
.row-actions { display: flex; flex-wrap: wrap; gap: var(--s-1); }
.cell-stack { display: grid; gap: var(--s-1); }
.cell-wide { min-width: 12rem; max-width: 26rem; overflow-wrap: anywhere; }
.field-error { color: #7f1d1d; font-size: var(--fs-xs); font-weight: 600; }
.tag { display: inline-flex; align-items: center; padding: 0.1rem var(--s-3); border-radius: 99px; background: var(--c-surface-2); border: 1px solid var(--c-border); font-size: var(--fs-sm); }
.tag-list { list-style: none; display: flex; flex-wrap: wrap; gap: var(--s-2); margin: 0; padding: 0; }

/* Explorer */
.table-card { display: block; text-decoration: none; color: inherit; }
.table-card:hover { border-color: var(--c-brand); color: inherit; }
.table-card h3 { color: var(--c-brand); margin-bottom: var(--s-1); }
.table-card .dl { margin-top: var(--s-3); }
.chart--tall { height: 26rem; }
.pill-nav { display: flex; flex-wrap: wrap; gap: var(--s-2); margin: 0 0 var(--s-4); padding: 0; list-style: none; }
.pill { display: inline-flex; align-items: center; padding: 0.3rem var(--s-3); border: 1px solid var(--c-border-strong); border-radius: 99px; font-size: var(--fs-sm); font-weight: 600; color: var(--c-text-muted); text-decoration: none; background: #fff; }
.pill:hover { background: var(--c-surface-2); color: var(--c-text); }
.pill[aria-current="page"] { background: var(--c-brand); border-color: var(--c-brand); color: #fff; }
.table-wrap--browser { max-height: 70vh; overflow: auto; }
.table--browser thead tr:first-child th { height: 2.5rem; }
.table--browser .filter-row th { top: 2.5rem; padding: var(--s-1) var(--s-2); font-weight: 400; }
.table--browser td.mono { font-size: var(--fs-xs); }
.sort-link { display: inline-flex; align-items: center; gap: var(--s-1); color: inherit; text-decoration: none; }
.sort-link:hover { color: var(--c-brand); text-decoration: underline; }
.sort-link__arrow { color: var(--c-brand); }
.crumbs { margin: 0 0 var(--s-1); font-size: var(--fs-sm); }
.browser-bar { display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: flex-end; margin-bottom: var(--s-3); }
.browser-bar .field { margin-bottom: 0; }
.browser-bar .field--grow { flex: 1 1 14rem; }
.notes-list { margin: 0; }

@media (max-width: 480px) {
  .drawer__head, .drawer__body, .drawer__foot { padding-left: var(--s-4); padding-right: var(--s-4); }
  .tab { padding: 0.6rem var(--s-3); }
  .issue__go { display: none; }
  .en-input { min-width: 11rem; }
  .chart--tall { height: 22rem; }
}
@media print {
  .drawer, .drawer-backdrop, .toast-region { display: none !important; }
}

/* Long spelling lists (big cities have hundreds of names) scroll inside their card instead of stretching the page */
.tag-list--scroll { max-height: 14rem; overflow-y: auto; padding: var(--s-3); border: 1px solid var(--c-border); border-radius: var(--radius-sm); background: #fff; }
