/*
 * N3i CRM styles.
 *
 *   1. Fonts, reset and design tokens (light, then dark)
 *   2. Base elements
 *   3. App shell: sidebar, top bar, menus, search, page header
 *   4. Components: buttons, badges and pills, cards, grids, tiles, tables, forms, filters, tabs, alerts,
 *      empty states, dialogs, detail lists, charts, date bands
 *   5. Pages: login, dashboard, customer record, tasks, sites map, admin
 *   6. Utilities (last, so they win)
 *
 * Dark theme: <html data-theme="dark"> is set before first paint from the user's choice (top bar toggle), else the OS
 * setting. Most colours are tokens that the dark block redefines. The few rules that change for dark are wrapped in
 * :where(:root[data-theme="dark"]) { … } beside the rule they change, which keeps them at the rule's own specificity.
 */

/* ── 1. Fonts (vendored from Google Fonts, latin subset, variable weight) ── */
@font-face {
    font-family: 'Sora';
    font-style: normal;
    font-weight: 100 800;
    font-display: swap;
    src: url("../fonts/sora-latin-0lDiYxg.woff2") format('woff2');
}
@font-face {
    font-family: 'Manrope';
    font-style: normal;
    font-weight: 200 800;
    font-display: swap;
    src: url("../fonts/manrope-latin-aA_waSK.woff2") format('woff2');
}
@font-face {
    font-family: 'JetBrains Mono';
    font-style: normal;
    font-weight: 100 800;
    font-display: swap;
    src: url("../fonts/jetbrains-mono-latin-AcnlIJe.woff2") format('woff2');
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    color-scheme: light;

    /* Brand palette */
    --n3i-light-blue-50:  #e7f4fb;
    --n3i-light-blue-100: #c0e2f3;
    --n3i-light-blue-200: #94cee9;
    --n3i-light-blue-300: #5cb4dc;
    --n3i-light-blue-600: #155d7a;
    --n3i-light-blue-700: #0d3e51;
    --n3i-dark-blue-100:  #c0bee0;
    --n3i-dark-blue-200:  #8e8ec8;
    --n3i-dark-blue-500:  #2c2a86;
    --n3i-dark-blue-600:  #211f66;
    --n3i-dark-blue-700:  #161547;
    --n3i-dark-blue-800:  #0b0a28;
    --n3i-orange:         #f6891f;
    --n3i-ink-0:   #ffffff;
    --n3i-ink-25:  #f9f9f9;
    --n3i-ink-50:  #f1f0f1;
    --n3i-ink-100: #e2e1e3;
    --n3i-ink-200: #c5c3c6;
    --n3i-ink-400: #6a696d;
    --n3i-ink-500: #4e4d50;
    --n3i-ink-600: #313032;

    /* Surfaces, text and lines */
    --bg-page:      var(--n3i-ink-25);
    --bg-surface:   var(--n3i-ink-0);
    --bg-surface-2: var(--n3i-ink-50);
    --bg-sidebar:   var(--n3i-dark-blue-700);  /* navy in both themes */
    --fg-1: var(--n3i-ink-600);
    --fg-2: var(--n3i-ink-500);
    --fg-3: var(--n3i-ink-400);
    --line-1: var(--n3i-ink-100);
    --line-2: var(--n3i-ink-200);

    /* Primary blue. light-blue-500 (#1d7ca3) is only 4.1:1 on the grey surfaces, so text and the primary button use
       --primary-text (4.85:1 on --bg-surface-2, 4.9:1 on --primary-soft, white on it 5.5:1). */
    --primary:       #1a7097;  /* fill of primary buttons, the active tab and ticked boxes, under white text */
    --primary-hover: var(--n3i-light-blue-600);
    --primary-press: var(--n3i-light-blue-700);
    --primary-soft:  var(--n3i-light-blue-50);
    --primary-line:  var(--n3i-light-blue-100);
    --primary-text:  #1a7097;
    --link:       var(--primary-text);
    --link-hover: var(--n3i-light-blue-600);

    /* Status: -soft backgrounds, -line borders, -ink text (at least 4.5:1 on -soft and on white) */
    --success-soft: #eef6dc; --success-line: #d6ebb0; --success-ink: #4d6f1f;
    --warning-soft: #ffeedd; --warning-line: #ffd9b5; --warning-ink: #9a5105;
    --danger-soft:  #fde0dd; --danger-line:  #fab8b1; --danger-ink:  #b81b10;

    /* Text colours for figures and labels: at least 4.5:1 on white and on the matching --tint. The dark theme swaps in
       lighter ones. Keep bright brand colours for fills, bars and large numbers only. */
    --tx-green: #15803d; --tx-amber: #b45309; --tx-red: #b91c1c; --tx-blue: #0057a8; --tx-purple: #7c3aed;
    --tx-pink: #be185d; --tx-cyan: #0e7490; --tx-teal: #047857; --tx-orange: #c2410c; --tx-grey: #4b5563;
    --tx-turquoise: #017771; --tx-indigo: #2e3192;
    /* Pale backgrounds for icon squares and coloured pills (.tone-*) */
    --tint-green: #dcfce7; --tint-amber: #fef3c7; --tint-red: #fee2e2; --tint-blue: #e8f1fb; --tint-purple: #ede9fe;
    --tint-pink: #fce7f3; --tint-teal: #ccfbf1; --tint-orange: #fff7ed; --tint-grey: #f3f4f6;
    --tint-turquoise: #d6f3f1; --tint-indigo: #eef0fc;

    /* The customer list's left bar: the customer status, or grey for a closed or merged organisation */
    --customer-status-active: var(--tx-green);
    --customer-status-prospect: var(--primary);
    --customer-status-churned: var(--tx-red);
    --customer-status-closed: var(--tx-grey);

    /* Focus indicator: a 2px outline at least 3:1 against every surface it can sit on (7.3:1 on white) */
    --focus: var(--n3i-light-blue-600);
    /* Borders that identify a form control (WCAG 1.4.11 needs 3:1; --line-2 is 1.75:1) */
    --input-border: #8a898e;

    --font-display: 'Sora', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-sans:    'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-mono:    'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

    --radius-xs: 4px; --radius-sm: 8px; --radius-md: 12px; --radius-lg: 16px; --radius-pill: 999px;
    --shadow-xs: 0 1px 2px rgba(44, 42, 134, 0.06);
    --shadow-md: 0 6px 16px rgba(44, 42, 134, 0.09), 0 2px 4px rgba(44, 42, 134, 0.05);
    --shadow-xl: 0 28px 64px rgba(44, 42, 134, 0.16), 0 8px 20px rgba(44, 42, 134, 0.08);
    --dur-fast: 120ms; --dur-base: 200ms;
    --ease-out: cubic-bezier(0.2, 0.7, 0.2, 1);

    --sidebar-w: 240px;
    --page-pad-x: 1.75rem;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg-page:      var(--n3i-dark-blue-800);
    --bg-surface:   var(--n3i-dark-blue-700);
    --bg-surface-2: var(--n3i-dark-blue-600);
    --fg-1: #f4f3f8;
    --fg-2: var(--n3i-dark-blue-100);
    --fg-3: var(--n3i-dark-blue-200);
    --line-1: var(--n3i-dark-blue-600);
    --line-2: var(--n3i-dark-blue-500);
    --primary-soft: var(--n3i-dark-blue-600);
    --primary-line: var(--line-2);
    --primary-text: var(--n3i-light-blue-300);
    --link:         var(--n3i-light-blue-300);
    --link-hover:   var(--n3i-light-blue-200);
    --success-soft: #14532d; --success-line: transparent; --success-ink: #d6ebb0;
    --warning-soft: #431407; --warning-line: transparent; --warning-ink: #ffd9b5;
    --danger-soft:  #450a0a; --danger-line:  transparent; --danger-ink:  #fab8b1;
    --tx-green: #4ade80;
    --tx-amber: #fbbf24;
    --tx-red: #f87171;
    --tx-blue: var(--n3i-light-blue-300);
    --tx-purple: #c4b5fd;
    --tx-pink: #f9a8d4; --tx-cyan: #22d3ee; --tx-teal: #34d399; --tx-orange: #fb923c; --tx-grey: var(--fg-2);
    --tx-turquoise: #a3e5e1; --tx-indigo: #a5b4fc;
    --tint-green: var(--bg-surface-2); --tint-amber: var(--bg-surface-2); --tint-red: var(--bg-surface-2);
    --tint-blue: var(--bg-surface-2); --tint-purple: var(--bg-surface-2); --tint-pink: var(--bg-surface-2);
    --tint-teal: var(--bg-surface-2); --tint-orange: var(--bg-surface-2); --tint-grey: var(--bg-surface-2);
    --tint-turquoise: var(--bg-surface-2); --tint-indigo: var(--bg-surface-2);
    --focus: var(--n3i-light-blue-200);
    --input-border: #6866b8;
}

