/*
 * Basis design system – plain CSS, no framework, no build step (ADR 0028).
 * Pages use only the components below; colours, type, spacing come from tokens.
 * A product changes its brand in css/brand.css (layer "brand", loaded last) – never here.
 */
@layer reset, tokens, base, layout, components, utilities, brand;

/* ------------------------------------------------------------------ tokens */
@layer tokens {
    :root {
        /* Accent scale: the only colours a product normally overrides. */
        --accent-50: #eef4fc;
        --accent-100: #dbe7f8;
        --accent-200: #b6cff0;
        --accent-500: #2f72c4;
        --accent-600: #1f5fae;
        --accent-700: #194f91;
        --accent-800: #174a87;
        --accent-900: #10325c;

        /* Semantic colours (light). A later dark mode only redefines these. */
        --color-bg: #f7f8fa;
        --color-surface: #ffffff;
        --color-surface-subtle: #f1f3f6;
        --color-text: #161b26;
        --color-text-muted: #525c6b;
        --color-border: #dfe3e9;
        --color-border-strong: #c5ccd6;
        --color-border-input: #7b8594;
        --color-accent: var(--accent-600);
        --color-accent-hover: var(--accent-700);
        --color-on-accent: #ffffff;
        --color-accent-subtle: var(--accent-50);
        --color-accent-subtle-text: var(--accent-800);
        --color-danger: #b42318;
        --color-danger-hover: #912018;
        --color-danger-subtle: #fdecea;
        --color-danger-subtle-text: #8f1c13;
        --color-danger-border: #f4bdb7;
        --color-danger-ring: #f6c6c1;
        --color-on-danger: #ffffff;
        --color-success: #157f3b;
        --color-success-subtle: #e6f4ea;
        --color-success-subtle-text: #0f5c2b;
        --color-success-border: #b7dfc4;
        --color-warning: #b54708;
        --color-warning-subtle: #fef4e6;
        --color-warning-subtle-text: #8a3a06;
        --color-warning-border: #f5d6a8;
        --color-row-hover: #fafbfc;
        --color-focus: var(--accent-600);
        --color-sidebar: #ffffff;
        --color-sidebar-text: var(--color-text);
        --color-sidebar-muted: var(--color-text-muted);
        --color-sidebar-hover: var(--color-surface-subtle);
        --color-sidebar-active: var(--accent-50);
        --color-sidebar-active-text: var(--accent-800);

        /* Type */
        --font-sans: system-ui, "Segoe UI Variable Text", "Segoe UI", -apple-system, Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
        --font-mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, "Liberation Mono", monospace;
        --text-xs: 0.75rem;
        --text-sm: 0.875rem;
        --text-base: 1rem;
        --text-lg: 1.125rem;
        --text-xl: 1.25rem;
        --text-2xl: 1.5rem;
        --text-3xl: 1.875rem;

        /* Space (4 px grid), radius, shadow, motion */
        --space-1: 0.25rem;
        --space-2: 0.5rem;
        --space-3: 0.75rem;
        --space-4: 1rem;
        --space-5: 1.25rem;
        --space-6: 1.5rem;
        --space-8: 2rem;
        --space-10: 2.5rem;
        --space-12: 3rem;
        --radius-sm: 4px;
        --radius: 8px;
        --radius-lg: 12px;
        --radius-full: 999px;
        --shadow-sm: 0 1px 2px rgb(16 24 40 / 0.06);
        --shadow-md: 0 4px 12px rgb(16 24 40 / 0.10);
        --shadow-lg: 0 12px 32px rgb(16 24 40 / 0.18);
        --duration-fast: 120ms;
        --duration: 200ms;
        --ease: cubic-bezier(0.2, 0, 0, 1);

        /* Widths */
        --width-content: 1200px;
        --width-form: 640px;
        --width-auth: 420px;
        --width-sidebar: 248px;
        --control-height: 2.5rem;

        color-scheme: light;
    }

    /*
     * Dark mode (ADR 0031): only semantic colours change. "data-theme" on <html> is "light", "dark" or "system";
     * ui.js turns "system" into the setting of the device. The accent follows the brand: its light steps carry text
     * and buttons, its darkest step the subtle backgrounds.
     */
    :root[data-theme="dark"] {
        --color-bg: #0e1117;
        --color-surface: #161b22;
        --color-surface-subtle: #1f2630;
        --color-text: #e6edf3;
        --color-text-muted: #9da7b3;
        --color-border: #2d3540;
        --color-border-strong: #3d4651;
        --color-border-input: #7a8594;
        --color-accent: var(--accent-200);
        --color-accent-hover: var(--accent-100);
        --color-on-accent: #0b1220;
        --color-accent-subtle: var(--accent-900);
        --color-accent-subtle-text: var(--accent-100);
        --color-danger: #f47067;
        --color-danger-hover: #ff938a;
        --color-danger-subtle: #3b1614;
        --color-danger-subtle-text: #ffb4ab;
        --color-danger-border: #6b2620;
        --color-danger-ring: #6b2620;
        --color-on-danger: #1b0806;
        --color-success: #56d364;
        --color-success-subtle: #12261a;
        --color-success-subtle-text: #7ee2a8;
        --color-success-border: #1f4d2e;
        --color-warning: #e3b341;
        --color-warning-subtle: #2e2410;
        --color-warning-subtle-text: #f2cc60;
        --color-warning-border: #5a4514;
        --color-row-hover: #1a2029;
        --color-focus: var(--accent-200);
        --color-sidebar: #161b22;
        --color-sidebar-text: var(--color-text);
        --color-sidebar-muted: var(--color-text-muted);
        --color-sidebar-hover: #1f2630;
        --color-sidebar-active: var(--accent-900);
        --color-sidebar-active-text: var(--accent-100);
        --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4);
        --shadow-md: 0 4px 12px rgb(0 0 0 / 0.45);
        --shadow-lg: 0 12px 32px rgb(0 0 0 / 0.55);

        color-scheme: dark;
    }

    /* The platform area gets a dark sidebar so nobody mistakes it for an organisation. */
    .app-platform {
        --color-sidebar: #111827;
        --color-sidebar-text: #e5e8ee;
        --color-sidebar-muted: #a3acba;
        --color-sidebar-hover: #1f2937;
        --color-sidebar-active: #273449;
        --color-sidebar-active-text: #ffffff;
    }

    @media (prefers-reduced-motion: reduce) {
        :root {
            --duration-fast: 0ms;
            --duration: 0ms;
        }
    }
}

/* ------------------------------------------------------------------- reset */
@layer reset {
    *, *::before, *::after { box-sizing: border-box; }
    body, h1, h2, h3, h4, p, figure, blockquote, dl, dd { margin: 0; }
    img, svg { display: block; max-width: 100%; }
    input, button, textarea, select { font: inherit; color: inherit; }
    [hidden] { display: none !important; }
}

/* -------------------------------------------------------------------- base */
@layer base {
    html { -webkit-text-size-adjust: 100%; }

    body {
        min-height: 100vh;
        font-family: var(--font-sans);
        font-size: var(--text-base);
        line-height: 1.5;
        color: var(--color-text);
        background: var(--color-bg);
        overflow-wrap: break-word;
    }

    h1 { font-size: var(--text-2xl); line-height: 2rem; font-weight: 650; letter-spacing: -0.01em; }
    h2 { font-size: var(--text-xl); line-height: 1.75rem; font-weight: 600; margin: var(--space-8) 0 var(--space-3); }
    h3 { font-size: var(--text-lg); line-height: 1.5rem; font-weight: 600; margin: var(--space-6) 0 var(--space-2); }
    p + p { margin-top: var(--space-3); }
    main p, main ul, main ol { max-width: 75ch; }
    main :is(p, ul, ol) + :is(p, ul, ol, .actions, .form) { margin-top: var(--space-3); }
    ul, ol { padding-left: var(--space-6); }

    a { color: var(--color-accent); text-underline-offset: 0.2em; }
    a:hover { color: var(--color-accent-hover); }

    code, kbd, pre, samp { font-family: var(--font-mono); font-size: 0.9em; }
    small { font-size: var(--text-sm); }
    hr { border: 0; border-top: 1px solid var(--color-border); margin: var(--space-6) 0; }

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

    ::selection { background: var(--accent-100); }

    table { font-variant-numeric: tabular-nums; }
}

