/* ============================================================================
   FCN Health design system — Phase 1 foundation.
   Neutral clinical canvas; brand color is accent-only. Light-first, dark-ready.
   Brand accents come from --brand-* (injected per-tenant in the layout <head>).
   ============================================================================ */

:root {
    /* Brand accents — overridden per tenant in the layout. Fallbacks match BrandTheme.Default. */
    --brand-primary: #2B5C8A;
    --brand-secondary: #4C8C6B;
    --brand-primary-contrast: #FFFFFF;

    /* Neutral clinical canvas */
    --surface: #FFFFFF;
    --surface-2: #F5F7FA;
    --surface-3: #EDF1F6;
    --border: #DBE1E8;
    --text: #1B2733;
    --text-muted: #5B6a7a;

    /* Semantic colors (fixed — never tenant-themed) */
    --success: #1F8A54;
    --warning: #B26A00;
    --danger: #C0392B;
    --info: #2B6CB0;

    /* Impact-report data series (fixed — encode stream identity, not brand; CVD-validated pair) */
    --impact-ind: #2A6FB0;       /* individual interactions */
    --impact-ind-soft: #8FBCE2;  /* family/friends — lighter tint of the individual stream */
    --impact-grp: #3D7156;       /* group activity */
    /* Professional (standalone) time on the group dashboard — the second stream there. Validated
       against --impact-grp: CVD ΔE 11.9 deutan / 17.8 normal-vision, >= 3:1 on this surface. */
    --impact-prof: #6A4C93;

    /* Spacing scale (8px base) */
    --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
    --sp-5: 24px; --sp-6: 32px; --sp-7: 48px;

    /* Radii */
    --radius-sm: 4px; --radius-md: 8px; --radius-pill: 999px;

    --sidebar-w: 248px;
    --topbar-h: 56px;

    --font-stack: Inter, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --surface: #141a21;
        --surface-2: #1b232c;
        --surface-3: #232d38;
        --border: #303c49;
        --text: #E7ECF2;
        --text-muted: #9AA7B5;

        /* Semantic tokens lightened for dark surfaces — the light-mode values land ~3–4:1
           against #141a21; these tints keep text usages ≥ 4.5:1 (WCAG AA) on all surfaces. */
        --success: #44C08A;
        --warning: #E09B3D;
        --danger: #F08A7E;
        --info: #64A9E8;

        --impact-ind: #57A2E0;
        --impact-ind-soft: #3A5F80;
        --impact-grp: #63B088;
        /* Re-stepped for the dark surface, not flipped: CVD ΔE 13.8 deutan / 20.3 normal-vision
           against the dark --impact-grp, >= 3:1 on #141a21. */
        --impact-prof: #9B85D6;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font-stack);
    font-size: 16px;               /* 16px min body/inputs */
    line-height: 1.5;
    color: var(--text);
    background: var(--surface-2);
}

.num { font-variant-numeric: tabular-nums lining-nums; text-align: right; }
/* Hide the spinner arrows on numeric inputs (customer ask) while KEEPING type="number", which is
   what gives phones the numeric keypad and the browser its own range validation. */
input.num[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input.num[type="number"]::-webkit-outer-spin-button,
input.num[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* asp-validation-summary="All" inside a form ALWAYS renders the element — on a clean page it is an
   empty <ul> classed .validation-summary-valid, kept as a target for client-side validation to fill.
   Nothing fills it here (no jQuery unobtrusive), and a summary styled .alert-danger would otherwise
   paint an empty red bar on every fresh group form. Errors switch it to .validation-summary-errors. */
.validation-summary-valid { display: none; }

/* WCAG: inputs must stay ≥16px even in Bootstrap's "sm" sizing (buttons may stay small). */
.form-control-sm, .form-select-sm { font-size: 1rem; }

/* Bootstrap pins its de-emphasized text to fixed LIGHT-scheme colours — .form-text to #6c757d
   (~3.4:1 on the dark surface) and .text-muted to rgba(33,37,41,.75), which on a dark panel is
   near-black on near-black. Bootstrap keys dark mode off [data-bs-theme], which the app never
   sets, so neither ever adapts. Both mean exactly what --text-muted means, and that token follows
   the scheme and is AA on every surface. (.text-muted is Bootstrap's own !important, so beating it
   takes one back.) */
.form-text { color: var(--text-muted); }
.text-muted { color: var(--text-muted) !important; }

/* A checkbox-group legend reads as an ordinary field label, not Bootstrap's heading-sized, floated
   <legend>. The reports filter bar already did this for itself (.rf-field > legend.form-label);
   the group forms need the same, so the rule generalizes to anything asking for a label. */
legend.form-label { font-size: inherit; font-weight: inherit; float: none; width: auto; line-height: inherit; }

/* Auto-growing notes textareas (site.js fitTextarea): the box expands to fit its content so a
   long note is fully visible without scrolling inside it. The rows attribute sets the floor;
   overflow-y stays hidden because the element is always tall enough to show everything. */
textarea.autogrow { overflow-y: hidden; resize: vertical; }

/* ---- App shell ---------------------------------------------------------- */
.app-shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.app-main { display: flex; flex-direction: column; min-width: 0; }
.app-content { padding: var(--sp-5); flex: 1; }

/* ---- Sidebar ------------------------------------------------------------ */
.app-sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    padding: var(--sp-4) var(--sp-3);
}
.app-brand { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-2) var(--sp-5); }
.app-brand__mark {
    width: 40px; height: 40px; border-radius: var(--radius-md);
    background: var(--brand-primary); color: var(--brand-primary-contrast);
    display: grid; place-items: center; font-weight: 700; font-size: 20px;
}
.app-brand__name { font-weight: 650; font-size: 15px; }

.app-nav { display: flex; flex-direction: column; gap: 2px; }
.app-nav__link {
    display: flex; align-items: center; gap: var(--sp-3);
    padding: var(--sp-2) var(--sp-3); border-radius: var(--radius-sm);
    color: var(--text); text-decoration: none; font-size: 15px;
}
.app-nav__link:hover { background: var(--surface-3); }
.app-nav__link.active {
    background: color-mix(in srgb, var(--brand-primary) 14%, transparent);
    color: var(--brand-primary); font-weight: 600;
    box-shadow: inset 3px 0 0 var(--brand-primary);
}
.app-nav__link--disabled { color: var(--text-muted); cursor: not-allowed; opacity: .65; }
.app-nav__icon { width: 20px; text-align: center; }

/* Hamburger + drawer backdrop: hidden on desktop, shown in the mobile breakpoint. */
.app-nav-toggle {
    display: none; margin-left: auto;
    background: none; border: 1px solid var(--border); border-radius: var(--radius-sm);
    color: var(--text); font-size: 20px; line-height: 1;
    width: 40px; height: 40px; cursor: pointer;
}
.app-nav-toggle:hover { background: var(--surface-3); }
.app-nav-backdrop { display: none; }

.app-sidebar__footer { margin-top: auto; padding-top: var(--sp-4); }
.badge-phase {
    font-size: 12px; color: var(--text-muted);
    border: 1px solid var(--border); border-radius: var(--radius-pill);
    padding: 2px var(--sp-3);
}
.app-sidebar__meta { font-size: 12px; color: var(--text-muted); margin-top: var(--sp-2); }

/* ---- Top bar ------------------------------------------------------------ */
.app-topbar {
    height: var(--topbar-h); min-height: var(--topbar-h);
    background: var(--surface); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: flex-end;
    padding: 0 var(--sp-5); gap: var(--sp-4);
    position: sticky; top: 0; z-index: 20;
}
.app-topbar__right { display: flex; align-items: center; gap: var(--sp-4); }

.context-badge {
    background: var(--surface-3); color: var(--text);
    border: 1px solid var(--border); border-radius: var(--radius-pill);
    padding: var(--sp-1) var(--sp-4); font-size: 14px; font-weight: 600;
}
.context-badge--muted { color: var(--text-muted); font-weight: 500; }
.context-switcher__menu { min-width: 220px; }

.app-user { display: flex; align-items: center; gap: var(--sp-2); }
.app-user__avatar {
    width: 32px; height: 32px; border-radius: var(--radius-pill);
    background: var(--brand-secondary); color: #fff;
    display: grid; place-items: center; font-size: 12px; font-weight: 700;
}
.app-user__name { font-size: 14px; }

/* ---- Page primitives ---------------------------------------------------- */
.page-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: var(--sp-5); }
.page-title { font-size: 24px; font-weight: 680; margin: 0; }
.page-subtitle { color: var(--text-muted); margin: var(--sp-1) 0 0; font-size: 14px; }

/* color is not decoration here: a panel is almost always written `class="card panel"`, and
   Bootstrap's `.card { color: var(--bs-body-color) }` pins everything inside it to the LIGHT body
   colour — Bootstrap keys dark mode off [data-bs-theme], which the app never sets, so the dark
   tokens never reach a card's contents and every inheriting label rendered near-black on
   near-black. Same fix, and same reasoning, as .impact further down; descendants with an explicit
   muted or semantic colour keep theirs. */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); margin-bottom: var(--sp-5); color: var(--text); }
.panel__head { padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); }
.panel__title { font-size: 16px; font-weight: 650; margin: 0; }
.panel__body { padding: var(--sp-5); }
.panel__body.p-0 { padding: 0; }

