/* app.css - shell and shared components of Geruchslost AI (design Y).
   Every value comes from tokens.css; areas add app/static/css/<area>.css via {% block styles %}.
   Flat surfaces and hairlines only: no gradients, no glow, no blur. Motion names its properties
   (never "all") and nothing moves on load. Breakpoints: 760 px (mobile) and 2200 px (WQHD). */

*, *::before, *::after { box-sizing: border-box; }
* { scrollbar-width: thin; scrollbar-color: var(--s4) transparent; }

html { background: var(--bg); }
body {
  margin: 0; min-height: 100dvh; background: var(--bg); color: var(--fg);
  font: 400 var(--t-base)/1.5 var(--sans);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
::selection { background: var(--accent-tint-2); }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p, dl, dd, figure { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
code, kbd, pre { font-family: var(--mono); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm); }

.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: .93em; }
.muted { color: var(--fg-2); }
.faint { color: var(--fg-3); }
.meta { font-size: var(--t-xs); color: var(--fg-3); }
/* Text for screen readers only (a page title the page already shows in another shape). */
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
/* Icons: icon() renders <svg class="ic">; .i is the prototype's wrapper around a bare <svg>. */
.ic { width: 16px; height: 16px; flex: none; }
.i { display: inline-flex; width: 16px; height: 16px; flex: none; }
.i svg { width: 100%; height: 100%; }
.i.lg, .ic.lg { width: 20px; height: 20px; }

.skip {
  position: absolute; left: 16px; top: 16px; z-index: var(--z-toast);
  padding: 8px 12px; border-radius: var(--r-ctl); background: var(--s3); color: var(--fg);
  transform: translateY(-200%);
}
.skip:focus { transform: none; }

/* --- Shell: sidebar, topbar, content ---------------------------------------------------- */

.shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100dvh; }
.shell.bare { grid-template-columns: minmax(0, 1fr); }

.gl-sidebar {
  position: sticky; top: 0; height: 100dvh; z-index: var(--z-sidebar);
  display: flex; flex-direction: column; padding: 0 12px 12px;
  background: var(--bg); border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; height: var(--topbar); padding: 0 8px; flex: none; font-weight: 500; white-space: nowrap; }
/* The logo: a white file (static/brand), 24 px high next to the name, 28 px on WQHD. */
.brand-mark { display: block; flex: none; height: 24px; width: auto; }
.brand > span { letter-spacing: -.01em; }

/* The negative margin leaves room for the focus ring inside the scrolling list. */
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; min-height: 0; overflow-y: auto; margin: 0 -4px; padding: 8px 4px 4px; }
.nav-label { padding: 20px 8px 6px; font-size: var(--t-xs); color: var(--fg-3); }
.nav a {
  display: flex; align-items: center; gap: 10px; flex: none; height: calc(var(--ctl) - 4px); padding: 0 8px;
  border-radius: var(--r-ctl); color: var(--fg-2);
  transition: background-color var(--d1) var(--ease), color var(--d1) var(--ease);
}
.nav a:hover { background: var(--s2); color: var(--fg); }
.nav a[aria-current] { background: var(--accent-tint); color: var(--fg); }
.nav a[aria-current] .ic { color: var(--accent-fg); }
.nav a > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav a .count { margin-left: auto; font: 400 var(--t-xs) var(--mono); color: var(--fg-3); }

