/* ============ TOKENS (docs/ui/foundations.md) ============ */
:root {
    --color-cyan: #7AD3F2;
    --color-cyan-deep: #3FA3D9;
    --color-orange: #FF8C3F;
    --color-red: #E04550;
    --color-green: #3FCC6E;
    --color-bg: #0A1320;
    --color-bg-deep: #050A14;
    --color-border: #1F3247;
    --color-text: #E8F4FF;
    --color-text-muted: #7A8A9F;

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 16px;
    --space-4: 24px;
    --space-5: 32px;
    --space-6: 48px;

    --font-display: "Silkscreen", monospace;
    --font-body: "VT323", monospace;

    --text-sm: clamp(15px, 0.9vw, 18px);
    --text-base: clamp(18px, 1.1vw, 22px);
    --text-lg: clamp(22px, 1.6vw, 32px);
    --text-xl: clamp(28px, 2.2vw, 48px);

    --radius: 4px;

    --kb-inset: 0px;   /* set by menu-core.js (visualViewport); consumed by .chat-input-row */

    /* Soft color variants — for data cells where the saturated greens/reds feel
       too loud. Devs reached for these inline 70+ times before they were tokens. */
    --color-green-soft: #5DD39E;
    --color-red-soft:   #E57373;
    --color-yellow:     #FFD166;
    --bg-thumbnail:     #222;   /* dark backdrop for transparent PNGs in chat/stats */

    /* Z-index scale — single source of truth for stacking. */
    --z-overlay:  100;    /* #menu, #dock fullscreen panels */
    --z-dropdown: 200;    /* .td-panel themed-dropdown popovers */
    --z-toast:    1000;   /* #toast-container slide-ins */
    --z-modal:    1100;   /* .modal-backdrop confirm dialogs */

    /* Motion scale — duration tokens for transitions. */
    --motion-fast: 80ms;
    --motion-base: 180ms;
    --motion-slow: 220ms;

    /* Glow tokens — cyan focus/active shadow used by panels, dropdowns, buttons. */
    --glow-cyan:        0 0 12px rgba(122, 211, 242, 0.35);
    --glow-cyan-strong: 0 0 16px rgba(122, 211, 242, 0.55);
}

/* ============ BASE ============ */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; touch-action: manipulation; }
body {
    margin: 0;
    background: var(--color-bg-deep);
    color: var(--color-text);
    font-family: var(--font-body);
    font-size: var(--text-base);
    -webkit-font-smoothing: none;
    image-rendering: pixelated;
}
button, .toast {
    touch-action: manipulation;   /* kill 300ms tap delay on mobile */
}
img { image-rendering: pixelated; }
canvas { image-rendering: pixelated; }
a { color: var(--color-cyan); text-decoration: none; }
a:hover { color: var(--color-cyan-deep); }

/* ============ COMPONENTS (docs/ui/components.md) ============ */

.panel {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: var(--space-3);
}

.panel-glow {
    background: var(--color-bg);
    border: 1px solid var(--color-cyan);
    border-radius: var(--radius);
    padding: var(--space-3);
    box-shadow: 0 0 16px rgba(122, 211, 242, 0.35), inset 0 0 8px rgba(122, 211, 242, 0.08);
}

