/* web/css/base.css
 *
 * The tokens, the resets, and the shell around everything: the palette and
 * radii on :root, the top bar and its menus, and the quota pill. First, because
 * every other file reads these variables.
 *
 * Linked from web/index.html in the order the sections had in the old
 * web/styles.css, and concatenated in that order they reproduce it exactly, so
 * the cascade is unchanged. A rule that moves between these files moves in the
 * cascade too: check what it now comes before and after.
 */

/* TGXCode — a console for concurrent coding agents.
 *
 * Visual language follows Google's current system: tonal surfaces rather than
 * borders, generous corner radii, pill-shaped controls, and a restrained blue
 * primary. Separation comes from surface elevation and space, not hairlines, so
 * a dense screen still reads calm. Dark is the designed default.
 */

/* ── tokens ─────────────────────────────────────────────────────────────
   Every value a surface needs, named for what it is for. The rule for the rest
   of web/css/ is that a colour, a shadow, a z-layer, a duration or an easing is
   read from here, never written out — docs/plans/22-ui-overhaul.md has the
   reference, the exceptions, and which token to reach for when.

   Two blocks. The first is the palette and everything else that is a colour,
   and it is the dark theme: a light theme would be a second copy of that block
   under `:root[data-theme="light"]` and nothing more, which only works while no
   other file writes a colour of its own. The second block is the scales —
   type, spacing, radii, layers, elevation, motion — which do not change with
   the theme.

   The older names (--s1…--s5, --text-*, --t-fast, --t-med, --ease) are kept as
   they were. Other branches are written against them, and --t-* and --ease are
   now aliases into the motion scale rather than values of their own. */

:root {
    /* Tonal surface ramp — each step is a lift, not a line. --s6 is the top
       of it: a scrollbar thumb under the pointer, an idle dot on --s3. */
    --bg:      #131314;
    --s1:      #1b1c1d;
    --s2:      #202124;
    --s3:      #282a2c;
    --s4:      #303134;
    --s5:      #3c3e41;
    --s6:      #4d5155;

    --outline:      #444746;
    --outline-soft: #2b2d2f;

    --text:   #e3e3e3;
    --text-2: #c4c7c5;
    --text-3: #9aa0a6;
    --text-4: #6f7579;

    --blue:      #a8c7fa;
    --blue-deep: #0b57d0;
    --blue-cont: #1f3760;   /* tonal container behind selected items */
    --blue-tint: #16233a;

    --green:  #6dd58c;
    --yellow: #fdd663;
    --red:    #f28b82;
    --purple: #d0bcff;
    --peach:  #f8b995;

    /* Containers: a hue turned into a ground, for a state that is worn by a
       whole row or button rather than by a word. `-cont` is the resting ground,
       `-hover` the step a pointer adds; `--on-*` is text and icons on it. */
    --blue-cont-hover:  #26406c;
    --blue-cont-active: #30507f;   /* pressed, or a menu open off a selected row */
    --on-blue:          #062e6f;   /* on solid --blue */
    --on-blue-deep:     #ffffff;   /* on solid --blue-deep */
    --on-blue-cont:     #dbe6fb;   /* on --blue-cont: titles, labels */
    --on-blue-cont-2:   #b3c7ea;   /* … secondary text */
    --on-blue-cont-3:   #9db3d8;   /* … meta, the quietest line */

    --red-cont:       #3a2422;     /* destructive hover, a failed thing */
    --red-cont-hover: #4a2b28;
    --red-soft:       #f4a9a3;     /* red text that has to be read at length */
    --on-red:         #4a0d09;     /* on solid --red */

    --yellow-tint:          #232017;   /* a whole card asking for you */
    --yellow-cont:          #2b2719;
    --yellow-cont-hover:    #3a3320;
    --yellow-cont-strong:   #4a4128;
    --on-yellow:            #241f07;   /* on solid --yellow */
    --amber-cont:           #46331a;   /* the dev badge — not a warning */

    --green-tint: #14211a;
    --green-edge: #3f6b4c;

    /* Find-in-page marks: amber, so a match never reads as a selection. */
    --mark-bg: #4d3f10;
    --mark-fg: #f6e3ab;

    --selection: #2e4a75;
    --on-selection: #ffffff;
    --scrim:        #00000099;
    --scrim-strong: #000000c2;
    --recess: #00000047;   /* a keycap sunk into a button, whatever its colour */
    --scroll-thumb:       var(--s5);
    --scroll-thumb-hover: var(--s6);

    /* The one light surface in a dark app — toasts — and its three moods. */
    --inverse-bg: #e3e3e3;
    --inverse-fg: #1f1f1f;
    --inverse-err-bg:  #f9dedc;  --inverse-err-fg:  #410e0b;
    --inverse-ok-bg:   #c4eed0;  --inverse-ok-fg:   #0a2e18;
    --inverse-warn-bg: #fde9c4;  --inverse-warn-fg: #3a2503;

    /* Code: syntax roles (web/highlight.js names the tokens) and diffs, which
       web/css/tools.css and the diff2html overrides in viewers.css share. */
    --syn-comment: var(--text-4);
    --syn-punct:   #8b9094;
    --syn-string:  #95d3a5;
    --syn-regex:   #86cfc4;
    --syn-number:  #f0b96b;
    --syn-keyword: #c9a6f5;
    --syn-builtin: var(--blue);
    --syn-fn:      #8fc0f0;
    --syn-type:    #7fd0c4;
    --syn-var:     #f2b48a;
    --syn-flag:    #c1adf0;
    --syn-add:     #a7e6bd;
    --syn-del:     #f4b4ae;

    --diff-add-bg:   var(--green-tint);
    --diff-add-fg:   #9ad8b2;
    --diff-add-hl:   #24523a;
    --diff-add-edge: #1f3a2a;
    --diff-del-bg:   #241819;
    --diff-del-fg:   #e8a9a4;
    --diff-del-hl:   #5a2f2c;
    --diff-del-edge: #3d2626;
    --diff-change-bg: #2a2413;

    /* Shadows are black on a near-black page: they say "above", not "lit". */
    --shadow-1:      0 1px 3px #0006;
    --shadow-toast:  0 4px 14px #0008;
    --shadow-pop:    0 10px 30px #000a;
    --shadow-float:  0 6px 22px #0009, 0 0 0 1px var(--outline-soft);
    --shadow-dialog: 0 24px 64px #000a;

    --focus-colour: var(--blue);

    /* Chunk C (UI audit). The image preview's near-black backdrop, and the red
       wash behind the Skills full-screen risk confirm — the two scrims that are
       not the dialog one. */
    --scrim-image:  #000000d9;
    --scrim-danger: color-mix(in oklab, var(--red-cont) 70%, var(--bg));
}

