/* Plain, hand-written CSS - no Tailwind, no build step, matching the
   "plain PHP, no JS framework" call for this whole app. One file.

   Palette and component shapes (sidebar, cards, badges, buttons,
   split-screen login) are ported 1:1 from the design mockup ("LDA Portal -
   Standalone.html") the client provided - the phone+OTP auth flow and all
   data underneath stayed exactly as built, only the visual language
   changed. The mockup's Manrope/Sora were replaced by Inter (one family,
   built for dense data UIs, tabular digits) - see "Fonts" below. */

/* ===== Fonts =====
   Inter, self-hosted (assets/fonts, SIL OFL - see Inter-LICENSE.txt) so it is
   identical in every browser and needs no third-party request. One variable
   file per script subset covers every weight. Only latin is preloaded (layout
   <head>); latin-ext downloads only if a page actually uses one of its glyphs.
   font-display: optional = the page never visibly swaps fonts: a preloaded,
   cached font is ready for the first paint; on the rare cold miss that view
   keeps the fallback and the next page has Inter.
   The filename carries the font version, so it can be cached forever - bump
   it (v4 -> v5) when replacing the file. */
@font-face {
  font-family: 'Inter'; font-style: normal; font-weight: 100 900; font-display: optional;
  src: url('/assets/fonts/inter-latin.v4.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Inter'; font-style: normal; font-weight: 100 900; font-display: optional;
  src: url('/assets/fonts/inter-latin-ext.v4.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* Arial resized to Inter's measurements (average glyph width over UI text,
   Inter's ascent/descent), so if the fallback is ever shown nothing reflows
   when Inter takes over. Computed from the v4 file with fontTools. */
@font-face {
  font-family: 'Inter Fallback'; font-weight: 100 599; src: local('Arial'), local('ArialMT');
  size-adjust: 107.77%; ascent-override: 89.89%; descent-override: 22.38%; line-gap-override: 0%;
}
@font-face {
  font-family: 'Inter Fallback'; font-weight: 600 900; src: local('Arial Bold'), local('Arial-BoldMT');
  size-adjust: 102.60%; ascent-override: 94.42%; descent-override: 23.51%; line-gap-override: 0%;
}

:root {
  /* ================================================================
     LDA DESIGN SYSTEM - tokens. Full rules: dashboard/DESIGN-SYSTEM.md
     Live reference: /design-system (Administrator).
     Three layers - use the highest layer that fits:
       3. component tokens  --btn-*, --control-*, --dt-*, --card-* ...
       2. semantic tokens   --color-*, --text-*, --space-*, --radius-* ...
       1. primitives        --navy-*, --slate-*, --green-* ... (raw values;
                            never referenced directly by a component)
     ================================================================ */

  /* ---- 1. PRIMITIVES ------------------------------------------- */
  /* Brand navy / indigo (from the client mockup) */
  --navy-950: #0d1230;
  --navy-900: #171e4e;
  --navy-700: #2f3c8f;
  --indigo-500: #5561d6;
  --indigo-100: #eef1fd;
  --indigo-50:  #f4f6fd;
  /* Slate - the neutral ramp, biased toward the navy */
  --slate-0:   #ffffff;
  --slate-25:  #f8f9fd;
  --slate-50:  #f4f6fb;
  --slate-100: #eef1f8;
  --slate-150: #e6e9f4;
  --slate-200: #dde1ee;
  --slate-400: #8c93ad;
  --slate-500: #6b7390;
  --slate-600: #555d7c;
  --slate-700: #475070;
  --slate-800: #3d4568;
  --slate-900: #1c2340;
  /* Status hues: -50 tint, -600 solid/icon, -700 text on its tint (all text pairs >= 4.5:1) */
  --green-50:  #e7f7ef; --green-600:  #0f9d76; --green-700:  #047857;
  --amber-50:  #fef3e2; --amber-600:  #b45309; --amber-700:  #9a4a06;
  --red-50:    #fdeaea; --red-600:    #b91c1c; --red-700:    #b91c1c;
  --blue-50:   #e7f2fe; --blue-600:   #1d6fc4; --blue-700:   #1a5fa8;
  --purple-50: #f3e8ff; --purple-600: #7c3aed; --purple-700: #7c3aed;
  --orange-600: #e0492f;  /* brand accent (logo red), decorative only */

  /* Type scale - SIX sizes, the only font sizes allowed anywhere on the site
     (px because the dashboard is a dense tool UI): 12 compact, 14 reading,
     16 emphasis, 20 headings, 24 titles, 30 big numbers / hero. 16 is also the
     minimum input text size that stops iPhone / iPad zooming into a field on tap. */
  --size-12: 12px; --size-14: 14px; --size-16: 16px;
  --size-20: 20px; --size-24: 24px; --size-30: 30px;

  /* Spacing - 4px grid */
  --space-1: 4px;  --space-2: 8px;  --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-8: 32px; --space-10: 40px; --space-12: 48px;

  /* ---- 2. SEMANTIC --------------------------------------------- */
  /* Fonts: one family (Inter); display text differs by size, weight and tracking, not by face */
  --font-sans: 'Inter', 'Inter Fallback', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: var(--font-sans);
  --font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Surfaces */
  --color-bg: var(--slate-50);            /* page ground */
  --color-surface: var(--slate-0);        /* cards, tables, panels */
  --color-surface-sunken: var(--slate-25);/* table header, row hover, inset areas */
  --color-surface-pressed: #f0f2fa;       /* row / item while pressed */
  --color-surface-selected: var(--indigo-50);

  /* Lines */
  --color-border: var(--slate-150);       /* card and table outer edges */
  --color-border-soft: var(--slate-100);  /* dividers inside a card */
  --color-border-control: var(--slate-400);/* form-control edges: 3:1 on white (WCAG 1.4.11) */

  /* Text - every pair here is >= 4.5:1 on surface AND surface-sunken */
  --color-text: var(--slate-900);         /* primary values, headings      15.4:1 */
  --color-text-secondary: var(--slate-800);/* body copy in panels            9.3:1 */
  --color-text-meta: var(--slate-600);    /* secondary lines, labels, hints  6.5:1 */
  --color-text-on-accent: #ffffff;

  /* Accent / interactive */
  --color-accent: var(--navy-700);        /* links, primary buttons, selected */
  --color-accent-strong: var(--navy-900); /* filled "set" pills, pressed */
  --color-accent-hover: var(--indigo-500); /* link hover, gradient end, count badges */
  --color-accent-soft: var(--indigo-100); /* info strips, selected tints */
  --color-focus: var(--indigo-500);
  --focus-ring: 0 0 0 3px rgba(85, 97, 214, .22);
  --color-backdrop: rgba(15, 20, 40, .55); /* behind a .modal (navy-950 at .55) */

  /* Status - bg / fg (text on bg) / solid (icons, dots, edges) */
  --status-success-bg: var(--green-50);  --status-success-fg: var(--green-700);  --status-success-solid: var(--green-600);
  --status-warning-bg: var(--amber-50);  --status-warning-fg: var(--amber-700);  --status-warning-solid: var(--amber-600);
  --status-danger-bg:  var(--red-50);    --status-danger-fg:  var(--red-700);    --status-danger-solid:  var(--red-600);
  --status-info-bg:    var(--blue-50);   --status-info-fg:    var(--blue-700);   --status-info-solid:    var(--blue-600);
  --status-verify-bg:  var(--purple-50); --status-verify-fg:  var(--purple-700); --status-verify-solid:  var(--purple-600);
  --status-neutral-bg: var(--slate-100); --status-neutral-fg: var(--slate-700);  --status-neutral-solid: var(--slate-500);

  /* Charts - categorical slots, in this order (dataviz reference hues, validated with validate_palette.js on the
     white card incl. the ring's wrap-around pair: worst adjacent CVD dE 9.2, normal 27.5). Colour follows the
     entity, never its rank. Red / green / amber are left out: they mean status. Slots 3 and 5 are under 3:1 on
     white, so a chart using them always ships a visible legend with values. */
  --chart-cat-1: #2a78d6;  /* blue */
  --chart-cat-2: #eb6834;  /* orange */
  --chart-cat-3: #1baf7a;  /* aqua */
  --chart-cat-4: #4a3aa7;  /* violet */
  --chart-cat-5: #e87ba4;  /* magenta */
  --chart-cat-other: var(--slate-400);
  /* Status marks in charts (SLA gauges): red / amber / green validated as a set (dataviz validate_palette.js: normal-vision
     ΔE ≥ 18.8, CVD ≥ 9.7, each ≥ 3:1 on white). The amber is lighter than --status-warning-solid, which sat too close to
     the red to tell apart (ΔE 9.1). Marks only - text keeps the text tokens. */
  --gauge-danger: var(--status-danger-solid);
  --gauge-warning: #d97706;
  --gauge-success: var(--status-success-solid);
  /* Red / amber / green - the map pins' trio: done (green), in progress (amber), overdue (red). Always with a label. */
  --rag-green: #0f9d76;
  --rag-amber: #f59e0b;
  --rag-red: #e0492f;
  /* Ordinal blue (light -> dark) for ordered steps, e.g. stages of the complaint cycle (validate_palette.js --ordinal) */
  --chart-seq-250: #86b6ef;
  --chart-seq-450: #2a78d6;
  --chart-seq-650: #104281;

  /* Typography roles -> the six sizes. Roles name the job; several roles share a size and
     differ by weight / tracking / colour. Size, weight, line-height and tracking travel
     together (see the .t-* classes). TYPOGRAPHY.md is the full rule book. */
  --fs-display: var(--size-30);  /* big KPI numbers, hero figures, login headline (weight 800, tabular) */
  --fs-page-title: var(--size-30); /* the page's main title: sticky-header h1, login card title (weight 700) */
  --fs-h1: var(--size-24);       /* large heading or figure inside a page (record reference, big values) */
  --fs-h2: var(--size-20);       /* section heading; insight-tile numbers */
  --fs-title: var(--size-16);    /* card / panel title */
  --fs-body: var(--size-16);     /* primary value in a table cell, emphasised text, search text */
  --fs-body-sm: var(--size-14);  /* reading text: paragraphs, controls, buttons, chips, AND secondary lines,
                                    timestamps, help text, errors (those add --color-text-meta) */
  --fs-label: var(--size-12);    /* compact: uppercase labels, column headers, badges, chips, small buttons, captions */

  --fw-regular: 500;  /* Inter 500 reads as regular at UI sizes */
  --fw-medium: 600;
  --fw-strong: 700;
  --fw-heavy: 800;    /* uppercase labels + display numbers only */

  --lh-tight: 1.3;    /* table cells, titles, single-line UI */
  --lh-snug: 1.45;    /* secondary lines, compact paragraphs (also the body default) */
  --lh-relaxed: 1.6;  /* long-form help text */
  --lh-display: 1.15; /* display / h1 */

  --tracking-display: -.02em; /* >= 20px */
  --tracking-tight: -.01em;   /* 15-17px emphasised values */
  --tracking-caps: .06em;     /* uppercase labels */

  /* Shape, depth, motion */
  --radius-sm: 6px;    /* tags, small inner elements */
  --radius-md: 10px;   /* buttons, inputs, menu items' container */
  --radius-lg: 14px;   /* cards, tiles, popovers */
  --radius-xl: 18px;   /* page-level panels (filter bar, table card) */
  --radius-pill: 999px;/* pills, chips, badges, search */
  --shadow-sm: 0 1px 2px rgba(28, 35, 64, .04);
  --shadow-md: 0 1px 2px rgba(28, 35, 64, .04), 0 8px 24px rgba(28, 35, 64, .04);
  --shadow-lg: 0 2px 6px rgba(28, 35, 64, .06), 0 16px 40px rgba(28, 35, 64, .14);  /* popovers */
  --ease-standard: cubic-bezier(.32, .72, 0, 1);  /* enter / move (iOS sheet curve) */
  --ease-exit: ease-in;
  --dur-fast: 120ms;   /* hover, press, exits */
  --dur-base: 160ms;   /* popovers in, colour changes */
  --dur-slow: 380ms;   /* panels expanding */
  --z-sticky: 1; --z-header: 5; --z-popover: 30; --z-menu: 40; --z-drawer: 60; --z-loader: 1000;

  /* ---- 3. COMPONENT -------------------------------------------- */
  --control-h: 42px;           /* inputs + selects */
  --control-h-sm: 36px;
  --pill-h: 40px;              /* filter pills, toolbar buttons */
  --btn-h: 42px; --btn-h-sm: 34px;
  --btn-radius: var(--radius-md);
  --card-padding: var(--space-5);
  --card-radius: var(--radius-lg);
  --dt-cell-x: 10px; --dt-cell-y: 12px; /* data table cell padding */
  --page-gutter-x: var(--space-8); --page-gutter-y: 26px;

  /* ---- LEGACY ALIASES (pre-system names; same values, so nothing changes yet).
     Pages still use these; each moves to the semantic names during the rollout,
     then the alias is deleted. Do not use in new code. --------------- */
  --blue-accent: #2f86eb;
  --accent: var(--orange-600);
  --bg: var(--color-bg);
  --surface: var(--color-surface);
  --border: var(--color-border);
  --border-soft: var(--color-border-soft);
  --border-input: var(--color-border-control);
  --text: var(--color-text);
  --text-secondary: var(--color-text-secondary);
  /* The two old greys failed WCAG for text (#8a92b2 3.1:1; #6b7390 4.3-4.7:1); both now resolve to the
     accessible meta grey site-wide. Replace with --color-text-meta when migrating. */
  --text-muted: var(--color-text-meta);
  --text-faint: var(--color-text-meta);
  --text-meta: var(--color-text-meta);
  --success: var(--green-600);  --success-bg: var(--green-50);  --success-text: var(--green-700);
  --warning: var(--amber-600);  --warning-bg: var(--amber-50);  --warning-text: var(--amber-700);
  --danger: var(--red-600);     --danger-bg: var(--red-50);
  --info: var(--blue-600);      --info-bg: var(--blue-50);      --info-text: var(--blue-700);
  --purple: var(--purple-600);  --purple-bg: var(--purple-50);
  --neutral: var(--slate-500);  --neutral-bg: var(--slate-100); --neutral-text: var(--slate-700);
}

/* ===== Text styles =====
   The typography rules as classes - one per role, each a fixed set of
   size + weight + leading + tracking (never set those four separately in a
   page). Colour is separate: add .t-meta-color / .t-secondary when needed. */
.t-display { font-size: var(--fs-display); font-weight: var(--fw-heavy); line-height: var(--lh-display); letter-spacing: var(--tracking-display); font-variant-numeric: tabular-nums; }
.t-h1      { font-size: var(--fs-page-title);      font-weight: var(--fw-strong); line-height: var(--lh-display); letter-spacing: var(--tracking-display); }
.t-h2      { font-size: var(--fs-h2);      font-weight: var(--fw-strong); line-height: 1.25; letter-spacing: var(--tracking-display); }
.t-title   { font-size: var(--fs-title);   font-weight: var(--fw-strong); line-height: var(--lh-tight); letter-spacing: var(--tracking-tight); }
.t-body    { font-size: var(--fs-body);    font-weight: var(--fw-medium); line-height: var(--lh-tight); letter-spacing: var(--tracking-tight); }
.t-body-sm { font-size: var(--fs-body-sm); font-weight: var(--fw-regular); line-height: var(--lh-snug); }
.t-label   { font-size: var(--fs-label);   font-weight: var(--fw-heavy); line-height: var(--lh-tight); letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--color-text-meta); }
.t-mono    { font-family: var(--font-mono); font-size: var(--fs-body-sm); font-weight: var(--fw-strong); letter-spacing: 0; }
.t-num     { font-variant-numeric: tabular-nums; }
.t-secondary  { color: var(--color-text-secondary); }
.t-meta-color { color: var(--color-text-meta); }

/* ===== Design system: base components (opt-in per page) =====
   Pages join the system by getting .ds on .main-body (list in
   layouts/app.php - $designSystemPages). Inside .ds the shared base
   components below follow the spec in DESIGN-SYSTEM.md; pages not yet
   migrated keep their current look until they are added. The Complaints
   page's components (.dt, .fb, .chip, .sel, .kpi-tile, .dt-chip) are part
   of the system already and work anywhere. */
.ds h1, .ds .h1 { font-size: var(--fs-page-title); font-weight: var(--fw-strong); line-height: var(--lh-display); letter-spacing: var(--tracking-display); }
.ds h2, .ds .section-title { font-size: var(--fs-h2); font-weight: var(--fw-strong); line-height: 1.25; letter-spacing: var(--tracking-display); margin: var(--space-8) 0 var(--space-3); }
.ds h3 { font-size: var(--fs-title); font-weight: var(--fw-strong); line-height: var(--lh-tight); letter-spacing: var(--tracking-tight); margin: 0 0 var(--space-2); }
.ds p { font-size: var(--fs-body-sm); line-height: var(--lh-snug); }
.ds .text-muted, .ds .muted { color: var(--color-text-meta); }

/* Button - primary (default) / secondary / danger / ghost; md (default) and sm */
.ds .btn {
  height: var(--btn-h); padding: 0 var(--space-5); border-radius: var(--btn-radius);
  font-size: var(--fs-body-sm); font-weight: var(--fw-strong); line-height: 1; letter-spacing: 0;
  box-shadow: var(--shadow-sm);
}
.ds .btn-sm { height: var(--btn-h-sm); padding: 0 var(--space-3); font-size: var(--fs-label); border-radius: var(--radius-md); }
.ds .btn-secondary { background: var(--color-surface); color: var(--color-accent); border: 1px solid var(--color-border-control); box-shadow: none; }
.ds .btn-secondary:hover { background: var(--color-accent-soft); border-color: var(--color-accent); }
.ds .btn-danger { background: var(--status-danger-solid); box-shadow: none; }
.ds .btn-ghost { background: transparent; color: var(--color-accent); box-shadow: none; }
.ds .btn-ghost:hover { background: var(--color-surface-sunken); filter: none; }
.ds .btn:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.ds .btn[disabled] { opacity: 1; background: var(--status-neutral-bg); color: var(--status-neutral-fg); border-color: transparent; box-shadow: none; transform: none; }

/* Card */
.ds .card { border-radius: var(--card-radius); box-shadow: var(--shadow-md); padding: var(--card-padding); }

/* Form field: label above, control, help / error below */
.ds .form-group { margin-bottom: var(--space-4); }
.ds .form-group label { display: block; margin-bottom: 6px; font-size: var(--fs-label); font-weight: var(--fw-strong); letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--color-text-meta); }
.ds .form-control {
  height: var(--control-h); padding: 0 var(--space-3); border: 1px solid var(--color-border-control); border-radius: var(--radius-md);
  font-size: var(--fs-body-sm); font-weight: var(--fw-regular); color: var(--color-text); background-color: var(--color-surface);
}
.ds textarea.form-control { height: auto; min-height: 96px; padding: 10px var(--space-3); line-height: var(--lh-snug); }
.ds .form-control:hover { border-color: var(--color-text-meta); }
.ds .form-control::placeholder { color: var(--color-text-meta); opacity: 1; }
.ds .form-control:focus { border-color: var(--color-focus); box-shadow: var(--focus-ring); }
.ds .form-control.is-invalid, .ds .form-control.is-invalid:hover, .ds .form-control.is-invalid:focus { border-color: var(--status-danger-solid); }
.ds .hint { font-size: var(--fs-body-sm); font-weight: var(--fw-regular); line-height: var(--lh-snug); color: var(--color-text-meta); margin-top: 6px; }

/* Status badge */
.ds .badge { padding: 3px 10px; font-size: var(--fs-label); font-weight: var(--fw-strong); line-height: 1.4; letter-spacing: 0; white-space: nowrap; }
.ds .badge-verification { color: var(--status-verify-fg); }
.ds .badge-danger { color: var(--status-danger-fg); }

/* Stat card = the same anatomy as .kpi-tile (label, display number, subline) */
.ds .stat-card { border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); padding: var(--space-4); }
.ds .stat-card .label { font-size: var(--fs-label); font-weight: var(--fw-heavy); letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--color-text-meta); }
.ds .stat-card .value { font-size: var(--fs-display); font-weight: var(--fw-heavy); line-height: var(--lh-display); letter-spacing: var(--tracking-display); font-variant-numeric: tabular-nums; }
.ds .stat-card .hint { font-size: var(--fs-body-sm); font-weight: var(--fw-regular); color: var(--color-text-meta); margin-top: var(--space-1); }