.btn {
    background: var(--color-cyan);
    color: var(--color-bg-deep);
    border: 1px solid var(--color-cyan-deep);
    border-radius: var(--radius);
    padding: var(--space-2) var(--space-3);
    font-family: var(--font-display);
    font-size: var(--text-lg);
    letter-spacing: 1px;
    cursor: pointer;
    transition: background 80ms;
    min-height: 44px;             /* mobile tap target */
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn:hover { background: var(--color-cyan-deep); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-alert {
    background: var(--color-orange);
    color: var(--color-bg-deep);
    border-color: #cc6f30;
}
.btn-alert:hover { background: #cc6f30; }

/* Destructive action button — STOP on pending bubble, NO-GO on proposal replies.
   Same shape + tap-target as .btn but red, signaling "this kills something". */
.btn-danger {
    background: var(--color-red);
    color: var(--color-text);
    border: 1px solid #a83139;
    border-radius: var(--radius);
    padding: var(--space-2) var(--space-3);
    font-family: var(--font-display);
    font-size: var(--text-base);
    letter-spacing: 1px;
    cursor: pointer;
    transition: background 80ms;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn-danger:hover { background: #a83139; }
.btn-danger:disabled { opacity: 0.5; cursor: not-allowed; }

.input {
    background: var(--color-bg-deep);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    color: var(--color-text);
    padding: var(--space-2);
    font-family: var(--font-body);
    /* >=16px guards against iOS Safari auto-zoom on focus — see docs/ui/mobile.md */
    font-size: max(16px, var(--text-base));
    min-height: 44px;
    outline: none;
    transition: border-color 80ms, box-shadow 80ms;
}
.input:focus {
    border-color: var(--color-cyan);
    box-shadow: 0 0 8px rgba(122, 211, 242, 0.4);
}
.input::placeholder { color: var(--color-text-muted); }

.tab {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    font-family: var(--font-display);
    font-size: var(--text-lg);
    color: var(--color-text-muted);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    letter-spacing: 1px;
    min-height: 44px;             /* mobile tap target */
}
.tab:hover { color: var(--color-text); }
.tab.active {
    color: var(--color-cyan);
    border-color: var(--color-cyan);
    box-shadow: var(--glow-cyan);
}
.tab--compact { font-size: var(--text-base); }

.badge {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-green);
    box-shadow: 0 0 6px currentColor;
}
.badge--orange { background: var(--color-orange); }
.badge--red { background: var(--color-red); }

.bubble-them {
    background: var(--color-bg-deep);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: var(--space-2) var(--space-3);
    color: var(--color-text);
    max-width: 70%;
    align-self: flex-start;
    overflow-wrap: anywhere;   /* break long URLs / unbroken strings */
    font-size: calc(var(--text-base) + 2px);
}
.bubble-them > *:first-child { margin-top: 0; }
.bubble-them > *:last-child { margin-bottom: 0; }
.bubble-them p { margin: var(--space-2) 0; line-height: 1.4; }
.bubble-them ul, .bubble-them ol { margin: var(--space-2) 0; padding-left: var(--space-4); }
.bubble-them li { margin: 2px 0; }
.bubble-them li > p { margin: 0; }
.bubble-them strong { color: var(--color-cyan); font-weight: bold; }
.bubble-them em { color: var(--color-orange); font-style: normal; }
.bubble-them code {
    font-family: ui-monospace, "Courier New", monospace;
    background: rgba(122, 211, 242, 0.1);
    border: 1px solid var(--color-border);
    border-radius: 3px;
    padding: 0 4px;
    font-size: 0.9em;
    color: var(--color-cyan);
}
.bubble-them pre {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: var(--space-2);
    overflow-x: auto;
    margin: var(--space-2) 0;
}
.bubble-them pre code { background: none; border: none; padding: 0; color: var(--color-text); }
.bubble-them h1, .bubble-them h2, .bubble-them h3 {
    color: var(--color-cyan);
    font-family: var(--font-display);
    margin: var(--space-3) 0 var(--space-2);
    font-size: var(--text-lg);
    letter-spacing: 1px;
}
.bubble-them a { color: var(--color-cyan); text-decoration: underline; }
.bubble-them blockquote {
    border-left: 3px solid var(--color-cyan-deep);
    margin: var(--space-2) 0;
    padding-left: var(--space-2);
    color: var(--color-text-muted);
}
.bubble-them hr { border: none; border-top: 1px solid var(--color-border); margin: var(--space-2) 0; }
/* Inline image previews (Rico's sticker variants, future image-generating minions). */
/* Dark backdrop reveals transparency on cutout PNGs without needing inline styles */
/* (which DOMPurify strips on sanitize). Sized for chat-bubble scale, not native res. */
.bubble-them img {
    max-width: 240px;
    max-height: 240px;
    background: #222;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: var(--space-1);
    margin: var(--space-1) var(--space-1) var(--space-1) 0;
    vertical-align: middle;
}

.bubble-you {
    background: var(--color-cyan-deep);
    border: 1px solid var(--color-cyan);
    border-radius: var(--radius);
    padding: var(--space-2) var(--space-3);
    color: var(--color-bg-deep);
    max-width: 70%;
    align-self: flex-start;
    overflow-wrap: anywhere;
    font-size: calc(var(--text-base) + 2px);
}

/* Time marker between bubbles — iMessage-style. Shown only on a >5min gap (or
   the first message), so a cron burst that lands together shares one marker
   instead of stamping every bubble. Centered, muted, with hairlines either side. */
.chat-ts-sep {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: var(--space-3) 0 var(--space-1);
    font-family: var(--font-display, ui-monospace, monospace);
    font-size: 10px;
    letter-spacing: 1px;
    color: var(--color-text-muted);
    opacity: 0.7;
    user-select: none;
}
.chat-ts-sep::before,
.chat-ts-sep::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--color-border);
}

.key-hint {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    background: var(--color-bg);
    border: 1px solid var(--color-cyan);
    border-radius: var(--radius);
    box-shadow: var(--glow-cyan);
    font-family: var(--font-body);
    font-size: var(--text-lg);
}
.key-hint .kbd {
    display: inline-flex;
    width: 28px;
    height: 28px;
    align-items: center;
    justify-content: center;
    background: var(--color-bg-deep);
    border: 1px solid var(--color-cyan);
    border-radius: var(--radius);
    color: var(--color-cyan);
    font-family: var(--font-display);
    font-size: var(--text-base);
}

/* ============ M-MENU LAYOUT ============ */

.menu-grid {
    display: grid;
    grid-template-columns: minmax(220px, clamp(240px, 18vw, 340px)) 1fr;
    gap: var(--space-3);
    width: 100%;
    height: 100%;
    padding: var(--space-3);
    box-sizing: border-box;
}

.menu-sidebar {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    overflow-y: auto;
    min-width: 0;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}
.menu-sidebar-title {
    padding: 0 var(--space-2);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.menu-main {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    min-width: 0;
    overflow: hidden;
    padding: var(--space-3);
}

.menu-header {
    display: flex;
    gap: var(--space-3);
    align-items: stretch;
    flex-wrap: wrap;
}
.menu-header-portrait {
    width: clamp(72px, 8vw, 140px);
    height: clamp(72px, 8vw, 140px);
    object-fit: cover;
    object-position: center top;
    border: 1px solid var(--color-cyan);
    background: var(--color-bg-deep);
    flex-shrink: 0;
}
.menu-header-name {
    flex: 1 1 200px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: var(--space-1);
}
.menu-header-title-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
    min-width: 0;
}

.status-cards {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
}
.status-card {
    display: inline-flex;
    align-items: baseline;
    gap: var(--space-2);
    padding: 2px var(--space-2);
    background: var(--color-bg);
    border: 1px solid var(--color-cyan);
    border-radius: var(--radius);
    font-family: var(--font-display);
    font-size: var(--text-sm);
    letter-spacing: 0.5px;
}
.status-card-label { color: var(--color-text-muted); }
.status-card-value { color: var(--color-text); }
.status-card-value--good  { color: var(--color-green); }
.status-card-value--warn  { color: var(--color-orange); }
.status-card-value--bad   { color: var(--color-red); }
.status-card-value--muted { color: var(--color-text-muted); }

.menu-tabs {
    display: flex;
    gap: var(--space-2);
    border-bottom: 1px solid var(--color-border);
    padding-bottom: var(--space-2);
    flex-wrap: wrap;
}
/* ===== Themed dropdown (see menu-themed-dropdown.js) — replaces native <select>
   inside .menu-tabs and .subtab-row. Hidden on desktop where the .tab buttons
   show; visible on phones where the buttons hide. */
.td { position: relative; display: none; width: 100%; }
.td-trigger {
    width: 100%;
    min-height: 44px;
    background: var(--color-bg-deep);
    border: 1px solid var(--color-cyan);
    border-radius: var(--radius);
    color: var(--color-cyan);
    font-family: var(--font-display);
    font-size: var(--text-base);
    letter-spacing: 1px;
    padding: var(--space-2) var(--space-3);
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
}
.td-trigger.open { box-shadow: 0 0 8px rgba(122, 211, 242, 0.4); }
.td-arrow { font-size: 0.8em; opacity: 0.7; transition: transform 120ms; }
.td-trigger.open .td-arrow { transform: rotate(180deg); }
.td-panel {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: var(--z-dropdown);   /* above .menu-tabs, below .modal-backdrop */
    background: var(--color-bg);
    border: 1px solid var(--color-cyan);
    border-radius: var(--radius);
    box-shadow: 0 0 16px rgba(122, 211, 242, 0.35);
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--space-1);
    max-height: 60dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
/* HTML [hidden] attribute is a UA-stylesheet rule at specificity (0,1,0) — same
   as .td-panel — so without this override, the panel renders open by default
   AND can't be closed by setting panel.hidden=true. (0,2,0) wins. */
.td-panel[hidden] { display: none; }
.td-option {
    background: transparent;
    border: 1px solid transparent;
    color: var(--color-text);
    font-family: var(--font-display);
    font-size: var(--text-base);
    letter-spacing: 1px;
    text-align: left;
    padding: var(--space-2) var(--space-3);
    min-height: 44px;
    cursor: pointer;
    border-radius: var(--radius);
}
.td-option.active { color: var(--color-cyan); border-color: var(--color-cyan); }
.td-option:hover { background: rgba(122, 211, 242, 0.08); }

.subtab-row { display: flex; align-items: center; flex-wrap: wrap; }

/* .cap-grid — used by Pete's SHARED TOOLBOX (menu-pipeline-pete.js). 3-column
   grid (tool/code/when, min 180+220 = 400px) doesn't fit on phones. On desktop
   .cap-grid-row uses display:contents so its 3 children flow into the parent
   grid. On phones we collapse to a stacked card per item (see @600px below). */
.cap-grid-row { display: contents; }

/* .wide-grid-wrap — for numeric/tabular grids that need to keep their
   column alignment (Gleb's check-distribution + recent-fixes). Inner grids
   declare min-width:480px so they keep all columns at full width; this
   wrapper provides horizontal scroll on phones. Desktop is unaffected. */
.wide-grid-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* BACK button — only meaningful at ≤600px on the minion view (two-screen nav). */
.menu-back { display: none; }

.menu-body {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    min-height: 0;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.menu-esc {
    align-self: flex-start;
    flex-shrink: 0;
    margin-left: var(--space-2);
}
.menu-header-row {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    width: 100%;
}

.roster-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    text-align: left;
    cursor: pointer;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: var(--space-3);
    color: var(--color-text);
    font-family: var(--font-body);
    font-size: var(--text-base);
}
.roster-row.active { border-color: var(--color-cyan); box-shadow: 0 0 8px rgba(122,211,242,.3); }
.roster-row.locked { opacity: 0.4; cursor: not-allowed; }
.roster-row-portrait {
    width: 60px; height: 60px;
    object-fit: cover; object-position: center top;
    border: 1px solid var(--color-border);
    background: var(--color-bg-deep);
    flex-shrink: 0;
}
.roster-row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.roster-row-top { display: flex; align-items: baseline; gap: var(--space-2); min-width: 0; }
.roster-row-name { color: var(--color-text); font-size: var(--text-base); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.roster-row-role { color: var(--color-text-muted); font-family: var(--font-display); font-size: calc(var(--text-sm) - 2px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.roster-row-time { font-family: var(--font-body); flex-shrink: 0; color: var(--color-text-muted); }

.chat-log {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-2);
    min-height: 0;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}
.chat-input-row {
    display: flex;
    gap: var(--space-2);
    align-items: stretch;
    padding-bottom: max(var(--space-1), env(safe-area-inset-bottom));
}
.chat-input-row .input { flex: 1; min-width: 0; }

/* Small viewports: stack header + collapse sidebar */
@media (max-width: 960px) {
    .menu-grid { grid-template-columns: 200px 1fr; padding: var(--space-2); gap: var(--space-2); }
    .menu-main { padding: var(--space-2); }
    .menu-header { gap: var(--space-2); }
}

/* Phones: Slack-style two-screen nav — roster OR minion, never both.
   .menu-grid[data-mobile-view] gates which child renders. */
@media (max-width: 600px) {
    .menu-grid {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr;        /* single visible child fills */
        padding-bottom: max(var(--space-2), env(safe-area-inset-bottom));
    }
    .menu-grid[data-mobile-view="roster"] .menu-main { display: none; }
    .menu-grid[data-mobile-view="minion"] .menu-sidebar { display: none; }
    .menu-sidebar { max-height: none; }      /* roster is full screen when shown */
    .menu-main { min-height: 0; }
    .roster-row { padding: var(--space-3); } /* bigger taps now that roster owns the screen */

    /* BACK button appears in the compact header on the minion screen. */
    .menu-back { display: inline-flex; }

    /* Compact header on phones — hide the bordered status pills so name +
       portrait + BACK + ESC fit a single row. Full status still lives in
       the STATS tab. */
    .menu-header { flex-wrap: nowrap; align-items: center; gap: var(--space-2); }
    .menu-header-portrait { width: 40px; height: 40px; }
    .menu-header-title-row .status-cards { display: none; }
    .menu-esc { margin-left: auto; align-self: center; }

    /* Long display names wrap into ESC and overlap.
       Truncate with ellipsis instead — name+role both single line, smaller font. */
    .menu-header-name { flex: 1 1 0; min-width: 0; }
    .menu-header-title-row > .display:first-child {
        font-size: var(--text-lg);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .menu-header-name > .display.muted {
        font-size: var(--text-sm);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Text-size tokens already floor at mobile-readable values via the clamp()
       definitions at :root — no per-breakpoint override needed. See foundations.md. */
    .bubble-them, .bubble-you { max-width: 88%; }
    .bubble-them p { line-height: 1.5; }

    /* Swap tab buttons for themed dropdown — 7 tabs wrap to 3+ rows on a 390px viewport.
       Same swap for inner subtab rows (chat Active/History, stats DAILY/KEYWORDS/...). */
    .menu-tabs { padding-bottom: 0; border-bottom: none; }
    .menu-tabs > .tab { display: none; }
    .subtab-row > .tab { display: none; }
    .td { display: block; }

    /* Lift the chat input only when an input is actually focused — body.kb-open
       is set by the visualViewport handler in menu-core.js. Without this gate
       the iOS address-bar gap (~113px) is mistaken for a keyboard at page load. */
    body.kb-open .chat-input-row {
        transform: translateY(calc(-1 * var(--kb-inset, 0px)));
        transition: transform 120ms ease-out;
    }

    /* Pete's SHARED TOOLBOX: stack each capability as a card on phones.
       The desktop 3-column grid (tool/code/when, 400px min) overflows the
       357px chat panel and clips text. */
    .cap-grid {
        display: block !important;
        grid-template-columns: none !important;
    }
    .cap-grid-h { display: none; }
    .cap-grid-row {
        display: block;
        padding: var(--space-2);
        margin-bottom: var(--space-2);
        border: 1px solid var(--color-border);
        border-radius: var(--radius);
        background: var(--color-bg-deep);
    }
    .cap-grid-row > div:nth-child(1) { color: var(--color-text); margin-bottom: 2px; }
    .cap-grid-row > div:nth-child(2) { font-size: var(--text-sm); margin-bottom: 4px; }
    .cap-grid-row > div:nth-child(3) { font-size: var(--text-sm); color: var(--color-text-muted); }
}

/* ============ DISPLAY UTILITIES ============ */
.display { font-family: var(--font-display); letter-spacing: 1px; }
.muted { color: var(--color-text-muted); }
.cyan { color: var(--color-cyan); }
.orange { color: var(--color-orange); }
.red { color: var(--color-red); }
.green { color: var(--color-green); }
.text-sm { font-size: var(--text-sm); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }

/* ============ STUDIO SCROLLBAR — GLOBAL ============
   Studio is a self-contained app, theme applies to every scrollbar. Default
   browser scrollbars (Windows native, light gray, fat) clash with the dark
   navy + cyan aesthetic. Target html + every descendant via universal
   selector so we don't have to remember to add a class on every container.
*/
html, body, * {
    scrollbar-width: thin;
    scrollbar-color: rgba(122, 211, 242, 0.35) rgba(10, 18, 33, 0.5);
}
*::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
*::-webkit-scrollbar-track {
    background: rgba(10, 18, 33, 0.5);
    border-radius: 4px;
}
*::-webkit-scrollbar-thumb {
    background: rgba(122, 211, 242, 0.35);
    border-radius: 4px;
    border: 1px solid rgba(10, 18, 33, 0.6);
}
*::-webkit-scrollbar-thumb:hover {
    background: rgba(122, 211, 242, 0.6);
}
*::-webkit-scrollbar-corner {
    background: transparent;
}
/* ============ DATA TABLE (grid-based, sticky header, ellipsis cells) ============
   Use with: .data-grid for the container, .data-grid-header for the sticky
   header row (set grid-template-columns inline), .data-grid-row for each data
   row (matches header columns).
*/
.data-grid {
    display: flex;
    flex-direction: column;
    gap: 1px;
}
.data-grid-header,
.data-grid-row {
    display: grid;
    align-items: baseline;
    gap: var(--space-3);
    padding: var(--space-1) var(--space-2);
}
.data-grid-header {
    position: sticky;
    top: 0;
    z-index: 1;
    background: rgba(10, 18, 33, 0.95);
    border-bottom: 1px solid var(--color-cyan-deep);
    color: var(--color-text-muted);
    font-family: var(--font-display);
    font-size: var(--text-sm);
    letter-spacing: 0.5px;
    text-transform: uppercase;
    padding-bottom: var(--space-2);
}
.data-grid-row {
    border-bottom: 1px solid rgba(122, 211, 242, 0.06);
    font-size: var(--text-sm);
    font-family: var(--font-body);
}
.data-grid-row:hover {
    background: rgba(122, 211, 242, 0.04);
}
.data-grid-cell-ellipsis {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}
/* Clickable cell content inside a .data-grid-row — transparent button that
   reads as cyan text with an underline on hover. Used for drill-down cells
   (open a modal viewer when clicked). */
.data-grid-cell-link {
    background: transparent;
    border: 0;
    padding: 0;
    margin: 0;
    color: var(--color-cyan);
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.data-grid-cell-link:hover { text-decoration: underline; }
.data-grid-cell-link:disabled {
    color: var(--color-text-muted);
    cursor: not-allowed;
    text-decoration: none;
}

/* ============ DOCK (B key — studio-wide overlay) ============ */
.dock-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-3);
    height: 100%;
    padding: var(--space-3);
    box-sizing: border-box;
}
.dock-main {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    min-width: 0;
    overflow: hidden;
    padding: var(--space-3);
}
.dock-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
}

/* ============ UPLOAD primitives (Mailbox) ============ */
.upload-zone {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-3);
    border: 1px dashed var(--color-cyan-deep);
    border-radius: var(--radius);
    background: rgba(122, 211, 242, 0.03);
}
.upload-row {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
    align-items: center;
}
.upload-row > .input,
.upload-row > select.input { flex: 1; min-width: 160px; }
.upload-progress {
    width: 100%;
    height: 10px;
    background: var(--color-bg-deep);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
}
.upload-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--color-cyan);
    transition: width 200ms;
}
.upload-progress.stalled { border-color: var(--color-red); }
.upload-progress.stalled .upload-progress-fill { background: var(--color-red); }
.upload-progress.done .upload-progress-fill { background: var(--color-green); }
.upload-status {
    font-family: var(--font-body);
    font-size: var(--text-sm);
    color: var(--color-text-muted);
}
.upload-status.error { color: var(--color-red); }
.upload-status.success { color: var(--color-green); }

/* Drag-and-drop affordance on the .upload-zone — `.dragover` is toggled by JS
   on dragover/dragleave so VAs see the drop target light up. */
.upload-zone.dragover {
    border-color: var(--color-cyan);
    background: rgba(122, 211, 242, 0.08);
    box-shadow: inset 0 0 12px rgba(122, 211, 242, 0.18);
}

/* ============ FILE PICKER component ============
   Wraps a hidden <input type=file> in a <label> with a styled trigger button
   + filename readout. Click anywhere on the label opens the native picker.
   JS listens to the input's `change` event to update the filename span. */
.file-picker {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
    cursor: pointer;
}
.file-picker > input[type="file"] {
    /* Visually-hidden but still keyboard-focusable + click-targeted via label. */
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
.file-picker-trigger {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    color: var(--color-cyan);
    border: 1px solid var(--color-cyan-deep);
    border-radius: var(--radius);
    padding: var(--space-2) var(--space-3);
    font-family: var(--font-display);
    font-size: var(--text-base);
    letter-spacing: 1px;
    min-height: 44px;
    transition: background 80ms;
}
.file-picker:hover .file-picker-trigger,
.file-picker > input[type="file"]:focus + .file-picker-trigger {
    background: rgba(122, 211, 242, 0.12);
}
.file-picker-filename {
    flex: 1;
    min-width: 0;
    color: var(--color-text);
    font-family: var(--font-body);
    font-size: var(--text-base);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.file-picker-filename.empty {
    color: var(--color-text-muted);
    font-style: italic;
}

/* ============ PAGINATION CONTROLS ============ */
.pager {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-2);
    padding: var(--space-2);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    color: var(--color-text-muted);
}
.pager-btn {
    background: transparent;
    border: 1px solid var(--color-cyan-deep);
    color: var(--color-cyan);
    border-radius: var(--radius);
    padding: 10px 14px;
    min-height: 44px;
    cursor: pointer;
    font-family: var(--font-display);
    font-size: var(--text-sm);
    letter-spacing: 1px;
}
.pager-btn:hover:not(:disabled) {
    background: rgba(122, 211, 242, 0.1);
}
.pager-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}
.pager-info {
    font-family: var(--font-display);
    color: var(--color-text-muted);
}

/* ============ MESSAGING POLISH (docs/ui/components.md + §6) ============
   Live status + notification surfaces for the M-menu chat:
   - .badge--working    pulsing orange dot, roster row, minion mid-spawn
   - .badge-count       small numeric pill on roster rows / M-button bell
   - .bubble-you.failed red border + tap-to-retry on dropped /api/chat sends
   - .typing-dots       animated three-dot bounce inside the pending bubble
   - #toast-container   top-right slide-in notification stack
   - .m-button--alert   M HUD button pulse when bell count > 0
*/

@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 4px currentColor; opacity: 0.75; }
    50%      { box-shadow: 0 0 14px currentColor; opacity: 1; }
}