/* Subjects INSIDE one card, rather than a card each. The card border and the <h2> panel head are
   the page's heaviest separators; spending them on every subject of a single-record form (the
   group forms did, five deep) costs a screen of height and pushes the fields down to two-up. A
   rule and a small eyebrow say "new subject" just as clearly — the same treatment .rail-card__title
   gives a rail card — which is what lets the fields go three-up again. */
.form-section { padding-top: var(--sp-4); margin-top: var(--sp-4); border-top: 1px solid var(--border); }
.form-section:first-child { padding-top: 0; margin-top: 0; border-top: 0; }
.form-section__title {
    font-size: 13px; text-transform: uppercase; letter-spacing: .05em;
    color: var(--text-muted); font-weight: 700; margin: 0 0 var(--sp-3);
}

/* ---- Stat cards --------------------------------------------------------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--sp-4); margin-bottom: var(--sp-5); }
.stat-card { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--sp-5); }
.stat-card__value { font-size: 32px; font-weight: 720; font-variant-numeric: tabular-nums lining-nums; }
.stat-card__label { color: var(--text-muted); font-size: 13px; margin-top: var(--sp-1); }
.stat-card--accent { border-color: var(--brand-primary); box-shadow: inset 0 3px 0 var(--brand-primary); }

/* "How is this calculated?" disclosure on stat cards. */
.stat-card__info {
    position: absolute; top: var(--sp-3); right: var(--sp-3);
    width: 24px; height: 24px; padding: 0;
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--border); border-radius: 50%;
    background: transparent; color: var(--text-muted);
    font-size: 13px; font-weight: 700; line-height: 1; cursor: pointer;
}
.stat-card__info:hover,
.stat-card__info[aria-expanded="true"] { color: var(--brand-primary); border-color: var(--brand-primary); }
.stat-card__info:focus-visible { outline: 2px solid var(--brand-primary); outline-offset: 2px; }
.stat-card__pop {
    position: absolute; top: calc(var(--sp-3) + 30px); right: var(--sp-3); left: var(--sp-3); z-index: 30;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
    box-shadow: 0 8px 24px rgba(0, 0, 0, .16);
    padding: var(--sp-3); font-size: 13px; line-height: 1.45; color: var(--text);
}

/* Hide Alpine-managed elements until Alpine initializes (prevents x-show flash). */
[x-cloak] { display: none !important; }

/* ---- Row actions + Copy popover (group-plane lists) --------------------- */
/* Keep the Edit link and the Copy trigger inline at the end of an Actions cell. */
.row-actions { display: inline-flex; gap: var(--sp-2); align-items: center; }

/* The Copy popover anchors its floating panel to the trigger. */
.copy-pop { position: relative; display: inline-block; }
.copy-pop__panel {
    position: absolute; top: calc(100% + var(--sp-1)); right: 0; z-index: 40;
    width: 260px; text-align: left;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .16); padding: var(--sp-3);
}
.copy-pop__title {
    font-size: 13px; font-weight: 700; color: var(--text);
    margin-bottom: var(--sp-2);
}
.copy-pop__list { list-style: none; margin: 0 0 var(--sp-3); padding: 0; }
.copy-pop__item {
    display: grid; grid-template-columns: auto 1fr; gap: var(--sp-2);
    align-items: start; padding: var(--sp-1) 0;
}
.copy-pop__item .form-check-label { display: flex; flex-direction: column; }
.copy-pop__label { font-size: 14px; color: var(--text); }
.copy-pop__subtitle { font-size: 12px; color: var(--text-muted); }
.copy-pop__footer { display: flex; justify-content: flex-end; border-top: 1px solid var(--border); padding-top: var(--sp-3); }

/* ---- Nav group heading -------------------------------------------------- */
.app-nav__group {
    font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
    color: var(--text-muted); padding: var(--sp-4) var(--sp-3) var(--sp-1); font-weight: 600;
}

/* A group and the links that belong to it, visibly bounded. "Group Activity" sits MID-nav —
   ungrouped links (Reports, Help, What's New) follow it — so the heading alone cannot say where
   the group ends; the rule stops with the last member. The trailing groups (Administration,
   System) run to the bottom of the nav and need no closing mark. */
.app-nav__section {
    display: flex; flex-direction: column; gap: 2px;
    margin: var(--sp-1) 0 var(--sp-2) var(--sp-1);
    padding-left: var(--sp-2);
    border-left: 2px solid var(--border);
}
/* Inside the rule the heading needs less lead-in than a free-standing group heading. */
.app-nav__section > .app-nav__group { padding-top: var(--sp-2); }

/* ---- Definition / detail list ------------------------------------------ */
.detail-list { display: grid; grid-template-columns: 40% 60%; gap: var(--sp-2) 0; margin: 0; }
.detail-list dt { color: var(--text-muted); font-size: 13px; }
.detail-list dd { margin: 0; font-size: 15px; }

/* ---- Pills / status ----------------------------------------------------- */
.pill {
    display: inline-block; font-size: 13px; font-weight: 600;
    padding: 2px var(--sp-3); border-radius: var(--radius-pill);
    background: var(--surface-3); color: var(--text);
}
/* Warning-tinted pill (e.g. positive screening result) — tinted background + full-contrast
   text, following the .toast-banner pattern (solid --warning behind #fff fails AA). */
.pill--warning {
    background: color-mix(in srgb, var(--warning) 18%, var(--surface));
    border: 1px solid var(--warning); color: var(--text);
}
/* Success/danger-tinted pills (e.g. bulk-import row outcomes), same tinted-bg + full-contrast
   text pattern as .pill--warning so both light and dark schemes stay AA. */
.pill--success {
    background: color-mix(in srgb, var(--success) 18%, var(--surface));
    border: 1px solid var(--success); color: var(--text);
}
.pill--danger {
    background: color-mix(in srgb, var(--danger) 18%, var(--surface));
    border: 1px solid var(--danger); color: var(--text);
}

/* ---- Reports: top filter bar + results ---------------------------------- */
.reports-page { display: flex; flex-direction: column; gap: var(--sp-5); }
.stat-card__sub { font-size: 14px; font-weight: 500; color: var(--text-muted); }
.reports-sheets-hint { border-bottom: 1px solid var(--border); }
.reports-sheets-hint > summary { cursor: pointer; font-weight: 500; color: var(--text-muted); }
.reports-sheets-hint[open] > summary { color: var(--text); }

/* Basic filters: one horizontal, wrapping row; actions push to the right. */
.reports-filter-row { display: flex; flex-wrap: wrap; gap: var(--sp-3); align-items: flex-end; }
.rf-field { display: flex; flex-direction: column; gap: 4px; min-width: 150px; margin: 0; border: 0; padding: 0; }
.rf-field .form-label { margin-bottom: 0; }
/* Checkbox-group / age legends read as ordinary field labels, not Bootstrap's heading-sized legend. */
.rf-field > legend.form-label { font-size: inherit; font-weight: inherit; float: none; width: auto; line-height: inherit; }
.rf-field--report { flex: 1 1 22rem; min-width: 18rem; }
.reports-filter-row .rf-field--report { flex-basis: 26rem; }
/* Organization / Nurse tick boxes differ in height; hang them from the top so their legends line up. */
.reports-filter-row .rf-field--checks { align-self: flex-start; }
.rf-actions { display: flex; gap: var(--sp-2); align-items: flex-end; margin-left: auto; }

/* Advanced filters: collapsed by default, laid out as an auto-fitting grid. */
.reports-advanced { margin-top: var(--sp-4); border-top: 1px solid var(--border); padding-top: var(--sp-3); }
.reports-advanced > summary { cursor: pointer; font-weight: 600; color: var(--text); list-style: revert; }
.reports-filter-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--sp-3) var(--sp-4); margin-top: var(--sp-3); align-items: start;
}
.rf-field--checks { min-width: 0; }
.rf-checkbox-box { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--sp-2); }
.rf-checkbox-box--scroll { max-height: 11rem; overflow-y: auto; }

/* Advanced filters are grouped by what they narrow (structural, visit + client, group activity),
   each group captioned with the data plane(s) it reaches for the selected report. */
.reports-filter-group { margin: var(--sp-3) 0 0; padding: 0; border: 0; min-width: 0; }
.reports-filter-group + .reports-filter-group { margin-top: var(--sp-4); padding-top: var(--sp-3); border-top: 1px dashed var(--border); }
.reports-filter-group__legend {
    /* Bootstrap's reboot floats legends so they flow like a block instead of sitting on the
       fieldset border — keep that, so the group's top rule stays above the legend. */
    float: left; width: 100%; margin: 0; padding: 0;
    font-size: 15px; font-weight: 700; color: var(--text);
    display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--sp-2) var(--sp-3);
}
.reports-filter-group__caption { font-size: 14px; font-weight: 500; color: var(--text-muted); }
.reports-filter-group .reports-filter-grid { clear: both; margin-top: var(--sp-2); }
/* Remembered-but-inapplicable filters hint, under the basic row. */
.reports-dormant-hint { margin-top: var(--sp-2); }
/* "What this report reads" badge beside the report title. */
.reports-plane-badge { font-size: 13px; font-weight: 600; vertical-align: middle; margin-left: var(--sp-2); }