/* Plain tables (not yet rebuilt on .dt markup) get the .dt look: one table design across the site.
   Rebuild a page's table on .dt (two-line cells, sort, column picker) when it is migrated. */
.ds table:not(.dt) { border-radius: var(--radius-xl); box-shadow: var(--shadow-md); font-variant-numeric: tabular-nums; }
.ds table:not(.dt) thead th {
  padding: var(--dt-cell-y) var(--dt-cell-x); background: var(--color-surface-sunken);
  font-size: var(--fs-label); font-weight: var(--fw-heavy); line-height: var(--lh-tight); letter-spacing: var(--tracking-caps); color: var(--color-text-meta);
}
.ds table:not(.dt) tbody td { padding: var(--dt-cell-y) var(--dt-cell-x); font-size: var(--fs-body-sm); line-height: var(--lh-tight); }
.ds table:not(.dt) tbody tr:hover { background: var(--color-surface-sunken); }
.ds .empty-row td { padding: var(--space-12) var(--space-4); color: var(--color-text-meta); font-size: var(--fs-body-sm); }


* { box-sizing: border-box; }

html, body {
  height: 100%;
}
body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: var(--fs-body-sm);
  /* Explicit leading: line-height:normal comes from each font's own metrics and differs between fonts */
  line-height: 1.45;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

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

h1, h2, .font-heading { font-family: var(--font-display); line-height: 1.25; }
h1 { font-size: var(--fs-page-title); font-weight: var(--fw-strong); letter-spacing: var(--tracking-display); margin: 0 0 4px; color: var(--text); }
h2 { font-size: var(--fs-title); font-weight: 700; letter-spacing: -.01em; margin: 32px 0 12px; color: var(--text); }
p { line-height: 1.5; }

::selection { background: #dfe4ff; }

/* Fixed to the viewport height, not the page's content height - .sidebar
   (a flex item that stretches to match) and .main scroll independently
   instead of the whole shell growing with .main-body's content, which used
   to drag the sidebar (and its bottom-anchored "Exit") down the page. */
.app-shell { display: flex; height: 100vh; overflow: hidden; }

/* Sidebar - dark, compact, collapsible to an icon rail (desktop). A rounded panel floating beside the page: 36px pill
   items (20px icon + a one-line label), the current page a lighter pill in white, groups split by a full-width hairline
   (group names are kept for screen readers only). The logo and every icon sit on one axis 30px from the panel's left
   edge, expanded and collapsed, so nothing shifts sideways as it folds. 256px fits the longest label ("Categories,
   priorities & SLA", 184px) on one line. Touch screens get 44px items. Below 1024px it is the off-canvas drawer. */
:root {
  --sidebar-w: 288px; --sidebar-rail: 60px;
  --sidebar-item-h: var(--control-h-sm);  /* 36px */
  --sidebar-pad: 10px;                    /* nav side padding; + 10px item padding puts the icon 20px in */
  --sidebar-bg: #141a2e;
  --sidebar-text: #a7aec8;                /* 7.9:1 on the panel */
  --sidebar-text-strong: #ffffff;
  --sidebar-hover: rgba(255, 255, 255, .06);
  --sidebar-active: rgba(255, 255, 255, .14);
  --sidebar-line: rgba(255, 255, 255, .09);
}
@media (pointer: coarse) { :root { --sidebar-item-h: 44px; } }
.sidebar {
  position: relative; z-index: 3;
  width: var(--sidebar-w); flex-shrink: 0;
  margin: 12px 0 12px 12px; height: calc(100vh - 24px);
  display: flex; flex-direction: column;
  background: var(--sidebar-bg); color: var(--sidebar-text);
  border-radius: 16px; box-shadow: 0 16px 44px rgba(0, 0, 0, .07);
  transition: width 220ms var(--ease-standard);
}
/* Fixed height: the two-line name is taller than the logo, and the menu must not move up when the name hides */
.sidebar-top { position: relative; display: flex; align-items: center; height: 60px; padding: 0 14px; flex: none; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.sidebar-logo { flex: none; width: 32px; height: 32px; border-radius: 9px; background: #fff; display: flex; align-items: center; justify-content: center; }
.sidebar-logo img { width: 24px; display: block; }
.sidebar-brand-text { display: flex; flex-direction: column; min-width: 0; white-space: nowrap; }
.sidebar-brand .title { font-family: var(--font-display); font-weight: var(--fw-heavy); font-size: var(--fs-title); line-height: var(--lh-display); color: var(--sidebar-text-strong); }
.sidebar-brand .subtitle { font-size: var(--fs-label); line-height: var(--lh-tight); color: var(--sidebar-text); font-weight: var(--fw-medium); }
/* Collapse button: a round handle on the panel's right edge, level with the logo */
.sidebar-collapse {
  position: absolute; right: -12px; top: 18px; z-index: 2;
  width: 24px; height: 24px; padding: 0; display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-pill); border: 1px solid rgba(255, 255, 255, .22); background: var(--sidebar-bg); color: var(--sidebar-text-strong);
  cursor: pointer; transition: background-color var(--dur-fast) ease, transform 220ms var(--ease-standard);
}
.sidebar-collapse::before { content: ""; position: absolute; inset: -10px; } /* 44px touch target */
.sidebar-collapse svg { width: 14px; height: 14px; }
.sidebar-collapse:hover { background: #262e48; }
.sidebar-collapse:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* No scrollbar (a classic Windows one would take the room the labels need). While more of the menu is below, the
   bottom 32px fade out instead (.has-more, set by the layout script) - 32px is more than the widest gap between items
   (a group divider), so part of an item always shows faded and the menu never looks finished when it isn't. */
.sidebar-nav { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 2px var(--sidebar-pad) 14px; scrollbar-width: none; }
.sidebar-nav::-webkit-scrollbar { display: none; }
/* "More" pill at the bottom of the menu while items are hidden below it; a gentle nudge so it reads as "scroll" */
.sidebar-more { position: absolute; left: 50%; bottom: 10px; z-index: 2; transform: translateX(-50%); display: inline-flex; align-items: center; gap: 4px; height: 28px; padding: 0 10px 0 12px; border-radius: var(--radius-pill); border: 1px solid rgba(255, 255, 255, .22); background: #262e48; color: var(--sidebar-text-strong); font: inherit; font-size: var(--fs-label); font-weight: var(--fw-strong); cursor: pointer; box-shadow: 0 4px 12px rgba(0, 0, 0, .3); }
.sidebar-more[hidden] { display: none; }
.sidebar-more svg { width: 14px; height: 14px; animation: more-nudge 1.6s ease-in-out infinite; }
.sidebar-more:hover { background: #313a58; }
.sidebar-more:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.sidebar-more::before { content: ""; position: absolute; inset: -8px; } /* 44px touch target */
@keyframes more-nudge { 0%, 100% { transform: translateY(-1px); } 50% { transform: translateY(2px); } }
@media (prefers-reduced-motion: reduce) { .sidebar-more svg { animation: none; } }
@media (min-width: 1024px) { .nav-collapsed .sidebar-more { padding: 0; width: 28px; justify-content: center; } .nav-collapsed .sidebar-more-text { display: none; } }
.sidebar-nav.has-more { -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 32px), transparent); mask-image: linear-gradient(to bottom, #000 calc(100% - 32px), transparent); }
.sidebar-group { display: flex; flex-direction: column; gap: 2px; }
/* Full-width hairline between groups (edge to edge, like the reference) */
.sidebar-group + .sidebar-group { margin: 8px calc(-1 * var(--sidebar-pad)) 0; padding: 8px var(--sidebar-pad) 0; border-top: 1px solid var(--sidebar-line); }
.nav-item {
  position: relative; display: flex; align-items: center; gap: 10px; min-height: var(--sidebar-item-h); padding: 6px 10px;
  border-radius: var(--radius-pill); color: var(--sidebar-text); font-size: var(--fs-body); font-weight: var(--fw-medium); line-height: var(--lh-tight);
  text-decoration: none; transition: background-color var(--dur-fast) ease, color var(--dur-fast) ease;
}
.nav-item:hover { background: var(--sidebar-hover); color: var(--sidebar-text-strong); text-decoration: none; }
.nav-item:active { background: var(--sidebar-active); }
.nav-item:focus-visible { outline: 2px solid #fff; outline-offset: -2px; }
/* Same weight as the rest (as in the reference): the pill marks it, and the label never re-wraps when it becomes current */
.nav-item.active { background: var(--sidebar-active); color: var(--sidebar-text-strong); }
.nav-ico { position: relative; flex: none; width: 20px; height: 20px; display: inline-flex; }
.nav-ico svg { width: 20px; height: 20px; }
.nav-label { min-width: 0; }
/* Unread dot (Notifications): orange, ringed in the panel colour */
.nav-dot { position: absolute; left: -3px; bottom: -2px; width: 9px; height: 9px; border-radius: 50%; background: #f97316; box-shadow: 0 0 0 2px var(--sidebar-bg); }
.nav-dot[hidden] { display: none; }
/* Name tooltip for the collapsed rail (fixed, so the scrolling nav never clips it) */
.nav-tip {
  position: fixed; z-index: calc(var(--z-drawer) + 1); transform: translateY(-50%); pointer-events: none; white-space: nowrap;
  background: var(--color-text); color: #fff; font-size: var(--fs-body-sm); font-weight: var(--fw-medium); line-height: var(--lh-tight);
  padding: 6px 10px; border-radius: 8px; box-shadow: var(--shadow-lg);
}
.nav-tip[hidden] { display: none; }

/* Collapsed rail (desktop only): round icon buttons centred in the rail, on the same axis as when expanded */
@media (min-width: 1024px) {
  .nav-collapsed .sidebar { --sidebar-pad: calc((var(--sidebar-rail) - var(--sidebar-item-h)) / 2); width: var(--sidebar-rail); }
  .nav-collapsed .sidebar-brand-text { display: none; }
  .nav-collapsed .sidebar-collapse { transform: rotate(180deg); }
  .nav-collapsed .nav-item { width: var(--sidebar-item-h); height: var(--sidebar-item-h); padding: 0; justify-content: center; }
  /* the name stays for screen readers, out of sight */
  .nav-collapsed .nav-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}
@media (max-width: 1023px) { :root { --sidebar-item-h: 44px; } .sidebar-collapse { display: none; } }

/* Account menu - top-right header dropdown (avatar, name/role, Profile, Notifications, Sign out),
   replacing the old fixed sidebar-bottom profile block so the sidebar is nav-only. */
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--color-accent), var(--color-accent-hover));
  color: var(--color-text-on-accent); display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: var(--fs-body-sm);
}
.avatar-sm { width: 32px; height: 32px; font-size: var(--fs-label); }
.account-menu { position: relative; }
.account-trigger {
  display: flex; align-items: center; gap: 9px; background: none; border: none; cursor: pointer;
  padding: 4px 6px; border-radius: 10px; font-family: inherit;
}
.account-dropdown {
  position: absolute; top: calc(100% + 8px); right: 0; min-width: 220px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 12px 32px rgba(28, 35, 64, .14); padding: 6px; z-index: 20;
}
.account-dropdown-header { padding: 10px 12px 11px; border-bottom: 1px solid var(--border-soft); margin-bottom: 6px; }
.account-dropdown-header .name { font-size: var(--fs-body-sm); font-weight: 800; color: var(--text); }
.account-dropdown-header .role { font-size: var(--fs-label); color: var(--text-faint); margin-top: 2px; }
.account-dropdown a {
  display: block; padding: 9px 12px; border-radius: 8px; color: var(--text-secondary);
  font-weight: 600; font-size: var(--fs-body-sm); text-decoration: none;
}
.account-dropdown a:hover { background: var(--bg); text-decoration: none; }
.account-dropdown form { margin: 2px 0 0; }
.account-dropdown button {
  width: 100%; text-align: left; background: none; border: none; cursor: pointer;
  padding: 9px 12px; border-radius: 8px; color: var(--danger); font-weight: 700; font-size: var(--fs-body-sm); font-family: inherit;
}
.account-dropdown button:hover { background: var(--danger-bg); }

/* No max-width cap - the design mockup fills the full viewport width next
   to its sidebar; a cap here is exactly what left a blank gap on the
   right on wide screens. The stat-grid's own minmax(165px) is what keeps
   six cards on one row, not a constrained container. */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow-y: auto; isolation: isolate; /* page content (map controls, popovers) stays below the off-canvas drawer whatever its own z-index */ scroll-padding-top: 100px; /* sticky header ~88px (30px title + subtitle) + gap: scrolled-to / focused things land clear of it */ }

/* Sticky per-page header - title/subtitle on the left, live clock + TV
   mode shortcut on the right, same row (the design mockup's header). */
.main-header {
  display: flex; align-items: center; gap: 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 16px 32px; position: sticky; top: 0; z-index: 5;
}
.main-header h1 { font-size: var(--fs-page-title); line-height: var(--lh-display); margin: 0; }
.main-header-sub { font-size: var(--fs-body-sm); color: var(--color-text-meta); font-weight: var(--fw-regular); }
.main-header-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.main-header-right #header-clock { font-size: var(--fs-body-sm); color: var(--color-text-meta); font-weight: var(--fw-medium); white-space: nowrap; font-variant-numeric: tabular-nums; }
.main-header-title { min-width: 0; }
/* Notifications bell + unread count */
.notif-bell { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: var(--radius-pill); color: var(--color-text-secondary); text-decoration: none; }
.notif-bell svg { width: 20px; height: 20px; }
.notif-bell:hover { background: var(--color-surface-sunken); color: var(--color-accent); text-decoration: none; }
.notif-bell:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.notif-badge {
  position: absolute; top: 2px; right: 0; min-width: 18px; padding: 1px 5px; border-radius: var(--radius-pill);
  background: var(--status-danger-solid); color: var(--color-text-on-accent);
  font-size: var(--fs-label); font-weight: var(--fw-heavy); line-height: 1.4; text-align: center; font-variant-numeric: tabular-nums;
}
/* Menu button: only shown when the sidebar is a drawer */
.nav-toggle {
  display: none; flex-shrink: 0; width: 44px; height: 44px; margin-left: -8px; align-items: center; justify-content: center;
  border: 0; border-radius: var(--radius-md); background: transparent; color: var(--color-text); cursor: pointer;
}
.nav-toggle svg { width: 22px; height: 22px; }
.nav-toggle:hover { background: var(--color-surface-sunken); }
.nav-toggle:active { background: var(--color-surface-pressed); }
.nav-toggle:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.nav-backdrop { display: none; }
.main-body { padding: var(--page-gutter-y) var(--page-gutter-x) 56px; container-type: inline-size; /* components size to the content column, not the viewport (the sidebar takes 256px - or 60px collapsed - of it) */ }

/* Stat cards - minmax(170px) is the design mockup's own stat-grid value,
   verbatim. No margin-top: in the mockup this grid is the first element
   inside the padded content area (right under the sticky header), so the
   only vertical gap above it is that container's own padding-top - an
   extra margin-top here (left over from before the header existed)
   doubled that gap. */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 8px 24px rgba(28, 35, 64, .05); padding: 16px 18px;
  transition: box-shadow .15s ease, transform .15s ease, border-color .15s ease;
}
a.stat-card:hover { box-shadow: 0 10px 28px rgba(28, 35, 64, .1); border-color: var(--color-focus); transform: translateY(-1px); }
a.stat-card:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.stat-card .label {
  font-size: var(--fs-label); text-transform: uppercase; color: var(--text-faint);
  font-weight: 800; letter-spacing: .06em;
}
.stat-card .value { font-family: var(--font-display); font-size: var(--fs-display); font-weight: 800; margin-top: 4px; color: var(--text); }
.stat-card .hint { font-size: var(--fs-body-sm); color: var(--text-faint); font-weight: 600; margin-top: 8px; }
.stat-card.stat-accent {
  background: linear-gradient(150deg, var(--color-accent-strong), var(--color-accent));
  border: none; color: var(--color-text-on-accent); box-shadow: 0 10px 24px rgba(23, 30, 78, .3);
}
.stat-card.stat-accent .label { color: #aab1dd; }
.stat-card.stat-accent .value { color: var(--color-text-on-accent); }

/* Tables */
table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; overflow: hidden; box-shadow: 0 8px 24px rgba(28, 35, 64, .05); }
thead th {
  text-align: left; padding: 11px 16px; font-size: var(--fs-label); text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-faint); font-weight: 800; background: #fafbfe;
  border-bottom: 1px solid var(--border);
}
tbody td { padding: 11px 16px; border-bottom: 1px solid var(--border-soft); font-size: var(--fs-body-sm); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfe; }
.table-wrap { overflow-x: auto; }
.empty-row td { text-align: center; color: var(--text-faint); padding: 32px; }

/* Badges - class names map to complaint status categories */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: var(--fs-label); font-weight: 800;
}
.badge-draft { background: var(--neutral-bg); color: var(--neutral-text); }
.badge-pending { background: var(--warning-bg); color: var(--warning-text); }
.badge-progress { background: var(--info-bg); color: var(--info-text); }
.badge-verification { background: var(--purple-bg); color: var(--purple); }
.badge-closed { background: var(--success-bg); color: var(--success-text); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 18px; border-radius: 12px; font-size: var(--fs-body-sm); font-weight: 700;
  border: none; cursor: pointer;
  background: linear-gradient(135deg, var(--color-accent), var(--color-accent-hover)); color: var(--color-text-on-accent);
  box-shadow: 0 10px 22px rgba(47, 60, 143, .25);
  font-family: var(--font-sans);
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn:active { transform: scale(.97); filter: brightness(.96); transition: transform 60ms ease-out; }
.btn { transition: transform 140ms ease-out, filter 140ms ease-out; }
.btn[disabled] { opacity: .7; cursor: not-allowed; filter: none; }
/* Apply with nothing to apply: flat and quiet, clearly not pressable */
.fb-actions .btn[disabled], .ds .fb-actions .btn[disabled] { opacity: 1; background: var(--neutral-bg); color: var(--neutral-text); transform: none; }
.btn .spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .4); border-top-color: #fff;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.btn-secondary { background: var(--color-surface); color: var(--color-accent); border: 1.5px solid var(--border); box-shadow: none; }
.btn-secondary:hover { background: var(--color-accent-soft); filter: none; }
.btn-danger { background: var(--accent); box-shadow: 0 10px 22px rgba(224, 73, 47, .25); }
.btn-danger:hover { filter: brightness(1.08); }
.btn-sm { padding: 7px 13px; font-size: var(--fs-label); border-radius: 9px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 8px 24px rgba(28, 35, 64, .05); padding: 20px 22px; }