@keyframes typing-bounce {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30%           { opacity: 1;   transform: translateY(-3px); }
}

.badge--working {
    background: var(--color-orange);
    animation: pulse-glow 1.2s ease-in-out infinite;
}

.badge--unread {
    background: var(--color-cyan);
    box-shadow: 0 0 10px var(--color-cyan), 0 0 4px var(--color-cyan);
}

.badge-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    margin-left: var(--space-1);
    border-radius: 9px;
    background: var(--color-orange);
    color: var(--color-bg-deep);
    font-family: var(--font-display);
    font-size: 11px;
    letter-spacing: 0;
    vertical-align: middle;
}

.bubble-you.failed {
    border-color: var(--color-red);
    box-shadow: 0 0 8px rgba(224, 69, 80, 0.4);
    cursor: pointer;
}
.bubble-you.failed::after {
    content: " ↻ tap to retry";
    color: var(--color-red);
    font-size: var(--text-sm);
    font-family: var(--font-display);
    letter-spacing: 1px;
    margin-left: var(--space-2);
}

/* Pending bubble layout — typing dots, name, STOP button, optional journal tail.
   STOP is right-aligned so it's reachable without scrolling on phones. */
#pending-bubble .pending-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}
#pending-bubble .pending-stop {
    margin-left: auto;
    padding: 4px var(--space-2);
    min-height: 32px;
    font-size: var(--text-sm);
}
/* Live progress lines from today's journal — italic + muted so they don't
   compete with the eventual real reply. Cap height so a long-running task
   doesn't push the input off-screen. */
