/*
 * Survey Platform design system.
 *
 * Every colour is a token on :root and is redefined under [data-theme="dark"], so the theme switch
 * is a single attribute flip with no per-component overrides. Layout is mobile-first: the field
 * screens are used one-handed on a phone, and the desktop shell is the enhancement.
 */

:root {
    /*
     * Bound to the app's theme, never to the operating system. The browser paints radios,
     * checkboxes, select arrows and scrollbars from this value; leaving it to the OS meant a
     * machine in dark mode drew unchecked radios as solid dark circles on our light surfaces.
     */
    color-scheme: light;

    --font-sans: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "JetBrains Mono", "Cascadia Code", Consolas, monospace;

    /* Surfaces */
    --surface-page: #f4f5f7;
    --surface-card: #ffffff;
    --surface-raised: #ffffff;
    --surface-sunken: #f1f2f6;
    --surface-inverse: #1c1f2e;

    /* Text */
    --text-strong: #1a1c29;
    --text-body: #43465a;
    --text-muted: #757889;
    --text-inverse: #f7f8fc;

    /* Lines */
    --border: #e3e5ec;
    --border-strong: #c9ccd8;

    /*
     * Indigo. Chosen over the previous teal because the selected state of a radio is the single
     * most repeated signal in this app, and indigo reads as "chosen" at a glance where teal read as
     * decoration. White on this step is 7.6:1, so buttons and chips carry body text safely.
     */
    --accent: #3f51b5;
    --accent-hover: #354497;
    --accent-soft: #e8eaf6;
    --accent-text: #ffffff;

    /* UI status colours, used for text and badges. */
    --positive: #15803d;
    --positive-soft: #dcfce7;
    --warning: #b45309;
    --warning-soft: #fef3c7;
    --negative: #b91c1c;
    --negative-soft: #fee2e2;
    --info: #1d4ed8;
    --info-soft: #dbeafe;
    --neutral-soft: #e8ecf2;

    /*
     * Chart tokens are kept apart from the UI chrome above. Charts encode data, so they use a
     * palette validated for colour vision deficiency rather than the brand hue.
     *
     * Sequential ramp (single hue, light to dark) for the choropleth: magnitude, not identity.
     */
    --ramp-0: #cde2fb;
    --ramp-1: #9ec5f4;
    --ramp-2: #6da7ec;
    --ramp-3: #3987e5;
    --ramp-4: #256abf;
    --ramp-5: #184f95;

    /* Single-series line colour. */
    --series-1: #2a78d6;

    /* Status palette, fixed in both themes and always paired with a written label. */
    --status-good: #0ca30c;
    --status-warning: #fab219;
    --status-critical: #d03b3b;
    --status-neutral: #898781;

    /* Recessive chart chrome. */
    --grid-line: #e1e0d9;
    --axis-line: #c3c2b7;

    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 16px;

    --shadow-sm: 0 1px 2px rgba(16, 23, 37, 0.06);
    --shadow: 0 2px 8px rgba(16, 23, 37, 0.08);
    --shadow-lg: 0 12px 32px rgba(16, 23, 37, 0.14);

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --space-7: 48px;

    --sidebar-width: 248px;
    --topbar-height: 60px;
}