/* Forms */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block; font-size: var(--fs-label); font-weight: 700; color: var(--text-secondary);
  margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em;
}
.form-control {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--border); border-radius: 12px;
  font-size: var(--fs-body-sm); font-family: inherit; background: var(--color-surface); color: var(--text);
}
.form-control { transition: border-color .15s ease, box-shadow .15s ease; }
.form-control:focus { outline: none; border-color: var(--color-focus); box-shadow: 0 0 0 3px rgba(85, 97, 214, .18); }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.form-row .form-group { flex: 1; min-width: 160px; margin-bottom: 0; }

.flash { padding: 11px 16px; border-radius: 12px; font-size: var(--fs-body-sm); font-weight: 600; margin-bottom: 16px; }
.flash-error { background: var(--danger-bg); color: var(--danger); }
.flash-success { background: var(--success-bg); color: var(--success); }

/* ===== Feedback text (design system, every page) =====
   Field error: the control gets .is-invalid, the message under it is
   .field-msg (hidden until then; .show forces it). Banners: .flash +
   -error / -success / -warning / -info. Status colour is always paired with
   words - never colour alone. */
.form-control.is-invalid, .is-invalid { border-color: var(--status-danger-solid); background-color: var(--status-danger-bg); }
.field-msg {
  display: none; margin-top: 6px;
  font-size: var(--fs-body-sm); font-weight: var(--fw-strong); line-height: var(--lh-snug); color: var(--status-danger-fg);
}
.is-invalid + .field-msg, .field-msg.show { display: block; }
.flash-warning { background: var(--status-warning-bg); color: var(--status-warning-fg); }
.flash-info { background: var(--status-info-bg); color: var(--status-info-fg); }
.ds .flash { padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); font-size: var(--fs-body-sm); font-weight: var(--fw-medium); line-height: var(--lh-snug); }
.ds .flash-success { color: var(--status-success-fg); }
.ds .flash-error { color: var(--status-danger-fg); }