.pending-journal {
    margin-top: var(--space-2);
    padding: var(--space-1) var(--space-2);
    border-left: 2px solid var(--color-cyan-deep);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    color: var(--color-text-muted);
    font-style: italic;
    max-height: 120px;
    overflow-y: auto;
}
.pending-journal > div {
    line-height: 1.35;
    margin: 2px 0;
}

/* Live working panel — the rolling window of tool calls the minion is firing
   right now (Read / Bash / Edit …), streamed from the backend stream-json tail.
   Monospace + a left rail so it reads like a live activity log, distinct from
   the italic journal milestones below it. Collapses with the pending bubble
   when the final reply lands. */
.pending-tools {
    margin-top: var(--space-2);
    padding: var(--space-1) var(--space-2);
    border-left: 2px solid var(--color-cyan);
    font-family: ui-monospace, "Courier New", monospace;
    font-size: var(--text-sm);
    color: var(--color-cyan);
    max-height: 132px;
    overflow-y: auto;
}
.pending-tools .pending-tool-line {
    line-height: 1.4;
    margin: 1px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.85;
}
/* Freshest call is the last child — nudge it brighter so the eye lands there. */
.pending-tools .pending-tool-line:last-child {
    opacity: 1;
    font-weight: 600;
}

/* Inline GO / NO-GO action row injected after a minion's "Type GO" proposal.
   Two big tap-targets, side-by-side. Lives at the bottom of the bubble. */