[data-theme="dark"] {
    color-scheme: dark;

    --surface-page: #0f1118;
    --surface-card: #171a24;
    --surface-raised: #1e2230;
    --surface-sunken: #13161f;
    --surface-inverse: #f7f8fc;

    --text-strong: #f2f3f8;
    --text-body: #c5c8d6;
    --text-muted: #8b8fa3;
    --text-inverse: #1a1c29;

    --border: #262a38;
    --border-strong: #363b4d;

    /*
     * Indigo stepped up for the dark surface rather than reused: #3f51b5 on #171a24 is under 3:1
     * and the selected radio would disappear. This step clears 7:1 and takes dark text on fills.
     */
    --accent: #8c9eff;
    --accent-hover: #a7b4ff;
    --accent-soft: #232842;
    --accent-text: #14172b;

    --positive: #4ade80;
    --positive-soft: #10301d;
    --warning: #fbbf24;
    --warning-soft: #332305;
    --negative: #f87171;
    --negative-soft: #3a1414;
    --info: #60a5fa;
    --info-soft: #11243f;
    --neutral-soft: #1e2736;

    /*
     * The dark ramp is selected for the dark surface rather than flipped: on a dark plane more
     * ink means lighter, so magnitude climbs towards the light end of the same single hue.
     */
    --ramp-0: #0d366b;
    --ramp-1: #184f95;
    --ramp-2: #256abf;
    --ramp-3: #3987e5;
    --ramp-4: #6da7ec;
    --ramp-5: #9ec5f4;

    --series-1: #3987e5;

    /* Status steps are mode-invariant and clear 3:1 on the dark surface. */
    --status-good: #0ca30c;
    --status-warning: #fab219;
    --status-critical: #d03b3b;
    --status-neutral: #898781;

    --grid-line: #2c2c2a;
    --axis-line: #383835;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.55);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.55;
    color: var(--text-body);
    background: var(--surface-page);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
    color: var(--text-strong);
    margin: 0 0 var(--space-3);
    line-height: 1.25;
    font-weight: 650;
}

h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
h4 { font-size: 0.92rem; }

p { margin: 0 0 var(--space-3); }

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

a:hover { text-decoration: underline; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

.muted { color: var(--text-muted); }
.small { font-size: 0.85rem; }
.mono { font-family: var(--font-mono); font-size: 0.85em; }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }
.text-center { text-align: center; }

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 200;
    background: var(--accent);
    color: var(--accent-text);
    padding: var(--space-2) var(--space-4);
    border-radius: 0 0 var(--radius) 0;
}

.skip-link:focus {
    left: 0;
}

/* ---------------------------------------------------------------- App shell */

.app {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
    background: var(--surface-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
}

.sidebar.is-open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-4);
    border-bottom: 1px solid var(--border);
    min-height: var(--topbar-height);
}

.sidebar__logo {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: var(--accent-text);
    display: grid;
    place-items: center;
    font-weight: 700;
    flex: none;
}

.sidebar__title {
    font-weight: 650;
    color: var(--text-strong);
    line-height: 1.2;
}

.sidebar__nav {
    padding: var(--space-3) var(--space-2);
    overflow-y: auto;
    flex: 1;
}

.sidebar__group-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    padding: var(--space-4) var(--space-3) var(--space-2);
    font-weight: 600;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 10px var(--space-3);
    border-radius: var(--radius);
    color: var(--text-body);
    font-weight: 500;
    margin-bottom: 2px;
}

.nav-item:hover {
    background: var(--surface-sunken);
    text-decoration: none;
}

.nav-item.is-active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}

.nav-item svg {
    width: 18px;
    height: 18px;
    flex: none;
}

.sidebar__footer {
    border-top: 1px solid var(--border);
    padding: var(--space-3);
}

.user-chip {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2);
}

.avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--surface-sunken);
    color: var(--text-strong);
    display: grid;
    place-items: center;
    font-weight: 650;
    font-size: 0.8rem;
    flex: none;
}

.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: var(--topbar-height);
    background: var(--surface-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 0 var(--space-4);
    position: sticky;
    top: 0;
    z-index: 40;
}

/*
 * A survey title is longer than a phone's top bar. Truncating keeps the language switch and the
 * theme toggle on screen; the full title is in the page heading just below.
 */
.topbar__title {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar__spacer { flex: 1; }

.content {
    padding: var(--space-5) var(--space-4) var(--space-7);
    max-width: 1440px;
    width: 100%;
    margin: 0 auto;
}

.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: var(--space-3);
    margin-bottom: var(--space-5);
}

.page-header__text { flex: 1 1 260px; min-width: 0; }
.page-header__actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }

.scrim {
    position: fixed;
    inset: 0;
    background: rgba(9, 13, 20, 0.5);
    z-index: 50;
    display: none;
}

.scrim.is-visible { display: block; }

@media (min-width: 1024px) {
    .sidebar { position: sticky; height: 100vh; transform: none; }
    .sidebar.is-open { box-shadow: none; }
    /*
     * Scoped to .topbar so it outranks the later `.icon-button { display: inline-grid }` rule.
     * Equal specificity would lose on source order and the drawer toggle would sit on a desktop
     * layout that has no drawer to toggle.
     */
    .topbar .icon-button--menu { display: none; }
    .scrim { display: none !important; }
    .content { padding: var(--space-6) var(--space-6) var(--space-7); }
}