/* Guest / login split screen */
.guest-page { min-height: 100vh; display: flex; }
.guest-hero {
  flex: 1.1; background: linear-gradient(150deg, #171e4e 0%, #2f3c8f 55%, #4150c4 100%);
  color: var(--color-text-on-accent); display: flex; flex-direction: column; justify-content: space-between;
  padding: 56px;
}
.guest-hero .brand { display: flex; align-items: center; gap: 14px; }
.guest-hero .brand .mark { background: var(--color-surface); border-radius: 14px; padding: 8px 10px; display: flex; }
.guest-hero .brand .mark img { width: 46px; display: block; }
.guest-hero .brand .name { font-family: var(--font-display); font-weight: 700; font-size: var(--fs-title); }
.guest-hero .brand .tag { font-size: var(--fs-label); opacity: .75; }
.guest-hero .eyebrow {
  font-size: var(--fs-label); letter-spacing: .18em; text-transform: uppercase; opacity: .7;
  font-weight: 700; margin-bottom: 14px;
}
.guest-hero .headline { font-family: var(--font-display); font-weight: 800; font-size: var(--fs-display); line-height: 1.15; max-width: 520px; }
.guest-hero .sub { max-width: 460px; font-size: var(--fs-body); line-height: 1.65; opacity: .82; margin: 18px 0 0; }
.guest-hero .stats { display: flex; gap: 28px; flex-wrap: wrap; }
.guest-hero .stats .n { font-family: var(--font-display); font-weight: 800; font-size: var(--fs-h1); }
.guest-hero .stats .l { font-size: var(--fs-label); opacity: .7; }
.guest-hero .stats .divider { width: 1px; background: rgba(255, 255, 255, .25); }

.guest-form-side { flex: 1; display: flex; align-items: center; justify-content: center; padding: 40px 24px; background: var(--bg); }
.guest-card { width: 100%; max-width: 400px; }
/* Phones: the hero becomes a compact brand header above the form (side by side it pushed the page wider than the screen) */
@media (max-width: 767px) {
  .guest-page { flex-direction: column; }
  .guest-hero { flex: none; padding: 24px 20px; gap: 16px; }
  .guest-hero .headline { font-size: var(--fs-h2); }
  .guest-hero .sub, .guest-hero .stats { display: none; }
  .guest-form-side { align-items: flex-start; padding: 28px 20px 40px; }
}
.guest-card .title { font-family: var(--font-display); font-size: var(--fs-page-title); font-weight: 800; color: var(--text); }
.guest-card .subtitle { color: var(--text-muted); font-size: var(--fs-body-sm); margin: 6px 0 26px; }
.debug-code { background: var(--purple-bg); color: var(--purple); padding: 10px 14px; border-radius: 12px; font-size: var(--fs-body-sm); margin-bottom: 16px; font-weight: 600; }
.auth-tabs { display: flex; background: var(--bg); border: 1px solid var(--border); border-radius: 11px; padding: 4px; margin-bottom: 22px; gap: 2px; }
.auth-tabs button {
  flex: 1; padding: 9px 0; border: none; background: transparent; border-radius: 8px;
  font-family: var(--font-sans); font-size: var(--fs-body-sm); font-weight: 700; color: var(--text-muted); cursor: pointer;
}
.auth-tabs button.active { background: var(--color-surface); color: var(--color-accent); box-shadow: 0 2px 8px rgba(28, 35, 64, .08); }
.otp-input { text-align: center; font-size: var(--fs-h2); letter-spacing: 10px; }
.guest-footnote { font-size: var(--fs-label); color: var(--text-faint); line-height: 1.6; margin-top: 22px; }

.error-page { max-width: 600px; margin: 80px auto; text-align: center; }

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar > h2, .ds .toolbar > h2 { margin: 0; } /* a section heading beside its action */
.section-title { font-family: var(--font-display); font-size: var(--fs-h2); font-weight: 800; }
.text-muted { color: var(--text-muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: var(--fs-body-sm); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* Shown only when the page was opened from a Dashboard tile */
.origin-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 8px 8px 8px 16px; margin-bottom: 12px; border-radius: 12px; background: var(--color-accent-soft);
  font-size: var(--fs-body-sm); color: var(--text-secondary);
}
.origin-banner b { color: var(--color-accent); }

/* ===== Insight tiles (.kpi-tile) =====
   Count tiles above a list. A tile is also a one-click filter (?kpi=):
   the active one is outlined, clicking it again clears it. */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
/* Six tiles = one row whenever there's room for ~140px each (laptops with the sidebar); never a 5 + 1 orphan */
/* Sized by the content column: 6 in a row when each tile gets ~160px, else 3 + 3 - never a cramped
   row of six or a 5 + 1 orphan. Phones: 2 per row (media block at the end). */
@container (min-width: 560px) { .kpi-grid { grid-template-columns: repeat(var(--kpi-cols-md, 3), minmax(0, 1fr)); } }
@container (min-width: 1000px) { .kpi-grid { grid-template-columns: repeat(var(--kpi-cols, 6), minmax(0, 1fr)); } }
/* Other tile counts: one row on wide screens, an even split on laptops - never an orphan */
.kpi-grid.cols-3 { --kpi-cols: 3; --kpi-cols-md: 3; }
.kpi-grid.cols-4 { --kpi-cols: 4; --kpi-cols-md: 2; }
.kpi-tile {
  /* Compact: icon + label on one row, the number and its subline share the next row's baseline */
  position: relative; display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: baseline; align-content: start; /* taller neighbours never push this tile's rows apart */ column-gap: 8px; row-gap: 6px;
  padding: 10px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  color: var(--text); text-decoration: none;
  transition: border-color 160ms ease-out, box-shadow 160ms ease-out, transform 160ms ease-out;
}
a.kpi-tile:hover { text-decoration: none; color: var(--text); box-shadow: 0 6px 18px rgba(28, 35, 64, .07); }
/* Feedback on press */
a.kpi-tile:active { transform: scale(.98); transition-duration: 80ms; }
a.kpi-tile:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.kpi-head { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.kpi-icon {
  width: 24px; height: 24px; border-radius: 7px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
  background: var(--tone); color: var(--color-text-on-accent);
}
.kpi-icon svg { width: 14px; height: 14px; }
.kpi-label {
  font-size: var(--fs-label); font-weight: var(--fw-strong); line-height: var(--lh-tight);
  letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--text-meta);
}
.kpi-value {
  font-family: var(--font-display); font-size: var(--fs-h2); font-weight: var(--fw-heavy); line-height: 1.1;
  letter-spacing: -.02em; font-variant-numeric: tabular-nums; color: var(--text);
}
.kpi-value small { font-size: var(--fs-label); font-weight: var(--fw-strong); letter-spacing: 0; color: var(--text-meta); }
.kpi-sub { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Labels say what the number is: wrap to a second line rather than cut ("TOTAL COMPLA…") */
.kpi-label { min-width: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.kpi-sub { font-size: var(--fs-label); font-weight: var(--fw-regular); color: var(--text-meta); }
/* A word value (e.g. a zone name) ends in "…"; the tile's tooltip has it in full */
.kpi-value { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Overline above a row of tiles */
.kpi-heading { margin: var(--space-5) 0 var(--space-2); }
.kpi-heading:first-child { margin-top: 0; }
/* Tone = tinted surface + solid icon badge. Values and labels stay in text colours
   (never the tone), so every number keeps full contrast on its tint. Tones match the
   status badges in the table: green on-time / resolved, blue in progress, red breached. */
.kpi-tile.tone-navy { --tone: var(--color-accent); --tint: #eef0fb; --edge: #d5daf3; }
.kpi-tile.tone-danger { --tone: var(--danger); --tint: var(--danger-bg); --edge: #f6cdcd; }
.kpi-tile.tone-info { --tone: var(--info); --tint: var(--info-bg); --edge: #c9e0f9; }
.kpi-tile.tone-success { --tone: var(--success-text); --tint: var(--success-bg); --edge: #c3ead6; }
.kpi-tile.tone-warning { --tone: var(--status-warning-solid); --tint: var(--status-warning-bg); --edge: #f6dcb4; }
.kpi-tile.tone-verify { --tone: var(--status-verify-solid); --tint: var(--status-verify-bg); --edge: #e4d2fb; }
.kpi-tile.tone-neutral { --tone: var(--neutral-text); --tint: var(--neutral-bg); --edge: #dde1ee; }
.kpi-tile { background: var(--tint, var(--surface)); border-color: var(--edge, var(--border)); }
a.kpi-tile:hover { border-color: var(--tone); }
.kpi-tile.is-active { border-color: var(--tone); box-shadow: inset 0 0 0 1px var(--tone), 0 6px 18px rgba(28, 35, 64, .08); background: var(--tint); }
.kpi-on { color: var(--text); font-weight: var(--fw-heavy); } /* text colour, not the tone: the blue tone is only 4.49:1 on its tint */

/* ===== Filter bar (.fb) =====
   Search pill + "Filters" toggle always visible; the filter pills live in a
   panel that opens by animating grid-template-rows 0fr -> 1fr, so it grows
   to its natural height with no measuring and no jump. Pills carry their own
   name ("Zone", "Zone · Gulberg") instead of a label row. */
.fb {
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  box-shadow: var(--shadow-sm); margin-bottom: 16px;
}
.fb-top { display: flex; gap: 10px; align-items: center; padding: 10px; }
.fb-search { position: relative; flex: 1; min-width: 0; }
/* The magnifier is a real submit button: click it or press Enter in the field */
.fb-search-btn {
  position: absolute; right: 5px; top: 50%; transform: translateY(-50%); width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 50%;
  background: transparent; color: var(--neutral-text); cursor: pointer;
  transition: background-color 120ms ease-out, color 120ms ease-out, transform 120ms ease-out;
}
.fb-search-btn svg { width: 18px; height: 18px; }
.fb-search-btn:hover { background: #e3e7f3; color: var(--color-accent); }
.fb-search-btn:active { transform: translateY(-50%) scale(.92); }
.fb-search-btn:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 1px; }
.fb-search-pill {
  width: 100%; min-width: 0; height: 46px; padding: 0 46px 0 18px; border: 1px solid transparent; border-radius: 999px;
  background: #f1f3f9;
  font-family: var(--font-sans); font-size: var(--fs-body); font-weight: var(--fw-regular); color: var(--text);
  transition: background-color 160ms ease-out, border-color 160ms ease-out, box-shadow 160ms ease-out;
}
.fb-search-pill::placeholder { color: var(--text-meta); opacity: 1; }
.fb-search-pill:hover { background-color: #eceff7; }
.fb-search-pill:focus { outline: none; background-color: var(--surface); border-color: var(--color-focus); box-shadow: var(--focus-ring); }
.fb-search-pill.is-set { background-color: var(--color-accent-soft); }

/* Pill: the toggle, every dropdown trigger and the date fields */
.chip {
  display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px;
  border: 1px solid var(--border-input); border-radius: 999px; background: var(--surface);
  font-family: var(--font-sans); font-size: var(--fs-body-sm); font-weight: var(--fw-medium); color: var(--text);
  white-space: nowrap; cursor: pointer;
  transition: background-color 140ms ease-out, border-color 140ms ease-out, color 140ms ease-out, transform 140ms ease-out;
}
/* background-color, never the background shorthand: it would reset the dropdown chevron image to a tiled repeat */
.chip:hover { border-color: var(--text-meta); background-color: var(--color-surface-sunken); }
.chip:active { transform: scale(.97); transition-duration: 60ms; }
.chip-date:active { transform: none; } /* a text field, not a button - pressing it to type shouldn't shrink it */
.chip:focus-visible, .chip:focus-within { outline: none; border-color: var(--color-focus); box-shadow: var(--focus-ring); }
/* Keyboard focus: a solid 2px ring with a gap - clearly visible on white, tints and the navy "set" pills */
.chip:focus-visible, .chip-date:focus-within, .fb-search-pill:focus-visible, .kpi-tile:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.chip.is-set { background: var(--color-accent-strong); border-color: var(--color-accent-strong); color: var(--color-text-on-accent); }
.chip.is-set:hover { background-color: var(--color-accent); border-color: var(--color-accent); }
.chip svg { width: 16px; height: 16px; flex-shrink: 0; }
.chip-count {
  min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--color-accent-hover); color: var(--color-text-on-accent); font-size: var(--fs-label); font-weight: var(--fw-heavy);
}
.chip.is-set .chip-count { background: var(--color-surface); color: var(--color-accent-strong); }
.fb-toggle { height: 46px; padding: 0 16px; }
.fb-toggle-chev { transition: transform 360ms cubic-bezier(.32, .72, 0, 1); }
.fb.is-open .fb-toggle-chev { transform: rotate(180deg); }

/* Dropdown pills: "Zone" / "Zone · Gulberg" + chevron */
/* Fixed width: choosing a value never resizes the pill (and never reflows the row); long values end in "…" */
.chip.sel-trigger { width: 210px; padding-right: 36px; overflow: hidden; background-repeat: no-repeat; background-position: right 12px center;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23475070' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E"); }
.chip.sel-trigger.is-set { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23ffffff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E"); }
.chip-key { flex-shrink: 0; }
.chip-val { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-weight: var(--fw-strong); }
.chip-val::before { content: '·'; margin-right: 8px; opacity: .7; }

.chip-date { gap: 6px; cursor: text; }
.chip-date > span { color: var(--text-meta); font-weight: var(--fw-strong); }
.chip-date.is-set > span { color: #c9cff0; }
.chip-date input {
  border: 0; padding: 0; background: transparent; color: inherit; font: inherit; font-weight: var(--fw-medium);
  min-width: 0; width: 128px; outline: none; color-scheme: light;
}
.chip-date.is-set input { color-scheme: dark; }

.fb-panel {
  display: grid; grid-template-rows: 0fr;
  /* Close a little faster than it opens */
  transition: grid-template-rows 260ms cubic-bezier(.32, .72, 0, 1);
}
.fb.is-open .fb-panel { grid-template-rows: 1fr; transition-duration: 380ms; }
.fb-panel-inner {
  min-height: 0; overflow: hidden; opacity: 0; transform: translateY(-6px);
  transition: opacity 180ms ease-out, transform 260ms cubic-bezier(.32, .72, 0, 1), visibility 0s 260ms;
  visibility: hidden;
}
.fb.is-open .fb-panel-inner { opacity: 1; transform: none; visibility: visible; transition: opacity 260ms ease-out 60ms, transform 380ms cubic-bezier(.32, .72, 0, 1), visibility 0s; }
/* Once fully open, let dropdown lists spill out of the panel */
.fb.is-settled .fb-panel-inner { overflow: visible; }
.fb-chips {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 10px 10px 12px; margin: 0 10px; border-top: 1px solid var(--border-soft);
}
.fb-actions { display: flex; gap: 8px; align-items: center; margin-left: auto; }
.fb-actions .btn, .ds .fb-actions .btn { height: var(--pill-h); padding: 0 var(--space-5); border-radius: var(--radius-pill); font-size: var(--fs-body-sm); box-shadow: none; }
.fb-clear {
  height: 40px; padding: 0 12px; border-radius: 999px; display: inline-flex; align-items: center;
  font-size: var(--fs-body-sm); font-weight: var(--fw-strong); color: var(--color-accent);
}
.fb-clear:hover { background: var(--bg); text-decoration: none; }
.fb-clear:active, .col-reset:active { background: var(--border-soft); }

/* ===== Themed dropdown (.sel) - built by /assets/select.js from <select data-select> ===== */
.sel { position: relative; display: inline-block; }
/* The real <select> stays for the form only - author display rules would otherwise beat [hidden] */
.sel > select { display: none !important; }
.sel-trigger { text-align: left; cursor: pointer; }
/* Form-field dropdown: same panel, chevron, states and keyboard as the filter pills; the closed field keeps
   the form-control shape (height, radius, border) so it lines up with the text inputs around it, and the
   label stays above it. */
.sel-field { display: block; width: 100%; }
.form-control.sel-trigger {
  display: block; width: 100%; padding-right: 40px; line-height: normal; /* = the text inputs beside it */
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--color-text);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23475070' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important; background-position: right 14px center !important; /* survives pages' own .is-invalid background shorthands */
  transition: border-color var(--dur-fast) ease-out, box-shadow var(--dur-fast) ease-out;
}
.form-control.sel-trigger:hover { border-color: var(--color-text-meta); }
.form-control.sel-trigger:active { background-color: var(--color-surface-sunken); }
.form-control.sel-trigger:focus-visible { outline: none; border-color: var(--color-focus); box-shadow: var(--focus-ring); }
.form-control.sel-trigger.is-placeholder { color: var(--color-text-meta); }
.form-control.sel-trigger:disabled { cursor: not-allowed; background-color: var(--color-surface-sunken); color: var(--color-text-meta); }
.form-control.sel-trigger.is-invalid { border-color: var(--status-danger-solid); background-color: var(--status-danger-bg); }
/* The error message sits after the dropdown's wrapper now, not right after the <select> */
.sel:has(> select.is-invalid) + .field-msg { display: block; }
.sel.is-open .sel-trigger { border-color: var(--color-focus); box-shadow: var(--focus-ring); }
.sel-list {
  position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; min-width: max(100%, 240px); max-width: min(340px, 90vw);
  max-height: 320px; overflow-y: auto; margin: 0; padding: 6px; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow-lg);
  /* Grows out of the trigger, so it reads as coming from it */
  transform-origin: top left; animation: sel-in 160ms cubic-bezier(.32, .72, 0, 1);
}
.sel.is-up .sel-list { top: auto; bottom: calc(100% + 6px); transform-origin: bottom left; animation-name: sel-in-up; }
.sel.is-right .sel-list { left: auto; right: 0; transform-origin: top right; }
.sel.is-up.is-right .sel-list { transform-origin: bottom right; }
/* Exit = a quicker reverse of the entrance, back toward the trigger */
.sel.is-closing .sel-list { animation: sel-out 120ms ease-in forwards; }
.sel.is-up.is-closing .sel-list { animation-name: sel-out-up; }
@keyframes sel-in { from { opacity: 0; transform: scale(.96) translateY(-4px); } }
@keyframes sel-in-up { from { opacity: 0; transform: scale(.96) translateY(4px); } }
@keyframes sel-out { to { opacity: 0; transform: scale(.97) translateY(-3px); } }
@keyframes sel-out-up { to { opacity: 0; transform: scale(.97) translateY(3px); } }
.sel-option {
  position: relative; padding: 9px 32px 9px 10px; border-radius: 8px; cursor: pointer;
  font-size: var(--fs-body-sm); font-weight: var(--fw-regular); line-height: var(--lh-tight); color: var(--text);
}
.sel-option.is-active { background: #eef1fb; }
.sel-option:active { background: #e3e7f7; }
.sel-option[aria-selected="true"] { color: var(--color-accent); font-weight: var(--fw-strong); }
.sel-option[aria-selected="true"]::after {
  content: ''; position: absolute; right: 10px; top: 50%; width: 14px; height: 14px; margin-top: -7px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%232f3c8f' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m3 8.5 3.2 3L13 4.5'/%3E%3C/svg%3E") no-repeat center / contain;
}
.sel-group {
  padding: 10px 10px 4px; font-size: var(--fs-label); font-weight: var(--fw-strong);
  letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--text-meta);
}
.sel-group:not(:first-child) { margin-top: 4px; border-top: 1px solid var(--border-soft); }

/* ===== Range bar (one line: quick ranges left, custom From / To + Apply right; wraps rather than clips) ===== */
/* Date range: no row of its own - the pill sits at the right of the "Complaints" overline (.kpi-head-row) and opens a panel
   floating over the page (as the themed dropdowns: grows out of the pill, 160ms), so nothing below moves. */
.kpi-head-row { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); margin-bottom: var(--space-2); }
.kpi-head-row .kpi-heading { margin: 0; }
.range-bar { position: relative; }
.range-toggle { gap: 8px; height: var(--control-h-sm); padding: 0 14px; }
.range-toggle svg { width: 16px; height: 16px; flex: none; }
.range-toggle-key { font-weight: var(--fw-medium); }
.range-toggle-val { font-weight: var(--fw-strong); }
.range-toggle-val::before { content: "·"; margin-right: 8px; font-weight: var(--fw-medium); opacity: .7; }
.range-toggle-chev { transition: transform var(--dur-base) var(--ease-standard); }
.range-bar.is-open .range-toggle-chev { transform: rotate(180deg); }
.range-panel {
  position: absolute; z-index: var(--z-popover); top: calc(100% + 8px); right: 0; width: 440px; max-width: calc(100vw - 32px);
  padding: var(--space-4); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; gap: var(--space-2);
  transform-origin: top right; animation: sel-in 160ms var(--ease-standard);
}
.range-panel[hidden] { display: none; }
.range-panel-label { margin: 0; }
.range-panel-label + .range-presets, .range-panel-label + .range-custom { margin-bottom: var(--space-2); }
.range-panel .range-presets { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); }
.range-panel .range-presets .chip { justify-content: center; }
.range-panel .range-custom { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); margin-left: 0; }
.range-panel .range-custom .btn { grid-column: 1 / -1; }
.range-panel .range-custom { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.range-panel .chip-date { width: auto; min-width: 0; }
.range-bar .btn { height: var(--pill-h); padding: 0 var(--space-5); border-radius: var(--radius-pill); box-shadow: none; }
.range-presets .chip, .range-presets .chip:hover { text-decoration: none; }
.range-custom .chip-date input { flex: 1; width: auto; min-width: 0; }
/* Very narrow: From / To stack */
@container (max-width: 379px) { .range-panel .range-custom { grid-template-columns: minmax(0, 1fr); } }
/* Touch: 16px in the date fields stops iPhone / iPad zooming into the field on tap */
@media (pointer: coarse) { .range-custom .chip-date input { font-size: var(--size-16); } }

/* ===== Charts: card head, donut (Complaints by category), hover tip, intake bar ===== */
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-2); flex-wrap: wrap; }
/* A card's link to its full page ("Open full map", "View all 15"): 14px accent text + arrow, as TYPOGRAPHY.md's links -
   underline on hover (the arrow nudges right), focus outline */
.card-link { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-body-sm); font-weight: var(--fw-medium); line-height: var(--lh-tight); color: var(--color-accent); white-space: nowrap; }
.card-link svg { width: 14px; height: 14px; flex: none; transition: transform var(--dur-fast) ease; }
.card-link:hover { color: var(--color-accent-hover); text-decoration: underline; }
.card-link:hover svg { transform: translateX(2px); }
.card-link:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; border-radius: 4px; }
@media (prefers-reduced-motion: reduce) { .card-link svg { transition: none; } }
.map-card { display: flex; flex-direction: column; }
.density-card .dash-map { min-height: 460px; }
.density-key { display: inline-flex; align-items: center; gap: 6px; color: var(--color-text-secondary); white-space: nowrap; }
.density-key i { width: 72px; height: 8px; border-radius: var(--radius-pill); background: linear-gradient(90deg, #0f9d76, #f59e0b, #e0492f); }
.density-n { color: var(--color-text); font-weight: var(--fw-strong); }
.dash-map { flex: 1; min-height: 0; margin-top: var(--space-3); border-radius: var(--radius-md); overflow: hidden; border: 1px solid var(--color-border-soft); }
/* Ring left, legend right at every width. The body's height is fixed (room for 6 legend rows: the ring's maximum,
   5 categories + Other) and the intake bar sits at the bottom, so a new date range never resizes the card. */
.mix-card { display: flex; flex-direction: column; container-type: inline-size; }
.mix-body { flex: 1; min-height: 172px; display: flex; align-items: center; margin-top: var(--space-3); }
.mix-empty { flex: 1; align-self: stretch; display: flex; align-items: center; justify-content: center; text-align: center; padding: var(--space-4); border: 2px dashed var(--color-border); border-radius: var(--radius-md); color: var(--color-text-meta); font-size: var(--fs-body-sm); }
.donut { flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--space-4); }
.donut-chart { position: relative; flex: none; width: 120px; }
/* The taller map row has room for a bigger ring */
.grid-map-row .donut-chart { width: 168px; }
/* A narrow card (the map row's side column, phones): ring above the legend, so long category names get the full width */
@container (max-width: 420px) {
  .donut { flex-direction: column; align-items: stretch; gap: var(--space-4); }
  .donut-chart, .grid-map-row .donut-chart { width: 148px; align-self: center; }
}
.donut-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.donut-seg { stroke: var(--color-surface); stroke-width: 2; stroke-linejoin: round; cursor: default; transition: opacity 150ms ease; }
.donut-seg.is-whole { stroke: none; }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; }
.donut-total { font-size: var(--size-24); font-weight: var(--fw-heavy); line-height: var(--lh-display); color: var(--color-text); font-variant-numeric: tabular-nums; }
.donut-caption { font-size: var(--size-12); line-height: var(--lh-tight); color: var(--color-text-meta); }
/* One grid for all rows (subgrid), so counts and percentages line up and take only the width they need */
.donut-legend { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 0; display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; column-gap: var(--space-2); align-content: center; font-size: var(--fs-body-sm); }
.donut-legend li { grid-column: 1 / -1; display: grid; grid-template-columns: auto minmax(0, 1fr) auto 3em; grid-template-columns: subgrid; align-items: center; padding: 4px 0; color: var(--color-text-secondary); transition: opacity 150ms ease; }
.donut-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.donut-n { color: var(--color-text-meta); text-align: right; }
.donut-pct { text-align: right; color: var(--color-text); font-weight: var(--fw-strong); }
.donut-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; vertical-align: -1px; }
/* Hover: the pointed arc / legend row stays, the rest steps back */
.donut.is-focus .donut-seg:not(.is-on), .donut.is-focus .donut-legend li:not(.is-on) { opacity: .35; }
.chart-tip { position: absolute; z-index: 3; pointer-events: none; transform: translate(-50%, calc(-100% - 10px)); white-space: nowrap; background: var(--color-text); color: var(--color-surface); font-size: var(--fs-body-sm); line-height: var(--lh-tight); padding: 6px 10px; border-radius: 8px; box-shadow: var(--shadow-lg); }
.chart-tip b { font-weight: var(--fw-strong); }
.intake { border-top: 1px solid var(--border-soft); margin-top: var(--space-4); padding-top: var(--space-3); }
.intake-bar { display: flex; gap: 2px; height: 12px; border-radius: var(--radius-pill); overflow: hidden; margin-top: var(--space-2); background: var(--color-bg); }
.intake-legend { display: flex; justify-content: space-between; gap: var(--space-2); flex-wrap: wrap; margin-top: var(--space-2); color: var(--color-text-secondary); }
.intake-legend .donut-swatch { margin-right: 6px; }

/* ===== Weekly trend (line chart). Plot = a box with % coordinates: grid lines, points, hover columns and the tip are
   HTML (text stays on the type scale), the two lines are an SVG stretched to the box with non-scaling 2px strokes. */
/* The card can be stretched by its row neighbour (SLA alerts); the plot takes up all spare height, so the card never has
   dead space - the chart just gets taller (180px minimum). */
.trend-card { container-type: inline-size; display: flex; flex-direction: column; }
.trend-meta { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-1) var(--space-4); flex-wrap: wrap; margin-top: 2px; }
.trend-legend { display: flex; gap: var(--space-4); color: var(--color-text-secondary); }
.trend-legend b { color: var(--color-text); font-weight: var(--fw-strong); margin-left: 2px; }
.trend-key { display: inline-block; width: 14px; height: 2px; border-radius: 2px; background: var(--c); vertical-align: middle; margin-right: 6px; position: relative; }
.trend-key::after { content: ""; position: absolute; left: 50%; top: 50%; width: 8px; height: 8px; border-radius: 50%; background: var(--c); transform: translate(-50%, -50%); }
.trend { flex: 1; display: flex; flex-direction: column; min-height: 0; margin-top: var(--space-4); padding-left: 32px; }
.trend-plot { position: relative; flex: 1; min-height: 180px; }
.trend-grid { position: absolute; left: 0; right: 0; height: 0; border-top: 1px solid var(--color-border-soft); }
.trend-grid.is-base { border-top-color: var(--color-border); }
.trend-ytick { position: absolute; right: calc(100% + 8px); top: 0; transform: translateY(-50%); font-size: var(--fs-label); line-height: 1; color: var(--color-text-meta); white-space: nowrap; }
.trend-lines { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.trend-lines polyline { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.trend-week { position: absolute; top: 0; bottom: 0; }
.trend-week::before { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: var(--color-border); opacity: 0; transition: opacity 120ms ease; }
.trend-dot { position: absolute; left: 50%; width: 8px; height: 8px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 2px var(--color-surface); transform: translate(-50%, -50%); transition: transform 120ms ease; }
.trend-tip { position: absolute; left: 50%; bottom: calc(100% + 8px); transform: translateX(-50%); z-index: 3; display: none; flex-direction: column; gap: 2px; white-space: nowrap; background: var(--color-text); color: var(--color-surface); font-size: var(--fs-body-sm); line-height: var(--lh-tight); padding: 8px 10px; border-radius: 8px; box-shadow: var(--shadow-lg); pointer-events: none; }
.trend-tip b { font-weight: var(--fw-strong); }
.trend-tip .trend-key { box-shadow: none; }
.trend-week.is-first .trend-tip { left: 0; transform: none; }
.trend-week.is-last .trend-tip { left: auto; right: 0; transform: none; }
.trend-week:hover::before { opacity: 1; }
.trend-week:hover .trend-dot { transform: translate(-50%, -50%) scale(1.25); }
.trend-week:hover .trend-tip { display: flex; }
/* Column variant (participation): one group of bars per week column, centred, 2px apart, square to the baseline */
.trend-bars { position: absolute; inset: 0; display: flex; align-items: flex-end; justify-content: center; gap: 2px; pointer-events: none; }
.trend-bar { width: min(16px, 30%); background: var(--c); border-radius: 4px 4px 0 0; transform-origin: bottom; transition: filter 120ms ease; }
.trend-week:hover .trend-bar { filter: brightness(.9); }
.part-card .trend-week::before { left: 0; width: 100%; background: rgba(28, 35, 64, .04); }
/* This week, still running: hatched bars in the series hue (45° texture), so a partial week never reads as a drop */
.trend-week.is-partial .trend-bar { background: repeating-linear-gradient(135deg, var(--c) 0 2px, color-mix(in srgb, var(--c) 30%, var(--color-surface)) 2px 5px); box-shadow: inset 0 0 0 1px var(--c); }
.trend-tip-note { font-weight: var(--fw-regular); opacity: .8; margin-left: 4px; }
.trend-x { position: relative; flex: none; height: 24px; }
.trend-x span { position: absolute; top: 8px; transform: translateX(-50%); font-size: var(--fs-label); line-height: 1; color: var(--color-text-meta); white-space: nowrap; }
/* Narrow card: label every other week so dates never collide */
@container (max-width: 440px) {
  .trend-x span:nth-child(even) { visibility: hidden; }
  /* the monthly area chart marks its own (it may show only two, and the latest must stay) */
  .area-card .trend-x span:nth-child(even) { visibility: visible; }
  .area-card .trend-x span.is-minor { visibility: hidden; }
}
/* A single area series (Validated patch area): a 10% wash of the line's hue under it. With many months the points
   show only on hover, so the line isn't beaded */
.trend-lines polygon { stroke: none; fill-opacity: .1; }
.trend.is-dense .trend-dot { opacity: 0; transition: opacity 120ms ease; }
.trend.is-dense .trend-week:hover .trend-dot { opacity: 1; }
.is-entering .trend.is-dense .trend-dot { animation: none; }
.area-total { color: var(--color-text-secondary); }
.area-total b { color: var(--color-text); font-weight: var(--fw-strong); }
.trend-now { border-top: 1px solid var(--color-border-soft); margin-top: var(--space-3); padding-top: var(--space-3); color: var(--color-text-secondary); }
.trend-now b { color: var(--color-text); font-weight: var(--fw-strong); }
@media (prefers-reduced-motion: reduce) { .trend-week::before, .trend-dot { transition: none; } }

/* ===== Zone comparison (spider chart). The SVG is drawn 1:1 in px (no scaling), centred at --cy; zone labels are HTML
   placed round it, anchored on the side they sit (right / left / top / bottom) so they grow away from the chart. */
.radar { --cy: 160px; position: relative; height: 300px; margin-top: var(--space-2); }
.radar-plot { position: absolute; left: calc(50% - 110px); top: calc(var(--cy) - 110px); overflow: visible; }
.radar-ring { fill: none; stroke: var(--color-border-soft); }
.radar-ring.is-outer { stroke: var(--color-border); }
.radar-tick { font-size: var(--fs-label); fill: var(--color-text-meta); font-variant-numeric: tabular-nums; }
.radar-spoke { stroke: var(--color-border-soft); transition: stroke 120ms ease; }
.radar-shape { fill: var(--c); fill-opacity: .12; stroke: var(--c); stroke-width: 2; stroke-linejoin: round; }
.radar-dot { fill: var(--c); stroke: var(--color-surface); stroke-width: 2; transform-box: fill-box; transform-origin: center; transition: transform 120ms ease, opacity 120ms ease; }
.radar-label { position: absolute; display: flex; flex-direction: column; gap: 2px; max-width: 120px; font-size: var(--fs-body-sm); line-height: var(--lh-tight); cursor: default; transition: opacity 120ms ease; }
.radar-label.is-right { transform: translate(0, -50%); text-align: left; }
.radar-label.is-left { transform: translate(-100%, -50%); text-align: right; align-items: flex-end; }
.radar-label.is-top { transform: translate(-50%, -100%); text-align: center; align-items: center; }
.radar-label.is-bottom { transform: translate(-50%, 0); text-align: center; align-items: center; }
.radar-name { color: var(--color-text-secondary); font-weight: var(--fw-strong); }
.radar-val { display: inline-flex; align-items: center; gap: 4px; color: var(--color-text-meta); font-size: var(--fs-label); white-space: nowrap; }
.radar-val b { color: var(--color-text); font-weight: var(--fw-strong); margin-right: 4px; }
.key-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; }
.radar.is-focus .radar-label:not(.is-on) { opacity: .4; }
.radar.is-focus .radar-dot:not(.is-on) { opacity: .35; }
.radar-dot.is-on { transform: scale(1.3); }
.radar-spoke.is-on { stroke: var(--color-text-meta); }
.zone-list { list-style: none; margin: var(--space-3) 0 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.zone-list li { display: flex; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; font-size: var(--fs-body-sm); }
@keyframes radar-in { from { transform: scale(0); } to { transform: scale(1); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.is-entering .radar-shape { transform-box: view-box; transform-origin: 50% 50%; animation: radar-in 800ms var(--ease-standard) both; }
.is-entering .radar-dot { animation: fade-in 300ms ease 550ms both; }

/* ===== Speed by stage (stacked bar), Category momentum (dumbbell), SLA performance and gate meters ===== */
.anim-card { display: flex; flex-direction: column; container-type: inline-size; }
.speed-total { display: flex; align-items: baseline; gap: var(--space-2); margin-top: var(--space-4); }
.speed-total b { font-size: var(--fs-h1); font-weight: var(--fw-heavy); line-height: var(--lh-display); letter-spacing: var(--tracking-display); color: var(--color-text); font-variant-numeric: tabular-nums; }
.stage-bar { display: flex; gap: 2px; height: 14px; margin-top: var(--space-3); border-radius: var(--radius-pill); overflow: hidden; }
.stage-bar span { min-width: 4px; }
.stage-legend { list-style: none; margin: var(--space-4) 0 0; padding: 0; display: grid; grid-template-columns: auto minmax(0, 1fr) auto 3em; gap: var(--space-2) var(--space-2); align-items: center; color: var(--color-text-secondary); }
.stage-legend li { display: contents; }
.stage-legend b { color: var(--color-text); font-weight: var(--fw-strong); text-align: right; }
.stage-share { color: var(--color-text-meta); text-align: right; }
.db-legend { display: flex; gap: var(--space-4); margin-top: var(--space-3); color: var(--color-text-secondary); }
.db-legend .key-dot { margin-right: 6px; }
.db-key-prior, .db-prior { background: var(--color-surface); box-shadow: inset 0 0 0 2px var(--chart-seq-250); }
/* Each row is its own grid with fixed side columns, so rows line up and a narrow card can put the track under the name */
.db-list { list-style: none; margin: var(--space-3) 0 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-3); font-size: var(--fs-body-sm); }
/* Each category is a panel like the contractor rows beside it; when the row is taller the panels share the height
   (content centred in each) instead of leaving a blank block */
.momentum-card .db-list { flex: 1; gap: var(--space-2); }
.momentum-card .db-list li { flex: 1; min-height: 44px; padding: 8px 12px; border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--color-bg); }
.momentum-card .db-track::before { border-top-color: var(--color-border); }
.db-list li { display: grid; grid-template-columns: minmax(0, 11em) minmax(60px, 1fr) 4.5em 2.5em; gap: var(--space-3); align-items: center; }
.db-name { color: var(--color-text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.db-track { position: relative; height: 12px; }
.db-track::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; border-top: 1px solid var(--color-border-soft); }
.db-line { position: absolute; top: calc(50% - 1px); height: 2px; background: var(--chart-seq-250); }
.db-dot { position: absolute; top: 50%; width: 12px; height: 12px; border-radius: 50%; transform: translate(-50%, -50%); }
.db-cur { background: var(--chart-seq-450); box-shadow: 0 0 0 2px var(--color-surface); }
.db-val { color: var(--color-text-meta); white-space: nowrap; text-align: right; }
.db-val b { color: var(--color-text); font-weight: var(--fw-strong); }
.db-change { text-align: right; font-weight: var(--fw-strong); white-space: nowrap; }
.db-change.is-down { color: var(--status-success-fg); }
.db-change.is-up { color: var(--color-text-secondary); }
.db-change.is-flat { color: var(--color-text-meta); }
@container (max-width: 360px) {
  .db-list li { grid-template-columns: minmax(0, 1fr) 4.5em 2.5em; grid-template-areas: "name val chg" "track track track"; row-gap: var(--space-1); }
  .db-name { grid-area: name; } .db-val { grid-area: val; } .db-change { grid-area: chg; } .db-track { grid-area: track; }
}
.meters { flex: 1; display: flex; flex-direction: column; justify-content: space-evenly; gap: var(--space-5); margin-top: var(--space-4); }
.meter-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-2); font-size: var(--fs-body-sm); color: var(--color-text-secondary); }
.meter-head b { font-size: var(--fs-h2); font-weight: var(--fw-heavy); color: var(--color-text); font-variant-numeric: tabular-nums; }
.meter-track { height: 10px; margin: var(--space-2) 0 6px; border-radius: var(--radius-pill); background: #e3eefb; overflow: hidden; }
.meter-fill { height: 100%; border-radius: var(--radius-pill); background: var(--chart-seq-450); }

/* SLA gauges (overview.php $renderGauge): Metro UI-style analog dials - a 250° ring of 10 segments in their band's colour
   (solid up to the value, a pale tint beyond), a tapered needle, scale numbers inside the ring and the value in its centre.
   All text is HTML on the dial's % grid. One large dial over two small ones. */
.gauges { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: space-evenly; gap: var(--space-4); margin-top: var(--space-3); }
.gauges-row { width: 100%; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-3); }
.gauge { width: 100%; display: flex; flex-direction: column; align-items: center; margin: 0 auto; }
.gauge-lg { max-width: 250px; }
.gauge-sm { max-width: 180px; }
.gauge-dial { position: relative; width: 100%; }
.gauge-dial svg { display: block; width: 100%; height: auto; overflow: visible; }
.gauge-seg { fill: none; stroke: var(--c); stroke-width: 15; }
.gauge-seg.is-tint { stroke-opacity: .2; }
.gauge-needle { transform-box: view-box; transform-origin: 100px 100px; transform: rotate(var(--deg)); }
.gauge-needle path { fill: var(--color-text); }
.gauge-needle circle { fill: var(--color-surface); stroke: var(--color-text); stroke-width: 3; }
.gauge-mark { position: absolute; transform: translate(-50%, -50%); font-size: var(--fs-label); line-height: 1; color: var(--color-text-meta); white-space: nowrap; pointer-events: none; }
/* The value sits low in the dial, below where the needle tip can reach (r 50 → 79% at either end) */
.gauge-num { position: absolute; left: 50%; top: 89%; transform: translate(-50%, -50%); font-size: var(--fs-h2); font-weight: var(--fw-medium); line-height: 1; letter-spacing: var(--tracking-display); color: var(--color-text); white-space: nowrap; }
.gauge-lg .gauge-num { font-size: var(--fs-display); top: 88%; }
.gauge-read { display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center; margin-top: var(--space-2); }
.gauge-label { font-size: var(--fs-body-sm); font-weight: var(--fw-medium); color: var(--color-text-secondary); }
.gauge-status { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-label); font-weight: var(--fw-strong); color: var(--color-text); }
.gauge-status svg { width: 14px; height: 14px; border-radius: 50%; color: #fff; padding: 1px; }
.gauge-note { font-size: var(--fs-label); color: var(--color-text-meta); }
.gauge-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-1) var(--space-4); margin-top: var(--space-4); padding-top: var(--space-3); border-top: 1px solid var(--color-border-soft); color: var(--color-text-secondary); }
.gauge-key { display: inline-block; width: 14px; height: 4px; border-radius: 2px; background: var(--c); vertical-align: middle; margin-right: 6px; }
/* Zone coverage (overview.php): one row per zone - name, a bar of its open complaints on a shared scale (past due +
   on track, 2px apart), the counts in words, contractors and load. Wide: one line; narrow: the bar goes under the name. */
.zc-strong { color: var(--color-text); font-weight: var(--fw-strong); }
.zc-key { display: inline-block; width: 14px; height: 8px; border-radius: 4px; background: var(--c); vertical-align: middle; margin-right: 6px; }
/* Exactly five zones tall at every width: each row has a fixed height for its layout (--zc-row), the list is five of them
   (the five most in need), any more scroll inside it; the card is as tall as that and no more */
.zc-list { --zc-row: 58px; list-style: none; margin: var(--space-3) 0 0; padding: 0 2px 0 0; max-height: calc(5 * var(--zc-row)); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.zc-list.has-more { -webkit-mask-image: linear-gradient(#000 calc(100% - 28px), transparent); mask-image: linear-gradient(#000 calc(100% - 28px), transparent); }
.zc-list:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; border-radius: var(--radius-sm); }
.zc-foot { margin-top: auto; padding-top: var(--space-2); border-top: 1px solid var(--color-border-soft); display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-1) var(--space-3); flex-wrap: wrap; }
.zc-more { padding-top: var(--space-2); border-top: 1px solid var(--color-border-soft); text-align: center; }
/* Default (cards 420-759px wide): two lines - name and counts, then the bar with the contractor count beside it */
.zc-row { box-sizing: border-box; height: var(--zc-row); display: grid; grid-template-columns: minmax(0, 1fr) 16em; grid-template-rows: 22px 24px; grid-template-areas: "name open" "bar ctr"; align-items: center; align-content: center; gap: 4px var(--space-4); border-top: 1px solid var(--color-border-soft); font-size: var(--fs-body-sm); line-height: 20px; }
.zc-row:first-child { border-top: 0; }
.zc-name { grid-area: name; font-weight: var(--fw-strong); color: var(--color-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.zc-bar { grid-area: bar; display: flex; gap: 2px; height: 10px; min-width: 0; border-radius: var(--radius-pill); background: var(--color-border-soft); overflow: hidden; }
.zc-seg { height: 100%; background: var(--c); }
.zc-seg:first-child { border-radius: var(--radius-pill) 0 0 var(--radius-pill); }
.zc-seg:last-child { border-radius: 0 var(--radius-pill) var(--radius-pill) 0; }
.zc-seg:only-child { border-radius: var(--radius-pill); }
.zc-open { grid-area: open; color: var(--color-text-secondary); white-space: nowrap; text-align: right; }
.zc-open b { color: var(--color-text); font-weight: var(--fw-strong); }
.zc-ctr { grid-area: ctr; color: var(--color-text-meta); white-space: nowrap; text-align: right; overflow: hidden; text-overflow: ellipsis; }
.zc-flag { display: inline-flex; align-items: center; gap: 6px; padding: 1px 10px 1px 4px; border-radius: var(--radius-pill); background: var(--status-warning-bg); color: var(--status-warning-fg); font-size: var(--fs-label); font-weight: var(--fw-strong); line-height: 20px; }
.zc-flag svg { width: 16px; height: 16px; border-radius: 50%; background: var(--status-warning-solid); color: #fff; padding: 1px; }
/* Wide card: one line per zone */
@container (min-width: 760px) {
  .zc-list { --zc-row: 46px; }
  .zc-row { grid-template-columns: minmax(110px, 170px) minmax(0, 1fr) 10em 16em; grid-template-rows: 24px; grid-template-areas: "name bar open ctr"; }
  .zc-ctr { text-align: left; }
}
/* Narrow card (phones): name and counts, the bar on its own line, then contractors */
@container (max-width: 419px) {
  .zc-list { --zc-row: 76px; }
  .zc-row { grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: 20px 10px 22px; grid-template-areas: "name open" "bar bar" "ctr ctr"; gap: 6px var(--space-3); }
  .zc-ctr { text-align: left; }
}
/* SLA escalation alerts (overview.php): the most overdue open complaints, each a row with its ref, how long overdue,
   where and who, and when it was due; a link to all of them underneath */
.esc-card { display: flex; flex-direction: column; }
.esc-list { list-style: none; margin: var(--space-3) 0 0; padding: 0; display: flex; flex-direction: column; }
.esc-row { padding: 10px 0 10px 12px; border-top: 1px solid var(--color-border-soft); box-shadow: inset 3px 0 0 var(--status-danger-solid); }
.esc-row:first-child { border-top: 0; }
.esc-top { display: flex; justify-content: space-between; align-items: center; gap: var(--space-2); }
.esc-ref { font-family: var(--font-mono); font-size: var(--fs-body-sm); font-weight: var(--fw-strong); color: var(--color-accent); }
.esc-ref:hover { color: var(--color-focus); }
.esc-meta { color: var(--color-text-secondary); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.esc-foot { margin-top: auto; padding-top: var(--space-3); border-top: 1px solid var(--color-border-soft); display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-1) var(--space-3); flex-wrap: wrap; }
.esc-list + .esc-foot { margin-top: var(--space-3); }
@keyframes gauge-swing { from { transform: rotate(-215deg); } }
@keyframes seg-in { from { opacity: 0; } }
.is-entering .gauge-seg.is-fill { animation: seg-in 240ms ease both; animation-delay: calc(var(--i, 0) * 70ms); }
.is-entering .gauge-needle { animation: gauge-swing 900ms var(--ease-standard) both; }
/* Ranked bars (Contractor performance): name + value line, then a full-width track; one hue, shared 0..max scale */
.rank-list { list-style: none; margin: var(--space-4) 0 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-3); flex: 1; justify-content: space-evenly; }
.rank-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-1) var(--space-3); flex-wrap: wrap; font-size: var(--fs-body-sm); }
.rank-name { display: inline-flex; align-items: baseline; gap: var(--space-2); color: var(--color-text-secondary); font-weight: var(--fw-strong); min-width: 0; }
.rank-no { color: var(--color-text-meta); font-weight: var(--fw-medium); min-width: 1ch; }
.rank-val { color: var(--color-text-secondary); white-space: nowrap; }
.rank-val b { color: var(--color-text); font-weight: var(--fw-strong); }
.rank-bar { position: relative; margin-top: 6px; }
.rank-track { height: 10px; border-radius: var(--radius-pill); background: var(--slate-100); overflow: hidden; }
/* Contractor performance: each contractor is a panel of one fixed height (its two detail lines never wrap - the full
   text is in the row's tooltip), so the list shows exactly three and scrolls for the rest. */
.contractor-card .rank-list {
  --row-h: 104px; flex: none; justify-content: flex-start; gap: var(--space-2);
  max-height: calc(3 * var(--row-h) + 2 * var(--space-2)); overflow-y: auto; overscroll-behavior: contain;
  scroll-snap-type: y proximity; scrollbar-width: thin; margin-right: -6px; padding-right: 6px;
}
.contractor-card .rank-list li {
  flex: none; height: var(--row-h); box-sizing: border-box; display: flex; flex-direction: column; justify-content: center;
  padding: 10px 12px; border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--color-bg);
  scroll-snap-align: start; transition: border-color 120ms ease, background-color 120ms ease;
}
.contractor-card .rank-list li:hover { border-color: var(--color-border); background: var(--color-surface); }
.contractor-card .rank-sub { display: block; }
.contractor-card .rank-sub > span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contractor-card .rank-name { min-width: 0; }
.rank-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-no { display: inline-flex; align-items: center; justify-content: center; flex: none; min-width: 20px; height: 20px; padding: 0 4px; border-radius: var(--radius-pill); background: var(--color-surface); border: 1px solid var(--color-border); color: var(--color-text-secondary); font-size: var(--fs-label); font-weight: var(--fw-strong); }
.contractor-card .rank-head { align-items: center; flex-wrap: nowrap; }
.contractor-card .rank-track { background: var(--color-surface); }
.rank-more { margin-top: var(--space-2); text-align: center; text-wrap: balance; }
/* Narrow card (phones): taller panels so names can take two lines and the variance line can wrap - still three shown */
@container (max-width: 420px) {
  .contractor-card .rank-list { --row-h: 140px; }
  .contractor-card .rank-sub > span:last-child { white-space: normal; }
  .contractor-card .rank-sub .nowrap { white-space: nowrap; }
  .contractor-card .rank-title { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
}
/* Stacked bar: agreed area (green), variance (red), pending validation (amber), 2px apart, on the shared scale */
.rank-stack { display: flex; gap: 2px; height: 100%; }
.rank-stack span { height: 100%; flex: none; }
.rank-stack span:first-child { border-radius: var(--radius-pill) 0 0 var(--radius-pill); }
.rank-stack span:last-child { border-radius: 0 var(--radius-pill) var(--radius-pill) 0; }
.rank-stack span:only-child { border-radius: var(--radius-pill); }
.rank-stack .is-done, .rank-key-fill.is-done { background: var(--rag-green); }
.rank-stack .is-pending, .rank-key-fill.is-pending { background: var(--rag-amber); }
.rank-stack .is-variance, .rank-key-fill.is-variance { background: var(--rag-red); }
/* A non-zero variance reads in the danger text colour (AA on white), the bar's red segment shows its size */
.variance-off, .rank-sub .variance-off b, .variance-off b { color: var(--status-danger-fg); }
.rank-sub { display: flex; justify-content: space-between; gap: 0 var(--space-3); flex-wrap: wrap; margin-top: 4px; color: var(--color-text-meta); }
.rank-sub b { color: var(--color-text-secondary); font-weight: var(--fw-strong); }
.rank-legend { display: flex; gap: var(--space-1) var(--space-4); flex-wrap: wrap; margin-top: var(--space-3); color: var(--color-text-secondary); }
.rank-key-fill { display: inline-block; width: 14px; height: 8px; border-radius: 4px; background: var(--chart-seq-450); margin-right: 6px; }
/* Card header tools (unit switch + period), and the sq m | sq ft switch itself */
.card-tools { display: inline-flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.unit-toggle { display: inline-flex; padding: 2px; border-radius: var(--radius-pill); background: var(--color-bg); border: 1px solid var(--color-border); }
.unit-toggle button { border: 0; background: transparent; font: inherit; font-size: var(--fs-label); font-weight: var(--fw-strong); color: var(--color-text-meta); padding: 4px 10px; min-height: 28px; border-radius: var(--radius-pill); cursor: pointer; transition: background-color 120ms ease, color 120ms ease; }
.unit-toggle button[aria-pressed="true"] { background: var(--color-surface); color: var(--color-text); box-shadow: var(--shadow-sm); }
.unit-toggle button:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 1px; }
/* Content for one area unit only, e.g. axis ticks that are round in that unit (area-units.js marks <html> with the
   chosen unit; sq m until it runs) */
:root:not([data-area-pref="sqft"]) [data-unit-only="sqft"], :root[data-area-pref="sqft"] [data-unit-only="sqm"] { display: none; }
.is-entering .rank-stack.hbar { animation-delay: calc(var(--i, 0) * 70ms); }
.is-entering .hbar { animation: grow-in 800ms var(--ease-standard) both; }
.is-entering .db-line { animation: grow-in 600ms var(--ease-standard) both; animation-delay: calc(var(--i, 0) * 70ms); }
.is-entering .db-cur { animation: pop-in 320ms var(--ease-standard) both; animation-delay: calc(var(--i, 0) * 70ms + 250ms); }

/* ===== Control Panel motion (overview.php starts it; final values are in the HTML, so no JS = no motion) =====
   .is-entering plays the entrance once; .is-waiting holds it at its first frame until the card scrolls into view. */
@property --sweep { syntax: '<angle>'; inherits: false; initial-value: 360deg; }
@keyframes rise-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes donut-sweep { from { --sweep: 0deg; } to { --sweep: 360deg; } }
@keyframes grow-in { from { clip-path: inset(0 100% 0 0 round 999px); } to { clip-path: inset(0 0 0 0 round 999px); } }
@keyframes wipe-in { from { clip-path: inset(-6px 100% -6px -6px); } to { clip-path: inset(-6px -6px -6px -6px); } }
@keyframes pop-in { from { opacity: 0; transform: translate(-50%, -50%) scale(.3); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
.kpi-grid.is-entering .kpi-tile { animation: rise-in 420ms var(--ease-standard) both; animation-delay: calc(var(--i, 0) * 40ms); }
.is-entering .donut-chart svg { -webkit-mask-image: conic-gradient(#000 var(--sweep), transparent 0); mask-image: conic-gradient(#000 var(--sweep), transparent 0); animation: donut-sweep 800ms var(--ease-standard) both; }
.is-entering .intake-bar { animation: grow-in 700ms var(--ease-standard) 150ms both; }
/* linear, so each point can land exactly when the line reaches its week */
.is-entering .trend-lines { animation: wipe-in 900ms linear both; }
/* bars rise from the baseline, week by week, left to right */
.is-entering .trend-bar { animation: bar-rise 520ms var(--ease-standard) both; animation-delay: calc(var(--i, 0) * 60ms); }
@keyframes bar-rise { from { transform: scaleY(0); } to { transform: scaleY(1); } }
.is-entering .trend-dot { animation: pop-in 260ms var(--ease-standard) both; animation-delay: calc((var(--i, 0) + .4) * 900ms / var(--n, 8)); }
.is-waiting, .is-waiting * { animation-play-state: paused !important; }
/* While a new range loads: a soft light passes over the tiles and the ring (after the same 120ms grace as the dim) */
@keyframes sheen { from { background-position: 150% 0; } to { background-position: -50% 0; } }
[data-list-region].is-refreshing .kpi-tile::after, [data-list-region].is-refreshing .donut-chart::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, .7) 50%, transparent 70%) 150% 0 / 200% 100% no-repeat;
  animation: sheen 1100ms linear 120ms infinite;
}
[data-list-region].is-refreshing .donut-chart::after { border-radius: 50%; }
@media (prefers-reduced-motion: reduce) {
  .is-entering, .is-entering *, [data-list-region].is-refreshing *::after { animation: none !important; }
}

/* In-place regions marked data-soft-load (Control Panel) dim while the next range loads, instead of the full-screen
   loader; the delay keeps fast responses from flickering. */
[data-list-region].is-refreshing { opacity: .55; pointer-events: none; transition: opacity 200ms ease 120ms; }
@media (prefers-reduced-motion: reduce) { [data-list-region].is-refreshing { transition: none; } }

/* ===== Complaint pin legend (map/_pin-legend.php): /map and the Control Panel's live work map ===== */
.pin-key { display: inline-flex; gap: 6px; align-items: center; }
.pin-dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: none; }
.pin-legend { display: flex; gap: var(--space-1) 14px; flex-wrap: wrap; margin-top: var(--space-2); font-weight: var(--fw-strong); color: var(--color-text-secondary); }

/* ===== Maps (Leaflet) =====
   Leaflet stacks its panes and controls at z-index 400-1000. Contain them in the map's own stacking
   context so dropdowns, menus and popovers opened next to a map (filter dropdowns, the column menu,
   the off-canvas sidebar) always render on top of it. */
.leaflet-container { isolation: isolate; }

/* ===== Column picker (#col-menu) - checkboxes hiding a .dt table's [data-col] cells (any list page) ===== */
.col-picker { position: relative; }
.col-menu {
  position: absolute; z-index: 40; top: calc(100% + 8px); right: 0; width: 250px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow-lg);
  transform-origin: top right; animation: sel-in 160ms cubic-bezier(.32, .72, 0, 1);
}
.col-menu[hidden] { display: none; }
.col-menu.is-closing { animation: sel-out 120ms ease-in forwards; }
@media (max-width: 420px) { .col-menu { width: min(250px, calc(100vw - 32px)); } }
.col-menu-head {
  display: flex; align-items: center; justify-content: space-between; padding: 8px 10px 6px;
  font-size: var(--fs-label); font-weight: var(--fw-strong); letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--text-meta);
}
.col-reset {
  border: 0; background: none; padding: 4px 6px; border-radius: 6px; cursor: pointer;
  font: inherit; font-size: var(--fs-label); font-weight: var(--fw-strong); letter-spacing: 0; text-transform: none; color: var(--color-accent);
}
.col-reset:hover { background: var(--bg); }
.col-opt {
  display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 0 10px; border-radius: 8px; cursor: pointer;
  font-size: var(--fs-body-sm); font-weight: var(--fw-medium); color: var(--text);
}
.col-opt:hover { background: var(--color-surface-selected); }
.col-opt input { width: 18px; height: 18px; margin: 0; accent-color: var(--color-accent); cursor: pointer; }
.col-opt small { margin-left: auto; font-size: var(--fs-label); font-weight: var(--fw-regular); color: var(--text-meta); }
.col-opt.is-locked { cursor: default; }
/* Hidden columns (any .dt table): list.js / the inline restore script set [hidden] on that column's cells */
table.dt [hidden] { display: none !important; }
/* Fewer columns need less room before the table scrolls sideways */
table.dt[data-hidden-cols]:not([data-hidden-cols=""]) { min-width: 0; }

/* ===== Full-screen loader - frosted layer while a list fetches ===== */
.page-loader {
  position: fixed; inset: 0; z-index: 1000; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: rgba(244, 246, 251, .6); -webkit-backdrop-filter: blur(6px) saturate(140%); backdrop-filter: blur(6px) saturate(140%);
  opacity: 0; transition: opacity 180ms ease-out;
}
.page-loader[hidden] { display: none; }
.page-loader.is-visible { opacity: 1; }
/* Failsafe for the first-load loader: if list.js never runs (blocked, failed to load), fade it out anyway */
.page-loader.is-boot { animation: loader-failsafe 200ms ease-out 6s forwards; }
@keyframes loader-failsafe { to { opacity: 0; visibility: hidden; } }
.page-loader-spin {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid rgba(47, 60, 143, .15); border-top-color: var(--color-accent);
  animation: loader-spin 800ms linear infinite;
}
.page-loader-text { font-size: var(--fs-body-sm); font-weight: var(--fw-strong); color: var(--text-secondary); }
@keyframes loader-spin { to { transform: rotate(360deg); } }

/* ===== Data table (.dt) =====
   The reusable table pattern - complaints list first, then every other
   list in the portal. Each cell is a two-line stack (.dt-primary value
   over a .dt-meta line) so related fields share one column instead of
   spreading across many. The ID cell holds the row's real link (.dt-rowlink:
   keyboard, new tab); clicking anywhere else on the row opens it via
   list.js, which leaves cell text selectable and hover titles working. */
.dt-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
/* position: relative so absolutely positioned bits inside (an .sr-only header label) scroll with the table instead of widening the page */
.dt-scroll { position: relative; overflow-x: auto; }
table.dt {
  border: none; border-radius: 0; box-shadow: none; min-width: 1000px;
  overflow: visible; /* the global table rule clips (overflow:hidden), which would stop the sticky columns sticking; .dt-card clips instead */
  font-family: var(--font-sans); font-variant-numeric: tabular-nums;
}
table.dt thead th {
  padding: 0; background: var(--color-surface-sunken); border-bottom: 1px solid var(--border);
  font-size: var(--fs-label); font-weight: var(--fw-heavy); line-height: var(--lh-tight);
  letter-spacing: var(--tracking-caps); text-transform: uppercase;
  color: var(--text-meta);
}
table.dt thead th > span { display: block; padding: 12px 10px; }
table.dt tbody td {
  padding: 12px 10px; vertical-align: middle; font-size: var(--fs-body);
  line-height: var(--lh-tight); color: var(--text);
}
table.dt tbody tr { position: relative; cursor: pointer; transition: background-color 120ms ease-out; }
/* Read-only table (logs, backups, alerts): rows aren't links - no pointer, no press feedback */
table.dt.is-static tbody tr { cursor: default; }
table.dt.is-static tbody tr:active, table.dt.is-static tbody tr:active > td { background: var(--color-surface-sunken); }
/* Row actions: right-aligned buttons in the last column; clicks on them never open the row */
table.dt .dt-actions { text-align: right; white-space: nowrap; width: 1%; }
table.dt .dt-actions > * + * { margin-left: var(--space-2); }
table.dt tbody tr:hover { background: var(--color-surface-sunken); }
/* Feedback on press, not on release */
table.dt tbody tr:active { background: var(--color-surface-pressed); transition-duration: 0ms; }
/* Focused row: ring drawn on the cells (a <tr> outline would be painted over by the pinned cells) */
table.dt tbody tr:focus-within, table.dt tbody tr:focus-within > td { background: var(--color-surface-selected); }
table.dt tbody tr:focus-within > td { box-shadow: inset 0 2px 0 var(--color-focus), inset 0 -2px 0 var(--color-focus); }
table.dt tbody tr:focus-within > td:first-child { box-shadow: inset 2px 0 0 var(--color-focus), inset 0 2px 0 var(--color-focus), inset 0 -2px 0 var(--color-focus); }
table.dt tbody tr:focus-within > td:last-child { box-shadow: inset -2px 0 0 var(--color-focus), inset 0 2px 0 var(--color-focus), inset 0 -2px 0 var(--color-focus); }

/* Sortable header: the whole cell is the hit target. aria-sort on the <th>
   tells screen readers the state; the arrow shows it visually. */
.dt-sort {
  display: flex; align-items: center; gap: 6px; padding: 12px 10px;
  color: inherit; text-decoration: none; cursor: pointer; user-select: none;
  transition: background-color 120ms ease-out, color 120ms ease-out;
}
.dt-sort:hover { color: var(--text); background: #eff1f9; text-decoration: none; }
.dt-sort:active { background: var(--color-border); transition-duration: 0ms; }
.dt-sort:focus-visible { outline: 2px solid var(--color-focus); outline-offset: -2px; }
.dt-sort svg { width: 12px; height: 12px; flex-shrink: 0; opacity: .55; }
.dt-sort:hover svg { opacity: 1; }
th[aria-sort="ascending"] .dt-sort, th[aria-sort="descending"] .dt-sort { color: var(--color-accent); }
th[aria-sort="ascending"] .dt-sort svg, th[aria-sort="descending"] .dt-sort svg { opacity: 1; }

/* Overdue rows carry a red edge so they can be spotted while scrolling */
table.dt tbody tr.is-overdue td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
table.dt tbody tr.is-overdue:focus-within > td:first-child { box-shadow: inset 3px 0 0 var(--danger), inset 0 2px 0 var(--color-focus), inset 0 -2px 0 var(--color-focus); }
/* Due soon (amber edge) - for queues that flag rows nearing their SLA */
table.dt tbody tr.is-warning td:first-child { box-shadow: inset 3px 0 0 var(--status-warning-solid); }
table.dt tbody tr.is-warning:focus-within > td:first-child { box-shadow: inset 3px 0 0 var(--status-warning-solid), inset 0 2px 0 var(--color-focus), inset 0 -2px 0 var(--color-focus); }

.dt-primary {
  display: block; font-size: var(--fs-body); font-weight: var(--fw-medium);
  line-height: var(--lh-tight); letter-spacing: var(--tracking-tight); color: var(--text);
}
.dt-meta {
  display: block; margin-top: 4px; font-size: var(--fs-body-sm); font-weight: var(--fw-regular);
  line-height: var(--lh-snug); color: var(--text-meta);
}
.dt-muted { color: var(--text-meta); font-weight: var(--fw-regular); }
.dt-truncate { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dt-nowrap { white-space: nowrap; }

.dt-ref {
  white-space: nowrap; font-family: var(--font-mono); font-size: var(--fs-body-sm); font-weight: var(--fw-strong);
  letter-spacing: 0; color: var(--color-accent); text-decoration: none;
}
a.dt-ref:hover { color: var(--color-accent-hover); text-decoration: none; }
/* One width shared by the ID cells and the pinned Complaint column's offset, so they can't overlap.
   72px fits a 6-digit ID in the mono face plus cell padding. */
table.dt { --dt-id-w: 72px; }
table.dt [data-col="id"] { width: var(--dt-id-w); min-width: var(--dt-id-w); max-width: var(--dt-id-w); box-sizing: border-box; }
/* Long headers ("Last updated by") wrap to two lines instead of widening their column */
.dt-sort { min-width: 0; }
/* ID + Complaint stay pinned while the table scrolls sideways (laptops can't show all nine columns at
   once), so the row being read is always identifiable. Cells need their own background to cover what
   scrolls beneath them; it follows the row's hover / press / focus tint. */
table.dt [data-col="id"], table.dt [data-col="complaint"] { position: sticky; z-index: 1; background: var(--surface); }
table.dt [data-col="id"] { left: 0; }
table.dt [data-col="complaint"] { left: var(--dt-id-w); box-shadow: inset -1px 0 0 var(--border-soft); }
table.dt thead [data-col="id"], table.dt thead [data-col="complaint"] { background: var(--color-surface-sunken); }
table.dt tbody tr:hover > [data-col="id"], table.dt tbody tr:hover > [data-col="complaint"] { background: var(--color-surface-sunken); }
table.dt tbody tr:active > [data-col="id"], table.dt tbody tr:active > [data-col="complaint"] { background: var(--color-surface-pressed); }
.dt-col-location .dt-truncate { max-width: 170px; }
/* People / company names wrap inside a cap instead of stretching the table */
.dt-col-name { min-width: 120px; max-width: 170px; overflow-wrap: anywhere; }
.dt-col-name .dt-meta, table.dt .badge { white-space: nowrap; }
.dt-status-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
/* Status detail under the badge (severity, rework, gate) is compact UI like the badge itself: 12px, one line */
.dt-status-meta, .dt-status-meta .dt-dot { font-size: var(--fs-label); }
.dt-id { font-family: var(--font-mono); font-size: var(--fs-body-sm); font-weight: var(--fw-strong); color: var(--text-secondary); text-decoration: none; }
a.dt-id:hover { color: var(--color-accent); text-decoration: none; }
a.dt-rowlink:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; border-radius: 4px; }

/* Dot + label: severity and similar ordinal values */
.dt-dot { display: inline-flex; align-items: center; gap: 8px; font-size: var(--fs-body-sm); font-weight: var(--fw-strong); white-space: nowrap; }
.dt-dot::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.dt-dot.sev-high { color: var(--danger); }
.dt-dot.sev-medium { color: var(--warning-text); }
.dt-dot.sev-low { color: var(--neutral-text); }

table.dt .badge { font-size: var(--fs-label); padding: 3px 10px; }

/* SLA chip - tone carries meaning, the text repeats it so colour is never the only signal */
.dt-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: var(--fs-label); font-weight: var(--fw-strong); line-height: 1.4; white-space: nowrap;
}
.dt-chip::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.dt-chip.tone-danger { background: var(--danger-bg); color: var(--danger); }
.dt-chip.tone-warning { background: var(--warning-bg); color: var(--warning-text); }
.dt-chip.tone-success { background: var(--success-bg); color: var(--success-text); }
.dt-chip.tone-info { background: var(--status-info-bg); color: var(--status-info-fg); }
.dt-chip.tone-verify { background: var(--status-verify-bg); color: var(--status-verify-fg); }
.dt-chip.tone-neutral { background: var(--neutral-bg); color: var(--neutral-text); }
.dt-flag { color: var(--warning-text); font-weight: var(--fw-strong); }

table.dt .empty-row td { padding: 48px 16px; text-align: center; font-size: var(--fs-body-sm); color: var(--text-meta); }

.dt-footer {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; border-top: 1px solid var(--border-soft);
  font-size: var(--fs-body-sm); font-weight: var(--fw-medium); color: var(--text-meta);
}
.dt-footer b { color: var(--text); font-weight: var(--fw-strong); }
.dt-pager { display: flex; gap: 4px; flex-wrap: wrap; }
.dt-pager a, .dt-pager span {
  min-width: 36px; height: 36px; padding: 0 10px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: var(--fs-body-sm); font-weight: var(--fw-strong); color: var(--text-secondary);
  text-decoration: none; border: 1px solid transparent;
}
.dt-pager a:hover { background: var(--bg); border-color: var(--border); text-decoration: none; }
.dt-pager a:active { background: var(--border-soft); }
.dt-pager a:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 1px; }
.dt-pager .is-current { background: var(--color-accent); color: var(--color-text-on-accent); }
.dt-pager .is-gap { color: var(--text-meta); }

/* ===== Layout grids for page content =====
   Two equal columns / main + side column, sized by the content column (container queries), so they stack
   on tablets and phones whatever the sidebar is doing. Use instead of inline grid styles. */
.grid-2 { display: grid; gap: var(--space-4); grid-template-columns: minmax(0, 1fr); }
.grid-sidebar { display: grid; gap: var(--space-4); grid-template-columns: minmax(0, 1fr); }
/* Side by side only from 880px of content, so each card gets ~430px+ (narrower, dense cards wrapped into tall stacks) */
@container (min-width: 880px) { .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@container (min-width: 900px) { .grid-sidebar { grid-template-columns: minmax(0, 1fr) 320px; } }
/* Wide main + narrower side card (Control Panel: map + Complaints by category, trend + SLA alerts). .is-fixed gives
   every card in the row one fixed height, so data changes never move the page. Side by side from 960px of content: the side column is then >= 410px,
   enough for the ring plus a legend with the longest category name in full; below that the cards stack. */
.grid-main-side { --widget-h: 400px; display: grid; gap: var(--space-4); grid-template-columns: minmax(0, 1fr); }
.grid-main-side.is-fixed > .card { height: var(--widget-h); }
@container (min-width: 960px) { .grid-main-side { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); } }
/* Live work map + Complaints by category (and the Patterns row under it): taller, split 2 : 1 on the KPI tiles' grid -
   with the tiles' 10px gap the map spans exactly four tiles and the side card the last two, so both edges line up with
   the tile columns above */
.grid-map-row { --widget-h: 520px; }
@container (min-width: 960px) {
  .grid-map-row { grid-template-columns: repeat(6, minmax(0, 1fr)); column-gap: 10px; }
  .grid-map-row > :first-child { grid-column: span 4; }
  .grid-map-row > :last-child { grid-column: span 2; }
}

/* ===== Complaint record (complaints/show.php) =====
   Header, then a summary card (5-step progress + key facts), then two columns: the main column leads with what the
   next decision depends on (the three proof stages side by side once a contractor is on it, the original report while
   at intake); the side column holds the decision panel for the zone Reviewer, the assignment and the timeline. Phones:
   summary, decision, evidence, then the rest. */
.back-link { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; font-size: var(--fs-body-sm); font-weight: var(--fw-strong); color: var(--color-accent); }
.back-link svg { width: 16px; height: 16px; }
/* Header: one band - the reference, then its status badges and History under it, on the left; the six key facts
   (category, zone, priority, SLA due, contractor, patch area) beside them on the same lines, label over value, a value
   wrapping to a second line rather than being cut. Narrower: the facts drop under the reference as a row of tiles. */
.cd-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "facts meta"; align-items: center; gap: var(--space-2) var(--space-4); }
.cd-meta { grid-area: meta; display: flex; flex-direction: column; align-items: flex-end; gap: var(--space-2); }
.cd-history { display: inline-flex; align-items: center; gap: 6px; }
/* Wide header (facts beside it): History as an icon button; its word shows when the facts sit below */
/* (History keeps its word: an icon alone did not read as a button) */
.cd-head .cd-facts { grid-area: facts; margin: 0; padding: var(--space-2) var(--space-4); border: 1px solid var(--color-border-soft); border-radius: var(--radius-md); background: var(--color-surface); box-shadow: var(--shadow-sm); display: grid; grid-auto-flow: column; grid-auto-columns: minmax(min-content, 1fr); gap: var(--space-2); align-self: stretch; align-content: center; align-items: start; }
/* never split a word; badges and chips may wrap like text */
.cd-head .cd-facts dd { overflow-wrap: normal; }
.cd-head .cd-facts .badge { white-space: normal; }
.cd-head .cd-facts .dt-chip { white-space: nowrap; }
.cd-head .cd-facts > div { min-width: 0; }
.cd-head .cd-facts dt { margin-bottom: 3px; white-space: nowrap; }
.cd-head .cd-facts dd { font-size: var(--fs-body-sm); line-height: 1.35; }
.cd-head .cd-facts dd .dt-chip { margin: 3px 0 0; }
@container (max-width: 1199px) {

  .cd-head .cd-facts { margin-top: var(--space-2); padding: var(--space-3) var(--space-4); border: 1px solid var(--color-border-soft); border-radius: var(--radius-md); background: var(--color-surface); display: grid; grid-auto-flow: row; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-3) var(--space-4); }
}
@container (max-width: 640px) {
  .cd-head .cd-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* phones: History (and View only) on a row of their own above the facts */
  .cd-head { grid-template-columns: minmax(0, 1fr); grid-template-areas: "meta" "facts"; }
  .cd-meta { flex-direction: row; justify-content: flex-end; }
}
.cd-address { margin: 0 0 var(--space-2); color: var(--color-text-secondary); }
/* The complaint number: first fact in the bar, and the page's heading */
.cd-fact-ref h2 { margin: 0; font-family: var(--font-mono); font-size: var(--fs-body-sm); font-weight: var(--fw-strong); line-height: 1.35; letter-spacing: 0; color: var(--color-accent); white-space: nowrap; }
.cd-fact-ref dd > span { display: block; font-size: var(--fs-label); }
.cd-head .cd-facts > .cd-fact-ref { min-width: max-content; } /* the number never shrinks under the next fact */
.cd-history svg { width: 16px; height: 16px; }
/* Status timeline (top of the main column): six steps on one compact line - dot, then label and date under it; the line
   fills green up to the current step. On load the dots appear and the line draws left to right, step by step. Narrow
   (phones): a titled vertical list. done = check, current = ringed, still to come = hollow, rejected / returned = red. */
.cd-summary { padding: var(--space-3) var(--space-4); }
.cd-status-head { display: none; }
.cd-steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); }
.cd-step { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; text-align: center; }
.cd-step::after { content: ""; position: absolute; top: 9px; left: calc(50% + 14px); right: calc(-50% + 14px); height: 2px; border-radius: 2px; background: var(--color-border); transform-origin: left; }
.cd-step:last-child::after { display: none; }
.cd-step.is-done::after { background: var(--status-success-solid); }
.cd-step-dot { position: relative; z-index: 1; flex: none; width: 20px; height: 20px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: var(--color-surface); border: 2px solid var(--color-border-control); color: #fff; }
.cd-step-dot svg { width: 12px; height: 12px; }
.cd-step.is-done .cd-step-dot { background: var(--status-success-solid); border-color: var(--status-success-solid); }
.cd-step.is-current .cd-step-dot { border-color: var(--color-accent); box-shadow: 0 0 0 3px var(--color-accent-soft); }
.cd-step.is-current .cd-step-dot::after { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--color-accent); }
.cd-step.is-warn .cd-step-dot { background: var(--status-danger-solid); border-color: var(--status-danger-solid); box-shadow: 0 0 0 3px var(--status-danger-bg); }
.cd-step.is-warn .cd-step-dot::after { display: none; }
.cd-step-text { display: flex; flex-direction: column; align-items: center; min-width: 0; max-width: 100%; padding: 0 2px; line-height: 1.25; }
.cd-step-text b { font-size: var(--fs-label); font-weight: var(--fw-strong); color: var(--color-text); text-wrap: balance; }
.cd-step-text span { font-size: var(--fs-label); color: var(--color-text-meta); white-space: nowrap; }
.cd-step.is-todo .cd-step-text b { color: var(--color-text-meta); font-weight: var(--fw-medium); }
.cd-step-note { margin: var(--space-2) 0 0; text-align: center; color: var(--status-danger-fg); font-weight: var(--fw-strong); }
@keyframes cd-dot-in { from { opacity: 0; transform: scale(.4); } }
@keyframes cd-line-in { from { transform: scaleX(0); } }
.cd-step-dot { animation: cd-dot-in 320ms var(--ease-standard) both; animation-delay: calc(var(--i, 0) * 160ms); }
.cd-step.is-done::after { animation: cd-line-in 260ms ease-out both; animation-delay: calc(var(--i, 0) * 160ms + 120ms); }
@media (prefers-reduced-motion: reduce) { .cd-step-dot, .cd-step.is-done::after { animation: none; } }
@container (max-width: 640px) {
  .cd-status-head { display: flex; }
  .cd-steps { grid-template-columns: minmax(0, 1fr); }
  .cd-step { flex-direction: row; align-items: flex-start; gap: 10px; padding-bottom: 12px; text-align: left; }
  .cd-step:last-child { padding-bottom: 0; }
  .cd-step::after { left: 9px; right: auto; top: 22px; bottom: 0; width: 2px; height: auto; transform-origin: top; }
  .cd-step.is-done::after { animation-name: cd-line-down; }
  .cd-step-text { flex: 1; flex-direction: row; justify-content: space-between; align-items: baseline; gap: var(--space-2); padding-top: 1px; }
  .cd-step-text b { font-size: var(--fs-body-sm); }
  .cd-step-note { text-align: left; }
}
@keyframes cd-line-down { from { transform: scaleY(0); } }
/* key facts, once */
.cd-facts { margin: var(--space-3) 0 0; padding-top: var(--space-3); border-top: 1px solid var(--color-border-soft); display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-3) var(--space-4); }
.cd-facts dt { margin-bottom: 2px; }
.cd-facts dd { margin: 0; font-size: var(--fs-body-sm); font-weight: var(--fw-strong); color: var(--color-text); }
.cd-facts dd .dt-chip { margin-left: 4px; vertical-align: 1px; }
/* the two columns */
.cd-layout { margin-top: var(--space-3); display: grid; gap: var(--space-4); grid-template-columns: minmax(0, 1fr); grid-template-areas: "act" "main" "aside"; }
.cd-main { grid-area: main; display: flex; flex-direction: column; gap: var(--space-4); min-width: 0; }
.cd-act { grid-area: act; display: flex; flex-direction: column; gap: var(--space-4); min-width: 0; }
.cd-act:empty { display: none; }
.cd-aside { grid-area: aside; display: flex; flex-direction: column; gap: var(--space-4); min-width: 0; }
@container (min-width: 900px) {
  .cd-layout { grid-template-columns: minmax(0, 1fr) 340px; grid-template-rows: auto 1fr; grid-template-areas: "main act" "main aside"; align-items: start; }
}
.cd-card .card-head { margin-bottom: var(--space-3); }
.cd-card .card-head h3 { margin: 0; }
/* proof of work: three stages in a row, in order */
.cd-stages { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-3); }
.cd-stage { margin: 0; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.cd-stage-head { display: flex; align-items: center; gap: 6px; font-size: var(--fs-body-sm); white-space: nowrap; overflow: hidden; }
.cd-stage-no { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 50%; background: var(--color-accent); color: #fff; font-size: var(--fs-label); font-weight: var(--fw-strong); }
.cd-stage.is-missing .cd-stage-no { background: var(--color-border-control); }
.cd-media { position: relative; display: block; aspect-ratio: 4 / 3; border-radius: var(--radius-md); overflow: hidden; background: var(--slate-100); }
.cd-media img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform var(--dur-base) var(--ease-standard); }
.cd-media:hover img { transform: scale(1.03); }
.cd-media:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.cd-media-fallback { display: none; }
.cd-media.is-broken { display: flex; align-items: center; justify-content: center; border: 1px dashed var(--color-border-control); }
.cd-media.is-broken .cd-media-fallback { display: block; padding: 0 6px; text-align: center; font-size: var(--fs-body-sm); color: var(--color-text-meta); }
@container (max-width: 640px) { .cd-media.is-broken .cd-media-fallback { font-size: var(--fs-label); } }
/* Stage photos: height follows the screen (taller on bigger screens, still the whole row on the first screen); portrait on phones */
.cd-stage .cd-media { aspect-ratio: auto; height: clamp(160px, 100vh - 525px, 380px); }
.cd-media-empty { display: flex; align-items: center; justify-content: center; border: 2px dashed var(--color-border); background: var(--color-surface-sunken); color: var(--color-text-meta); font-size: var(--fs-body-sm); }
.cd-media-play { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--navy-900, #1c2340); color: #fff; }
.cd-media-play svg { width: 36px; height: 36px; }
.cd-media-cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 6px 8px; background: linear-gradient(0deg, rgba(15, 20, 40, .75), transparent); color: #fff; font-size: var(--fs-label); font-weight: var(--fw-strong); }
.cd-stamp { display: flex; flex-direction: column; gap: 1px; }
.cd-stamp .is-ok, .cd-stamp .is-bad { display: inline-flex; align-items: center; gap: 4px; font-weight: var(--fw-strong); white-space: nowrap; }
.cd-stamp .is-ok { color: var(--status-success-fg); }
.cd-stamp .is-bad { color: var(--status-danger-fg); }
.cd-stamp svg { width: 14px; height: 14px; flex: none; }
.cd-empty { margin: 0; padding: var(--space-4); border: 2px dashed var(--color-border); border-radius: var(--radius-md); color: var(--color-text-meta); }
/* measurement: three figures (+ AI check) in a row */
.cd-measure { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--space-3); }
.cd-figure { display: flex; flex-direction: column; gap: 2px; padding: var(--space-3); border-radius: var(--radius-md); background: var(--color-surface-sunken); min-width: 0; }
.cd-figure b { font-size: var(--fs-h2); font-weight: var(--fw-heavy); color: var(--color-text); line-height: 1.2; }
.cd-figure .t-label { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
/* original report */
.cd-report { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-4); }
.cd-sub { margin: var(--space-3) 0 6px; }
.cd-report > div > .cd-sub:first-child { margin-top: 0; }
.cd-thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: var(--space-2); }
/* reported media: the first item large across the card, the rest as thumbnails */
#card-media .card-head { margin-bottom: 0; }
.cd-media-by { margin: 2px 0 var(--space-3); }
#card-media .cd-thumbs > :first-child { grid-column: 1 / -1; }
#card-media .cd-thumbs > :first-child .cd-media { aspect-ratio: 4 / 3; }
#card-media .cd-thumbs > :not(:first-child) .cd-media-cap { display: none; }
#card-media > .cd-media-empty { aspect-ratio: 16 / 9; }
/* At intake it leads the main column: each item the same 4:3 tile as in the side column once a complaint is approved,
   side by side (auto-fill keeps one photo at that tile size instead of stretching it across the column) */