.go-actions {
    display: flex;
    gap: var(--space-2);
    margin-top: var(--space-2);
    padding-top: var(--space-2);
    border-top: 1px dashed var(--color-border);
}
.go-actions .btn,
.go-actions .btn-danger {
    flex: 1;
    font-size: var(--text-base);
    min-height: 40px;
    padding: var(--space-1) var(--space-2);
}

/* Snippet line under chat history rows when a body-search hits. The matched
   substring is wrapped in <mark> client-side; we re-skin it cyan-on-dark to
   match the studio palette (browser default mark is yellow-on-yellow). */
.chat-snippet {
    color: var(--color-text-muted);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    font-style: italic;
    line-height: 1.35;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-snippet mark {
    background: rgba(122, 211, 242, 0.18);
    color: var(--color-cyan);
    padding: 0 2px;
    border-radius: 2px;
}

.typing-dots { display: inline-flex; gap: 4px; vertical-align: middle; }
.typing-dots span {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-text-muted);
    animation: typing-bounce 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.30s; }

#toast-container {
    position: fixed;
    top: max(var(--space-3), env(safe-area-inset-top));
    right: max(var(--space-3), env(safe-area-inset-right));
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    z-index: var(--z-toast);
    pointer-events: none;
}
.toast {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    background: var(--color-bg);
    border: 1px solid var(--color-cyan);
    border-radius: var(--radius);
    box-shadow: var(--glow-cyan);
    color: var(--color-text);
    font-family: var(--font-body);
    pointer-events: auto;
    cursor: pointer;
    transform: translateX(120%);
    opacity: 0;
    transition: transform 220ms ease-out, opacity 220ms ease-out;
    max-width: 320px;
}
.toast.show { transform: translateX(0); opacity: 1; }
.toast img {
    width: 36px;
    height: 36px;
    object-fit: cover;
    object-position: center top;
    border: 1px solid var(--color-border);
    flex-shrink: 0;
}
.toast-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.toast-name { color: var(--color-cyan); font-family: var(--font-display); letter-spacing: 1px; font-size: var(--text-base); }
.toast-msg { color: var(--color-text-muted); font-size: var(--text-sm); }

.m-button--alert { animation: pulse-glow 1.2s ease-in-out infinite; }

/* ============ SPEECH BUBBLES (docs/ui/components.md § Notifications) ============
   RCT-style ambient pixel-art bubbles that pop up over minion sprites in the
   lobby when activity events fire. Positioned via JS (public/speech-bubbles.js)
   which converts the minion's world coords -> screen coords each frame using
   the existing Lobby.update() loop. See patterns.md once added for usage. */
#speech-bubbles-container {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 10; /* above canvas, below overlays (--z-overlay: 100) */
    overflow: hidden;
}
.speech-bubble {
    position: absolute;
    background: var(--color-bg);
    border: 1px solid var(--color-cyan);
    border-radius: var(--radius);
    padding: 6px 10px;
    color: var(--color-text);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    box-shadow: var(--glow-cyan);
    pointer-events: auto; /* clickable */
    cursor: pointer;
    white-space: nowrap;
    max-width: 280px;
    transform-origin: center bottom;
    transform: translate(-50%, -100%) scale(0);
    animation: speech-bubble-pop 220ms cubic-bezier(0.34, 1.6, 0.64, 1) forwards;
    display: flex;
    align-items: center;
    gap: 6px;
}
.speech-bubble.fading {
    animation: speech-bubble-fade 320ms ease-in forwards;
}
.speech-bubble::after {
    content: '';
    position: absolute;
    bottom: -7px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 7px solid var(--color-cyan);
}
.speech-bubble::before {
    content: '';
    position: absolute;
    bottom: -5px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid var(--color-bg);
    z-index: 1;
}
.speech-bubble img.speech-bubble-icon {
    width: 16px;
    height: 16px;
    image-rendering: pixelated;
    flex-shrink: 0;
}
.speech-bubble-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 240px;
}
/* Severity modifiers — match status-pill colors */
.speech-bubble--success { border-color: var(--color-green-soft); box-shadow: 0 0 12px rgba(93, 211, 158, 0.35); }
.speech-bubble--success::after { border-top-color: var(--color-green-soft); }
.speech-bubble--warn    { border-color: var(--color-orange); box-shadow: 0 0 12px rgba(255, 140, 63, 0.35); }
.speech-bubble--warn::after    { border-top-color: var(--color-orange); }
.speech-bubble--error   { border-color: var(--color-red-soft); box-shadow: 0 0 12px rgba(229, 115, 115, 0.4); }
.speech-bubble--error::after   { border-top-color: var(--color-red-soft); }
/* Thinking stage — italic dots, no icon, muted tone */
.speech-bubble--thinking {
    border-color: var(--color-text-muted);
    box-shadow: none;
    font-style: italic;
    color: var(--color-text-muted);
}
.speech-bubble--thinking::after { border-top-color: var(--color-text-muted); }
.speech-bubble--thinking::before { border-top-color: var(--color-bg); }
/* The "!" pop above the sprite that fires JUST before a resolved bubble */
.speech-bubble-pop {
    position: absolute;
    color: var(--color-cyan);
    font-family: var(--font-display);
    font-size: var(--text-lg);
    font-weight: bold;
    pointer-events: none;
    transform: translate(-50%, -100%) scale(0);
    animation: speech-bubble-pop-bang 420ms ease-out forwards;
    text-shadow: 0 0 8px var(--color-cyan);
}
.speech-bubble-pop--warn { color: var(--color-orange); text-shadow: 0 0 8px var(--color-orange); }
.speech-bubble-pop--error { color: var(--color-red-soft); text-shadow: 0 0 8px var(--color-red-soft); }
.speech-bubble-pop--success { color: var(--color-green-soft); text-shadow: 0 0 8px var(--color-green-soft); }

