/* Cascade — app.css
   Single stylesheet for the greenfield build. Uses @layer for deterministic
   specificity across the cascade. Visual language locked to navy/gold per
   docs/DEMO_ARCHITECTURE.md + demo precedent.

   Load order:
     tokens     — design tokens (CSS custom properties)
     reset      — minimal modern reset
     base       — typography, form/element defaults
     layout     — site shell (header, nav, main, footer, skip-link)
     components — cards, buttons, badges, tables, forms, tiles
     utilities  — atomic helpers (always win against components) */

@layer tokens, reset, base, layout, components, utilities;

/* -------------------------------------------------------------------------
   @layer tokens — design tokens
   ------------------------------------------------------------------------- */
@layer tokens {
    :root {
        /* Brand palette — locked */
        --color-navy:            #1A2744;
        --color-navy-600:        #232F52;   /* hover on navy surfaces */
        --color-navy-800:        #141E36;   /* footer, deeper accents */
        --color-gold:            #C9A84C;
        --color-gold-600:        #B89838;   /* hover on gold surfaces */

        /* Neutrals */
        --color-bg:              #F5F5F7;
        --color-surface:         #FFFFFF;
        --color-border:          #E5E7EB;
        --color-border-strong:   #D1D5DB;
        --color-text:            #1A2744;
        --color-text-muted:      #6B7280;
        --color-text-subtle:     #9CA3AF;

        /* Semantic */
        --color-success:         #065F46;
        --color-success-bg:      #D1FAE5;
        --color-warning:         #78350F;
        --color-warning-bg:      #FEF3C7;
        --color-danger:          #991B1B;
        --color-danger-bg:       #FEE2E2;
        --color-info:            #1E40AF;
        --color-info-bg:         #DBEAFE;

        /* Role-based aliases (prefer these in components). Dark-mode block below
           overrides these; components should reference these, not the brand tokens. */
        --bg-page:               var(--color-bg);
        --bg-surface:            var(--color-surface);
        --bg-surface-2:          #F9FAFB;                /* sunken surface (search bar, dashed placeholders, ss-mini) */
        --bg-header:             var(--color-navy);      /* legacy — used only by old top-header. Dying. */
        --fg-on-navy:            #FFFFFF;
        --fg-accent:             var(--color-gold);
        --border-card:           var(--color-border);

        /* Semantic accent — drives hover/active states, badges, links.
           Defaults to brand gold; a future per-user preference can override via
           inline style on <html>. Components reference --accent, not --color-gold,
           so the swap is transparent. */
        --accent:                var(--color-gold);
        --accent-fg:              #1A2744;
        --accent-soft:           color-mix(in srgb, var(--accent) 15%, transparent);

        /* Density tokens — mutated by [data-density="..."] block */
        --row-h:                 40px;
        --pad:                   16px;
        --gap:                   12px;

        /* User-preference radius — mutated by [data-radius="..."] block */
        --radius:                var(--radius-md);

        /* Sidebar width — mutated by [data-sidebar="..."] block */
        --sidebar-w:             240px;

        /* Type */
        --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
        --font-mono: "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;

        /* Fluid type scale — clamp(min, preferred-vw, max).
           Each step grows ~1rem between 320px and 1400px viewport. */
        --fs-xs:    0.75rem;                              /* 12px */
        --fs-sm:    0.8125rem;                            /* 13px */
        --fs-base:  0.9375rem;                            /* 15px — matches demo */
        --fs-md:    1rem;                                 /* 16px */
        --fs-lg:    clamp(1.0625rem, 0.95rem + 0.4vw, 1.25rem);
        --fs-xl:    clamp(1.25rem, 1.05rem + 0.7vw, 1.5rem);
        --fs-2xl:   clamp(1.5rem, 1.2rem + 1.1vw, 2rem);
        --fs-3xl:   clamp(1.875rem, 1.4rem + 1.8vw, 2.75rem);

        --fw-regular:  400;
        --fw-medium:   500;
        --fw-semibold: 600;
        --fw-bold:     700;

        --lh-tight:   1.15;
        --lh-base:    1.5;
        --lh-relaxed: 1.65;

        /* Spacing — 4px base */
        --space-1:  0.25rem;    /* 4  */
        --space-2:  0.5rem;     /* 8  */
        --space-3:  0.75rem;    /* 12 */
        --space-4:  1rem;       /* 16 */
        --space-5:  1.25rem;    /* 20 */
        --space-6:  1.5rem;     /* 24 */
        --space-8:  2rem;       /* 32 */
        --space-10: 2.5rem;     /* 40 */
        --space-12: 3rem;       /* 48 */
        --space-16: 4rem;       /* 64 */

        /* Radii */
        --radius-sm:   3px;
        --radius-md:   4px;
        --radius-lg:   8px;
        --radius-xl:   12px;
        --radius-full: 9999px;

        /* Shadows — 3 levels, consistent with demo */
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
        --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.08);
        --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);

        /* Z-index scale */
        --z-back-to-top: 90;
        --z-header:      100;
        --z-dropdown:    200;
        --z-toast:       800;
        --z-modal:       1000;

        /* Motion */
        --ease-out:    cubic-bezier(0.2, 0.8, 0.2, 1);
        --duration-1:  120ms;
        --duration-2:  200ms;
        --duration-3:  320ms;

        /* Layout */
        --container-max: 1200px;
        --container-pad: var(--space-8);

        /* Surface aliases — referenced across pages as --surface-1/2/3.
           Map to the canonical bg-/border tokens so callers don't have to
           remember which name the token system uses. */
        --surface-1: var(--bg-surface);
        --surface-2: var(--bg-surface-2);
        --surface-3: var(--color-border-strong);
    }

    /* -- Dark mode --
       Applied by [data-dark="true"] on <html>. Keeps navy/gold readable by
       using navy as an accented dark surface rather than flattening to black. */
    :root[data-dark="true"] {
        --color-bg:              #0F1628;    /* deep navy-black */
        --color-surface:         #1A2744;    /* brand navy becomes the card surface */
        --color-border:          #2A3A63;
        --color-border-strong:   #3A4C7A;
        --color-text:            #F5F5F7;
        --color-text-muted:      #9CA3AF;
        --color-text-subtle:     #6B7280;

        --bg-page:               var(--color-bg);
        --bg-surface:            var(--color-surface);
        --bg-surface-2:          #14203A;
        --border-card:           var(--color-border);

        --accent-fg:             #1A2744;
        --accent-soft:           color-mix(in srgb, var(--accent) 22%, #000);

        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
        --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.35);
        --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
    }

    /* -- Density variants (personal preference) -- */
    :root[data-density="comfortable"] { --row-h: 48px; --pad: 20px; --gap: 16px; }
    :root[data-density="dense"]       { --row-h: 32px; --pad: 12px; --gap: 8px;  }

    /* -- Radius variant (personal preference) --
       Also bumps radius-lg + radius-sm in proportion so whole surface feels cohesive. */
    :root[data-radius="sharp"]  { --radius: 2px;  --radius-sm: 2px;  --radius-lg: 4px;  }
    :root[data-radius="soft"]   { --radius: 10px; --radius-sm: 6px;  --radius-lg: 14px; }

    /* -- Sidebar variant -- */
    :root[data-sidebar="narrow"] { --sidebar-w: 64px; }
    :root[data-sidebar="wide"]   { --sidebar-w: 240px; }
}

/* -------------------------------------------------------------------------
   @layer reset — minimal modern reset
   (Inspired by Andy Bell / Josh Comeau)
   ------------------------------------------------------------------------- */
@layer reset {
    *, *::before, *::after { box-sizing: border-box; }

    * { margin: 0; }

    html {
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
        tab-size: 4;
    }

    body {
        min-block-size: 100vh;
        line-height: var(--lh-base);
        -webkit-font-smoothing: antialiased;
        text-rendering: optimizeLegibility;
    }

    img, picture, video, canvas, svg {
        display: block;
        max-inline-size: 100%;
    }

    input, button, textarea, select {
        font: inherit;
        color: inherit;
    }

    button { cursor: pointer; }

    p, h1, h2, h3, h4, h5, h6 { overflow-wrap: break-word; }

    /* Break unbreakable strings (long URLs, raw JSON, email-list CCs) at
       any character rather than overflowing the cell. Catches the most
       common cause of horizontal page scroll on tables and dl-grids. */
    td, dd { overflow-wrap: anywhere; }

    /* Make the HTML `hidden` attribute actually hide elements. The UA
       stylesheet sets [hidden]{display:none} without !important, so any
       author rule that touches `display` on the same element wins by
       cascade order and the element stays visible. Adding !important
       here closes that loophole site-wide so element.hidden = true
       always hides. (Caught 2026-05-18 on .nav-item__submenu which had
       display:flex from the author rule.) */
    [hidden] { display: none !important; }

    ul[role="list"], ol[role="list"] { list-style: none; padding: 0; }

    @media (prefers-reduced-motion: reduce) {
        *, *::before, *::after {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
            scroll-behavior: auto !important;
        }
    }
}

/* -------------------------------------------------------------------------
   @layer base — document defaults
   ------------------------------------------------------------------------- */
@layer base {
    body {
        font-family: var(--font-sans);
        font-size: var(--fs-base);
        color: var(--color-text);
        background: var(--bg-page);
    }

    h1, h2, h3, h4, h5, h6 {
        line-height: var(--lh-tight);
        font-weight: var(--fw-semibold);
        color: var(--color-navy);
    }

    h1 { font-size: var(--fs-2xl); }
    h2 { font-size: var(--fs-xl); }
    h3 { font-size: var(--fs-lg); }
    h4 { font-size: var(--fs-md); }

    a {
        color: var(--color-navy);
        text-decoration-color: var(--color-gold);
        text-underline-offset: 2px;
    }
    a:hover { color: var(--color-navy-600); }

    :focus-visible {
        outline: 2px solid var(--color-gold);
        outline-offset: 2px;
        border-radius: var(--radius-sm);
    }

    ::selection {
        background: var(--color-gold);
        color: var(--color-navy);
    }

    hr {
        border: 0;
        border-block-start: 1px solid var(--color-border);
        margin-block: var(--space-6);
    }

    code, pre, kbd, samp {
        font-family: var(--font-mono);
        font-size: 0.875em;
    }
}

/* -------------------------------------------------------------------------
   @layer layout — site shell
   ------------------------------------------------------------------------- */