.cd-main #card-media .cd-thumbs { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.cd-main #card-media .cd-thumbs > * { grid-column: auto; }
.cd-main #card-media .cd-thumbs .cd-media { aspect-ratio: 4 / 3; }
.cd-main #card-media .cd-thumbs .cd-media-cap { display: block; }
.cd-main #card-media > .cd-media-empty { aspect-ratio: auto; height: 96px; } /* nothing to show: don't hold the space */
.cd-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.cd-tag { padding: 3px 10px; border-radius: var(--radius-pill); background: var(--color-accent-soft); color: var(--color-accent); font-size: var(--fs-label); font-weight: var(--fw-strong); }
.cd-remarks { margin: 0; color: var(--color-text-secondary); }
.cd-coords { margin-left: 6px; text-transform: none; letter-spacing: 0; font-weight: var(--fw-medium); }
.cd-map { height: 260px; border-radius: var(--radius-md); border: 1px solid var(--color-border-soft); }
/* decision panels (zone Reviewer) */
.cd-decide { border-top: 4px solid var(--c, var(--color-accent)); }
.cd-decide.tone-warning { --c: var(--status-warning-solid); }
.cd-decide.tone-verify { --c: var(--status-verify-solid); }
.cd-decide.tone-success { --c: var(--status-success-solid); background: var(--status-success-bg); }
.cd-decide-note { margin: var(--space-1) 0 0; color: var(--color-text-secondary); }
.cd-decide-steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: var(--space-4); font-size: var(--fs-body-sm); color: var(--color-text-secondary); }
.cd-decide-steps > li > b { color: var(--color-text); }
.cd-validate { margin-top: var(--space-2); display: grid; gap: 6px; }
.cd-validate > div { display: grid; gap: 4px; }
#close-form { margin-top: var(--space-2); }
.cd-btn-wide { width: 100%; justify-content: center; }
.cd-reject { margin-top: var(--space-4); padding-top: var(--space-4); border-top: 1px solid var(--color-border-soft); display: grid; gap: 6px; }
.cd-ok-ico { display: inline-flex; width: 22px; height: 22px; margin-right: 8px; border-radius: 50%; background: var(--status-success-solid); color: #fff; align-items: center; justify-content: center; vertical-align: -4px; }
.cd-ok-ico svg { width: 14px; height: 14px; }
/* side: assignment + timeline */
.cd-kv { margin: 0; display: flex; flex-direction: column; gap: 8px; }
.cd-kv > div { display: flex; justify-content: space-between; gap: var(--space-3); }
.cd-kv dt { color: var(--color-text-meta); }
.cd-kv dd { margin: 0; font-weight: var(--fw-strong); color: var(--color-text); text-align: right; }
/* narrower content: facts wrap to 3 + 2, stages stay three-up down to ~560px, then stack */
.cd-short { display: none; }
/* Below the two-column width: one column ordered summary -> lead section (proof, or the report at intake) -> the
   decision -> the rest */
@container (max-width: 899px) {
  .cd-layout { display: flex; flex-direction: column; }
  .cd-main, .cd-aside { display: contents; }
  .cd-main > * { order: 4; }
  .cd-main > :first-child { order: 0; }
  .cd-main > :nth-child(2) { order: 1; }
  .cd-act { order: 2; }
  .cd-aside > * { order: 5; }
  .cd-aside > #card-media { order: 3; }
}
/* Phones: the three stages stay side by side, portrait, with short names, the distance and a short date (GPS and
   device are in the photo viewer's caption) */
@container (max-width: 640px) {
  .cd-stages { gap: var(--space-2); }
  .cd-stage .cd-media { height: auto; aspect-ratio: 3 / 4; }
  .cd-long { display: none; }
  .cd-short { display: inline; }
  .cd-stamp { font-size: var(--fs-label); }
  .cd-stamp .is-ok, .cd-stamp .is-bad { gap: 2px; }
}
@media (prefers-reduced-motion: reduce) { .cd-media img { transition: none; } }

/* ===== Admin record components: page head, key-value panel, list row, checkbox group, modal =====
   Built for the Contractors list + record (wave 3) from the proposed specs in DESIGN-SYSTEM.md section 7. Work anywhere. */

/* Page head: back link, the record's name (24px) with its status chip, one meta line; actions on the right, wrapping under on phones */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: var(--space-3) var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-4); }
.page-head-main { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.page-head .back-link { align-self: flex-start; min-height: 44px; }
.page-head-title { display: flex; align-items: center; gap: var(--space-2) var(--space-3); flex-wrap: wrap; }
.page-head-title h2 { margin: 0; font-size: var(--fs-h1); font-weight: var(--fw-strong); line-height: var(--lh-display); letter-spacing: var(--tracking-display); color: var(--color-text); overflow-wrap: anywhere; }
.page-head-meta { margin: 0; font-size: var(--fs-body-sm); font-weight: var(--fw-regular); line-height: var(--lh-snug); color: var(--color-text-meta); }
.page-head-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }
/* One-sentence page lead beside the page's primary action (.toolbar) */
.page-lead { margin: 0; max-width: 72ch; font-size: var(--fs-body-sm); font-weight: var(--fw-regular); line-height: var(--lh-snug); color: var(--color-text-secondary); }

