/*
 * Copyright (c) 2026 Syncop.  All rights reserved.
 *
 * Shared stylesheet for the LeanDelegate Qute/HTMX console.
 *
 * Everything is written against the token layer below rather than raw hex, so light and dark
 * swap in one place. The palette is the one in the brand guide at
 * META-INF/resources/images/README.md — deep navy, compliance emerald, slate — not a generic
 * framework blue.
 *
 * Colour was chosen last and checked rather than eyeballed. Status marks clear 3:1 against the
 * surface they sit on and badge ink clears 4.5:1 against its own tint, in both modes; the light
 * mark set also clears the categorical separation gates (worst normal-vision pair 18.1, worst
 * CVD pair 7.1 — inside the band that requires secondary encoding, which every badge has: a dot
 * plus a word, so state is never carried by hue alone).
 */

/* ============================================================================ Tokens */

:root {
    color-scheme: light;

    /* -- brand constants, mode-invariant ------------------------------------ */
    --brand-navy: #0F172A;
    --brand-emerald: #10B981;

    /* -- surfaces ----------------------------------------------------------- */
    --page: #F1F5F9;
    --surface: #FFFFFF;
    --surface-sunken: #F8FAFC;
    --surface-raised: #FFFFFF;
    --surface-inverse: #0F172A;

    /* -- ink ---------------------------------------------------------------- */
    --ink: #0F172A;
    --ink-secondary: #475569;
    --ink-muted: #64748B;
    --ink-inverse: #F8FAFC;
    --ink-inverse-muted: #94A3B8;

    /* -- lines -------------------------------------------------------------- */
    --line: #E2E8F0;
    --line-strong: #CBD5E1;

    /* -- interactive accent -------------------------------------------------- */
    --accent: #1D4ED8;
    --accent-hover: #1E40AF;
    --accent-wash: #EFF6FF;
    --accent-ring: rgba(29, 78, 216, 0.35);

    /* -- status marks: dots, rules, tile accents ----------------------------- */
    --good: #059669;
    --warning: #BE8300;
    --critical: #DC2626;
    --info: #2563EB;
    --neutral: #64748B;

    /* -- status badges: tint + ink pairs ------------------------------------- */
    --good-tint: #ECFDF5;
    --good-ink: #065F46;
    --warning-tint: #FEFCE8;
    --warning-ink: #854D0E;
    --critical-tint: #FEF2F2;
    --critical-ink: #991B1B;
    --info-tint: #EFF6FF;
    --info-ink: #1E40AF;
    --neutral-tint: #F1F5F9;
    --neutral-ink: #334155;

    /* -- demo banner: its own pair, because a full-bleed strip of the warning tint is far more
       colour than the same tint carries inside a pill --------------------------- */
    --banner-bg: #FEFCE8;
    --banner-ink: #854D0E;
    --banner-line: #FDE68A;

    /* -- elevation ----------------------------------------------------------- */
    --shadow-1: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.05);
    --shadow-2: 0 4px 12px rgba(15, 23, 42, 0.08), 0 1px 3px rgba(15, 23, 42, 0.06);
    --shadow-3: 0 16px 48px rgba(15, 23, 42, 0.20);

    /* -- geometry ------------------------------------------------------------ */
    --radius-sm: 4px;
    --radius: 8px;
    --radius-lg: 12px;
    --radius-pill: 999px;

    /* -- type ---------------------------------------------------------------- */
    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/*
 * Dark is a selected set of steps against the dark surface, not an inverted copy of light.
 * Declared under both scopes: the media query follows the OS, the attribute follows the
 * viewer's toggle, and the toggle wins either way.
 */