@layer layout {
    /* Skip link — keyboard users first stop */
    .skip-link {
        position: absolute;
        inset-block-start: -40px;
        inset-inline-start: var(--space-4);
        background: var(--color-navy);
        color: var(--fg-on-navy);
        padding: var(--space-2) var(--space-4);
        border-radius: var(--radius-md);
        z-index: calc(var(--z-header) + 1);
        transition: inset-block-start var(--duration-2) var(--ease-out);
    }
    .skip-link:focus { inset-block-start: var(--space-2); }

    /* ------- App shell: sidebar + topbar ------- */
    .app-shell {
        display: grid;
        grid-template-columns: var(--sidebar-w) 1fr;
        min-block-size: 100vh;
        /* Prevent any wide grid child (stats row, table, sticky pill) from
           pushing the whole page past the viewport on a phone. Without
           min-width:0 the 1fr column resolves to max-content, not the
           remaining track width — see assets/css mobile audit 2026-05-19.
           NOTE: do NOT put overflow:hidden here. The sidebar is a direct
           child and uses position:sticky; any overflow on an ancestor
           creates a new scroll container that breaks sticky. The clip
           lives on .page-area instead (regression caught 2026-05-20). */
        min-inline-size: 0;
        max-inline-size: 100vw;
    }
    /* The 1fr column owns its own width discipline: shrink-to-fit + clip
       any too-wide child so the page can't grow past the viewport. Doing
       this here instead of on .app-shell keeps the sidebar's sticky
       positioning working (sticky needs no overflow on ancestors). */
    .app-shell > .page-area {
        min-inline-size: 0;
        max-inline-size: 100%;
        overflow-x: hidden;
    }
    @media (max-width: 800px) {
        .app-shell { grid-template-columns: 1fr; }
    }

    /* ------- Sidebar ------- */
    .sidebar {
        background: var(--bg-surface);
        border-inline-end: 1px solid var(--color-border);
        display: flex;
        flex-direction: column;
        padding: var(--space-4) var(--space-3);
        position: sticky;
        inset-block-start: 0;
        block-size: 100vh;
        overflow-y: auto;
    }
    /* ------- Blake modals (<dialog> elements in blake-email.php) ------- */
    /*
     * <dialog> doesn't center by default and rendered pinned to top-left.
     * Use the modern margin:auto + max-block-size pattern so dialogs sit
     * centered on the viewport. Inputs need clearly-visible borders so
     * each field reads as a field rather than a label-with-string.
     */
    .blake-modal {
        margin: auto;
        padding: 0;
        border: 1px solid var(--color-border);
        border-radius: var(--radius);
        background: #fff;
        color: var(--color-text);
        max-inline-size: 92vw;
        max-block-size: 88vh;
        inline-size: 100%;
        box-shadow: 0 20px 60px rgba(15, 23, 42, 0.25);
        overflow: auto;
    }
    .blake-modal::backdrop {
        background: rgba(15, 23, 42, 0.5);
    }
    .blake-modal > form {
        padding: var(--space-5);
        display: flex;
        flex-direction: column;
        gap: var(--space-3);
    }
    .blake-modal h3 {
        margin: 0 0 var(--space-2);
        font-size: var(--fs-lg);
        color: var(--color-navy, #1A2744);
    }
    .blake-modal label {
        display: block;
        font-weight: var(--fw-medium);
        color: var(--color-text);
        font-size: var(--fs-sm);
    }
    .blake-modal input[type="text"],
    .blake-modal input[type="date"],
    .blake-modal input[type="email"],
    .blake-modal input[type="number"],
    .blake-modal select,
    .blake-modal textarea {
        display: block;
        inline-size: 100%;
        margin-block-start: var(--space-1);
        padding: 9px 12px;
        border: 2px solid #94a3b8;
        border-radius: var(--radius-sm, 4px);
        background: #fcfcfd;
        color: #0f172a;
        font: inherit;
        font-size: var(--fs-sm);
        font-weight: var(--fw-medium);
        outline: 0;
        transition: border-color var(--duration-1) var(--ease-out),
                    box-shadow   var(--duration-1) var(--ease-out),
                    background   var(--duration-1) var(--ease-out);
    }
    .blake-modal input:hover,
    .blake-modal select:hover,
    .blake-modal textarea:hover {
        border-color: #64748b;
    }
    .blake-modal input:focus,
    .blake-modal select:focus,
    .blake-modal textarea:focus {
        border-color: var(--color-gold, #C9A84C);
        background: #fff;
        box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.22);
    }
    .blake-modal input::placeholder,
    .blake-modal textarea::placeholder {
        color: #cbd5e1;
        font-style: italic;
        font-weight: var(--fw-regular);
    }
    .blake-modal textarea {
        min-block-size: 80px;
        resize: vertical;
    }
    .blake-modal__actions {
        display: flex;
        gap: var(--space-2);
        justify-content: flex-end;
        margin-block-start: var(--space-3);
        padding-block-start: var(--space-3);
        border-block-start: 1px solid var(--color-border);
    }

    /* ------- Document upload modal (deal-detail) ------- */
    .doc-dropzone {
        border: 2px dashed var(--surface-3);
        border-radius: var(--radius-md);
        padding: var(--space-6);
        text-align: center;
        cursor: pointer;
        color: var(--color-text-subtle);
        background: var(--surface-2);
        transition: border-color var(--duration-1) var(--ease-out),
                    background    var(--duration-1) var(--ease-out);
    }
    .doc-dropzone:hover,
    .doc-dropzone:focus-visible {
        border-color: var(--color-gold);
        outline: none;
    }
    .doc-dropzone.is-drag {
        border-color: var(--color-gold);
        background: rgba(201, 168, 76, 0.10);
        color: var(--color-text);
    }
    .doc-dropzone__inner {
        display: flex;
        flex-direction: column;
        gap: var(--space-2);
        align-items: center;
        font-size: var(--fs-sm);
    }
    .doc-file-list {
        list-style: none;
        padding: 0;
        margin: var(--space-3) 0 0;
        display: flex;
        flex-direction: column;
        gap: var(--space-2);
    }
    .doc-file-list__item {
        display: flex;
        align-items: center;
        gap: var(--space-2);
        padding: var(--space-2) var(--space-3);
        background: var(--surface-2);
        border: 1px solid var(--surface-3);
        border-radius: var(--radius-sm);
        font-size: var(--fs-xs);
    }
    .doc-file-list__item.is-bad {
        border-color: var(--color-danger);
        color: var(--color-danger);
    }
    .doc-file-list__name {
        flex: 1 1 auto;
        min-inline-size: 0;
        word-break: break-word;
        font-weight: var(--fw-medium);
    }
    .doc-file-list__meta {
        color: var(--color-text-subtle);
        white-space: nowrap;
    }
    .doc-file-list__remove {
        background: none;
        border: none;
        cursor: pointer;
        color: var(--color-text-subtle);
        font-size: var(--fs-sm);
        line-height: 1;
        padding: 0 var(--space-1);
    }
    .doc-file-list__remove:hover {
        color: var(--color-danger);
    }

    /* ------- Compound search bar (icon + input pill) ------- */
    /*
     * Used by blake-inbox.php and company-intel.php. Rounded pill matches
     * the inbox filter chip family, navy border in resting state, gold
     * focus ring. Inputs inside have no border of their own; the wrapper
     * is the field.
     */
    .ci-search-bar {
        display: flex;
        align-items: center;
        gap: var(--space-2);
        padding: 6px 14px;
        background: #fff;
        border: 1.5px solid var(--color-navy, #1A2744);
        border-radius: 999px;
        color: var(--color-text-muted);
        font-size: var(--fs-sm);
        /* Fill the row, never overflow the viewport on a phone. */
        inline-size: 100%;
        max-inline-size: 100%;
        box-sizing: border-box;
        flex-wrap: wrap;
        transition: border-color var(--duration-1) var(--ease-out),
                    box-shadow   var(--duration-1) var(--ease-out);
    }
    .ci-search-bar:focus-within {
        border-color: var(--color-gold, #C9A84C);
        box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.2);
    }
    .ci-search-bar input {
        flex: 1;
        border: 0;
        outline: 0;
        background: transparent;
        font-size: var(--fs-sm);
        color: var(--color-text);
        min-inline-size: 0;
    }
    .ci-search-bar input::placeholder {
        color: #9ca3af;
        font-style: italic;
    }

    /* ------- Blake inbox filter chips ------- */
    /*
     * Default: empty / bordered chip. Active: filled navy + gold count.
     * Pattern matches the locked navy/gold theme. Previously the chips
     * used inline styles that left selected state as white-on-gray and
     * disappeared in the cascade.
     */
    .inbox-chip {
        display: inline-flex;
        align-items: center;
        gap: var(--space-2);
        padding: 5px 10px;
        border: 1.5px solid var(--color-navy, #1A2744);
        border-radius: 999px;
        background: #fff;
        color: var(--color-navy, #1A2744);
        font-size: var(--fs-sm);
        font-weight: var(--fw-medium);
        text-decoration: none;
        transition: background var(--duration-1) var(--ease-out),
                    color var(--duration-1) var(--ease-out);
    }
    .inbox-chip:hover {
        background: rgba(26, 39, 68, 0.06);
    }
    .inbox-chip__label { line-height: 1; }
    .inbox-chip__count {
        font-family: var(--font-mono);
        font-size: var(--fs-xs);
        padding: 1px 6px;
        border-radius: 999px;
        background: rgba(26, 39, 68, 0.08);
        color: var(--color-navy, #1A2744);
        line-height: 1.2;
    }
    .inbox-chip--active {
        background: var(--color-navy, #1A2744);
        color: #fff;
    }
    .inbox-chip--active:hover {
        background: #232f52;
    }
    .inbox-chip--active .inbox-chip__count {
        background: var(--color-gold, #C9A84C);
        color: var(--color-navy, #1A2744);
    }

    /* ------- Sidebar as off-canvas drawer at ≤800px ------- */
    /*
     * The sidebar stays a flex column at all sizes — only its positioning
     * model swaps. At ≤800px it becomes a fixed-position drawer that
     * slides in from the inline-start edge, sits over the page content,
     * and pairs with .nav-backdrop. data-nav-open on <html> is the
     * single toggle; CSS does the rest, JS just flips the attribute.
     */
    .nav-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.45);
        z-index: var(--z-header);
        opacity: 0;
        transition: opacity var(--duration-2) var(--ease-out);
    }
    /* `.topbar .nav-toggle` (not just `.nav-toggle`) so we win over
     * the later-in-source `.icon-btn { display: grid }` rule on desktop. */
    .topbar .nav-toggle { display: none; }

    @media (max-width: 800px) {
        .topbar .nav-toggle { display: grid; }
        .sidebar {
            position: fixed;
            inset-block-start: 0;
            inset-inline-start: 0;
            block-size: 100vh;
            inline-size: min(280px, 86vw);
            z-index: calc(var(--z-header) + 1);
            transform: translateX(-100%);
            transition: transform var(--duration-2) var(--ease-out);
            box-shadow: var(--shadow-lg, 0 12px 32px rgba(15, 23, 42, 0.25));
        }
        :root[data-nav-open="true"] .sidebar { transform: translateX(0); }
        :root[data-nav-open="true"] .nav-backdrop {
            display: block;
            opacity: 1;
        }
        /* Body scroll lock while the drawer is open. Applied to <html>
         * (since the sidebar lives at viewport scope), not body, to dodge
         * iOS Safari's overflow:hidden-on-body quirks. */
        :root[data-nav-open="true"] { overflow: hidden; }
    }

    .brand {
        display: flex;
        align-items: center;
        gap: var(--space-3);
        padding: var(--space-2) var(--space-3) var(--space-4);
        font-weight: var(--fw-semibold);
        font-size: var(--fs-md);
        letter-spacing: -0.01em;
        color: var(--color-text);
    }
    .brand-mark {
        inline-size: 28px;
        block-size: 28px;
        border-radius: var(--radius);
        background: var(--color-navy);
        color: var(--color-gold);
        display: grid;
        place-items: center;
        font-family: var(--font-mono);
        font-weight: var(--fw-bold);
        font-size: var(--fs-sm);
        flex: 0 0 auto;
    }
    .brand-mark img { inline-size: 20px; block-size: 20px; }
    .brand-text .accent { color: var(--accent); }
    .brand-text .sub {
        font-size: var(--fs-xs);
        font-weight: var(--fw-regular);
        color: var(--color-text-subtle);
        line-height: 1.1;
    }
    :root[data-sidebar="narrow"] .brand-text { display: none; }

    /* Nav group label (Workspace / Insights / Admin) */
    .nav-label {
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: 0.08em;
        color: var(--color-text-subtle);
        padding: var(--space-3) var(--space-3) var(--space-1);
        font-weight: var(--fw-semibold);
    }
    :root[data-sidebar="narrow"] .nav-label { display: none; }

    /* Nav item */
    .nav-item {
        display: flex;
        align-items: center;
        gap: var(--space-3);
        padding: 7px var(--space-3);
        border-radius: var(--radius);
        color: var(--color-text-muted);
        text-decoration: none;
        font-weight: var(--fw-medium);
        font-size: var(--fs-sm);
        user-select: none;
        transition: background var(--duration-1) var(--ease-out),
                    color var(--duration-1) var(--ease-out);
    }
    .nav-item:hover {
        background: color-mix(in srgb, var(--color-text) 6%, transparent);
        color: var(--color-text);
    }
    /* Active — elevated surface treatment, not a color bar */
    .nav-item[aria-current="page"] {
        background: var(--bg-surface-2);
        color: var(--color-text);
        box-shadow: var(--shadow-sm);
    }
    :root[data-dark="true"] .nav-item[aria-current="page"] {
        background: var(--bg-surface-2);
        color: var(--color-text);
    }
    .nav-item .nav-icon {
        inline-size: 16px;
        block-size: 16px;
        flex: 0 0 auto;
        opacity: 0.9;
    }
    .nav-item .nav-label-text { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .nav-item .nav-badge {
        margin-inline-start: auto;
        font-family: var(--font-mono);
        font-size: var(--fs-xs);
        background: var(--accent-soft);
        color: var(--accent);
        padding: 1px 6px;
        border-radius: var(--radius-full);
        font-weight: var(--fw-medium);
    }
    :root[data-sidebar="narrow"] .nav-item {
        justify-content: center;
        padding: 9px 0;
    }
    :root[data-sidebar="narrow"] .nav-item .nav-label-text,
    :root[data-sidebar="narrow"] .nav-item .nav-badge { display: none; }

    /* Sidebar dropdown — used by Quick Add (and reusable for future
       nested nav items). The trigger looks identical to .nav-item; the
       popout opens to the right of the sidebar so it overlays page
       content rather than pushing other nav items down. */
    /* Override .nav-item's display:flex on the wrapper so the trigger
       button and the (initially hidden) submenu stack vertically rather
       than sitting in a flex row. Otherwise the submenu appears to the
       RIGHT of the trigger label instead of below it. */
    .nav-item--has-submenu {
        display: block;
        padding: 0;
    }
    .nav-item--has-submenu .nav-item__trigger {
        all: unset;
        display: flex;
        align-items: center;
        gap: var(--space-3);
        padding: 7px var(--space-3);
        border-radius: var(--radius);
        color: var(--color-text-muted);
        font-weight: var(--fw-medium);
        font-size: var(--fs-sm);
        cursor: pointer;
        inline-size: 100%;
        box-sizing: border-box;
        transition: background var(--duration-1) var(--ease-out),
                    color var(--duration-1) var(--ease-out);
    }
    .nav-item--has-submenu .nav-item__trigger:hover {
        background: color-mix(in srgb, var(--color-text) 6%, transparent);
        color: var(--color-text);
    }
    /* Submenu expands inline below the trigger at ALL widths. The popup-
       to-the-right variant we used originally on desktop got clipped by
       .sidebar's overflow:auto (overflow-y:auto forces overflow-x:auto
       per the spec). Inline expansion works the same on desktop +
       mobile, pushes the items below down while open, and stays inside
       the sidebar's scroll container. */
    .nav-item__submenu {
        display: flex;
        flex-direction: column;
        gap: 2px;
        margin-block-start: var(--space-1);
        margin-inline-start: var(--space-3);
        padding-inline-start: var(--space-2);
        border-inline-start: 2px solid var(--color-border);
    }
    .nav-item__submenu a,
    .nav-item__submenu button {
        all: unset;
        display: flex;
        align-items: center;
        gap: var(--space-2);
        padding: var(--space-2) var(--space-3);
        border-radius: var(--radius-sm);
        font-size: var(--fs-sm);
        color: var(--color-text);
        cursor: pointer;
        white-space: nowrap;
    }
    .nav-item__submenu a:hover,
    .nav-item__submenu button:hover {
        background: color-mix(in srgb, var(--color-text) 8%, transparent);
    }

    /* Card-level + add affordance — top-right of cards that have a primary
       "create another of these" action. Used on dashboard My Open Todos
       and deal-detail Notes / Excerpts. 32px keeps it comfortable on
       trackpad and laptop touch; pointer:coarse bumps it to 44px below
       for phones / tablets. */
    .card__add {
        all: unset;
        cursor: pointer;
        inline-size: 32px;
        block-size: 32px;
        border-radius: var(--radius-full);
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 20px;
        line-height: 1;
        font-weight: var(--fw-bold);
        color: var(--color-text-muted);
        background: transparent;
        border: 1px solid transparent;
        transition: background var(--duration-1) var(--ease-out),
                    color var(--duration-1) var(--ease-out),
                    border-color var(--duration-1) var(--ease-out);
    }
    .card__add:hover {
        background: var(--accent-soft, rgba(201,168,76,0.18));
        color: var(--accent, #C9A84C);
        border-color: var(--accent, #C9A84C);
    }

    /* Sidebar foot — user + role */
    .sidebar-foot {
        margin-block-start: auto;
        border-block-start: 1px solid var(--color-border);
        display: flex;
        align-items: center;
        gap: var(--space-3);
        padding: var(--space-3);
    }
    .avatar {
        inline-size: 28px;
        block-size: 28px;
        border-radius: 50%;
        background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 60%, white), var(--accent));
        color: white;
        display: grid;
        place-items: center;
        font-size: var(--fs-xs);
        font-weight: var(--fw-semibold);
        font-family: var(--font-mono);
        flex: 0 0 auto;
    }
    .who { display: flex; flex-direction: column; min-inline-size: 0; }
    .who .name {
        font-size: var(--fs-sm);
        font-weight: var(--fw-medium);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        color: var(--color-text);
    }
    .who .role {
        font-size: var(--fs-xs);
        color: var(--color-text-subtle);
    }
    :root[data-sidebar="narrow"] .who { display: none; }

    /* ------- Topbar (navy band, demo style) ------- */
    .topbar {
        display: flex;
        align-items: center;
        gap: var(--space-3);
        padding: var(--space-3) var(--space-6);
        border-block-end: 1px solid #0f1a30;
        background: var(--color-navy, #1A2744);
        color: #fff;
        position: sticky;
        inset-block-start: 0;
        z-index: var(--z-header);
        min-block-size: 56px;
    }
    .topbar .brand-logo {
        block-size: 28px;
        inline-size: auto;
        flex: 0 0 auto;
        margin-inline-end: var(--space-2);
    }
    .crumbs {
        display: flex;
        align-items: center;
        gap: var(--space-2);
        color: rgba(255, 255, 255, 0.78);
        font-size: var(--fs-sm);
    }
    .crumbs .sep { opacity: 0.5; }
    .crumbs .here { color: #fff; font-weight: var(--fw-medium); }
    .crumbs a { color: inherit; text-decoration: none; }
    .crumbs a:hover,
    .crumbs a:focus-visible { color: #fff; text-decoration: underline; }
    .search {
        margin-inline-start: auto;
        display: flex;
        align-items: center;
        gap: var(--space-2);
        background: rgba(255, 255, 255, 0.08);
        border: 1px solid rgba(255, 255, 255, 0.15);
        padding: 6px var(--space-3);
        border-radius: var(--radius);
        inline-size: 280px;
        color: rgba(255, 255, 255, 0.7);
        font-size: var(--fs-sm);
    }
    .search input {
        background: transparent;
        border: 0;
        outline: 0;
        flex: 1;
        font-size: var(--fs-sm);
        color: #fff;
    }
    .search input::placeholder { color: rgba(255, 255, 255, 0.5); }
    .search .k {
        font-family: var(--font-mono);
        font-size: var(--fs-xs);
        padding: 1px 5px;
        border: 1px solid rgba(255, 255, 255, 0.25);
        border-radius: 3px;
        color: rgba(255, 255, 255, 0.7);
    }
    /* Topbar icon-buttons (tweaks / bell / hamburger): white on navy */
    .topbar .icon-btn {
        color: rgba(255, 255, 255, 0.85);
    }
    .topbar .icon-btn:hover {
        background: rgba(255, 255, 255, 0.1);
        color: #fff;
    }
    .topbar .icon-btn[disabled] {
        opacity: 0.45;
    }
    .topbar .sep-v {
        inline-size: 1px;
        background: rgba(255, 255, 255, 0.2);
        align-self: stretch;
        margin-inline: var(--space-1);
    }

    /* Staging environment marker. The <body> carries env-staging (set in
       Layout::emitHead) and the topbar renders a STAGING flag (emitTopbar).
       Deep green (#166534) — same hue family as the staging favicon's bright
       #22C55E, but dark enough that the white crumbs/icons/avatar stay legible.
       The flag itself is red, all-caps, sat just left of the appearance icon. */
    body.env-staging .topbar {
        background: #166534;
        border-block-end-color: #0d3b1f;
    }
    .env-flag {
        font-size: var(--fs-sm, 0.8125rem);
        font-weight: var(--fw-bold, 700);
        letter-spacing: 0.1em;
        text-transform: uppercase;
        color: #ff5c5c;
        padding-inline: var(--space-1);
        white-space: nowrap;
        user-select: none;
    }
    @media (max-width: 700px) {
        .search { inline-size: auto; }
        .search input { inline-size: 120px; }
    }

    /* Topbar mobile collapse — at narrow widths the 8 children no longer
       fit in a single non-wrapping flex row. Drop ornamental items first
       (crumbs at <=720px, search + key hint at <=520px), tighten padding,
       and let .icon-btn shrink slightly. */
    @media (max-width: 720px) {
        .topbar { padding-inline: var(--space-3); gap: var(--space-2); }
        .topbar .crumbs { display: none; }
        .topbar .brand-logo { block-size: 24px; }
    }
    @media (max-width: 520px) {
        .topbar .search { display: none; }
        .topbar .icon-btn[title="Notifications"] { display: none; }
    }

    /* Page-level overflow guard — no single component should ever push the
       <html> wider than the viewport. Anything that tries (a wide table,
       an unwrapped flex row, a fixed-width inline style) gets clipped
       and/or scrolls inside its own container instead.
       NOTE: use `clip`, not `hidden`. `overflow:hidden` creates a scroll
       container which breaks position:sticky on the sidebar (sticky requires
       no overflow on any ancestor up to the scrolling root). `clip` provides
       the same visual clip without creating a scroll container. Caught when
       the sidebar started scrolling with the page after the .app-shell
       overflow change on 2026-05-19 — the html/body rule was also at fault. */
    html, body { max-inline-size: 100%; overflow-x: clip; }

    .icon-btn {
        inline-size: 32px;
        block-size: 32px;
        display: grid;
        place-items: center;
        border-radius: var(--radius);
        border: 1px solid transparent;
        background: transparent;
        cursor: pointer;
        color: var(--color-text-muted);
        padding: 0;
    }
    .icon-btn:hover { background: var(--bg-surface-2); color: var(--color-text); }
    /* Compact variant for inline/contextual help links (e.g. the dashboard
       help-circle jumps to the Help Center). Keep sizing here, not inline. */
    .icon-btn--sm { inline-size: 22px; block-size: 22px; }
    .sep-v {
        inline-size: 1px;
        block-size: 18px;
        background: var(--color-border);
        margin: 0 var(--space-1);
    }

    /* ------- Main content region (inside the right column) ------- */
    .page-area {
        display: flex;
        flex-direction: column;
        min-block-size: 100vh;
    }
    .site-main {
        max-inline-size: var(--container-max);
        margin-inline: auto;
        padding: var(--space-8) var(--space-6);
        inline-size: 100%;
        /* Let flex/grid children inside main shrink below their content's
           intrinsic width on narrow viewports — paired with the .app-shell
           min-inline-size:0 fix above. */
        min-inline-size: 0;
    }
    .site-main--narrow { max-inline-size: 720px; }

    /* Footer */
    .site-footer {
        color: var(--color-text-muted);
        font-size: var(--fs-xs);
        padding: var(--space-6) var(--space-6) var(--space-8);
        text-align: center;
        border-block-start: 1px solid var(--color-border);
        margin-block-start: auto;
    }

    /* Auth / pre-auth layout — no nav, centered */
    .auth-shell {
        min-block-size: 100vh;
        display: grid;
        place-items: center;
        padding: var(--space-8);
    }
    .auth-shell .brand {
        text-align: center;
        margin-block-end: var(--space-6);
    }
    .auth-shell .brand img { block-size: 44px; inline-size: auto; margin-inline: auto; }
}

/* -------------------------------------------------------------------------
   @layer components — reusable building blocks
   ------------------------------------------------------------------------- */
@layer components {
    /* -- Card -- */
    .card {
        background: var(--bg-surface);
        border: 1px solid var(--border-card);
        border-radius: var(--radius-lg);
        padding: var(--space-6);
        box-shadow: var(--shadow-sm);
    }
    .card__title {
        font-size: var(--fs-lg);
        font-weight: var(--fw-semibold);
        margin-block-end: var(--space-3);
    }
    .card__body > * + * { margin-block-start: var(--space-3); }

    /* -- Tile grid (dashboard) -- */
    .tile-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
        gap: var(--space-6);
    }
    .tile {
        display: block;
        background: var(--bg-surface);
        border: 1px solid var(--border-card);
        border-radius: var(--radius-lg);
        padding: var(--space-6);
        color: var(--color-text);
        text-decoration: none;
        box-shadow: var(--shadow-sm);
        transition: transform var(--duration-2) var(--ease-out),
                    box-shadow var(--duration-2) var(--ease-out),
                    border-color var(--duration-1) var(--ease-out);
    }
    .tile:hover {
        transform: translateY(-2px);
        box-shadow: var(--shadow-md);
        border-color: var(--color-gold);
    }
    .tile__eyebrow {
        color: var(--color-gold-600);
        font-size: var(--fs-xs);
        font-weight: var(--fw-bold);
        text-transform: uppercase;
        letter-spacing: 0.06em;
        margin-block-end: var(--space-2);
    }
    .tile__title {
        font-size: var(--fs-lg);
        font-weight: var(--fw-semibold);
        margin-block-end: var(--space-2);
    }
    .tile__desc {
        color: var(--color-text-muted);
        font-size: var(--fs-sm);
        line-height: var(--lh-base);
    }

    /* -- Button -- */
    .btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: var(--space-2);
        padding: var(--space-2) var(--space-5);
        border-radius: var(--radius-md);
        border: 1px solid transparent;
        font-size: var(--fs-sm);
        font-weight: var(--fw-semibold);
        line-height: 1;
        text-decoration: none;
        cursor: pointer;
        transition: background var(--duration-1) var(--ease-out),
                    color var(--duration-1) var(--ease-out),
                    border-color var(--duration-1) var(--ease-out);
    }
    .btn--primary {
        background: var(--color-navy);
        color: var(--fg-on-navy);
    }
    .btn--primary:hover { background: var(--color-navy-600); }
    .btn--accent {
        background: var(--color-gold);
        color: var(--color-navy);
    }
    .btn--accent:hover { background: var(--color-gold-600); color: var(--color-navy); }
    .btn--ghost {
        background: transparent;
        color: var(--color-navy);
        border-color: var(--color-border-strong);
    }
    .btn--ghost:hover { border-color: var(--color-gold); color: var(--color-navy); }
    /* Neutral subordinate action (Cancel, secondary). Subtle fill so it reads
       as a real button beside the navy --primary, distinct from the fully
       transparent --ghost. Uses --color-text (not --color-navy) so it stays
       readable in dark mode. */
    .btn--secondary {
        background: var(--bg-surface-2);
        color: var(--color-text);
        border-color: var(--color-border-strong);
    }
    .btn--secondary:hover { background: var(--color-surface); border-color: var(--color-gold); }
    /* Destructive action (Delete deal). Outlined at rest so it doesn't shout
       from the page; fills red on hover so intent is unmistakable. */
    .btn--danger {
        background: transparent;
        color: var(--color-danger);
        border-color: var(--color-danger);
    }
    .btn--danger:hover { background: var(--color-danger); color: #fff; border-color: var(--color-danger); }
    .btn--sm { padding: var(--space-1) var(--space-3); font-size: var(--fs-xs); }
    /* Table-row scale (admin-deleted Restore, S7 Compare-and-merge). Was
       referenced in markup before it existed here; buttons silently fell
       back to full size. */
    .btn--xs { padding: 2px var(--space-2); font-size: var(--fs-xs); }
    .btn[disabled] { opacity: 0.5; cursor: not-allowed; }

    /* -- Badge -- */
    .badge {
        display: inline-flex;
        align-items: center;
        padding: 0.125rem var(--space-2);
        border-radius: var(--radius-sm);
        font-size: var(--fs-xs);
        font-weight: var(--fw-bold);
        letter-spacing: 0.02em;
        text-transform: uppercase;
        white-space: nowrap;
    }
    .badge--success { background: var(--color-success-bg); color: var(--color-success); }
    .badge--warning { background: var(--color-warning-bg); color: var(--color-warning); }
    .badge--danger  { background: var(--color-danger-bg);  color: var(--color-danger); }
    .badge--info    { background: var(--color-info-bg);    color: var(--color-info); }
    .badge--neutral { background: var(--color-border);     color: var(--color-text); }
    /* Accent: gold on navy. Used for count chips next to card headings
       on the dashboard (My open todos, Pending to Dynamo). */
    .badge--accent  { background: var(--color-gold);       color: var(--color-navy); }

    /* -- Form fields -- */
    .field {
        display: flex;
        flex-direction: column;
        gap: var(--space-2);
    }
    .field__label {
        font-size: var(--fs-sm);
        font-weight: var(--fw-semibold);
        color: var(--color-text);
    }
    /* Required-field marker — red asterisk appended to a .field__label. */
    .field__req { color: var(--color-danger); font-weight: var(--fw-bold); margin-inline-start: 2px; }
    .field__hint {
        font-size: var(--fs-xs);
        color: var(--color-text-muted);
    }
    /* Inline-at-field validation error slot. Lives right after the
       input (or anywhere inside the label). Hidden until JS sets the
       text content + flips .is-visible. The companion .field--error
       class on the input turns its border red so the field itself
       reads as invalid even before the user looks at the message. */
    .field__error {
        display: none;
        margin-block-start: var(--space-1);
        font-size: var(--fs-xs);
        font-weight: var(--fw-medium);
        color: var(--color-danger);
        line-height: 1.35;
    }
    .field__error.is-visible { display: block; }
    .input.field--error,
    .select.field--error,
    .textarea.field--error,
    .blake-modal input.field--error,
    .blake-modal select.field--error,
    .blake-modal textarea.field--error {
        border-color: var(--color-danger) !important;
        background: var(--color-danger-bg);
    }
    .input.field--error:focus,
    .select.field--error:focus,
    .textarea.field--error:focus,
    .blake-modal input.field--error:focus,
    .blake-modal select.field--error:focus,
    .blake-modal textarea.field--error:focus {
        box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-danger) 25%, transparent);
        background: #fff;
    }
    /* Form-level error slot used for server-side failures that don't
       map cleanly to a single field. Lives just above the modal actions
       row. Same visibility toggle as .field__error. */
    .form__error {
        display: none;
        margin-block-end: var(--space-2);
        padding: var(--space-2) var(--space-3);
        font-size: var(--fs-xs);
        font-weight: var(--fw-medium);
        color: var(--color-danger);
        background: var(--color-danger-bg);
        border: 1px solid color-mix(in srgb, var(--color-danger) 35%, transparent);
        border-radius: var(--radius-sm);
        line-height: 1.4;
    }
    .form__error.is-visible { display: block; }
    /* Server-rendered, always-visible form-level error banner (PHP
       form_error_banner). Distinct from .form__error above, which is the
       JS-toggled client-side slot. Composes with .badge--danger for the red
       tokens and .u-mb-6 for spacing; this class supplies only the layout. */
    .form__error-banner {
        display: block;
        padding: var(--space-3) var(--space-4);
        font-size: var(--fs-sm);
        font-weight: var(--fw-medium);
        letter-spacing: 0;
        text-transform: none;
    }
    /* Form fields — same prominent border + gold focus state used inside
       .blake-modal so admin / settings / form pages share the polish. */
    .input, .select, .textarea {
        font-family: inherit;
        font-size: var(--fs-sm);
        font-weight: var(--fw-medium);
        padding: 9px 12px;
        border: 2px solid #94a3b8;
        border-radius: var(--radius-sm, 4px);
        background: #fcfcfd;
        color: #0f172a;
        inline-size: 100%;
        outline: 0;
        transition: border-color var(--duration-1) var(--ease-out),
                    box-shadow   var(--duration-1) var(--ease-out),
                    background   var(--duration-1) var(--ease-out);
    }
    .input:hover, .select:hover, .textarea:hover {
        border-color: #64748b;
    }
    .input:focus, .select:focus, .textarea:focus {
        border-color: var(--color-gold, #C9A84C);
        background: #fff;
        box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.22);
    }
    .input::placeholder, .textarea::placeholder {
        color: #cbd5e1;
        font-style: italic;
        font-weight: var(--fw-regular);
    }
    .textarea { min-block-size: 6rem; resize: vertical; }

    /* Dark-mode form fields: keep the navy theme readable without the
       light-gray surface treatment fighting the dark background. */
    :root[data-dark="true"] .input,
    :root[data-dark="true"] .select,
    :root[data-dark="true"] .textarea {
        background: var(--bg-surface-2);
        color: var(--color-text);
        border-color: var(--color-border-strong);
    }
    :root[data-dark="true"] .input:focus,
    :root[data-dark="true"] .select:focus,
    :root[data-dark="true"] .textarea:focus {
        background: var(--bg-surface);
    }

    /* -- Table -- */
    .table {
        inline-size: 100%;
        border-collapse: collapse;
        background: var(--bg-surface);
        border-radius: var(--radius-lg);
        overflow: hidden;
        box-shadow: var(--shadow-sm);
    }
    .table thead th {
        text-align: start;
        font-size: var(--fs-xs);
        text-transform: uppercase;
        letter-spacing: 0.06em;
        color: var(--color-text-muted);
        padding: var(--space-3) var(--space-4);
        background: var(--color-bg);
        border-block-end: 1px solid var(--color-border);
    }
    .table thead th.is-sortable {
        cursor: pointer;
        user-select: none;
        white-space: nowrap;
    }
    .table thead th.is-sortable:hover { color: var(--color-text); }
    .table thead th.is-sortable:focus-visible {
        outline: 2px solid var(--color-gold);
        outline-offset: -2px;
    }
    .table thead th[aria-sort] { color: var(--color-text); }
    .table thead th .sort-ind {
        font-size: 0.85em;
        color: var(--color-gold);
    }
    .table tbody td {
        padding: var(--space-3) var(--space-4);
        border-block-end: 1px solid var(--color-border);
        vertical-align: middle;
    }
    .table tbody tr:last-child td { border-block-end: 0; }
    .table tbody tr:hover { background: rgba(201, 168, 76, 0.06); }

    /* -- Back-to-top (JS adds .is-visible) -- */
    .back-to-top {
        position: fixed;
        inset-inline-end: var(--space-6);
        inset-block-end: var(--space-6);
        inline-size: 44px;
        block-size: 44px;
        border-radius: var(--radius-full);
        background: var(--color-navy);
        color: var(--color-gold);
        border: 2px solid var(--color-gold);
        font-size: var(--fs-md);
        font-weight: var(--fw-bold);
        display: flex; align-items: center; justify-content: center;
        box-shadow: var(--shadow-md);
        opacity: 0;
        pointer-events: none;
        transform: translateY(8px);
        transition: opacity var(--duration-2) var(--ease-out),
                    transform var(--duration-2) var(--ease-out),
                    background var(--duration-1) var(--ease-out);
        z-index: var(--z-back-to-top);
    }
    .back-to-top.is-visible {
        opacity: 1;
        pointer-events: auto;
        transform: translateY(0);
    }
    .back-to-top:hover { background: var(--color-navy-600); }

    /* -- Dashboard hero -- */
    .hero {
        display: grid;
        grid-template-columns: 1fr auto;
        gap: var(--space-8);
        align-items: center;
        margin-block-end: var(--space-8);
    }
    .hero h1 { font-size: var(--fs-2xl); margin-block-end: var(--space-2); }
    .hero h1 .accent { color: var(--color-gold); }
    .hero .sub {
        color: var(--color-text-muted);
        font-size: var(--fs-base);
        line-height: var(--lh-base);
        max-inline-size: 56ch;
    }
    @media (max-width: 720px) {
        .hero { grid-template-columns: 1fr; }
        .mic-area { order: -1; text-align: center; }
    }

    /* -- Mic quick-add button -- */
    .mic-area { text-align: center; }
    .mic-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        inline-size: 88px;
        block-size: 88px;
        border-radius: var(--radius-full);
        background: linear-gradient(135deg, var(--color-gold) 0%, var(--color-gold-600) 100%);
        border: 4px solid var(--color-navy);
        color: var(--color-navy);
        cursor: pointer;
        box-shadow: 0 6px 24px rgba(201, 168, 76, 0.4);
        transition: transform var(--duration-1) var(--ease-out),
                    box-shadow var(--duration-1) var(--ease-out);
        text-decoration: none;
    }
    .mic-btn:hover {
        transform: scale(1.08);
        box-shadow: 0 8px 32px rgba(201, 168, 76, 0.5);
    }
    .mic-btn:active { transform: scale(0.96); }
    .mic-label {
        display: block;
        margin-block-start: var(--space-2);
        font-size: var(--fs-xs);
        font-weight: var(--fw-bold);
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: var(--color-text-muted);
    }

    /* -- Stats row (top-of-dashboard summary numbers) -- */
    .stats-row {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        gap: var(--space-3);
        margin-block-end: var(--space-8);
    }
    .stat-card {
        background: var(--bg-surface);
        border-radius: var(--radius-lg);
        padding: var(--space-4) var(--space-5);
        box-shadow: var(--shadow-sm);
    }
    .stat-card .n {
        font-size: var(--fs-2xl);
        font-weight: 800;
        color: var(--color-navy);
        line-height: 1;
    }
    .stat-card .label {
        font-size: var(--fs-xs);
        color: var(--color-text-muted);
        text-transform: uppercase;
        letter-spacing: 0.05em;
        font-weight: var(--fw-bold);
        margin-block-start: var(--space-2);
    }
    .stat-card--accent .n { color: var(--color-gold); }

    /* -- Two-column dashboard grid (left: charts, right: placeholders) -- */
    .grid-2 {
        display: grid;
        grid-template-columns: 1.4fr 1fr;
        gap: var(--space-5);
        margin-block-end: var(--space-8);
    }
    .grid-2 > * > * + * { margin-block-start: var(--space-5); }
    @media (max-width: 900px) {
        .grid-2 { grid-template-columns: 1fr; }
    }

    /* -- Three-column dashboard grid (col 1: todos+pending,
          col 2: AI assistant, col 3: stats stack) -- */
    .grid-3 {
        display: grid;
        grid-template-columns: 1fr 1fr 1fr;
        gap: var(--space-5);
        margin-block-end: var(--space-6);
        align-items: start;
    }
    .grid-3 .dash-col { display: flex; flex-direction: column; gap: var(--space-4); }
    @media (max-width: 1100px) {
        .grid-3 { grid-template-columns: 1fr 1fr; }
        .grid-3 > :nth-child(3) { grid-column: 1 / -1; }
    }
    @media (max-width: 700px) {
        .grid-3 { grid-template-columns: 1fr; }
        .grid-3 > :nth-child(3) { grid-column: auto; }
    }

    /* -- Stat card variant: vertically stacked in col 3 of grid-3.
          Same visual as .stat-card but accepts the col flex flow. -- */
    .stat-card--stack {
        margin: 0;
    }

    /* -- Charts row beneath the 3-col grid (Pipeline | Priority | Sector) -- */
    .charts-row {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: var(--space-5);
        margin-block-end: var(--space-8);
    }
    @media (max-width: 1100px) {
        .charts-row { grid-template-columns: 1fr 1fr; }
    }
    @media (max-width: 900px) {
        .charts-row { grid-template-columns: 1fr; }
    }

    /* -- Dashboard main row: Blake (2/3) + side rail (1/3). `order` puts the
          chat wide-left regardless of source order; hidden chat panels
          (display:none) don't count as grid items. -- */
    .dash-grid {
        display: grid;
        grid-template-columns: 1fr 2fr;       /* side rail (1/3) | Blake (2/3) */
        gap: var(--space-5);
        margin-block-end: var(--space-6);
        align-items: start;
    }
    .dash-grid .dash-col { display: flex; flex-direction: column; gap: var(--space-4); }
    .dash-grid .dash-side { order: 1; }   /* col 1: todos + pending + sweet spot */
    .dash-grid .dash-main { order: 2; }   /* cols 2-3: Blake chat */
    @media (max-width: 900px) {
        .dash-grid { grid-template-columns: 1fr; }
    }

    /* -- Top stat strip: five cards across the top (4 clickable + the
          informational NDAs-Executed count). -- */
    .stats-row--top {
        grid-template-columns: repeat(5, 1fr);
        margin-block-end: var(--space-6);
    }
    a.stat-card {
        text-decoration: none;
        color: inherit;
        display: block;
        transition: box-shadow .15s ease, transform .15s ease;
    }
    a.stat-card:hover { box-shadow: var(--shadow-md, 0 6px 18px rgba(0,0,0,0.12)); transform: translateY(-1px); }
    a.stat-card:focus-visible { outline: 2px solid var(--color-gold); outline-offset: 2px; }
    @media (max-width: 980px) {
        .stats-row--top { grid-template-columns: repeat(3, 1fr); }
    }
    @media (max-width: 700px) {
        .stats-row--top { grid-template-columns: 1fr 1fr; }
    }

    /* Deal Detail main 2fr/1fr collapses to a single column at 900px.
       Below that the right sidebar gets crushed and Sweet Spot loses
       readability. */
    @media (max-width: 900px) {
        .deal-detail-grid { grid-template-columns: 1fr !important; }
    }

    /* -- Touch targets --
       Bumped to meet ~44px guidance when the primary pointer is coarse
       (phones / tablets). Mouse users keep the tighter desktop sizes. */
    @media (pointer: coarse) {
        .card__add    { inline-size: 44px; block-size: 44px; font-size: 22px; }
        .btn--sm      { min-block-size: 40px; padding-inline: var(--space-3); }
        .nav-item,
        .nav-item__trigger { padding-block: 12px; }
    }

    /* -- Phone-specific tweaks (<= 480px) --
       The dashboard hero stacks at 720px already; below 480px we also
       reduce card padding so widgets don't lose half their inline space
       to chrome on a 375px iPhone. */
    @media (max-width: 480px) {
        .card { padding: var(--space-4); }
        /* The dialogs ship with inline style="max-inline-size:480px;" so
           the centered desktop modal looks compact. On a phone that's
           wider than the viewport, so we force a tighter cap with
           !important. inline-size also explicit so position:fixed top-
           layer dialogs don't size to intrinsic content. */
        .blake-modal {
            inline-size:     calc(100vw - 1rem) !important;
            max-inline-size: calc(100vw - 1rem) !important;
            max-block-size:  calc(100vh - 1rem);
            margin-inline:   auto;
        }
        .blake-modal > form { padding: var(--space-4); }
        /* Stack the action buttons too — Cancel + a long-labeled primary
           ("Save excerpt") together don't fit on a narrow row. */
        .blake-modal__actions { flex-wrap: wrap; }
        .blake-modal__actions .btn { flex: 1 1 auto; }
    }

    /* -- Blake AI Assistant placeholder card (Stage 2 chat surface
          coming soon; reserved slot in col 2 of the 3-col grid) -- */
    .ai-assistant-card {
        background: linear-gradient(180deg, #fffbeb 0%, #fff 65%);
        border: 1px solid var(--color-gold, #C9A84C);
        border-radius: var(--radius);
        padding: var(--space-5);
        display: flex;
        flex-direction: column;
        gap: var(--space-3);
        min-block-size: 280px;
        box-shadow: var(--shadow-sm);
    }
    .ai-assistant-card__head {
        display: flex;
        align-items: center;
        gap: var(--space-3);
    }
    .ai-assistant-card h2 {
        margin: 0;
        font-size: var(--fs-md);
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: var(--color-navy, #1A2744);
    }
    .blake-avatar {
        inline-size: 36px;
        block-size: 36px;
        border-radius: 50%;
        object-fit: cover;
        object-position: center top;
        border: 2px solid var(--color-gold, #C9A84C);
        flex: 0 0 auto;
        background: var(--color-navy, #1A2744);
    }
    .ai-assistant-card .lead {
        font-size: var(--fs-base);
        line-height: var(--lh-base);
        color: var(--color-text);
        margin: 0;
    }
    .ai-assistant-card .preview-prompt {
        background: rgba(26, 39, 68, 0.04);
        border-left: 3px solid var(--color-gold, #C9A84C);
        border-radius: 0 var(--radius-sm, 4px) var(--radius-sm, 4px) 0;
        padding: var(--space-3) var(--space-4);
        font-size: var(--fs-sm);
        color: var(--color-text-muted);
        font-style: italic;
    }
    .ai-assistant-card .preview-input {
        margin-block-start: auto;
        display: flex;
        align-items: center;
        gap: var(--space-2);
        padding: var(--space-3);
        border: 1.5px dashed var(--color-gold, #C9A84C);
        border-radius: var(--radius);
        color: var(--color-text-subtle);
        font-size: var(--fs-sm);
        background: #fff;
        font-style: italic;
    }
    .ai-assistant-card .preview-input .badge {
        background: var(--color-gold, #C9A84C);
        color: var(--color-navy, #1A2744);
        margin-inline-start: auto;
        font-size: var(--fs-xs);
        padding: 2px 8px;
        border-radius: 999px;
        font-weight: var(--fw-bold);
    }

    /* -- Card heading used inside .card on dashboard -- */
    .card__heading {
        font-size: var(--fs-md);
        text-transform: uppercase;
        letter-spacing: 0.05em;
        font-weight: var(--fw-bold);
        color: var(--color-navy);
        margin-block-end: var(--space-4);
    }

    /* -- Chart wrapper -- */
    .chart-wrap {
        position: relative;
        inline-size: 100%;
        max-block-size: 320px;
    }
    .chart-wrap--sm { max-block-size: 260px; }

    /* -- Dashed placeholder card ("coming soon") -- */
    .placeholder {
        background: #F9FAFB;
        border: 2px dashed var(--color-border-strong);
        border-radius: var(--radius-lg);
        padding: var(--space-8) var(--space-6);
        text-align: center;
        color: var(--color-text-subtle);
        font-size: var(--fs-sm);
        line-height: var(--lh-base);
    }
    .placeholder strong { color: var(--color-text-muted); display: block; margin-block-end: var(--space-2); }
    .placeholder .icon-hero {
        font-size: var(--fs-2xl);
        opacity: 0.5;
        display: block;
        margin-block-end: var(--space-2);
    }
    .placeholder em {
        font-size: var(--fs-xs);
        display: inline-block;
        margin-block-start: var(--space-2);
    }

    /* -- Sweet Spot mini summary (used on dashboard + deal-detail) -- */
    .ss-mini {
        display: flex;
        align-items: center;
        gap: var(--space-4);
        padding: var(--space-4);
        background: #F9FAFB;
        border-radius: var(--radius-md);
        border: 1px solid var(--color-border);
    }
    .ss-mini .big-n {
        font-size: var(--fs-2xl);
        font-weight: 800;
        color: var(--color-gold);
        line-height: 1;
        min-inline-size: 48px;
        text-align: center;
    }
    .ss-mini .detail {
        font-size: var(--fs-sm);
        color: var(--color-text-muted);
    }
    .ss-mini .detail strong { color: var(--color-navy); }
    .ss-mini .detail a { color: var(--color-gold-600); font-weight: var(--fw-semibold); }

    /* -- Icon (Lucide inline SVG from includes/icon.php) -- */
    .icon {
        display: inline-block;
        vertical-align: -0.15em;
        flex-shrink: 0;
        color: currentColor;
        stroke: currentColor;
        fill: none;
    }
    .icon--missing {
        inline-size: 1em;
        block-size: 1em;
        background: var(--color-danger-bg);
        border-radius: var(--radius-sm);
    }

    /* -- Password-visibility eye toggle (login + any password input) -- */
    .pw-wrap {
        position: relative;
    }
    .pw-wrap input {
        padding-inline-end: 2.5rem;
    }
    .pw-eye {
        position: absolute;
        inset-inline-end: 0.5rem;
        inset-block-start: 50%;
        transform: translateY(-50%);
        inline-size: 28px;
        block-size: 28px;
        background: transparent;
        border: none;
        cursor: pointer;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        color: var(--color-text-muted);
    }
    .pw-eye:hover,
    .pw-eye:focus-visible {
        color: var(--color-gold);
        outline: none;
    }
    .pw-eye svg { inline-size: 18px; block-size: 18px; }

    /* -- User menu dropdown (topbar avatar button) -- */
    .user-menu {
        position: relative;
    }
    .avatar--button {
        border: none;
        cursor: pointer;
        font-family: inherit;
        padding: 0;
    }
    .avatar--button:focus-visible {
        outline: 2px solid var(--color-gold);
        outline-offset: 2px;
    }
    .user-menu-dropdown {
        position: absolute;
        inset-block-start: calc(100% + 8px);
        inset-inline-end: 0;
        min-inline-size: 220px;
        background: var(--bg-surface);
        border: 1px solid var(--color-border);
        border-radius: var(--radius-md);
        box-shadow: var(--shadow-lg);
        z-index: var(--z-dropdown);
        overflow: hidden;
        padding-block: var(--space-1);
    }
    .user-menu-header {
        padding: var(--space-3) var(--space-4);
        background: var(--bg-surface-2);
        border-block-end: 1px solid var(--color-border);
    }
    .user-menu-header .name {
        font-weight: var(--fw-semibold);
        color: var(--color-text);
        font-size: var(--fs-sm);
    }
    .user-menu-header .role {
        font-size: var(--fs-xs);
        color: var(--color-text-subtle);
    }
    .user-menu-dropdown a,
    .user-menu-dropdown button {
        display: flex;
        align-items: center;
        gap: var(--space-3);
        padding: var(--space-2) var(--space-4);
        color: var(--color-text);
        text-decoration: none;
        font-size: var(--fs-sm);
        background: transparent;
        border: none;
        inline-size: 100%;
        text-align: start;
        cursor: pointer;
        font-family: inherit;
    }
    .user-menu-dropdown a:hover,
    .user-menu-dropdown button:hover {
        background: var(--bg-surface-2);
    }

    /* -- Sidebar foot as clickable link -- */
    a.sidebar-foot {
        text-decoration: none;
        color: inherit;
        transition: background var(--duration-1) var(--ease-out);
    }
    a.sidebar-foot:hover {
        background: var(--bg-surface-2);
    }

    /* -- Sweet Spot stoplight dot (used on pipeline rows) -- */
    .stoplight {
        display: inline-block;
        inline-size: 12px;
        block-size: 12px;
        border-radius: 50%;
        background: var(--color-border-strong);
        vertical-align: -2px;
    }
    .stoplight--green  { background: #22C55E; }
    .stoplight--yellow { background: #F59E0B; }
    .stoplight--red    { background: #DC2626; }

    /* -- Priority badge mapping (uses base .badge variants) -- */
    .badge--priority-high      { background: var(--color-danger-bg);  color: var(--color-danger); }
    .badge--priority-medium    { background: var(--color-warning-bg); color: var(--color-warning); }
    .badge--priority-low       { background: var(--color-success-bg); color: var(--color-success); }
    .badge--priority-undefined { background: var(--color-border);     color: var(--color-text-muted); }
    .badge--priority-dead      { background: #1F2937;                 color: #F3F4F6; }

    /* -- Priority inline editor (select styled like the badge) -- */
    .priority-select {
        appearance: none;
        -webkit-appearance: none;
        border: 0;
        padding: 0.125rem var(--space-2);
        padding-inline-end: 18px;   /* room for the caret overlay */
        border-radius: var(--radius-sm);
        font-size: var(--fs-xs);
        font-weight: var(--fw-bold);
        text-transform: uppercase;
        letter-spacing: 0.02em;
        cursor: pointer;
        font-family: inherit;
        line-height: 1.2;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 4px center;
        background-size: 10px 10px;
    }
    .priority-select option { background: var(--bg-surface); color: var(--color-text); }
    .priority-select[data-priority="high"]      { background-color: var(--color-danger-bg);  color: var(--color-danger); }
    .priority-select[data-priority="medium"]    { background-color: var(--color-warning-bg); color: var(--color-warning); }
    .priority-select[data-priority="low"]       { background-color: var(--color-success-bg); color: var(--color-success); }
    .priority-select[data-priority="undefined"] { background-color: var(--color-border);     color: var(--color-text-muted); }
    .priority-select[data-priority="dead"]      { background-color: #1F2937;                 color: #F3F4F6; }
    .priority-select:focus-visible { outline: 2px solid var(--color-gold); outline-offset: 2px; }
    .priority-select.is-saving     { opacity: 0.6; }
    .priority-select.is-error      { outline: 2px solid var(--color-danger); }

    /* -- Pipeline status inline editor (neutral chrome, navy badge look) -- */
    .status-select {
        appearance: none;
        -webkit-appearance: none;
        border: 0;
        padding: 0.25rem var(--space-2);
        padding-inline-end: 20px;   /* room for the caret overlay */
        border-radius: var(--radius-sm);
        font-size: var(--fs-xs);
        font-weight: var(--fw-bold);
        letter-spacing: 0.02em;
        cursor: pointer;
        font-family: inherit;
        line-height: 1.2;
        max-inline-size: 22ch;
        text-overflow: ellipsis;
        background-color: var(--color-navy);
        color: var(--fg-on-navy);
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 5px center;
        background-size: 10px 10px;
    }
    .status-select option { background: var(--bg-surface); color: var(--color-text); }
    .status-select:focus-visible { outline: 2px solid var(--color-gold); outline-offset: 2px; }
    .status-select.is-saving     { opacity: 0.6; }
    .status-select.is-error      { outline: 2px solid var(--color-danger); }

    /* -- Source badge (Dynamo-synced vs locally-created) -- */
    .badge--source-dynamo { background: var(--color-info-bg); color: var(--color-info); }
    .badge--source-local  { background: var(--color-border);  color: var(--color-text-muted); }

    /* -- Pipeline stage accordion (uses native <details>/<summary>) -- */
    .stage-group {
        background: var(--bg-surface);
        border: 1px solid var(--color-border);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-sm);
        margin-block-end: var(--space-3);
    }
    .stage-group[open] {
        box-shadow: var(--shadow-md);
    }
    .stage-group > summary {
        display: flex;
        align-items: center;
        gap: var(--space-3);
        padding: var(--space-4) var(--space-5);
        cursor: pointer;
        list-style: none;
        font-weight: var(--fw-semibold);
        color: var(--color-text);
        border-radius: var(--radius-lg);
    }
    .stage-group > summary::-webkit-details-marker { display: none; }
    .stage-group > summary::before {
        content: "▶";
        font-size: 10px;
        color: var(--color-text-muted);
        transition: transform var(--duration-1) var(--ease-out);
    }
    .stage-group[open] > summary::before { transform: rotate(90deg); }
    .stage-group > summary:hover { background: var(--bg-surface-2); }
    .stage-group .stage-count {
        margin-inline-start: auto;
        font-family: var(--font-mono);
        font-size: var(--fs-xs);
        color: var(--color-text-muted);
        background: var(--bg-surface-2);
        padding: 1px var(--space-2);
        border-radius: var(--radius-full);
    }

    /* Populated stages — navy header to signal "has deals", matching demo */
    .stage-group.stage-group--populated > summary {
        background: var(--color-navy);
        color: var(--fg-on-navy);
    }
    .stage-group.stage-group--populated > summary::before,
    .stage-group.stage-group--populated > summary .u-text-subtle {
        color: rgba(255, 255, 255, 0.85);
    }
    .stage-group.stage-group--populated > summary .stage-count {
        background: rgba(255, 255, 255, 0.15);
        color: var(--fg-on-navy);
    }
    .stage-group.stage-group--populated > summary:hover {
        background: var(--color-navy-600);
    }
    .stage-group .stage-body {
        padding: 0 var(--space-2) var(--space-2);
        overflow-x: auto;          /* keep 8-col pipeline table scrollable on narrow */
        -webkit-overflow-scrolling: touch;
    }

    /* Reusable scroll container for tables that have too many columns to
       fit comfortably on narrow viewports (audit log, future reports). */
    .table-scroll {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-inline: calc(var(--space-4) * -1);
        padding-inline: var(--space-4);
    }

    /* Safety net: at phone widths, any direct container of a .table gets
       horizontal scroll automatically, so a new page that forgets to wrap
       its <table class="table"> in .table-scroll still works on a phone.
       Belt-and-suspenders for the explicit wrappers above. */
    @media (max-width: 800px) {
        .card:has(> .table),
        section:has(> .table),
        form:has(> .table),
        .stage-body:has(> .table) {
            overflow-x: auto;
            -webkit-overflow-scrolling: touch;
        }
    }

    /* Pipeline stats row (narrower than dashboard stats) */
    .pipeline-stats {
        display: flex;
        gap: var(--space-4);
        flex-wrap: wrap;
        margin-block-end: var(--space-6);
    }
    .pipeline-stats .stat {
        background: var(--bg-surface);
        border: 1px solid var(--color-border);
        border-radius: var(--radius-md);
        padding: var(--space-2) var(--space-4);
        font-size: var(--fs-sm);
    }
    .pipeline-stats .stat strong {
        font-size: var(--fs-lg);
        color: var(--color-navy);
        display: block;
    }
    /* Clickable variant — renders as a button but inherits the .stat tile look.
       is-active highlights the currently-applied card filter. */
    .pipeline-stats .stat--clickable {
        font: inherit;
        text-align: start;
        cursor: pointer;
        color: var(--color-text);
        transition: border-color 0.15s ease, background 0.15s ease, transform 0.05s ease;
    }
    .pipeline-stats .stat--clickable:hover {
        border-color: var(--color-navy);
        background: var(--surface-2, var(--bg-surface-2));
    }
    .pipeline-stats .stat--clickable:focus-visible {
        outline: 2px solid var(--accent);
        outline-offset: 2px;
    }
    .pipeline-stats .stat--clickable.is-active {
        border-color: var(--accent);
        box-shadow: inset 0 0 0 1px var(--accent);
    }
    .pipeline-stats .stat--clickable.is-active strong { color: var(--accent-fg, var(--color-navy)); }

    /* -- Toast (aria-live region) -- */
    .toast {
        position: fixed;
        inset-block-end: var(--space-6);
        inset-inline-start: 50%;
        transform: translateX(-50%) translateY(12px);
        background: var(--color-navy);
        color: var(--fg-on-navy);
        padding: var(--space-3) var(--space-5);
        border-radius: var(--radius-md);
        box-shadow: var(--shadow-lg);
        font-size: var(--fs-sm);
        opacity: 0;
        pointer-events: none;
        z-index: var(--z-toast);
        transition: opacity var(--duration-2) var(--ease-out),
                    transform var(--duration-2) var(--ease-out);
    }
    .toast.is-visible {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }

    /* ------- Tweaks / Preferences controls ------- */
    /* The floating panel and the Settings page share these — consistent controls. */
    .tweaks {
        position: fixed;
        inset-inline-end: var(--space-6);
        inset-block-start: 72px;
        inline-size: 300px;
        background: var(--bg-surface);
        border: 1px solid var(--color-border);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-lg);
        z-index: var(--z-dropdown);
        transform: translateY(-8px);
        opacity: 0;
        pointer-events: none;
        transition: opacity var(--duration-2) var(--ease-out),
                    transform var(--duration-2) var(--ease-out);
    }
    .tweaks.is-visible {
        opacity: 1;
        transform: translateY(0);
        pointer-events: auto;
    }
    .tweaks-h {
        padding: var(--space-3) var(--space-4);
        border-block-end: 1px solid var(--color-border);
        display: flex;
        align-items: center;
        gap: var(--space-2);
    }
    .tweaks-h .tt {
        font-weight: var(--fw-semibold);
        font-size: var(--fs-sm);
        color: var(--color-text);
    }
    .tweaks-h .tt-sub {
        font-family: var(--font-mono);
        font-size: var(--fs-xs);
        color: var(--color-text-subtle);
        margin-inline-start: auto;
    }
    .tweaks-b {
        padding: var(--space-3) var(--space-4);
        display: flex;
        flex-direction: column;
        gap: var(--space-3);
    }
    .tweaks-row {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: var(--space-2);
    }
    .tweaks-row .lbl {
        color: var(--color-text-muted);
        font-size: var(--fs-sm);
    }

    /* Segmented control */
    .seg {
        display: inline-flex;
        border: 1px solid var(--color-border);
        border-radius: var(--radius);
        overflow: hidden;
        background: var(--bg-surface);
    }
    .seg button {
        background: transparent;
        border: 0;
        padding: 4px var(--space-3);
        font-size: var(--fs-xs);
        color: var(--color-text-muted);
        cursor: pointer;
    }
    .seg button.on {
        background: var(--bg-surface-2);
        color: var(--color-text);
    }

    /* Toggle switch */
    .tog {
        inline-size: 34px;
        block-size: 20px;
        background: var(--color-border-strong);
        border-radius: var(--radius-full);
        position: relative;
        cursor: pointer;
        transition: background var(--duration-1) var(--ease-out);
    }
    .tog::after {
        content: "";
        position: absolute;
        inset-block-start: 2px;
        inset-inline-start: 2px;
        inline-size: 16px;
        block-size: 16px;
        border-radius: 50%;
        background: white;
        box-shadow: var(--shadow-sm);
        transition: inset-inline-start var(--duration-1) var(--ease-out);
    }
    .tog.on { background: var(--accent); }
    .tog.on::after { inset-inline-start: 16px; }

    /* ------------------------------------------------------------------
       Blake chat (dashboard middle column)
       ------------------------------------------------------------------ */
    .chat-card {
        display: flex;
        flex-direction: column;
        background: var(--bg-surface);
        border: 1px solid var(--color-border);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-sm);
        min-block-size: 520px;
        max-block-size: 700px;
        overflow: hidden;
    }
    .chat-card__head {
        display: flex;
        align-items: center;
        gap: var(--space-2);
        padding: var(--space-3) var(--space-4);
        border-block-end: 1px solid var(--color-border);
        background: var(--surface-2, var(--bg-surface-2));
    }
    .chat-card__head .blake-avatar { inline-size: 24px; block-size: 24px; border-radius: 50%; }
    .chat-card__title { margin: 0; font-size: var(--fs-md); }
    .chat-card__sub {
        font-size: var(--fs-xs);
        color: var(--color-text-subtle);
        margin-inline-end: auto;
        margin-inline-start: var(--space-2);
    }

    .chat-thread {
        flex: 1;
        overflow-y: auto;
        padding: var(--space-4);
        background: var(--bg-surface);
    }
    .chat-thread .chat-empty {
        color: var(--color-text-subtle);
        font-size: var(--fs-sm);
        text-align: center;
        padding: var(--space-6) var(--space-3);
    }
    .chat-thread .chat-empty p { margin-block-end: var(--space-2); }

    /* Chat turn layout: each turn is a 3-column row (avatar | body | spacer).
       Blake on the left with avatar, You on the right with initials disc.
       Bubble corners are rounded except the corner closest to the avatar,
       which is squared — gives the bubbles a "spoken from here" feel. */
    .chat-turn {
        display: grid;
        grid-template-columns: 32px 1fr 32px;
        column-gap: var(--space-2);
        margin-block-end: var(--space-4);
        align-items: flex-start;
    }
    .chat-turn__avatar {
        grid-column: 1;
        grid-row: 1 / span 2;
        inline-size: 32px;
        block-size: 32px;
        border-radius: 50%;
        overflow: hidden;
        background: var(--bg-surface-2);
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
    }
    .chat-turn__avatar img {
        inline-size: 100%;
        block-size: 100%;
        object-fit: cover;
        display: block;
    }
    .chat-turn__role {
        grid-column: 2;
        grid-row: 1;
        font-size: var(--fs-xs);
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: var(--color-text-subtle);
        margin-block-end: var(--space-1);
        font-weight: var(--fw-semibold);
    }
    .chat-turn__body {
        grid-column: 2;
        grid-row: 2;
        background: var(--surface-2, var(--bg-surface-2));
        padding: var(--space-3);
        border-radius: var(--radius-md);
        border-start-start-radius: 4px; /* squared corner toward avatar (Blake on left) */
        font-size: var(--fs-sm);
        line-height: 1.5;
        color: var(--color-text);
    }
    .chat-turn__body p { margin: 0 0 var(--space-2); }
    .chat-turn__body p:last-child { margin-block-end: 0; }
    .chat-turn__body ul { margin: var(--space-2) 0; padding-inline-start: var(--space-5); }
    .chat-turn__body code { background: rgba(0,0,0,0.07); padding: 1px 5px; border-radius: 3px; font-size: 0.9em; }

    /* User turn: avatar moves to the right column, body justifies right, corner
       squared toward the avatar (top-right corner this time). */
    .chat-turn--user .chat-turn__avatar {
        grid-column: 3;
        grid-row: 1 / span 2;
        background: var(--color-navy);
        color: #fff;
        font-size: var(--fs-xs);
        font-weight: var(--fw-semibold);
        letter-spacing: 0.02em;
    }
    .chat-turn--user .chat-turn__role {
        grid-column: 2;
        text-align: end;
    }
    .chat-turn--user .chat-turn__body {
        grid-column: 2;
        background: var(--accent-soft);
        color: var(--color-text);
        border-start-start-radius: var(--radius-md);
        border-start-end-radius: 4px;
        /* Right-justify the user bubble visually without forcing min-width. */
        margin-inline-start: 20%;
    }
    @media (max-width: 720px) {
        .chat-turn--user .chat-turn__body { margin-inline-start: 8%; }
    }
    .chat-turn--pending .chat-typing {
        font-style: italic;
        color: var(--color-text-subtle);
    }
    .chat-turn--error .chat-turn__body {
        background: rgba(220, 38, 38, 0.08);
        color: var(--color-danger);
    }
    .chat-citations {
        margin-block-start: var(--space-2);
        font-size: var(--fs-xs);
        color: var(--color-text-subtle);
    }
    /* Per-response actions: kept in DOM but hidden by default — actions now
       live in .chat-thread-actions (thread footer). Left in case we want to
       restore the inline pattern later. */
    .chat-turn__actions {
        display: none;
    }
    .chat-saved-badge {
        font-size: var(--fs-xs);
        color: var(--color-success, #16a34a);
        margin-inline-start: var(--space-1);
    }

    /* Sticky thread-level action bar. One row of buttons that operate on the
       most-recent assistant answer. Renders disabled until the first answer
       lands. */
    .chat-thread-actions {
        display: flex;
        align-items: center;
        gap: var(--space-2);
        flex-wrap: wrap;
        padding: var(--space-2) var(--space-4);
        border-block-start: 1px solid var(--color-border);
        background: var(--bg-surface);
        font-size: var(--fs-xs);
    }
    .chat-thread-actions[hidden] { display: none; }
    .chat-thread-actions__label {
        color: var(--color-text-subtle);
        margin-inline-end: var(--space-1);
    }
    .chat-thread-actions__status {
        margin-inline-start: auto;
        color: var(--color-success, #16a34a);
        font-size: var(--fs-xs);
    }
    .chat-thread-actions .btn[disabled] {
        opacity: 0.45;
        cursor: not-allowed;
    }
    .chat-warning {
        margin-block-start: var(--space-2);
        padding: var(--space-2) var(--space-3);
        background: rgba(201, 168, 76, 0.1);
        color: var(--color-text);
        border-inline-start: 3px solid var(--accent);
        font-size: var(--fs-xs);
        border-radius: var(--radius-sm);
    }

    /* Header "?" help popover */
    .chat-help {
        position: relative;
        display: inline-flex;
    }
    .chat-help__btn {
        color: var(--color-text-subtle);
    }
    .chat-help__btn:hover,
    .chat-help__btn[aria-expanded="true"] {
        color: var(--accent);
    }
    /* Fixed positioning (placed by JS from the button rect) so the popover
       escapes the chat card's overflow:hidden clip. */
    .chat-help__pop {
        position: fixed;
        inset-block-start: 0;
        inset-inline-start: 0;
        inline-size: 300px;
        max-inline-size: calc(100vw - 16px);
        background: var(--bg-surface);
        border: 1px solid var(--color-border);
        border-radius: var(--radius-md);
        box-shadow: var(--shadow-md, 0 12px 32px rgba(0,0,0,0.18));
        padding: var(--space-3) var(--space-4);
        z-index: 1000;
    }
    .chat-help__pop[hidden] { display: none; }
    .chat-help__title { margin: 0 0 var(--space-1); font-size: var(--fs-sm); }
    .chat-help__lead { margin: 0 0 var(--space-2); font-size: var(--fs-xs); color: var(--color-text-muted); }
    .chat-help__list { list-style: none; margin: 0 0 var(--space-2); padding: 0; display: flex; flex-direction: column; gap: 2px; }
    .chat-help__example {
        inline-size: 100%;
        text-align: start;
        background: transparent;
        border: 0;
        border-radius: var(--radius-sm);
        padding: var(--space-1) var(--space-2);
        font: inherit;
        font-size: var(--fs-sm);
        color: var(--accent-strong, var(--color-navy));
        cursor: pointer;
    }
    .chat-help__example:hover { background: var(--accent-soft); }
    .chat-help__foot { margin: var(--space-2) 0 0; }

    .chat-suggestions {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: var(--space-2);
        padding: 0 var(--space-4) var(--space-2);
    }
    .chat-suggestions[hidden] { display: none; }
    .chat-suggestions__label {
        font-size: var(--fs-xs);
        color: var(--color-text-subtle);
        margin-inline-end: var(--space-1);
    }
    .chat-suggestions .chip {
        font: inherit;
        font-size: var(--fs-xs);
        background: var(--surface-2, var(--bg-surface-2));
        border: 1px solid var(--color-border);
        color: var(--color-text-muted);
        padding: 4px 10px;
        border-radius: 999px;
        cursor: pointer;
        transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
    }
    .chat-suggestions .chip:hover {
        background: var(--accent-soft);
        border-color: var(--accent);
        color: var(--color-text);
    }

    .chat-input {
        display: flex;
        gap: var(--space-2);
        padding: var(--space-3) var(--space-4);
        border-block-start: 1px solid var(--color-border);
        background: var(--bg-surface);
        align-items: flex-end;
    }
    .chat-input textarea {
        flex: 1;
        min-inline-size: 0;
        resize: none;
        font: inherit;
        font-size: var(--fs-sm);
        line-height: 1.4;
        padding: var(--space-2) var(--space-3);
        border: 1px solid var(--color-border);
        border-radius: var(--radius-md);
        background: var(--bg-surface);
        color: var(--color-text);
        max-block-size: 160px;
    }
    .chat-input textarea:focus {
        outline: 2px solid var(--accent);
        outline-offset: 1px;
    }

    /* ------ Chat history side panel ------ */
    .chat-history-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 998;
    }
    .chat-history-panel {
        position: fixed;
        inset-block: 0;
        inset-inline-end: 0;
        inline-size: 360px;
        max-inline-size: 100vw;
        background: var(--bg-surface);
        border-inline-start: 1px solid var(--color-border);
        box-shadow: -8px 0 24px rgba(0,0,0,0.15);
        z-index: 999;
        display: flex;
        flex-direction: column;
    }
    .chat-history-panel__head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: var(--space-3) var(--space-4);
        border-block-end: 1px solid var(--color-border);
    }
    .chat-history-panel__head h3 { margin: 0; font-size: var(--fs-md); }
    .chat-history-search { padding: var(--space-3) var(--space-4); border-block-end: 1px solid var(--color-border); }
    .chat-history-search input {
        inline-size: 100%;
        padding: var(--space-2) var(--space-3);
        border: 1px solid var(--color-border);
        border-radius: var(--radius-md);
        background: var(--bg-surface);
        color: var(--color-text);
    }
    .chat-history-list {
        list-style: none;
        margin: 0;
        padding: 0;
        flex: 1;
        overflow-y: auto;
    }
    .chat-history-item {
        display: flex;
        align-items: stretch;
        gap: var(--space-2);
        padding: 0 var(--space-2);
        border-block-end: 1px solid var(--color-border);
    }
    .chat-history-row {
        flex: 1;
        background: transparent;
        border: 0;
        text-align: start;
        padding: var(--space-3) var(--space-2);
        cursor: pointer;
        color: var(--color-text);
        display: flex;
        flex-direction: column;
        gap: 2px;
        min-inline-size: 0;
    }
    .chat-history-row:hover { background: var(--surface-2, var(--bg-surface-2)); }
    .chat-history-row__title {
        font-size: var(--fs-sm);
        font-weight: var(--fw-medium);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .chat-history-row__meta { font-size: var(--fs-xs); color: var(--color-text-subtle); }
    .chat-history-del {
        align-self: center;
        opacity: 0.5;
        font-size: 12px;
        background: transparent;
        border: 0;
        cursor: pointer;
        padding: var(--space-2);
        color: var(--color-text-subtle);
    }
    .chat-history-del:hover { opacity: 1; color: var(--color-danger, #dc2626); }
    .chat-history-empty {
        padding: var(--space-6) var(--space-4);
        text-align: center;
        color: var(--color-text-subtle);
        font-size: var(--fs-sm);
    }

    /* ------ Chat save-to-deal modal ------ */
    .chat-save-modal {
        border: 0;
        border-radius: var(--radius-lg);
        padding: 0;
        max-inline-size: 520px;
        inline-size: calc(100vw - 2rem);
        background: var(--bg-surface);
        color: var(--color-text);
        box-shadow: 0 24px 60px rgba(0,0,0,0.35);
    }
    .chat-save-modal::backdrop { background: rgba(0,0,0,0.55); }
    .chat-save-modal form { padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-4); }
    .chat-save-modal__head {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin: 0 0 var(--space-2);
    }
    .chat-save-modal__head h3 { margin: 0; font-size: var(--fs-md); }
    .chat-save-modal__foot { display: flex; gap: var(--space-2); justify-content: flex-end; }
    .chat-save-deal-results {
        list-style: none;
        margin: var(--space-2) 0 0;
        padding: 0;
        border: 1px solid var(--color-border);
        border-radius: var(--radius-md);
        background: var(--bg-surface);
        max-block-size: 200px;
        overflow-y: auto;
    }
    .chat-save-deal-results li > button {
        display: block;
        inline-size: 100%;
        text-align: start;
        background: transparent;
        border: 0;
        padding: var(--space-2) var(--space-3);
        cursor: pointer;
        font: inherit;
        color: var(--color-text);
    }
    .chat-save-deal-results li > button:hover { background: var(--surface-2, var(--bg-surface-2)); }
    .chat-save-deal-empty {
        padding: var(--space-3);
        text-align: center;
        color: var(--color-text-subtle);
        font-size: var(--fs-sm);
    }

    @media (max-width: 800px) {
        .chat-card { min-block-size: 460px; max-block-size: 80vh; }
        .chat-history-panel { inline-size: 100vw; border-inline-start: 0; }
    }

    /* ------------------------------------------------------------------
       Back-to-top button (injected by assets/js/app.js after >400px scroll)
       Navy disc with gold ring + arrow, sits above the bottom-right corner
       on every page rendered through Layout. Matches the demo's treatment.
       ------------------------------------------------------------------ */
    .back-to-top {
        position: fixed;
        inset-inline-end: 1.5rem;
        inset-block-end: 1.5rem;
        inline-size: 44px;
        block-size: 44px;
        border-radius: 50%;
        background: var(--color-navy);
        color: var(--accent);
        border: 2px solid var(--accent);
        font-size: 1.125rem;
        font-weight: 700;
        font-family: inherit;
        line-height: 1;
        cursor: pointer;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
        opacity: 0;
        pointer-events: none;
        transform: translateY(8px);
        transition: opacity 0.2s ease, transform 0.2s ease, background 0.15s ease;
        z-index: 90;
    }
    .back-to-top.visible {
        opacity: 1;
        pointer-events: auto;
        transform: translateY(0);
    }
    .back-to-top:hover { background: var(--color-navy-600); }
    .back-to-top:focus-visible {
        outline: 2px solid var(--accent);
        outline-offset: 2px;
    }
    /* Don't crowd the print page or sit on top of mobile nav fab room */
    @media print { .back-to-top { display: none !important; } }
}

/* -------------------------------------------------------------------------
   @layer utilities — atomic helpers, always win
   ------------------------------------------------------------------------- */
@layer utilities {
    /* A11y */
    .u-sr-only {
        position: absolute;
        inline-size: 1px;
        block-size: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
        border: 0;
    }

    /* Flex / stack helpers */
    .u-stack > * + * { margin-block-start: var(--space-4); }
    .u-stack-sm > * + * { margin-block-start: var(--space-2); }
    .u-stack-lg > * + * { margin-block-start: var(--space-8); }
    .u-row { display: flex; gap: var(--space-4); }
    .u-row--center { align-items: center; }
    .u-row--wrap { flex-wrap: wrap; }
    .u-spread { display: flex; justify-content: space-between; align-items: center; gap: var(--space-4); }

    /* Text */
    .u-text-muted  { color: var(--color-text-muted); }
    .u-text-subtle { color: var(--color-text-subtle); }
    .u-text-sm     { font-size: var(--fs-sm); }
    .u-text-xs     { font-size: var(--fs-xs); }
    .u-text-right  { text-align: end; }
    .u-text-center { text-align: center; }

    /* Spacing (block) */
    .u-mb-0 { margin-block-end: 0; }
    .u-mb-2 { margin-block-end: var(--space-2); }
    .u-mb-3 { margin-block-end: var(--space-3); }
    .u-mb-4 { margin-block-end: var(--space-4); }
    .u-mb-6 { margin-block-end: var(--space-6); }
    .u-mb-8 { margin-block-end: var(--space-8); }

    .u-mt-0 { margin-block-start: 0; }
    .u-mt-1 { margin-block-start: var(--space-1); }
    .u-mt-2 { margin-block-start: var(--space-2); }
    .u-mt-3 { margin-block-start: var(--space-3); }
    .u-mt-4 { margin-block-start: var(--space-4); }
    .u-mt-6 { margin-block-start: var(--space-6); }
    .u-mt-8 { margin-block-start: var(--space-8); }
}
