/* App shell (sidebar, top bar, page anatomy). Loaded in <head> so the layout never jumps on load. */
    /* ── App shell v6 ───────────────────────────────────────────────
       One grid: a solid full-height sidebar column + the page column.
       Page width and side padding come from three variables so every
       app page lines up with the top bar and with each other. */
    :root { --side-w: 256px; --page-max: 1280px; --page-pad-x: 32px; --top-h: 64px; }
    @media (max-width: 1199.98px) { :root { --page-pad-x: 24px; } }
    @media (max-width: 767.98px) { :root { --page-pad-x: 16px; --top-h: 56px; } }
    body { overflow-x: hidden; }
    /* The sidebar colour is painted on the grid column itself, so it reaches the bottom of
       any page length (full-page captures, zoomed-out windows) even though the panel is sticky. */
    .ms-shell {
        display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100vh;
        background: linear-gradient(to right, var(--side-bg) 0, var(--side-bg) calc(var(--side-w) - 1px), var(--side-line) calc(var(--side-w) - 1px), var(--side-line) var(--side-w), transparent var(--side-w)) no-repeat;
    }
    .ms-side {
        position: sticky; top: 0; align-self: start; height: 100vh; height: 100dvh;
        display: flex; flex-direction: column; gap: 12px; padding: 16px 12px 12px;
        background: var(--side-bg); border-right: 1px solid var(--side-line); z-index: 40;
    }
    .ms-side-top { display: flex; align-items: center; justify-content: space-between; min-height: 36px; padding: 0 8px; }
    .ms-brand { text-decoration: none; color: inherit; display: inline-flex; align-items: center; }
    .ms-workspace-chip { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 12px; text-decoration: none; color: var(--text-primary); background: var(--solid); min-width: 0; transition: border-color var(--duration-fast), box-shadow var(--duration-fast); }
    .ms-workspace-chip:hover { border-color: var(--line-strong); color: var(--text-primary); box-shadow: var(--shadow-1); }
    .ms-ws-avatar { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: var(--gradient-brand); color: var(--on-primary); font-weight: 700; font-size: .85rem; flex: none; }
    .ms-ws-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
    .ms-ws-text strong { font-size: .875rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .ms-ws-text small { font-size: .75rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

    .ms-nav { flex: 1; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 2px; min-height: 0; margin: 0 -12px; padding: 4px 12px 8px; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; padding-bottom: 20px; -webkit-mask-image: linear-gradient(to bottom, black calc(100% - 20px), transparent); mask-image: linear-gradient(to bottom, black calc(100% - 20px), transparent); }
    .ms-link { position: relative; display: flex; align-items: center; gap: 12px; height: 38px; flex: none; padding: 0 10px; border-radius: 9px; color: var(--text-secondary); text-decoration: none; font-size: .875rem; font-weight: 500; line-height: 1; min-width: 0; transition: background-color var(--duration-fast), color var(--duration-fast); }
    .ms-link span:not(.ms-pill) { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .ms-link > i { font-size: 18px; width: 20px; height: 20px; display: inline-flex; align-items: center; justify-content: center; line-height: 1; flex: none; color: var(--t, currentColor); --icon-tint: var(--t); }
    .ms-link:hover { background: var(--hover); color: var(--text-primary); }
    .ms-link.is-active { background: var(--nav-active-bg); color: var(--nav-active-fg); font-weight: 600; }
    .ms-link.is-active::before { content: ""; position: absolute; left: -12px; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0; background: var(--nav-active-bar); }
    .ms-link.is-active > i { --icon-tint-opacity: .45; }
    .ms-link:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
    /* Each destination keeps its own colour, everywhere it appears in the sidebar. */
    .ms-link .bi-house { --t: var(--tint-green); }
    .ms-link .bi-camera-video { --t: var(--tint-blue); }
    .ms-link .bi-check2-square { --t: var(--tint-teal); }
    .ms-link .bi-calendar3 { --t: var(--tint-orange); }
    .ms-link .bi-stars { --t: var(--tint-violet); }
    .ms-link .bi-layout-text-window-reverse { --t: var(--tint-amber); }
    .ms-link .bi-plug { --t: var(--tint-pink); }
    .ms-link .bi-folder2-open { --t: var(--tint-sky); }
    .ms-link .bi-people { --t: var(--tint-violet); }
    .ms-link .bi-credit-card { --t: var(--tint-green); }
    .ms-link .bi-sliders { --t: var(--tint-slate); }
    .ms-link .bi-key { --t: var(--tint-amber); }
    .ms-link .bi-link-45deg { --t: var(--tint-blue); }
    .ms-link .bi-hdd-network { --t: var(--tint-teal); }
    .ms-link .bi-person-badge { --t: var(--tint-orange); }
    .ms-link .bi-bar-chart { --t: var(--tint-sky); }
    .ms-pill { margin-left: auto; display: inline-flex; align-items: center; gap: 4px; height: 20px; font-size: .6875rem; font-weight: 600; line-height: 1; padding: 0 8px; border-radius: 999px; background: var(--bg-elevated); color: var(--text-secondary); flex: none; }
    .ms-pill i { font-size: 11px; }
    .ms-pill--brand { background: var(--brand-soft); color: var(--brand); }
    /* Plan pill on gated nav items: same look as the Integrations cards, sized to the nav's 20px pills. */
    .ms-nav .ms-link .plan-pill { height: 20px; padding: 0 8px 0 7px; font-size: .6875rem; gap: 4px; }
    .ms-nav .ms-link .plan-pill i { font-size: 10px; }
    .ms-nav-label { font-family: var(--font-body); font-size: .6875rem; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--text-secondary); margin: 14px 0 4px; padding: 6px 10px; display: flex; justify-content: space-between; align-items: center; list-style: none; cursor: default; border-radius: 8px; }
    .ms-dev { display: flex; flex-direction: column; gap: 2px; }
    .ms-dev summary { cursor: pointer; transition: background-color var(--duration-fast), color var(--duration-fast); }
    .ms-dev summary:hover { background: var(--hover); color: var(--text-primary); }
    .ms-dev summary:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
    .ms-dev summary::-webkit-details-marker { display: none; }
    .ms-dev summary i { font-size: 12px; transition: transform var(--duration-fast) var(--ease-out); }
    .ms-dev[open] summary i { transform: rotate(180deg); }
    .ms-side-foot { padding-top: 12px; border-top: 1px solid var(--side-line); }
    .ms-side-foot .ai-usage-meter { margin: 0; }

    .ms-main { min-width: 0; display: flex; flex-direction: column; }
    /* Top bar: page title on the left; one primary action + the account menu on the right.
       Its side padding tracks the content column so both share the same left and right edges. */
    .ms-top {
        position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px; height: var(--top-h);
        padding: 0 max(var(--page-pad-x), calc((100% - var(--page-max)) / 2));
        border-bottom: 1px solid transparent; background: transparent;
        transition: border-color .2s, box-shadow .2s, background-color .2s;
    }
    /* Transparent at the top of the page; frosted with a hairline once content scrolls under it. */
    .ms-top.is-scrolled { border-bottom-color: var(--line); background: color-mix(in srgb, var(--canvas) 78%, transparent); -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur); box-shadow: 0 6px 18px -16px rgba(0, 0, 0, .35); }
    .ms-top-title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .ms-top-actions { display: flex; align-items: center; gap: 12px; }
    .ms-start { display: inline-flex; align-items: center; gap: 6px; }
    .ms-top-sep { width: 1px; height: 24px; background: var(--line-strong); }
    .ms-icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--solid); color: var(--text-secondary); display: inline-grid; place-items: center; transition: color var(--duration-fast), border-color var(--duration-fast); }
    .ms-icon-btn:hover { color: var(--text-primary); border-color: var(--line-strong); }
    .ms-avatar-btn { border: 0; background: transparent; padding: 0; border-radius: 50%; display: inline-flex; align-items: center; gap: 4px; }
    .ms-avatar-btn:hover > :first-child, .ms-avatar-btn[aria-expanded="true"] > :first-child { box-shadow: 0 0 0 2px var(--canvas), 0 0 0 4px var(--brand-border); }
    .ms-avatar-btn > :first-child { border-radius: 50%; transition: box-shadow var(--duration-fast); }
    .ms-avatar-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; }
    .ms-body { padding: 28px var(--page-pad-x) 64px; max-width: calc(var(--page-max) + 2 * var(--page-pad-x)); width: 100%; margin: 0 auto; }
    .ms-scrim { display: none; }
    @media (max-width: 767.98px) {
        .ms-shell { grid-template-columns: 1fr; background: none; }
        .ms-side { position: fixed; inset: 0 auto 0 0; width: 284px; max-width: 86vw; transform: translateX(-102%); transition: transform .25s cubic-bezier(.16,1,.3,1); box-shadow: var(--shadow-lg); }
        body.ms-nav-open .ms-side { transform: none; }
        body.ms-nav-open .ms-scrim { display: block; position: fixed; inset: 0; background: var(--scrim); -webkit-backdrop-filter: var(--scrim-blur); backdrop-filter: var(--scrim-blur); z-index: 35; }
        .ms-start span { display: none; }
        .ms-start { width: 40px; padding: 0 !important; }
        .ms-body { padding-top: 20px; padding-bottom: 48px; }
    }

    /* Ask dock: the Ask Minutely bar, pinned 5px above the viewport bottom on every page that has one.
       It spans the page column (beside the sidebar), keeps the page gutters and clears the phone
       home indicator. The page reserves its height (--ask-dock-h, kept in sync by sidebar.html)
       so the last content can always scroll clear of it. Only a dock that is shown reserves space:
       one inside an inactive tab pane does not. */
    :root { --ask-dock-gap: 5px; --ask-dock-h: 66px; --ask-dock-max: 880px; }
    .ask-dock {
        position: fixed; z-index: 30; left: var(--side-w); right: 0;
        bottom: calc(var(--ask-dock-gap) + env(safe-area-inset-bottom, 0px));
        padding: 0 var(--page-pad-x); pointer-events: none; margin: 0;
    }
    .ask-dock__bar {
        pointer-events: auto; max-width: var(--ask-dock-max); margin: 0 auto;
        display: flex; align-items: flex-end; gap: 10px; padding: 8px 8px 8px 16px; border-radius: 18px;
        background: var(--solid); border: 1px solid var(--line-strong); box-shadow: var(--shadow-2);
        transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
    }
    .ask-dock__bar:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--brand-glow), var(--shadow-2); }
    .ask-dock__bar > .bi { color: var(--brand); font-size: 20px; line-height: 1; align-self: center; flex: none; }
    .ask-dock__input {
        flex: 1; min-width: 0; border: 0; outline: none; resize: none; background: transparent; color: var(--text-primary);
        font-size: 16px; line-height: 1.5; padding: 7px 0; height: 38px; max-height: 160px; overflow-y: auto;
    }
    .ask-dock__input::placeholder { color: var(--text-secondary); }
    .ask-dock__bar > .btn { flex: none; min-height: 40px; }
    .ms-body:has(.ask-dock:not(.detail-tab-pane:not(.active) *)) {
        padding-bottom: calc(var(--ask-dock-h) + var(--ask-dock-gap) + env(safe-area-inset-bottom, 0px) + 24px);
    }
    @media (max-width: 767.98px) {
        .ask-dock { left: 0; }
        .ask-dock__bar { padding-left: 12px; gap: 8px; }
        .ask-dock__bar > .btn span { display: none; }
    }

    /* Ghost buttons in the app read as buttons, not as plain text. */
    .ms-body .btn-ghost:not(.p-0), .ms-body .btn-link:not(.p-0), .modal .btn-ghost:not(.p-0), .modal .btn-link:not(.p-0) { --btn-bg: var(--bg-elevated); --btn-fg: var(--text-primary); --btn-border: var(--line); text-decoration: none; }
    .ms-body .btn-ghost:not(.p-0):hover, .ms-body .btn-link:not(.p-0):hover, .modal .btn-ghost:not(.p-0):hover, .modal .btn-link:not(.p-0):hover { --btn-bg: var(--hover); --btn-border: var(--line-strong); }
    .ms-body .btn-link.text-danger:not(.p-0), .modal .btn-link.text-danger:not(.p-0) { --btn-fg: var(--danger); --btn-bg: var(--danger-soft); --btn-border: transparent; }

    /* Colourful feature icons: section and card headings tint their duotone icon. */
    .ms-body h2 > .bi, .ms-body h3 > .bi, .ms-body .card-title > .bi, .ms-body .hm-empty > .bi, .ms-body .empty > .bi, .ms-body .empty__icon .bi { color: var(--t, var(--brand)); --icon-tint: var(--t, var(--brand)); --icon-tint-opacity: .32; }
    .ms-body .bi-calendar-event, .ms-body .bi-calendar3, .ms-body .bi-calendar-check { --t: var(--tint-orange); }
    .ms-body .bi-shield-check, .ms-body .bi-check2-square { --t: var(--tint-teal); }
    .ms-body .bi-clock-history { --t: var(--tint-blue); }
    .ms-body .bi-stars, .ms-body .bi-magic { --t: var(--tint-violet); }
    .ms-body .bi-people, .ms-body .bi-person-plus { --t: var(--tint-violet); }
    .ms-body .bi-camera-video { --t: var(--tint-blue); }
    .ms-body .bi-folder2-open, .ms-body .bi-file-earmark-text { --t: var(--tint-sky); }
    .ms-body .bi-plug, .ms-body .bi-plug-fill { --t: var(--tint-pink); }
    .ms-body .bi-key { --t: var(--tint-amber); }
    .ms-body .bi-translate, .ms-body .bi-globe { --t: var(--tint-sky); }
    .ms-body .bi-layout-text-window-reverse { --t: var(--tint-amber); }
    .ms-body .bi-lightning-charge { --t: var(--tint-amber); }
    .ms-body .bi-exclamation-triangle { --t: var(--warning); }

    /* ── Shared page anatomy: every page starts with .page-head ── */
    .page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem 1.5rem; flex-wrap: wrap; margin-bottom: 1.75rem; }
    .page-head > div:first-child { min-width: 0; flex: 1 1 420px; }
    /* Every page uses the same width and starting point, whatever container it was built with. */
    #content > .container, #content > .container-xxl, #content > .container-fluid { max-width: none !important; padding-left: 0 !important; padding-right: 0 !important; margin-top: 0 !important; padding-top: 0 !important; }
    .page-head h1, .page-head h2 { font-family: var(--font-display); font-weight: 500; font-size: clamp(1.5rem, 2.4vw, 1.9rem); letter-spacing: -.025em; margin: 0; }
    .page-head p { color: var(--text-secondary); margin: .35rem 0 0; max-width: 640px; }
    .surface { background: var(--bg-surface); border: 1px solid var(--bg-border); border-radius: 18px; -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur); }
    #content > * { min-width: 0; }

    /* ── Legacy page components, harmonised with the v5 system ── */
    #content h2:not([class]), #content .page-title { font-family: var(--font-display); font-weight: 500; letter-spacing: -.025em; }
    #content > .container > .d-flex > h2:first-child, #content > .container > h2:first-child { font-size: clamp(1.5rem, 2.4vw, 1.9rem); }
    .meetings-subtitle { color: var(--text-secondary) !important; }
    .card-glass { background: var(--bg-surface) !important; border: 1px solid var(--bg-border) !important; border-radius: 18px !important; -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur); }
    .card-glass-header { border-bottom-color: var(--bg-border) !important; }
    .card-glass-title { color: var(--text-primary) !important; }
    .btn-teal { background: var(--brand) !important; border-color: var(--brand) !important; color: var(--text-on-brand) !important; border-radius: 999px; }
    .btn-teal:hover { background: var(--brand-hover) !important; border-color: var(--brand-hover) !important; }
    .btn-outline-teal { color: var(--brand) !important; border-color: var(--brand-border) !important; background: transparent !important; border-radius: 999px; }
    .btn-outline-teal:hover { background: var(--brand-soft) !important; }
    .badge-admin, .badge-member, .badge-status-active, .badge-status-pending, .badge-status-disabled, .badge-project { border-radius: 999px !important; font-weight: 600 !important; font-size: .74rem !important; padding: .25em .7em !important; }
    .badge-admin { background: var(--brand-soft) !important; color: var(--brand) !important; }
    .badge-member, .badge-project { background: var(--bg-elevated) !important; color: var(--text-secondary) !important; }
    .badge-status-active { background: var(--success-soft) !important; color: var(--success) !important; }
    .badge-status-pending { background: var(--warning-soft) !important; color: var(--warning) !important; }
    .badge-status-disabled { background: var(--danger-soft) !important; color: var(--danger) !important; }
    .user-avatar-sm { background: var(--brand-soft) !important; color: var(--brand) !important; }
    .table-glass th, .table th { color: var(--text-muted) !important; font-size: .72rem !important; letter-spacing: .06em !important; font-weight: 600 !important; border-bottom-color: var(--bg-border) !important; }
    .table td { border-color: var(--bg-border) !important; }
    .alert-info { background: var(--info-soft); color: var(--text-primary); border-color: transparent; border-radius: 14px; }
    .alert-warning { background: var(--warning-soft); color: var(--text-primary); border-color: transparent; border-radius: 14px; }
    .alert-danger { background: var(--danger-soft); color: var(--text-primary); border-color: transparent; border-radius: 14px; }
    .alert-success { background: var(--success-soft); color: var(--text-primary); border-color: transparent; border-radius: 14px; }
    .text-truncate-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
    #content .container, #content .container-xxl, #content .container-fluid { max-width: 100%; padding-left: 0; padding-right: 0; }