/* ── 2. Base elements ── */
body {
    font-family: var(--font-sans); font-size: 0.875rem; line-height: 1.5;
    background: var(--bg-page); color: var(--fg-1);
    min-height: 100vh; display: flex; flex-direction: column;
}
h1, h2, h3, h4 { font-family: var(--font-display); color: var(--fg-1); line-height: 1.25; letter-spacing: -0.01em; }
h2 { font-size: 1.125rem; font-weight: 700; }
h3 { font-size: 0.9375rem; font-weight: 700; }
p + p { margin-top: 0.75rem; }
a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); text-decoration: underline; }
code { font-family: var(--font-mono); }
.icon { flex-shrink: 0; vertical-align: middle; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
/* Inside containers that clip (menus, scrolling tables, the tab bar) and on the navy bars, draw it inside the
   element */
.topbar-menu :focus-visible, .table-scroll :focus-visible, .tab-bar :focus-visible { outline-offset: -2px; }
.app-sidebar :focus-visible { outline-color: #fff; outline-offset: -2px; }
/* Targets of in-page links (the skip link's <main tabindex="-1">) take focus but are not controls */
[tabindex="-1"]:focus { outline: none; }

/* Skip link: the first thing a keyboard user reaches; hidden until it has focus */
.skip-link {
    position: absolute; top: 0.5rem; left: 0.5rem; z-index: 2000; transform: translateY(-200%);
    padding: 0.625rem 1rem; border-radius: var(--radius-sm); background: var(--bg-surface); color: var(--link);
    font-weight: 700; text-decoration: underline; box-shadow: var(--shadow-md);
}
.skip-link:focus { transform: none; }

/* Reduced motion: no entrance animations, and transitions (hover fades, the sidebar width, chevrons) happen at once */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ── 3. App shell: full-height left sidebar + main column ── */
.app-shell { display: flex; align-items: stretch; flex: 1; width: 100%; }
.app-main  { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.app-sidebar {
    width: var(--sidebar-w); flex-shrink: 0; background: var(--bg-sidebar);
    position: sticky; top: 0; height: 100vh; z-index: 200;
    display: flex; flex-direction: column;
    transition: width var(--dur-base) var(--ease-out);
}
.app-sidebar-brand { display: flex; align-items: center; gap: 0.625rem; padding: 1.25rem 1.25rem 1rem; flex-shrink: 0; }
.app-sidebar-brand img { height: 32px; width: 32px; display: block; }
.app-sidebar-brand:hover { text-decoration: none; }
.app-sidebar-brand-text {
    font-family: var(--font-display);
    font-size: 1.125rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1;
    color: #fff;
}
/* The Menu button only shows on narrow screens (see the media queries below) */
.app-nav-menu-toggle { display: none; }
.app-sidebar-nav {
    flex: 1;
    padding: 0.5rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
}

/* Sidebar links: a top-level .app-nav-link, or a .nav-group-item inside a group */
.app-nav-link, .nav-group-item {
    display: flex; align-items: center; gap: 0.75rem;
    font-weight: 500; text-decoration: none; color: rgba(255, 255, 255, 0.7);
    transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.app-nav-link:hover, .nav-group-item:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    text-decoration: none;
}
.app-nav-link.active, .nav-group-item.active { background: rgba(255, 255, 255, 0.14); color: #fff; font-weight: 600; }
.app-nav-link .icon, .nav-group-item .icon { width: 16px; height: 16px; opacity: 0.85; }
.app-nav-link {
    position: relative;
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: none;
    border-radius: var(--radius-sm);
    background: none;
    font-family: inherit; font-size: 0.8125rem; cursor: pointer; text-align: left; white-space: nowrap;
}
.nav-group-item {
    padding: 0.45rem 0.75rem;
    border-radius: var(--radius-xs);
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.65);
}

/* A group: header link + chevron button, with its items expanding inline below */
.nav-group { position: relative; }
.nav-group > .app-nav-link { padding-right: 2.25rem; }
.nav-group-toggle {
    position: absolute; top: 0; right: 0; height: 2.35rem; width: 2.25rem;
    display: flex; align-items: center; justify-content: center;
    background: none; border: none; border-radius: var(--radius-sm); cursor: pointer; color: rgba(255, 255, 255, 0.6);
}
.nav-group-toggle:hover { color: #fff; }
.nav-group-toggle .icon, .app-sidebar-toggle .icon { transition: transform var(--dur-fast) var(--ease-out); }
.nav-group.open .nav-group-toggle .icon { transform: rotate(180deg); }
.nav-group-menu { display: none; flex-direction: column; gap: 1px; padding: 2px 0 4px 0.75rem; }
.nav-group.open .nav-group-menu { display: flex; }
.nav-divider { height: 1px; background: rgba(255, 255, 255, 0.1); margin: 0.5rem 0.75rem; }
.nav-group-divider { height: 1px; background: rgba(255, 255, 255, 0.1); margin: 3px 0.75rem; }
/* A count on a sidebar item, e.g. the open feedback on Admin > Feedback */
.nav-badge {
    margin-left: auto;
    min-width: 1.25rem;
    padding: 0 0.375rem;
    border-radius: var(--radius-pill);
    background: rgba(255, 255, 255, 0.16);
    font-size: 0.6875rem;
    font-weight: 700;
    line-height: 1.25rem;
    text-align: center;
    color: #fff;
}

/* Collapse toggle at the foot of the sidebar */
.app-sidebar-toggle-wrap {
    flex-shrink: 0;
    padding: 0.5rem 0.75rem 0.75rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}
@media (min-width: 901px) {
    html.sidebar-collapsed .app-sidebar { width: 68px; }
    html.sidebar-collapsed .app-sidebar-brand { justify-content: center; padding-left: 0; padding-right: 0; }
    html.sidebar-collapsed .app-nav-link { justify-content: center; padding-left: 0; padding-right: 0; }
    html.sidebar-collapsed .nav-label,
    html.sidebar-collapsed .app-nav-link .nav-badge,
    html.sidebar-collapsed .app-sidebar-brand-text,
    html.sidebar-collapsed .nav-group-toggle,
    html.sidebar-collapsed .nav-group .nav-group-menu { display: none; }
    html.sidebar-collapsed .app-sidebar-toggle .icon { transform: rotate(180deg); }
    /* The current section keeps a marker on its icon, as the highlight alone is faint on a narrow rail */
    html.sidebar-collapsed .app-nav-link.active { box-shadow: inset 3px 0 0 #fff; }

    /* A group's menu pops out beside the rail on hover or keyboard focus. It is fixed so the nav's scrolling doesn't
       clip it; ui.js sets --flyout-top. The ::before bridges the gap left by the nav's padding, so the pointer can
       cross to it. Esc sets .flyout-closed until the pointer or focus leaves. */
    html.sidebar-collapsed .nav-group:is(:hover, :focus-within):not(.flyout-closed) .nav-group-menu {
        display: flex;
        position: fixed; left: 68px; top: var(--flyout-top, 0); z-index: 300;
        min-width: 13rem; padding: 0.5rem;
        background: var(--bg-sidebar);
        border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
        box-shadow: var(--shadow-lg, 0 8px 24px rgba(0, 0, 0, 0.3));
    }
    html.sidebar-collapsed .nav-group-menu::before {
        content: ''; position: absolute; top: 0; bottom: 0; left: -1rem; width: 1rem;
    }
    html.sidebar-collapsed .nav-group-menu-title {
        display: block; padding: 0.25rem 0.75rem 0.5rem;
        font-size: 0.6875rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
        color: rgba(255, 255, 255, 0.55);
    }
}
/* The pop-out's heading only shows when the sidebar is collapsed */
.nav-group-menu-title { display: none; }

/*
 * While an admin impersonates a user (IS_IMPERSONATOR): a banner pinned above everything, the same red and white in
 * light and dark, and the sidebar starts below it.
 */
.impersonation-banner {
    --impersonation-bg: #b81b10;
    position: sticky; top: 0; z-index: 900; min-height: 2.75rem;
    display: flex; align-items: center; justify-content: center; gap: 1rem; flex-wrap: wrap;
    padding: 0.375rem 1rem; background: var(--impersonation-bg); color: #fff; font-weight: 500;
    border-bottom: 3px solid #fff;
}
.impersonation-banner p { margin: 0; display: flex; align-items: center; gap: 0.5rem; }
.impersonation-banner .btn { background: #fff; border-color: #fff; color: #7a110a; font-weight: 600; }
.impersonation-banner .btn:hover { background: #ffe9e6; }
@media (min-width: 901px) {
    .is-impersonating .app-sidebar { top: 2.75rem; height: calc(100vh - 2.75rem); }
}

.is-impersonating .topbar { top: 2.75rem; }

/* Top bar: breadcrumb on the left; date, search, theme, user menu and apps on the right. It stays at the top of the
   viewport as the page scrolls. */
.topbar {
    position: sticky; top: 0; z-index: 100;
    background: var(--bg-surface); border-bottom: 1px solid var(--line-1); height: 42px; flex-shrink: 0;
    padding: 0 var(--page-pad-x); display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.8125rem;
    min-width: 0;
    white-space: nowrap;
}
.breadcrumb a, .breadcrumb > span { color: var(--fg-2); text-decoration: none; transition: color var(--dur-fast); }
.breadcrumb a:hover { color: var(--primary-text); }
.breadcrumb .breadcrumb-sep { color: var(--fg-3); font-size: 0.7rem; }
.breadcrumb .breadcrumb-current { color: var(--fg-1); font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.topbar-end { display: flex; align-items: center; gap: 0.75rem; font-size: 0.75rem; color: var(--fg-3); }
.topbar-date { font-size: 0.7rem; white-space: nowrap; }

/* Round grey icon button (search, theme, apps) and the pill-shaped user button */
.topbar-btn, .topbar-user {
    display: flex; align-items: center; justify-content: center; flex-shrink: 0; height: 30px;
    background: var(--bg-surface-2); border: 1px solid var(--line-1); cursor: pointer; color: var(--fg-2);
    transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.topbar-btn { width: 30px; border-radius: 50%; }
.topbar-btn:hover, .topbar-btn.open {
    background: var(--primary-soft);
    color: var(--primary-text);
    text-decoration: none;
}
.theme-toggle .icon-sun, :root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: inline-flex; }
.topbar-user {
    gap: 0.5rem;
    padding: 0 0.75rem;
    border-radius: var(--radius-pill);
    font-family: inherit;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--fg-1);
}
.topbar-user:hover { background: var(--primary-soft); }
.topbar-user > .icon { opacity: 0.5; }
.topbar-user-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Drop-down menus from the top bar */
.topbar-menu-wrap { position: relative; }
.topbar-menu {
    position: absolute; top: calc(100% + 8px); right: 0; z-index: 900; min-width: 200px; overflow: hidden;
    background: var(--bg-surface);
    border: 1px solid var(--line-1);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}
.menu-header {
    padding: 0.625rem 1rem;
    border-bottom: 1px solid var(--line-1);
    background: var(--bg-surface-2);
    font-size: 0.8125rem;
    font-weight: 700;
    color: var(--fg-1);
}
.menu-header small {
    display: block;
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--fg-3);
    text-transform: capitalize;
}
.menu-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    font-size: 0.8125rem;
    color: var(--fg-1);
    text-decoration: none;
}
.menu-item:hover { background: var(--bg-page); color: var(--fg-1); text-decoration: none; }
.menu-item .icon { color: var(--fg-3); }
.menu-item-danger, .menu-item-danger:hover, .menu-item-danger .icon { color: var(--tx-red); }

/* Full-screen customer search ("spotlight") opened from the top bar */
.search-overlay {
    position: fixed; inset: 0; z-index: 1000; background: rgba(8, 7, 28, 0.78);
    display: flex; align-items: flex-start; justify-content: center; padding: 18vh 1rem 1rem;
}
.search-overlay[hidden] { display: none; }
.search-overlay-box {
    width: 100%;
    max-width: 760px;
    overflow: hidden;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
}
.search-input-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.5rem 1.75rem;
    border-bottom: 1px solid var(--line-1);
}
.search-input-row > .icon { color: var(--fg-3); }
.search-input-row:focus-within { box-shadow: inset 0 -3px 0 var(--focus); }
.search-overlay .search-input-row input {
    flex: 1;
    min-width: 0;
    min-height: 0;
    padding: 0;
    border: none;
    outline: none;
    box-shadow: none;
    background: transparent;
    font-size: 1.375rem;
    color: var(--fg-1);
}
.search-overlay input::-webkit-search-cancel-button { display: none; }
.search-overlay-close {
    display: flex;
    padding: 0.25rem;
    border: none;
    border-radius: var(--radius-xs);
    background: none;
    cursor: pointer;
    color: var(--fg-3);
}
.search-overlay-close:hover { color: var(--fg-1); background: var(--bg-page); }
.search-hint { padding: 0.875rem 1.75rem; font-size: 0.8125rem; color: var(--fg-3); }

/* Page body and the page header (large title, buttons on the right) */
.page-body { flex: 1; width: 100%; padding: 2rem var(--page-pad-x); }
/* Plain section headings and intro paragraphs placed straight in a page */
.page-body > h2 { margin: 1.75rem 0 0.75rem; }
.page-body > h2:first-child { margin-top: 0; }
.page-body > p { margin-bottom: 0.75rem; color: var(--fg-2); }
/* Links inside running text are underlined, not told apart by colour alone (WCAG 1.4.1) */
.page-body p a:not(.btn), .alert a:not(.btn), .form-hint a { text-decoration: underline; }

.page-header {
    margin-bottom: 1.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}
.page-header .btn { font-size: 0.875rem; padding: 0.525rem 1rem; }
.page-header-btns { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.page-title {
    font-family: var(--font-display);
    font-size: 1.875rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--fg-1);
    line-height: 1.2;
}

/* Each top-level block of the page fades in and rises on load, staggered */
@keyframes fade-in-up { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
.page-body > :not(script):not(style):not([hidden]) { animation: fade-in-up 0.4s ease backwards; }
.page-body > :nth-child(2) { animation-delay: 0.05s; }
.page-body > :nth-child(3) { animation-delay: 0.10s; }
.page-body > :nth-child(4) { animation-delay: 0.15s; }
.page-body > :nth-child(5) { animation-delay: 0.20s; }
.page-body > :nth-child(n+6) { animation-delay: 0.25s; }

/* Narrow screens: the sidebar becomes a top bar with the logo and a Menu button. The button opens the links as one
   panel below the bar (groups expand inside it, as in the sidebar), which scrolls when taller than the screen. */
@media (max-width: 900px) {
    .app-shell { flex-direction: column; }
    .app-sidebar {
        width: 100%;
        height: auto;
        position: relative;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
    /* 56px tall with the 32px logo: the panel's max-height below relies on it */
    .app-sidebar-brand { padding: 0.75rem 1rem; }
    .app-nav-menu-toggle {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        min-height: 40px;
        margin-right: 0.75rem;
        padding: 0.5rem 0.875rem;
        border: 1px solid rgba(255, 255, 255, 0.3);
        border-radius: var(--radius-sm);
        background: rgba(255, 255, 255, 0.06);
        font-family: inherit; font-size: 0.8125rem; font-weight: 600; color: #fff; cursor: pointer;
    }
    .app-nav-menu-toggle:hover, .app-nav-menu-toggle[aria-expanded="true"] { background: rgba(255, 255, 255, 0.14); }
    .app-sidebar-nav {
        display: none; position: absolute; top: 100%; left: 0; right: 0; z-index: 300;
        max-height: calc(100vh - 56px); max-height: calc(100dvh - 56px); overflow-y: auto; overscroll-behavior: contain;
        padding: 0.5rem 0.75rem 0.75rem;
        background: var(--bg-sidebar);
        border-top: 1px solid rgba(255, 255, 255, 0.12);
        box-shadow: var(--shadow-md);
    }
    .app-sidebar.nav-open .app-sidebar-nav { display: flex; }
    .app-sidebar-toggle-wrap { display: none; }
}
@media (max-width: 768px) {
    :root { --page-pad-x: 1rem; }
    .page-body { padding: 1rem; }
    .topbar-date, .topbar-user-name { display: none; }
}
/* Reflow (WCAG 1.4.10): at 320px wide the breadcrumb and the top bar buttons wrap rather than overlap or scroll
   sideways */
@media (max-width: 600px) {
    .topbar { height: auto; min-height: 42px; flex-wrap: wrap; padding-top: 0.375rem; padding-bottom: 0.375rem; }
    .breadcrumb { flex-wrap: wrap; white-space: normal; }
    .topbar-end { margin-left: auto; }
    .search-overlay { padding-top: 10vh; }
    .search-input-row { padding: 1rem; gap: 0.625rem; }
}

/* ── 4. Components ── */

/* Buttons. A bare .btn is the white secondary button; add .btn-primary for the blue one.
   Icons go inside: <a class="btn btn-primary">{{ ui.icon('plus', 15) }} Add customer</a> */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
    padding: 0.5rem 1rem; border: 1px solid var(--line-2); border-radius: var(--radius-sm);
    background: var(--bg-surface); color: var(--fg-1); text-decoration: none;
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    font-weight: 600;
    line-height: 1.4;
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--dur-fast) var(--ease-out);
}
.btn:hover { background: var(--bg-page); color: var(--fg-1); text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.btn[hidden] { display: none; }
/* A delete button that is disabled because the item is in use; the span carries the reason as a tooltip */
.in-use { display: inline-flex; }
.btn .icon { width: 14px; height: 14px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
.btn-primary:active { background: var(--primary-press); }
.btn-danger, .btn-danger:hover {
    background: var(--danger-soft);
    border-color: var(--danger-line);
    color: var(--danger-ink);
}
.btn-danger:hover { filter: brightness(0.97); }
:where(:root[data-theme="dark"]) { .btn-danger { border-color: #b81b10; } }
/* Solid red: the OK button of a confirm dialog for a delete */
.btn-danger-solid, .btn-danger-solid:hover { background: #b81b10; border-color: #b81b10; color: #fff; }
.btn-danger-solid:hover { filter: brightness(0.92); }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.75rem; }
/* Square icon-only button, e.g. edit/delete in a table row. Give it a title and an .sr-only label. */
.btn-icon { padding: 0.4rem; border-radius: var(--radius-xs); }
.btn-icon.btn-danger { border-color: transparent; }
.btn-done { color: var(--tx-green); }
.btn-group { display: inline-flex; align-items: center; gap: 0.375rem; }
.btn-group form { display: inline-flex; }

/* Badges: small uppercase status labels. A bare .badge is grey; colours: badge-green, -orange, -red, -blue, -pink,
   -purple. Add .badge-plain to keep the text's own case. */
.badge {
    display: inline-flex; align-items: center; gap: 0.25rem; white-space: nowrap;
    padding: 0.2rem 0.6rem; border-radius: var(--radius-pill); line-height: 1.4;
    font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em;
    background: var(--bg-surface-2); color: var(--fg-2);
}
.badge-green  { background: var(--success-soft); color: var(--success-ink); }
.badge-orange { background: var(--warning-soft); color: var(--warning-ink); }
.badge-red    { background: var(--danger-soft); color: var(--danger-ink); }
.badge-blue   { background: var(--primary-soft); color: var(--primary-text); }
.badge-pink   { background: var(--tint-pink); color: var(--tx-pink); }
.badge-purple { background: var(--tint-purple); color: var(--tx-purple); }
.badge-plain  { text-transform: none; letter-spacing: 0; }

/* Pills: small bold rounded labels, coloured with a .tone-* class (contact roles, margins, "Primary") */
.pill {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.15rem 0.5rem;
    border-radius: var(--radius-pill);
    font-size: 0.68rem;
    font-weight: 700;
    white-space: nowrap;
    background: var(--tint-grey);
    color: var(--tx-grey);
}
.pill-row { display: flex; flex-wrap: wrap; gap: 0.25rem; }

/* Tooltips: <span class="tip"><button class="tip-trigger" aria-describedby="x">…</button>
   <span class="tip-text" id="x" role="tooltip">…</span></span>. The text shows on hover (including over the text
   itself) and keyboard focus; ui.js also toggles it on a click or tap (.is-open) and hides it on Escape
   (.is-dismissed), as WCAG 1.4.13 asks. It opens above the trigger, right-aligned, so it stays inside a table. */
.tip { position: relative; display: inline-flex; vertical-align: middle; }
.tip-trigger { border: 0; font-family: inherit; line-height: inherit; cursor: help; }
.tip-text {
    display: none;
    position: absolute;
    z-index: 30;
    right: 0;
    bottom: calc(100% + 6px);
    width: max-content;
    max-width: 16rem;
    padding: 0.35rem 0.6rem;
    border-radius: var(--radius-xs);
    background: var(--fg-1);
    color: var(--bg-surface);
    box-shadow: var(--shadow-md);
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1.4;
    text-align: left;
    white-space: normal;
}
/* bridges the gap to the trigger, so the pointer can move onto the text without it closing */
.tip-text::after { content: ''; position: absolute; top: 100%; right: 0; left: 0; height: 6px; }
.tip:hover > .tip-text, .tip:focus-within > .tip-text, .tip.is-open > .tip-text { display: block; }
.tip.is-dismissed > .tip-text { display: none; }
/* A service's name, tinted in the service colour (style="--svc: #hex") */
.service-pill {
    color: var(--fg-1);
    background: color-mix(in srgb, var(--svc) 9%, transparent);
    border: 1px solid color-mix(in srgb, var(--svc) 27%, transparent);
}
/* Customer type: solid, in the type's colour (inline style) */
.type-chip {
    display: inline-block;
    padding: 0.2rem 0.7rem;
    border-radius: var(--radius-pill);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    white-space: nowrap;
}
/* Small mono chip for codes (ODS codes, references) */
.code-chip {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border: 1px solid var(--line-1);
    border-radius: var(--radius-xs);
    background: var(--bg-surface-2);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--fg-1);
    white-space: nowrap;
}
/* "Managed by N3i" chip, with the logo */
.managed-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.1rem 0.4rem;
    border: 1px solid var(--line-1);
    border-radius: var(--radius-xs);
    background: var(--bg-page);
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--fg-1);
    white-space: nowrap;
}
.managed-chip img { width: 12px; height: 12px; }

/* Cards */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--line-1);
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.card + .card, .card + .table-scroll, .table-scroll + .card { margin-top: 1.25rem; }
.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--line-1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}
.card-header a { font-size: 0.75rem; }
.card-title { font-family: var(--font-display); font-size: 0.9375rem; font-weight: 700; color: var(--fg-1); }
.card-body { padding: 1.25rem; }
.card-footer { padding: 0.75rem 1.25rem; border-top: 1px solid var(--line-1); }
/* A heading row: title (and subline) on the left, buttons on the right. Add .toolbar-end for buttons only. */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin: 0 0 1rem;
}
.card + .toolbar, .overview-grid + .toolbar { margin-top: 1.75rem; }
.toolbar-end { justify-content: flex-end; }
.toolbar-title { font-family: var(--font-sans); font-size: 1rem; font-weight: 600; }
/* A card with an icon on the left, a title and a line or two (the admin overview) */
.card.link-card {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1.5rem;
    color: inherit;
    text-decoration: none;
    transition: box-shadow var(--dur-base), border-color var(--dur-base);
}
.link-card:hover { color: inherit; text-decoration: none; border-color: var(--primary); box-shadow: var(--shadow-md); }
.link-card-body { flex: 1; min-width: 0; }
.link-card-title { display: block; font-size: 0.9375rem; font-weight: 700; color: var(--fg-1); }
.link-card-desc { display: block; margin-top: 0.2rem; font-size: 0.8125rem; color: var(--fg-2); }
.link-card-stat { display: block; margin-top: 0.6rem; font-size: 0.75rem; font-weight: 500; color: var(--fg-3); }
.link-card-stat strong { margin-right: 0.3rem; font-size: 1.25rem; font-weight: 800; color: var(--fg-1); }
/* A link card holding its own controls (the finance overview's margin pill): the title is the link, and its ::after
   covers the card so the whole card is still clickable; controls sit above it */
.link-card-covered { position: relative; }
.link-card-cover::after { content: ''; position: absolute; inset: 0; }
.link-card-cover:hover { text-decoration: none; }
.link-card-covered .tip { z-index: 1; }

/* Grids and stacks */
.grid-2, .grid-3 { display: grid; gap: 1.25rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 > .card + .card, .grid-3 > .card + .card { margin-top: 0; }
.card + .grid-2 { margin-top: 1.5rem; }
@media (max-width: 1100px) { .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 900px)  { .grid-2 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 700px)  { .grid-3 { grid-template-columns: minmax(0, 1fr); } }
.stack { display: flex; flex-direction: column; gap: 0.75rem; }
.stack > .card + .card { margin-top: 0; }

/* Stat tiles: coloured icon square, big number, label.
   <a class="stat-tile" href="..."><span class="stat-icon tone-green">{{ ui.icon('check-circle', 18) }}</span>
       <span><span class="stat-value text-green">8</span><span class="stat-label">Active customers</span></span></a> */
.stat-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
    gap: 1rem;
    margin-bottom: 1.75rem;
}
@media (max-width: 600px) { .stat-tiles { grid-template-columns: minmax(0, 1fr); } }
.stat-tile {
    display: flex; align-items: center; gap: 1rem; padding: 1.125rem 1.25rem;
    background: var(--bg-surface); border: 1px solid var(--line-1); border-radius: var(--radius-md);
    color: inherit; text-decoration: none;
}
.stat-tile > span:last-child { min-width: 0; overflow-wrap: break-word; }
a.stat-tile { transition: box-shadow var(--dur-base) var(--ease-out), border-color var(--dur-base) var(--ease-out); }
a.stat-tile:hover { box-shadow: var(--shadow-md); border-color: var(--primary); text-decoration: none; color: inherit; }
.stat-icon {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: var(--bg-surface-2);
    color: var(--fg-3);
}
.stat-value {
    display: block;
    font-family: var(--font-display);
    font-size: 1.625rem;
    font-weight: 800;
    letter-spacing: -0.04em;
    line-height: 1;
    color: var(--fg-1);
}
/* A smaller figure for long values (money), kept on one line; its tiles get .stat-tiles-wide so they have room */
.stat-value-sm { font-size: 1.125rem; white-space: nowrap; }
.stat-tiles-wide { grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); }
.stat-label { display: block; font-size: 0.73rem; font-weight: 500; color: var(--fg-3); margin-top: 0.2rem; }

/* Tables: wrap in .table-scroll (the rounded card); the table gets .data-table */
.table-scroll {
    position: relative;
    /* keeps .sr-only text inside the scroll box */ overflow-x: auto;
    background: var(--bg-surface);
    border: 1px solid var(--line-1);
    border-radius: var(--radius-lg);
}
.card > .table-scroll { border: 0; border-radius: 0; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.8125rem; color: var(--fg-1); }
.data-table th {
    text-align: left; padding: 0.75rem 1rem; white-space: nowrap;
    font-size: 0.6875rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em;
    color: var(--fg-2); background: var(--bg-page); border-bottom: 1px solid var(--line-1);
}
.data-table td { padding: 0.8rem 1rem; border-bottom: 1px solid var(--line-1); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover td { background: var(--bg-surface-2); }
.data-table td a { font-weight: 500; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .actions { text-align: right; white-space: nowrap; }
.data-table .mono { font-family: var(--font-mono); font-size: 0.75rem; color: var(--fg-2); }
/* A message row (colspan) and the italic "no data" cell */
.data-table td[colspan] { padding: 2rem 1rem; text-align: center; color: var(--fg-3); }
.data-table tbody tr:hover td[colspan] { background: transparent; }
/* A line of smaller text under a cell's main value */
.cell-sub { display: block; margin-top: 2px; font-size: 0.75rem; font-weight: 400; color: var(--fg-3); }
a.cell-sub { color: var(--primary-text); }
.row-inactive td:first-child { color: var(--fg-3); }
/* Sortable column headers */
.data-table th .sort-link { color: inherit; font-weight: inherit; }
.data-table th .sort-link:hover, .data-table th .sort-link.active { color: var(--fg-1); }
.data-table th .sort-arrow { margin-left: 0.15rem; }
/* Drag to reorder (SortableJS) */
.reorder-cell { display: flex; align-items: center; gap: 0.5rem; }
.drag-handle { display: inline-flex; color: var(--fg-3); cursor: grab; }
.drag-handle:active { cursor: grabbing; }
.sortable-ghost { opacity: 0.4; }

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 1.25rem;
    font-size: 0.8125rem;
}

/* Form controls: every input, select and textarea gets the same look */
input:not([type]), input[type="text"], input[type="search"], input[type="email"], input[type="url"], input[type="tel"],
input[type="number"], input[type="date"], input[type="datetime-local"], input[type="month"], input[type="password"],
select, textarea {
    padding: 0.5625rem 0.75rem; min-height: 40px;
    background: var(--bg-surface); border: 1px solid var(--input-border); border-radius: var(--radius-sm);
    font-family: var(--font-sans); font-size: 0.875rem; color: var(--fg-1);
    transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
/* Focus on a text control: the border turns blue and grows from 1px to 2px, with the padding giving up the same 1px so
   nothing moves. One border, not a border plus a ring or outline, so every side snaps to whole pixels alike (separate
   pieces looked uneven at 125% zoom). The outline stays transparent so forced-colours mode still draws one. */
:is(
    input:not([type]),
    input[type="text"],
    input[type="search"],
    input[type="email"],
    input[type="url"],
    input[type="tel"],
    input[type="number"],
    input[type="date"],
    input[type="datetime-local"],
    input[type="month"],
    input[type="password"],
    select,
    textarea
):focus,
.ts-dropdown .dropdown-input:focus,
.ts-wrapper.focus .ts-control,
.ts-wrapper.plugin-dropdown_input.focus.dropdown-active .ts-control {
    border: 2px solid var(--focus);
}
:is(
    input:not([type]),
    input[type="text"],
    input[type="search"],
    input[type="email"],
    input[type="url"],
    input[type="tel"],
    input[type="number"],
    input[type="date"],
    input[type="datetime-local"],
    input[type="month"],
    input[type="password"],
    select,
    textarea
):focus-visible {
    outline-color: transparent;
}
/* The Tom Select search input sits inside .ts-control, which draws the indicator */
.ts-control input:focus-visible { outline: none; }
:is(
    input:not([type]),
    input[type="text"],
    input[type="search"],
    input[type="email"],
    input[type="url"],
    input[type="tel"],
    input[type="number"],
    input[type="date"],
    input[type="datetime-local"],
    input[type="month"],
    input[type="password"],
    select,
    textarea
):focus {
    padding: calc(0.5625rem - 1px) calc(0.75rem - 1px);
}
select:not([multiple]):focus { padding-right: calc(2rem - 1px); background-position: right calc(0.75rem - 1px) center; }
select[multiple]:focus { padding-right: calc(0.75rem - 1px); }
select {
    appearance: none; cursor: pointer; padding-right: 2rem;
    background-image:
        url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='12'%20height='12'%20viewBox='0%200%2024%2024'%20fill='none'%20stroke='%236a696d'%20stroke-width='2.5'%3E%3Cpolyline%20points='6%209%2012%2015%2018%209'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 0.75rem center;
}
select[multiple] { background-image: none; padding-right: 0.75rem; min-height: 6rem; }

/* Searchable selects (assets/js/select.js puts Tom Select on every select): .ts-wrapper takes the select's classes and
   holds .ts-control (the box, with the chosen items and the search input) and .ts-dropdown (the options).
   These rules give it the look of the other controls above, on top of Tom Select's base CSS. */
.ts-wrapper { min-width: 0; }
.ts-wrapper.single { --ts-pr-caret: 2rem; } /* room for the arrow (Tom Select sets padding-right from this) */
.ts-wrapper .ts-control {
    min-height: 40px; padding: 0.4375rem 0.75rem; align-items: center; gap: 0.25rem;
    background: var(--bg-surface); border: 1px solid var(--input-border); border-radius: var(--radius-sm);
    font-size: 0.875rem; line-height: 1.5rem; color: var(--fg-1);
    transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.ts-wrapper .ts-control, .ts-wrapper .ts-control input, .ts-dropdown {
    font-family: var(--font-sans);
    font-size: 0.875rem;
    line-height: 1.5rem;
    color: var(--fg-1);
}
.ts-wrapper .ts-control input::placeholder { color: var(--fg-3); }
.ts-wrapper.single .ts-control, .ts-wrapper.single.input-active .ts-control, .ts-wrapper.full .ts-control {
    background: var(--bg-surface);
}
.ts-wrapper.single .ts-control::after {
    content: "";
    position: absolute;
    right: 0.75rem;
    top: 50%;
    width: 12px;
    height: 12px;
    margin-top: -6px;
    pointer-events: none;
    background:
        url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='12'%20height='12'%20viewBox='0%200%2024%2024'%20fill='none'%20stroke='%236a696d'%20stroke-width='2.5'%3E%3Cpolyline%20points='6%209%2012%2015%2018%209'/%3E%3C/svg%3E")
        no-repeat;
}
/* A single select shows only the chosen option (its search box is in the dropdown), cut short if it is too long */
.ts-wrapper.single .ts-control { flex-wrap: nowrap; }
.ts-wrapper.single .ts-control > .item { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.ts-wrapper .ts-control > .items-placeholder { min-height: 0; padding: 0; background: transparent; }
.ts-wrapper.multi.has-items .ts-control { padding: 0.3125rem 0.75rem 0.3125rem 0.375rem; }
.ts-wrapper.focus .ts-control, .ts-wrapper.plugin-dropdown_input.focus.dropdown-active .ts-control {
    padding: calc(0.4375rem - 1px) calc(0.75rem - 1px);
}
.ts-wrapper.single.focus { --ts-pr-caret: calc(2rem - 1px); }
.ts-wrapper.multi.has-items.focus .ts-control {
    padding: calc(0.3125rem - 1px) calc(0.75rem - 1px) calc(0.3125rem - 1px) calc(0.375rem - 1px);
}
.ts-wrapper.single.focus .ts-control::after { right: calc(0.75rem - 1px); }
select[aria-invalid="true"] + .ts-wrapper .ts-control { border-color: var(--danger-ink); }
.ts-wrapper.disabled .ts-control { opacity: 0.6; }
/* Chosen items of a multiple select: pills with a remove button */
.ts-wrapper.multi .ts-control > .item {
    margin: 0; padding: 0.0625rem 0.5rem; border-radius: var(--radius-xs);
    background: var(--primary-soft); color: var(--primary-text); font-size: 0.8125rem; font-weight: 500;
}
.ts-wrapper.multi .ts-control > .item.active { background: var(--primary); color: #fff; }
.ts-wrapper.plugin-remove_button:not(.rtl) .item .remove {
    margin-left: 0.375rem;
    padding: 0 0.375rem;
    border-left: 1px solid currentColor;
    border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
    font-size: 1rem;
    line-height: 1.25rem;
    opacity: 0.75;
}
.ts-wrapper.plugin-remove_button .item .remove:hover { opacity: 1; background: rgba(0, 0, 0, 0.08); }
.ts-dropdown {
    z-index: 800; margin-top: 0.25rem; overflow: hidden;
    background: var(--bg-surface);
    border: 1px solid var(--input-border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
}
.ts-dropdown .ts-dropdown-content { max-height: 18rem; }
/* The search box at the top of a single select's list */
.ts-dropdown .dropdown-input-wrap { padding: 0.375rem; border-bottom: 1px solid var(--line-1); }
.ts-dropdown .dropdown-input {
    width: 100%;
    min-height: 34px;
    padding: 0.3125rem 0.625rem;
    border: 1px solid var(--input-border);
    border-radius: var(--radius-xs);
    background: var(--bg-surface);
}
.ts-dropdown .dropdown-input:focus { padding: calc(0.3125rem - 1px) calc(0.625rem - 1px); }
.ts-dropdown .option, .ts-dropdown .no-results, .ts-dropdown .optgroup-header { padding: 0.4375rem 0.75rem; }
.ts-dropdown .optgroup-header { background: var(--bg-page); color: var(--fg-2); font-size: 0.75rem; font-weight: 700; }
.ts-dropdown .optgroup + .optgroup { border-top: 1px solid var(--line-1); }
.ts-dropdown .no-results { color: var(--fg-3); }
.ts-dropdown .option.selected { font-weight: 600; }
.ts-dropdown .active { background: var(--primary-soft); color: var(--primary-text); }
.ts-dropdown [data-selectable] .highlight { background: none; font-weight: 700; text-decoration: underline; }
textarea { resize: vertical; min-height: 80px; width: 100%; }
input[type="checkbox"], input[type="radio"] {
    width: 1rem;
    height: 1rem;
    accent-color: var(--primary);
    vertical-align: middle;
}
input[type="file"] { font-family: inherit; font-size: 0.8125rem; }
::placeholder { color: var(--fg-3); opacity: 1; } /* full strength: at 0.8 it was 3.6:1 */
/* Field errors: red text from form_errors, and a red border on the field itself via aria-invalid */
:is(input, select, textarea)[aria-invalid="true"] { border-color: var(--danger-ink); }
.form-errors { list-style: none; font-size: 0.8125rem; color: var(--danger-ink); }
/* A unit joined to its input, from the form theme's money and percent widgets:
   <div class="input-affix"><span class="input-affix-text">£</span><input></div> */
.input-affix { display: flex; flex-direction: row; align-items: stretch; gap: 0; }
.input-affix > input { flex: 1; min-width: 0; }
.input-affix-text {
    display: flex; align-items: center; padding: 0 0.75rem;
    background: var(--bg-page); border: 1px solid var(--input-border); border-radius: var(--radius-sm);
    font-size: 0.875rem; font-weight: 600; color: var(--fg-2);
}
.input-affix > .input-affix-text:first-child {
    border-right: none;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}
.input-affix > .input-affix-text:last-child {
    border-left: none;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}
.input-affix > input:not(:first-child) { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.input-affix > input:not(:last-child) { border-top-right-radius: 0; border-bottom-right-radius: 0; }
/* Compact controls, in table cells and inline forms */
.inline-edit-fields input[type="text"], .inline-add input[type="text"] {
    min-height: 34px; padding: 0.35rem 0.6rem; font-size: 0.8125rem;
}
/* Optional fields end their label with "(optional)" (the form theme adds it); required ones are unmarked */
.optional { font-weight: 400; color: var(--fg-3); }

/* Hand-built fields: <label class="form-label">…</label><input>…<p class="form-hint">…</p> */
.form-label { display: block; margin-bottom: 0.375rem; font-size: 0.8125rem; font-weight: 600; color: var(--fg-1); }
.form-hint { margin-top: 0.25rem; font-size: 0.75rem; line-height: 1.45; color: var(--fg-3); }
.form-hint.form-hint-over { color: var(--tx-red); font-weight: 600; }
.form-actions { display: flex; align-items: center; gap: 0.625rem; margin-top: 0.5rem; }
.card > .card-body.form-actions { margin-top: 0; border-top: 1px solid var(--line-1); }
/* A note above a form (e.g. which other customers a change also applies to) */
.form-note {
    margin-bottom: 1rem;
    padding: 0.6rem 0.8rem;
    border-radius: var(--radius-md);
    background: var(--primary-soft);
    font-size: 0.85rem;
    color: var(--primary-text);
}
/* Uppercase heading with a rule under it, between groups of fields */
.form-section {
    margin: 1.5rem 0 0.875rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--line-1);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--fg-2);
}
.form-section:first-child { margin-top: 0; }
/* A checkbox with its label to the right */
.check-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    color: var(--fg-1);
    cursor: pointer;
}
/* The "Show archived" tick box of a list (ui.show_archived) */
.show-archived { display: inline-flex; align-items: center; gap: 0.5rem; font-size: 0.875rem; }
.show-archived label { display: inline-flex; align-items: center; gap: 0.375rem; cursor: pointer; }

/* Symfony forms rendered with form_widget(form) inside <form class="stacked-form">, usually in a card:
   <div class="card form-card"><div class="card-body"><form class="stacked-form">…
   <div class="form-actions">buttons</div></form></div></div> */
.form-card { max-width: 44rem; }
.stacked-form { display: flex; flex-direction: column; gap: 1rem; max-width: 36rem; }
.stacked-form.wide-form { max-width: 60rem; }
.wide-form .form-card { max-width: none; }
/* (not the searchable select's own markup, the money field's .input-affix, nor the rich text editor) */
.stacked-form div:where(:not(.ts-wrapper, .ts-wrapper *, .input-affix, .rich-editor, .rich-editor *)) {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}
.stacked-form > div { gap: 1rem; } /* the form_widget wrapper around the field rows */
.stacked-form .form-field { gap: 0.375rem; } /* a form theme row: label, hint, errors and field close together */
.stacked-form label { font-size: 0.8125rem; font-weight: 600; color: var(--fg-1); }
/* The hint sits between the label and the field (form theme): tucked under the label, the usual gap before the field */
.stacked-form .form-hint { margin-top: -0.125rem; }
.stacked-form input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):where(:not(.ts-control > input)),
.stacked-form select,
.stacked-form textarea {
    width: 100%;
}
.stacked-form div:not(.checkbox-list):has(> input[type="checkbox"]) {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
}
.stacked-form div:not(.checkbox-list):has(> input[type="checkbox"]) > label { order: 2; font-weight: 500; }
.stacked-form .checkbox-list {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 0.375rem 0.5rem;
}
.stacked-form .checkbox-list label, .stacked-form .check-row { font-weight: 400; }
.stacked-form .check-row { flex-direction: row; }
.stacked-form .form-actions { flex-direction: row; align-items: center; }
.stacked-form .form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem 1.25rem; }
.stacked-form .form-checks { justify-content: center; gap: 0.5rem; }
.stacked-form .btn, .stacked-form .select-all, .stacked-form > a { align-self: flex-start; }
/* The contract form's tolerances: a group for each ticked service, and in it a row for each metric (include, quantity,
   notes). tolerances.js shows and hides the groups. */
.tolerances { border: 0; padding: 0; margin: 0; min-width: 0; display: flex; flex-direction: column; gap: 0.75rem; }
.tolerances legend { padding: 0; margin-bottom: 0.5rem; font-size: 0.8125rem; font-weight: 600; color: var(--fg-1); }
.stacked-form .tolerance-group { gap: 0.5rem; }
.stacked-form .tolerance-group[hidden] { display: none; }
.tolerance-service { font-size: 0.875rem; }
.stacked-form .tolerance-row {
    display: grid; grid-template-columns: minmax(9rem, 1fr) minmax(8rem, 11rem) minmax(0, 1.5fr);
    gap: 0.25rem 0.75rem; align-items: start;
}
.stacked-form .tolerance-row > div { gap: 0.25rem; }
.tolerance-help { grid-column: 1 / -1; margin: 0; }
@media (max-width: 40rem) { .stacked-form .tolerance-row { grid-template-columns: 1fr; } }
/* The tolerance history table: this contract's column is tinted, and a change is signed and coloured (up green, down
   red) */
.tolerance-history .is-current { background: var(--primary-soft); }
.tolerance-history .delta { font-size: 0.8125rem; }
.tolerance-history .delta-up { color: var(--tx-green); }
.tolerance-history .delta-down { color: var(--tx-red); }
.stacked-form > a:not(.btn) { font-size: 0.8125rem; }
@media (max-width: 700px) { .stacked-form .form-grid { grid-template-columns: 1fr; } }

/* Filters: a white card with labelled controls in a row, button at the end.
   <form class="filter-card"><div class="filter-field"><label>Type</label><select>…</select></div> …
   <button class="btn btn-primary">Filter</button></form> */
.filter-card {
    display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.75rem;
    padding: 1rem 1.25rem; margin-bottom: 1.25rem;
    background: var(--bg-surface); border: 1px solid var(--line-1); border-radius: var(--radius-lg);
}
.filter-field { display: flex; flex-direction: column; min-width: 150px; }
.filter-field.grow { flex: 1; min-width: 180px; }
.filter-field label { font-size: 0.75rem; font-weight: 600; color: var(--fg-2); margin-bottom: 4px; }
.filter-card .btn { min-height: 40px; }
/* A tick box in the filter row, such as "Show archived" */
.filter-check {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    min-height: 40px;
    font-size: 0.875rem;
    cursor: pointer;
}
/* A filter set from elsewhere with no control of its own (customer list's system); the link removes it */
.filter-chip {
    display: inline-flex; align-items: center; gap: 0.35rem; min-height: 40px; padding: 0 0.75rem;
    border: 1px solid var(--primary-line); border-radius: var(--radius-pill); background: var(--primary-soft);
    font-size: 0.8125rem; font-weight: 600; color: var(--primary-text); text-decoration: none; white-space: nowrap;
}
.filter-chip:hover { border-color: var(--primary); text-decoration: none; }
/* Blocks under the filters that pick one value (customer list's localities): a count over a name; the chosen one is
   solid blue.
   <nav class="locality-blocks"><a class="locality-block active"><span class="locality-count">12</span>
   <span class="locality-name">Hull</span></a> …</nav> */
.locality-blocks {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}
.locality-block {
    display: flex; flex-direction: column; gap: 0.2rem; padding: 0.875rem 1rem; min-width: 0;
    background: var(--bg-surface); border: 1px solid var(--line-1); border-radius: var(--radius-md);
    color: inherit; text-decoration: none;
    transition: box-shadow var(--dur-base) var(--ease-out), border-color var(--dur-base) var(--ease-out);
}
.locality-block:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
    text-decoration: none;
    color: inherit;
}
.locality-count {
    font-family: var(--font-display);
    font-size: 1.375rem;
    font-weight: 800;
    letter-spacing: -0.04em;
    line-height: 1;
    color: var(--fg-1);
}
.locality-name { font-size: 0.75rem; font-weight: 600; color: var(--fg-2); overflow-wrap: break-word; }
.locality-block.active { background: var(--primary); border-color: var(--primary); }
.locality-block.active .locality-count, .locality-block.active .locality-name { color: #fff; }
/* A locality with a colour (--locality, and --locality-text for text on it): a coloured top edge, solid when chosen */
.locality-block.coloured { border-top: 4px solid var(--locality); }
.locality-block.coloured:hover { border-color: var(--locality); }
.locality-block.coloured.active { background: var(--locality); border-color: var(--locality); }
.locality-block.coloured.active .locality-count,
.locality-block.coloured.active .locality-name { color: var(--locality-text); }
@media (max-width: 600px) { .locality-blocks { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* Tabs: a white pill bar; the active tab is solid blue */
.tab-bar {
    display: flex; align-items: center; padding: 4px; margin-bottom: 1.5rem; overflow-x: auto; flex-shrink: 0;
    background: var(--bg-surface);
    border: 1px solid var(--line-1);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xs);
}
.tab-bar > a {
    position: relative; display: flex; align-items: center; gap: 0.35rem; flex-shrink: 0;
    padding: 0.45rem 1rem; border-radius: var(--radius-sm);
    font-size: 0.8125rem; font-weight: 500; color: var(--fg-2); text-decoration: none; white-space: nowrap;
    transition: color var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
}
.tab-bar > a + a::before {
    content: '';
    position: absolute;
    left: 0;
    top: 20%;
    height: 60%;
    width: 1px;
    background: var(--line-1);
}
.tab-bar > a.active::before, .tab-bar > a.active + a::before { display: none; }
.tab-bar > a.active { background: var(--primary); color: #fff; font-weight: 600; }
.tab-bar > a:hover:not(.active) { color: var(--fg-1); background: var(--bg-page); text-decoration: none; }
.tab-bar .icon { opacity: 0.7; }
.tab-bar .active .icon { opacity: 1; }
.tab-count { font-size: 0.7rem; font-weight: 700; opacity: 0.7; }

/* Flash messages and notices: <div class="alert alert-success">{{ ui.icon('check-circle') }} <span>…</span></div>
   Types: alert-success, -error, -warning, -info */
.alert {
    display: flex; align-items: flex-start; gap: 0.625rem; margin-bottom: 1.25rem;
    padding: 0.875rem 1rem; border: 1px solid; border-radius: var(--radius-sm); font-size: 0.875rem; line-height: 1.4;
}
.alert[hidden] { display: none; }
.alert > .icon { width: 16px; height: 16px; margin-top: 1px; }
.alert-success { background: var(--success-soft); border-color: var(--success-line); color: var(--success-ink); }
.alert-error   { background: var(--danger-soft); border-color: var(--danger-line); color: var(--danger-ink); }
.alert-warning { background: var(--warning-soft); border-color: var(--warning-line); color: var(--warning-ink); }
.alert-info    { background: var(--primary-soft); border-color: var(--primary-line); color: var(--primary-text); }
:where(:root[data-theme="dark"]) { .alert-info { border-color: transparent; color: var(--fg-1); } }
/* A hint line with an icon, above a tab's content */
.hint {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 1rem;
    font-size: 0.8125rem;
    color: var(--fg-3);
}

/* Empty state: <div class="card empty-state">{{ ui.icon('inbox', 28) }}<p class="empty-state-title">No tasks</p>
   <p>Add one with the button above.</p></div> */
.empty-state { padding: 2.5rem 1.5rem; text-align: center; color: var(--fg-3); font-size: 0.875rem; }
.empty-state > .icon { color: var(--line-2); margin-bottom: 0.75rem; }
.empty-state-title { font-family: var(--font-display); font-size: 0.9375rem; font-weight: 700; color: var(--fg-1); }
.empty-state .btn { margin-top: 1rem; }

/* Modal dialogs (<dialog>): the confirm dialog in the layout, and the icon picker */
.dialog {
    margin: auto;
    padding: 1.5rem;
    border: 1px solid var(--line-1);
    border-radius: var(--radius-lg);
    background: var(--bg-surface);
    color: var(--fg-1);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.dialog p { margin: 0 0 1.25rem; font-size: 0.95rem; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; }
.dialog-btns { display: flex; justify-content: flex-end; gap: 0.5rem; }
.confirm-dialog { width: min(26rem, calc(100vw - 2rem)); }

/* Detail lists: <dl class="detail-list"> with <dt>/<dd> pairs, in two columns (label, value).
   .detail-grid puts each pair in a grid cell (wrap each in a <div>), label above value. */
.detail-list { display: grid; grid-template-columns: max-content 1fr; gap: 0.625rem 2rem; font-size: 0.875rem; }
.detail-list dt {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--fg-3);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding-top: 0.1rem;
}
.detail-list dd { overflow-wrap: anywhere; }
.detail-list.detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem 2rem; }
.detail-grid dt, .detail-label {
    margin-bottom: 0.35rem;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--fg-3);
}
.detail-grid dd { font-size: 0.9375rem; }
.detail-grid dd strong, .detail-grid .plain-link { font-weight: 700; }
.detail-grid .col-first { grid-column-start: 1; }
.detail-sep { grid-column: 1 / -1; height: 1px; background: var(--line-1); }
.detail-sub { display: block; margin-top: 0.35rem; font-size: 0.75rem; color: var(--fg-3); }
@media (max-width: 900px) {
    .detail-list.detail-grid { grid-template-columns: minmax(0, 1fr); }
}

/* Chart cards: a heading row (title, link or note on the right), then a canvas in .chart-box */
.chart-card {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 18rem;
    padding: 1.25rem;
    background: var(--bg-surface);
    border: 1px solid var(--line-1);
    border-radius: var(--radius-md);
}
.chart-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.chart-card-head h2 { font-size: 0.8125rem; font-weight: 700; }
.chart-card-head a, .chart-card-aside { font-size: 0.72rem; color: var(--fg-3); white-space: nowrap; }
.chart-card-head a { color: var(--primary-text); }
.chart-box { position: relative; flex: 1; min-height: 12rem; }
/* Out of the flow, so the canvas (which Chart.js sizes to the box) never holds the box open: otherwise opening and
   closing "Show data" would leave the box at its taller size, growing it each time (#272) */
.chart-box > canvas { position: absolute; inset: 0; }
.chart-empty { padding: 2rem 1rem; text-align: center; font-size: 0.8125rem; color: var(--fg-3); }
/* A chart's figures (templates/_charts.html.twig): "Show data" under the canvas opens them as a small table */
.chart-data { margin-top: 0.75rem; font-size: 0.75rem; }
.chart-data > summary {
    width: fit-content;
    min-height: 24px;
    cursor: pointer;
    color: var(--primary-text);
    font-weight: 600;
}
.chart-data-table { width: 100%; margin-top: 0.5rem; border-collapse: collapse; color: var(--fg-1); }
.chart-data-table th, .chart-data-table td {
    padding: 0.3rem 0.5rem;
    border-bottom: 1px solid var(--line-1);
    text-align: left;
}
.chart-data-table thead th { color: var(--fg-3); font-weight: 600; }
.chart-data-table tbody th { font-weight: 500; }
.chart-data-table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* Contract master calendar: the financial year's four quarters side by side, each listing the contracts ending in it */
.calendar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.calendar-head h2 { font-size: 1rem; font-weight: 700; text-align: center; }
.quarter-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; align-items: start; }
@media (max-width: 1100px) { .quarter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 600px)  { .quarter-grid { grid-template-columns: minmax(0, 1fr); } }
.quarter {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 0;
    padding: 0.75rem;
    background: var(--bg-surface);
    border: 1px solid var(--line-1);
    border-radius: var(--radius-md);
}
.quarter-head { display: flex; align-items: baseline; gap: 0.5rem; padding: 0 0.25rem 0.25rem; }
.quarter-head h3 { font-size: 0.9375rem; font-weight: 700; }
.quarter-months { flex: 1; font-size: 0.75rem; color: var(--fg-3); }
.quarter-contract {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    padding: 0.6rem 0.75rem;
    background: var(--bg-surface-2);
    border: 1px solid var(--line-1);
    border-radius: var(--radius-sm);
    color: inherit;
}
.quarter-contract:hover { border-color: var(--primary); text-decoration: none; color: inherit; }
.quarter-contract-holder { font-size: 0.8125rem; font-weight: 600; color: var(--fg-1); overflow-wrap: anywhere; }
.quarter-contract-ref { font-size: 0.75rem; color: var(--fg-2); overflow-wrap: anywhere; }
.quarter-contract-foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.35rem;
    margin-top: 0.25rem;
    font-size: 0.72rem;
    color: var(--fg-3);
}
.quarter-empty { padding: 1rem 0.25rem; font-size: 0.78rem; color: var(--fg-3); }

/* Doughnut with its legend beside it (below it on narrow screens) */
.donut-with-legend { display: flex; align-items: center; justify-content: space-between; gap: 1.25rem; flex: 1; }
.donut-box { position: relative; width: 210px; height: 210px; flex-shrink: 1; margin: 0 auto; }
.chart-legend { list-style: none; display: flex; flex-direction: column; gap: 0.5rem; padding-right: 15px; }
.chart-legend li {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.78rem;
    color: var(--fg-2);
    white-space: nowrap;
}
.chart-legend strong { font-weight: 600; color: var(--fg-1); }
.legend-swatch { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
@media (max-width: 600px) {
    .donut-with-legend { flex-direction: column; }
    .chart-legend li { white-space: normal; }
}

/* Date bands: how soon a date is, as colours for a row, a date and its pill, and a key.
   Set a band class (band-expired, -urgent, -soon, -later, -safe, -closed) on the row or element; the parts read its
   variables.
   <tr class="banded band-soon"> …
   <span class="band-date">12 May 2026 <span class="pill band-pill">45d left</span></span> */
.band-expired {
    --band-edge: #ef4444;
    --band-row: #fff5f5;
    --band-ink: #991b1b;
    --band-tint: #fef2f2;
    --band-line: #fca5a5;
}
.band-urgent {
    --band-edge: #f97316;
    --band-row: #fff5f5;
    --band-ink: #991b1b;
    --band-tint: #fef2f2;
    --band-line: #fca5a5;
}
.band-soon {
    --band-edge: #f59e0b;
    --band-row: #fffdf0;
    --band-ink: #92400e;
    --band-tint: #fffbeb;
    --band-line: #fcd34d;
}
.band-later {
    --band-edge: #fb923c;
    --band-row: #fffaf5;
    --band-ink: #78350f;
    --band-tint: #fff7ed;
    --band-line: #fed7aa;
}
.band-safe {
    --band-edge: #22c55e;
    --band-row: #f6fff9;
    --band-ink: #14532d;
    --band-tint: #f0fdf4;
    --band-line: #86efac;
}
.band-closed {
    --band-edge: #d1d5db;
    --band-row: transparent;
    --band-ink: var(--fg-2);
    --band-tint: var(--tint-grey);
    --band-line: var(--line-1);
}
:where(:root[data-theme="dark"]) {
    .band-expired, .band-urgent, .band-soon, .band-later, .band-safe, .band-closed {
        --band-row: var(--bg-surface-2);
        --band-ink: var(--fg-1);
        --band-tint: var(--bg-surface-2);
        --band-line: var(--line-2);
    }
}
.banded td { background: var(--band-row); }
.banded td:first-child { box-shadow: inset 3px 0 0 var(--band-edge); }
.band-date { display: inline-flex; align-items: center; gap: 0.4rem; font-weight: 600; color: var(--band-ink); }
.band-pill { background: var(--band-tint); border: 1px solid var(--band-line); color: var(--band-ink); }
.band-key { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem; margin-top: 1rem; font-size: 0.75rem; }
.band-key-title { font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--fg-3); }
.band-key-item {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding-left: 0.4rem;
    border-left: 4px solid var(--band-edge);
    font-weight: 500;
    color: var(--band-ink);
}
.band-key-item::before {
    content: '';
    width: 14px;
    height: 14px;
    border-radius: 3px;
    background: var(--band-row);
    border: 1px solid var(--band-edge);
}

/* Services: an icon in the service colour, and a row of them */
.service-icon { display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.service-icons { display: flex; flex-wrap: wrap; gap: 0.5rem; }

/* Tones: a pale background and a readable text colour, for icon squares and pills */
.tone-blue      { background: var(--tint-blue); color: var(--tx-blue); }
.tone-green     { background: var(--tint-green); color: var(--tx-green); }
.tone-purple    { background: var(--tint-purple); color: var(--tx-purple); }
.tone-amber     { background: var(--tint-amber); color: var(--tx-amber); }
.tone-red       { background: var(--tint-red); color: var(--tx-red); }
.tone-orange    { background: var(--tint-orange); color: var(--tx-orange); }
.tone-pink      { background: var(--tint-pink); color: var(--tx-pink); }
.tone-teal      { background: var(--tint-teal); color: var(--tx-teal); }
.tone-turquoise { background: var(--tint-turquoise); color: var(--tx-turquoise); }
.tone-grey      { background: var(--tint-grey); color: var(--tx-grey); }

/* ── 5. Pages ── */

/* Login (no sidebar): a navy brand panel with the logo beside the sign-in panel; on narrow screens the brand panel is a
   header strip above it */
.login-page {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 4fr);
    min-height: 100vh;
    background: var(--bg-page);
}
.login-brand {
    position: relative; overflow: hidden; display: flex; align-items: center; gap: 1.5rem; padding: 4rem;
    background: var(--bg-sidebar); color: #fff;
}
/* Faint rings echoing the logo's interlocking circles */
.login-brand::before, .login-brand::after {
    content: '';
    position: absolute;
    width: 640px;
    height: 640px;
    border-radius: 50%;
    border: 56px solid rgba(92, 180, 220, 0.08);
}
.login-brand::before { right: -260px; bottom: -220px; }
.login-brand::after { right: -40px; bottom: -340px; border-color: rgba(246, 137, 31, 0.07); }
.login-brand-logo { position: relative; width: 112px; height: 112px; }
.login-brand-name {
    position: relative;
    font-family: var(--font-display);
    font-size: 4.5rem;
    font-weight: 800;
    line-height: 1;
    letter-spacing: 0.04em;
}
.login-body { display: flex; align-items: center; padding: 4rem; }
.login-form { width: 100%; max-width: 360px; }
.login-form h1 {
    font-family: var(--font-display);
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.2;
    color: var(--fg-1);
}
.login-lead { margin: 0.5rem 0 2rem; font-size: 0.9375rem; color: var(--fg-2); }
.login-form .alert { margin-bottom: 1rem; }
.btn.login-sso {
    width: 100%;
    min-height: 48px;
    gap: 0.625rem;
    padding: 0.75rem 1.25rem;
    border-radius: 10px;
    font-size: 0.9375rem;
    font-weight: 700;
    white-space: normal;
}
.btn.login-sso .icon { width: 18px; height: 18px; }
.login-help {
    display: flex; gap: 0.75rem; margin-top: 2rem; padding: 1rem; border-radius: 10px;
    background: var(--bg-surface-2); font-size: 0.8125rem; line-height: 1.55; color: var(--fg-2);
}
.login-help .icon { flex: none; margin-top: 1px; color: var(--primary-text); }
.login-help strong { display: block; color: var(--fg-1); }
.login-help a { text-decoration: underline; text-underline-offset: 2px; }
@media (max-width: 760px) {
    .login-page { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
    .login-brand { gap: 1rem; padding: 2rem 1.25rem; }
    .login-brand-logo { width: 56px; height: 56px; }
    .login-brand-name { font-size: 2.25rem; }
    .login-body { align-items: flex-start; padding: 2rem 1.25rem; }
}

/* Dashboard: tiles, chart cards, and the expiring contracts and my tasks lists */
.dashboard-tiles { grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); }
.dashboard-row { margin-bottom: 1.75rem; }
.list-card { padding: 0; overflow: hidden; min-height: 0; }
.dashboard-row:has(> .list-card) { align-items: start; }
.list-card .chart-card-head { margin: 0; padding: 1rem 1.25rem; border-bottom: 1px solid var(--line-1); }
/* A row in a list card: main text (link + small line) on the left, anything else on the right */
.list-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1.25rem;
    border-bottom: 1px solid var(--line-1);
}
.list-row:last-child { border-bottom: 0; }
.list-row.unread { box-shadow: inset 3px 0 0 var(--primary); background: var(--primary-soft); }
.list-row-main { flex: 1; min-width: 0; }
.list-row-main a {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--fg-1);
}
.list-row-main span, .list-row-side span:not(.badge) {
    display: block;
    margin-top: 1px;
    font-size: 0.72rem;
    color: var(--fg-3);
}
.list-row-side { text-align: right; flex-shrink: 0; }
.list-row.banded {
    padding-left: calc(1.25rem - 3px);
    border-left: 3px solid var(--band-edge);
    background: var(--band-row);
}
.list-row.activity { align-items: flex-start; }
.list-row.activity .list-row-main a { font-weight: 500; }
.activity-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; }
.dot-red { background: #dc2626; } .dot-orange { background: #ea580c; } .dot-amber { background: #d97706; }

/* Customer record: header (parent, title, known as, child organisations, pills) and the tab bar */
.record-header { min-width: 0; }
.record-relation {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--fg-3);
}
.record-parent { margin-bottom: 0.25rem; }
.record-known-as { margin-top: 0.15rem; font-size: 0.8125rem; color: var(--fg-3); }
.ods-code { font-weight: 600; color: var(--fg-3); }
/* The child organisations popout: the summary toggles a scrolling list below it */
.record-children { position: relative; margin-top: 0.35rem; }
.record-children > summary { width: fit-content; min-height: 24px; cursor: pointer; list-style: none; }
.record-children > summary::-webkit-details-marker { display: none; }
.record-children > summary:hover { color: var(--fg-1); }
.record-children-list {
    position: absolute;
    z-index: 20;
    top: calc(100% + 0.35rem);
    left: 0;
    min-width: 260px;
    max-width: min(420px, calc(100vw - 2rem));
    max-height: 320px;
    overflow-y: auto;
    padding: 0.35rem;
    list-style: none;
    background: var(--bg-surface);
    border: 1px solid var(--line-1);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}