:root {
    /* Type. Integer steps: the half-pixel sizes these replaced were too close
       to tell apart and too many to keep straight. --fs-base is body text;
       most chrome sits at --fs-sm and --fs-md. */
    --fs-2xs:  10px;
    --fs-xs:   11px;
    --fs-sm:   12px;
    --fs-md:   13px;
    --fs-base: 14px;
    --fs-lg:   16px;
    --fs-xl:   18px;
    --fs-2xl:  21px;
    --fs-3xl:  26px;

    --lh-none:  1;
    --lh-tight: 1.3;
    --lh-snug:  1.4;
    --lh-base:  1.5;
    --lh-prose: 1.6;

    --fw-regular: 400;
    --fw-medium:  500;
    --fw-strong:  600;

    /* Spacing, on a 2px grid that thins out as it grows. */
    --sp-1:  2px;
    --sp-2:  4px;
    --sp-3:  6px;
    --sp-4:  8px;
    --sp-5:  10px;
    --sp-6:  12px;
    --sp-7:  16px;
    --sp-8:  20px;
    --sp-9:  24px;
    --sp-10: 32px;

    /* Radii: tighter inside, softer outside. A control inside a card takes one
       step below the card's. */
    --r-2xs: 3px;
    --r-xs: 6px;
    --r-sm: 8px;
    --r:    12px;
    --r-lg: 16px;
    --r-xl: 24px;
    --pill: 999px;

    /* Layers that cross the whole window. Smaller numbers inside a panel are
       that panel's own business and stay literal. */
    --z-card:  40;   /* a card that is not modal: over the panes, under dialogs */
    --z-scrim: 50;
    --z-pop:   60;   /* menus and popovers, over the page */
    --z-over:  70;   /* the context menu, over dialogs too */
    --z-toast: 80;

    /* An accent edge down the left of a card or row: `inset var(--edge-w) 0 0 <hue>`. */
    --edge-w: 3px;

    --focus-w: 2px;
    --focus-offset: 2px;
    --ring-inset: inset 0 0 0 var(--focus-w) var(--focus-colour);

    --gutter: 68px;
    --rail: 304px;
    --turns: 30px;

    --sans: "Google Sans Text", "Google Sans", Roboto, "Segoe UI Variable Text",
            "Segoe UI", system-ui, -apple-system, sans-serif;
    --mono: "Google Sans Mono", "Roboto Mono", "Cascadia Code", "JetBrains Mono",
            Consolas, ui-monospace, SFMono-Regular, monospace;

    /* Motion. web/motion.js reads these by name, so a duration changed here
       changes the JS-driven motion too. See the presets table there.
         press  — a button going down: fast enough not to be seen as motion
         fast   — colour and opacity changes, every exit, small popovers in
         base   — a menu or dock opening, a list re-sorting
         slow   — a dialog arriving
         loop   — one breath of a pulsing status dot */
    --dur-press: 90ms;
    --dur-fast:  120ms;
    --dur-base:  180ms;
    --dur-slow:  240ms;
    --dur-loop:  1.6s;
    --dur-flash: 1.3s;   /* the highlight on whatever a jump landed on */

    /* standard — something already on screen changing: colour, position, size
       out    — something arriving: decelerates into place
       in     — something leaving: accelerates away, so it is gone sooner
       linear — constant-rate loops only */
    --ease-standard: cubic-bezier(0.2, 0, 0, 1);
    --ease-out:      cubic-bezier(0.05, 0.7, 0.1, 1);
    --ease-in:       cubic-bezier(0.3, 0, 0.8, 0.15);
    --ease-linear:   linear;

    --t-fast: var(--dur-fast);
    --t-med:  var(--dur-base);
    --ease:   var(--ease-standard);

    /* Chunk A (wave 2). The horizontal inset of a pane in the main column —
       the conversation header, the log, the composer and the docks above it,
       the boards. A layout dimension like --gutter and --rail rather than a
       step on the spacing scale: it is the one edge all of those line up on,
       and naming it is what keeps them lined up. */
    --pane-x: 28px;

    /* Chunk C (UI audit). Control heights: a compact control inside a row or a
       card (28), a control on the bar or a panel head (34), a dialog's footer
       button (40). A new button or select takes one of these. */
    --ctl-sm: 28px;
    --ctl:    34px;
    --ctl-lg: 40px;
    /* A control that cannot be used right now. One value, so every disabled
       button in the app is equally faint. */
    --disabled-opacity: 0.45;
}

/* Chunk C (UI audit). The one pulse: a skeleton line, a status that is waiting
   on something. `--pulse-dim` sets how far it fades; the period is the caller's,
   normally `var(--dur-loop)`. The skeleton, the command dot and the preview's
   driving dot use it; reviews.css's crv-pulse can move onto it too. */
@keyframes pulse { 50% { opacity: var(--pulse-dim, 0.4); } }