/* In-page section jump list for long multi-section reports (screen only). */
.report-jump { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-3); align-items: baseline; }
.report-jump__label {
    font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted);
}
.report-jump__list { display: flex; flex-wrap: wrap; gap: 4px var(--sp-3); list-style: none; margin: 0; padding: 0; font-size: 14px; }
/* Section titles sit UNDER the report title (.panel__title, 16px), so they must not outrank it —
   Bootstrap's default h3 (~29px) did, and cost a lot of vertical space in a 40-section report.
   Rendered as a centred header row that closes with a rule, like the table's own header. */
.report-section-title {
    font-size: 15px; font-weight: 650; text-align: center; margin: 0;
    padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--border);
    scroll-margin-top: var(--sp-5);
}

/* Applied filter-criteria header shown above the report body (and in exports). */
.report-criteria {
    padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.report-criteria__label {
    display: block; font-size: 13px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .03em; color: var(--text-muted); margin-bottom: var(--sp-2);
}
.report-criteria__list { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-5); margin: 0; }
.report-criteria__item { display: flex; gap: 6px; margin: 0; }
.report-criteria__item dt { font-weight: 600; color: var(--text-muted); margin: 0; }
.report-criteria__item dd { margin: 0; color: var(--text); }

/* ---- Brand preview (settings) ------------------------------------------ */
.brand-preview { display: flex; gap: var(--sp-3); }
.brand-preview__chip { padding: var(--sp-2) var(--sp-4); border-radius: var(--radius-sm); font-weight: 600; font-size: 14px; }

/* ---- Toast banner ------------------------------------------------------- */
.toast-banner {
    background: color-mix(in srgb, var(--success) 14%, var(--surface));
    border: 1px solid var(--success); color: var(--text);
    border-radius: var(--radius-md); padding: var(--sp-3) var(--sp-4); margin-bottom: var(--sp-4);
}

/* Warning/error banner (validation failures, clinical safety alerts) — must be visually prominent. */
.toast-banner--warning {
    background: color-mix(in srgb, var(--danger) 14%, var(--surface));
    border: 2px solid var(--danger); font-weight: 600;
}

/* ---- Dashboard: announcements + section header ---------------------------- */
/* A secondary header for a section lower on a page (the impact tiles): same layout as
   .page-header, smaller title, tighter bottom margin. */
.page-header--section { margin-bottom: var(--sp-4); align-items: flex-end; }
.page-header--section .page-title { font-size: 18px; }

/* One announcement card: a left rule in the severity color (semantic tokens, never brand), the
   tinted-background + full-contrast-text pattern of .toast-banner so both schemes stay AA. */
.announcement {
    position: relative;
    border: 1px solid var(--border); border-left: 4px solid var(--info);
    border-radius: var(--radius-sm); padding: var(--sp-3) var(--sp-4);
    background: var(--surface);
}
.announcement + .announcement { margin-top: var(--sp-3); }
.announcement--info { border-left-color: var(--info); }
.announcement--warning {
    border-left-color: var(--warning);
    background: color-mix(in srgb, var(--warning) 8%, var(--surface));
}
.announcement--critical {
    border-left-color: var(--danger);
    background: color-mix(in srgb, var(--danger) 8%, var(--surface));
}
.announcement__head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--sp-2) var(--sp-3); }
.announcement__title { font-size: 16px; font-weight: 650; margin: 0; }
.announcement__meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); font-size: 13px; color: var(--text-muted); }
.announcement__audience::before { content: "·"; margin-right: var(--sp-2); }
.announcement__date::before { content: "·"; margin-right: var(--sp-2); }
.announcement__meta > :first-child::before { content: none; }
/* Plain text with the author's line breaks kept — no markup is ever rendered from an announcement. */
.announcement__body { white-space: pre-line; margin: var(--sp-2) 0 0; }
.announcement__actions { margin-top: var(--sp-3); }

/* ---- Encounter form: rail + sectioned document -------------------------- */
.encounter-layout { display: grid; grid-template-columns: 260px 1fr; gap: var(--sp-5); align-items: start; }
.rail { position: sticky; top: calc(var(--topbar-h) + var(--sp-4)); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--sp-3); }
.rail__status { font-size: 13px; padding: var(--sp-2) var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--border); margin-bottom: var(--sp-2); }
.rail__saved { color: var(--success); font-weight: 600; }
.rail__errors { color: var(--danger); font-weight: 700; }
.rail__list { list-style: none; margin: 0; padding: 0; }
.rail__item a { display: flex; align-items: center; gap: var(--sp-2); padding: 5px var(--sp-2); border-radius: var(--radius-sm); color: var(--text); text-decoration: none; font-size: 14px; }
.rail__item a:hover { background: var(--surface-3); }
.rail__icon { width: 18px; text-align: center; font-weight: 700; }
.rail__title { flex: 1; }
/* color: var(--surface) keeps the badge text ≥ 4.5:1 in both schemes (white on the light-red
   dark-mode --danger tint would fail). */
.rail__badge { background: var(--danger); color: var(--surface); border-radius: var(--radius-pill); font-size: 11px; padding: 0 6px; }
.rail__item--complete .rail__icon { color: var(--success); }
.rail__item--partial .rail__icon { color: var(--warning); }
.rail__item--error .rail__icon { color: var(--danger); }
.rail__item--empty .rail__icon { color: var(--text-muted); }
.rail__item--planned a { color: var(--text-muted); }
.section-card { scroll-margin-top: calc(var(--topbar-h) + var(--sp-4)); }

/* Per-section finalize-validation messages (mirrors the .toast-banner danger treatment). */
.section-errors {
    background: color-mix(in srgb, var(--danger) 12%, var(--surface));
    border: 1px solid var(--danger); color: var(--text);
    border-radius: var(--radius-sm); padding: var(--sp-3) var(--sp-4); margin-bottom: var(--sp-4);
}
.section-errors ul { margin: 0; padding-left: 1.2em; }
.calc-strip { background: var(--surface-2); border-radius: var(--radius-sm); padding: var(--sp-2) var(--sp-3); font-size: 14px; display: inline-block; }
.encounter-actions { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--border); padding: var(--sp-3) 0; margin-top: var(--sp-4); display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.encounter-actions > form { margin: 0; }
/* Click-to-open "what do these do?" popover anchored to the info icon at the end of the action bar. */
.actions-help { position: relative; display: inline-flex; align-items: center; }
.actions-help__panel { position: absolute; bottom: calc(100% + var(--sp-2)); right: 0; width: min(380px, 90vw); padding: var(--sp-3); text-align: left; box-shadow: 0 6px 24px rgba(0,0,0,.18); z-index: 30; }
.actions-help__panel dt { font-weight: 700; margin-top: var(--sp-2); }
.actions-help__panel dt:first-child { margin-top: 0; }
.actions-help__panel dd { margin: 0; color: var(--text-muted); font-size: .9rem; }
@media (max-width: 900px) { .encounter-layout { grid-template-columns: 1fr; } .rail { position: static; } }

/* ---- Group activity form: working column + sticky totals rail ------------
   The mirror image of the encounter layout — the rail sits on the RIGHT here
   because it carries live totals rather than a navigation index, so it reads
   as the result of the work rather than a table of contents. */
.group-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: var(--sp-5); align-items: start; }
.group-main { min-width: 0; }
.group-rail { position: sticky; top: calc(var(--topbar-h) + var(--sp-4)); display: flex; flex-direction: column; gap: var(--sp-3); }
.rail-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--sp-4); }
.rail-card__title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: 700; margin: 0 0 var(--sp-3); }
.rail-card__note { font-size: 12px; color: var(--text-muted); margin: var(--sp-1) 0 0; }
.rail-figure__value { display: block; font-size: 30px; font-weight: 720; line-height: 1.1; font-variant-numeric: tabular-nums lining-nums; }
.rail-figure__label { display: block; font-size: 13px; color: var(--text-muted); }
.rail-stats { display: grid; grid-template-columns: 1fr auto; gap: var(--sp-2) var(--sp-3); margin: var(--sp-3) 0 0; padding-top: var(--sp-3); border-top: 1px solid var(--border); }
.rail-stat { display: contents; }
.rail-stat dt { font-size: 13px; color: var(--text-muted); }
.rail-stat dd { margin: 0; font-size: 15px; font-weight: 650; text-align: right; font-variant-numeric: tabular-nums lining-nums; }
.rail-progress { height: 8px; background: var(--surface-3); }
.rail-progress .progress-bar { background: var(--brand-primary); }
.rail-actions { display: flex; flex-direction: column; gap: var(--sp-2); }
.rail-actions > form { margin: 0; }

/* Readiness checklist. State is carried by the mark AND visually-hidden text, never colour alone. */
.checklist { list-style: none; margin: var(--sp-3) 0 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-2); }
.checklist__item { display: flex; gap: var(--sp-2); font-size: 14px; line-height: 1.35; }
.checklist__mark { width: 16px; flex: 0 0 auto; font-weight: 700; color: var(--text-muted); }
.checklist__item--ok { color: var(--text-muted); }
.checklist__item--ok .checklist__mark { color: var(--success); }
.checklist__item--todo .checklist__mark { color: var(--warning); }
/* An unmet check is a link to the first place it fails. Underlined, so it does not rely on colour
   to read as clickable, and padded to a comfortable target without stretching the list. */
.checklist__link { color: inherit; text-decoration: underline; text-underline-offset: 2px; padding: 2px 0; }
.checklist__link:hover, .checklist__link:focus-visible { color: var(--brand-primary); }