/* Legacy harmonisation for older pages. */
    /* Rotate chevron based on expanded state */
    [aria-expanded="true"] .bi-chevron-down {
        transform: rotate(180deg);
    }

    [aria-expanded="false"] .bi-chevron-down {
        transform: rotate(0deg);
    }

    .collapse,
    .collapsing {
        transition-duration: 0s !important;
    }

    /* Left menu: journey-grouped product IA */
    .sidebar-main-nav .nav-link {
        position: relative;
        display: flex;
        align-items: center;
        gap: 0.625rem;
        padding: 0.625rem 0.75rem;
        margin-bottom: 0.125rem;
        border-radius: var(--radius-sm);
        color: var(--text-secondary);
        text-decoration: none;
        border: 1px solid transparent;
        background: transparent;
        font-size: 0.9rem;
    }

    .sidebar-nav-section {
        margin-bottom: 1rem;
    }

    .sidebar-nav-label {
        padding: 0.35rem 0.75rem;
        color: var(--text-tertiary);
        font-size: 0.66rem;
        font-weight: 700;
        letter-spacing: 0.08em;
        text-transform: uppercase;
    }

    .sidebar-main-nav .nav-link i {
        font-size: 1.125rem;
        opacity: 0.9;
    }

    .sidebar-main-nav .nav-link:hover {
        color: var(--text-primary);
        /* Use a token-based tint so light theme gets a visible hover
           too — rgba(255,255,255,0.04) was invisible on a cream sidebar. */
        background: var(--brand-soft);
        border-color: var(--brand-border);
    }

    .sidebar-main-nav .nav-link.active {
        /* The active state uses the brand color for the foreground —
           reads on both light AND dark sidebar backgrounds. The previous
           color:#ffffff went WHITE-ON-CREAM in light theme = invisible. */
        color: var(--brand);
        background: var(--brand-soft);
        border-color: var(--brand-border);
        font-weight: 600;
    }

    .sidebar-main-nav .nav-link.active i {
        color: var(--brand);
    }

    .sidebar-main-nav .nav-link.active::after {
        content: '';
        position: absolute;
        right: 0;
        top: 50%;
        transform: translateY(-50%);
        width: 4px;
        height: 1.5rem;
        background: var(--signal);
        border-radius: 2px;
    }

    .sidebar-main-nav .nav-link-disabled {
        opacity: 0.62;
        cursor: not-allowed;
    }

    .sidebar-main-nav .nav-link-disabled:hover {
        color: var(--text-secondary);
        background: transparent;
    }

    .sidebar {
        top: 0;
        z-index: 100;
        max-width: 256px;
        /* Use the token-based surface so the sidebar matches the rest
           of the dashboard chrome in both themes. Previously the bg was
           hardcoded near-black (rgba(11,13,18,0.98)) which CLASHED with
           the light theme override at templates/base.html:1145
           making the page look broken on first paint. */
        background-color: var(--bg-surface);
        border-right: 1px solid var(--bg-border);
        box-shadow: var(--shadow-sm);
    }

    /* Bootstrap 5 doesn't ship a min-h-0 utility but the sidebar relies on
       it so the scrollable nav can shrink and keep the user bar pinned to
       the bottom. Define it locally. */
    .min-h-0 { min-height: 0 !important; }

    /* Keep the user bar locked to the bottom even when nav content is short
       AND visible above the viewport when content is long. */
    .sidebar-nav-scroll {
        min-height: 0;
        scrollbar-width: thin;
    }
    .sidebar-nav-scroll::-webkit-scrollbar { width: 6px; }
    .sidebar-nav-scroll::-webkit-scrollbar-thumb {
        background: var(--bg-elevated);
        border-radius: 3px;
    }
    .sidebar-user-section {
        position: relative;
        flex-shrink: 0;
    }
    .sidebar-nav-section { margin-bottom: 0.75rem; }
    .sidebar-main-nav .nav-link { padding: 0.5rem 0.75rem; }

    /* Dashboard shell background — use the token directly so light and
       dark themes both work. Previously this had a HARDCODED dark
       gradient fading to var(--ink-950) at the bottom, which made dark text
       on light theme go INVISIBLE halfway down the page. */
    .projects-page {
        min-height: 100vh;
        background: var(--bg-base);
    }

    .main-workspace {
        min-height: 100vh;
    }

    .account-dropdown {
        position: relative;
    }

    .account-submenu {
        transition: all 0.3s ease;
    }

    .account-submenu .nav-link {
        font-size: 0.95em;
    }

    .account-caret {
        transform: rotate(0deg);
    }

    .account-caret-container {
        display: inline-flex;
        align-items: center;
        transform: translateY(5px);
    }

    .api-integration-dropdown {
        position: relative;
    }

    .api-integration-submenu {
        transition: all 0.3s ease;
    }

    .api-integration-submenu .nav-link {
        font-size: 0.95em;
    }

    .api-integration-caret {
        transform: rotate(0deg);
    }

    .api-integration-caret-container {
        display: inline-flex;
        align-items: center;
        transform: translateY(5px);
    }

    .settings-dropdown {
        position: relative;
    }

    .settings-submenu {
        transition: all 0.3s ease;
    }

    .settings-submenu .nav-link {
        font-size: 0.95em;
    }

    .settings-caret {
        transform: rotate(0deg);
    }

    .settings-caret-container {
        display: inline-flex;
        align-items: center;
        transform: translateY(5px);
    }

    /* User bar and context menu (bottom left) */
    .sidebar-user-section {
        overflow: visible;
        padding: 0.5rem 0.75rem 0.75rem;
        border-top: 1px solid var(--bg-border);
    }

    .user-bar {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        width: 100%;
        padding: 0.5rem 0.25rem;
        border: none;
        border-radius: var(--radius-sm);
        background: var(--surface-raised);
        border: 1px solid var(--border-subtle);
        color: inherit;
        cursor: pointer;
        font-size: 0.9rem;
        text-align: left;
    }

    .user-bar:hover {
        background: var(--bg-elevated);
    }

    .user-avatar {
        flex-shrink: 0;
        width: 2rem;
        height: 2rem;
        border-radius: 50%;
        background: linear-gradient(180deg, var(--brand-primary), var(--brand-primary-hover));
        color: var(--text-primary);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 0.75rem;
        font-weight: 600;
    }

    .user-avatar-lg {
        width: 2.5rem;
        height: 2.5rem;
        font-size: 0.9rem;
    }

    .user-bar-name {
        flex: 1;
        min-width: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .user-bar-chevron {
        flex-shrink: 0;
        font-size: 0.75rem;
        opacity: 0.8;
    }

    .user-context-menu {
        position: absolute;
        bottom: 100%;
        left: 0.75rem;
        right: 0.75rem;
        margin-bottom: 0.25rem;
        max-width: 256px;
        background-color: var(--surface-overlay);
        border: 1px solid var(--border-subtle);
        border-radius: var(--radius-lg);
        box-shadow: 0 -16px 48px rgba(0, 0, 0, 0.32);
        z-index: 200;
        overflow: hidden;
    }

    .user-context-menu-header {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        padding: 1rem;
        border-bottom: 1px solid var(--bg-border);
    }

    .user-context-menu-info {
        min-width: 0;
    }

    .user-context-menu-name {
        font-weight: 500;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .user-context-menu-email {
        font-size: 0.8rem;
        opacity: 0.85;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .user-context-menu-items {
        padding: 0.25rem 0;
    }

    .user-context-menu-label {
        font-size: 0.7rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: var(--text-secondary);
        padding: 0.5rem 1rem 0.25rem;
        margin-top: 0.5rem;
    }

    .user-context-menu-label:first-of-type {
        margin-top: 0;
    }

    .user-context-item {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        width: 100%;
        padding: 0.6rem 1rem;
        border: none;
        background: none;
        color: inherit;
        font-size: 0.9rem;
        text-decoration: none;
        cursor: pointer;
        text-align: left;
    }

    .user-context-item:hover {
        background: var(--bg-elevated);
    }

    .user-context-item-logout {
        color: var(--danger);
        margin-top: 0.25rem;
    }

    .user-context-item-logout:hover {
        background: rgba(224, 124, 124, 0.15);
        color: var(--danger);
    }

    .user-context-logout-form {
        width: 100%;
    }

    .user-context-logout-form .user-context-item {
        width: 100%;
    }

    /* Project selector custom styling */
    .project-dropdown-toggle {
        background-color: transparent;
        border: none;
        padding: 0.5rem 0;
        font-weight: 500;
    }

    .project-dropdown-toggle:focus {
        box-shadow: none;
    }

    .project-selector .dropdown-menu {
        border-radius: 0.5rem;
    }

    /* Position the menu below the toggle without relying on Bootstrap's Popper */
    .project-selector .dropdown-menu.show {
        display: block;
        position: absolute;
        top: 100%;
        left: 0;
        margin-top: 0.125rem;
    }
    .project-selector .dropdown-item {
        cursor: pointer;
    }

    /* Fix for active dropdown item text color */
    .project-selector .dropdown-item.active {
        color: var(--bs-body-color);
    }

    /* ─────────────────────────────────────────────────────────────────
     * APP TOPBAR (Phase 3)
     * Slim sticky top bar inside the content column. Houses the pinned
     * theme toggle, a Billing shortcut, and the user avatar — research-
     * aligned convention (top-right of the header, always visible,
     * never buried in a submenu).
     * ────────────────────────────────────────────────────────────────── */
    .app-topbar {
        position: sticky;
        top: 0;
        z-index: 50;
        background: var(--bg-base);
        border-bottom: 1px solid var(--bg-border);
        backdrop-filter: saturate(140%) blur(10px);
        -webkit-backdrop-filter: saturate(140%) blur(10px);
        transition: padding 200ms var(--ease-out), box-shadow 200ms var(--ease-out);
    }
    .app-topbar.is-scrolled {
        box-shadow: var(--shadow-sm);
    }
    .app-topbar-inner {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 10px 24px;
        gap: 16px;
    }
    .app-topbar-brand {
        display: flex;
        align-items: center;
        gap: 10px;
        min-width: 0;
    }
    .app-topbar-project {
        font-family: "Inter", inherit;
        font-size: 0.95rem;
        font-weight: 600;
        color: var(--text-primary);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        letter-spacing: -0.01em;
    }
    .app-topbar-actions {
        display: flex;
        align-items: center;
        gap: 8px;
    }
    .app-topbar-theme-btn,
    .app-topbar-billing-btn {
        appearance: none;
        background: transparent;
        border: 1px solid var(--bg-border);
        color: var(--text-secondary);
        height: 36px;
        padding: 0 12px;
        border-radius: 9px;
        cursor: pointer;
        font-size: 13px;
        font-weight: 500;
        font-family: "Inter", inherit;
        text-decoration: none;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        transition: all 150ms var(--ease-out);
        white-space: nowrap;
    }
    .app-topbar-theme-btn {
        width: 36px;
        padding: 0;
    }
    .app-topbar-theme-btn:hover,
    .app-topbar-billing-btn:hover {
        color: var(--brand);
        border-color: var(--brand-border);
        background: var(--brand-soft);
        transform: translateY(-1px);
    }
    .app-topbar-theme-btn:active,
    .app-topbar-billing-btn:active { transform: translateY(0); }

    .app-topbar-avatar {
        width: 36px;
        height: 36px;
        border-radius: 50%;
        background: var(--primary);
        color: var(--on-primary);
        font-family: "Inter", inherit;
        font-weight: 600;
        font-size: 13px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 0 0 2px var(--bg-base), 0 0 0 3px var(--brand-border);
    }

    /* ─── Profile dropdown (top-right) ─── */
    .profile-menu-wrap { position: relative; }
    .app-topbar-avatar-btn {
        appearance: none;
        background: transparent;
        border: 0;
        padding: 0;
        cursor: pointer;
        border-radius: 50%;
        display: inline-flex;
    }
    .app-topbar-avatar-btn:hover .app-topbar-avatar { background: var(--brand-hover); }
    .app-topbar-avatar-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; }
    .profile-dropdown {
        position: absolute;
        top: calc(100% + 8px);
        right: 0;
        min-width: 230px;
        background: var(--bg-surface);
        border: 1px solid var(--bg-border);
        border-radius: 10px;
        box-shadow: var(--shadow-lg);
        z-index: 1000;
        padding: 6px 0;
    }
    .profile-dropdown[hidden] { display: none; }
    .profile-dropdown a,
    .profile-dropdown button[role="menuitem"] {
        display: flex;
        align-items: center;
        gap: 10px;
        width: 100%;
        padding: 9px 16px;
        font-size: 14px;
        color: var(--text-primary);
        text-decoration: none;
        background: none;
        border: 0;
        cursor: pointer;
        text-align: left;
        font-family: "Inter", inherit;
    }
    .profile-dropdown a:hover,
    .profile-dropdown button[role="menuitem"]:hover { background: var(--bg-elevated); }
    .profile-dropdown a:focus-visible,
    .profile-dropdown button[role="menuitem"]:focus-visible {
        outline: 2px solid var(--brand);
        outline-offset: -2px;
    }
    .profile-dropdown i { font-size: 15px; color: var(--text-secondary); }
    .profile-dropdown-header {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 10px 16px 12px;
        border-bottom: 1px solid var(--bg-border);
        margin-bottom: 6px;
    }
    .profile-dropdown-id { min-width: 0; }
    .profile-dropdown-name {
        font-weight: 600;
        font-size: 13px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .profile-dropdown-email {
        font-size: 12px;
        color: var(--text-muted);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .profile-dropdown-sep { height: 1px; background: var(--bg-border); margin: 6px 0; }
    .profile-dropdown-danger,
    .profile-dropdown-danger i { color: var(--danger) !important; }
    .profile-dropdown-danger:hover { background: var(--danger-soft) !important; }


    /* Account menu v6: rounded panel, inset items, tinted icons. */
    .profile-dropdown { min-width: 296px; border-radius: 14px; padding: 6px; background: var(--solid); border-color: var(--line); }
    .profile-dropdown a, .profile-dropdown button[role="menuitem"] { border-radius: 8px; padding: 8px 10px; font-family: var(--font-body); min-height: 38px; white-space: nowrap; }
    .profile-dropdown a:hover, .profile-dropdown button[role="menuitem"]:hover { background: var(--hover); }
    .profile-dropdown-header { padding: 8px 10px 12px; margin: 0 -6px 6px; padding-left: 16px; padding-right: 16px; border-bottom-color: var(--line); }
    .profile-dropdown-sep { margin: 6px -6px; background: var(--line); }
    .profile-dropdown i { font-size: 17px; width: 18px; text-align: center; color: var(--t, var(--text-secondary)); --icon-tint: var(--t); }
    .profile-dropdown .bi-person-circle { --t: var(--tint-blue); }
    .profile-dropdown .bi-credit-card { --t: var(--tint-green); }
    .profile-dropdown .bi-chat-heart { --t: var(--tint-pink); }
    .profile-dropdown .bi-moon-stars { --t: var(--tint-violet); }
    .profile-dropdown .bi-sun { --t: var(--tint-amber); }
    .profile-dropdown .bi-volume-up-fill, .profile-dropdown .bi-volume-mute-fill { --t: var(--tint-sky); }
    .profile-dropdown .bi-speedometer2, .profile-dropdown .bi-heart-pulse, .profile-dropdown .bi-cpu { --t: var(--tint-orange); }
    .profile-dropdown-kbd { margin-left: auto; font-family: var(--font-mono); font-size: 11px; color: var(--text-secondary); background: var(--bg-elevated); border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; }
    @media (max-width: 768px) {
        .app-topbar-inner { padding: 8px 16px; }
        .app-topbar-billing-btn span { display: none; }
    }

    .ai-usage-meter { margin: 12px 10px 4px; padding: 10px 12px; border: 1px solid var(--bg-border); border-radius: 10px; font-size: 12px; background: var(--bg-surface); }
    .ai-usage-meter-head { display: flex; justify-content: space-between; align-items: center; font-weight: 600; margin-bottom: 6px; }
    .ai-usage-meter-plan { font-weight: 500; color: var(--text-secondary); }
    .ai-usage-meter-bar { height: 6px; border-radius: 999px; background: var(--bg-border); overflow: hidden; }
    .ai-usage-meter-bar span { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
    .ai-usage-meter.is-warning .ai-usage-meter-bar span { background: var(--gold); }
    .ai-usage-meter.is-exhausted .ai-usage-meter-bar span { background: var(--red-450); }
    .ai-usage-meter-foot { margin-top: 6px; color: var(--text-secondary); }
    .ai-usage-meter-foot a { color: var(--brand); font-weight: 600; text-decoration: none; }