@media (prefers-color-scheme: dark) {
    :root:where(:not([data-theme="light"])) {
        color-scheme: dark;

        --page: #0B1120;
        --surface: #1E293B;
        --surface-sunken: #172033;
        --surface-raised: #273449;
        --surface-inverse: #0B1120;

        --ink: #F1F5F9;
        --ink-secondary: #CBD5E1;
        --ink-muted: #94A3B8;
        --ink-inverse: #F1F5F9;
        --ink-inverse-muted: #94A3B8;

        --line: #334155;
        --line-strong: #475569;

        --accent: #60A5FA;
        --accent-hover: #93C5FD;
        --accent-wash: #16305C;
        --accent-ring: rgba(96, 165, 250, 0.45);

        --good: #34D399;
        --warning: #FBBF24;
        --critical: #F87171;
        --info: #60A5FA;
        --neutral: #94A3B8;

        --good-tint: #0B3B2E;
        --good-ink: #6EE7B7;
        --warning-tint: #3B2F0B;
        --warning-ink: #FCD34D;
        --critical-tint: #3F1D1D;
        --critical-ink: #FCA5A5;
        --info-tint: #16305C;
        --info-ink: #93C5FD;
        --neutral-tint: #293548;
        --neutral-ink: #CBD5E1;

        --banner-bg: #1E2436;
        --banner-ink: #FCD34D;
        --banner-line: #3B2F0B;

        --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.40);
        --shadow-2: 0 4px 12px rgba(0, 0, 0, 0.45);
        --shadow-3: 0 16px 48px rgba(0, 0, 0, 0.60);
    }
}

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

    --page: #0B1120;
    --surface: #1E293B;
    --surface-sunken: #172033;
    --surface-raised: #273449;
    --surface-inverse: #0B1120;

    --ink: #F1F5F9;
    --ink-secondary: #CBD5E1;
    --ink-muted: #94A3B8;
    --ink-inverse: #F1F5F9;
    --ink-inverse-muted: #94A3B8;

    --line: #334155;
    --line-strong: #475569;

    --accent: #60A5FA;
    --accent-hover: #93C5FD;
    --accent-wash: #16305C;
    --accent-ring: rgba(96, 165, 250, 0.45);

    --good: #34D399;
    --warning: #FBBF24;
    --critical: #F87171;
    --info: #60A5FA;
    --neutral: #94A3B8;

    --good-tint: #0B3B2E;
    --good-ink: #6EE7B7;
    --warning-tint: #3B2F0B;
    --warning-ink: #FCD34D;
    --critical-tint: #3F1D1D;
    --critical-ink: #FCA5A5;
    --info-tint: #16305C;
    --info-ink: #93C5FD;
    --neutral-tint: #293548;
    --neutral-ink: #CBD5E1;

    --banner-bg: #1E2436;
    --banner-ink: #FCD34D;
    --banner-line: #3B2F0B;

    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.40);
    --shadow-2: 0 4px 12px rgba(0, 0, 0, 0.45);
    --shadow-3: 0 16px 48px rgba(0, 0, 0, 0.60);
}

/* ============================================================================ Base */

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