/* "Something in here isn't done" badge, on card headers and on the activity rows themselves.
   Advisory: it points, it never blocks. Reads as a .pill--warning with a leading mark, and the
   wording always names what is missing so the colour is never the only signal. */
.attention { display: inline-flex; align-items: center; gap: var(--sp-2); white-space: nowrap; }
.attention__mark { font-weight: 800; color: var(--warning); }
.activity-card__flag { margin-top: var(--sp-1); white-space: normal; }

/* Advisory nudge under the Follow-up fields (shown only while neither a date nor "No follow-up" is
   set). Same AA-safe recipe as .attention — full-contrast text plus a tinted leading mark, so the
   colour is never the only signal — and it only points: the server still enforces the rule at
   finalize. */
.follow-up-hint { color: var(--text); }
.follow-up-hint::before { content: "!"; font-weight: 800; color: var(--warning); margin-right: var(--sp-2); }

/* "Unsaved" marker, injected by site.js beside a dirty form's own Save button (the
   unsaved-changes guard). It sits inline next to most buttons, but the group rail's actions are
   a flex COLUMN, where an inline-block pill would otherwise stretch to the full column width. */
[data-fcn-unsaved] { align-self: start; }

/* Activity accordion: the summary row is the whole tap target. */
.section-intro { color: var(--text-muted); font-size: 14px; max-width: 66ch; margin: 0 0 var(--sp-4); }
.empty-state { color: var(--text-muted); font-size: 14px; margin: 0 0 var(--sp-3); }
.panel__head--split { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
/* The right-hand end of a split head: a count, and the action that card's contents are added with. */
.panel__head-tools { display: flex; align-items: center; gap: var(--sp-3); }
.activity-card { border: 1px solid var(--border); border-radius: var(--radius-md); margin-bottom: var(--sp-3); background: var(--surface); }
.activity-card[open] { border-color: var(--brand-primary); }
.activity-card__summary { display: flex; align-items: center; gap: var(--sp-4); padding: var(--sp-3) var(--sp-4); cursor: pointer; min-height: 60px; border-radius: var(--radius-md); list-style: none; }
.activity-card__summary:hover { background: var(--surface-2); }
/* display:flex already drops the native triangle in Chrome/Safari and list-style:none finishes the
   job in Firefox — .activity-card__toggle replaces it, and says "Open"/"Close" in words so the
   affordance never rests on a glyph alone. */
.activity-card__summary::marker { content: ""; }
.activity-card__summary::-webkit-details-marker { display: none; }
.activity-card__toggle {
    flex: 0 0 auto; display: inline-flex; align-items: center; gap: var(--sp-1);
    font-size: 13px; font-weight: 650; color: var(--text-muted);
}
.activity-card__summary:hover .activity-card__toggle { color: var(--brand-primary); }
.activity-card__chev { transition: transform .15s ease; }
.activity-card[open] .activity-card__chev { transform: rotate(180deg); }
.activity-card:not([open]) .activity-card__toggle-word--open,
.activity-card[open] .activity-card__toggle-word--closed { display: none; }
@media (prefers-reduced-motion: reduce) { .activity-card__chev { transition: none; } }
.activity-card__date { flex: 0 0 auto; font-size: 13px; font-weight: 650; color: var(--text-muted); min-width: 3.5rem; }
.activity-card__main { flex: 1; min-width: 0; }
.activity-card__name { display: block; font-weight: 650; }
.activity-card__sub { display: block; font-size: 13px; color: var(--text-muted); }
.activity-card__figure { flex: 0 0 auto; text-align: right; min-width: 3.5rem; }
.activity-card__figure-value { display: block; font-size: 20px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums lining-nums; }
.activity-card__figure-label { display: block; font-size: 11px; color: var(--text-muted); }
.activity-card__body { padding: var(--sp-4); border-top: 1px solid var(--border); background: var(--surface-2); }
.activity-card__block { margin-top: var(--sp-5); padding-top: var(--sp-4); border-top: 1px solid var(--border); }
.activity-card__block-title { font-size: 15px; font-weight: 650; margin: 0 0 var(--sp-3); }
.activity-card__foot {
    margin-top: var(--sp-4); padding-top: var(--sp-3); border-top: 1px solid var(--border);
    display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3);
}
/* Delete is pushed to the far end rather than sitting beside Save — same row, no accidental hit. */
.activity-card__foot form { margin-left: auto; }
.staff-table { background: var(--surface); }
.staff-table tbody td { vertical-align: middle; }
/* The hours total belongs in the grid it totals, not on a strip underneath it. */
.staff-table tfoot td, .staff-table tfoot th { border-top: 2px solid var(--border); font-weight: 700; }
.staff-table tfoot th { text-align: left; }
.staff-table__total-note { font-weight: 400; font-size: 13px; color: var(--text-muted); }

/* Age ranges as tap chips. They stay ordinary checkboxes — presence, not counts — so the checked
   state is carried by border weight and background, never by colour alone. */
.chip-row { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.chip-check { margin: 0; padding: 0; }
.chip-check .form-check-input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chip-check .form-check-label {
    display: inline-flex; align-items: center; min-height: 44px; padding: 0 var(--sp-4);
    border: 1px solid var(--border); border-radius: var(--radius-pill); background: var(--surface);
    font-size: 15px; cursor: pointer; user-select: none;
}
.chip-check .form-check-label:hover { background: var(--surface-3); }
.chip-check .form-check-input:checked + .form-check-label {
    border: 2px solid var(--brand-primary); background: color-mix(in srgb, var(--brand-primary) 12%, var(--surface));
    font-weight: 650; padding: 0 calc(var(--sp-4) - 1px);
}
.chip-check .form-check-input:focus-visible + .form-check-label { outline: 2px solid var(--brand-primary); outline-offset: 2px; }

/* Blood-pressure counters, kept behind their own checkbox so a non-screening activity doesn't
   carry seven empty boxes. The total taken sits last in the same row, set apart by a rule rather
   than by a line of its own — they are two different figures, but not worth a second row. */
.bp-toggle { margin-bottom: var(--sp-2); }
.bp-toggle .form-check-label { font-size: 15px; font-weight: 650; }
.bp-count { margin: var(--sp-1) 0 0; }
/* The seven boxes share the row and shrink together rather than wrapping at the first squeeze;
   inputs bottom-align so the taken box's two-line label doesn't step it out of line. */
.bp-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--sp-2); }
.bp-cell { flex: 1 1 88px; min-width: 76px; }
.bp-cell .form-label { margin-bottom: var(--sp-1); color: var(--text-muted); }
/* After .bp-cell — the taken box is one of them, but reads as the headline figure. */
.bp-taken { flex: 1 1 104px; min-width: 92px; padding-left: var(--sp-3); border-left: 1px solid var(--border); }
.bp-taken .form-label { color: var(--text); font-weight: 650; }

.totals-strip { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-5); background: var(--surface-2); border-radius: var(--radius-sm); padding: var(--sp-3) var(--sp-4); font-size: 14px; margin-bottom: var(--sp-4); }

/* "Add a …" cards, deliberately dashed so they read as an action, not a record. */
.add-card { border: 1px dashed var(--border); border-radius: var(--radius-md); padding: var(--sp-4); margin-top: var(--sp-4); }
.add-card__title { font-size: 15px; font-weight: 650; margin: 0 0 var(--sp-3); }
/* The activities card opens its add form from the panel head, so this one sits at the top and
   collapses. Closed, it is just its own summary line — hence no bottom margin on the title. */
details.add-card { margin: 0 0 var(--sp-4); }
details.add-card:not([open]) .add-card__title { margin-bottom: 0; }
summary.add-card__title { cursor: pointer; }

/* "Add one of these" inside a card, one level down from .add-card: same dashed language, so a row
   of empty inputs under a table reads as the way to add a row rather than as one of its rows. */
.add-row { border: 1px dashed var(--border); border-radius: var(--radius-md); padding: var(--sp-3) var(--sp-3) var(--sp-4); margin-top: var(--sp-3); }
.add-row__title { font-size: 14px; font-weight: 650; color: var(--text-muted); margin: 0 0 var(--sp-3); }
/* The block's own action: a two-word label on one line, whatever the column does. */
.add-row__submit { white-space: nowrap; }
/* The pill site.js injects after this Save, lifted ABOVE it and out of flow. In flow it sat under
   the button, grew the column and moved the button the moment a person was picked — the control
   walking away from the cursor about to click it. It lands in the label line the button borrows
   from its blank spacer, which is empty precisely because this column has nothing to label. */
.add-row__action { position: relative; }
/* Block, so the label's own margin-bottom actually pushes: .form-label is inline by default on a
   span, and a vertical margin on an inline box does nothing — which left Save 8px above the
   hours inputs it is supposed to line up with. */
.add-row__action > .form-label { display: block; }
.add-row__action > [data-fcn-unsaved] { position: absolute; top: 0; left: 0; margin: 0; }

/* One person control per helper: the dropdown and its "+" share a row, and whichever text box the
   choice calls for appears under them rather than beside — the row asks one question at a time. */
.person-pick { min-width: 0; }
.person-pick__row { display: flex; gap: var(--sp-2); align-items: stretch; }
.person-pick__row .form-select { min-width: 0; }
.person-pick__add { flex: none; width: 2.75rem; font-size: 20px; line-height: 1; padding: 0; }
.person-pick__extra { margin-top: var(--sp-2); }
.person-pick__extra .form-label { margin-bottom: var(--sp-1); color: var(--text-muted); }