/* ------------------------------------------------------------------ layout */
@layer layout {
    .skip-link {
        position: absolute;
        left: var(--space-4);
        top: var(--space-2);
        z-index: 100;
        padding: var(--space-2) var(--space-4);
        color: var(--color-on-accent);
        background: var(--color-accent);
        border-radius: var(--radius);
        transform: translateY(-200%);
    }
    .skip-link:focus { transform: none; color: var(--color-on-accent); }

    /* App shell: sidebar on wide screens, top bar with a menu button below 1024 px. */
    .app { min-height: 100vh; }

    .sidebar {
        display: flex;
        flex-direction: column;
        gap: var(--space-4);
        padding: var(--space-4) var(--space-3);
        color: var(--color-sidebar-text);
        background: var(--color-sidebar);
        border-right: 1px solid var(--color-border);
    }
    .app-platform .sidebar { border-right-color: transparent; }

    .appbar {
        position: sticky;
        top: 0;
        z-index: 20;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: var(--space-3);
        min-height: 3.5rem;
        padding: var(--space-2) var(--space-4);
        color: var(--color-sidebar-text);
        background: var(--color-sidebar);
        border-bottom: 1px solid var(--color-border);
    }
    .appbar .brand { font-size: var(--text-base); }

    .menu-button { display: none; }

    @media (min-width: 1024px) {
        .app {
            display: grid;
            grid-template-columns: var(--width-sidebar) minmax(0, 1fr);
            /* The sidebar colour continues below the sticky sidebar on long pages. */
            background: linear-gradient(to right, var(--color-sidebar) calc(var(--width-sidebar) - 1px), var(--color-border) 0 var(--width-sidebar), transparent 0);
        }
        .app > .appbar { display: none; }
        .sidebar {
            position: sticky;
            top: 0;
            height: 100vh;
            overflow-y: auto;
        }
    }

    @media (max-width: 1023.98px) {
        /* With JavaScript the navigation folds into the menu button; without it, it stays open above the content. */
        .js .menu-button { display: inline-flex; }
        .js .app .sidebar { display: none; }
        .js .app.menu-open .sidebar {
            display: flex;
            position: fixed;
            inset: 3.5rem 0 0 0;
            z-index: 30;
            overflow-y: auto;
            box-shadow: var(--shadow-lg);
        }
        .js .app.menu-open { overflow: hidden; }
        .app > .sidebar .sidebar-brand { display: none; }
    }

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

    .content {
        width: 100%;
        max-width: var(--width-content);
        margin: 0 auto;
        padding: var(--space-6) var(--space-4) var(--space-10);
        flex: 1;
    }
    @media (min-width: 640px) { .content { padding: var(--space-8) var(--space-8) var(--space-12); } }

    /* Kept for products that still use it. */
    .container { max-width: var(--width-content); margin: 0 auto; padding: var(--space-6) var(--space-4); }

    /* Sign-in, registration and other pages without navigation: one centred column. */
    .auth {
        min-height: 100vh;
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: var(--space-6) var(--space-4);
    }
    .auth-head { width: 100%; max-width: var(--width-form); display: flex; justify-content: space-between; align-items: center; gap: var(--space-4); margin-bottom: var(--space-8); }
    .auth .content { max-width: var(--width-form); padding: 0; flex: 0 0 auto; }
    .auth.auth-narrow .content { max-width: var(--width-auth); }
    .auth .content > h1 { margin-bottom: var(--space-2); }
    .auth .content > h1 + .muted, .auth .content > h1 + p { margin-bottom: var(--space-6); }
    .auth .footer { margin-top: auto; padding: var(--space-10) 0 0; max-width: var(--width-form); }
    .auth.auth-narrow .content > .card, .auth-card {
        padding: var(--space-8) var(--space-6);
        background: var(--color-surface);
        border: 1px solid var(--color-border);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-sm);
    }
    @media (max-width: 479.98px) { .auth-card { padding: var(--space-6) var(--space-4); } }
    .auth-card > h1 { margin-bottom: var(--space-1); }
    .auth-card > h1 + p { margin-bottom: var(--space-6); color: var(--color-text-muted); }
    .auth-card .form { max-width: none; }

    .footer {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: var(--space-2) var(--space-4);
        width: 100%;
        max-width: var(--width-content);
        margin: 0 auto;
        padding: var(--space-4);
        color: var(--color-text-muted);
        font-size: var(--text-sm);
    }
    @media (min-width: 640px) { .app .footer { padding: var(--space-4) var(--space-8) var(--space-6); } }
    .footer a { color: var(--color-text-muted); }
    .footer .languages { display: flex; gap: var(--space-2); margin-left: auto; }
    .footer .languages button, .footer .themes button { padding: 0 var(--space-1); color: var(--color-text-muted); background: none; border: 0; cursor: pointer; text-decoration: underline; text-underline-offset: 0.2em; }
    .footer .languages button[aria-current="true"], .footer .themes button[aria-current="true"] { color: var(--color-text); font-weight: 600; text-decoration: none; }

    .stack > * + * { margin-top: var(--space-6); }
    .grid-2 { display: grid; gap: var(--space-6); align-items: start; }
    @media (min-width: 1024px) { .grid-2 { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); } }
}