html {
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.55;
    color: var(--ink);
    background-color: var(--page);
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 {
    color: var(--ink);
    font-weight: 600;
    letter-spacing: -0.011em;
    line-height: 1.25;
    text-wrap: balance;
}

a {
    color: var(--accent);
}

a:hover {
    color: var(--accent-hover);
}

code {
    font-family: var(--font-mono);
}

/* One focus treatment for everything, visible on both surfaces. */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

::selection {
    background-color: var(--accent-wash);
    color: var(--ink);
}

/* ============================================================================ Marketing */

/*
 * The hero is drawn, not photographed.
 *
 * It used to sit on a bright-yellow flat-lay of loose pills, a thermometer and a face mask.
 * Two things were wrong with that. The subject was wrong — this product is about staff
 * credentials and delegation paperwork, not medication — and a saturated yellow under the navy
 * scrim it needed for legible type turned the whole band olive. It was also a 1.8 MB
 * 5472x3648 JPEG on the first paint of the public page.
 *
 * What replaces it is built from the brand's own vocabulary: navy ground, an emerald glow, a
 * blueprint grid for "records and rigour", and the logo mark — shield, S-curve, gatekeeper
 * node — as a watermark. All CSS and one 1 KB SVG, so it stays sharp at any width, needs no
 * CDN, and costs nothing to load. A photograph can be layered back in as a low-opacity
 * overlay under .hero if a fitting one turns up; nothing else would have to change.
 */

header.hero {
    position: relative;
    isolation: isolate;
    overflow: hidden;
    color: #FFFFFF;
    padding: 0 1.5rem;
    background-color: var(--brand-navy);
    background-image:
            radial-gradient(55rem 26rem at 88% 115%, rgba(16, 185, 129, 0.20), transparent 62%),
            radial-gradient(38rem 20rem at 34% 95%, rgba(30, 58, 138, 0.45), transparent 70%),
            linear-gradient(180deg, #0F172A 0%, #111C33 100%);
}

/*
 * Blueprint grid, faded out toward the edges so it never reads as a table. It starts below the
 * logo bar: the lockup carries its own flat navy backing, and grid lines stopping at its edges
 * outline that backing as a visible rectangle.
 */
header.hero::before {
    content: '';
    position: absolute;
    inset: 7rem 0 0;
    z-index: -2;
    background-image:
            linear-gradient(to right, rgba(148, 163, 184, 0.10) 1px, transparent 1px),
            linear-gradient(to bottom, rgba(148, 163, 184, 0.10) 1px, transparent 1px);
    background-size: 4rem 4rem;
    -webkit-mask-image: radial-gradient(70% 70% at 40% 40%, #000 30%, transparent 100%);
    mask-image: radial-gradient(70% 70% at 40% 40%, #000 30%, transparent 100%);
}

/* The logo mark as a watermark: brand shape carrying the depth a stock photo used to. */
header.hero::after {
    content: '';
    position: absolute;
    z-index: -1;
    right: max(3rem, calc(50% - 32rem));
    top: 50%;
    transform: translateY(-50%);
    width: 24rem;
    height: 24rem;
    background-color: var(--brand-emerald);
    -webkit-mask: url('/images/logo_mark.svg') no-repeat center / contain;
    mask: url('/images/logo_mark.svg') no-repeat center / contain;
    opacity: 0.10;
    pointer-events: none;
}

header.hero .header-top-bar {
    max-width: 68rem;
    margin: 0 auto;
    padding: 1.5rem 0 0;
    display: flex;
    align-items: center;
}

header.hero .header-top-bar img {
    width: 168px;
    height: auto;
}

/* Left-aligned: a B2B claim reads as a statement, not as a poster. */
header.hero .header-main-content {
    max-width: 68rem;
    margin: 0 auto;
    padding: 3.5rem 0 4rem;
}

.hero-eyebrow {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0 0 1rem;
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--brand-emerald);
}

.hero-eyebrow::before {
    content: '';
    width: 1.75rem;
    height: 2px;
    border-radius: var(--radius-pill);
    background-color: var(--brand-emerald);
}

header.hero h1 {
    color: #FFFFFF;
    font-weight: 700;
    font-size: clamp(2.75rem, 6.5vw, 4.25rem);
    letter-spacing: -0.035em;
    line-height: 1.02;
    margin: 0;
}

.hero-lede {
    margin: 1.25rem 0 0;
    max-width: 44ch;
    font-size: clamp(1.0625rem, 1.6vw, 1.25rem);
    line-height: 1.5;
    color: rgba(255, 255, 255, 0.78);
}

/* The product's one rule, given the weight of a quotation rather than a sentence. */
.hero-rule {
    margin: 1.75rem 0 0;
    padding-left: 1rem;
    border-left: 3px solid var(--brand-emerald);
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.92);
}

.hero-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin-top: 2.25rem;
}

/* The hero CTA is emerald: the navy primary button would vanish into this ground. */
.btn-brand {
    background-color: var(--brand-emerald);
    color: #04231A;
    font-size: 1rem;
    padding: 0.7rem 1.4rem;
}

.btn-brand:hover {
    background-color: #34D399;
    color: #04231A;
}

.hero-secondary {
    color: rgba(255, 255, 255, 0.72);
    font-size: 0.9375rem;
    text-decoration: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.28);
    padding-bottom: 0.1rem;
}

.hero-secondary:hover {
    color: #FFFFFF;
    border-bottom-color: #FFFFFF;
}

/* A specification strip, not a testimonial strip: the four claims a buyer checks first. */
.hero-facts {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 2.25rem;
    list-style: none;
    margin: 0 auto;
    padding: 1.1rem 0;
    max-width: 68rem;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    font-size: 0.875rem;
    color: rgba(255, 255, 255, 0.72);
}