.record-children-list li { padding: 0.4rem 0.6rem; border-radius: var(--radius-sm); font-size: 0.875rem; }
.record-children-list li:has(a:hover) { background: var(--bg-surface-2); }
/* The tab bar with the record's reopen and delete actions at its right end */
.record-nav { display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.75rem; }
.record-nav .record-tabs { flex: 1; min-width: 0; margin-bottom: 0; }
.record-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    padding-top: 5px;
}
@media (max-width: 900px) { .record-nav { flex-direction: column; align-items: stretch; } }
/* More tabs than fit on one line, so they sit in an even grid that wraps rather than scroll out of sight */
.record-tabs {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr));
    padding: 5px;
    gap: 3px;
    margin-bottom: 1.75rem;
}
.record-tabs > a { justify-content: center; padding: 0.5rem; font-size: 0.8rem; color: var(--fg-3); }
.record-tabs > a + a::before { display: none; }
.record-tabs > a.active {
    background: var(--bg-page);
    color: var(--n3i-dark-blue-700);
    font-weight: 700;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 0 0 1px rgba(0, 0, 0, 0.04);
}
.record-tabs .icon { opacity: 0.5; }
.record-tabs .tab-count { font-size: inherit; font-weight: inherit; opacity: 1; }
:where(:root[data-theme="dark"]) { .record-tabs > a.active { color: var(--fg-1); } }