/* A column of cards with the standard block gap (inside .grid-sidebar / .grid-2 cells) */
.stack { display: flex; flex-direction: column; gap: var(--space-4); min-width: 0; }
.card > .t-body-sm { margin: var(--space-2) 0 var(--space-4); }
.card > .t-body-sm:last-child { margin-bottom: 0; }

/* Key-value panel: label left, value right, hairline between rows */
.kv { margin: 0; }
.card > .t-title + .kv { margin-top: var(--space-4); }
.kv + .t-body-sm { margin: var(--space-4) 0 0; }
.kv-row { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-3); padding: var(--space-3) 0; border-bottom: 1px solid var(--color-border-soft); }
.kv-row:first-child { padding-top: 0; }
.kv-row:last-child { border-bottom: none; padding-bottom: 0; }
.kv dt { font-size: var(--fs-body-sm); font-weight: var(--fw-medium); color: var(--color-text-meta); }
.kv dd { margin: 0; text-align: right; font-size: var(--fs-body-sm); font-weight: var(--fw-strong); color: var(--color-text); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kv dd small { font-size: inherit; font-weight: var(--fw-regular); color: var(--color-text-meta); }

/* List row: people, settings, inbox items inside a card */
.list-rows { margin: 0; padding: 0; list-style: none; }
.list-row { display: flex; align-items: center; gap: var(--space-3); min-height: 52px; padding: var(--space-3) 0; border-bottom: 1px solid var(--color-border-soft); }
.list-row:first-child { padding-top: 0; }
.list-row:last-child { border-bottom: none; }
.list-lead { flex: none; width: 36px; height: 36px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: var(--color-accent-soft); color: var(--color-accent); font-size: var(--fs-label); font-weight: var(--fw-strong); }
.list-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.list-title { font-size: var(--fs-body-sm); font-weight: var(--fw-medium); line-height: var(--lh-tight); color: var(--color-text); overflow-wrap: anywhere; }
.list-sub { font-size: var(--fs-body-sm); font-weight: var(--fw-regular); line-height: var(--lh-snug); color: var(--color-text-meta); }
.list-trail { flex: none; display: flex; align-items: center; gap: var(--space-2); }

/* Checkbox group: a fieldset of checkboxes, each with a 44px hit area */
.check-group { margin: 0 0 var(--space-4); padding: 0; border: none; min-width: 0; }
.check-group legend { padding: 0; margin-bottom: var(--space-2); font-size: var(--fs-label); font-weight: var(--fw-strong); letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--color-text-meta); }
.check-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: var(--space-2); }
.check { display: flex; align-items: center; gap: var(--space-2); min-height: 44px; padding: 0 var(--space-3); border: 1px solid var(--color-border-control); border-radius: var(--radius-md); background: var(--color-surface); font-size: var(--fs-body-sm); font-weight: var(--fw-regular); line-height: var(--lh-tight); color: var(--color-text); cursor: pointer; transition: background-color var(--dur-fast) ease, border-color var(--dur-fast) ease; }
.check:hover { border-color: var(--color-text-meta); background: var(--color-surface-sunken); }
.check[hidden] { display: none; }
.check input { flex: none; width: 18px; height: 18px; margin: 0; accent-color: var(--color-accent); cursor: pointer; }
.check:has(input:checked) { border-color: var(--color-accent); background: var(--color-surface-selected); font-weight: var(--fw-medium); }
.check:has(input:focus-visible) { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.check-group .hint { margin-top: var(--space-2); }

/* Modal: <dialog class="modal"> opened by [data-modal-open="id"] (modal.js). A bottom sheet on phones. */
dialog.modal { width: min(640px, 100vw - 32px); max-width: none; max-height: min(90dvh, 100% - 32px); margin: auto; padding: 0; border: none; border-radius: var(--radius-xl); background: var(--color-surface); color: var(--color-text); box-shadow: var(--shadow-lg); overflow: hidden; flex-direction: column; }
dialog.modal[open] { display: flex; animation: modal-in var(--dur-base) var(--ease-standard); }
dialog.modal.is-closing { animation: modal-out var(--dur-fast) var(--ease-exit) forwards; }
dialog.modal::backdrop { background: var(--color-backdrop); }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); padding: var(--space-4) var(--space-6); border-bottom: 1px solid var(--color-border-soft); }
.modal-head h2 { margin: 0; font-size: var(--fs-title); font-weight: var(--fw-strong); line-height: var(--lh-tight); letter-spacing: var(--tracking-tight); }
.modal-close { flex: none; width: 44px; height: 44px; margin-right: -10px; display: inline-flex; align-items: center; justify-content: center; border: none; border-radius: 50%; background: transparent; color: var(--color-text-meta); cursor: pointer; }
.modal-close:hover { background: var(--color-surface-sunken); color: var(--color-text); }
.modal-close:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.modal-close svg { width: 18px; height: 18px; }
.modal-body { padding: var(--space-5) var(--space-6); overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--space-2); flex-wrap: wrap; padding: var(--space-4) var(--space-6); border-top: 1px solid var(--color-border-soft); background: var(--color-surface-sunken); }
.modal form { display: flex; flex-direction: column; min-height: 0; }
.modal .form-row { align-items: flex-start; margin-bottom: var(--space-4); }
.modal .form-row .form-group { min-width: 220px; } /* pairs stack on phones */
@keyframes modal-in { from { opacity: 0; transform: scale(.98); } }
@keyframes modal-out { to { opacity: 0; transform: scale(.98); } }
@keyframes sheet-in { from { transform: translateY(100%); } }
@keyframes sheet-out { to { transform: translateY(100%); } }
@media (max-width: 767px) {
  dialog.modal { width: 100vw; max-height: 92dvh; margin: auto 0 0; border-radius: var(--radius-xl) var(--radius-xl) 0 0; }
  dialog.modal[open] { animation: sheet-in var(--dur-slow) var(--ease-standard); }
  dialog.modal.is-closing { animation: sheet-out var(--dur-fast) var(--ease-exit) forwards; }
  .modal-head, .modal-body, .modal-foot { padding-left: var(--space-4); padding-right: var(--space-4); }
  .modal-foot { padding-bottom: max(var(--space-4), env(safe-area-inset-bottom)); }
  .modal-foot .btn { flex: 1; }
}