/* Everything CSS animates, stopped in one place for a reader who asked for less
   motion: transitions are cut to nothing, and a looping keyframe like `breathe`
   ends on its last frame and holds there, which is a steady dot rather than a
   missing one.

   The durations are deliberately *not* zeroed. web/motion.js checks the same
   query itself and, rather than snapping, keeps a short opacity fade with the
   travel, scale and height taken out — a change you can still see happen,
   without the movement this query is about. */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0ms !important;
    }
}

/* A 12-hour clock is two characters longer than a 24-hour one ("3:04:05 PM"
   against "15:04:05"), which is more than the 68px gutter holds. See
   transcript.clock in bridge/prefs.js and applyClock in web/app.js. */
:root[data-clock="12h"] { --gutter: 80px; }

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
    background: var(--bg);
    color: var(--text);
    font: 400 var(--fs-base)/var(--lh-prose) var(--sans);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

::selection { background: var(--selection); color: var(--on-selection); }

/* Text for a screen reader and nothing else. Clipped rather than `display:none`
   or `visibility:hidden`, either of which takes it out of the accessibility tree
   along with the pixels, which is the whole thing it is for. */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--scroll-thumb);
    border: 3.5px solid transparent;
    border-radius: var(--pill);
    background-clip: content-box;
}
/* The thumb thickens under the pointer as well as lightening, so the thing you
   are about to grab says so. The corner where two scrollbars meet is painted
   white by default, which on this background is a bright square in the corner
   of every pane that scrolls both ways. */
::-webkit-scrollbar-thumb:hover {
    background: var(--scroll-thumb-hover);
    background-clip: content-box;
    border-width: 2.5px;
}
::-webkit-scrollbar-corner { background: transparent; }

button, input, textarea, select { font: inherit; color: inherit; background: none; border: none; }
button { cursor: pointer; }

/* The up/down arrows on a number input. Left native, Chromium draws its stock
   light-grey spinner on a dark field. `appearance: none` drops only the drawing:
   clicking the top half still steps up, the bottom half steps down, and holding
   it repeats, so no input needs a wrapper or a handler. The glyph is a mask
   rather than a background image so it can take its colour from the palette;
   `img-src` allows the data: URL. */
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    appearance: none;
    flex: none;
    align-self: stretch;
    width: 10px;
    margin-left: 4px;
    cursor: pointer;
    background-color: var(--text-3);
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 16'%3E%3Cpath d='M5 2.5 8.5 6.5h-7zM5 13.5 1.5 9.5h7z'/%3E%3C/svg%3E") center / 10px 16px no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 16'%3E%3Cpath d='M5 2.5 8.5 6.5h-7zM5 13.5 1.5 9.5h7z'/%3E%3C/svg%3E") center / 10px 16px no-repeat;
}
input[type="number"]::-webkit-inner-spin-button:hover { background-color: var(--text); }
input[type="number"]:disabled::-webkit-inner-spin-button { opacity: 0.4; cursor: default; }
input[type="number"]:disabled::-webkit-inner-spin-button:hover { background-color: var(--text-3); }
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

:focus-visible { outline: var(--focus-w) solid var(--focus-colour); outline-offset: var(--focus-offset); border-radius: var(--r-xs); }

/* A text field always matches :focus-visible, so the ring above was drawn as a
   hard rectangle inside every rounded field that already says it has the focus
   — the composer, the search pill, the reply box on a live card all lift their
   ground on :focus-within. The caret and that lift are the focus state there;
   a second ring inside them was noise. */
:is(.input-row, .bar-search, .lsend) :is(input, textarea):focus-visible { outline: none; }

/* Press: a button sinks a little under the pointer, so a click is felt before
   whatever it does arrives. `scale` rather than `transform`, so it composes with
   any transform a button already has instead of replacing it, and no
   transition: this is the most frequent motion in the app and it should be
   instant. Compact controls only — a full-width row shrinking by 3% reads as
   the row moving, not as being pressed. */