/* -------------------------------------------------------------- components */
@layer components {
    /* Icons: own SVG drawings used as masks, so they take the text colour. */
    .icon {
        /* Unknown icon names (e.g. a new module's) show a neutral document instead of a filled square. */
        --icon: url("../icons/file.svg");
        display: inline-block;
        flex: none;
        width: 1.25em;
        height: 1.25em;
        vertical-align: -0.25em;
        background-color: currentColor;
        -webkit-mask: var(--icon) center / contain no-repeat;
        mask: var(--icon) center / contain no-repeat;
    }
    .icon-sm { width: 1rem; height: 1rem; }
    .icon-lg { width: 1.5rem; height: 1.5rem; }
    .icon-xl { width: 2.5rem; height: 2.5rem; }
    .icon-home { --icon: url("../icons/home.svg"); }
    .icon-notes { --icon: url("../icons/notes.svg"); }
    .icon-file { --icon: url("../icons/file.svg"); }
    .icon-bell { --icon: url("../icons/bell.svg"); }
    .icon-help { --icon: url("../icons/help.svg"); }
    .icon-lifebuoy { --icon: url("../icons/lifebuoy.svg"); }
    .icon-send { --icon: url("../icons/send.svg"); }
    .icon-sun { --icon: url("../icons/sun.svg"); }
    .icon-moon { --icon: url("../icons/moon.svg"); }
    .icon-users { --icon: url("../icons/users.svg"); }
    .icon-shield { --icon: url("../icons/shield.svg"); }
    .icon-settings { --icon: url("../icons/settings.svg"); }
    .icon-card { --icon: url("../icons/card.svg"); }
    .icon-building { --icon: url("../icons/building.svg"); }
    .icon-chart { --icon: url("../icons/chart.svg"); }
    .icon-user { --icon: url("../icons/user.svg"); }
    .icon-receipt { --icon: url("../icons/receipt.svg"); }
    .icon-plug { --icon: url("../icons/plug.svg"); }
    .icon-list { --icon: url("../icons/list.svg"); }
    .icon-logout { --icon: url("../icons/logout.svg"); }
    .icon-chevrons { --icon: url("../icons/chevrons.svg"); }
    .icon-chevron-down { --icon: url("../icons/chevron-down.svg"); }
    .icon-chevron-right { --icon: url("../icons/chevron-right.svg"); }
    .icon-check { --icon: url("../icons/check.svg"); }
    .icon-x { --icon: url("../icons/x.svg"); }
    .icon-info { --icon: url("../icons/info.svg"); }
    .icon-warning { --icon: url("../icons/warning.svg"); }
    .icon-error { --icon: url("../icons/error.svg"); }
    .icon-success { --icon: url("../icons/success.svg"); }
    .icon-trash { --icon: url("../icons/trash.svg"); }
    .icon-copy { --icon: url("../icons/copy.svg"); }
    .icon-printer { --icon: url("../icons/printer.svg"); }
    .icon-menu { --icon: url("../icons/menu.svg"); }
    .icon-plus { --icon: url("../icons/plus.svg"); }
    .icon-download { --icon: url("../icons/download.svg"); }
    .icon-external { --icon: url("../icons/external.svg"); }
    .icon-lock { --icon: url("../icons/lock.svg"); }
    .icon-globe { --icon: url("../icons/globe.svg"); }
    .icon-clock { --icon: url("../icons/clock.svg"); }
    .icon-key { --icon: url("../icons/key.svg"); }
    .icon-monitor { --icon: url("../icons/monitor.svg"); }
    .icon-phone { --icon: url("../icons/phone.svg"); }
    .icon-mail { --icon: url("../icons/mail.svg"); }
    .icon-arrow-left { --icon: url("../icons/arrow-left.svg"); }
    .icon-eye { --icon: url("../icons/eye.svg"); }
    .icon-pause { --icon: url("../icons/pause.svg"); }
    .icon-gift { --icon: url("../icons/gift.svg"); }
    .icon-refund { --icon: url("../icons/refund.svg"); }
    .icon-tag { --icon: url("../icons/tag.svg"); }
    .icon-search { --icon: url("../icons/search.svg"); }
    .icon-calendar { --icon: url("../icons/calendar.svg"); }
    .icon-sparkles { --icon: url("../icons/sparkles.svg"); }

    /* Brand, organisation switcher, navigation, user menu */
    .brand {
        display: inline-flex;
        align-items: center;
        gap: var(--space-2);
        min-width: 0;
        font-weight: 650;
        font-size: var(--text-lg);
        color: inherit;
        text-decoration: none;
    }
    .brand:hover { color: inherit; }
    .brand-logo { max-height: 32px; max-width: 140px; object-fit: contain; }
    .brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .area-badge {
        padding: 0 var(--space-2);
        font-size: var(--text-xs);
        font-weight: 600;
        line-height: 1.25rem;
        letter-spacing: 0.02em;
        text-transform: uppercase;
        color: #111827;
        background: #fbbf24;
        border-radius: var(--radius-sm);
    }

    .avatar {
        display: inline-grid;
        place-items: center;
        flex: none;
        width: 2rem;
        height: 2rem;
        font-size: var(--text-xs);
        font-weight: 650;
        color: var(--accent-800);
        background: var(--accent-100);
        border-radius: var(--radius-full);
    }
    .avatar-org { border-radius: var(--radius); color: var(--color-on-accent); background: var(--color-accent); }
    .avatar img { width: 100%; height: 100%; object-fit: contain; border-radius: inherit; background: var(--color-surface); }

    .switcher, .usermenu { position: relative; }
    .switcher > summary, .usermenu > summary, .sidebar-brand {
        display: flex;
        align-items: center;
        gap: var(--space-3);
        width: 100%;
        padding: var(--space-2);
        list-style: none;
        border-radius: var(--radius);
        cursor: pointer;
    }
    .sidebar-brand { cursor: default; }
    .switcher > summary::-webkit-details-marker, .usermenu > summary::-webkit-details-marker { display: none; }
    .switcher > summary:hover, .usermenu > summary:hover { background: var(--color-sidebar-hover); }
    .switcher > summary .icon, .usermenu > summary .icon { margin-left: auto; color: var(--color-sidebar-muted); }
    .menu-label { display: flex; flex-direction: column; min-width: 0; line-height: 1.25rem; }
    .menu-label strong { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .menu-label span { font-size: var(--text-xs); color: var(--color-sidebar-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

    .popover {
        position: absolute;
        left: 0;
        right: 0;
        z-index: 40;
        margin: var(--space-1) 0 0;
        padding: var(--space-1);
        list-style: none;
        color: var(--color-text);
        background: var(--color-surface);
        border: 1px solid var(--color-border);
        border-radius: var(--radius);
        box-shadow: var(--shadow-md);
    }
    .usermenu .popover { top: auto; bottom: 100%; margin: 0 0 var(--space-1); }
    .popover li + li { margin-top: 2px; }
    .popover hr { margin: var(--space-1) 0; }
    .popover a, .popover button {
        display: flex;
        align-items: center;
        gap: var(--space-2);
        width: 100%;
        padding: var(--space-2);
        font-size: var(--text-sm);
        text-align: left;
        color: var(--color-text);
        text-decoration: none;
        background: none;
        border: 0;
        border-radius: var(--radius-sm);
        cursor: pointer;
    }
    .popover a:hover, .popover button:hover { background: var(--color-surface-subtle); }
    .popover [aria-current="true"] { font-weight: 600; }
    .popover [aria-current="true"]::after { content: ""; margin-left: auto; width: 1rem; height: 1rem; background: currentColor; -webkit-mask: url("../icons/check.svg") center / contain no-repeat; mask: url("../icons/check.svg") center / contain no-repeat; }
    .popover-title { padding: var(--space-1) var(--space-2); font-size: var(--text-xs); color: var(--color-text-muted); }

    .mainnav { display: flex; flex-direction: column; gap: var(--space-4); flex: 1; }
    .nav-group { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; list-style: none; }
    .nav-group-title {
        padding: 0 var(--space-2) var(--space-1);
        font-size: var(--text-xs);
        font-weight: 600;
        letter-spacing: 0.04em;
        text-transform: uppercase;
        color: var(--color-sidebar-muted);
    }
    .nav-link {
        display: flex;
        align-items: center;
        gap: var(--space-3);
        min-height: 2.25rem;
        padding: var(--space-1) var(--space-2);
        font-size: var(--text-sm);
        font-weight: 500;
        color: var(--color-sidebar-text);
        text-decoration: none;
        border-radius: var(--radius);
    }
    .nav-link .icon { color: var(--color-sidebar-muted); }
    .nav-link:hover { color: var(--color-sidebar-text); background: var(--color-sidebar-hover); }
    .nav-link[aria-current="page"] { color: var(--color-sidebar-active-text); background: var(--color-sidebar-active); font-weight: 600; }
    .nav-link[aria-current="page"] .icon { color: currentColor; }
    .sidebar-foot { margin-top: auto; padding-top: var(--space-3); border-top: 1px solid var(--color-border); }
    .app-platform .sidebar-foot { border-top-color: #273449; }

    /* Banners across the whole page (viewing as organisation, read-only) */
    .banner {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: center;
        gap: var(--space-2) var(--space-4);
        padding: var(--space-2) var(--space-4);
        font-size: var(--text-sm);
        font-weight: 500;
    }
    .banner form { display: inline; }
    .banner-warning { color: var(--color-warning-subtle-text); background: var(--color-warning-subtle); border-bottom: 1px solid var(--color-warning-border); }
    .banner-danger { color: var(--color-on-danger); background: var(--color-danger); }
    .banner-danger .linklike, .banner-danger a { color: var(--color-on-danger); }
    .platform-access { color: #ffffff; background: #9a3412; }
    .platform-access .linklike { color: #ffffff; font-weight: 600; }

    /* Page header */
    .page-header {
        display: flex;
        flex-wrap: wrap;
        align-items: flex-end;
        justify-content: space-between;
        gap: var(--space-3) var(--space-6);
        margin-bottom: var(--space-6);
    }
    .page-header > div:first-child { min-width: 0; }
    .page-header h1 { margin: 0; }
    .page-subtitle { margin-top: var(--space-1); color: var(--color-text-muted); }
    .page-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
    .page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }
    .page-head h1 { margin: 0; }
    .content > h1 { margin-bottom: var(--space-4); }
    .breadcrumb { display: flex; flex-wrap: wrap; gap: var(--space-1); margin: 0 0 var(--space-2); padding: 0; list-style: none; font-size: var(--text-sm); color: var(--color-text-muted); }
    .breadcrumb li + li::before { content: "/"; margin-right: var(--space-1); color: var(--color-border-strong); }
    .breadcrumb a { color: var(--color-text-muted); text-decoration: none; }
    .breadcrumb a:hover { color: var(--color-accent); text-decoration: underline; }

    /* Tabs wrap onto a second line instead of scrolling: a scroll container would also scroll vertically by the 1 px
       the active tab overlaps the line, and Windows shows both scroll bars. */
    .subnav { display: flex; flex-wrap: wrap; gap: 0 var(--space-1); margin: 0 0 var(--space-6); padding: 0; list-style: none; border-bottom: 1px solid var(--color-border); }
    .subnav a { display: block; padding: var(--space-2) var(--space-3); font-size: var(--text-sm); font-weight: 500; white-space: nowrap; color: var(--color-text-muted); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; }
    .subnav a:hover { color: var(--color-text); }
    .subnav a[aria-current="page"] { color: var(--color-accent); border-bottom-color: var(--color-accent); }

    /* Buttons */
    .button {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: var(--space-2);
        min-height: var(--control-height);
        padding: var(--space-2) var(--space-4);
        font-size: var(--text-sm);
        font-weight: 600;
        line-height: 1.25rem;
        text-align: center;
        color: var(--color-on-accent);
        text-decoration: none;
        background: var(--color-accent);
        border: 1px solid var(--color-accent);
        border-radius: var(--radius);
        box-shadow: var(--shadow-sm);
        cursor: pointer;
        transition: background-color var(--duration-fast) var(--ease), border-color var(--duration-fast) var(--ease);
    }
    .button:hover { color: var(--color-on-accent); background: var(--color-accent-hover); border-color: var(--color-accent-hover); }
    .button-secondary { color: var(--color-text); background: var(--color-surface); border-color: var(--color-border-strong); }
    .button-secondary:hover { color: var(--color-text); background: var(--color-surface-subtle); border-color: var(--color-border-input); }
    .button-ghost { color: var(--color-accent); background: transparent; border-color: transparent; box-shadow: none; }
    .button-ghost:hover { color: var(--color-accent-hover); background: var(--color-accent-subtle); border-color: transparent; }
    .button-danger { color: var(--color-on-danger); background: var(--color-danger); border-color: var(--color-danger); }
    .button-danger:hover { color: var(--color-on-danger); background: var(--color-danger-hover); border-color: var(--color-danger-hover); }
    .button-danger.button-secondary, .button-danger-secondary { color: var(--color-danger); background: var(--color-surface); border-color: var(--color-danger-border); }
    .button-danger.button-secondary:hover, .button-danger-secondary:hover { color: var(--color-danger-hover); background: var(--color-danger-subtle); border-color: var(--color-danger); }
    .button-sm { min-height: 2rem; padding: var(--space-1) var(--space-3); font-size: var(--text-sm); }
    .button-block { display: flex; width: 100%; }
    .button:disabled, .button[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
    @media (pointer: coarse) { .button { min-height: 2.75rem; } }

    /* Sign-in link in the header of pages without navigation (deliberately not a .button). */
    .header-link { display: inline-flex; align-items: center; min-height: 2rem; padding: var(--space-1) var(--space-3); font-size: var(--text-sm); font-weight: 600; color: var(--color-text); text-decoration: none; background: var(--color-surface); border: 1px solid var(--color-border-strong); border-radius: var(--radius); }
    .header-link:hover { color: var(--color-text); background: var(--color-surface-subtle); }

    .linklike { padding: 0; font: inherit; color: var(--color-accent); background: none; border: 0; cursor: pointer; text-decoration: underline; text-underline-offset: 0.2em; }
    .linklike:hover { color: var(--color-accent-hover); }
    .linklike.danger { color: var(--color-danger); }

    .actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); margin-top: var(--space-6); }
    .actions-end { justify-content: flex-end; }
    .form-inline { display: inline; }

    /* Forms */
    .form { display: flex; flex-direction: column; gap: var(--space-2); max-width: var(--width-form); }
    .form.narrow { max-width: var(--width-auth); }
    .form.wide { max-width: none; }
    .form > label, .form fieldset > label, .field > label { margin-top: var(--space-3); font-size: var(--text-sm); font-weight: 600; }
    .form > label:first-of-type, .form > .alert + label, .form > input[type="hidden"] + label { margin-top: 0; }
    .form label.checkbox, label.checkbox {
        display: flex;
        align-items: flex-start;
        gap: var(--space-2);
        margin-top: var(--space-2);
        font-weight: 400;
        font-size: var(--text-base);
        cursor: pointer;
    }
    label.checkbox input { margin-top: 0.2rem; }
    .optional { font-weight: 400; color: var(--color-text-muted); }

    input:not([type="checkbox"], [type="radio"], [type="hidden"], [type="file"], [type="submit"], [type="button"]), select, textarea {
        width: 100%;
        min-height: var(--control-height);
        padding: var(--space-2) var(--space-3);
        font-size: var(--text-base);
        color: var(--color-text);
        background: var(--color-surface);
        border: 1px solid var(--color-border-input);
        border-radius: var(--radius);
        transition: border-color var(--duration-fast) var(--ease), box-shadow var(--duration-fast) var(--ease);
    }
    textarea { min-height: 8rem; resize: vertical; line-height: 1.5; }
    select { padding-right: var(--space-8); }
    input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; border-color: var(--color-focus); box-shadow: 0 0 0 3px var(--accent-200); }
    [aria-invalid="true"] { border-color: var(--color-danger) !important; }
    [aria-invalid="true"]:focus-visible { box-shadow: 0 0 0 3px var(--color-danger-ring) !important; }
    input[type="checkbox"], input[type="radio"] { width: 1.125rem; height: 1.125rem; accent-color: var(--color-accent); flex: none; }
    input[type="file"] { font-size: var(--text-sm); max-width: 100%; }
    input[type="file"]::file-selector-button {
        margin-right: var(--space-3);
        padding: var(--space-2) var(--space-4);
        font: inherit;
        font-weight: 600;
        color: var(--color-text);
        background: var(--color-surface);
        border: 1px solid var(--color-border-strong);
        border-radius: var(--radius);
        cursor: pointer;
    }
    input:disabled, select:disabled, textarea:disabled { background: var(--color-surface-subtle); color: var(--color-text-muted); }

    fieldset {
        display: flex;
        flex-direction: column;
        gap: var(--space-2);
        min-width: 0;
        margin: var(--space-4) 0 0;
        padding: var(--space-5);
        background: var(--color-surface);
        border: 1px solid var(--color-border);
        border-radius: var(--radius-lg);
    }
    legend { padding: 0 var(--space-2); margin-left: calc(-1 * var(--space-2)); font-weight: 600; font-size: var(--text-base); }
    fieldset > legend + label, fieldset > legend + .hint { margin-top: 0; }

    .input-suffix, .input-group {
        display: flex;
        align-items: stretch;
        width: 100%;
        background: var(--color-surface);
        border: 1px solid var(--color-border-input);
        border-radius: var(--radius);
        overflow: hidden;
    }
    .input-suffix:focus-within, .input-group:focus-within { border-color: var(--color-focus); box-shadow: 0 0 0 3px var(--accent-200); }
    .input-suffix > span, .input-group > span {
        display: flex;
        align-items: center;
        padding: 0 var(--space-3);
        font-size: var(--text-sm);
        color: var(--color-text-muted);
        background: var(--color-surface-subtle);
        white-space: nowrap;
    }
    .input-suffix > input, .input-group > input { min-width: 0; border: 0 !important; border-radius: 0; box-shadow: none !important; }

    .hint { display: block; font-size: var(--text-sm); color: var(--color-text-muted); }
    .field-error { display: block; font-size: var(--text-sm); font-weight: 500; color: var(--color-danger); }
    .field-error:empty { display: none; }
    .field-error:not(:empty)::before {
        content: "";
        display: inline-block;
        width: 1rem;
        height: 1rem;
        margin-right: var(--space-1);
        vertical-align: -0.2em;
        background: currentColor;
        -webkit-mask: url("../icons/error.svg") center / contain no-repeat;
        mask: url("../icons/error.svg") center / contain no-repeat;
    }

    .form-section { padding: var(--space-6); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); }

    /* Alerts and toasts */
    .alert {
        position: relative;
        display: block;
        max-width: none;
        padding: var(--space-3) var(--space-4) var(--space-3) calc(var(--space-4) + 1.75rem);
        font-size: var(--text-sm);
        color: var(--color-text);
        background: var(--color-surface);
        border: 1px solid var(--color-border);
        border-radius: var(--radius);
    }
    .alert::before {
        content: "";
        position: absolute;
        left: var(--space-4);
        top: calc(var(--space-3) + 0.0625rem);
        width: 1.25rem;
        height: 1.25rem;
        background: var(--alert-icon-color, var(--color-accent));
        -webkit-mask: var(--alert-icon, url("../icons/info.svg")) center / contain no-repeat;
        mask: var(--alert-icon, url("../icons/info.svg")) center / contain no-repeat;
    }
    .alert + .alert, .alert + *, * + .alert { margin-top: var(--space-4); }
    .alert strong:first-child { display: block; }
    .alert .actions { margin-top: var(--space-3); }
    .alert p { max-width: none; }
    .alert ul { margin: var(--space-1) 0 0; padding-left: var(--space-5); }
    .alert a:not(.button) { color: inherit; font-weight: 600; }
    .alert-info { color: var(--color-accent-subtle-text); background: var(--color-accent-subtle); border-color: var(--accent-200); }
    .alert-success { color: var(--color-success-subtle-text); background: var(--color-success-subtle); border-color: var(--color-success-border); --alert-icon: url("../icons/success.svg"); --alert-icon-color: var(--color-success); }
    .alert-warning { color: var(--color-warning-subtle-text); background: var(--color-warning-subtle); border-color: var(--color-warning-border); --alert-icon: url("../icons/warning.svg"); --alert-icon-color: var(--color-warning); }
    .alert-error { color: var(--color-danger-subtle-text); background: var(--color-danger-subtle); border-color: var(--color-danger-border); --alert-icon: url("../icons/error.svg"); --alert-icon-color: var(--color-danger); }
    .alert-error:empty, .validation-summary-valid { display: none; }
    .alert:focus { outline: 2px solid var(--color-focus); outline-offset: 2px; }
    .form > .alert { margin: 0 0 var(--space-2); }

    /* Without JavaScript a toast is an ordinary box above the page content. */
    .toast-region { margin-bottom: var(--space-6); }
    .js .toast-region { position: fixed; top: 4.5rem; right: var(--space-4); left: var(--space-4); z-index: 60; display: flex; flex-direction: column; align-items: flex-end; gap: var(--space-2); margin: 0; pointer-events: none; }
    .js .toast-region .alert { width: min(28rem, 100%); margin: 0; pointer-events: auto; box-shadow: var(--shadow-md); padding-right: var(--space-10); }
    .toast-close { display: none; }
    .js .toast-close { position: absolute; top: var(--space-2); right: var(--space-2); display: grid; place-items: center; width: 1.75rem; height: 1.75rem; color: inherit; background: none; border: 0; border-radius: var(--radius-sm); cursor: pointer; }
    .js .toast-close:hover { background: rgb(0 0 0 / 0.06); }

    /* Badges */
    .badge, .tag {
        display: inline-flex;
        align-items: center;
        gap: var(--space-1);
        padding: 0.0625rem var(--space-2);
        font-size: var(--text-xs);
        font-weight: 600;
        line-height: 1.125rem;
        white-space: nowrap;
        color: var(--color-text-muted);
        background: var(--color-surface-subtle);
        border: 1px solid var(--color-border);
        border-radius: var(--radius-full);
        vertical-align: 0.1em;
    }
    .badge-dot::before { content: ""; width: 0.375rem; height: 0.375rem; border-radius: 50%; background: currentColor; }
    .badge-accent { color: var(--color-accent-subtle-text); background: var(--color-accent-subtle); border-color: var(--accent-200); }
    .badge-success { color: var(--color-success-subtle-text); background: var(--color-success-subtle); border-color: var(--color-success-border); }
    .badge-warning { color: var(--color-warning-subtle-text); background: var(--color-warning-subtle); border-color: var(--color-warning-border); }
    .badge-danger { color: var(--color-danger-subtle-text); background: var(--color-danger-subtle); border-color: var(--color-danger-border); }
    .badges { display: inline-flex; flex-wrap: wrap; gap: var(--space-1); }

    /* Cards */
    .card {
        display: block;
        padding: var(--space-5);
        background: var(--color-surface);
        border: 1px solid var(--color-border);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-sm);
    }
    .card + .card, .card + .danger-zone, .card + fieldset, form + .card { margin-top: var(--space-6); }
    :is(.choice, .cards, .grid-2, .plans, .stats) > .card { margin-top: 0; }
    .card > h2:first-child, .card > h3:first-child, .card-header h2, .card-header h3 { margin: 0; font-size: var(--text-lg); }
    .card > h2:first-child, .card > h3:first-child { margin-bottom: var(--space-3); }
    .card-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2) var(--space-4); margin-bottom: var(--space-4); }
    .card-header p { margin-top: var(--space-1); color: var(--color-text-muted); font-size: var(--text-sm); }
    .card-footer { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--space-3); margin: var(--space-5) calc(-1 * var(--space-5)) calc(-1 * var(--space-5)); padding: var(--space-4) var(--space-5); background: var(--color-surface-subtle); border-top: 1px solid var(--color-border); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
    .card-form { max-width: var(--width-form); }
    .card-title { margin: 0 0 var(--space-2); font-size: var(--text-lg); font-weight: 600; }
    .card .form { max-width: none; }
    .card > .table-wrap:last-child { margin-bottom: calc(-1 * var(--space-5)); }
    .card > .table-wrap { margin-left: calc(-1 * var(--space-5)); margin-right: calc(-1 * var(--space-5)); border-radius: 0 0 var(--radius-lg) var(--radius-lg); border-width: 1px 0 0; box-shadow: none; }
    .card > .table-wrap:not(:last-child) { border-radius: 0; border-width: 1px 0; }

    .cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); gap: var(--space-4); margin: 0; padding: 0; list-style: none; }
    .cards > li { display: flex; }
    .cards > li > .card { flex: 1; }
    .card-link { position: relative; transition: border-color var(--duration-fast) var(--ease), box-shadow var(--duration-fast) var(--ease); }
    .card-link:hover { border-color: var(--color-border-strong); box-shadow: var(--shadow-md); }
    .card-link a.stretched { color: var(--color-text); text-decoration: none; }
    .card-link a.stretched::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
    .card-link:focus-within { outline: 2px solid var(--color-focus); outline-offset: 2px; }
    .card-link a.stretched:focus-visible { outline: none; }
    /* A second link inside such a card, e.g. "Attachments (2)": above the stretched one, so it can be clicked. */
    .card-link a.above { position: relative; z-index: 1; }
    .note-body { white-space: pre-line; }
    .note-text { display: -webkit-box; -webkit-line-clamp: 3; line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; color: var(--color-text-muted); white-space: pre-line; }

    /* Danger zone */
    .danger-zone {
        display: block;
        margin-top: var(--space-10);
        padding: var(--space-5);
        background: var(--color-surface);
        border: 1px solid var(--color-danger-border);
        border-radius: var(--radius-lg);
    }
    .danger-zone > h2:first-child { margin: 0 0 var(--space-3); font-size: var(--text-lg); color: var(--color-danger); }
    .danger-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3) var(--space-6); padding: var(--space-4) 0; border-top: 1px solid var(--color-border); }
    .danger-zone > h2 + .danger-row { border-top: 0; padding-top: 0; }
    .danger-row:last-child { padding-bottom: 0; }
    .danger-row > div:first-child { flex: 1 1 18rem; }
    .danger-row h3 { margin: 0; font-size: var(--text-base); }
    .danger-row p { margin-top: var(--space-1); font-size: var(--text-sm); color: var(--color-text-muted); }
    .danger-row .form { flex: 1 1 100%; }

    /* Tables */
    .table-wrap {
        width: 100%;
        overflow-x: auto;
        background: var(--color-surface);
        border: 1px solid var(--color-border);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-sm);
    }
    .table-wrap + *, * + .table-wrap { margin-top: var(--space-4); }
    .table { width: 100%; border-collapse: collapse; background: var(--color-surface); font-size: var(--text-sm); }
    .table caption { padding: var(--space-3) var(--space-4); text-align: left; font-weight: 600; }
    .table th, .table td { padding: var(--space-3) var(--space-4); text-align: left; vertical-align: middle; border-bottom: 1px solid var(--color-border); }
    .table thead th { font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.02em; text-transform: uppercase; color: var(--color-text-muted); background: var(--color-surface-subtle); white-space: nowrap; }
    .table tbody tr:last-child > * { border-bottom: 0; }
    .table tbody tr:hover > * { background: var(--color-row-hover); }
    .table .num { text-align: right; white-space: nowrap; }
    .table .actions-cell { text-align: right; white-space: nowrap; }
    .table .actions-cell > * + * { margin-left: var(--space-2); }
    .table td form { display: inline; }
    .table .muted { font-size: var(--text-sm); }
    .table-wrap > .table { min-width: 100%; }
    .cell-main { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
    .cell-main > div { min-width: 0; }
    .cell-main strong, .cell-main a { font-weight: 600; }
    .cell-sub { display: block; color: var(--color-text-muted); font-size: var(--text-xs); }
    .table-empty { padding: var(--space-8) var(--space-4); text-align: center; color: var(--color-text-muted); }
    .table-empty .icon { margin: 0 auto var(--space-2); }

    /* Below 640 px the main lists become one card per row; each cell shows its column name. */
    @media (max-width: 639.98px) {
        .table-stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
        .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
        .table-stack tr { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--color-border); }
        .table-stack tbody tr:last-child { border-bottom: 0; }
        .table-stack td { display: flex; justify-content: space-between; gap: var(--space-4); padding: var(--space-1) 0; border: 0; text-align: right; }
        .table-stack td[data-label]::before { content: attr(data-label); font-weight: 600; color: var(--color-text-muted); text-align: left; }
        .table-stack td:first-child { display: block; text-align: left; padding-bottom: var(--space-2); }
        .table-stack td.actions-cell { justify-content: flex-end; padding-top: var(--space-2); }
        .table-stack td.num { white-space: normal; }
    }

    /* Empty states */
    .empty {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: var(--space-2);
        padding: var(--space-10) var(--space-6);
        text-align: center;
        background: var(--color-surface);
        border: 1px dashed var(--color-border-strong);
        border-radius: var(--radius-lg);
    }
    .empty .icon { color: var(--color-text-muted); }
    .empty h2, .empty h3 { margin: var(--space-2) 0 0; font-size: var(--text-lg); }
    .empty p { max-width: 42ch; color: var(--color-text-muted); }
    .empty .actions { justify-content: center; margin-top: var(--space-3); }

    /* Facts (definition lists) and key figures */
    .facts { display: grid; grid-template-columns: minmax(8rem, max-content) 1fr; gap: var(--space-2) var(--space-6); margin: 0; font-size: var(--text-sm); }
    .facts dt { color: var(--color-text-muted); font-weight: 500; }
    .facts dd { margin: 0; min-width: 0; }
    @media (max-width: 479.98px) { .facts { grid-template-columns: 1fr; gap: 0; } .facts dd { margin-bottom: var(--space-2); } }

    .stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr)); gap: var(--space-4); margin: 0; }
    .stat { display: flex; flex-direction: column; justify-content: flex-start; gap: var(--space-1); padding: var(--space-5); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
    .stat dt { font-size: var(--text-sm); color: var(--color-text-muted); }
    .stat dd { margin: 0; font-size: var(--text-3xl); line-height: 2.25rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
    .stat-hero { grid-column: 1 / -1; background: linear-gradient(135deg, var(--accent-600), var(--accent-800)); border-color: transparent; }
    .stat-hero dt { color: rgb(255 255 255 / 0.85); }
    .stat-hero dd { color: #ffffff; font-size: 2.5rem; line-height: 2.75rem; }
    .stats-title { margin: var(--space-8) 0 var(--space-3); font-size: var(--text-sm); font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--color-text-muted); }

    /* Filters */
    .filters {
        display: flex;
        flex-wrap: wrap;
        align-items: flex-end;
        gap: var(--space-3);
        margin: 0 0 var(--space-4);
        padding: var(--space-4);
        background: var(--color-surface);
        border: 1px solid var(--color-border);
        border-radius: var(--radius-lg);
    }
    .filters input:not([type="checkbox"]), .filters select { width: auto; min-width: 10rem; flex: 1 1 12rem; max-width: 22rem; }
    .filters label.checkbox { margin: 0; align-self: center; font-size: var(--text-sm); }
    .filters .filter-count { margin-left: auto; align-self: center; font-size: var(--text-sm); color: var(--color-text-muted); }

    .pager { display: flex; align-items: center; gap: var(--space-3); margin: var(--space-4) 0; }

    /* Lists */
    .links { padding-left: var(--space-5); }
    .links li + li { margin-top: var(--space-1); }
    .link-list { margin: 0; padding: 0; list-style: none; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); }
    .link-list li + li { border-top: 1px solid var(--color-border); }
    .link-list a { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); color: var(--color-text); text-decoration: none; }
    .link-list a:hover { background: var(--color-surface-subtle); }
    .link-list a > .icon:last-child { margin-left: auto; color: var(--color-text-muted); }
    .link-list .row-text { display: flex; flex-direction: column; min-width: 0; }
    .link-list .row-text span { font-size: var(--text-sm); color: var(--color-text-muted); }
    .link-list .row-status { margin-left: auto; }

    /* Timeline */
    .timeline { margin: 0; padding: 0; list-style: none; }
    .timeline > li { position: relative; padding: 0 0 var(--space-4) var(--space-6); border-left: 2px solid var(--color-border); margin-left: var(--space-2); }
    .timeline > li:last-child { border-left-color: transparent; }
    .timeline > li::before { content: ""; position: absolute; left: -0.4375rem; top: 0.375rem; width: 0.75rem; height: 0.75rem; border-radius: 50%; background: var(--color-surface); border: 2px solid var(--color-border-strong); }
    .timeline > li.is-note::before { border-color: var(--color-accent); background: var(--color-accent); }
    .timeline time, .timeline .meta { display: block; font-size: var(--text-xs); color: var(--color-text-muted); }
    .timeline .note-text { -webkit-line-clamp: unset; line-clamp: unset; color: var(--color-text); }

    /* Plans */
    .plans { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); gap: var(--space-4); margin: 0; padding: 0; list-style: none; }
    .plan { display: flex; flex-direction: column; gap: var(--space-3); padding: var(--space-5); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
    .plan.is-current { border: 2px solid var(--color-accent); padding: calc(var(--space-5) - 1px); }
    .plan-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2); }
    .plan h3 { margin: 0; }
    .plan-price { font-size: var(--text-3xl); line-height: 2.25rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
    .plan-price small { display: block; font-size: var(--text-sm); font-weight: 400; letter-spacing: 0; color: var(--color-text-muted); }
    .plan-features { margin: 0; padding: 0; list-style: none; font-size: var(--text-sm); flex: 1; }
    .plan-features li { display: flex; gap: var(--space-2); }
    .plan-features li + li { margin-top: var(--space-1); }
    .plan-features li::before { content: ""; flex: none; width: 1rem; height: 1rem; margin-top: 0.125rem; background: var(--color-success); -webkit-mask: url("../icons/check.svg") center / contain no-repeat; mask: url("../icons/check.svg") center / contain no-repeat; }
    .plan form, .plan .button { width: 100%; }
    .plan .actions { margin-top: 0; }

    progress, meter {
        width: 100%;
        height: 0.5rem;
        appearance: none;
        border: 0;
        border-radius: var(--radius-full);
        background: var(--color-surface-subtle);
        overflow: hidden;
    }
    progress::-webkit-progress-bar { background: var(--color-surface-subtle); border-radius: var(--radius-full); }
    progress::-webkit-progress-value { background: var(--color-accent); border-radius: var(--radius-full); }
    progress::-moz-progress-bar { background: var(--color-accent); border-radius: var(--radius-full); }

    /* Dialog (confirmation) */
    .dialog {
        width: min(30rem, calc(100% - 2rem));
        padding: 0;
        color: var(--color-text);
        background: var(--color-surface);
        border: 1px solid var(--color-border);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-lg);
    }
    .dialog::backdrop { background: rgb(16 24 40 / 0.45); }
    .dialog[open] { animation: dialog-in var(--duration) var(--ease); }
    @keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
    .dialog-body { display: flex; gap: var(--space-4); padding: var(--space-6); }
    .dialog-icon { display: grid; place-items: center; flex: none; width: 2.5rem; height: 2.5rem; color: var(--color-danger); background: var(--color-danger-subtle); border-radius: var(--radius-full); }
    .dialog-icon-neutral { color: var(--color-accent); background: var(--color-accent-subtle); }
    .dialog h2 { margin: 0 0 var(--space-2); font-size: var(--text-lg); }
    .dialog p { color: var(--color-text-muted); font-size: var(--text-sm); }
    .dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--space-3); padding: var(--space-4) var(--space-6); background: var(--color-surface-subtle); border-top: 1px solid var(--color-border); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

    /* Status pages (404, access denied, suspended …) */
    .status-page { display: flex; flex-direction: column; align-items: center; gap: var(--space-3); max-width: 36rem; margin: var(--space-10) auto; text-align: center; }
    .status-page .status-icon { display: grid; place-items: center; width: 3.5rem; height: 3.5rem; color: var(--color-accent); background: var(--color-accent-subtle); border-radius: var(--radius-full); }
    .status-page.is-danger .status-icon { color: var(--color-danger); background: var(--color-danger-subtle); }
    .status-page.is-warning .status-icon { color: var(--color-warning); background: var(--color-warning-subtle); }
    .status-page h1 { margin: var(--space-2) 0 0; }
    .status-page p { color: var(--color-text-muted); }
    .status-page .actions { justify-content: center; margin-top: var(--space-3); }
    .status-page .alert { text-align: left; width: 100%; }

    /* Steps (two-factor setup), QR code, recovery codes, copyable values */
    .steps { margin: 0; padding: 0; list-style: none; counter-reset: step; }
    .steps > li { position: relative; padding: 0 0 var(--space-6) var(--space-10); counter-increment: step; }
    .steps > li::before { content: counter(step); position: absolute; left: 0; top: 0; display: grid; place-items: center; width: 1.75rem; height: 1.75rem; font-size: var(--text-sm); font-weight: 650; color: var(--color-accent-subtle-text); background: var(--color-accent-subtle); border-radius: var(--radius-full); }
    .steps > li > :first-child { font-weight: 600; }
    .qr { display: inline-block; margin: var(--space-3) 0; padding: var(--space-3); background: #ffffff; border: 1px solid var(--color-border); border-radius: var(--radius); }
    .qr svg, .qr img { width: 180px; height: 180px; }
    .codes { display: grid; grid-template-columns: repeat(2, minmax(0, max-content)); gap: var(--space-2) var(--space-8); margin: var(--space-3) 0; padding: var(--space-4) var(--space-5); list-style: none; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); }
    .codes code { font-size: var(--text-base); letter-spacing: 0.04em; }
    .copyable { display: inline-flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
    .copyable code { padding: var(--space-1) var(--space-2); background: var(--color-surface-subtle); border: 1px solid var(--color-border); border-radius: var(--radius-sm); word-break: break-all; }
    .copy-button { display: none; }
    .js .copy-button { display: inline-flex; }

    /* Platform tenant details */
    .action-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: var(--space-4); align-items: start; }
    .action-grid > form { padding: var(--space-5); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); }
    .action-grid > form h3 { margin-top: 0; }
    .payload { overflow: auto; max-height: 32rem; padding: var(--space-4); font-size: var(--text-sm); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); }
    .logo-preview { max-height: 64px; max-width: 240px; padding: var(--space-2); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); }

    /* Consent banner and external content */
    .consent-banner {
        position: fixed;
        left: var(--space-4);
        right: var(--space-4);
        bottom: var(--space-4);
        z-index: 50;
        max-width: 48rem;
        margin: 0 auto;
        background: var(--color-surface);
        border: 1px solid var(--color-border);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-lg);
    }
    .consent-banner .container { padding: var(--space-5); max-width: none; }
    .consent-banner h2 { margin: 0 0 var(--space-1); font-size: var(--text-lg); }
    .consent-banner p { font-size: var(--text-sm); color: var(--color-text-muted); }
    .consent-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); margin-top: var(--space-4); }
    .external-content iframe { width: 100%; aspect-ratio: 16 / 9; border: 0; border-radius: var(--radius-lg); }
    .external-content-placeholder { padding: var(--space-5); background: var(--color-surface); border: 1px dashed var(--color-border-strong); border-radius: var(--radius-lg); }
    .privacy-service { margin-bottom: var(--space-4); }

    /* Central start page */
    .hero { margin: var(--space-6) 0 var(--space-8); text-align: center; }
    .hero h1 { font-size: 2.25rem; line-height: 2.75rem; letter-spacing: -0.02em; }
    .hero p { margin: var(--space-3) auto 0; max-width: 40rem; font-size: var(--text-lg); color: var(--color-text-muted); }
    .choice { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: var(--space-4); }
    .choice .card { display: flex; flex-direction: column; gap: var(--space-3); }
    .choice .card p { flex: 1; color: var(--color-text-muted); font-size: var(--text-sm); }
    .choice .card .icon { color: var(--color-accent); }

    /* Top bar above the content: notifications (ADR 0030). */
    .topbar {
        display: flex;
        justify-content: flex-end;
        align-items: center;
        gap: var(--space-2);
        width: 100%;
        max-width: var(--width-content);
        margin: 0 auto;
        padding: var(--space-3) var(--space-4) 0;
    }
    @media (min-width: 640px) { .topbar { padding: var(--space-4) var(--space-8) 0; } }
    .topbar + .banners, .topbar ~ .content { margin-top: 0; }
    .bell { position: relative; }
    .bell > summary {
        display: inline-flex;
        align-items: center;
        gap: var(--space-2);
        min-height: 2.5rem;
        padding: 0 var(--space-3);
        list-style: none;
        color: var(--color-text);
        background: var(--color-surface);
        border: 1px solid var(--color-border-strong);
        border-radius: var(--radius);
        cursor: pointer;
    }
    .bell > summary::-webkit-details-marker { display: none; }
    .bell > summary:hover { background: var(--color-surface-subtle); }
    .bell .popover { left: auto; right: 0; width: min(24rem, calc(100vw - 2rem)); padding: var(--space-2); }
    .count-badge, .nav-badge {
        min-width: 1.25rem;
        padding: 0 0.375rem;
        font-size: var(--text-xs);
        font-weight: 700;
        line-height: 1.25rem;
        text-align: center;
        color: var(--color-on-accent);
        background: var(--color-accent);
        border-radius: var(--radius-full);
    }
    .nav-badge { margin-left: auto; }
    .notification-list { margin: 0; padding: 0; list-style: none; }
    .notification-list a {
        display: flex;
        flex-direction: column;
        gap: 2px;
        padding: var(--space-2);
        color: var(--color-text);
        text-decoration: none;
        border-radius: var(--radius-sm);
    }
    .notification-list a:hover { background: var(--color-surface-subtle); }
    .notification-list .is-unread a { font-weight: 600; }
    .notification-list .is-unread a::before { content: ""; width: 0.5rem; height: 0.5rem; border-radius: 50%; background: var(--color-accent); }
    .notification-list time { font-size: var(--text-xs); font-weight: 400; color: var(--color-text-muted); }
    .bell-foot { display: flex; justify-content: space-between; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-2) 0; margin-top: var(--space-1); border-top: 1px solid var(--color-border); font-size: var(--text-sm); }
    .bell-foot button { padding: 0; color: var(--color-accent); background: none; border: 0; cursor: pointer; text-decoration: underline; text-underline-offset: 0.2em; }

    /* Support conversation */
    .thread { display: flex; flex-direction: column; gap: var(--space-4); margin: 0 0 var(--space-6); padding: 0; list-style: none; }
    .message { padding: var(--space-4) var(--space-5); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); }
    .message-operator { background: var(--color-accent-subtle); border-color: var(--accent-200); }
    .message-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--space-2); margin-bottom: var(--space-2); font-size: var(--text-sm); color: var(--color-text-muted); }
    .message-head strong { color: var(--color-text); }
    .message-body { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }

    /* Quick search in the top bar (ADR 0031) */
    .quick-search { position: relative; display: flex; align-items: center; flex: 1; max-width: 28rem; margin-right: auto; }
    .quick-search > .icon { position: absolute; left: var(--space-3); color: var(--color-text-muted); pointer-events: none; }
    .quick-search input { width: 100%; padding-left: 2.25rem; padding-right: 3.75rem; }
    .quick-search kbd {
        position: absolute;
        right: var(--space-2);
        padding: 0 var(--space-1);
        font-size: var(--text-xs);
        color: var(--color-text-muted);
        border: 1px solid var(--color-border-strong);
        border-radius: var(--radius-sm);
        pointer-events: none;
    }
    .quick-search input:focus + kbd, .quick-search input:not(:placeholder-shown) + kbd { display: none; }
    @media (max-width: 639.98px) { .quick-search kbd { display: none; } }
    .quick-search-list { top: 100%; max-height: min(24rem, 70vh); overflow-y: auto; }
    .quick-search-list [role="option"] { display: flex; flex-direction: column; padding: var(--space-2); border-radius: var(--radius-sm); cursor: pointer; }
    .quick-search-list [role="option"] span { font-size: var(--text-xs); color: var(--color-text-muted); }
    .quick-search-list [role="option"]:hover, .quick-search-list [aria-selected="true"] { background: var(--color-surface-subtle); }
    .quick-search-list [aria-selected="true"] { outline: 2px solid var(--color-focus); outline-offset: -2px; }
    .search-list { margin: 0; padding: 0; list-style: none; }
    .search-list li { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-2); padding: var(--space-2) 0; border-top: 1px solid var(--color-border); }
    .search-list li:first-child { border-top: 0; }

    /* Help: questions that open */
    .faq { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--color-border); }
    .faq details { border-bottom: 1px solid var(--color-border); }
    .faq summary { padding: var(--space-3) 0; font-weight: 600; cursor: pointer; }
    .faq details > div { padding: 0 0 var(--space-4); color: var(--color-text-muted); }
    .faq details > div p + p { margin-top: var(--space-2); }

    [data-theme="dark"] .brand-logo, [data-theme="dark"] .avatar img, [data-theme="dark"] .logo-preview {
        background: #ffffff;
        border-radius: var(--radius-sm);
    }

    /* Appearance switch in the footer, like the languages. */
    .footer .themes { display: flex; gap: var(--space-2); align-items: center; }

    .external-providers form + form { margin-top: var(--space-2); }
    .external-providers .button { width: 100%; }
    .divider { display: flex; align-items: center; gap: var(--space-3); margin: var(--space-5) 0; font-size: var(--text-sm); color: var(--color-text-muted); }
    .divider:has(+ form [data-passkey-start][hidden]):not(:has(~ .external-providers)) { display: none; }
    .divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--color-border); }
    .auth-links { display: flex; flex-direction: column; gap: var(--space-1); margin-top: var(--space-6); padding: 0; list-style: none; font-size: var(--text-sm); }

    /* Output of a language model (ADR 0039, <ai-output>): always under its label, always as text. */
    .ai-output { margin: var(--space-4) 0; padding: var(--space-4); border: 1px solid var(--color-border-strong); border-inline-start-width: 4px; border-radius: var(--radius-sm); background: var(--color-surface); }
    .ai-label { margin: 0 0 var(--space-3); font-size: var(--text-sm); font-weight: 600; letter-spacing: 0.02em; }
    .ai-output-text { white-space: pre-wrap; overflow-wrap: anywhere; }
    .ai-review { margin: var(--space-3) 0 0; font-size: var(--text-sm); color: var(--color-text-muted); }
}

/* --------------------------------------------------------------- utilities */
@layer utilities {
    .muted { color: var(--color-text-muted); }
    .small { font-size: var(--text-sm); }
    .nowrap { white-space: nowrap; }
    .mono { font-family: var(--font-mono); }
    .mt-0 { margin-top: 0 !important; }
    .mt-2 { margin-top: var(--space-2) !important; }
    .mt-4 { margin-top: var(--space-4) !important; }
    .mt-8 { margin-top: var(--space-8) !important; }
    .sr-only {
        position: absolute !important;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
        border: 0;
    }

    @media print {
        .sidebar, .appbar, .footer, .skip-link, .no-print, .actions, .banner { display: none !important; }
        .app { display: block; }
        body { background: #ffffff; }
        /* On paper the label of machine-generated content stays with its text (ADR 0039). */
        .ai-output { border-color: currentColor; break-inside: avoid; }
        .ai-output .ai-label { display: block !important; visibility: visible !important; }
    }
}