.side-foot { display: flex; flex-direction: column; gap: 8px; flex: none; padding-top: 12px; }
.side-plan {
  display: flex; flex-direction: column; gap: 8px; padding: 12px;
  border: 1px solid var(--line); border-radius: var(--r-card); background: var(--s1); font-size: var(--t-sm);
  transition: background-color var(--d1) var(--ease), border-color var(--d1) var(--ease);
}
.side-plan:hover { background: var(--s2); border-color: var(--line-2); }
.side-plan .user-plan { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-plan-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; min-width: 0; }
.side-plan-go { display: inline-flex; align-items: center; align-self: center; gap: 2px; flex: none; font-size: var(--t-xs); color: var(--fg-3); }
.side-plan-pct { flex: none; color: var(--fg-2); }
.side-plan-note { font-size: var(--t-xs); color: var(--fg-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-menu { display: block; }
.side-user {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 8px; border-radius: var(--r-ctl); text-align: left;
  cursor: pointer; transition: background-color var(--d1) var(--ease);
}
.side-user:hover, .side-user[aria-expanded="true"] { background: var(--s2); }
.side-user-text { flex: 1; min-width: 0; }
.side-user .user-name, .side-user .sub { display: block; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user .user-name { font-weight: 500; font-size: var(--t-sm); }
.side-user .sub { font-size: var(--t-xs); color: var(--fg-3); }
.side-user > .ic { color: var(--fg-3); }
.side-menu > [data-popover] { width: 100%; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 100dvh; }
.topbar {
  position: sticky; top: 0; z-index: var(--z-topbar); flex: none; height: var(--topbar);
  display: flex; align-items: center; gap: 16px; padding: 0 var(--pad);
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.topbar > .brand { padding: 0; }
.crumbs { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--fg-3); white-space: nowrap; }
.crumbs .sep { color: var(--line-2); }
.crumbs b { color: var(--fg); font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 12px; flex: none; }
.top-status { display: flex; align-items: center; gap: 8px; padding: 0 4px; font-size: var(--t-sm); color: var(--fg-2); white-space: nowrap; }
.search-btn {
  display: flex; align-items: center; gap: 8px; width: 264px; height: calc(var(--ctl) - 4px); padding: 0 6px 0 10px;
  border: 1px solid var(--line); border-radius: var(--r-ctl); background: var(--s1); color: var(--fg-3); font-size: var(--t-sm);
  cursor: pointer; transition: border-color var(--d1) var(--ease), background-color var(--d1) var(--ease);
}
.search-btn:hover { border-color: var(--line-2); background: var(--s2); }
.search-btn .keys { margin-left: auto; display: flex; gap: 3px; }
.topbar .menu-btn, .gl-scrim { display: none; }

.content { flex: 1; width: 100%; max-width: 2328px; margin: 0 auto; padding: 32px var(--pad) 64px; outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 32px; }
.page-head h1 { font-size: var(--t-h1); font-weight: 500; letter-spacing: -.02em; line-height: 1.25; }
.page-head p { margin-top: 4px; color: var(--fg-2); }
.page-head > div:first-child { min-width: 0; }
.page-head .actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.page-head .actions form { display: flex; margin: 0; }

/* --- Page pieces every area shares (prototype pages.css) ------------------------------- */

.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--gap); min-width: 0; }
.grid > * { grid-column: span 12; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }

/* The one leading number of a page, and the numbers below it; the unit stands in <small>. */
.hero-num, .big-num { display: flex; align-items: baseline; min-width: 0; font-weight: 500; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hero-num { gap: 6px; font-size: var(--t-hero); line-height: 1; letter-spacing: -.035em; }
.hero-num small { font-size: .45em; font-weight: 400; color: var(--fg-3); letter-spacing: 0; }
.big-num { flex-wrap: wrap; gap: 2px 6px; font-size: var(--t-num); line-height: 1.1; letter-spacing: -.03em; }
.big-num small { font-size: var(--t-sm); font-weight: 400; color: var(--fg-3); letter-spacing: 0; white-space: normal; }
:is(.hero-num, .big-num)[data-tone="err"] > .num { color: var(--err-fg); }
:is(.hero-num, .big-num)[data-tone="warn"] > .num { color: var(--warn); }
.delta { font-size: var(--t-sm); color: var(--fg-3); }
.delta b { font-weight: 500; color: var(--fg-2); }
.delta b.up { color: var(--ok); }
.delta b.down { color: var(--err); }

/* Number strip: one card with divided cells, not a row of tiles. */
.strip, .card.strip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.strip > div { display: flex; flex-direction: column; gap: 8px; min-width: 0; padding: var(--card-pad); border-left: 1px solid var(--line); }
.strip > div:first-child { border-left: 0; }
/* The caption of a number (in a strip, above a leading number). */
.cap { font-size: var(--t-sm); color: var(--fg-2); }

/* Windows: the cells at the foot of a card, each a label, its value and a meter (`--n` cells in
   a row). The cells draw their own lines to the left and to the top; the edge of the grid cuts
   the outer ones off, so any number of windows wraps cleanly. */
.windows { display: grid; grid-template-columns: repeat(var(--n, 3), minmax(0, 1fr)); border-top: 1px solid var(--line); overflow: hidden; border-radius: 0 0 var(--r-card) var(--r-card); }
.windows > div { display: flex; flex-direction: column; gap: 10px; min-width: 0; margin: -1px 0 0 -1px; padding: 20px var(--card-pad); border-left: 1px solid var(--line); border-top: 1px solid var(--line); }
.windows .top, .meter-head, .timeband-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; font-size: var(--t-sm); color: var(--fg-2); }
.windows .top span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.windows .top b, .meter-text, .timeband-text { flex: none; font-weight: 500; color: var(--fg); font-variant-numeric: tabular-nums; white-space: nowrap; }
.windows .sub { font-size: var(--t-xs); color: var(--fg-3); }

/* Definition list in a card (macro kv). */
.kv { display: flex; flex-direction: column; }
.kv > div { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 40px; border-top: 1px solid var(--line-soft); font-size: var(--t-sm); }
.kv > div:first-child { border-top: 0; }
.kv dt, .kv .k { display: flex; align-items: center; gap: 8px; color: var(--fg-2); }
.kv dd, .kv .v { min-width: 0; color: var(--fg); text-align: right; overflow-wrap: anywhere; }
.kv :is(dd, .v)[data-tone="warn"] { color: var(--warn); }

/* A line of code with its copy button. */
.copyline {
  display: flex; align-items: center; gap: 8px; min-width: 0; height: var(--ctl); padding: 0 4px 0 12px;
  border: 1px solid var(--line); border-radius: var(--r-ctl); background: var(--bg);
  font: 400 var(--t-xs) var(--mono); color: var(--fg-2);
}
.copyline span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- A narrow page (form page, error page) ---------------------------------------------- */

.page.narrow { display: flex; flex-direction: column; gap: var(--gap); max-width: 560px; }
/* In a column with a gap the head keeps the distance it has on every other page. */
.page.narrow > .page-head { margin-bottom: calc(32px - var(--gap)); }

/* --- Meter and timeband (macros meter, timeband) ------------------------------------------
   One bar for every share: <div class="meter" style="--v: .62"><i></i></div>, sizes sm | lg,
   `neutral` for what does not lead. With a label the macro puts the head line (label left, value
   right, as in .windows) above it in a .meter-row. The timeband is the same bar for a time
   window: the fill is what is used of the limit, the mark is now. */

.meter-row, .timeband { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.meter, .timeband-track { display: block; position: relative; height: 6px; border-radius: 3px; background: var(--s4); }
.meter { overflow: hidden; }
.meter > i, .timeband-fill {
  position: absolute; inset: 0; border-radius: inherit; background: var(--accent);
  transform-origin: left center; transform: scaleX(var(--v, 0));
  transition: transform var(--d3) var(--ease), background-color var(--d2) var(--ease);
}
.timeband-fill { transform: scaleX(var(--p, 0)); }
.meter.neutral > i { background: var(--fg-3); }
.meter.sm, .timeband-sm > .timeband-track { height: 4px; border-radius: 2px; }
.meter.lg { height: 8px; border-radius: 4px; }
.meter[data-level="high"] > i, [data-level="high"] > .meter > i, [data-level="high"] > .timeband-track > .timeband-fill { background: var(--warn); }
.meter[data-level="full"] > i, [data-level="full"] > .meter > i, [data-level="full"] > .timeband-track > .timeband-fill { background: var(--err); }
.timeband-now { position: absolute; top: -3px; bottom: -3px; left: var(--x, 0%); width: 2px; margin-left: -1px; border-radius: 1px; background: var(--fg); }
.timeband-scale { display: flex; justify-content: space-between; gap: 12px; font-size: var(--t-xs); color: var(--fg-3); font-variant-numeric: tabular-nums; }
.timeband-now-label { color: var(--fg-2); }

/* --- Components (prototype ui.css, one to one) --------------------------------------------
   card, btn, kbd, badge, dot, tabs, input, select, switch, table, avatar, swap, cmdk and
   the width helpers. Basecoat ships classes of the same names inside @layer; these rules are
   unlayered, so they win, and each one resets what Basecoat would add (padding, shadow). */

/* Card */
.card {
  display: flex; flex-direction: column; gap: 0; min-width: 0; padding: 0; overflow: visible;
  background: var(--s1); border: 1px solid var(--line); border-radius: var(--r-card); box-shadow: none;
  color: var(--fg); font-size: inherit; line-height: inherit;
}
.card-head { display: flex; align-items: center; gap: 12px; padding: 20px var(--card-pad) 0; min-height: 56px; }
.card-head h2 { font-size: var(--t-base); font-weight: 500; line-height: 1.4; white-space: nowrap; }
.card-head p { font-size: var(--t-sm); color: var(--fg-3); white-space: nowrap; }
.card-head .end { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.card-body { padding: var(--card-pad); flex: 1; min-width: 0; }
.card-foot {
  display: flex; align-items: center; gap: 12px; padding: 12px var(--card-pad);
  border-top: 1px solid var(--line); font-size: var(--t-sm); color: var(--fg-3);
}
.card-foot .end { margin-left: auto; }
.card > .table-wrap:last-child { border-radius: 0 0 var(--r-card) var(--r-card); }
.link { color: var(--fg-2); display: inline-flex; align-items: center; gap: 4px; transition: color var(--d1) var(--ease); }
.link:hover { color: var(--fg); }

/* Button: .btn plus primary | secondary | ghost | danger, sizes sm | lg | icon | block. Without a
   variant a .btn is primary (as in Basecoat). */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: var(--ctl); padding: 0 14px;
  border-radius: var(--r-ctl); border: 1px solid transparent; box-shadow: none;
  background: var(--accent-solid); color: var(--on-accent);
  font-size: var(--t-sm); font-weight: 500; white-space: nowrap; cursor: pointer;
  transition: background-color var(--d1) var(--ease), border-color var(--d1) var(--ease),
    color var(--d1) var(--ease), transform var(--d1) var(--ease);
}
.btn:is(:hover, :active) { background: var(--accent-solid-h); }
.btn:active { transform: scale(.98); }
.btn.secondary { background: var(--s2); border-color: var(--line-2); color: var(--fg); }
.btn.secondary:is(:hover, :active) { background: var(--s4); }
.btn.ghost { background: transparent; color: var(--fg-2); }
.btn.ghost:is(:hover, :active) { background: var(--s2); color: var(--fg); }
.btn.danger { background: var(--err-tint); border-color: var(--err-line); color: var(--err-fg); }
.btn.danger:is(:hover, :active) { background: var(--err-tint-2); }
.btn.sm { height: 28px; padding: 0 10px; border-radius: var(--r-sm); font-size: var(--t-xs); gap: 6px; }
.btn.lg { height: 40px; }
.btn.icon { width: var(--ctl); padding: 0; }
.btn.icon.sm { width: 28px; padding: 0; }
.btn.block { width: 100%; }
.btn:is(:disabled, [aria-disabled="true"]) { opacity: .5; pointer-events: none; }

/* Keycap */
.kbd {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; border-radius: var(--r-xs);
  background: var(--s3); border: 1px solid var(--line-2); border-bottom-width: 2px; color: var(--fg-2);
  font: 500 11px/1 var(--sans);
}

/* Badge: a state, never decoration. */
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border-radius: var(--r-sm);
  font-size: var(--t-xs); font-weight: 500; white-space: nowrap;
  background: var(--s3); color: var(--fg-2); border: 1px solid var(--line);
}
.badge.accent { background: var(--accent-tint); color: var(--accent-fg); border-color: transparent; }
.badge.ok { background: var(--ok-tint); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-tint); color: var(--warn); border-color: transparent; }
.badge.err { background: var(--err-tint); color: var(--err-fg); border-color: transparent; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--fg-3); flex: none; }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.err { background: var(--err); }
.dot.accent { background: var(--accent); }
.dot.sm { width: 6px; height: 6px; }
/* Only for what is live right now (a running request, a stream). */
.dot.live { position: relative; }
.dot.live::after { content: ''; position: absolute; inset: 0; border-radius: 50%; background: inherit; animation: ping 2s var(--ease) infinite; }
@keyframes ping { 0% { transform: scale(1); opacity: .6; } 70%, 100% { transform: scale(2.6); opacity: 0; } }