:is(.btn, .btn-send, .bar-btn, .icon-btn, .mini, .perm-btn, .tb-btn, .lbtn, .seg-btn,
    .more-btn, .dash-btn, .quota-pill, .db-status):active:not(:disabled):not(.bar-more-menu *) {
    scale: 0.97;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── shell ───────────────────────────────────────────────────────────── */

.app {
    display: grid;
    grid-template-rows: 52px 1fr;
    grid-template-columns: var(--rail) 1fr;
    grid-template-areas: "bar bar" "rail main";
    height: 100vh;
    background: var(--bg);
}

.bar {
    grid-area: bar;
    display: flex;
    align-items: center;
    /* Tight, because the view buttons have no ground at rest and their own
       padding is what spaces them. The wordmark and the groups add their own
       room below. */
    gap: var(--sp-1);
    padding: 0 var(--sp-6) 0 var(--sp-7);
    -webkit-app-region: drag;
}
.bar > * { flex: none; }
/* In the desktop app the bar is the window's titlebar, so everything on it
   that is not a control moves the window: the wordmark, the dev badge, the
   gaps, the spacer. A drag region takes the press for the OS, so the controls
   are carved out of it — and carry a drag of their own, from a press that
   travels (web/titlebar.js). Menus and popovers hanging off the bar are
   carved out too, for the part of them that overlaps it. */
.bar :is(button, input, a[href], label, .quota-wrap, .bar-more-wrap, .quota-menu, .bar-more-menu) {
    -webkit-app-region: no-drag;
}

.wordmark {
    display: flex;
    align-items: center;
    gap: var(--sp-4);
    margin-right: var(--sp-7);
    font: 500 var(--fs-lg)/var(--lh-none) var(--sans);
    color: var(--text-2);
    white-space: nowrap;
    letter-spacing: 0.01em;
}
.wordmark b { color: var(--blue); font-size: var(--fs-xs); }

/* Only present on a development instance — the everyday window has no badge. */
.dev-badge {
    margin-left: var(--sp-2);
    padding: var(--sp-1) var(--sp-4);
    border-radius: var(--pill);
    background: var(--amber-cont);
    color: var(--yellow);
    font: 500 var(--fs-xs)/var(--lh-snug) var(--mono);
    letter-spacing: 0.02em;
}

/* The one thing on the bar that grows and shrinks. Everything else is
   `flex: none`, and when there is still not room fitBar() in
   web/settings/toolbar.js takes it from the buttons, never from this below its
   floor. The floor is read back by fitBar(), so it is the only place to set it. */
.bar-search {
    flex: 1 1 auto;
    min-width: 160px;
    max-width: 520px;
    display: flex;
    align-items: center;
    gap: var(--sp-5);
    height: 34px;
    margin-right: var(--sp-7);
    padding: 0 var(--sp-7);
    background: var(--s2);
    border-radius: var(--pill);
    transition: background var(--dur-fast) var(--ease-standard);
}
.bar-search:hover { background: var(--s3); }
.bar-search:focus-within { background: var(--s3); }
.bar-search svg { flex: none; color: var(--text-3); }
.bar-search input { flex: 1; min-width: 0; font-size: var(--fs-base); }
.bar-search input::placeholder { color: var(--text-3); }

.bar > .bar-spacer { flex: 1 1 0; }

/* ── the bar as the titlebar ─────────────────────────────────────────────
   `data-titlebar="custom"` is set on <html> by app/preload.js when the window
   has no native titlebar (app/titlebar.js), and never in a browser.

   The window controls are the OS's, drawn over the page at the bar's right
   end — the traffic lights at its left on macOS. --tb-right and --tb-left are
   the room they take, from the Window Controls Overlay rect (web/titlebar.js);
   the fallbacks are what three Windows caption buttons and the macOS traffic
   lights measure, for a shell where that API is missing. fitBar() reads the
   padding back, so the buttons spill into More before reaching the controls. */
html[data-titlebar="custom"] .bar {
    padding-right: calc(var(--sp-4) + var(--tb-right, 138px));
    user-select: none;
}
html[data-titlebar="custom"][data-platform="darwin"] .bar {
    padding-left: calc(var(--sp-5) + var(--tb-left, 76px));
    padding-right: var(--sp-6);
}
html[data-titlebar="custom"][data-window-full] .bar { --tb-left: 0px; --tb-right: 0px; }

/* The strip that is always there to drag the window by, however full the bar.
   fitBar() counts this floor as taken (`reserve` in web/bar-fit.js), so the
   buttons go into More before the strip goes below it. 64px is about two
   finger-widths of a mouse pointer's aim, and less than one view button. */
html[data-titlebar="custom"] .bar > .bar-spacer { min-width: 64px; }

/* The caption buttons take ~140px the bar used to have, and what is left on a
   narrow window is the part that cannot go into More: the wordmark, the search
   box's floor and the window-state pills. So a narrow titlebar gives up the
   wordmark's words (the ◆ stays, and still drags) and some of the search box's
   floor before those pills are pushed under the controls — a window snapped to
   half a 1080p screen is about this wide. The text is a bare node, so it goes
   by font-size; the ◆ and the dev badge set sizes of their own. */
@media (max-width: 1100px) {
    html[data-titlebar="custom"] .bar > .wordmark { font-size: 0; gap: 0; margin-right: var(--sp-5); }
    html[data-titlebar="custom"] .bar > .wordmark .dev-badge { margin-left: var(--sp-4); }
}
@media (max-width: 1000px) {
    html[data-titlebar="custom"] .bar > .bar-search { min-width: 112px; margin-right: var(--sp-4); }
}

/* A window in the background has a quieter titlebar, as a native one does.
   The pills and buttons rather than their wrappers, so a popover that is open
   when the window loses focus is not dimmed with them. No transition: a
   native titlebar changes at once, and a transition here would replace the
   buttons' own. */
html[data-titlebar="custom"][data-window-focus="off"] :is(
    .bar > .wordmark, .bar > .bar-search, .bar > .bar-btn, .bar > .db-status,
    .bar > .quota-wrap > .quota-pill, .bar #bar-more) {
    opacity: 0.55;
}

/* The view buttons — Tasks, Live, Dashboard, History, Drafts, Schedules,
   Settings. Places to go, so they are quiet: no ground until the pointer is on
   one, and the open view's `.on` is the only blue on the bar. The window-state
   pills further along (quota, version, DevBrowser) keep a ground of their own,
   which is what tells the two kinds apart. */
.bar-btn {
    display: flex;
    align-items: center;
    gap: var(--sp-4);
    height: 34px;
    padding: 0 var(--sp-6);
    font: 500 var(--fs-md)/var(--lh-none) var(--sans);
    color: var(--text-2);
    background: transparent;
    border-radius: var(--pill);
    white-space: nowrap;
    transition: background var(--dur-fast) var(--ease-standard), color var(--dur-fast) var(--ease-standard);
}
.bar-btn:hover { background: var(--s2); color: var(--text); }
.bar-btn svg { flex: none; color: var(--text-3); transition: color var(--dur-fast) var(--ease-standard); }
.bar-btn:hover svg { color: var(--text-2); }
.bar-btn.on { background: var(--blue-cont); color: var(--on-blue-cont); }
.bar-btn.on:hover { background: var(--blue-cont-hover); }
.bar-btn.on svg { color: var(--blue); }

/* A square button for a setup step you do once per device, rather than one that
   spends a word of the bar on itself forever. */
.bar-btn.icon-only { padding: 0; width: 34px; justify-content: center; gap: 0; }
/* The label goes; a count stays, since it is the reason to look at the button.
   With one showing, the square widens to a pill around the icon and the count. */
.bar-btn.icon-only > span:not(.bar-badge) { display: none; }
.bar-btn.icon-only:has(> .bar-badge:not([hidden])) { width: auto; padding: 0 var(--sp-5); gap: var(--sp-3); }

/* The bar's first concession to a narrow window (fitBar()): every view button
   keeps its icon and its count and loses its word. Clipped rather than
   `display: none`, so the word is still the button's accessible name — these
   buttons carry no aria-label unless Settings turned the label off. Direct
   children only: a button in the More menu is a row, and a row has its words. */
.bar.compact > .bar-btn:not(.icon-only) { padding: 0; width: 34px; justify-content: center; gap: 0; }
.bar.compact > .bar-btn:not(.icon-only):has(> .bar-badge:not([hidden])) { width: auto; padding: 0 var(--sp-5); gap: var(--sp-3); }
.bar.compact > .bar-btn > span:not(.bar-badge) {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}
.bar.compact > .bar-btn { position: relative; }

/* Where a run of view buttons meets the state pills, or the other way round —
   fitBar() marks the first of each run, so this follows whatever order
   Settings put them in. Space, not a rule: the grounds already say which is
   which. */
.bar > [data-group-start] { margin-left: var(--sp-7); }
/* The state pills sit closer to each other than the views do to them. */
.bar > :is(.quota-wrap, .db-status) + :is(.quota-wrap, .db-status):not([data-group-start]) { margin-left: var(--sp-2); }


/* A count, not an alert: unfinished work is the normal state of this machine. */
.bar-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 var(--sp-3);
    border-radius: var(--pill);
    background: var(--s3);
    color: var(--text-2);
    font: 500 var(--fs-xs)/var(--lh-none) var(--mono);
    font-variant-numeric: tabular-nums;
}
.bar-badge[hidden] { display: none; }
.bar-btn:hover .bar-badge { background: var(--s4); }
.bar-btn.on .bar-badge { background: var(--blue-cont-active); color: var(--on-blue-cont); }