/* The page's primary action ("Add user") at the end of the filter bar's top row: same height as the pills; shares the row with Filters on phones */
.fb-top > .btn.fb-cta { flex: none; height: 46px; padding: 0 var(--space-5); border-radius: var(--radius-pill); }
@media (max-width: 767px) { .fb-top > .btn.fb-cta { flex: 1; } }
/* Figures stay on one line ("1,084 sq m") */
table.dt td.dt-num, table.dt th.dt-num, table.dt th.dt-nowrap { white-space: nowrap; }
/* Right-aligned tabular figures (and their header) */
table.dt .dt-num { text-align: right; font-variant-numeric: tabular-nums; }
table.dt th.dt-num .dt-sort, table.dt th.dt-num > span { justify-content: flex-end; text-align: right; }
.dt-num small { font-size: var(--fs-body-sm); font-weight: var(--fw-regular); color: var(--color-text-meta); }

/* ===== Media viewer (complaint record): dark full-screen dialog, zoom + pan, X to close ===== */
dialog.viewer { width: min(96vw, 1200px); height: min(92dvh, 900px); max-width: none; max-height: none; padding: 0; border: none; border-radius: var(--radius-xl); background: var(--navy-950); color: var(--color-text-on-accent); box-shadow: var(--shadow-lg); overflow: hidden; }
dialog.viewer[open] { display: flex; flex-direction: column; animation: modal-in var(--dur-base) var(--ease-standard); }
dialog.viewer::backdrop { background: rgba(5, 8, 22, .8); }
.viewer-bar { flex: none; display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-2) var(--space-2) var(--space-5); border-bottom: 1px solid rgba(255, 255, 255, .12); }
.viewer-caption { flex: 1; min-width: 0; font-size: var(--fs-body-sm); font-weight: var(--fw-medium); line-height: var(--lh-snug); color: rgba(255, 255, 255, .9); }
.viewer-tools { flex: none; display: flex; align-items: center; gap: 2px; padding: 2px; border-radius: var(--radius-pill); background: rgba(255, 255, 255, .08); }
.viewer-tools[hidden] { display: none; }
.viewer-btn, .viewer-level { flex: none; height: 44px; min-width: 44px; display: inline-flex; align-items: center; justify-content: center; border: none; border-radius: var(--radius-pill); background: transparent; color: #fff; cursor: pointer; font: inherit; }
.viewer-level { min-width: 64px; padding: 0 var(--space-2); font-size: var(--fs-label); font-weight: var(--fw-strong); }
.viewer-btn svg { width: 18px; height: 18px; }
.viewer-btn:hover, .viewer-level:hover { background: rgba(255, 255, 255, .14); }
.viewer-btn:focus-visible, .viewer-level:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }
.viewer-stage { flex: 1; min-height: 0; overflow: auto; display: flex; padding: var(--space-4); cursor: zoom-out; }
.viewer-media { margin: auto; max-width: 100%; max-height: 100%; border-radius: var(--radius-md); cursor: zoom-in; flex: none; }
.viewer-stage.is-zoomed .viewer-media { cursor: grab; border-radius: 0; }
.viewer-stage.is-zoomed .viewer-media:active { cursor: grabbing; }
video.viewer-media { cursor: default; max-height: 100%; }
@media (max-width: 767px) { dialog.viewer { width: 100vw; height: 100dvh; border-radius: 0; } .viewer-caption { font-size: var(--fs-label); } }
@media (prefers-reduced-motion: reduce) { dialog.viewer[open] { animation: none; } }