/* Overview tab: pinned notes, then details (left) beside sites and contacts (right) */
.pinned-notes { margin-bottom: 1.25rem; padding: 1.1rem 1.25rem; border-color: #fde68a; }
.pinned-notes-title {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-bottom: 0.625rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--tx-amber);
}
.pinned-note {
    padding: 0.625rem 0.75rem;
    margin-top: 0.5rem;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: var(--radius-sm);
}
.pinned-note p { font-size: 0.8125rem; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.pinned-notes-more { margin-top: 0.625rem; font-size: 0.8125rem; }
.pinned-note .pinned-note-meta { margin-top: 0.375rem; font-size: 0.7rem; color: var(--fg-3); }
:where(:root[data-theme="dark"]) {
    .pinned-note { background: var(--bg-surface-2); border-color: var(--line-2); }
    .pinned-notes { border-color: var(--line-2); }
}
.overview-grid {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    gap: 1.25rem;
    align-items: start;
}
@media (max-width: 900px) { .overview-grid { grid-template-columns: minmax(0, 1fr); } }
/* A card heading with a rule running to the buttons on the right */
.overview-card-head { display: flex; align-items: center; gap: 1rem; padding: 1.25rem 1.25rem 0; }
.overview-card-head h2 { font-size: 1.25rem; font-weight: 800; white-space: nowrap; }
.overview-card-rule { flex: 1; height: 1px; background: var(--line-1); }
#overview-map { height: 200px; margin: 1rem 1.25rem 0; border-radius: var(--radius-md); background: var(--bg-page); }
/* The Sites and Contacts cards: one section per site or contact (primary first) */
.overview-entry + .overview-entry { margin-top: 1.25rem; padding-top: 1.25rem; border-top: 1px solid var(--line-1); }
.overview-entry-name {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 0.75rem;
    font-family: var(--font-sans);
    font-size: 0.9375rem;
    font-weight: 700;
}
.overview-entry-name:has(+ .overview-entry-sub) { margin-bottom: 0.15rem; }
.overview-entry-sub { margin-bottom: 0.75rem; font-size: 0.8125rem; color: var(--fg-2); }
.overview-entry-pills { margin-bottom: 0.75rem; }
/* The Sites card's groups: the primary site, then the branches */
.overview-group-label {
    margin: 1.5rem 0 0.75rem;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--fg-2);
}
.overview-group-label:first-child { margin-top: 0; }
.detail-list.overview-entry-details { grid-template-columns: minmax(0, 1fr); gap: 0.85rem; }
.overview-entry-details address { font-style: normal; line-height: 1.55; }
.overview-entry-actions { margin-top: 0.85rem; flex-wrap: wrap; }
.site-unmapped {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    margin-top: 0.35rem;
    font-size: 0.75rem;
    color: var(--warning-ink);
}