@keyframes speech-bubble-pop {
    0%   { transform: translate(-50%, -100%) scale(0); opacity: 0; }
    60%  { transform: translate(-50%, -100%) scale(1.1); opacity: 1; }
    100% { transform: translate(-50%, -100%) scale(1); opacity: 1; }
}
@keyframes speech-bubble-fade {
    0%   { transform: translate(-50%, -100%) scale(1); opacity: 1; }
    100% { transform: translate(-50%, -110%) scale(0.95); opacity: 0; }
}
@keyframes speech-bubble-pop-bang {
    0%   { transform: translate(-50%, -100%) scale(0); opacity: 0; }
    30%  { transform: translate(-50%, -120%) scale(1.3); opacity: 1; }
    100% { transform: translate(-50%, -160%) scale(1); opacity: 0; }
}

/* ============ SFX-PLAYER (docs/ui/components.md) ============
   Inline audio player that replaces native <audio controls> wherever it
   shows up — chat bubbles (Echo's SFX variants) and stats panels. Native
   controls clash with the pixel-art look; this is a flat-themed skin over
   the same HTMLAudioElement API. Upgrade is one-shot per element, idempotent
   via [data-sfx-upgraded]. See public/sfx-player.js for the JS. */
.sfx-player {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-1) var(--space-2);
    background: var(--color-bg-deep);
    border: 1px solid var(--color-cyan-deep);
    border-radius: var(--radius);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    color: var(--color-text);
    margin: var(--space-1) 0;
    min-width: 240px;
    max-width: 360px;
    box-sizing: border-box;
    vertical-align: middle;
}
.sfx-player__btn {
    flex: 0 0 44px;
    height: 44px;
    background: transparent;
    color: var(--color-cyan);
    border: 1px solid var(--color-cyan-deep);
    border-radius: var(--radius);
    font-family: var(--font-display);
    font-size: 13px;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    transition: background 80ms, color 80ms;
}
.sfx-player__btn:hover { background: rgba(122, 211, 242, 0.12); }
.sfx-player.is-playing .sfx-player__btn { color: var(--color-orange); border-color: var(--color-orange); }
.sfx-player.is-playing .sfx-player__btn:hover { background: rgba(255, 140, 63, 0.12); }
.sfx-player__bar {
    flex: 1;
    height: 6px;
    background: var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    position: relative;
    min-width: 60px;
}
.sfx-player__bar-fill {
    height: 100%;
    background: var(--color-cyan);
    width: 0%;
    transition: width 80ms linear;
}
.sfx-player.is-playing .sfx-player__bar-fill { background: var(--color-orange); }
.sfx-player__time {
    flex: 0 0 auto;
    color: var(--color-text-muted);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    min-width: 64px;
    text-align: right;
    letter-spacing: 0;
}
.sfx-player.has-error {
    border-color: var(--color-red);
}
.sfx-player.has-error .sfx-player__time { color: var(--color-red); }

/* Modal overlay (confirm/alert in our theme — replaces native window.confirm) */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);  /* above #menu (z-overlay) and #toast-container (z-toast) */
    background: rgba(5, 10, 20, 0.82);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 180ms ease-out;
}
.modal-backdrop.show { opacity: 1; }
.modal-card {
    position: relative;  /* containing block for .modal-card-close */
    min-width: 320px;
    max-width: 480px;
    max-height: 85dvh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    transform: translateY(8px);
    transition: transform 220ms ease-out;
}
.modal-backdrop.show .modal-card { transform: translateY(0); }
.modal-title { letter-spacing: 1px; }
.modal-msg { color: var(--color-text); font-size: var(--text-base); line-height: 1.4; }
.modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-2);
}
/* Canonical close affordance for form modals — top-right X. See docs/ui/patterns.md §9. */
.modal-card-close {
    position: absolute;
    top: var(--space-2);
    right: var(--space-2);
    min-height: 32px;
    min-width: 32px;
    padding: 0 10px;
    font-size: var(--text-base);
    line-height: 1;
    z-index: 1;
}

/* ============ BROADCAST tab (fan out one msg to N minions) ============ */
.broadcast-wrap {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    height: 100%;
    min-height: 0;
}
.broadcast-compose {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}
.broadcast-text {
    width: 100%;
    resize: vertical;
    min-height: 60px;
    font-family: var(--font-body);
}
.broadcast-roster {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
}
.broadcast-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px var(--space-2) 4px 4px;
    background: var(--color-bg-deep);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    color: var(--color-text);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    cursor: pointer;
    min-height: 36px;
    transition: border-color 80ms, background 80ms;
}
.broadcast-chip:hover { border-color: var(--color-cyan-deep); }
.broadcast-chip.selected {
    border-color: var(--color-cyan);
    background: rgba(122, 211, 242, 0.10);
    box-shadow: 0 0 6px rgba(122, 211, 242, 0.25);
}
.broadcast-chip input[type="checkbox"] {
    accent-color: var(--color-cyan);
    margin: 0;
    cursor: pointer;
}
.broadcast-portrait {
    width: 28px;
    height: 28px;
    object-fit: cover;
    object-position: center top;
    border: 1px solid var(--color-border);
    background: var(--color-bg);
    flex-shrink: 0;
    image-rendering: pixelated;
}
.broadcast-chip-name {
    color: var(--color-text);
    font-family: var(--font-display);
    font-size: var(--text-sm);
    letter-spacing: 1px;
}
.broadcast-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
}
.broadcast-actions .tab {
    min-height: 36px;
    font-size: var(--text-sm);
}

.broadcast-inbox {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    flex: 1;
    min-height: 0;
}
.broadcast-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    padding: 0 var(--space-1);
}

.broadcast-card {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: var(--space-2);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}
.broadcast-card-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-2);
    padding: var(--space-1) var(--space-2);
    border-bottom: 1px solid var(--color-border);
}
.broadcast-card-msg {
    color: var(--color-cyan);
    font-family: var(--font-display);
    font-size: var(--text-base);
    letter-spacing: 1px;
    overflow-wrap: anywhere;
}
.broadcast-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: var(--space-2);
}
.broadcast-col {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    background: var(--color-bg-deep);
    border: 1px solid var(--color-cyan-deep);
    border-radius: var(--radius);
    padding: var(--space-2);
    color: var(--color-text);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    text-align: left;
    cursor: pointer;
    min-height: 100px;
    max-height: 240px;
    overflow: hidden;
    transition: border-color 80ms, box-shadow 80ms;
}
.broadcast-col:hover {
    border-color: var(--color-cyan);
    box-shadow: 0 0 8px rgba(122, 211, 242, 0.3);
}
.broadcast-col-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding-bottom: var(--space-1);
    border-bottom: 1px solid var(--color-border);
}
.broadcast-col-portrait {
    width: 24px;
    height: 24px;
    object-fit: cover;
    object-position: center top;
    border: 1px solid var(--color-border);
    background: var(--color-bg);
    flex-shrink: 0;
    image-rendering: pixelated;
}
.broadcast-col-name {
    color: var(--color-cyan);
    font-family: var(--font-display);
    font-size: var(--text-sm);
    letter-spacing: 1px;
}
.broadcast-col-body {
    flex: 1;
    overflow-y: auto;
    overflow-wrap: anywhere;
    line-height: 1.35;
}
.broadcast-col-body p { margin: var(--space-1) 0; }
.broadcast-col-body strong { color: var(--color-cyan); }
.broadcast-col-body em { color: var(--color-orange); font-style: normal; }
.broadcast-col-body pre, .broadcast-col-body code {
    font-family: ui-monospace, "Courier New", monospace;
    font-size: 12px;
}
.broadcast-col-pending,
.broadcast-col-empty {
    color: var(--color-text-muted);
    font-style: italic;
    padding: var(--space-2);
}