.db-status {
    display: flex;
    align-items: center;
    gap: var(--sp-4);
    height: 34px;
    padding: 0 var(--sp-6);
    font: 500 var(--fs-md)/var(--lh-none) var(--sans);
    color: var(--text-2);
    background: var(--s2);
    border-radius: var(--pill);
    white-space: nowrap;
    transition: background var(--dur-fast) var(--ease-standard), color var(--dur-fast) var(--ease-standard);
}
.db-status:hover { background: var(--s3); color: var(--text); }
.db-status .led { width: 6px; height: 6px; border-radius: 50%; background: var(--text-4); }
.db-status[data-up="true"] .led { background: var(--green); }

/* The bar's overflow. The buttons in it are the bar's own, moved here by
   paintToolbar() rather than copied — either because Settings put them here,
   or because fitBar() ran out of room for them — so these rules restyle a
   pill as a menu row: full width, always labelled, and the count pushed to
   the far edge. */
.bar-more-wrap { position: relative; }
.bar-more-wrap[hidden] { display: none; }
.bar [data-bar-hidden] { display: none; }
#bar-more { position: relative; }
/* A count on a square button would push the dots off-centre, so it rides the
   corner instead. */
#bar-more .bar-badge {
    position: absolute;
    top: calc(-1 * var(--sp-2));
    right: calc(-1 * var(--sp-2));
    min-width: 16px;
    height: 16px;
    padding: 0 var(--sp-2);
    font-size: var(--fs-2xs);
}
#bar-more[aria-expanded="true"] { background: var(--s2); color: var(--text); }

.bar-more-menu {
    position: absolute;
    top: calc(100% + var(--sp-4));
    right: 0;
    z-index: var(--z-pop);
    min-width: 200px;
    padding: var(--sp-3);
    display: flex;
    flex-direction: column;
    gap: var(--sp-1);
    background: var(--s3);
    border-radius: var(--r);
    box-shadow: var(--shadow-pop);
    transform-origin: top right;
}
.bar-more-menu[hidden] { display: none; }
.bar-more-menu .bar-btn,
.bar-more-menu .db-status {
    width: 100%;
    height: 34px;
    padding: 0 var(--sp-5);
    gap: var(--sp-5);
    justify-content: flex-start;
    background: transparent;
    border-radius: var(--r-xs);
}
.bar-more-menu .bar-btn:hover,
.bar-more-menu .db-status:hover { background: var(--s4); }
.bar-more-menu .bar-btn.on { background: var(--blue-cont); }
/* A button whose label you turned off on the bar still needs one in a list. */
.bar-more-menu .bar-btn.icon-only > span:not(.bar-badge) { display: inline; }
.bar-more-menu .bar-badge { margin-left: auto; background: var(--s4); }

/* ── quota ───────────────────────────────────────────────────────────── */

.quota-wrap { position: relative; }
.quota-wrap[hidden] { display: none; }