/* Tabs (segmented): buttons with aria-selected, or links with aria-current. */
.tabs {
  display: inline-flex; flex-direction: row; align-items: stretch; padding: 3px; gap: 2px; height: var(--ctl);
  border-radius: var(--r-ctl); background: var(--s2); border: 1px solid var(--line);
}
.tabs button, .tabs a {
  display: inline-flex; align-items: center; padding: 0 12px; border: 0; border-radius: calc(var(--r-ctl) - 3px);
  background: transparent; font-size: var(--t-sm); font-weight: 500; color: var(--fg-2); white-space: nowrap; cursor: pointer;
  transition: background-color var(--d1) var(--ease), color var(--d1) var(--ease);
}
.tabs button:hover, .tabs a:hover { color: var(--fg); }
.tabs button:is([aria-selected=true], [aria-pressed=true]), .tabs a[aria-current] { background: var(--s4); color: var(--fg); box-shadow: inset 0 0 0 1px var(--line); }
.tabs.sm { height: 32px; }
.tabs.sm button, .tabs.sm a { padding: 0 10px; font-size: var(--t-xs); }

/* Input (a wrapper around <input>, or the <input> itself) and the look of a select trigger.
   Real choices use the macro select_box; `.select.sel` is its Basecoat root and stays unstyled. */