/* Reported media: what, when and where under each photo (like the proof stages' stamps) */
.cd-thumb { margin: 0; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.cd-media-meta { gap: 1px; color: var(--color-text-meta); overflow-wrap: anywhere; }
.cd-media-meta b { color: var(--color-text); font-weight: var(--fw-strong); }
.cd-media-meta .is-ok, .cd-media-meta .is-bad { display: block; white-space: normal; }
.cd-media-meta .is-ok svg, .cd-media-meta .is-bad svg { display: inline; vertical-align: -2px; margin-right: 4px; }
/* In the side column only the first (large) item keeps its details; the rest are thumbnails */
.cd-aside #card-media .cd-thumbs > :not(:first-child) .cd-media-meta { display: none; }

/* ===== No sideways drag, site-wide =====
   Every page renders inside .main-body, so these rules cover the whole site (current pages and new ones):
   - nothing in page content may be wider than its column: form fields and media are capped, and long unbroken strings
     (URLs, keys, codes, file names) wrap instead of pushing the page wide;
   - on phones, any page-local multi-column grid written inline (style="grid-template-columns:...") collapses to one
     column - many older pages lay out cards that way and never stacked. Pages on the design system use .grid-2 /
     .grid-sidebar / .grid-main-side, which already stack. Add data-keep-cols to an inline grid that must stay columned.
   - last resort: the scrolling column never scrolls sideways, so a stray wide element is clipped rather than letting
     the whole page drag left and right. Wide tables keep their own horizontal scroll inside their card (.dt-scroll). */
.main { overflow-x: hidden; }
.main-body { overflow-wrap: break-word; }
.main-body :where(code, kbd, samp, pre, a) { overflow-wrap: anywhere; }
.main-body :where(pre) { white-space: pre-wrap; }
.main-body :where(img, video, canvas, iframe, input, select, textarea, .form-control, .leaflet-container):not(.leaflet-container *) { max-width: 100%; }
/* Map layers size and place themselves inside 0-width panes - never cap them (a capped heat-map canvas renders 0x0) */
.leaflet-container canvas, .leaflet-container img { max-width: none !important; }
@media (max-width: 767px) {
  .main-body [style*="grid-template-columns"]:not([data-keep-cols]) { grid-template-columns: minmax(0, 1fr) !important; }
  .main-body [style*="display:flex"][style*="flex-wrap"] > *, .main-body [style*="display: flex"][style*="flex-wrap"] > * { max-width: 100%; min-width: 0; }
}

/* ===== Responsive app shell =====
   Below 1024px (tablets, phones) the sidebar becomes an off-canvas drawer opened by the menu button,
   so page content gets the full width. It slides in from the left edge and leaves the same way. */
@media (max-width: 1023px) {
  .nav-toggle { display: inline-flex; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: var(--z-drawer);
    width: min(280px, 85vw); height: auto; margin: 0; border-radius: 0 16px 16px 0; box-shadow: var(--shadow-lg);
    transform: translateX(-100%); visibility: hidden;
    transition: transform 260ms var(--ease-exit), visibility 0s 260ms;
  }
  .app-shell.nav-open .sidebar { transform: none; visibility: visible; transition: transform var(--dur-slow) var(--ease-standard), visibility 0s; }
  .nav-backdrop {
    display: block; position: fixed; inset: 0; z-index: calc(var(--z-drawer) - 1);
    background: rgba(13, 18, 48, .38); animation: backdrop-in var(--dur-base) ease-out;
  }
  .nav-backdrop[hidden] { display: none; }
  .main-header { padding: 12px var(--space-6); }
}
@keyframes backdrop-in { from { opacity: 0; } }
@media (max-width: 767px) {
  :root { --page-gutter-x: var(--space-4); --page-gutter-y: var(--space-5); }
  .main-header { padding: 10px var(--space-4); gap: var(--space-2); }
  .main-header-right { gap: var(--space-1); }
  .main-header-right #header-clock { display: none; }
  .main-header-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* Phones / small tablets: the table keeps all columns and scrolls sideways
   inside its card (page itself never scrolls horizontally); cells tighten. */
@media (max-width: 768px) {
  /* Narrow screens: pinning two columns would leave no room to scroll the rest into view - pin only the ID */
  table.dt [data-col="complaint"] { position: static; box-shadow: none; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .fb-top { flex-wrap: wrap; }
  .fb-search { flex: 1 1 100%; }
  .fb-top > .chip, .fb-top > .col-picker { flex: 1; }
  .col-picker > .chip { width: 100%; }
  .fb-toggle { padding: 0 10px; gap: 6px; justify-content: center; }
  .fb-chips { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fb-chips .sel, .fb-chips .chip.sel-trigger { width: 100%; max-width: none; }
  .fb-chips .chip-date, .fb-actions { grid-column: 1 / -1; } /* scoped: the Control Panel range bar lays its own out */
  .fb-chips .chip-date input { flex: 1; width: auto; }
  .fb-actions { margin-left: 0; }
  .fb-actions .btn { flex: 1; }
  table.dt thead th > span, .dt-sort { padding: 10px 12px; }
  table.dt tbody td { padding: 12px; }
  .dt-footer { justify-content: center; }
  .dt-pager a, .dt-pager span { min-width: 32px; padding: 0 6px; }
}

@media (prefers-reduced-motion: reduce) {
  table.dt tbody tr, .dt-sort, .chip, .kpi-tile, .fb-search-pill, .fb-panel, .fb-panel-inner, .fb-toggle-chev, .page-loader, .range-toggle-chev { transition: none !important; }
  .sel-list, .col-menu, .nav-backdrop, dialog.modal { animation: none !important; }
  .check { transition: none; }
  .sidebar, .sidebar-collapse { transition: none !important; }
  .btn { transition: none; }
  .page-loader-spin { animation-duration: 2s; }
}
@media (prefers-reduced-transparency: reduce) {
  .page-loader { background: rgba(244, 246, 251, .96); backdrop-filter: none; -webkit-backdrop-filter: none; }
}
@media (prefers-contrast: more) {
  /* Every meta-grey text darkens, not only tables: redefine the token itself */
  :root { --color-text-meta: var(--slate-800); --color-border-control: var(--slate-600); }
  .dt-meta, .dt-muted, table.dt thead th, .kpi-label, .kpi-sub { color: var(--text-secondary); }
  .chip { border-color: var(--text-secondary); }
}