.quota-pill {
    display: flex;
    align-items: center;
    gap: var(--sp-4);
    height: 34px;
    padding: 0 var(--sp-6);
    font: 500 var(--fs-md)/var(--lh-none) var(--sans);
    white-space: nowrap;
    color: var(--text-2);
    background: var(--s2);
    border-radius: var(--pill);
    transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.quota-pill:hover { background: var(--s3); color: var(--text); }
.quota-pill[aria-expanded="true"] { background: var(--s3); color: var(--text); }

/* A window just went from fine to not-fine. This was a toast until it wasn't,
   and a toast was the wrong shape for it twice over: `rate_limit_event` arrives
   on *every* turn for as long as the limit holds, so it stacked identical
   warnings over the composer, and the thing it was about is already drawn a few
   pixels away in the header. So the pill says it about itself. See quotaFlash()
   in web/app.js.

   These rules sit after `:hover` and `[aria-expanded]` on purpose — all three
   are specificity (0,2,0), so source order is what decides the flash still shows
   while the pointer is over the pill.

   The ring is a spread `box-shadow` for the reason flash-settings-row gives
   further down this file: the pill has padding and a background of its
   own, so a highlight has to be carried out past it by something that takes no
   part in layout. The shadow inherits `border-radius: var(--pill)`, so it comes
   out as a ring around a capsule rather than as a rectangle clipped to the text.

   Tinted with color-mix into --s2 rather than two new hex values, so the colour
   the pill settles back to is the one it actually lives on rather than a
   near-miss somebody has to notice later. */
.quota-pill.q-flash {
    background: var(--q-flash-tint);
    animation: flash-quota-pill 0.7s var(--ease) 3;
}
.quota-pill.q-flash[data-flash="warn"] {
    --q-flash-tint: color-mix(in srgb, var(--yellow) 22%, var(--s2));
    --q-flash-ring: color-mix(in srgb, var(--yellow) 55%, transparent);
}
.quota-pill.q-flash[data-flash="bad"] {
    --q-flash-tint: color-mix(in srgb, var(--red) 24%, var(--s2));
    --q-flash-ring: color-mix(in srgb, var(--red) 60%, transparent);
}

/* Three rings rather than one fade. A single 1.3s wash in the corner of a wide
   window is exactly what the toast was covering for, and this is now the only
   thing on screen that moves when a limit is hit.

   The ring reaches its full spread in the first third and then fades *in place*,
   rather than fading as it expands. The obvious radar-ping shape — grow and fade
   together — does not work here: a shadow with no spread sits entirely behind an
   opaque pill, so the ring is at its most transparent exactly when it first
   becomes visible, and --ease is cubic-bezier(0.2, 0, 0, 1), which front-loads
   hard enough that it is all but gone by the time it clears the edge. Measured
   at 8% alpha before it was split in two. */
@keyframes flash-quota-pill {
    0%   { box-shadow: 0 0 0 0 var(--q-flash-ring); }
    35%  { box-shadow: 0 0 0 5px var(--q-flash-ring); }
    100% { box-shadow: 0 0 0 5px transparent; }
}

/* Not `animation: none`, which is what every other flash in this file does.
   Those are a nicety over something the user is already looking at; this one is
   the only channel left now the toast is gone, so switching it off switches the
   feature off for anybody who asked for less motion. The tint and a static ring
   are held instead for the 2.1s the class is applied, and .quota-pill's existing
   `transition: background` fades them in and out — a colour crossfade, which is
   not the problem this query is about. */
@media (prefers-reduced-motion: reduce) {
    .quota-pill.q-flash {
        animation: none;
        box-shadow: 0 0 0 5px var(--q-flash-ring);
    }
}

.quota-pill #quota-pill-body { display: flex; align-items: center; gap: var(--sp-5); }

/* One window's worth: a label, a bar, a number. */
.q-win { display: flex; align-items: center; gap: var(--sp-3); }
.q-win .q-label { color: var(--text-4); font-size: var(--fs-sm); }

.q-bar {
    position: relative;
    width: 34px;
    height: 4px;
    border-radius: var(--pill);
    background: var(--s4);
    overflow: hidden;
}
.q-bar i {
    position: absolute;
    inset: 0 auto 0 0;
    display: block;
    border-radius: var(--pill);
    background: var(--green);
    transition: width var(--t-fast) var(--ease);
}
.q-win[data-status="allowed_warning"] .q-bar i { background: var(--yellow); }
.q-win[data-status="rejected"] .q-bar i { background: var(--red); }

/* Aged out. The number is still the last thing we know, and saying so quietly
   is the whole point of the feature — a stale percentage rendered as current is
   the failure this is designed against. */
.q-win.stale .q-bar i { background: var(--text-4); }
.q-win.stale .q-num { color: var(--text-4); }

.q-num { font-variant-numeric: tabular-nums; }

/* When the window comes back. Set apart by a rule rather than another dot:
   the groups before it are percentages and this is a duration, and the eye
   should not have to read the units to tell them apart. */
.q-reset {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    padding-left: var(--sp-5);
    border-left: 1px solid var(--s4);
    color: var(--text-4);
    font-variant-numeric: tabular-nums;
    /* "8m 05s" has a space in it and the header bar is a tight flex row, so
       without this the countdown breaks after the minutes and the pill grows
       to two lines — which it did the moment seconds were added. */
    white-space: nowrap;
}
.q-reset svg { flex: none; }

.quota-menu {
    position: absolute;
    top: calc(100% + var(--sp-4));
    right: 0;
    z-index: var(--z-pop);
    width: 306px;
    padding: var(--sp-6) var(--sp-7);
    background: var(--s3);
    border-radius: var(--r);
    box-shadow: var(--shadow-pop);
    transform-origin: top right;
}
.quota-menu[hidden] { display: none; }

/* The popover's title. Sentence case: it names one thing, it does not head a
   list — "Limit events" below does, and keeps its overline. */
.quota-head {
    display: flex;
    align-items: center;
    gap: var(--sp-4);
    margin-bottom: var(--sp-5);
    font: 500 var(--fs-md)/var(--lh-tight) var(--sans);
    color: var(--text-2);
}

/* Sibling of .tasks-collapse, which is the same affordance in the changes
   panel. Not uppercase like the label beside it: it is a verb, not a heading. */
.quota-refresh {
    margin-left: auto;
    padding: var(--sp-1) var(--sp-3);
    border: 0;
    border-radius: var(--r-xs);
    background: none;
    color: var(--text-4);
    font: 400 var(--fs-sm)/var(--lh-base) var(--sans);
    letter-spacing: normal;
    text-transform: none;
    cursor: pointer;
}
.quota-refresh:hover:not(:disabled) { background: var(--s4); color: var(--text-2); }
/* Two in one head (the version panel's Changelog and Check again): the first
   takes the push to the right edge and the second sits beside it. */
.quota-refresh + .quota-refresh { margin-left: 0; }
.quota-refresh[hidden] { display: none; }
/* A run takes a few seconds, and the only honest thing to do is look busy for
   them. `wait` rather than `not-allowed`: nothing is disallowed, it is working. */
.quota-refresh:disabled { opacity: 0.45; cursor: default; }
.quota-refresh.busy { cursor: wait; }

.q-row { padding: var(--sp-4) 0; border-top: 1px solid var(--s2); }
.q-row:first-child { border-top: 0; padding-top: 0; }

.q-row-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--sp-5);
    font: 400 var(--fs-md)/var(--lh-snug) var(--sans);
    color: var(--text-2);
}
.q-row-top .q-pct { font: 500 var(--fs-md)/var(--lh-snug) var(--sans); color: var(--text); font-variant-numeric: tabular-nums; }
.q-row.stale .q-row-top .q-pct { color: var(--text-4); }