/* Notes tab */
.note { display: flex; align-items: flex-start; gap: 0.75rem; padding: 1rem 1.25rem; }
.note-pinned { border-left: 3px solid #d97706; }
.note-body { flex: 1; min-width: 0; }
.note-pin-label {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    margin-bottom: 0.375rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--tx-amber);
}
.note-content { font-size: 0.875rem; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.note-meta { margin-top: 0.5rem; font-size: 0.75rem; color: var(--fg-3); }

/* Account tab: a card per meeting, with its actions as a checklist */
.toolbar-sub { margin-top: 0.125rem; font-size: 0.8125rem; color: var(--fg-3); }
.meeting { padding: 1rem 1.25rem; }
.meeting-head { display: flex; align-items: flex-start; gap: 0.875rem; }
.meeting-date {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    min-width: 3.25rem;
    padding: 0.375rem 0.5rem;
    border-radius: var(--radius-sm);
    background: var(--primary-soft);
    color: var(--primary-text);
    line-height: 1.1;
}
.meeting-day { font-family: var(--font-display); font-size: 1.25rem; font-weight: 700; }
.meeting-month { font-size: 0.6875rem; font-weight: 600; white-space: nowrap; }
.meeting-heading { flex: 1; min-width: 0; }
.meeting-title {
    font-family: var(--font-display);
    font-size: 0.9375rem;
    font-weight: 700;
    color: var(--fg-1);
    overflow-wrap: anywhere;
}
.meeting-heading .note-meta { margin-top: 0.125rem; }
.meeting-notes { margin-top: 0.875rem; }
.meeting-actions { margin-top: 1rem; padding-top: 0.875rem; border-top: 1px solid var(--line-1); }
.meeting-actions-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--fg-2);
}
.meeting-actions-title span { font-weight: 500; text-transform: none; letter-spacing: 0; color: var(--fg-3); }
.meeting-no-actions { margin-top: 0.375rem; font-size: 0.8125rem; }
.checklist { list-style: none; display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.625rem; }
.checklist-item { display: flex; align-items: flex-start; gap: 0.625rem; }
.checklist-item form { display: flex; }
.checklist-tick {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    margin-top: 1px;
    padding: 0;
    flex-shrink: 0;
    border: 2px solid var(--line-2);
    border-radius: var(--radius-xs);
    background: var(--bg-surface);
    color: #fff;
    cursor: pointer;
}
.checklist-tick:hover { border-color: var(--tx-green); }
.checklist-tick[aria-pressed="true"] {
    border-color: var(--tx-green);
    background: var(--tx-green);
    color: var(--bg-surface);
}
.checklist-body { flex: 1; min-width: 0; }
.checklist-text { display: block; font-size: 0.875rem; color: var(--fg-1); overflow-wrap: anywhere; }
.is-done .checklist-text { color: var(--fg-3); text-decoration: line-through; }
.checklist-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 0.875rem;
    margin-top: 0.125rem;
    font-size: 0.75rem;
    color: var(--fg-3);
}
.checklist-meta > span { display: inline-flex; align-items: center; gap: 0.25rem; }