/* "Who else helped" rows on the add form: one column header, and per-row labels that stay for
   screen readers until the columns collapse (the same treatment as the professional-time list).
   The person column is the widest: it carries a select, a button and sometimes a text box. */
.helper-list { --helper-cols: minmax(11rem, 1.8fr) 6.5rem 6.5rem 2.5rem; min-width: 0; }
.helper-list__head, .helper-list__row { display: grid; grid-template-columns: var(--helper-cols); gap: var(--sp-2); align-items: end; }
.helper-list__head { font-size: 13px; font-weight: 650; color: var(--text-muted); margin-bottom: var(--sp-1); }
/* A row is two controls tall — the identity control appears UNDER the kind picker, because the row
   asks one question at a time — so without a rule between them three rows read as one block of
   selects. Same treatment .time-list__row gets. Top-aligned, so the hours sit under their own
   column header instead of floating down beside whichever control the second question needed. */
.helper-list__row {
    align-items: start; padding-bottom: var(--sp-3); margin-bottom: var(--sp-3);
    border-bottom: 1px solid var(--border);
}
.helper-list__row:last-of-type { border-bottom: 0; }
.suggestions { margin-top: var(--sp-4); padding-top: var(--sp-3); border-top: 1px solid var(--border); }
.suggestions__label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: var(--sp-2); }
.chip-btn {
    min-height: 44px; padding: 0 var(--sp-4); border: 1px solid var(--border); border-radius: var(--radius-pill);
    background: var(--surface); color: var(--text); font-size: 14px; cursor: pointer;
}
.chip-btn:hover { background: var(--surface-3); }

/* Professional-time entries read as a table with ONE header: the column labels live in
   .time-list__head, and each row repeats them only for screen readers (.time-list__label).
   Header and rows share --time-cols, so the two grids line up without duplicated widths.
   A row is still two forms — edit + independent delete — hence the flex wrapper. */
.time-list { --time-cols: 8.5rem minmax(7rem, 1.1fr) 5.5rem minmax(8rem, 1.6fr) 5.5rem; --time-del: 2.25rem; }
.time-list__head, .time-list__row { display: flex; align-items: flex-end; gap: var(--sp-2); }
.time-list__head { padding-bottom: var(--sp-1); }
.time-list__head::after, .time-list__row > form:last-child { width: var(--time-del); flex: none; }
.time-list__head::after { content: ""; }
.time-list__row { padding: var(--sp-2) 0; border-bottom: 1px solid var(--border); }
.time-list__cells { flex: 1; margin: 0; display: grid; grid-template-columns: var(--time-cols); gap: var(--sp-2); align-items: end; }
.time-list__head .time-list__cells { font-size: 13px; font-weight: 650; color: var(--text-muted); }
.time-list__row > form:last-child { margin: 0 0 var(--sp-1); }
.time-list__label, .helper-list__label {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}
@media (max-width: 1000px) {
    /* Too narrow for columns: drop the header and give every field its own visible label back. */
    .time-list__head, .helper-list__head { display: none; }
    .time-list__cells { grid-template-columns: 1fr 1fr; }
    .helper-list__row { grid-template-columns: 1fr 1fr; margin-bottom: var(--sp-3); }
    .time-list__label, .helper-list__label {
        position: static; width: auto; height: auto; margin: 0 0 var(--sp-1);
        overflow: visible; clip-path: none;
    }
}
@media (max-width: 700px) { .time-list__cells, .helper-list__row { grid-template-columns: 1fr; } }

@media (max-width: 1100px) {
    .group-layout { grid-template-columns: 1fr; }
    .group-rail { position: static; }
}
@media (max-width: 700px) {
    .activity-card__summary { flex-wrap: wrap; gap: var(--sp-2) var(--sp-3); }
    .activity-card__main { flex: 1 0 100%; order: -1; }
}

/* ---- Checkbox tag groups (legacy multi-select checkbox lists) ------------ */
.tag-group__legend { font-size: 15px; font-weight: 650; margin-bottom: var(--sp-2); float: none; width: auto; }
.tag-group__category {
    font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
    color: var(--text-muted); font-weight: 600; margin: var(--sp-2) 0 var(--sp-1);
}
.checkbox-columns { columns: 220px 3; column-gap: var(--sp-6); }
.checkbox-columns .form-check { break-inside: avoid; }
@media (max-width: 700px) { .checkbox-columns { columns: 1; } }
/* Paired (need + resource) groups: row-major grid so cells line up across columns. */
.checkbox-grid {
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
    column-gap: var(--sp-6); row-gap: var(--sp-2); align-items: start;
}
.checkbox-grid > .form-check { margin-bottom: 0; }
.tag-group__resource { margin: 2px 0 0; min-height: 0; }
@media (max-width: 1000px) { .checkbox-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 700px) { .checkbox-grid { grid-template-columns: 1fr; } }
.tag-group__other { max-width: 480px; }

/* ---- Field-help toggletips (<help> tag helper) ---------------------------
   Shown on hover (pure CSS) or via aria-expanded, which site.js toggles on
   click/Enter and clears on Escape/focusout. .field-help--esc lets Escape
   suppress a hover-opened tip without moving the pointer (WCAG 1.4.13). */
.field-help { position: relative; display: inline-block; vertical-align: text-bottom; margin-left: var(--sp-1); }
.field-help__btn {
    width: 18px; height: 18px; padding: 0;
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--border); border-radius: 50%;
    background: transparent; color: var(--text-muted);
    font-size: 11px; font-weight: 700; line-height: 1; cursor: pointer;
}
.field-help__btn:hover, .field-help__btn:focus-visible, .field-help__btn[aria-expanded="true"] {
    color: var(--text); border-color: var(--text-muted);
}
.field-help__tip {
    display: none; position: absolute; z-index: 40;
    top: calc(100% + 6px); left: 50%; transform: translateX(-50%);
    width: max-content; max-width: min(300px, calc(100vw - 2rem));
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    box-shadow: 0 4px 14px rgba(0, 0, 0, .18);
    padding: var(--sp-2) var(--sp-3);
    font-size: 13px; font-weight: 400; line-height: 1.45;
    text-align: left; text-transform: none; letter-spacing: normal; white-space: normal;
}
.field-help__btn[aria-expanded="true"] + .field-help__tip,
.field-help:hover:not(.field-help--esc) .field-help__tip { display: block; }

/* ---- Combobox (<combobox> tag helper) -----------------------------------
   Free-text input + chevron + suggestion list, replacing the browser-drawn
   <datalist> popup. Behaviour is delegated in site.js; state is aria-expanded /
   aria-activedescendant on the input. Styled from the tokens (NOT Bootstrap's
   .dropdown-menu, whose colours key off [data-bs-theme], which the app never
   sets) so the list follows the OS colour scheme like .field-help__tip does.
   is-current = the option equal to the typed value; aria-selected = the one
   the arrow keys have landed on. */
.fcn-combobox { position: relative; display: block; }
.fcn-combobox__input { padding-right: 2.25rem; }
/* The chevron sits ON the input, so it takes Bootstrap's input-side colours (like .form-select's
   arrow) rather than the scheme tokens — .form-control stays light in the dark scheme. */