.hero-facts li {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.hero-facts li::before {
    content: '';
    width: 0.375rem;
    height: 0.375rem;
    border-radius: 50%;
    background-color: var(--brand-emerald);
    flex-shrink: 0;
}

@media (max-width: 720px) {
    header.hero::after {
        display: none;
    }

    header.hero .header-main-content {
        padding: 2.5rem 0 3rem;
    }

    /* Stacked rather than wrapped: four facts across two ragged lines read as a broken row. */
    .hero-facts {
        flex-direction: column;
        gap: 0.5rem;
    }

    header.hero .header-main-content,
    .hero-facts {
        padding-left: 0;
        padding-right: 0;
    }
}

.container {
    max-width: 68rem;
    margin: 2rem auto;
    padding: 0 1.5rem;
    flex-grow: 1;
    width: 100%;
}

.container.wide {
    max-width: 88rem;
}

section {
    background-color: var(--surface);
    padding: 1.75rem;
    margin-bottom: 1.5rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-1);
}

section > h2 {
    font-size: 1.125rem;
    margin: 0 0 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--line);
}

/*
 * Prose pages are sized to the measure rather than to the console's width: the card tracks the
 * text instead of leaving half of itself empty beside a 68-character line.
 */
.container.prose {
    max-width: 56rem;
}

.prose {
    color: var(--ink-secondary);
}

.prose h2 {
    color: var(--ink);
}

.prose ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.prose ul li {
    position: relative;
    padding-left: 2rem;
    margin-bottom: 0.9rem;
    max-width: 72ch;
}

/* Emerald tick, from the brand palette rather than a framework green. */
.prose ul li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0.36em;
    width: 1.1em;
    height: 1.1em;
    background-color: var(--brand-emerald);
    -webkit-mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9 16.17 4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"/></svg>') no-repeat center / contain;
    mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9 16.17 4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"/></svg>') no-repeat center / contain;
}

.prose strong {
    color: var(--ink);
    font-weight: 600;
}

footer {
    background-color: var(--surface-inverse);
    color: var(--ink-inverse-muted);
    text-align: center;
    padding: 1.5rem;
    margin-top: auto;
    font-size: 0.875rem;
}

footer p {
    margin: 0;
}

/* ============================================================================ Console shell */

header.appbar {
    position: sticky;
    top: 0;
    z-index: 30;
    background-color: var(--brand-navy);
    color: #FFFFFF;
    padding: 0 1.25rem;
    min-height: 3.5rem;
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

header.appbar .brand {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

header.appbar .brand img {
    width: 132px;
    height: auto;
    display: block;
}

header.appbar nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-grow: 1;
    overflow-x: auto;
    scrollbar-width: none;
}

header.appbar nav::-webkit-scrollbar {
    display: none;
}

/*
 * Nav items are pills rather than underlines: the current page then reads as a filled shape at
 * a glance, which an underline two pixels tall does not.
 */
header.appbar nav a {
    color: rgba(255, 255, 255, 0.72);
    text-decoration: none;
    font-size: 0.9375rem;
    font-weight: 500;
    white-space: nowrap;
    padding: 0.4rem 0.8rem;
    border-radius: var(--radius-sm);
    transition: background-color 120ms ease, color 120ms ease;
}

header.appbar nav a:hover {
    color: #FFFFFF;
    background-color: rgba(255, 255, 255, 0.08);
}

header.appbar nav a[aria-current="page"] {
    color: #FFFFFF;
    background-color: rgba(255, 255, 255, 0.14);
    font-weight: 600;
}

header.appbar :focus-visible {
    outline-color: #FFFFFF;
}

.appbar-right {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-left: auto;
    flex-shrink: 0;
}

.role-badge {
    background-color: rgba(255, 255, 255, 0.10);
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: rgba(255, 255, 255, 0.85);
    border-radius: var(--radius-pill);
    padding: 0.2rem 0.7rem;
    font-size: 0.8125rem;
    white-space: nowrap;
}

.action-counter {
    background-color: var(--brand-emerald);
    color: #04231A;
    border-radius: var(--radius-pill);
    min-width: 1.6rem;
    padding: 0.1rem 0.5rem;
    text-align: center;
    font-weight: 700;
    font-size: 0.8125rem;
    font-variant-numeric: tabular-nums;
}

/* Theme toggle: an icon button that swaps glyph with the resolved theme. */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: var(--radius-sm);
    background-color: rgba(255, 255, 255, 0.06);
    color: #FFFFFF;
    cursor: pointer;
    line-height: 1;
    font-size: 0.95rem;
}

.theme-toggle:hover {
    background-color: rgba(255, 255, 255, 0.14);
}

.theme-toggle .icon-dark { display: none; }
.theme-toggle .icon-light { display: inline; }