/* Meeting form: its actions, a row of fields each */
.stacked-form .action-list {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}
.stacked-form .action-list > legend {
    margin-bottom: 0.25rem;
    padding: 0;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--fg-1);
}
.action-rows { list-style: none; display: flex; flex-direction: column; gap: 0.625rem; }
.action-rows:empty { display: none; }
.action-row {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem;
    border: 1px solid var(--line-1);
    border-radius: var(--radius-sm);
    background: var(--bg-surface-2);
}
.action-row fieldset { flex: 1; min-width: 0; margin: 0; padding: 0; border: 0; }
.stacked-form .action-fields {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1.25fr) minmax(0, 1fr) auto;
    align-items: start;
    gap: 0.75rem;
}
.stacked-form .action-fields > div:has(> input[type="checkbox"]) { align-self: center; margin-top: 1.5rem; }
.action-row > .btn { margin-top: 1.5rem; }
@media (max-width: 900px) {
    .stacked-form .action-fields { grid-template-columns: 1fr 1fr; }
    .stacked-form .action-fields > div:first-child { grid-column: 1 / -1; }
    .stacked-form .action-fields > div:has(> input[type="checkbox"]) { margin-top: 0; }
}

/* Top bar tasks menu: the user's open tasks, with a count of the overdue and due-today ones on the button */
.tasks-btn { position: relative; }
.topbar-badge {
    position: absolute;
    top: -5px;
    right: -6px;
    min-width: 17px;
    height: 17px;
    padding: 0 4px;
    border-radius: var(--radius-pill);
    font-size: 0.625rem;
    font-weight: 700;
    line-height: 17px;
    text-align: center;
    color: #fff;
    border: 2px solid var(--bg-surface);
    box-sizing: content-box;
}
.topbar-badge-red { background: #b91c1c; }
.topbar-badge-amber { background: #b45309; }
.tasks-menu { width: min(24rem, calc(100vw - 2rem)); }
.tasks-menu .menu-header small { text-transform: none; }
.tasks-menu-list { list-style: none; max-height: min(26rem, 70vh); overflow-y: auto; }
.tasks-menu-item {
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
    padding: 0.625rem 1rem;
    border-bottom: 1px solid var(--line-1);
}
.tasks-menu-item:last-child { border-bottom: 0; }
.tasks-menu-main { flex: 1; min-width: 0; font-size: 0.75rem; color: var(--fg-3); }
.tasks-menu-main a {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--fg-1);
    overflow-wrap: anywhere;
}
.tasks-menu-main span { display: block; margin-top: 1px; }
.tasks-menu-item form { flex-shrink: 0; }
.tasks-menu-empty { padding: 1rem; font-size: 0.8125rem; color: var(--fg-3); text-align: center; }
.tasks-menu-more { padding: 0.5rem 1rem 0.75rem; font-size: 0.75rem; color: var(--fg-3); text-align: center; }
.dot-grey { background: var(--line-2); }

/* The customer's Services card: one card per service; the icon circle takes the service colour when the customer
   has it */
.service-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1rem; }
.service-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.625rem;
    min-height: 148px;
    padding: 1.25rem 0.875rem;
    border: 2px solid var(--line-1);
    border-radius: var(--radius-md);
    background: var(--bg-page);
    text-align: center;
}
.service-card.active { border-color: var(--primary); background: var(--bg-surface); }
.service-card-icon {
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--line-1);
}
.service-name { font-size: 0.875rem; font-weight: 600; line-height: 1.3; }
.service-state { font-size: 0.72rem; }

/* Members tab */
.inline-link-form { display: flex; align-items: center; gap: 0.5rem; }
.inline-link-form select, .inline-link-form .ts-wrapper { width: 22rem; max-width: 100%; }

/* Customer list: room for the name, so the ODS code and name sit on one line */
.customer-col { min-width: 16rem; }
.customer-col .ods-code { display: block; font-size: 0.75rem; }
.customer-cell { display: flex; align-items: center; gap: 0.75rem; }
.record-title { display: flex; align-items: center; gap: 0.5rem; }

/* A customer's square icon (customers/_icon.html.twig): an uploaded or built-in image, or a Lucide icon or the
   name's initial on a tile */
.customer-icon { flex: none; display: block; border-radius: var(--radius-sm); object-fit: cover; }
.customer-icon-tile {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-soft);
    color: var(--primary-text);
    font-family: var(--font-display);
    font-weight: 700;
    line-height: 1;
}

/* Customer form: the icon choices as tiles, and the crop dialog */
.icon-options { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0 0 1rem; padding: 0; border: 0; }
.icon-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    width: 5.5rem;
    padding: 0.5rem 0.25rem;
    border: 1px solid var(--line-1);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    font-size: 0.75rem;
    text-align: center;
    cursor: pointer;
}
.icon-option:hover { border-color: var(--line-2); background: var(--bg-surface-2); }
.icon-option:has(:checked) {
    border-color: var(--primary);
    background: var(--primary-soft);
    box-shadow: inset 0 0 0 1px var(--primary);
}
.icon-option:has(:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.icon-option-tile {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    background: var(--primary-soft);
    color: var(--primary-text);
    overflow: hidden;
}
.icon-option-tile img { display: block; width: 40px; height: 40px; object-fit: cover; }
.crop-dialog { width: min(36rem, calc(100vw - 2rem)); }
.crop-dialog[open] { display: flex; flex-direction: column; gap: 1rem; }
.crop-dialog p { margin: 0; }
.crop-area { height: min(60vh, 24rem); background: var(--bg-surface-2); }
.crop-area img { display: block; max-width: 100%; }

/* Tasks: a row of filter pills (links) */
.pill-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-bottom: 1.5rem; }
.pill-filters-divider { width: 1px; height: 20px; margin: 0 0.25rem; background: var(--line-1); }