/* ---------------------------------------------------------------- Controls */

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: 9px 16px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    background: var(--accent);
    color: var(--accent-text);
    font: inherit;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.button:hover { background: var(--accent-hover); text-decoration: none; }
.button:disabled { opacity: 0.55; cursor: not-allowed; }

.button--secondary {
    background: var(--surface-card);
    color: var(--text-strong);
    border-color: var(--border-strong);
}

.button--secondary:hover { background: var(--surface-sunken); }

.button--ghost {
    background: transparent;
    color: var(--text-body);
    border-color: transparent;
}

.button--ghost:hover { background: var(--surface-sunken); }

.button--danger {
    background: var(--negative);
    color: #fff;
}

.button--danger:hover { background: var(--negative); filter: brightness(0.92); }

.button--small { padding: 6px 12px; font-size: 0.82rem; }
.button--block { width: 100%; }

.icon-button {
    display: inline-grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface-card);
    color: var(--text-body);
    cursor: pointer;
    flex: none;
}

.icon-button:hover { background: var(--surface-sunken); }
.icon-button svg { width: 18px; height: 18px; }

/* ---------------------------------------------------------------- Forms */

.field { margin-bottom: var(--space-4); }

.field__label {
    display: block;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-strong);
    margin-bottom: var(--space-2);
}

.field__hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: var(--space-1);
}

.field__error {
    font-size: 0.8rem;
    color: var(--negative);
    margin-top: var(--space-1);
    font-weight: 500;
}

.required-mark { color: var(--negative); margin-left: 2px; }

input[type="text"],
input[type="password"],
input[type="email"],
input[type="tel"],
input[type="number"],
input[type="date"],
input[type="search"],
select,
textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface-card);
    color: var(--text-body);
    font: inherit;
    font-size: 0.92rem;
}