.fcn-combobox__toggle {
    position: absolute; top: 0; right: 0; bottom: 0; width: 2.25rem; padding: 0;
    display: flex; align-items: center; justify-content: center;
    border: 0; background: transparent; color: var(--bs-secondary-color, #6c757d); cursor: pointer;
    border-radius: 0 var(--bs-border-radius, .375rem) var(--bs-border-radius, .375rem) 0;
}
.fcn-combobox__toggle:hover, .fcn-combobox__toggle[aria-expanded="true"] { color: var(--bs-body-color, #212529); }
.fcn-combobox__chevron { transition: transform .12s ease-out; }
.fcn-combobox__toggle[aria-expanded="true"] .fcn-combobox__chevron { transform: rotate(180deg); }
/* No option store bound (the group form before a category is chosen) → nothing to open. */
.fcn-combobox__input:not([data-fcn-options]) ~ .fcn-combobox__toggle { display: none; }
.fcn-combobox__input:not([data-fcn-options]) { padding-right: .75rem; }
.fcn-combobox__list {
    position: absolute; z-index: 40; left: 0; right: 0; top: calc(100% + 2px);
    margin: 0; padding: var(--sp-1) 0; list-style: none;
    max-height: 16rem; overflow-y: auto; overscroll-behavior: contain;
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border); border-radius: var(--radius-md);
    box-shadow: 0 6px 20px rgba(0, 0, 0, .16);
    font-size: 1rem; line-height: 1.4; text-align: left; white-space: normal;
}
.fcn-combobox__list[hidden] { display: none; }
.fcn-combobox__option { padding: .375rem .75rem; cursor: pointer; }
.fcn-combobox__option:hover { background: var(--surface-2); }
.fcn-combobox__option.is-current { font-weight: 600; }
.fcn-combobox__option[aria-selected="true"],
.fcn-combobox__option[aria-selected="true"]:hover { background: var(--brand-primary); color: var(--brand-primary-contrast); }

/* Informational section feedback (htmx op messages) — info-tinted variant of .section-errors. */
.section-messages {
    background: color-mix(in srgb, var(--info) 12%, var(--surface));
    border-color: var(--info);
}

/* ---- Program-module accordions (legacy jQuery-UI accordion echo) --------- */
.module-details { border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: var(--sp-3); }
.module-details > summary { cursor: pointer; padding: var(--sp-3) var(--sp-4); font-weight: 650; }
.module-details[open] > summary { border-bottom: 1px solid var(--border); }
.module-details .module-details__body { padding: var(--sp-4); }

/* ---- Patient-context strip on the encounter form ------------------------- */
.patient-context {
    display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-6);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
    padding: var(--sp-3) var(--sp-4); margin-bottom: var(--sp-4); font-size: 14px;
}
.patient-context dt { color: var(--text-muted); font-size: 12px; margin: 0; font-weight: 500; }
.patient-context dd { margin: 0; font-weight: 600; }

/* ---- Nesting for diagnosis → intervention → outcome --------------------- */
.nest-1 { border-left: 3px solid var(--brand-primary); padding-left: var(--sp-3); margin-bottom: var(--sp-3); }
.nest-2 { border-left: 3px solid var(--brand-secondary); padding-left: var(--sp-3); margin: var(--sp-2) 0 var(--sp-2) var(--sp-4); }
.nest-3 { border-left: 3px solid var(--border); padding-left: var(--sp-3); margin: var(--sp-2) 0 var(--sp-2) var(--sp-6); }
.delta-badge { font-weight: 700; }
.delta-badge--up { color: var(--success); }
.delta-badge--down { color: var(--danger); }

/* ---- Data table --------------------------------------------------------- */
.data-table thead th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.data-table tbody td { font-size: 15px; }

/* Shared-with disclosure in the patient list: the badge is the summary; the
   nurse names reveal on click (names already loaded, so expansion is instant). */
.share-cell summary { cursor: pointer; display: inline-flex; align-items: center; gap: .3rem; }
.share-cell__names { list-style: none; margin: .35rem 0 0; padding: 0; font-size: 13px; color: var(--text-muted); }
.share-cell__names li { white-space: nowrap; }

/* ---- Report tables ------------------------------------------------------- */
/* Each report section renders as its own table, so a wide label in one section
   would otherwise push its Count/% columns to a different x-position than the
   next section's. Pinning numeric columns (via the <colgroup> the shared
   _ReportResult partial emits) to one width keeps them aligned down the page. */
.report-table .report-col--num { width: 7.5rem; }
.report-table .num { white-space: nowrap; }
.report-notes { border-top: 1px solid var(--border); }

/* Multi-section reports pack their narrow sections (one label + up to two numeric columns)
   two per row, in reading order; wide sections and the odd narrow section left at the end of a
   run span both columns (the partial decides which is which — see _ReportResult.cshtml). The
   report body is a size container so the grid drops to one column when the body itself is
   narrow (sidebar open on a small screen), independent of the viewport; a printed page keeps
   two-up regardless (see the print stylesheet, which tightens the table sizing to fit). */
.report-body { container-type: inline-size; }
.report-sections--two-up {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--sp-4); padding: var(--sp-4); align-items: start;
}
.report-sections--two-up .report-section--full { grid-column: 1 / -1; }
/* Each packed section is its own bordered block, so neighbours (side by side or stacked) never
   bleed into one another; the block edge replaces the table's last row rule. */
.report-sections--two-up .report-section {
    border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden;
}
.report-sections--two-up .report-section .report-table > tbody > tr:last-child > td { border-bottom: 0; }
/* Half-width sections have less room, so their numeric columns pin narrower (they still align
   with the other half-width sections in the same column; a wider value simply widens the cell). */
.report-sections--two-up .report-section--half .report-col--num { width: 6.5rem; }
@container (max-width: 719px) {
    .report-sections--two-up { grid-template-columns: minmax(0, 1fr); }
    .report-sections--two-up .report-section--half .report-col--num { width: 7.5rem; }
}

/* ---- Help center --------------------------------------------------------- */
.help-categories { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: var(--sp-5); align-items: start; }
.help-category { margin-bottom: 0; }
.help-category__title { font-size: 16px; font-weight: 650; margin: 0; }
.help-article-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--sp-4); }
.help-article-list a { font-weight: 600; }
.help-article-list__summary { color: var(--text-muted); font-size: 14px; margin: var(--sp-1) 0 0; }

.help-breadcrumb { display: flex; gap: var(--sp-2); align-items: center; font-size: 14px; color: var(--text-muted); margin-bottom: var(--sp-4); }
.help-layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: var(--sp-5); align-items: start; }
@media (max-width: 900px) { .help-layout { grid-template-columns: 1fr; } }
.help-aside__list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--sp-3); font-size: 14px; }
.help-aside__list [aria-current="page"] { font-weight: 650; }

/* Rendered markdown body: readable measure + heading scale under the page title. */
.help-article { max-width: 72ch; line-height: 1.6; margin-top: var(--sp-4); }
.help-article h2 { font-size: 19px; font-weight: 650; margin: var(--sp-6) 0 var(--sp-3); }
.help-article h2:first-child { margin-top: 0; }
.help-article h3 { font-size: 17px; font-weight: 650; margin: var(--sp-5) 0 var(--sp-2); }
.help-article p, .help-article ul, .help-article ol { margin: 0 0 var(--sp-4); }
.help-article li { margin-bottom: var(--sp-2); }
.help-article table { width: 100%; border-collapse: collapse; margin-bottom: var(--sp-4); font-size: 15px; }
.help-article th, .help-article td { border: 1px solid var(--border); padding: var(--sp-2) var(--sp-3); text-align: left; }
.help-article blockquote {
    border-left: 3px solid var(--brand-primary); margin: 0 0 var(--sp-4);
    padding: var(--sp-2) var(--sp-4); background: var(--surface-2);
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
}
.help-article code { background: var(--surface-3); padding: 1px 5px; border-radius: var(--radius-sm); font-size: 14px; }

/* Contextual "?" link in a page header, jumping to that screen's help article. */
.help-page-link {
    display: inline-flex; align-items: center; justify-content: center;
    width: 24px; height: 24px; margin-left: var(--sp-2); vertical-align: text-bottom;
    border: 1px solid var(--border); border-radius: 50%; background: none; cursor: pointer;
    color: var(--text-muted); font-size: 13px; font-weight: 700; text-decoration: none; line-height: 1;
}
.help-page-link:hover { color: var(--brand-primary); border-color: var(--brand-primary); }

/* ---- Responsive: mobile nav (drawer + hamburger) ----------------------- */
@media (max-width: 900px) {
    /* minmax(0,1fr) — not plain 1fr — so the nowrap brand name can't blow the
       track past the viewport (1fr's auto minimum = min-content otherwise). */
    .app-shell { grid-template-columns: minmax(0, 1fr); }

    /* The sidebar collapses to a single-line app header: brand on the left,
       hamburger on the right. The nav itself becomes a drop-down drawer. */
    .app-sidebar {
        flex-direction: row; align-items: center;
        border-right: none; border-bottom: 1px solid var(--border);
        padding: var(--sp-2) var(--sp-4);
        position: sticky; top: 0; z-index: 30; background: var(--surface);
    }
    .app-brand { flex: 1; min-width: 0; padding: 0; }
    .app-brand__name {
        flex: 1; min-width: 0;   /* allow the flex item to shrink so ellipsis engages */
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    .app-nav-toggle { display: inline-flex; align-items: center; justify-content: center; }

    /* Drawer: anchored under the header, hidden until the shell is .nav-open. */
    .app-nav {
        display: none;
        position: absolute; top: 100%; left: 0; right: 0;
        flex-direction: column; gap: 2px;
        background: var(--surface); border-bottom: 1px solid var(--border);
        box-shadow: 0 10px 24px rgba(0, 0, 0, .14);
        padding: var(--sp-3);
        max-height: calc(100vh - var(--topbar-h)); overflow-y: auto;
    }
    .app-shell.nav-open .app-nav { display: flex; }
    .app-nav__link { font-size: 16px; padding: var(--sp-3); }
    .app-sidebar__footer { display: none; }

    /* Backdrop dims the page behind the open drawer. */
    .app-shell.nav-open .app-nav-backdrop {
        display: block; position: fixed; inset: 0;
        background: rgba(0, 0, 0, .35); z-index: 25;
    }

    /* Top bar: let the context / user / sign-out cluster wrap tidily. */
    .app-topbar {
        height: auto; min-height: 0;
        padding: var(--sp-2) var(--sp-4); flex-wrap: wrap;
    }
    .app-topbar__right {
        flex-wrap: wrap; gap: var(--sp-2) var(--sp-3); justify-content: flex-end;
        min-width: 0;
    }
    .context-badge {
        max-width: 60vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    }
}

@media (max-width: 560px) {
    /* The avatar carries identity on tiny screens; the name label is redundant. */
    .app-user__name { display: none; }
}

/* Accessible focus ring on interactive elements. */
a:focus-visible, button:focus-visible, input:focus-visible, .dropdown-item:focus-visible {
    outline: 2px solid var(--brand-primary); outline-offset: 2px;
}

/* ---- Skip-to-content link (keyboard/screen-reader) ---------------------- */
.skip-link {
    position: absolute; left: -999px; top: 0; z-index: 1000;
    background: var(--brand-primary); color: var(--brand-primary-contrast);
    padding: var(--sp-2) var(--sp-4); border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus { left: 0; }

/* ---- Impact reports (dashboard-style) ----------------------------------- */
/* Bootstrap's `.card { color: var(--bs-body-color) }` pins everything inside the results card to
   its LIGHT body color — Bootstrap keys dark mode off [data-bs-theme], not prefers-color-scheme,
   so the app's dark tokens never reach here and the dashboards rendered near-black-on-black.
   Re-asserting the app's text token on the dashboard root fixes both impact reports; descendants
   with an explicit muted/semantic color keep theirs. */
.impact { padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-4); color: var(--text); }
.impact-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--sp-4); }
/* "Copy image" (D8) is a compact clipboard icon in the top-right corner; the title (or the
   reach-head's right-hand total) gets a small right padding so nothing slides under it. Injected by
   impact-copy.js, so it only exists when the feature is live, and it is dropped from print. */