/* A bold figure in a table cell */
.figure { font-size: 0.9375rem; font-weight: 800; }

/* Sites map view: List | Map tabs, type pills (toggle a type's markers), pins in the type colour, popups (always
   light, as Leaflet draws them) */
.view-tabs { display: inline-flex; margin-bottom: 1rem; }
.map-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-bottom: 1rem; }
.map-toolbar-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--fg-3);
}
.type-pill {
    --pill: #64748b;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.75rem;
    border-radius: var(--radius-pill);
    cursor: pointer;
    user-select: none;
    font-family: inherit; font-size: 0.78rem; font-weight: 600; color: var(--fg-1);
    background: color-mix(in srgb, var(--pill) 13%, transparent);
    border: 2px solid color-mix(in srgb, var(--pill) 27%, transparent);
    transition: opacity var(--dur-fast), border-color var(--dur-fast);
}
/* not opacity: unreadable */
.type-pill.off {
    background: transparent;
    border-style: dashed;
    color: var(--fg-3);
    text-decoration: line-through;
}
.type-pill.off .type-pill-dot { opacity: 0.4; }
.type-pill-all { background: var(--tint-grey); border-color: var(--line-1); }
.type-pill-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--pill); }
.type-pill-count { font-size: 0.68rem; }
.map-count { font-size: 0.8125rem; color: var(--fg-3); }
.map-unlocated { margin: 0 0 1rem; font-size: 0.8125rem; color: var(--warning-ink); }
#map {
    height: calc(100vh - 260px);
    min-height: 480px;
    border: 1px solid var(--line-1);
    border-radius: var(--radius-md);
    z-index: 0;
}
.map-popup { min-width: 180px; font-family: var(--font-sans); }
.map-popup-badge {
    display: inline-block;
    margin-bottom: 4px;
    padding: 0.1rem 0.45rem;
    border-radius: var(--radius-pill);
    font-size: 0.68rem;
    font-weight: 700;
    color: #fff;
}
.map-popup-name { margin-bottom: 4px; font-size: 0.9rem; font-weight: 700; color: #1e293b; }
.map-popup-name a { color: inherit; }
.map-popup-primary {
    padding: 0.1rem 0.35rem;
    border-radius: var(--radius-pill);
    background: #0057a8;
    font-size: 0.65rem;
    font-weight: 600;
    color: #fff;
}
.map-popup-meta { font-size: 0.78rem; line-height: 1.5; color: #64748b; }
.map-popup-meta a { color: #0057a8; }

/* Admin: dropdown lists (a label that turns into a text field on Edit), service icon picker */
/* fixed, so the columns keep their widths while a label is edited */
.option-table { table-layout: fixed; min-width: 48rem; }
.option-table td { padding: 0.5rem 1rem; }
.option-table .col-reorder { width: 7.5rem; }
.option-table .col-status { width: 7rem; }
.option-table .col-actions { width: 8.5rem; }
.inline-edit { display: flex; flex-direction: column; gap: 0.25rem; }
.inline-edit-view, .inline-edit-fields { display: flex; align-items: center; gap: 0.5rem; }
.inline-edit-fields { flex-wrap: wrap; }
.inline-edit-view[hidden], .inline-edit-fields[hidden] { display: none; }
.inline-edit-fields input[type="text"] { flex: 1 1 8rem; min-width: 0; }
.inline-edit-fields .colour-picker { flex: 0 1 auto; min-width: 0; } /* the swatches wrap, not the buttons */
.inline-edit-text { min-width: 0; overflow-wrap: anywhere; }
.inline-edit-error { font-size: 0.8125rem; color: var(--danger-ink); }
.inline-edit-error:empty { display: none; }
.inline-add { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.inline-add input[type="text"] { width: 18rem; max-width: 100%; }

/* Customer type colours: the picker on the admin list, and the colour at the left of customer list rows */
.option-colour { width: 14px; height: 14px; border-radius: var(--radius-xs); flex-shrink: 0; }
.colour-picker { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; }
.colour-picker input[type="color"] {
    width: 2.25rem;
    height: 2rem;
    padding: 0.125rem;
    border: 1px solid var(--line-2);
    border-radius: var(--radius-xs);
    background: var(--bg-surface);
    cursor: pointer;
}
.colour-swatches { display: inline-flex; flex-wrap: wrap; gap: 0.375rem; }
.colour-swatches[hidden] { display: none; }
.colour-swatch {
    width: 20px;
    height: 20px;
    padding: 0;
    border: none;
    border-radius: var(--radius-xs);
    cursor: pointer;
}
.colour-swatch:focus-visible { outline-offset: 2px; }
.colour-swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--bg-surface), 0 0 0 4px var(--fg-1); }
/* The customer list's status bar: its own narrow first column, so the tooltip is on the bar alone */
.data-table .status-edge-col, .data-table td.status-edge { width: 6px; min-width: 6px; padding: 0; }
/* As specific as the row hover rule above, and after it, so the bar keeps its colour under the pointer */
.data-table tbody tr td.status-edge-active { background: var(--customer-status-active); }
.data-table tbody tr td.status-edge-prospect { background: var(--customer-status-prospect); }
.data-table tbody tr td.status-edge-churned { background: var(--customer-status-churned); }
.data-table tbody tr td.status-edge-closed,
.data-table tbody tr td.status-edge-merged { background: var(--customer-status-closed); }
.title-with-icon { display: inline-flex; align-items: center; gap: 0.75rem; }
.icon-field { display: flex; flex-direction: column; gap: 0.375rem; }
.stacked-form .icon-field-row { flex-direction: row; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.icon-preview {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border: 1px solid var(--line-1);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
}
.icon-preview.is-default { opacity: 0.5; border-style: dashed; }
.icon-dialog { width: min(40rem, calc(100vw - 2rem)); max-height: calc(100vh - 4rem); }
.icon-dialog[open] { display: flex; flex-direction: column; gap: 1rem; }
.icon-dialog p { margin: 0; }
.icon-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(3rem, 1fr));
    gap: 0.5rem;
    max-height: 50vh;
    overflow-y: auto;
    padding: 2px;
}
.icon-choice {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 3rem;
    padding: 0;
    border: 1px solid var(--line-1);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--fg-1);
    cursor: pointer;
}
.icon-choice:hover { background: var(--bg-surface-2); border-color: var(--focus); }

/* Feedback: the top bar's "Submit feedback" dialog (and its form on a page of its own), and the admin pages */
.feedback-dialog { width: min(34rem, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); }
.feedback-dialog[open] { display: flex; flex-direction: column; gap: 1rem; }
.feedback-dialog h2 { font-size: 1.125rem; }
.feedback-dialog .stacked-form { max-width: none; }
.feedback-form .feedback-page { margin: 0; font-size: 0.8125rem; overflow-wrap: anywhere; }
.feedback-form .feedback-error[hidden] { display: none; }
.feedback-types, .radio-fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.feedback-types legend {
    padding: 0;
    margin-bottom: 0.375rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--fg-1);
}
.stacked-form :is(.feedback-types, .radio-fieldset) .radio-row {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.5rem 1.25rem;
}
.stacked-form :is(.feedback-types, .radio-fieldset) .check-row { margin: 0; font-weight: 400; }
/* Fields shown only for one option of a group of radios (data-choice-panels, in ui.js) */
.stacked-form [data-choice-panel][hidden] { display: none; }
.feedback-description { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.9375rem; line-height: 1.6; }
.feedback-page-cell { max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail-grid .span-all { grid-column: 1 / -1; }

/* Profit and loss (templates/pnl): the chart above the years, the total row, and the edit form's grid of amounts */
.pnl-chart { margin-bottom: 1.25rem; }
.pnl-chart .chart-box { min-height: 16rem; }
.data-table tfoot th, .data-table tfoot td {
    padding: 0.8rem 1rem;
    border-top: 2px solid var(--line-2);
    font-weight: 700;
    text-align: left;
}
.data-table tfoot .num { text-align: right; }
.pnl-summary .pnl-notes { grid-column: 1 / -1; }
.pnl-grid td { padding: 0.4rem 0.5rem; vertical-align: top; }
.pnl-grid th[scope="row"], .data-table tfoot th {
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: normal;
    text-transform: none;
    text-align: left;
    color: var(--fg-1);
    background: transparent;
}
.pnl-grid input:disabled { background: var(--bg-surface-2); cursor: not-allowed; }
.pnl-grid input[inputmode="decimal"] {
    min-width: 8.5rem;
    min-height: 34px;
    padding: 0.35rem 0.6rem;
    font-size: 0.8125rem;
    text-align: right;
}
.pnl-grid .pnl-not-started th { color: var(--fg-3); }

/* Forecast (templates/forecast): the lock status banner with its form, the summary and progress tables */
.forecast-status { align-items: center; flex-wrap: wrap; }
.forecast-status-text { display: flex; flex: 1; flex-direction: column; gap: 0.15rem; min-width: 12rem; }
.forecast-lock-note { white-space: pre-wrap; overflow-wrap: anywhere; }
.forecast-status-form { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.forecast-status-form input[type="text"] { min-width: 16rem; min-height: 34px; padding: 0.35rem 0.6rem; }
.forecast-top, .forecast-charts { margin-bottom: 1.25rem; }
.forecast-charts .chart-box { min-height: 16rem; }
.forecast-summary th[scope="row"], .forecast-lines th[scope="row"], .forecast-progress th[scope="row"] {
    font-size: 0.8125rem;
    font-weight: 500;
    letter-spacing: normal;
    text-transform: none;
    text-align: left;
    color: var(--fg-1);
    background: transparent;
}
.forecast-summary .forecast-subtotal > *, .forecast-lines .forecast-subtotal > * { font-weight: 700; }
.forecast-notes p { margin-top: 0.25rem; overflow-wrap: anywhere; }
.forecast-progress .pnl-not-entered td { color: var(--fg-3); }
.forecast-form-group { margin-top: 0.5rem; font-size: 0.9375rem; font-weight: 700; }

/* ── 6. Utilities. The colours are !important so they win over a component's own colour (a figure in a table cell,
   a stat value, a column heading). ── */
.text-muted  { color: var(--fg-3) !important; }
.text-green  { color: var(--tx-green) !important; }
.text-amber  { color: var(--tx-amber) !important; }
.text-red    { color: var(--tx-red) !important; }
.text-blue   { color: var(--tx-blue) !important; }
.text-purple { color: var(--tx-purple) !important; }
.text-pink   { color: var(--tx-pink) !important; }
.overdue     { color: var(--tx-red) !important; font-weight: 600; }
.strong { font-weight: 600; color: var(--fg-1); }
.small  { font-size: 0.75rem; }
.nowrap { white-space: nowrap; }
.mono   { font-family: var(--font-mono); }
.mono-muted { font-family: var(--font-mono); font-size: 0.8em; color: var(--fg-3); }
.plain-link, .plain-link:hover { color: inherit; }
.strong-link { display: inline-flex; align-items: center; gap: 0.35rem; font-weight: 700; }
.icon-link { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.8rem; }
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ---- Projects app ---- */

/* Text typed with line breaks, such as a description */
.pre-wrap { white-space: pre-wrap; overflow-wrap: anywhere; }

/* A heading after a detail list in the same card */
.detail-list + h3 { margin-top: 1.5rem; }

/* One categorisation question with its justification */
.question-fieldset { border: 0; border-top: 1px solid var(--line-1); margin: 0; padding: 1rem 0 0; }

/* A note on a project's Notes and files tab */
.note + .note { border-top: 1px solid var(--line-1); margin-top: 1rem; padding-top: 1rem; }
.note-meta { font-size: 0.8125rem; margin: 0 0 0.25rem; }
.card-body > .note { display: block; padding: 0; }
.note .btn-group { margin-top: 0.5rem; }

/* A form that is one control, such as a task's status menu in a table */
.inline-form { display: inline-flex; align-items: center; gap: 0.35rem; margin: 0; }
.inline-form select, .inline-form select:focus {
    min-height: 0;
    padding: 0.2rem 1.75rem 0.2rem 0.5rem;
    background-position: right 0.5rem center;
    font-size: 0.78rem;
}
.card-note { padding: 0.75rem 1.25rem; color: var(--fg-3); font-size: 0.8125rem; }

/* Plan tab: the Gantt. The task columns stay put while the weeks scroll sideways under them. */
.gantt-scroll { max-height: 75vh; }
.data-table.gantt { width: auto; min-width: 100%; font-size: 0.78rem; }
.gantt th, .gantt td { padding: 0.4rem 0.55rem; white-space: nowrap; }
.gantt thead th { position: sticky; top: 0; z-index: 3; background: var(--bg-surface-2); }
.gantt .gantt-num { width: 2.5rem; text-align: right; color: var(--fg-3); font-variant-numeric: tabular-nums; }
.gantt .gantt-name { min-width: 16rem; max-width: 24rem; white-space: normal; }
.gantt .gantt-order .btn { padding: 0.1rem; }
.gantt-section th {
    background: var(--primary-soft);
    color: var(--primary-text);
    font-family: var(--font-display);
    font-weight: 700;
    text-align: left;
}
.gantt-section th .btn-group { margin-left: 0.5rem; vertical-align: middle; }
.gantt-section td { background: var(--primary-soft); }
.data-table.gantt tbody tr:hover td.gantt-cell { background: inherit; }
.gantt td.gantt-empty { padding: 0.5rem; text-align: left; color: var(--fg-3); }
.gantt .gantt-week, .gantt .gantt-cell { width: 2.25rem; min-width: 2.25rem; padding: 0; text-align: center; }
.gantt .gantt-cell { border-left: 1px solid var(--line-1); }
.gantt th.gantt-week { line-height: 1.15; vertical-align: bottom; white-space: normal; letter-spacing: 0; }
.gantt-week-label { display: block; font-weight: 700; font-size: 0.72rem; color: var(--fg-1); }
.gantt-week-date { display: block; font-size: 0.6rem; font-weight: 500; color: var(--fg-3); text-transform: none; }
.gantt .gantt-live { background: var(--danger-soft); }
.gantt thead .gantt-live .gantt-week-label { color: var(--danger-ink); }
.gantt thead .gantt-current { box-shadow: inset 0 -3px 0 var(--primary); }
.gantt td.gantt-current:not(.gantt-bar) { background: var(--bg-surface-2); }
.gantt td.gantt-bar { background-clip: content-box; padding: 0.45rem 0; }
.gantt-bar-not_started { background-color: var(--n3i-ink-200); }
.gantt-bar-in_progress { background-color: var(--primary); }
.gantt-bar-complete { background-color: var(--tx-green); }
.gantt-bar-on_hold { background-color: var(--n3i-orange); }
.gantt-bar-blocked { background-color: var(--tx-red); }
.gantt-key {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.25rem;
    padding: 0.75rem 1.25rem;
    list-style: none;
    font-size: 0.75rem;
    color: var(--fg-2);
}
.gantt-key li { display: inline-flex; align-items: center; gap: 0.4rem; }
.gantt-swatch { display: inline-block; width: 1.25rem; height: 0.6rem; border-radius: 2px; }

/* Task board and pipeline board: columns of cards */
.view-toggle { margin-bottom: 1rem; }
.board { display: flex; gap: 0.875rem; padding: 1rem 1.25rem 1.25rem; overflow-x: auto; align-items: flex-start; }
.board.pipeline { padding: 0 0 1.25rem; }
.board-column {
    flex: 1 0 15rem;
    max-width: 22rem;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--line-1);
    border-radius: var(--radius-md, 10px);
    background: var(--bg-surface-2);
}
.board-column-header { display: flex; align-items: center; gap: 0.5rem; padding: 0.65rem 0.75rem; }
.board-column-header h2, .board-column-header h3 { flex: 1; margin: 0; font-size: 0.8125rem; font-weight: 700; }
.board-count {
    min-width: 1.5rem;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    background: var(--bg-surface);
    font-size: 0.7rem;
    font-weight: 700;
    text-align: center;
    color: var(--fg-2);
}
.board-cards {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-height: 4rem;
    margin: 0;
    padding: 0 0.5rem 0.75rem;
    list-style: none;
}
.board-card {
    padding: 0.6rem 0.7rem;
    border: 1px solid var(--line-1);
    border-left: 3px solid var(--line-2);
    border-radius: var(--radius-sm, 6px);
    background: var(--bg-surface);
    font-size: 0.8125rem;
}
.board-card[data-movable] { cursor: grab; }
.board-card.sortable-ghost { opacity: 0.4; }
.board-card-in_progress { border-left-color: var(--primary); }
.board-card-complete { border-left-color: var(--tx-green); }
.board-card-on_hold { border-left-color: var(--n3i-orange); }
.board-card-blocked { border-left-color: var(--tx-red); }
.board-card-title { display: block; font-weight: 600; color: var(--fg-1); overflow-wrap: anywhere; }
.board-card-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem 0.5rem;
    margin-top: 0.4rem;
    font-size: 0.72rem;
    color: var(--fg-3);
}
.board-owner { margin-left: auto; }
.board-column-completed .board-cards, .board-column-cancelled .board-cards { opacity: 0.85; }