.q-row .q-bar { width: 100%; height: 4px; margin: var(--sp-3) 0; }

/* tabular-nums because the right-hand half of this row is a countdown that
   ticks every second (tickQuotaClocks), and proportional digits make the whole
   row shuffle sideways once a second. */
.q-row-sub {
    display: flex;
    justify-content: space-between;
    gap: var(--sp-5);
    font: 400 var(--fs-sm)/var(--lh-base) var(--sans);
    color: var(--text-4);
    font-variant-numeric: tabular-nums;
}
.q-row-sub .warn { color: var(--yellow); }
.q-row-sub .bad { color: var(--red); }

.quota-events {
    margin-top: var(--sp-5);
    font: 400 var(--fs-sm)/var(--lh-prose) var(--sans);
    color: var(--text-4);
}
.quota-events:empty { display: none; }
.quota-events .q-ev-head {
    font: 500 var(--fs-xs)/var(--lh-none) var(--sans);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-4);
    margin-bottom: var(--sp-3);
}
.quota-events div + .q-ev-head { margin-top: var(--sp-5); }

.quota-note {
    margin-top: var(--sp-5);
    font: 400 var(--fs-sm)/var(--lh-base) var(--sans);
    color: var(--text-4);
}
.quota-note:empty { display: none; }
.quota-note div + div { margin-top: var(--sp-3); }
.quota-note .warn { color: var(--yellow); }
.quota-note code {
    font: 400 var(--fs-xs)/var(--lh-base) var(--mono);
    color: var(--text-3);
    word-break: break-all;
}

/* The foot of the popover rather than a widget inside it: the menu has
   its own padding, so a row that stopped short of those edges would
   read as a card within a card. The negative margins bleed it back out to the
   corners and the bottom radius finishes them.

   Busy and disabled are lifted from .quota-refresh above, which is the point of
   moving this control here at all — there is no `.bar-btn.busy` rule anywhere in
   this file, so the old header button looked inert for the whole 45 seconds a
   restart can take. */
.quota-restart {
    display: flex;
    /* Not centred: the sub line wraps to two on a worktree path, and a centred
       icon then sits beside the path rather than beside the label it belongs to. */
    align-items: flex-start;
    gap: var(--sp-5);
    width: calc(100% + 2 * var(--sp-7));
    margin: var(--sp-5) calc(-1 * var(--sp-7)) calc(-1 * var(--sp-6));
    padding: var(--sp-5) var(--sp-7);
    border: 0;
    border-top: 1px solid var(--s2);
    border-radius: 0 0 var(--r) var(--r);
    background: none;
    color: var(--text-3);
    text-align: left;
    cursor: pointer;
}
.quota-restart[hidden] { display: none; }
.quota-restart:hover:not(:disabled) { background: var(--s4); color: var(--text); }
.quota-restart:disabled { opacity: 0.45; cursor: default; }
.quota-restart.busy { cursor: wait; }
.quota-restart svg { flex: none; margin-top: var(--sp-1); }

.qr-text { display: flex; flex-direction: column; gap: var(--sp-1); min-width: 0; }
.qr-label { font: 400 var(--fs-md)/var(--lh-tight) var(--sans); }
/* A worktree checkout is a long path with no spaces in it, and this popover is
   306px wide — without this it runs off the edge rather than wrapping. */
.qr-sub { font: 400 var(--fs-xs)/var(--lh-snug) var(--sans); color: var(--text-4); overflow-wrap: anywhere; }
.qr-sub:empty { display: none; }


/* The Claude Code version badge — the quota pill's shape, and only drawn when
   something is behind, so it carries the one tint that says so. See renderCv()
   in web/app.js. */
.cv-wrap { flex: none; }
.cv-pill { color: var(--yellow); white-space: nowrap; }
.cv-pill:hover, .cv-pill[aria-expanded="true"] { color: var(--yellow); }
.cv-row { display: flex; justify-content: space-between; gap: var(--sp-6);
    font: 400 var(--fs-md)/var(--lh-snug) var(--sans); color: var(--text-3); }
.cv-row b { font: 500 var(--fs-sm)/var(--lh-snug) var(--mono); color: var(--text); }
.cv-stale-head { font: 400 var(--fs-md)/var(--lh-snug) var(--sans); color: var(--text-3); margin-bottom: var(--sp-2); }
.cv-stale {
    display: flex; justify-content: space-between; gap: var(--sp-5);
    width: calc(100% + 2 * var(--sp-3)); padding: var(--sp-2) var(--sp-3); margin: 0 calc(-1 * var(--sp-3));
    border: 0; border-radius: var(--r-xs);
    background: none; color: var(--text-2); text-align: left; cursor: pointer;
    font: 400 var(--fs-sm)/var(--lh-snug) var(--sans);
}
.cv-stale:hover { background: var(--s4); color: var(--text); }
.cv-stale-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cv-stale-ver { flex: none; font: 400 var(--fs-xs)/var(--lh-prose) var(--mono); color: var(--text-4); }
.cv-old { color: var(--yellow); }