.field { display: flex; flex-direction: column; gap: 8px; }
.field label { font-size: var(--t-sm); font-weight: 500; color: var(--fg); }
.input, .select:not(.sel) {
  display: flex; align-items: center; gap: 8px; height: var(--ctl); padding: 0 12px; border-radius: var(--r-ctl);
  background: var(--s1); border: 1px solid var(--line-2); box-shadow: none; font-size: var(--t-sm); color: var(--fg); min-width: 0;
  transition: border-color var(--d1) var(--ease), box-shadow var(--d1) var(--ease), background-color var(--d1) var(--ease);
}
.input input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; height: 100%; }
.input input::placeholder { color: var(--fg-3); }
.input .i, .input .ic, .select:not(.sel) .i, .select:not(.sel) .ic { color: var(--fg-3); }
.input:focus-visible { outline: 0; }
.input:focus-within, .input.is-focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint-2); }
.select:not(.sel) { width: auto; background-image: none; appearance: none; cursor: pointer; color: var(--fg-2); white-space: nowrap; }
.select:not(.sel) b { font-weight: 400; color: var(--fg); }
.select:not(.sel):hover { background-color: var(--s2); border-color: var(--line-2); }
.select:not(.sel) .i:last-child, .select:not(.sel) .ic:last-child { margin-left: auto; }