@media (prefers-color-scheme: dark) {
    :root:where(:not([data-theme="light"])) .theme-toggle .icon-dark { display: inline; }
    :root:where(:not([data-theme="light"])) .theme-toggle .icon-light { display: none; }
}

:root[data-theme="dark"] .theme-toggle .icon-dark { display: inline; }
:root[data-theme="dark"] .theme-toggle .icon-light { display: none; }

.demo-banner {
    background-color: var(--banner-bg);
    color: var(--banner-ink);
    border-bottom: 1px solid var(--banner-line);
    padding: 0.6rem 1.5rem;
    font-size: 0.875rem;
    text-align: center;
}

.demo-banner strong {
    color: inherit;
    font-weight: 700;
}

/* ============================================================================ Page furniture */

.page-head {
    display: flex;
    align-items: flex-end;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.page-head h1 {
    font-size: 1.625rem;
    letter-spacing: -0.02em;
    margin: 0;
}

.page-head .subtitle {
    color: var(--ink-muted);
    font-size: 0.9375rem;
    margin: 0.25rem 0 0;
}

.page-head .spacer,
.overlay-head .spacer,
.chain-banner-head .spacer {
    flex-grow: 1;
}

.subtitle {
    color: var(--ink-muted);
}

/*
 * The filter row. Given a surface of its own so a lone select reads as "the filters for what
 * follows" rather than as a control someone left behind above the content.
 */
.toolbar {
    display: flex;
    align-items: flex-end;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
    padding: 0.85rem 1rem;
    background-color: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-1);
}

/* ============================================================================ Forms */