/* Phones: single-column reply grid */
@media (max-width: 600px) {
    .broadcast-card-grid { grid-template-columns: 1fr; }
    .broadcast-col { max-height: 200px; }
}

/* ============================================================
   PATTERNS (docs/ui/patterns.md) — compositions of components + tokens
   that solve recurring UX problems. Reach for these BEFORE
   inventing a bespoke markup block.
   ============================================================ */

/* Empty / Loading state — muted centered message inside a section body.
   Replaces 16+ inline `<div style="padding:var(--space-3);color:#7A8A9F">loading…</div>` blocks. */
.empty-state {
    padding: var(--space-3);
    color: var(--color-text-muted);
    font-family: var(--font-body);
    font-size: var(--text-base);
    font-style: italic;
    text-align: center;
}
.empty-state--lg { padding: var(--space-5) var(--space-3); }
.empty-state .empty-state-title {
    display: block;
    color: var(--color-text);
    font-family: var(--font-display);
    font-size: var(--text-lg);
    letter-spacing: 1px;
    font-style: normal;
    margin-bottom: var(--space-2);
}

/* Status pill — soft-colored inline chip for "active / failed / idle / warn".
   Replaces 60+ inline `style="color:#5dd39e"` patterns scattered across stats files. */
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 1px var(--space-2);
    border-radius: 10px;
    font-family: var(--font-display);
    font-size: var(--text-sm);
    letter-spacing: 0.5px;
    border: 1px solid currentColor;
    background: transparent;
    line-height: 1.4;
}
.status-pill--active { color: var(--color-green-soft); }
.status-pill--failed { color: var(--color-red-soft); }
.status-pill--warn   { color: var(--color-orange); }
.status-pill--idle   { color: var(--color-text-muted); }
.status-pill--info   { color: var(--color-cyan); }

/* Stat KV — label + colored value pair. Tight, inline-flex.
   Replaces 31+ ad-hoc `_statsKv()` markup blocks. */
.stat-kv {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    font-family: var(--font-body);
    font-size: var(--text-sm);
}
.stat-kv .stat-kv-label {
    color: var(--color-text-muted);
    font-family: var(--font-display);
    letter-spacing: 0.5px;
    text-transform: uppercase;
    font-size: var(--text-sm);
}
.stat-kv .stat-kv-value {
    color: var(--color-text);
    font-family: var(--font-display);
    font-size: var(--text-base);
    letter-spacing: 0.5px;
}
.stat-kv .stat-kv-value--good { color: var(--color-green-soft); }
.stat-kv .stat-kv-value--bad  { color: var(--color-red-soft); }
.stat-kv .stat-kv-value--warn { color: var(--color-orange); }
.stat-kv .stat-kv-value--info { color: var(--color-cyan); }
.stat-kv .stat-kv-value--muted { color: var(--color-text-muted); }

/* Headline KV row — flex-wrap strip of stat-kv items, used at the top of a
   stats panel. Replaces 134+ inline flex declarations. */
.headline-kv-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    align-items: baseline;
    padding: var(--space-1) 0;
    font-family: var(--font-body);
    font-size: var(--text-base);
}

/* Filter chip — selected vs muted toggle. Replaces three different hand-rolled
   implementations in menu-stats-cassie / danny / vinny. */
.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px var(--space-2);
    background: transparent;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    color: var(--color-text-muted);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    cursor: pointer;
    min-height: 32px;
    letter-spacing: 0.5px;
    transition: border-color var(--motion-fast), background var(--motion-fast), color var(--motion-fast);
}
.filter-chip:hover { color: var(--color-text); border-color: var(--color-cyan-deep); }
.filter-chip.active {
    background: var(--color-cyan);
    color: var(--color-bg-deep);
    border-color: var(--color-cyan);
}

/* Alert box — inline left-border + tinted bg, severity-colored. Replaces the
   Gleb/Mike/Cassie variants of "inline notice with a colored stripe". */
.alert-box {
    display: flex;
    align-items: flex-start;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius);
    border-left: 4px solid var(--color-cyan-deep);
    background: rgba(122, 211, 242, 0.06);
    color: var(--color-text);
    font-family: var(--font-body);
    font-size: var(--text-base);
    line-height: 1.4;
}
.alert-box--warn  { border-left-color: var(--color-orange); background: rgba(255, 140, 63, 0.10); }
.alert-box--error { border-left-color: var(--color-red);    background: rgba(224, 69, 80, 0.10); color: var(--color-red-soft); }
.alert-box--info  { border-left-color: var(--color-cyan);   background: rgba(122, 211, 242, 0.08); }
.alert-box--muted { border-left-color: var(--color-text-muted); background: rgba(122, 138, 159, 0.08); color: var(--color-text-muted); }
.alert-box-title {
    display: block;
    font-family: var(--font-display);
    font-size: var(--text-base);
    letter-spacing: 1px;
    color: currentColor;
    margin-bottom: 2px;
}

/* Thumbnail — bordered square with dark backdrop for transparent PNG previews.
   Used by Rico's sticker variants + Cassie's image previews. Replaces inline
   `style="background:#222;..."`. */
.thumbnail {
    display: inline-block;
    background: var(--bg-thumbnail);
    border: 1px solid var(--color-cyan-deep);
    border-radius: var(--radius);
    object-fit: cover;
    image-rendering: pixelated;
    vertical-align: middle;
}
.thumbnail--sm { width: 64px;  height: 64px;  padding: 2px; }
.thumbnail--md { width: 120px; height: 120px; padding: var(--space-1); }
.thumbnail--lg { width: 180px; height: 180px; padding: var(--space-1); }
.thumbnail--muted { border-color: var(--color-border); }

/* Stats section — a titled block inside a stats page body. Used by the
   _statsSection() helper in menu-stats.js. Composed inside .minion-page-body. */
.stats-section { margin-bottom: var(--space-4); }
.stats-section-title {
    margin-bottom: var(--space-2);
    padding-bottom: var(--space-1);
    border-bottom: 1px solid rgba(122, 211, 242, 0.25);
}

/* ============================================================
   TEMPLATES (docs/ui/patterns.md#templates) — page-level scaffolding. One template
   covers stats pages, pipeline pages, and any future "look at
   one minion" view. Compose patterns + components inside it.
   ============================================================ */

/* The container — fills its parent (.menu-body), scrolls vertically, applies
   the consistent inner padding + gap rhythm so every minion page reads the same. */
.minion-page {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    min-height: 0;
    width: 100%;
}

/* Header — title + fetchTime + optional badges. Composes flex utilities;
   keep it to one line on desktop. Wraps on narrow viewports. */
.minion-page-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-3);
    flex-wrap: wrap;
}
.minion-page-header .minion-page-title {
    color: var(--color-cyan);
    font-family: var(--font-display);
    font-size: var(--text-lg);
    letter-spacing: 1px;
}
.minion-page-header .minion-page-subtitle {
    color: var(--color-text-muted);
    font-family: var(--font-body);
    font-size: var(--text-sm);
}