/* 16px stops iOS Safari from zooming the page when a field takes focus. */
@media (max-width: 767px) {
    input, select, textarea { font-size: 16px; }
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

input.is-invalid,
select.is-invalid,
textarea.is-invalid {
    border-color: var(--negative);
}

textarea { min-height: 96px; resize: vertical; }

.field-row {
    display: grid;
    gap: var(--space-4);
    grid-template-columns: 1fr;
}

@media (min-width: 640px) {
    .field-row--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .field-row--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .field-row--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.choice-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.choice-list--inline { flex-direction: row; flex-wrap: wrap; }
.choice-list--inline .choice { flex: 1 1 160px; }

/*
 * One option per row: the label reads from the left, the control sits at the right edge where a
 * thumb reaches it. The native control is kept and tinted with accent-color rather than replaced,
 * so it keeps the platform's own checked shape — a filled dot is understood everywhere, and the
 * shape change means the selection is never carried by colour alone.
 */
.choice {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-card);
    cursor: pointer;
    /* Comfortable touch target for a surveyor tapping through a form outdoors. */
    min-height: 48px;
    transition: border-color 0.12s ease, background 0.12s ease;
}

.choice:hover {
    border-color: var(--border-strong);
    background: var(--surface-sunken);
}

.choice input {
    margin: 0;
    flex: none;
    width: 20px;
    height: 20px;
    /* Moved past the label so the control lands on the right, without reordering the markup. */
    order: 2;
    accent-color: var(--accent);
    cursor: pointer;
}

.choice:has(input:focus-visible) {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.choice:has(input:checked) {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.choice:has(input:checked) .choice__label {
    color: var(--text-strong);
    font-weight: 600;
}

.choice__label { order: 1; flex: 1; line-height: 1.35; }
.choice__score {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--text-muted);
    flex: none;
}

/* Likert row: a compact scale on desktop, a stacked list on a phone. */
.likert {
    display: grid;
    gap: var(--space-2);
    grid-template-columns: 1fr;
}

@media (min-width: 720px) {
    .likert { grid-template-columns: repeat(var(--likert-steps, 5), minmax(0, 1fr)); }
    .likert .choice { flex-direction: column; align-items: center; text-align: center; gap: var(--space-2); }
    .likert .choice__label { flex: none; font-size: 0.85rem; }
    /*
     * A scale is read left to right, so its control goes above the label rather than after it;
     * the right-edge placement only makes sense for a stacked list of options.
     */
    .likert .choice input { order: 0; }
    .likert .choice__label { order: 1; }
}

.switch {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    cursor: pointer;
}

.switch input { width: auto; }

/* ---------------------------------------------------------------- Cards */

.card {
    background: var(--surface-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.card__header {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.card__header h2,
.card__header h3 { margin: 0; flex: 1 1 auto; }

/* Controls travel as one block, so they never split across two rows on a phone. */
.card__header-controls {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-left: auto;
}

.card__body { padding: var(--space-4); }
.card__body--flush { padding: 0; }
.card__footer { padding: var(--space-3) var(--space-4); border-top: 1px solid var(--border); background: var(--surface-sunken); }

.grid {
    display: grid;
    gap: var(--space-4);
    grid-template-columns: 1fr;
}

@media (min-width: 720px) {
    .grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 1100px) {
    .grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .grid--sidebar { grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr); }
}

/* ---------------------------------------------------------------- KPI tiles */

.kpi-grid {
    display: grid;
    gap: var(--space-3);
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-bottom: var(--space-4);
}

@media (min-width: 900px) {
    .kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.kpi {
    background: var(--surface-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    box-shadow: var(--shadow-sm);
}

.kpi__label {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: var(--space-2);
}

.kpi__value {
    font-size: 1.75rem;
    font-weight: 680;
    color: var(--text-strong);
    line-height: 1.1;
    /* Proportional figures read better standing alone; tabular is for columns that must align. */
}

.kpi__meta { font-size: 0.82rem; color: var(--text-muted); margin-top: var(--space-1); }

/* ---------------------------------------------------------------- Tables */

.table-wrap { overflow-x: auto; }

table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

table.data th,
table.data td {
    padding: 10px var(--space-4);
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

table.data th {
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    font-weight: 650;
    background: var(--surface-sunken);
    position: sticky;
    top: 0;
    z-index: 1;
    white-space: nowrap;
}

table.data tbody tr:hover { background: var(--surface-sunken); }
table.data td.numeric { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr:last-child td { border-bottom: none; }

.row-link { cursor: pointer; }

/* ---------------------------------------------------------------- Badges */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 0.76rem;
    font-weight: 600;
    background: var(--neutral-soft);
    color: var(--text-body);
    white-space: nowrap;
}

.badge--positive { background: var(--positive-soft); color: var(--positive); }
.badge--negative { background: var(--negative-soft); color: var(--negative); }
.badge--warning { background: var(--warning-soft); color: var(--warning); }
.badge--info { background: var(--info-soft); color: var(--info); }
.badge--accent { background: var(--accent-soft); color: var(--accent); }

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    flex: none;
}

/* ---------------------------------------------------------------- Alerts */

.alert {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface-card);
    margin-bottom: var(--space-4);
    font-size: 0.9rem;
}

.alert--success { background: var(--positive-soft); border-color: transparent; color: var(--positive); }
.alert--error { background: var(--negative-soft); border-color: transparent; color: var(--negative); }
.alert--info { background: var(--info-soft); border-color: transparent; color: var(--info); }

/* ---------------------------------------------------------------- Breadcrumb */

.breadcrumb {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
    font-size: 0.86rem;
    margin-bottom: var(--space-3);
}

.breadcrumb__sep { color: var(--text-muted); }
.breadcrumb__current { color: var(--text-strong); font-weight: 600; }

/*
 * While a drill-down is in flight the figures are the previous area's. Fading them says so
 * without moving anything, which a spinner in their place would.
 */
.content.is-loading .kpi-grid,
.content.is-loading table.data {
    opacity: 0.55;
    transition: opacity 0.12s ease;
}

.content.is-loading { cursor: progress; }

/* ---------------------------------------------------------------- Scale categories */

/*
 * The categorisation colours from the scoring guide. Each aspect has its own hue and each
 * category its own step of that hue — knowledge blue, attitude green, behaviour brown — so a
 * reader following one aspect down a page is following one colour.
 *
 * The aspect is addressed by its position in the questionnaire rather than by name, because the
 * hues belong to first, second and third aspect, and a survey may name them anything.
 */
.aspect-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: var(--space-2) var(--space-3);
    align-items: center;
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--border);
}

.aspect-row:last-child { border-bottom: none; }

.aspect-row__name { font-weight: 600; color: var(--text-strong); }

.aspect-row__score {
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* The bar shows where the score sits in the range the aspect could have produced. */
.aspect-bar {
    grid-column: 1 / -1;
    height: 8px;
    border-radius: 4px;
    background: var(--surface-sunken);
    overflow: hidden;
}

.aspect-bar__fill { display: block; height: 100%; border-radius: 4px; }

.category-chip {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 650;
    white-space: nowrap;
}

/* Aspect 1 — knowledge: dark blue, light blue, faded blue-grey. */
.category-chip--a0.is-GOOD { background: #1e3a8a; color: #ffffff; }
.category-chip--a0.is-FAIR { background: #bfdbfe; color: #14306b; }
.category-chip--a0.is-POOR { background: #cbd5e1; color: #37455c; }
.aspect-bar__fill--a0.is-GOOD { background: #1e3a8a; }
.aspect-bar__fill--a0.is-FAIR { background: #93c5fd; }
.aspect-bar__fill--a0.is-POOR { background: #cbd5e1; }

/* Aspect 2 — attitude: forest green, mint, pale sage. */
.category-chip--a1.is-GOOD { background: #14532d; color: #ffffff; }
.category-chip--a1.is-FAIR { background: #bbf7d0; color: #0d3c22; }
.category-chip--a1.is-POOR { background: #cfd8cb; color: #3a4536; }
.aspect-bar__fill--a1.is-GOOD { background: #14532d; }
.aspect-bar__fill--a1.is-FAIR { background: #86efac; }
.aspect-bar__fill--a1.is-POOR { background: #cfd8cb; }

/* Aspect 3 — behaviour: dark brown, light brown, pale lilac. */
.category-chip--a2.is-GOOD { background: #5c3a1e; color: #ffffff; }
.category-chip--a2.is-FAIR { background: #e0c9a6; color: #4a2f18; }
.category-chip--a2.is-POOR { background: #d8cfe4; color: #453a52; }
.aspect-bar__fill--a2.is-GOOD { background: #5c3a1e; }
.aspect-bar__fill--a2.is-FAIR { background: #cdae82; }
.aspect-bar__fill--a2.is-POOR { background: #d8cfe4; }

/*
 * The combined status leaves the per-aspect hues behind for a universal scale, so that whoever
 * is deciding something can read the whole person without knowing which colour meant which
 * aspect.
 */
.status-chip {
    display: inline-block;
    padding: 3px 12px;
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 650;
    white-space: nowrap;
}

.status-chip.is-EXCELLENT { background: #16a34a; color: #ffffff; }
.status-chip.is-WARNING { background: #f5b301; color: #3b2a00; }
.status-chip.is-ATTENTION { background: #ea7317; color: #ffffff; }
.status-chip.is-AVERAGE { background: #e3d9a5; color: #4a4320; }
.status-chip.is-CRITICAL { background: #dc2626; color: #ffffff; }

/* ---------------------------------------------------------------- Live updates */

/*
 * Says the screen is keeping itself current, and flashes when it does. Deliberately quiet: it
 * reports on the page rather than on the data, so it must never compete with the figures.
 */
.live-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    margin: var(--space-2) 0 0;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.live-badge::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--status-good);
    flex: none;
}

.live-badge.is-flash { animation: live-flash 1.4s ease-out; }

@keyframes live-flash {
    0% { color: var(--accent); }
    100% { color: var(--text-muted); }
}

/* Someone who has asked for less motion still gets the text, just not the animation. */
@media (prefers-reduced-motion: reduce) {
    .live-badge.is-flash { animation: none; }
}

/* ---------------------------------------------------------------- Survey cards */

/*
 * The monitor's survey list. One card per survey, stacked rather than gridded: each card's
 * figures are a row of numbers to compare down the column, and two cards abreast would break
 * that reading. On a wide screen the card simply stops growing rather than spreading thin.
 */
.survey-cards {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    max-width: 1100px;
}

.survey-card__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
}

.survey-card__meta {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-1);
}

.survey-card__title {
    font-size: 1.1rem;
    margin: 0 0 var(--space-1);
}

.survey-card__title a { color: var(--text-strong); }

.survey-card__period { margin: 0; }

/*
 * Auto-fit rather than a fixed column count, so the five figures sit on one line on a desktop
 * and reflow to two or three on a phone without a breakpoint for each case.
 */
.survey-card__stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: var(--space-4);
    margin: var(--space-4) 0 0;
    padding-top: var(--space-4);
    border-top: 1px solid var(--border);
}

.survey-card__stats dt {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-bottom: var(--space-1);
}

.survey-card__stats dd {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 650;
    color: var(--text-strong);
}

/* Figures read down the column, so the digits have to line up. */
.survey-card__stats dd.numeric { font-variant-numeric: tabular-nums; }

.survey-card__stats dd.small { font-size: 0.9rem; font-weight: 500; }

.survey-card__empty { margin: var(--space-3) 0 0; }

/* ---------------------------------------------------------------- Map */

.map-shell {
    position: relative;
    height: 460px;
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--surface-sunken);
}

@media (min-width: 1100px) {
    .map-shell { height: 560px; }
}

#map { position: absolute; inset: 0; }

.map-legend {
    position: absolute;
    right: var(--space-3);
    bottom: var(--space-3);
    z-index: 500;
    background: var(--surface-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-3);
    box-shadow: var(--shadow);
    font-size: 0.78rem;
}

.map-legend__scale { display: flex; align-items: center; gap: 2px; margin-top: 6px; }
.map-legend__swatch { width: 26px; height: 12px; }
.map-legend__labels { display: flex; justify-content: space-between; font-size: 0.7rem; color: var(--text-muted); margin-top: 3px; }

/* Leaflet paints its own surfaces, so the popup and controls are re-skinned to match the theme. */
.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
    background: var(--surface-card);
    color: var(--text-body);
    box-shadow: var(--shadow);
}

.leaflet-popup-content { margin: var(--space-3); font-family: var(--font-sans); }
.leaflet-bar a { background: var(--surface-card); color: var(--text-body); border-color: var(--border); }
.leaflet-bar a:hover { background: var(--surface-sunken); }
[data-theme="dark"] .leaflet-tile { filter: brightness(0.82) contrast(1.05) saturate(0.85); }

.map-popup__title { font-weight: 650; color: var(--text-strong); margin-bottom: 4px; }
.map-popup__row { display: flex; justify-content: space-between; gap: var(--space-4); font-size: 0.82rem; }

/* The way deeper into the tree. A click on the area now reads it; this opens it. */
.map-popup__drill {
    display: inline-block;
    margin-top: var(--space-3);
    font-size: 0.82rem;
    font-weight: 600;
}

/* ---------------------------------------------------------------- Charts */

.chart-shell { position: relative; height: 240px; }
.chart-shell--tall { height: 300px; }

.bar-row {
    display: grid;
    grid-template-columns: minmax(90px, 1fr) minmax(0, 3fr) auto;
    gap: var(--space-3);
    align-items: center;
    margin-bottom: var(--space-2);
    font-size: 0.85rem;
}

.bar-track {
    height: 8px;
    border-radius: 999px;
    background: var(--surface-sunken);
    overflow: hidden;
}

/*
 * 4px rounded data-end anchored to the baseline: the bar starts square against the axis and is
 * rounded only where the value ends, so the reader is never misled about where zero is.
 */
.bar-fill {
    height: 100%;
    border-radius: 0 4px 4px 0;
    background: var(--series-1);
    min-width: 2px;
}

.bar-fill--positive { background: var(--status-good); }
.bar-fill--negative { background: var(--status-critical); }
.bar-fill--neutral { background: var(--status-neutral); }
.bar-fill--warning { background: var(--status-warning); }

/* ---------------------------------------------------------------- Builder */

.builder-section {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-4);
    background: var(--surface-card);
}

.builder-section__head {
    display: flex;
    gap: var(--space-3);
    align-items: center;
    padding: var(--space-3) var(--space-4);
    background: var(--surface-sunken);
    border-bottom: 1px solid var(--border);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    flex-wrap: wrap;
}

.builder-question {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-4);
    margin: var(--space-3) var(--space-4);
    background: var(--surface-page);
}

.builder-option-row {
    display: grid;
    grid-template-columns: 80px minmax(0, 1fr) 90px auto;
    gap: var(--space-2);
    align-items: center;
    margin-bottom: var(--space-2);
}

@media (max-width: 640px) {
    .builder-option-row { grid-template-columns: 1fr 1fr; }
}

/* ---------------------------------------------------------------- Stepper */

.stepper {
    display: flex;
    gap: var(--space-2);
    overflow-x: auto;
    padding-bottom: var(--space-2);
    margin-bottom: var(--space-4);
    scrollbar-width: thin;
}

.step-chip {
    padding: 6px 14px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-card);
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
}

.step-chip.is-active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
}

.step-chip.is-done { color: var(--accent); border-color: var(--accent); }

.form-step { display: none; }
.form-step.is-active { display: block; }

.form-actions {
    display: flex;
    gap: var(--space-3);
    flex-wrap: wrap;
    position: sticky;
    bottom: 0;
    background: var(--surface-page);
    padding: var(--space-4) 0;
    border-top: 1px solid var(--border);
    margin-top: var(--space-5);
}

.form-actions .button { flex: 1 1 auto; }

@media (min-width: 720px) {
    .form-actions .button { flex: 0 0 auto; }
}

/* ---------------------------------------------------------------- Login */

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: var(--space-4);
    background:
        radial-gradient(900px 500px at 15% -10%, var(--accent-soft), transparent 60%),
        var(--surface-page);
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: var(--space-6);
}

.auth-card__brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-5);
}

.demo-accounts {
    margin-top: var(--space-5);
    padding-top: var(--space-4);
    border-top: 1px dashed var(--border);
    font-size: 0.82rem;
}

.demo-accounts table { width: 100%; border-collapse: collapse; }
.demo-accounts td { padding: 3px 0; }

/* ---------------------------------------------------------------- Misc */

.pagination {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    justify-content: center;
    padding: var(--space-4);
}

.empty-state {
    text-align: center;
    padding: var(--space-7) var(--space-4);
    color: var(--text-muted);
}

.filter-bar {
    display: flex;
    gap: var(--space-3);
    flex-wrap: wrap;
    align-items: flex-end;
    margin-bottom: var(--space-4);
}

.filter-bar .field { margin-bottom: 0; flex: 1 1 180px; min-width: 0; }

.stack > * + * { margin-top: var(--space-3); }
.inline { display: inline-flex; align-items: center; gap: var(--space-2); }

.definition-list {
    display: grid;
    grid-template-columns: minmax(120px, auto) 1fr;
    gap: var(--space-2) var(--space-4);
    font-size: 0.9rem;
}

.definition-list dt { color: var(--text-muted); }
.definition-list dd { margin: 0; color: var(--text-strong); }

@media print {
    .sidebar, .topbar, .form-actions, .page-header__actions { display: none !important; }
    body { background: #fff; }
    .card { box-shadow: none; border-color: #ccc; }
}

/* ---------------------------------------------------------------- Sidebar survey list */

/* Survey titles run long, so a nav entry wraps to two lines instead of being cut off. */
.nav-item__label {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.3;
}

.nav-item:has(.nav-item__label) { align-items: flex-start; }
.nav-item:has(.nav-item__label) svg { margin-top: 2px; }

.nav-empty {
    color: var(--text-muted);
    padding: var(--space-3);
    margin: 0;
}

/* ---------------------------------------------------------------- Pager */

.pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--border);
}

.pager__controls {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    flex-wrap: wrap;
}

.pager__page {
    min-width: 38px;
    height: 38px;
    padding: 0 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-card);
    color: var(--text-body);
    font-size: 0.86rem;
    font-variant-numeric: tabular-nums;
}

.pager__page:hover { background: var(--surface-sunken); text-decoration: none; }

.pager__page.is-current {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
    font-weight: 650;
}

.pager__gap {
    padding: 0 var(--space-1);
    color: var(--text-muted);
}

/* Disabled controls stay in place so the row does not reflow at the first and last page. */
.icon-button.is-disabled {
    opacity: 0.4;
    pointer-events: none;
}

.pager__size {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
}

.pager__size select { width: auto; padding: 6px 10px; font-size: 0.86rem; }

@media (max-width: 640px) {
    .pager { justify-content: center; }
    .pager__size { justify-content: center; width: 100%; }
}

/* A reference is an identifier, not prose: wrapping it makes every row on a phone twice as tall. */
table.data td.mono { white-space: nowrap; }

/* ---------------------------------------------------------------- Fullscreen map */

.map-shell.is-fullscreen {
    position: fixed;
    inset: 0;
    z-index: 100;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
}

/* Stops the page behind from scrolling under the expanded map. */
body.has-fullscreen-map { overflow: hidden; }

/*
 * The way out of the expanded map. Hidden until the map is expanded, because outside fullscreen
 * the header button is the control and two of them would be one too many. Above Leaflet's own
 * panes (z-index 400-700) so nothing on the map can sit on top of it.
 */
.map-exit {
    position: absolute;
    top: var(--space-3);
    right: var(--space-3);
    z-index: 900;
    display: none;
    align-items: center;
    gap: var(--space-2);
    box-shadow: var(--shadow-lg);
}

.map-shell.is-fullscreen .map-exit { display: inline-flex; }

.map-exit svg { width: 18px; height: 18px; }

.map-shell.is-fullscreen .map-legend {
    right: var(--space-4);
    bottom: var(--space-4);
}

/*
 * Region names sit on the map itself. Leaflet's default tooltip is a white box with a border,
 * which at this density reads as clutter, so it is reduced to legible text with a halo that
 * survives both a pale sea and a dark landmass.
 */
/*
 * The way back up, sitting on the map so it is still reachable when the expanded map covers the
 * breadcrumb. Left side, clear of the exit button on the right and the zoom control above.
 */
.map-up {
    position: absolute;
    top: var(--space-3);
    left: 56px;
    z-index: 900;
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    box-shadow: var(--shadow-lg);
    max-width: 55%;
}

.map-up[hidden] { display: none; }

.map-up svg { width: 16px; height: 16px; flex: none; }

.map-up span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------------------------------------------------------------- Area score recap */

.recap {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 420px;
    overflow-y: auto;
}

/*
 * Four columns: colour, name, responses, score. The two figures are fixed width and right
 * aligned so they read straight down the column, which is the point of the list.
 */
.recap__row {
    display: grid;
    grid-template-columns: 12px 1fr auto 62px;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-4);
    border-bottom: 1px solid var(--border);
}

.recap__row:last-child { border-bottom: none; }

.recap__swatch {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    border: 1px solid var(--border);
}

.recap__name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.9rem;
}

.recap__count {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.recap__score {
    text-align: right;
    font-weight: 650;
    color: var(--text-strong);
    font-variant-numeric: tabular-nums;
    font-size: 0.9rem;
}

.recap__empty { padding: var(--space-4); }

/* Dropped because it would have landed on a name already drawn; the popup still carries it. */
.leaflet-tooltip.map-label.is-label-hidden { display: none; }

/*
 * The label is a name over a score, stacked. Two lines because these islands spread east to
 * west: laid out on one line the labels collide long before they run out of vertical room.
 */
.leaflet-tooltip.map-label .map-label__name,
.leaflet-tooltip.map-label .map-label__score {
    display: block;
    line-height: 1.15;
}

.leaflet-tooltip.map-label .map-label__score {
    font-variant-numeric: tabular-nums;
    font-size: 0.92em;
    opacity: 0.85;
}

.leaflet-tooltip.map-label {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
    text-align: center;
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 650;
    color: var(--text-strong);
    text-shadow:
        0 0 3px var(--surface-card), 0 0 3px var(--surface-card),
        0 0 3px var(--surface-card), 0 0 3px var(--surface-card);
    white-space: nowrap;
}

.leaflet-tooltip.map-label::before { display: none; }