/* @mention suggestions under a comment box, and a mention in a comment */
.comment-form { margin-top: 1.25rem; position: relative; }
.mention-list {
    position: absolute;
    z-index: 20;
    min-width: 16rem;
    margin: 0.25rem 0 0;
    padding: 0.25rem;
    list-style: none;
    border: 1px solid var(--line-2);
    border-radius: var(--radius-sm, 6px);
    background: var(--bg-surface);
    box-shadow: 0 6px 18px rgb(0 0 0 / 0.12);
}
.mention-list li { padding: 0.35rem 0.6rem; border-radius: 4px; cursor: pointer; font-size: 0.8125rem; }
.mention-list li[aria-selected="true"], .mention-list li:hover { background: var(--primary-soft); }
.mention { color: var(--primary-text); font-weight: 600; }

/* Budget tab: its five figures in a row, then how much of the budget is spent, coloured as the Spent figure */
.budget-tiles { grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); }
.budget-bar {
    height: 10px;
    margin: -0.75rem 0 1.75rem;
    border-radius: var(--radius-pill);
    background: var(--bg-surface-2);
    overflow: hidden;
}
.budget-bar > span { display: block; height: 100%; border-radius: inherit; background: var(--tx-green); }
.budget-bar-amber > span { background: var(--tx-amber); }
.budget-bar-red > span { background: var(--tx-red); }

/* Resources tab: the resource calendar, a month of days Monday to Sunday with each day's bookings */
.resource-calendar { width: 100%; min-width: 48rem; table-layout: fixed; border-collapse: collapse; }
.resource-calendar th {
    padding: 0.5rem;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--fg-3);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: var(--bg-surface-2);
}
.resource-calendar td {
    position: relative;
    height: 6.5rem;
    padding: 0.35rem 0.4rem 1.6rem;
    vertical-align: top;
    border: 1px solid var(--line-1);
}
.resource-calendar .rc-weekend { background: var(--bg-surface-2); }
.resource-calendar .rc-other .rc-date { color: var(--fg-3); font-weight: 500; }
.resource-calendar .rc-booked { background: var(--tint-green); }
.resource-calendar .rc-today { box-shadow: inset 0 0 0 2px var(--primary); }
.resource-calendar .rc-live { box-shadow: inset 0 0 0 2px var(--tx-green); }
.rc-day-head { display: flex; align-items: center; gap: 0.3rem; margin-bottom: 0.25rem; }
.rc-date { font-size: 0.8rem; font-weight: 700; color: var(--fg-1); }
.rc-today .rc-date { color: var(--primary-text); }
.rc-tag {
    padding: 0 0.35rem;
    border-radius: var(--radius-pill);
    font-size: 0.62rem;
    font-weight: 800;
    text-transform: uppercase;
    color: #fff;
    background: var(--tx-green);
}
.rc-total { margin-left: auto; font-size: 0.68rem; font-weight: 700; color: var(--fg-3); }
.rc-bookings { margin: 0; padding: 0; list-style: none; font-size: 0.72rem; }
.rc-bookings li a, .rc-bookings li { display: flex; gap: 0.3rem; min-width: 0; color: var(--fg-1); }
.rc-bookings li a:hover .rc-name { text-decoration: underline; }
.rc-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rc-hours { margin-left: auto; color: var(--fg-3); }
.rc-add {
    position: absolute;
    right: 0.3rem;
    bottom: 0.3rem;
    display: flex;
    padding: 0.15rem;
    border-radius: var(--radius-xs);
    color: var(--fg-3);
    opacity: 0;
}
.resource-calendar td:hover .rc-add, .rc-add:focus-visible { opacity: 1; }
.rc-add:hover { color: var(--primary-text); background: var(--primary-soft); }
@media (hover: none) { .rc-add { opacity: 1; } }

/* Rich text (the brief and the project documents): as shown, and the editor (assets/js/rich-text.js) */
.rich-text { font-size: 0.9rem; line-height: 1.65; overflow-wrap: anywhere; }
.rich-text > :first-child { margin-top: 0; }
.rich-text > :last-child { margin-bottom: 0; }
.rich-text p, .rich-text ul, .rich-text ol { margin: 0 0 0.6rem; }
.rich-text ul, .rich-text ol { padding-left: 1.4rem; }
.rich-editor {
    border: 1px solid var(--input-border);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    overflow: hidden;
}
.rich-editor:focus-within { outline: 2px solid var(--focus); outline-offset: 1px; }
.rich-editor-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 0.3rem;
    border-bottom: 1px solid var(--line-1);
    background: var(--bg-surface-2);
}
.rich-editor-button {
    min-width: 2rem;
    height: 1.9rem;
    padding: 0 0.4rem;
    border: 0;
    border-radius: var(--radius-xs);
    background: transparent;
    color: var(--fg-2);
    font: inherit;
    font-size: 0.85rem;
    cursor: pointer;
}
.rich-editor-button:hover { background: var(--bg-surface); color: var(--fg-1); }
.rich-editor-button[aria-pressed="true"] { background: var(--primary); color: #fff; }
.rich-editor-box { min-height: 14rem; max-height: 60vh; padding: 0.75rem 1rem; overflow-y: auto; outline: none; }

/* Brief tab: the steps down the side, ticked as they are written, and the phases' colours */
.brief-layout { display: grid; grid-template-columns: 16rem minmax(0, 1fr); gap: 1.25rem; align-items: start; }
@media (max-width: 900px) { .brief-layout { grid-template-columns: minmax(0, 1fr); } }
.brief-rail { position: sticky; top: 1rem; padding: 0.75rem; }
.brief-progress { margin: 0 0 0.5rem; padding: 0 0.4rem; font-size: 0.8125rem; color: var(--fg-3); }
.brief-progress strong { color: var(--fg-1); }
.brief-phase {
    margin: 0.6rem 0 0.2rem;
    padding: 0 0.4rem;
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--phase);
}
.brief-steps { margin: 0; padding: 0; list-style: none; }
.brief-steps a {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.4rem;
    border-radius: var(--radius-sm);
    color: var(--fg-1);
    font-size: 0.8125rem;
    text-decoration: none;
}
.brief-steps a:hover { background: var(--bg-surface-2); }
.brief-steps a[aria-current="step"] { background: var(--primary-soft); font-weight: 700; }
.brief-dot {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 1.3rem;
    height: 1.3rem;
    border: 2px solid var(--line-2);
    border-radius: 50%;
    font-size: 0.65rem;
    font-weight: 800;
    color: var(--fg-3);
}
.brief-steps a.done .brief-dot { border-color: var(--tx-green); background: var(--tx-green); color: #fff; }
.brief-phase-define { --phase: var(--tx-blue); }
.brief-phase-analyse { --phase: var(--tx-purple); }
.brief-phase-improve { --phase: var(--tx-green); }
.brief-phase-card { border-top: 3px solid var(--phase); }
.brief-phase-card .card-title { color: var(--phase); }
.brief-step + .brief-step { border-top: 1px solid var(--line-1); }
.brief-step-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.brief-step-head h3 { margin: 0 0 0.5rem; font-size: 0.95rem; }
.brief-step-head h3 .text-muted { margin-left: 0.35rem; font-size: 0.8rem; font-weight: 500; }
.brief-kicker {
    margin: 0 0 0.75rem;
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--phase);
}

/* Documents tab: a written document's page, and the communications plan's power and influence scores */
.document-card { max-width: 60rem; }
.document-head { margin-bottom: 1rem; }
.document-head h2 { margin: 0; }
.power {
    display: inline-block;
    min-width: 1.75rem;
    padding: 0.1rem 0.4rem;
    border-radius: var(--radius-xs);
    font-weight: 800;
    text-align: center;
}
.power-high { background: var(--tint-red); color: var(--tx-red); }
.power-medium { background: var(--tint-amber); color: var(--tx-amber); }
.power-low { background: var(--tint-green); color: var(--tx-green); }

/* Closure tab: the checklist, the board's decision, what is outstanding; and colleagues' views (review requests) */
.locked-banner { align-items: center; }
.closure-heading { margin: 1.5rem 0 0.5rem; font-size: 0.95rem; }
.closure-checklist { margin: 0; padding: 0; list-style: none; display: grid; gap: 0.4rem; }
.closure-checklist li { display: flex; gap: 0.5rem; align-items: flex-start; font-size: 0.875rem; color: var(--fg-3); }
.closure-checklist li.done { color: var(--fg-1); }
.closure-checklist li.done .icon { color: var(--tx-green); }
.closure-checklist .icon { flex-shrink: 0; margin-top: 0.15rem; }
.closure-decision { border-top: 1px solid var(--line-1); }
.closure-decision p { margin: 0 0 0.4rem; }
.closure-decision-approved { background: var(--tint-green); }
.closure-decision-changes_requested { background: var(--tint-red); }
.section-heading { margin: 1.75rem 0 0.75rem; font-size: 1.05rem; }
.closure-outstanding { align-items: start; }
@media (max-width: 900px) { .closure-outstanding { grid-template-columns: minmax(0, 1fr); } }
.outstanding-list { margin: 0; padding: 0.25rem 0; list-style: none; }
.outstanding-list li {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    padding: 0.55rem 1.25rem;
    font-size: 0.85rem;
    border-top: 1px solid var(--line-1);
}
.outstanding-list li:first-child { border-top: 0; }
.outstanding-list .text-muted { font-size: 0.78rem; }
.review-list { margin: 0; padding: 0; list-style: none; }
.review-list > li { padding: 0.85rem 1.25rem; border-top: 1px solid var(--line-1); }
.review-list p { margin: 0.35rem 0 0; font-size: 0.85rem; }
.review-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; font-size: 0.875rem; }
.review-head form { margin-left: auto; }
.review-respond { display: grid; gap: 0.4rem; max-width: 36rem; margin-top: 0.75rem; }
.review-respond label { font-size: 0.8125rem; font-weight: 600; }

/* Programme Overview: its projects' health and benefits as counts */
.programme-rollups { align-items: start; }
@media (max-width: 900px) { .programme-rollups { grid-template-columns: minmax(0, 1fr); } }
.rollup-list { display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem; margin: 0; padding: 0; list-style: none; }
.rollup-list li { display: flex; align-items: center; gap: 0.4rem; font-size: 0.875rem; }
.programme-report h3 { margin: 1.5rem 0 0.5rem; }

/* Admin > Project templates: a task's five fields in a row, on a screen wide enough */
@media (min-width: 900px) {
    .stacked-form .action-fields.template-task-fields { grid-template-columns: 2fr 1.3fr 0.8fr 0.8fr 1.1fr; }
    .stacked-form .action-fields.template-task-fields > div:first-child { grid-column: auto; }
}

/* Highlight reports: a fieldset per risk to rescore, and the report printed without the app around it */
.highlight-risks { border: 0; margin: 1.5rem 0 0; padding: 0; }
.highlight-risks > legend { font-weight: 700; margin-bottom: 0.25rem; }
.highlight-risk {
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    border: 1px solid var(--line-1);
    border-radius: var(--radius-sm);
}
.highlight-risk > legend { padding: 0 0.35rem; font-size: 0.875rem; font-weight: 600; color: var(--fg-1); }
.highlight-report .card-body h3 { margin: 1.5rem 0 0.5rem; }
.print-only { display: none; }
@media print {
    .app-sidebar, .topbar, .record-tabs, .record-actions, .page-header-btns, .no-print, .alert, #feedback-status,
    .sf-toolbar { display: none !important; }
    .print-only { display: grid; }
    .page-body > * { animation: none !important; }
    .card { box-shadow: none; break-inside: avoid-page; }
}