/* Alerts slot — stack of .alert-box items at the top of the page body.
   Hidden when empty (use [hidden] on the container). */
.minion-page-alerts {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}
.minion-page-alerts:empty { display: none; }

/* Tabs slot — composes the existing .menu-tabs / .subtab-row + .td dropdown.
   Mobile swap is already wired by those classes. Optional — omit if 1 tab. */
.minion-page-tabs {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

/* Body — scrollable region that holds either loading/empty/error state OR
   a stack of .minion-page-section blocks. */
.minion-page-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* Section — composes .panel + adds top/bottom spacing inside the body.
   The same class is referenced by _statsPanel() for backward compat. */
.minion-page-section {
    padding: var(--space-3);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

/* Pager — pagination row at the bottom of a section. Composes .pager. */
.minion-page-pager {
    margin-top: var(--space-2);
}

/* Phones: stat-kv items wrap onto two lines (label above value) inside a tight column. */
@media (max-width: 600px) {
    .headline-kv-row { gap: var(--space-2); }
    .alert-box { font-size: var(--text-base); }
}

/* ============================================================
   MULTIPLAYER — sprite picker + section dividers
   Reused by the login guest panel + admin Add-Dev modal +
   roster sidebar (HUMANS/MINIONS dividers).
   ============================================================ */

.sprite-option {
    position: relative;
    display: block;
    width: 64px;
    height: 64px;
    background: var(--color-bg);
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    overflow: hidden;
    transition: border-color 80ms, box-shadow 80ms;
}
.sprite-option:hover {
    border-color: var(--color-cyan-deep);
}
.sprite-option.selected {
    border-color: var(--color-cyan);
    box-shadow: 0 0 12px rgba(122, 211, 242, 0.55);
}
.sprite-option img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    image-rendering: pixelated;
    display: block;
}

/* ============================================================
   Sprite grid (login guest panel): 2x3 grid of large clickable
   sprite cells, no preview — what you see is what you click.
   ============================================================ */
.sprite-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-2);
    padding: var(--space-2);
    background: var(--color-bg-deep);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}
@media (max-width: 600px) {
    .sprite-grid { grid-template-columns: repeat(3, 1fr); }
}
.sprite-grid .sprite-option {
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
}
.sprite-grid .sprite-option input[type=radio] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.section-header {
    color: var(--color-text-muted);
    font-family: var(--font-display);
    font-size: var(--text-sm);
    letter-spacing: 2px;
    padding: var(--space-2) var(--space-2) var(--space-1);
    margin-top: var(--space-2);
    border-bottom: 1px solid var(--color-border);
}
.section-header:first-child { margin-top: 0; }

/* ============ DRAW (P key — admin whiteboard overlay) ============ */
/* Make the whole #draw chain fill the overlay height so the canvas-wrap
   (flex:1) has vertical room to grow into. The shared .dock-grid is a grid
   whose single row wasn't stretching here, leaving the canvas short with empty
   space below — override it to a flex column and let dock-main flex:1 fill. */
#draw .dock-grid { display: flex; flex-direction: column; height: 100%; min-height: 0; padding: var(--space-2); }
#draw .dock-main { flex: 1 1 auto; min-height: 0; gap: var(--space-2); padding: var(--space-2); }

/* Compact chrome — the whiteboard wants maximum canvas, minimum toolbar. The
   shared .tab/.btn are text-lg + 44px tall (mobile tap target); this is an
   admin desktop tool, so tighten everything to claw back vertical space. */
#draw .dock-header { padding-bottom: 0; }
#draw .dock-header .text-xl { font-size: var(--text-lg); }
#draw .menu-tabs { padding-bottom: var(--space-1); }
#draw .draw-toolbar { gap: var(--space-1); }
#draw .tab,
#draw .btn {
    font-size: var(--text-sm);
    padding: var(--space-1) var(--space-2);
    min-height: 30px;
    letter-spacing: 0.5px;
}
#draw .draw-swatch { width: 22px; height: 22px; }
#draw .draw-color-input { width: 26px; height: 24px; }
#draw .draw-divider { min-height: 22px; }
.draw-view { display: flex; flex-direction: column; gap: var(--space-3); min-height: 0; flex: 1; }
/* The hidden view still carries .draw-view/.menu-body display:flex, which beats
   the [hidden] UA display:none (specificity 0,1,0 > 0,0,0). Without this the
   "hidden" gallery panel stays laid out as a flex:1 sibling and steals half the
   canvas height. (0,2,0) wins — same trap fixed for .td-panel[hidden]. */
.draw-view[hidden] { display: none; }
.draw-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-2);
}
/* Keep related controls together so the toolbar wraps as whole groups, not
   mid-group, on narrow viewports. */
.draw-group { display: inline-flex; align-items: center; gap: var(--space-1); flex-wrap: nowrap; }
.draw-divider {
    width: 1px;
    align-self: stretch;
    min-height: 28px;
    background: var(--color-border);
    margin: 0 var(--space-1);
}
.draw-swatches { display: inline-flex; align-items: center; gap: var(--space-1); flex-wrap: wrap; }
.draw-swatch-label {
    color: var(--color-text-muted);
    font-family: var(--font-display);
    font-size: var(--text-sm);
    letter-spacing: 1px;
    margin-right: 2px;
}
.draw-swatch {
    width: 28px; height: 28px;
    border: 2px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    padding: 0;
}
.draw-swatch.active { border-color: var(--color-cyan); box-shadow: var(--glow-cyan); }
.draw-color-input {
    width: 32px; height: 28px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg-deep);
    cursor: pointer;
    padding: 0;
}
.draw-tool-group { display: flex; gap: var(--space-1); }
.draw-tool-label {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    color: var(--color-text-muted);
    font-family: var(--font-display);
    font-size: var(--text-sm);
    letter-spacing: 1px;
}
.draw-range { accent-color: var(--color-cyan); }
.draw-size-val {
    min-width: 22px;
    text-align: right;
    color: var(--color-cyan);
    font-family: var(--font-display);
    font-size: var(--text-sm);
}
.draw-name { max-width: 200px; }
.draw-canvas-wrap {
    flex: 1;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
    position: relative;  /* anchors the text-tool input overlay */
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    /* No padding/centering — the canvas backing store is sized to this box
       (see drawResize) so the white fills the entire area edge-to-edge. */
}
.draw-canvas {
    display: block;
    width: 100%;
    height: 100%;
    background: #FFFFFF;
    image-rendering: auto;
    cursor: crosshair;
}
.draw-text-input {
    position: absolute;
    z-index: 2;
    background: transparent;
    border: 1px dashed var(--color-cyan);
    outline: none;
    padding: 0 2px;
    margin: 0;
    min-width: 120px;
    line-height: 1;
    caret-color: var(--color-cyan);
}
.draw-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--space-3);
}
.draw-card {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg);
    padding: var(--space-2);
}
.draw-card-img {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: contain;
    background: #FFFFFF;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}
.draw-card-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.draw-card-name {
    font-family: var(--font-display);
    font-size: var(--text-base);
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.draw-card-actions { display: flex; gap: var(--space-2); }
.draw-card-actions .tab { flex: 1; }