/* Switch: <button class="switch" role="switch" aria-checked>. */
.switch { width: 32px; height: 18px; border-radius: 9px; background: var(--s4); position: relative; flex: none; transition: background-color var(--d2) var(--ease); }
.switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--on-accent); transition: transform var(--d2) var(--ease); }
.switch[aria-checked=true], input.switch:checked { background: var(--accent-solid); }
.switch[aria-checked=true]::after, input.switch:checked::after { transform: translateX(14px); }
/* The same switch as a form control: <input type="checkbox" role="switch" class="switch">. */
input.switch { appearance: none; margin: 0; border: 0; cursor: pointer; }
.switch:disabled { opacity: .5; cursor: default; }
/* The form switch with its label (macro switch_field). */
.switch-field { display: inline-flex; align-items: center; gap: 12px; min-height: var(--ctl); font-size: var(--t-sm); color: var(--fg); cursor: pointer; }
.switch-field:has(:disabled) { color: var(--fg-3); cursor: default; }

/* Table (inside a card: <div class="table-wrap"><table class="table">). */
.card > .table-wrap, .card-body > .table-wrap { border: 0; border-radius: 0; background: transparent; }
.table { width: 100%; border-collapse: collapse; font-size: var(--t-sm); }
.table tr { border: 0; background: transparent; }
.table th {
  height: 40px; padding: 0 12px; text-align: left; white-space: nowrap;
  font-weight: 400; font-size: var(--t-xs); color: var(--fg-3); border-bottom: 1px solid var(--line);
}
.table td { height: var(--row); padding: 0 12px; border-bottom: 1px solid var(--line-soft); white-space: nowrap; color: var(--fg-2); }
.table tr:last-child td { border-bottom: 0; }
.table th:first-child, .table td:first-child { padding-left: var(--card-pad); }
.table th:last-child, .table td:last-child { padding-right: var(--card-pad); }
.table tbody tr { transition: background-color var(--d1) var(--ease); }
.table tbody tr:hover { background: var(--s2); }
.table tbody tr.is-active { background: var(--accent-tint); }
.table tbody tr.is-active td:first-child { box-shadow: inset 2px 0 0 var(--accent); }
.table .r { text-align: right; }
.table .strong { color: var(--fg); }
.table .cell { display: flex; align-items: center; gap: 8px; }
/* A row that just arrived (live data only, never on load). */
@keyframes row-in {
  from { opacity: 0; transform: translateY(-6px); background: var(--accent-tint-2); }
  40% { opacity: 1; transform: none; background: var(--accent-tint-2); }
  to { background: transparent; }
}
.table tbody tr.is-new { animation: row-in 1.6s var(--ease); }

/* Avatar */
.avatar, .gl-avatar {
  display: grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: 50%;
  background: var(--s4); border: 1px solid var(--line); font-size: 11px; font-weight: 500; color: var(--fg);
}
.avatar.lg, .gl-avatar.lg { width: 40px; height: 40px; font-size: var(--t-sm); }
.avatar.accent { background: var(--accent-tint-2); color: var(--accent-fg); border-color: transparent; }

/* A number that changes live: out, then in (gl.swap in app.js). */
.swap { display: inline-block; }
.swap.out { animation: swap-out var(--d1) var(--ease) forwards; }
.swap.in { animation: swap-in var(--d2) var(--ease); }
@keyframes swap-out { to { opacity: 0; transform: translateY(-4px); } }
@keyframes swap-in { from { opacity: 0; transform: translateY(4px); } }

/* Command palette */
.cmdk-overlay {
  position: fixed; inset: 0; z-index: var(--z-overlay); background: var(--overlay);
  display: grid; justify-items: center; align-items: start; padding-top: 16vh;
  opacity: 0; pointer-events: none; transition: opacity var(--d2) var(--ease);
}
.cmdk-overlay.open { opacity: 1; pointer-events: auto; }
.cmdk {
  width: min(600px, calc(100vw - 32px)); overflow: hidden;
  background: var(--s2); border: 1px solid var(--line-2); border-radius: var(--r-card); box-shadow: var(--shadow-overlay);
  transform: translateY(8px) scale(.985); transition: transform var(--d2) var(--ease);
}
.cmdk-overlay.open .cmdk { transform: none; }
.cmdk-input { display: flex; align-items: center; gap: 12px; height: 52px; padding: 0 16px; border-bottom: 1px solid var(--line); color: var(--fg-3); }
.cmdk-input input { flex: 1; background: none; border: 0; outline: 0; font-size: var(--t-lg); color: var(--fg); }
.cmdk-input input::placeholder { color: var(--fg-3); }
.cmdk-list { padding: 8px; max-height: 360px; overflow: auto; }
.cmdk-group { padding: 8px 8px 4px; font-size: var(--t-xs); color: var(--fg-3); }
.cmdk-item { display: flex; align-items: center; gap: 12px; height: 40px; padding: 0 8px; border-radius: var(--r-ctl); color: var(--fg-2); font-size: var(--t-base); }
.cmdk-item .keys { margin-left: auto; display: flex; gap: 3px; }
.cmdk-item.sel { background: var(--accent-tint); color: var(--fg); }
.cmdk-item.sel .i, .cmdk-item.sel .ic { color: var(--accent-fg); }
.cmdk-foot { display: flex; gap: 16px; align-items: center; height: 40px; padding: 0 16px; border-top: 1px solid var(--line); font-size: var(--t-xs); color: var(--fg-3); }
.cmdk-foot span { display: inline-flex; gap: 6px; align-items: center; }