.impact-card.has-copy { position: relative; }
.impact-card.has-copy > .impact-card__title,
.impact-card.has-copy > .impact-reach-head { padding-right: 2.25rem; }
.impact-copy {
    position: absolute; top: var(--sp-3); right: var(--sp-3); z-index: 2;
    display: inline-flex; align-items: center; justify-content: center;
    width: 1.9rem; height: 1.9rem; padding: 0;
    color: var(--text-muted); background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer;
    transition: color .12s, border-color .12s, background .12s;
}
.impact-copy:hover { color: var(--text); background: var(--surface-2); border-color: var(--text-muted); }
.impact-copy:focus-visible { outline: 2px solid var(--brand-500, var(--text)); outline-offset: 1px; }
.impact-copy:disabled, .impact-copy.is-busy { opacity: .55; cursor: default; }
.impact-copy.is-copied { color: var(--success); border-color: currentColor; }
.impact-copy svg { width: 1rem; height: 1rem; fill: currentColor; }
@media print { .impact-copy { display: none !important; } }
.impact-card__title { font-size: 1rem; font-weight: 600; margin: 0 0 2px; }
.impact-card__cap { font-size: .85rem; color: var(--text-muted); margin: 0 0 var(--sp-3); }
.impact-card__cap--foot { margin: var(--sp-3) 0 0; font-size: .78rem; }
.impact-empty { color: var(--text-muted); font-size: .9rem; padding: var(--sp-3) 0; }
.impact-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-4); }
@media (max-width: 720px) { .impact-grid2 { grid-template-columns: 1fr; } }

/* KPI row */
.impact-kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--sp-3); }
@media (max-width: 900px) { .impact-kpis { grid-template-columns: repeat(2, 1fr); } }
.impact-kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--sp-3) var(--sp-4); position: relative; overflow: hidden; }
.impact-kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--brand-primary); opacity: .8; }
.impact-kpi__label { font-size: .78rem; color: var(--text-muted); font-weight: 500; }
.impact-kpi__value { font-size: 1.4rem; font-weight: 650; letter-spacing: -.02em; margin-top: var(--sp-1); font-variant-numeric: tabular-nums; white-space: nowrap; }
.impact-kpi__sub { font-size: .74rem; color: var(--text-muted); margin-top: 2px; }

/* horizontal stacked bars (reach + split) */
.impact-bar { display: flex; height: 26px; gap: 2px; }
.impact-bar--tall { height: 30px; }
.impact-bar--empty { background: var(--surface-3); border-radius: var(--radius-sm); }
.impact-seg { display: flex; align-items: center; padding: 0 var(--sp-2); color: #fff; font-size: .8rem; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; border-radius: 2px; min-width: 0; overflow: hidden; }
/* Stream identity is color only; shape and label alignment come from POSITION in the bar, so the
   same segment class works whether it sits left (group dashboard) or right (organizational one). */
.impact-seg--ind { background: var(--impact-ind); }
.impact-seg--fam { background: var(--impact-ind-soft); color: var(--text); justify-content: center; }
.impact-seg--grp { background: var(--impact-grp); }
.impact-seg--prof { background: var(--impact-prof); }
.impact-bar > .impact-seg:first-child { border-radius: var(--radius-sm) 2px 2px var(--radius-sm); justify-content: flex-start; }
.impact-bar > .impact-seg:last-child { border-radius: 2px var(--radius-sm) var(--radius-sm) 2px; justify-content: flex-end; }
.impact-bar > .impact-seg:only-child { border-radius: var(--radius-sm); }

.impact-splits { display: flex; flex-direction: column; gap: var(--sp-3); }
.impact-split { min-width: 0; }
.impact-split__top { display: flex; justify-content: space-between; align-items: baseline; gap: var(--sp-2); margin-bottom: var(--sp-1); }
.impact-split__m { font-size: .85rem; color: var(--text-muted); }
.impact-split__t { font-size: .95rem; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* legend */
.impact-legend { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-4); margin-top: var(--sp-3); }
.impact-legend span { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--text-muted); }
.impact-legend b { color: var(--text); font-variant-numeric: tabular-nums; }
.impact-swatch { width: 11px; height: 11px; border-radius: 3px; display: inline-block; flex: 0 0 auto; }
.impact-swatch--ind { background: var(--impact-ind); }
.impact-swatch--fam { background: var(--impact-ind-soft); }
.impact-swatch--grp { background: var(--impact-grp); }
.impact-swatch--prof { background: var(--impact-prof); }