/* The second meter: Codex's, after Claude's in the pill and under it in the
   popover. Named, because two sets of bars with no names are one confusing set. */
.q-runtime { color: var(--text-3); font-size: var(--fs-sm); }
.q-runtime.after { padding-left: var(--sp-5); border-left: 1px solid var(--s4); }
/* Codex signed out: a dot after its name. The words are the pill's tooltip and
   the popover's first line; in the bar they cost the room the view buttons'
   labels needed. */
.q-signin {
    flex: none;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--yellow);
}

/* A compact bar is one that ran out of room for the view buttons' words. The
   pills give up their decoration first — the mini bars, the countdown and the
   version pill's name — so the numbers stay and the buttons can stay on the bar.
   The status the bar's colour carried moves to the number. Both still sit in the
   tooltip and the popover. fitBar measures the bar compact as well as full, so
   it sees the smaller pills. */
.bar.compact .quota-pill .q-bar,
.bar.compact .quota-pill .q-reset,
.bar.compact .cv-pill .cv-name { display: none; }
.bar.compact .quota-pill .q-win[data-status="allowed_warning"] .q-num { color: var(--yellow); }
.bar.compact .quota-pill .q-win[data-status="rejected"] .q-num { color: var(--red); }
.bar.compact .quota-pill .q-win.stale .q-num { color: var(--text-4); }
.quota-codex { margin-top: var(--sp-6); padding-top: var(--sp-6); border-top: 1px solid var(--s4); }
.quota-codex[hidden] { display: none; }

/* The header's context-window figure, tinted once there is little room left. */
.ctx-use.full { color: var(--yellow); }

/* Phone installs — the quota pill's shape again. Quiet while nothing is moving
   (an install from earlier today, listed for the record), in the normal text
   colour while one is in flight, and yellow for the three things a person has
   to look at. See web/phone-installs.js. */
.pi-wrap { flex: none; }
.pi-pill { gap: var(--sp-3); }
.pi-pill[data-kind="idle"] { color: var(--text-4); }
.pi-pill[data-kind="busy"] { color: var(--text-2); }
.pi-pill[data-kind="warn"],
.pi-pill[data-kind="warn"]:hover,
.pi-pill[data-kind="warn"][aria-expanded="true"] { color: var(--yellow); }
.pi-pill svg { flex: none; }
.pi-pill span { font-variant-numeric: tabular-nums; }

/* The name and the count are for the More menu, where the pill is a row and ⋯
   adds up its badge; on the bar the icon and the status say it. */
.pi-pill .pi-name, .pi-pill .bar-badge { display: none; }
.bar-more-menu .pi-wrap { width: 100%; }
.bar-more-menu .pi-pill {
    width: 100%;
    height: 34px;
    padding: 0 var(--sp-5);
    gap: var(--sp-5);
    justify-content: flex-start;
    background: transparent;
    border-radius: var(--r-xs);
}
.bar-more-menu .pi-pill:hover { background: var(--s4); }
.bar-more-menu .pi-pill .pi-text { display: none; }
.bar-more-menu .pi-pill .pi-name { display: inline; }
.bar-more-menu .pi-pill .bar-badge:not([hidden]) { display: inline-flex; }
/* Off the bar the popover has no pill to hang from: dockPhoneInstalls() pins it
   under ⋯ or the bar's end, and sets top and right. */
.pi-menu.pi-detached { position: fixed; }

/* Twenty rows of this fit nowhere a popover can sit, so the list scrolls. */
.pi-menu { width: 340px; }
#pi-body { max-height: min(60vh, 520px); overflow-y: auto; margin-right: calc(-1 * var(--sp-4)); padding-right: var(--sp-4); }

.pi-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.pi-pkg { font: 400 var(--fs-xs)/var(--lh-snug) var(--mono); color: var(--text-4); overflow-wrap: anywhere; }
.pi-row .q-row-sub { margin-top: var(--sp-1); }
.pi-row[data-stalled="1"] .pi-state,
.pi-row[data-state="needs_action"] .pi-state { color: var(--yellow); }
.pi-row[data-state="failed"] .pi-state { color: var(--red); }
.pi-row[data-state="installed"] .pi-state { color: var(--green); }
.pi-row[data-stalled="1"] .q-bar i { background: var(--yellow); }
.pi-msg { margin-top: var(--sp-2); font: 400 var(--fs-sm)/var(--lh-base) var(--sans); color: var(--text-3); overflow-wrap: anywhere; }
.pi-acts { display: flex; justify-content: flex-end; gap: var(--sp-2); margin-top: var(--sp-3); }
.pi-acts .pi-act { margin-left: 0; }
.pi-acts .pi-act.primary { color: var(--blue); }

/* Its toast opens the popover; the buttons in it keep their own jobs. */
.toast.pi-toast { cursor: pointer; }



/* Pace, under a popover row: an estimate, so quieter than the reading above
   it, and amber only when it says the window runs out before it resets. */
.q-pace { margin-top: 2px; font-size: var(--fs-sm); color: var(--text-3); }
.q-pace.warn { color: var(--yellow); }
.q-pace .q-est {
    margin-left: 4px; padding: 0 4px; border: 1px solid var(--outline);
    border-radius: 3px; font-size: 10px; color: var(--text-4);
}
/* The pill's notch: a small amber dot after the number, when the window is on
   course to reach 100% before it resets. */
.q-win.q-oncourse .q-num::after {
    content: ''; display: inline-block; width: 5px; height: 5px; margin-left: 3px;
    border-radius: 50%; background: var(--yellow); vertical-align: 2px;
}