/* Width helpers: mobile up to 760 px, WQHD from 2200 px. */
@media (max-width: 760px) {
  .hide-m, .mid-only { display: none !important; }
  .table th, .table td { padding: 0 6px; }
}
@media (max-width: 2199px) { .wq-only { display: none !important; } }
@media (min-width: 2200px) { .brand-mark { height: 28px; } }
@media (min-width: 2200px) { .mid-only { display: none !important; } }
@media (min-width: 761px) { .m-only { display: none !important; } }

/* --- Forms: field, select_box, multi_box (Basecoat popovers in our surfaces) ------------- */

.textarea {
  padding: 8px 12px; border-radius: var(--r-ctl); background: var(--s1); border: 1px solid var(--line-2); box-shadow: none;
  font-size: var(--t-sm); color: var(--fg);
  transition: border-color var(--d1) var(--ease), box-shadow var(--d1) var(--ease);
}
.textarea::placeholder, input.input::placeholder { color: var(--fg-3); }
.textarea:focus-visible { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint-2); }
.form { display: flex; flex-direction: column; gap: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid > [data-span="2"] { grid-column: span 2; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.field { min-width: 0; }
.field-help { font-size: var(--t-xs); color: var(--fg-3); }
.field-error { font-size: var(--t-xs); color: var(--err-fg); }
.field.invalid .input, .field.invalid .textarea, .field.invalid .sel > .btn { border-color: var(--err); }

/* select_box: its button looks like the prototype's select, the list is a popover on --s2. */
.sel { position: relative; min-width: 0; }
.sel > .btn {
  width: 100%; justify-content: flex-start; gap: 8px; padding: 0 12px; font-weight: 400;
  background: var(--s1); border-color: var(--line-2); color: var(--fg);
}
.sel > .btn:is(:hover, :active, [aria-expanded="true"]) { background: var(--s2); }
.sel > .btn > [data-value] { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
.sel > .btn > .text-muted-foreground { color: var(--fg-3); }
.sel-label { font-size: var(--t-sm); color: var(--fg-2); }
.sel-chev, .sel-ic { color: var(--fg-3); }
.sel-sm > .btn { height: 32px; }
.sel [data-popover], .multi [data-popover], .dropdown-menu > [data-popover] {
  padding: 4px; background: var(--s2); border: 1px solid var(--line-2); border-radius: var(--r-ctl); box-shadow: var(--shadow-overlay);
}
.sel [role="option"], .multi [role="option"], [role="menu"] [role^="menuitem"] {
  display: flex; align-items: center; gap: 8px; width: 100%; min-height: 32px; padding: 0 8px;
  border-radius: var(--r-sm); font-size: var(--t-sm); color: var(--fg-2); text-align: left; cursor: pointer;
}
.sel [role="option"], .multi [role="option"] { justify-content: space-between; gap: 12px; }
.sel [role="option"]:is(:hover, .active, [aria-selected="true"]), .multi [role="option"]:is(:hover, .active, [aria-selected="true"]),
[role="menu"] [role^="menuitem"]:is(:hover, .active, :focus-visible) { background: var(--s4); color: var(--fg); }
[role="menu"] [role^="menuitem"] > .ic { color: var(--fg-3); }
[role="menu"] > form { display: contents; }
.opt-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opt-hint { flex: none; font: 400 var(--t-xs) var(--mono); color: var(--fg-3); }
[role="listbox"]:empty::after, [role="listbox"][data-no-match]::after {
  content: attr(data-empty); display: block; padding: 12px; font-size: var(--t-sm); color: var(--fg-3);
}

/* --- Overlays: dialog, toast, command palette --------------------------------------------- */

.dialog::backdrop { background: var(--overlay); }
.dialog > article {
  padding: 24px; gap: 20px; background: var(--s2); border: 1px solid var(--line-2); border-radius: var(--r-card);
  box-shadow: var(--shadow-overlay); color: var(--fg);
}
.dialog[open] > article { animation: gl-dialog-in var(--d2) var(--ease); }
@keyframes gl-dialog-in { from { opacity: 0; transform: translateY(8px) scale(.985); } }
.dlg-head { position: relative; display: flex; flex-direction: column; gap: 4px; padding-right: 40px; }
.dlg-head > :is(h1, h2) { font-size: var(--t-lg); font-weight: 500; line-height: 1.4; }
.dlg-head > p { font-size: var(--t-sm); color: var(--fg-2); }
.dlg-close { position: absolute; top: -4px; right: -4px; }
.dialog[data-loading] [data-dlg-body] { min-height: 160px; }

.gl-toaster {
  position: fixed; right: 0; bottom: 0; z-index: var(--z-toast);
  display: flex; flex-direction: column-reverse; gap: 8px; width: 100%; max-width: 400px; padding: 16px; pointer-events: none;
}
.gl-toast {
  display: flex; align-items: flex-start; gap: 12px; pointer-events: auto; padding: 12px 16px;
  border-radius: var(--r-card); background: var(--s2); border: 1px solid var(--line-2); box-shadow: var(--shadow-overlay);
  font-size: var(--t-sm); color: var(--fg-2);
  animation: gl-toast-in var(--d2) var(--ease);
  transition: opacity var(--d1) var(--ease), transform var(--d1) var(--ease);
}
.gl-toast[data-leaving] { opacity: 0; transform: translateY(4px); }
@keyframes gl-toast-in { from { opacity: 0; transform: translateY(4px); } }
.gl-toast > .ic { margin-top: 2px; }
.gl-toast[data-kind="success"] > .ic { color: var(--ok); }
.gl-toast[data-kind="error"] > .ic { color: var(--err); }
.gl-toast[data-kind="warning"] > .ic { color: var(--warn); }
.gl-toast-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.gl-toast-title { font-weight: 500; color: var(--fg); }

/* The palette is a <dialog> (focus trap, Escape) in the form of the prototype's cmdk. */
.palette > .cmdk { width: min(600px, calc(100vw - 32px)); max-width: none; padding: 0; gap: 0; transform: none; transition: none; }
.palette .cmdk-input > .ic { flex: none; }
.palette .cmdk-input input { min-width: 0; height: 100%; }
.cmdk-list:empty::after { content: attr(data-empty); display: block; padding: 12px 8px; font-size: var(--t-sm); color: var(--fg-3); }
.cmdk-item { width: 100%; border: 0; background: transparent; text-align: left; cursor: pointer; }
.cmdk-item > span:first-of-type { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmdk-item > .ic { color: var(--fg-3); }
.cmdk-foot .kbd + .kbd { margin-left: -3px; }

/* --- Content parts: table, pager, empty, copy, chip, code, skeleton, banner --------------- */

/* A table outside a card wears the card's frame itself. */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-card); background: var(--s1); }

.pager { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.pager-label { margin-right: auto; font-size: var(--t-sm); color: var(--fg-3); }
.card-foot > .pager { flex: 1; }

/* Empty state: an icon in a small frame, one sentence, at most one action. */
.gl-empty { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 40px 24px; text-align: center; color: var(--fg-2); }
.gl-empty > .ic {
  box-sizing: content-box; width: 16px; height: 16px; margin-bottom: 12px; padding: 11px;
  border: 1px solid var(--line); border-radius: var(--r-ctl); background: var(--s2); color: var(--fg-2);
}
.gl-empty-title { font-weight: 500; color: var(--fg); }
.gl-empty-text { max-width: 48ch; font-size: var(--t-sm); }
.gl-empty-action { margin-top: 16px; }

.copy-btn { position: relative; }
.copy-btn .copy-ic, .copy-btn .copy-ok { display: inline-flex; transition: opacity var(--d1) var(--ease); }
.copy-btn .copy-ok { position: absolute; left: 0; top: 0; width: 28px; height: 100%; align-items: center; justify-content: center; opacity: 0; color: var(--ok); }
.copy-btn:not(.sm) .copy-ok { width: var(--ctl); }
.copy-btn[data-copied] .copy-ic { opacity: 0; }
.copy-btn[data-copied] .copy-ok { opacity: 1; }
[data-copy]:not(button) { cursor: copy; }

.chip {
  display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px;
  border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--s3);
  font: 400 var(--t-xs) var(--mono); color: var(--fg-2); white-space: nowrap;
}

/* Code inside a sentence, wherever prose stands (an answer in the chat, the API guide): one chip. */
.chat-body :not(pre) > code, .guide :is(p, li, .guide-opts) code.mono {
  padding: 1px 5px; border: 1px solid var(--line); border-radius: var(--r-xs); background: var(--s2);
  font: 400 .88em var(--mono); color: var(--fg); overflow-wrap: anywhere;
}
.code { border: 1px solid var(--line); border-radius: var(--r-card); background: var(--bg); overflow: hidden; }
.code-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 40px; padding: 0 8px 0 16px;
  border-bottom: 1px solid var(--line); background: var(--s1); font: 400 var(--t-xs) var(--mono); color: var(--fg-3);
}
.code > pre { margin: 0; padding: 16px; overflow-x: auto; font-size: var(--t-sm); line-height: 1.6; color: var(--fg); }
.code .tok-key { color: var(--accent-fg); }
.code .tok-str { color: var(--code-string); }
.code .tok-dim { color: var(--fg-3); }

/* Skeleton: a still bar; nothing shimmers. */
.gl-skeleton { display: block; height: 12px; border-radius: var(--r-xs); background: var(--s3); }

.banner {
  display: flex; align-items: flex-start; gap: 12px; padding: 12px 16px;
  border-radius: var(--r-ctl); border: 1px solid var(--line); background: var(--s2); font-size: var(--t-sm); color: var(--fg-2);
}
.banner > .ic { margin-top: 2px; }
.banner[data-kind="error"] { background: var(--err-tint); border-color: var(--err-line); color: var(--fg); }
.banner[data-kind="error"] > .ic { color: var(--err); }
.banner[data-kind="warning"] { background: var(--warn-tint); border-color: transparent; color: var(--fg); }
.banner[data-kind="warning"] > .ic { color: var(--warn); }
/* A notice of the whole page stands between the page head and the grid. */
.banner.page-note { margin-bottom: var(--gap); }

.form-card { gap: 20px; padding: var(--card-pad); }
.error-card { gap: 12px; align-items: flex-start; padding: var(--card-pad); }
.error-status { font: 400 var(--t-xs) var(--mono); color: var(--fg-3); }
.error-title { font-size: var(--t-h1); font-weight: 500; letter-spacing: -.02em; line-height: 1.25; }
.error-text { color: var(--fg-2); }
.error-actions { display: flex; gap: 8px; margin-top: 12px; }
.error-meta { font-size: var(--t-xs); color: var(--fg-3); }

/* --- Mobile (up to 760 px): the sidebar is a drawer behind the menu button ---------------- */

@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .gl-sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(288px, 86vw); padding-bottom: max(12px, env(safe-area-inset-bottom));
    background: var(--s1); transform: translateX(-100%); visibility: hidden;
    transition: transform var(--d3) var(--ease), visibility 0s linear var(--d3);
  }
  .nav-open .gl-sidebar { transform: none; visibility: visible; transition-delay: 0s; }
  .nav a { height: 40px; }
  .gl-scrim {
    display: block; position: fixed; inset: 0; z-index: calc(var(--z-sidebar) - 1); border: 0; background: var(--overlay);
    opacity: 0; pointer-events: none; transition: opacity var(--d3) var(--ease);
  }
  .nav-open .gl-scrim { opacity: 1; pointer-events: auto; }
  .top-status, .search-btn span, .search-btn .keys, .crumbs .root, .crumbs .sep { display: none; }
  .topbar .menu-btn { display: inline-flex; margin-left: -6px; }
  .search-btn { width: 32px; padding: 0; justify-content: center; border-color: transparent; background: none; color: var(--fg-2); }
  .topbar { gap: 8px; }
  .top-right { gap: 8px; }
  .content { padding: 24px var(--pad) 48px; }
  .page-head { flex-direction: column; align-items: stretch; margin-bottom: 24px; }
  .page.narrow > .page-head { margin-bottom: calc(24px - var(--gap)); }
  .page-head .actions { margin-left: 0; }
  .page-head .actions :is(.btn, form) { flex: 1; }
  /* Tabs that do not fit roll inside their own line, the page never scrolls sideways. */
  .page-head .actions > .tabs, .card-head .tabs { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
  .tabs > :is(a, button) { flex: none; }
  .windows { grid-template-columns: minmax(0, 1fr); }
  .windows > div { padding: 16px var(--card-pad); }
  .strip, .card.strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .strip > div:nth-child(odd) { border-left: 0; }
  .strip > div:nth-child(n + 3) { border-top: 1px solid var(--line); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid > [data-span="2"] { grid-column: auto; }
  .gl-toaster { max-width: none; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
}
@media (min-width: 761px) and (max-width: 1100px) {
  .search-btn { width: 200px; }
}

/* --- Reduced motion (Settings or the system): what animates here stands still -------------- */

:root[data-motion="reduced"] :is(.dialog[open] > article, .gl-toast, .table tbody tr.is-new, .swap.out, .swap.in),
:root[data-motion="reduced"] .dot.live::after { animation: none; }
:root[data-motion="reduced"] .btn:active { transform: none; }
@media (prefers-reduced-motion: reduce) {
  :root:not([data-motion="full"]) :is(.dialog[open] > article, .gl-toast, .table tbody tr.is-new, .swap.out, .swap.in),
  :root:not([data-motion="full"]) .dot.live::after { animation: none; }
  :root:not([data-motion="full"]) .btn:active { transform: none; }
}