/* community reach header */
.impact-reach-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--sp-4); margin-bottom: var(--sp-3); }
.impact-reach-total { text-align: right; white-space: nowrap; }
.impact-reach-total__big { font-size: 1.9rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.impact-reach-total__lbl { display: block; font-size: .74rem; color: var(--text-muted); margin-top: -2px; }

/* trend chart */
.impact-chart { display: block; width: 100%; height: auto; }
.impact-grid { stroke: var(--border); stroke-width: 1; }
.impact-axis { stroke: var(--text-muted); stroke-width: 1; opacity: .6; }
.impact-tick { fill: var(--text-muted); font-size: 11px; font-family: var(--font-stack); font-variant-numeric: tabular-nums; }
.impact-xaxis { display: flex; padding: 0 8px; margin-top: 2px; }
.impact-xaxis > span { flex: 1 1 0; text-align: center; font-size: .72rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.impact-area--ind { fill: var(--impact-ind); fill-opacity: .9; }
.impact-area--grp { fill: var(--impact-grp); fill-opacity: .9; }
.impact-area--prof { fill: var(--impact-prof); fill-opacity: .9; }
.impact-seam { fill: none; stroke: var(--surface); stroke-width: 2; }
.impact-topline { fill: none; stroke: var(--impact-grp); stroke-width: 2; }
.impact-topline--prof { stroke: var(--impact-prof); }
.impact-endpoint { fill: var(--impact-grp); stroke: var(--surface); stroke-width: 1.5; }
.impact-endpoint--prof { fill: var(--impact-prof); }

/* SDOH compact */
.impact-sdoh-head { display: flex; align-items: baseline; gap: var(--sp-2); }
.impact-sdoh-pct { font-size: 2.4rem; font-weight: 700; letter-spacing: -.03em; line-height: 1; color: var(--success); font-variant-numeric: tabular-nums; }
.impact-sdoh-lbl { font-size: .85rem; color: var(--text-muted); }
.impact-meter { height: 8px; background: var(--surface-3); border-radius: var(--radius-sm); overflow: hidden; margin: var(--sp-3) 0 var(--sp-4); }
.impact-meter > span { display: block; height: 100%; background: var(--success); border-radius: var(--radius-sm); }
.impact-sdoh-break { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-2) var(--sp-5); }
.impact-sdoh-break > div { display: flex; justify-content: space-between; align-items: baseline; gap: var(--sp-3); border-bottom: 1px solid var(--border); padding-bottom: var(--sp-1); }
.impact-sdoh-break dt { font-size: .82rem; color: var(--text-muted); margin: 0; }
.impact-sdoh-break dd { margin: 0; font-size: .92rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.impact-good { color: var(--success); }

/* cost-by-type bars */
.impact-cbt { display: grid; gap: var(--sp-2); }
.impact-cbt__row { display: grid; grid-template-columns: 140px 1fr auto; align-items: center; gap: var(--sp-3); }
.impact-cbt__name { font-size: .82rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.impact-cbt__track { height: 12px; background: var(--surface-3); border-radius: var(--radius-sm); overflow: hidden; }
.impact-cbt__fill { display: block; height: 100%; background: var(--impact-ind); border-radius: var(--radius-sm); }
.impact-cbt__fill--grp { background: var(--impact-grp); }
.impact-cbt__fill--prof { background: var(--impact-prof); }
.impact-cbt__amt { font-size: .82rem; font-weight: 600; font-variant-numeric: tabular-nums; }

.impact-notes { font-size: .78rem; color: var(--text-muted); border-top: 1px solid var(--border); padding-top: var(--sp-3); }
.impact-notes p { margin: 0 0 var(--sp-1); }

/* ---- Group Activity Impact report — additions on the same vocabulary ---------------------- */

/* Six headline metrics rather than five; degrades 6 → 3 → 2 across the breakpoints. */
.impact-kpis--6 { grid-template-columns: repeat(6, 1fr); }
@media (max-width: 1200px) { .impact-kpis--6 { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 900px) { .impact-kpis--6 { grid-template-columns: repeat(2, 1fr); } }

/* A second, independent cut of the same measure inside a card (direct vs indirect hours). The
   rule separates it from the stacked stream bars above so the two aren't read as one series. */
.impact-subsplit { margin-top: var(--sp-4); border-top: 1px solid var(--border); padding-top: var(--sp-3); }
.impact-subsplit .impact-meter { margin: var(--sp-2) 0 0; }

/* Dashboard tables — the report tables' data density in the impact cards' visual language. */
.impact-tbl { width: 100%; border-collapse: collapse; font-size: .85rem; }
.impact-tbl caption { caption-side: top; }
.impact-tbl th, .impact-tbl td { padding: var(--sp-2) var(--sp-2); border-bottom: 1px solid var(--border); text-align: left; }
.impact-tbl thead th { font-size: .74rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
.impact-tbl tbody th { font-weight: 500; }
.impact-tbl td.num, .impact-tbl th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.impact-tbl tbody tr:last-child th, .impact-tbl tbody tr:last-child td { border-bottom: 0; }
.impact-tbl tfoot th, .impact-tbl tfoot td { border-top: 2px solid var(--border); border-bottom: 0; font-weight: 650; font-variant-numeric: tabular-nums; }
.impact-tbl tfoot td { text-align: right; }
/* Long organization names wrap instead of forcing the table wider than its card. */
.impact-tbl--wide tbody th { min-width: 12rem; font-weight: 500; }
.impact-tbl-scroll { overflow-x: auto; }

/* Value column that carries a share bar beside its amount (a wrapper inside the cell, so the
   <td> keeps its table-cell layout and the column still sizes with the rest). */
.impact-tbl__bar { display: flex; align-items: center; gap: var(--sp-2); justify-content: flex-end; }
.impact-tbl__bar .impact-cbt__track { flex: 1 1 auto; min-width: 32px; max-width: 110px; height: 10px; }
.impact-tbl__bar-amt { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }

/* ---- Print stylesheet --------------------------------------------------- */
@media print {
    /* Screen chrome. `.page-header--no-print` marks a page heading that is navigation, not content
       (the Reports page: the printed report carries its own title and criteria); the "?" help icons
       are meaningless on paper everywhere. */
    .app-sidebar, .app-topbar, .encounter-actions, .rail, .reports-filterbar,
    .skip-link, form .btn, .btn, .reports-sheets-hint, .report-jump,
    .page-header--no-print, .help-page-link,
    .fcn-combobox__toggle, .fcn-combobox__list { display: none !important; }
    .app-shell { grid-template-columns: 1fr; }
    .encounter-layout { grid-template-columns: 1fr; }
    .app-content { padding: 0; }
    body { background: #fff; color: #000; font-size: 12px; }
    .card, .panel { border: 1px solid #999; box-shadow: none; break-inside: avoid; }
    /* A report/encounter body can span several pages. `break-inside: avoid` on its
       outer card makes the browser shove the whole card to the next page when it
       won't fit under the header — leaving a blank first page. Let these wrappers
       break across pages (nested impact cards below still stay whole). */
    .reports-results > .card, .reports-results > .panel { break-inside: auto; }
    a { text-decoration: none; color: #000; }
    @page { margin: 1.5cm; }
    /* Impact dashboard: keep each card/chart whole on a page; force color fills to print. */
    .impact-card, .impact-kpi { break-inside: avoid; }
    .impact-seg, .impact-area, .impact-topline, .impact-endpoint, .impact-meter > span,
    .impact-cbt__fill, .impact-swatch { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .impact-grid2 { grid-template-columns: 1fr 1fr; }
    /* Six KPIs won't fit a printed row; a long organization table must paginate, not clip. */
    .impact-kpis--6 { grid-template-columns: repeat(3, 1fr); }
    .impact-tbl-scroll { overflow-x: visible; }
    .impact-tbl { font-size: 10px; }
    .impact-tbl thead { display: table-header-group; }
    .impact-tbl tr { break-inside: avoid; }
    /* Multi-section reports: keep the two-up packing on paper (the screen-size container query
       above must not collapse it — a page is narrower than a desktop panel but wide enough once
       the type is sized for print), size the tables for the page, keep each title with its
       table, and repeat headers when a long section runs over. */
    .report-sections--two-up { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); padding: var(--sp-3); }
    .report-sections--two-up .report-section { border-color: #999; }
    .report-section-title { break-after: avoid; font-size: 11px; padding: 4px 6px; border-bottom-color: #999; }
    .report-table thead th { font-size: 9px; }
    .report-table tbody td { font-size: 11px; padding: 3px 6px; }
    .report-table .report-col--num,
    .report-sections--two-up .report-section--half .report-col--num { width: 5rem; }
    .report-table thead { display: table-header-group; }
    .report-table tr { break-inside: avoid; }
}

/* ---- Auth shell (login / forced password change) ---------------------- */
.auth-page { background: var(--surface-2); }
.auth-shell {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    padding: var(--sp-5);
}
.auth-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--sp-6) var(--sp-6);
    width: 100%; max-width: 420px;
}
.auth-card__brand {
    font-size: 28px; font-weight: 700; margin: 0;
    color: var(--brand-primary);
}
.auth-card__tagline { color: var(--text-muted); font-size: 14px; margin: var(--sp-1) 0 var(--sp-5); }
.auth-card__title { font-size: 20px; font-weight: 650; margin: 0 0 var(--sp-4); }
.auth-card__links { font-size: 14px; }

/* Show/hide password toggle: keep the eye button visually aligned with the input height. */
.password-toggle { display: inline-flex; align-items: center; justify-content: center; }

/* "Explain this report" glossary (Reports page modal): term/meaning pairs, compact. */
.report-glossary__list { margin: 0; }
.report-glossary__list dt { font-weight: 600; margin-top: .5rem; }
.report-glossary__list dd { margin: 0 0 .25rem 0; }

/* ---- What's New (release notes) ---------------------------------------- */
/* Filter chips are LINKS (each filter is its own URL, so a filtered view is shareable and the
   back button works). Sized to the 44px touch target like .chip-btn. */
.whatsnew-filters { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.filter-chip {
    display: inline-flex; align-items: center; gap: var(--sp-2);
    min-height: 44px; padding: 0 var(--sp-4);
    border: 1px solid var(--border); border-radius: var(--radius-pill);
    background: var(--surface); color: var(--text);
    font-size: 14px; text-decoration: none;
}
.filter-chip:hover { background: var(--surface-3); color: var(--text); }
.filter-chip--active {
    background: color-mix(in srgb, var(--brand-primary) 14%, var(--surface));
    border-color: var(--brand-primary); color: var(--brand-primary); font-weight: 600;
}
.filter-chip__count { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.filter-chip--active .filter-chip__count { color: inherit; }

.whatsnew-timeline { display: flex; flex-direction: column; gap: var(--sp-4); }
.whatsnew-release__head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-3); }
.whatsnew-release__title { font-size: 18px; font-weight: 650; margin: 0; }
.whatsnew-release__date { font-size: 13px; color: var(--text-muted); margin: var(--sp-1) 0 0; }

.whatsnew-changes { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-5); }
.whatsnew-change__tags { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-bottom: var(--sp-2); }
.whatsnew-change__title { font-size: 16px; font-weight: 650; margin: 0 0 var(--sp-1); }
.whatsnew-change__detail { margin: 0; color: var(--text); max-width: 72ch; }
.whatsnew-change__help { margin: var(--sp-2) 0 0; font-size: 14px; }

/* Kind pills carry the same tinted-bg + full-contrast text as .pill--warning so both schemes stay AA. */
.pill--new, .pill--kind-new {
    background: color-mix(in srgb, var(--success) 18%, var(--surface));
    border: 1px solid var(--success); color: var(--text);
}
.pill--kind-improved {
    background: color-mix(in srgb, var(--brand-primary) 14%, var(--surface));
    border: 1px solid var(--brand-primary); color: var(--text);
}
.pill--kind-changed, .pill--kind-renamed {
    background: var(--surface-3); border: 1px solid var(--border); color: var(--text);
}
/* Topic pill doubles as the filter link for that topic. */
.pill--topic { text-decoration: none; border: 1px solid var(--border); color: var(--text-muted); font-weight: 500; }
.pill--topic:hover { background: var(--surface-3); color: var(--text); }

/* Sidebar unread badge. */
.app-nav__badge {
    margin-left: auto; font-size: 11px; font-weight: 700; letter-spacing: .04em;
    padding: 1px var(--sp-2); border-radius: var(--radius-pill);
    background: var(--brand-primary); color: var(--brand-primary-contrast);
}

@media print {
    .whatsnew-filters { display: none; }
}

/* Client notes history (client page panel + the printable NotesHistory page). On screen the panel
   scrolls inside itself so a long history doesn't bury the panels below it; on paper it unrolls. */
.notes-history { max-height: 36rem; overflow-y: auto; }
.notes-entry + .notes-entry { margin-top: var(--sp-4); padding-top: var(--sp-4); border-top: 1px solid var(--border); }
.notes-entry__title { font-size: 1rem; font-weight: 600; display: flex; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-2); }
.notes-entry__body { grid-template-columns: 8rem 1fr; }
.notes-entry__body dd { white-space: pre-wrap; }

@media print {
    .notes-history { max-height: none; overflow: visible; }
    .notes-history--print { break-inside: auto; }
    .notes-entry { break-inside: avoid; }
}