.field {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

/*
 * Direct child only. A field's caption is styled as a small uppercase label, but a <label>
 * nested deeper is doing another job — see .file-trigger, which is a label styled as a button —
 * and must be left to whatever class it carries.
 */
.field > label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--ink-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.field select,
.field input,
.field textarea {
    font-family: inherit;
    font-size: 0.9375rem;
    color: var(--ink);
    padding: 0.5rem 0.7rem;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background-color: var(--surface);
    min-width: 14rem;
    transition: border-color 120ms ease, box-shadow 120ms ease;
}

.field select {
    appearance: none;
    padding-right: 2rem;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="%2364748B"><path d="M5.5 7.5 10 12l4.5-4.5z"/></svg>');
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    background-size: 1.1em;
}

.field select:hover,
.field input:hover,
.field textarea:hover {
    border-color: var(--ink-muted);
}

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

.field input[aria-invalid="true"] {
    border-color: var(--critical);
}

/* ------------------------------------------------------------------ File input */

/*
 * The browser's own file control renders as an unstyled "Browse… / No file selected." pair that
 * sits beside our buttons looking like it belongs to a different application. It cannot be
 * restyled, so it is driven from a <label> instead: clicking a label opens the picker natively,
 * with no script involved.
 *
 * The real <input> stays in the page — hidden to the eye but not to the accessibility tree, and
 * still focusable. That distinction matters: display:none would drop it from the tab order, and
 * Chrome refuses to report a validation message against a control it cannot focus, so a required
 * empty file field would fail submission with no visible explanation.
 */
.file-control {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-height: 2.35rem;
}

.file-input {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* The label is the visible affordance, so it takes the focus ring the hidden input receives. */
.file-control:has(.file-input:focus-visible) .file-trigger {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.file-control:has(.file-input:user-invalid) .file-trigger {
    border-color: var(--critical);
    color: var(--critical-ink);
}

.file-name {
    color: var(--ink-muted);
    font-size: 0.875rem;
    max-width: 18rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* A chosen file is a fact about the form, not a hint: it reads in body ink. */
.file-name.has-file {
    color: var(--ink);
    font-weight: 500;
}

/* ============================================================================ Buttons */

.btn {
    font-family: inherit;
    font-size: 0.9375rem;
    font-weight: 600;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    line-height: 1.4;
    white-space: nowrap;
    transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

.btn-primary {
    background-color: var(--brand-navy);
    color: #FFFFFF;
}

.btn-primary:hover {
    background-color: #1E293B;
    color: #FFFFFF;
}

:root[data-theme="dark"] .btn-primary,
:root[data-theme="dark"] .btn-primary:hover {
    background-color: var(--accent);
    color: #0B1120;
}

@media (prefers-color-scheme: dark) {
    :root:where(:not([data-theme="light"])) .btn-primary,
    :root:where(:not([data-theme="light"])) .btn-primary:hover {
        background-color: var(--accent);
        color: #0B1120;
    }
}

.btn-secondary {
    background-color: var(--surface);
    color: var(--ink);
    border-color: var(--line-strong);
    box-shadow: var(--shadow-1);
}

.btn-secondary:hover {
    background-color: var(--surface-sunken);
    border-color: var(--ink-muted);
    color: var(--ink);
}

.btn-ghost {
    background-color: transparent;
    color: var(--ink-secondary);
    border-color: transparent;
}

.btn-ghost:hover {
    background-color: var(--surface-sunken);
    color: var(--ink);
}

.btn-sm {
    font-size: 0.8125rem;
    padding: 0.3rem 0.7rem;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ============================================================================ Stat tiles */

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.metric-card {
    background-color: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 1.1rem 1.25rem;
    box-shadow: var(--shadow-1);
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

/*
 * The value wears ink, not the status colour. A number in red says "this figure is red"; the
 * state belongs to the dot beside the label, where a word sits next to it.
 */
.metric-card .metric-value {
    font-size: 2.25rem;
    font-weight: 600;
    line-height: 1.05;
    letter-spacing: -0.02em;
    color: var(--ink);
    /* Proportional figures: tabular-nums gives every digit a zero's width, which reads loose
       at display sizes. Tabular is for columns that must align — see .data-table .num. */
}

.metric-card .metric-label {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    color: var(--ink-muted);
    font-size: 0.8125rem;
    font-weight: 500;
    letter-spacing: 0.01em;
}

/* The status dot — the icon half of the icon+label pairing status colour requires. */
.metric-card .metric-label::before {
    content: '';
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    flex-shrink: 0;
    background-color: var(--neutral);
}

.metric-card.ok .metric-label::before { background-color: var(--good); }
.metric-card.warn .metric-label::before { background-color: var(--warning); }
.metric-card.danger .metric-label::before { background-color: var(--critical); }
.metric-card.info .metric-label::before { background-color: var(--info); }

/* ============================================================================ Tables */

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

.data-table caption {
    text-align: left;
    color: var(--ink-muted);
    font-size: 0.875rem;
    padding-bottom: 0.75rem;
}

.data-table th,
.data-table td {
    text-align: left;
    padding: 0.7rem 0.85rem;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}

.data-table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background-color: var(--surface-sunken);
    color: var(--ink-muted);
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--line-strong);
    white-space: nowrap;
}

.data-table tbody th {
    font-weight: 600;
}

/* A row header's secondary line is still secondary — it must not inherit the header weight. */
.data-table tbody th .task-desc {
    font-weight: 400;
}

.data-table tbody tr:last-child td,
.data-table tbody tr:last-child th {
    border-bottom: none;
}

.data-table tbody tr:hover {
    background-color: var(--surface-sunken);
}

.data-table .num {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.table-scroll {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background-color: var(--surface);
}

.task-codes {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.task-code {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    background-color: var(--surface-sunken);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 0.05rem 0.4rem;
    color: var(--ink-secondary);
    white-space: nowrap;
}

.task-desc {
    display: block;
    color: var(--ink-muted);
    font-size: 0.8125rem;
}

.empty-state {
    padding: 3rem 1rem;
    text-align: center;
    color: var(--ink-muted);
}

/* ============================================================================ Badges */

/*
 * A badge is a tint plus ink plus a dot. The dot is the icon half of the icon+label pairing a
 * status colour requires: hue never carries the state on its own, so the badges stay readable
 * under colour-vision deficiency, in grayscale print, and in forced-colors.
 */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4em;
    border-radius: var(--radius-pill);
    padding: 0.15em 0.65em;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    white-space: nowrap;
    background-color: var(--neutral-tint);
    color: var(--neutral-ink);
    border: 1px solid transparent;
}

.badge::before {
    content: '';
    width: 0.45em;
    height: 0.45em;
    border-radius: 50%;
    background-color: currentColor;
    flex-shrink: 0;
}

@media (forced-colors: active) {
    .badge {
        border-color: currentColor;
    }
}

/* DelegationStatus */
.badge-draft,
.badge-superseded { background-color: var(--neutral-tint); color: var(--neutral-ink); }
.badge-pending_grantee_sig,
.badge-pending_pi_approval { background-color: var(--warning-tint); color: var(--warning-ink); }
.badge-active { background-color: var(--good-tint); color: var(--good-ink); }
.badge-terminated { background-color: var(--critical-tint); color: var(--critical-ink); }

/* ComplianceState */
.badge-assigned { background-color: var(--neutral-tint); color: var(--neutral-ink); }
.badge-in_progress { background-color: var(--info-tint); color: var(--info-ink); }
.badge-completed { background-color: var(--good-tint); color: var(--good-ink); }
.badge-expired { background-color: var(--critical-tint); color: var(--critical-ink); }

/* SiteStatus */
.badge-initiation { background-color: var(--info-tint); color: var(--info-ink); }
.badge-closed { background-color: var(--neutral-tint); color: var(--neutral-ink); }

/* ProcessingStatus */
.badge-uploaded { background-color: var(--neutral-tint); color: var(--neutral-ink); }
.badge-ocr_processing,
.badge-extracted { background-color: var(--info-tint); color: var(--info-ink); }
.badge-awaiting_review { background-color: var(--warning-tint); color: var(--warning-ink); }
.badge-failed { background-color: var(--critical-tint); color: var(--critical-ink); }

/* Training verification gate */
.badge-verified { background-color: var(--good-tint); color: var(--good-ink); }
.badge-blocked { background-color: var(--critical-tint); color: var(--critical-ink); }

/* ============================================================================ Activity feed */

.activity-feed {
    list-style: none;
    margin: 0;
    padding: 0;
}

.activity-feed li {
    display: flex;
    gap: 1rem;
    padding: 0.7rem 0;
    border-bottom: 1px solid var(--line);
}

.activity-feed li:last-child {
    border-bottom: none;
}

.activity-feed time {
    color: var(--ink-muted);
    font-size: 0.8125rem;
    white-space: nowrap;
    min-width: 9.5rem;
    font-variant-numeric: tabular-nums;
    padding-top: 0.1rem;
}

/* ============================================================================ Drawer and modal */

.overlay-backdrop {
    position: fixed;
    inset: 0;
    background-color: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(2px);
    z-index: 40;
}

.drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(30rem, 100%);
    background-color: var(--surface);
    box-shadow: var(--shadow-3);
    z-index: 50;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(35rem, calc(100% - 2rem));
    max-height: calc(100vh - 4rem);
    overflow-y: auto;
    background-color: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-3);
    z-index: 50;
}

.overlay-head {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.1rem 1.35rem;
    border-bottom: 1px solid var(--line);
}

.overlay-head h2 {
    margin: 0;
    border: none;
    padding: 0;
    font-size: 1.0625rem;
}

.overlay-body {
    padding: 1.35rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.overlay-foot {
    display: flex;
    justify-content: flex-end;
    gap: 0.7rem;
    padding: 1.1rem 1.35rem;
    border-top: 1px solid var(--line);
    background-color: var(--surface-sunken);
}

.legal-text {
    background-color: var(--surface-sunken);
    border: 1px solid var(--line);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    padding: 0.85rem 1rem;
    font-size: 0.875rem;
    color: var(--ink-secondary);
}

.checklist {
    list-style: none;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 16rem;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 0.75rem 0.9rem;
    background-color: var(--surface);
}

.checklist li {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.checklist .task-name {
    font-weight: 600;
}

/* ============================================================================ Notices and errors */

.form-error {
    background-color: var(--critical-tint);
    border: 1px solid transparent;
    border-left: 3px solid var(--critical);
    border-radius: var(--radius-sm);
    color: var(--critical-ink);
    padding: 0.8rem 1rem;
    font-size: 0.875rem;
}

.form-error ul {
    margin: 0.4rem 0 0;
    padding-left: 1.2rem;
}

.field-error {
    color: var(--critical-ink);
    font-size: 0.8125rem;
}

.field-warn {
    color: var(--warning-ink);
    font-size: 0.8125rem;
}

.notice {
    border: 1px solid var(--line);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius-sm);
    background-color: var(--accent-wash);
    color: var(--ink-secondary);
    padding: 0.85rem 1rem;
    font-size: 0.875rem;
}

.notice.warn {
    background-color: var(--warning-tint);
    border-left-color: var(--warning);
    color: var(--warning-ink);
}

.notice.ok {
    background-color: var(--good-tint);
    border-left-color: var(--good);
    color: var(--good-ink);
}

.notice strong,
.notice.ok strong,
.notice.warn strong {
    color: inherit;
}

/* ============================================================================ Document portal */

.dropzone {
    border: 1.5px dashed var(--line-strong);
    border-radius: var(--radius);
    padding: 1.35rem;
    background-color: var(--surface-sunken);
    transition: border-color 120ms ease, background-color 120ms ease;
}

.dropzone.dragging {
    border-color: var(--accent);
    background-color: var(--accent-wash);
}

.dropzone-hint {
    margin: 0 0 0.9rem;
    color: var(--ink-muted);
    font-size: 0.875rem;
}

.dropzone-fields {
    display: flex;
    align-items: flex-end;
    gap: 1rem;
    flex-wrap: wrap;
}

.dropzone input[type="file"] {
    min-width: 18rem;
    background-color: var(--surface);
    font-size: 0.875rem;
}

.dropzone #upload-result:not(:empty),
.dropzone #certificate-upload-result:not(:empty) {
    margin-top: 1rem;
}

/* Indeterminate progress dot on rows the extraction pipeline still owns. */
.spinner {
    display: inline-block;
    width: 0.5rem;
    height: 0.5rem;
    margin-left: 0.4rem;
    border-radius: 50%;
    background-color: var(--info);
    animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.25; }
    50% { opacity: 1; }
}

/* ============================================================================ Review workspace */

.split-view {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 1.5rem;
    align-items: start;
}

.ocr-raw {
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    line-height: 1.6;
    background-color: var(--surface-sunken);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 1rem;
    max-height: 34rem;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--ink-secondary);
}

.ocr-field-list {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
}

.ocr-field {
    border-left: 3px solid transparent;
    padding-left: 0.8rem;
}

/* The amber highlight the OCR spec requires for sub-threshold extractions. */
.ocr-field.low-confidence {
    border-left-color: var(--warning);
    background-color: var(--warning-tint);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    padding: 0.6rem 0.8rem;
}

.ocr-field .field input {
    width: 100%;
    min-width: 0;
}

.ocr-field .confidence {
    float: right;
    font-variant-numeric: tabular-nums;
    color: var(--ink-muted);
    letter-spacing: normal;
}

.ocr-field.low-confidence .confidence {
    color: var(--warning-ink);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.7rem;
    margin-top: 1.5rem;
}

/* ============================================================================ Audit inspector */

.chain-banner {
    border-left: 3px solid var(--good);
}

.chain-banner.danger {
    border-left-color: var(--critical);
    background-color: var(--critical-tint);
}

.chain-banner-head {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 0.8rem;
}

.chain-detail {
    margin: 0.5rem 0 0;
    font-weight: 600;
}

.detail-list {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    gap: 0.6rem 1.25rem;
    margin: 0;
}

.detail-list dt {
    color: var(--ink-muted);
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding-top: 0.15rem;
}

.detail-list dd {
    margin: 0;
    min-width: 0;
}

.hash-full {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    background-color: var(--surface-sunken);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 0.15rem 0.4rem;
    word-break: break-all;
    color: var(--ink-secondary);
}

.json-payload {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    line-height: 1.6;
    background-color: var(--surface-sunken);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 0.9rem;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--ink-secondary);
}

/* ============================================================================ HTMX plumbing */

.htmx-indicator {
    opacity: 0;
    transition: opacity 150ms ease-in;
    color: var(--ink-muted);
    font-size: 0.875rem;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
    opacity: 1;
}

.htmx-swapping {
    opacity: 0.5;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* ============================================================================ Responsive */

@media (max-width: 1000px) {
    .split-view {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 720px) {
    header.appbar {
        flex-wrap: wrap;
        padding: 0.6rem 1rem;
        gap: 0.6rem;
    }

    header.appbar nav {
        order: 3;
        width: 100%;
        flex-basis: 100%;
    }

    .container {
        padding: 0 1rem;
        margin: 1.25rem auto;
    }

    section {
        padding: 1.25rem;
    }
}

/* ============================================================================ Motion */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .spinner {
        animation: none;
        opacity: 0.6;
    }
}
