/*
  components.css: the shared component library (DESIGN 4) and the global shell.

  Masthead, provenance bar, colophon, session banner, buttons, fields, segmented
  controls, tabs, chips, badges, pills, cards, notes, banners, footnotes,
  glossary terms, definition lists, state blocks, skeletons, refetch progress,
  toasts, drawers, dialogs, menus, popovers, tooltips, the About popover, the
  command palette, coach marks, the shortcuts sheet and code cards.

  Rules: semantic tokens from foundation.css only; no raw colors (system colors
  appear only under forced-colors). State is styled from ARIA and native
  attributes (aria-pressed, aria-selected, aria-checked, aria-current,
  aria-expanded, aria-busy, aria-invalid, aria-disabled, disabled, hidden);
  foundation.css makes [hidden] win. Motion sits inside prefers-reduced-motion:
  no-preference. Breakpoints: phone below 600, tablet 600, desktop 960, wide 1280.

  Part names beside the DESIGN 4 vocabulary (a name after a slash is an alias):
    shell   masthead, masthead__inner, masthead__lockup / masthead__brand,
            masthead__logo, masthead__names / masthead__wordmark, masthead__org,
            masthead__product, masthead__menu-btn, masthead__nav (optional
            masthead__nav-list), masthead__link / masthead__nav-link,
            masthead__tools / masthead__actions, cmd-btn / masthead__command,
            cmd-btn__label / masthead__command-label, cmd-btn__keys /
            masthead__kbd, theme-toggle, user-menu (its .menu child is the
            panel), user-btn / user-menu__trigger, user-btn__name /
            user-menu__name, avatar, provenance-bar / provenance, their __inner,
            provenance-bar__lead / provenance__data, provenance-bar__slot /
            provenance__readings, dataset-pill__glyph, dataset-pill__info,
            colophon, colophon__line, colophon__meta, colophon__item,
            session-slot (fixed under the shell)
    parts   banner__icon, banner__text, banner__lead, banner__actions,
            banner__action, toast__icon, toast__body, toast__title, toast__text,
            toast__detail, toast__action, toast__close, menu__list,
            menu__identity, menu__note, menu__label, menu__item--danger,
            popover__head, popover__title, popover__close, popover__body,
            popover__note, popover__reason, about, about__section, about__id,
            about__check(--tone), about__links, about__link, dialog__head,
            dialog__title, dialog__body, dialog__foot, drawer__title,
            drawer__crumbs, drawer__close, state__icon, state__title,
            state__body, state__actions, state__details, status-pill__dot,
            chip__count, search__clear, palette__input, palette__list,
            palette__group, palette__option, palette__meta, palette__empty,
            palette__foot, coach__step, coach__title, coach__body,
            coach__actions, code-card__head, code-card__lang, code-card__body,
            code-card__toggle, code lines (.line), SQL tokens tok-kw, tok-fn,
            tok-str, tok-num, tok-com
    extras  spinner, kbd, state--compact, alert--compact, status-pill--on/--off
    roles   input[role="switch"], .menu [role^="menuitem"], .palette
            [role="combobox" | "listbox" | "option"], .seg [role="radio"]
  Pages may set --drawer-w on their drawer and --toast-offset on body. Body
  exposes --shell-sticky-top (0 on phones, masthead plus provenance height above).
*/

/* ---------- Helpers and tone families ---------- */
.spinner {
  display: inline-block; flex: none; width: 1em; height: 1em; border: 2px solid currentColor;
  border-right-color: transparent; border-radius: 50%; vertical-align: -0.15em;
}

:where(kbd),
.kbd {
  display: inline-block; min-width: 1.6em; padding: 1px 5px; border: 1px solid var(--c-line-strong);
  border-bottom-width: 2px; border-radius: var(--r-1); background: var(--c-surface); color: var(--c-ink-2);
  font-family: var(--font-mono); font-size: var(--fs-label); line-height: var(--lh-label); text-align: center;
  white-space: nowrap;
}

/* Tone families shared by badges, notes, banners, pills, state blocks, toasts and checklist rows. */
.badge, .alert, .banner, .status-pill, .state, .toast, .about__check {
  --tone: var(--c-neutral-base); --tone-ink: var(--c-neutral-ink); --tone-wash: var(--c-neutral-wash);
}
.badge--good, .alert-good, .banner--good, .status-pill--good, .status-pill--on, .toast--good, .toast--success,
.about__check--good {
  --tone: var(--c-good-base); --tone-ink: var(--c-good-ink); --tone-wash: var(--c-good-wash);
}
.badge--watch, .alert-watch, .banner--watch, .banner--session, .status-pill--watch, .state--unavailable,
.toast--watch, .toast--warning, .about__check--watch {
  --tone: var(--c-watch-base); --tone-ink: var(--c-watch-ink); --tone-wash: var(--c-watch-wash);
}
.badge--critical, .alert-urgent, .banner--critical, .status-pill--critical, .state--error,
.toast--critical, .toast--error, .about__check--critical {
  --tone: var(--c-critical-base); --tone-ink: var(--c-critical-ink); --tone-wash: var(--c-critical-wash);
}
.badge--info, .alert-info, .banner--info, .status-pill--info, .toast--info, .about__check--info {
  --tone: var(--c-info-base); --tone-ink: var(--c-info-ink); --tone-wash: var(--c-info-wash);
}
.badge--accent { --tone: var(--c-accent); --tone-ink: var(--c-accent-ink); --tone-wash: var(--c-accent-wash); }

/* ---------- Masthead ---------- */
.masthead {
  position: relative; z-index: var(--z-masthead); border-bottom: 1px solid var(--c-line);
  background: var(--c-surface); color: var(--c-ink);
}
.masthead__inner {
  display: flex; align-items: center; gap: var(--sp-2) var(--sp-3); min-height: var(--masthead-h);
  padding: 0 var(--gutter);
}
.masthead__lockup, .masthead__brand {
  display: flex; flex: 0 1 auto; align-items: center; gap: var(--sp-2); min-width: 0; max-width: 22rem;
  border-radius: var(--r-1); color: var(--c-ink); text-decoration: none;
}
:is(.masthead__lockup, .masthead__brand):hover .masthead__org { text-decoration: underline; text-underline-offset: 3px; }
.masthead__logo { display: block; flex: none; width: auto; height: 32px; max-width: 7.5rem; object-fit: contain; }
.masthead__names, .masthead__wordmark { display: grid; min-width: 0; line-height: 1.25; }
.masthead__org, .masthead__product { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.masthead__org { color: var(--c-ink); font-size: var(--fs-h3); font-weight: var(--fw-semibold); }
.masthead__product { color: var(--c-muted); font-size: var(--fs-label); font-weight: var(--fw-medium); }
.masthead .masthead__menu-btn { display: none; }
.masthead__nav, .masthead__nav-list {
  display: flex; align-items: stretch; gap: var(--sp-1); margin: 0; padding: 0; list-style: none;
}
.masthead__nav { align-self: stretch; margin-left: var(--sp-4); }
.masthead__nav-list > li { display: flex; }
.masthead__link, .masthead__nav-link {
  position: relative; display: inline-flex; align-items: center; gap: var(--sp-2); padding: 0 var(--sp-3);
  color: var(--c-ink-2); font-size: var(--fs-ui); font-weight: var(--fw-medium); text-decoration: none;
  white-space: nowrap;
}
:is(.masthead__link, .masthead__nav-link):hover { color: var(--c-ink); box-shadow: inset 0 -3px 0 var(--c-line-strong); }
:is(.masthead__link, .masthead__nav-link):focus-visible { outline-offset: -2px; }
:is(.masthead__link, .masthead__nav-link) :is(svg, .icon) { width: 18px; height: 18px; }
:is(.masthead__link, .masthead__nav-link)[aria-current]:not([aria-current="false"]) {
  color: var(--c-ink); font-weight: var(--fw-semibold); box-shadow: none;
}
:is(.masthead__link, .masthead__nav-link)[aria-current]:not([aria-current="false"])::after {
  content: ""; position: absolute; right: var(--sp-3); bottom: 0; left: var(--sp-3); height: 3px;
  border-radius: 3px 3px 0 0; background: var(--c-accent);
}
.masthead__tools, .masthead__actions { display: flex; flex: none; align-items: center; gap: var(--sp-1); margin-left: auto; }

.cmd-btn, .masthead__command {
  display: inline-flex; align-items: center; gap: var(--sp-2); min-width: 13rem; min-height: var(--control-h);
  padding: 0 var(--sp-2) 0 var(--sp-3); border: 1px solid var(--c-line-strong); border-radius: var(--r-2);
  background: var(--c-surface-2); color: var(--c-muted); font: inherit; font-size: var(--fs-ui); cursor: pointer;
}
:is(.cmd-btn, .masthead__command):hover { background: var(--c-surface-3); color: var(--c-ink-2); }
:is(.cmd-btn, .masthead__command) > :is(svg, .icon) { width: 18px; height: 18px; }
.cmd-btn__label, .masthead__command-label { flex: 1 1 auto; text-align: left; white-space: nowrap; }
.cmd-btn__keys { display: inline-flex; gap: 2px; }

.icon-btn.theme-toggle[aria-pressed="true"] { border-color: transparent; background: transparent; color: var(--c-ink-2); }
.icon-btn.theme-toggle[aria-pressed="true"]:hover { background: var(--c-surface-2); color: var(--c-ink); }
.theme-icon { display: inline-block; font-family: var(--font-sans); font-size: 1.125rem; line-height: 1; }

.user-menu { position: relative; display: flex; }
.user-btn, .user-menu__trigger {
  display: inline-flex; align-items: center; gap: var(--sp-2); min-height: var(--control-h); max-width: 14rem;
  padding: 0 var(--sp-2) 0 3px; border: 1px solid var(--c-line-strong); border-radius: var(--r-pill);
  background: var(--c-surface); color: var(--c-ink); font: inherit; font-size: var(--fs-ui);
  font-weight: var(--fw-medium); cursor: pointer;
}
:is(.user-btn, .user-menu__trigger):hover { background: var(--c-surface-2); }
:is(.user-btn, .user-menu__trigger)[aria-expanded="true"] { background: var(--c-surface-3); }
.user-btn__name, .user-menu__name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
:is(.user-btn, .user-menu__trigger) > :is(svg, .icon):last-child { width: 16px; height: 16px; color: var(--c-muted); }
:is(.user-btn, .user-menu__trigger)[aria-expanded="true"] > :is(svg, .icon):last-child { transform: rotate(180deg); }
.user-menu > .menu { position: absolute; top: calc(100% + 6px); right: 0; width: max-content; min-width: 15rem; }

.avatar {
  display: inline-grid; flex: none; place-items: center; width: 28px; height: 28px; border-radius: 50%;
  background: var(--c-accent); color: var(--c-on-accent); font-size: var(--fs-label);
  font-weight: var(--fw-bold); letter-spacing: 0.02em; text-transform: uppercase;
}
.avatar :is(svg, .icon) { width: 16px; height: 16px; }
.header-email { color: var(--c-ink-2); font-size: var(--fs-small); overflow-wrap: anywhere; }

@media (min-width: 600px) {
  .masthead { position: sticky; top: 0; }
}

@media (max-width: 1279.98px) {
  .cmd-btn, .masthead__command { min-width: 0; }
  .cmd-btn__label, .cmd-btn__keys, .masthead__command-label, .masthead__kbd { display: none; }
  .user-btn__name, .user-menu__name { display: none; }
}

@media (max-width: 959.98px) {
  .masthead .masthead__menu-btn { display: inline-grid; }
  .masthead__nav { display: none; }
  .masthead:has(.masthead__menu-btn[aria-expanded="true"]) .masthead__nav {
    position: absolute; top: 100%; right: 0; left: 0; display: flex; flex-direction: column; gap: 2px;
    margin: 0; padding: var(--sp-2) var(--gutter) var(--sp-3); border-bottom: 1px solid var(--c-line);
    background: var(--c-surface); box-shadow: var(--e-2);
  }
  .masthead__nav-list { flex-direction: column; gap: 2px; }
  .masthead__link, .masthead__nav-link { flex: 1 1 auto; min-height: max(40px, var(--hit)); border-radius: var(--r-1); }
  :is(.masthead__link, .masthead__nav-link):hover { background: var(--c-surface-2); box-shadow: none; }
  :is(.masthead__link, .masthead__nav-link)[aria-current]:not([aria-current="false"]) { background: var(--c-accent-wash); }
  :is(.masthead__link, .masthead__nav-link)[aria-current]:not([aria-current="false"])::after {
    top: var(--sp-2); right: auto; bottom: var(--sp-2); left: 0; width: 3px; height: auto;
    border-radius: 0 3px 3px 0;
  }
  .cmd-btn, .masthead__command {
    justify-content: center; width: var(--control-h); padding: 0; border-color: transparent;
    background: transparent; color: var(--c-ink-2);
  }
  .cmd-btn__label, .cmd-btn__keys, .masthead__command-label, .masthead__kbd { display: none; }
}

@media (max-width: 599.98px) {
  .masthead__inner { gap: var(--sp-1); }
  .masthead__org { font-size: var(--fs-ui); }
  .masthead__product { display: none; }
  .masthead__logo { height: 28px; max-width: 5.5rem; }
  .user-btn, .user-menu__trigger { padding: 0 3px; }
  .user-btn__name, .user-menu__name, :is(.user-btn, .user-menu__trigger) > :is(svg, .icon):last-child {
    display: none;
  }
}

@media (max-width: 359.98px) {
  .masthead__names, .masthead__wordmark { display: none; }
}

/* ---------- Provenance bar, dataset pill, micro-label, colophon ---------- */
.provenance-bar, .provenance {
  position: relative; z-index: var(--z-sticky); border-bottom: 1px solid var(--c-line);
  background: var(--c-surface-2); color: var(--c-ink-2); font-size: var(--fs-small); line-height: var(--lh-small);
}
.provenance-bar__inner, .provenance__inner {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-1) var(--sp-3);
  min-height: var(--provenance-h); padding: 3px var(--gutter);
}
.provenance-bar__lead, .provenance__data {
  display: flex; flex: 1 1 auto; flex-wrap: wrap; align-items: center; gap: var(--sp-1) var(--sp-2);
  min-width: 0;
}
.provenance-bar__slot, .provenance__readings {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); margin-left: auto;
}

@media (min-width: 600px) {
  .provenance-bar, .provenance { position: sticky; top: var(--masthead-h); }
}

.dataset-pill {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%; min-height: 24px;
  padding: 2px var(--sp-3) 2px var(--sp-2); border: 1px solid var(--c-line-strong); border-radius: var(--r-pill);
  background: var(--c-surface); color: var(--c-ink-2); font-size: var(--fs-small); font-weight: var(--fw-medium);
  line-height: 1.35;
}
@media (max-width: 599.98px) {
  .provenance-bar__lead { flex-wrap: nowrap; }
  .provenance-bar__lead .dataset-pill { flex: 1 1 auto; min-width: 0; }
}
.dataset-pill .dataset-label { min-width: 0; white-space: normal; overflow-wrap: anywhere; }
.dataset-pill__glyph { display: inline-flex; flex: none; color: var(--c-muted); }
.dataset-pill__glyph :is(svg, .icon) { width: 16px; height: 16px; }
.dataset-pill:has(.dataset-label[data-synthetic="true"]) {
  border-color: var(--c-accent-line); background: var(--c-synth-bg); color: var(--c-synth-ink);
}
.dataset-pill:has(.dataset-label[data-synthetic="true"]) .dataset-pill__glyph { color: var(--c-synth-mark); }
.dataset-pill:has(.dataset-label[data-synthetic="false"][data-reference-date=""]) {
  border-color: var(--c-watch-base); background: var(--c-watch-wash); color: var(--c-watch-ink);
}
.dataset-pill:has(.dataset-label[data-synthetic="false"][data-reference-date=""]) .dataset-pill__glyph {
  color: var(--c-watch-ink);
}
/* Loaded, but built for an older schema: the label already says a reseed is needed. */
.dataset-pill:has(.dataset-label[data-schema-current="false"]) {
  border-color: var(--c-watch-base); background: var(--c-watch-wash); color: var(--c-watch-ink);
}
.dataset-pill:has(.dataset-label[data-schema-current="false"]) .dataset-pill__glyph { color: var(--c-watch-ink); }

.micro-label {
  display: inline-flex; align-items: center; gap: 4px; color: var(--c-muted); font-size: var(--fs-label);
  font-weight: var(--fw-semibold); letter-spacing: var(--ls-label); line-height: var(--lh-label);
  text-transform: uppercase;
}
.micro-label :is(svg, .icon) { width: 14px; height: 14px; }

/* What the assistant answers and what it cannot see (templates/_answer_scope.html). */
.answer-scope {
  display: flex; align-items: flex-start; gap: var(--sp-1); margin: 0; color: var(--c-ink-2);
  font-size: var(--fs-small); line-height: var(--lh-small);
}
.answer-scope__icon { flex: none; width: 14px; height: 14px; margin-top: 2px; color: var(--c-info-base); }

.colophon {
  display: grid; gap: var(--sp-1); margin-top: auto;
  padding: var(--sp-4) var(--gutter) max(var(--sp-4), env(safe-area-inset-bottom)); border-top: 1px solid var(--c-line);
  background: var(--c-canvas); color: var(--c-muted); font-size: var(--fs-small); line-height: var(--lh-small);
}
.colophon__inner { display: contents; }
.colophon__line, .colophon__meta { display: flex; flex-wrap: wrap; align-items: center; margin: 0; }
.colophon__line { gap: var(--sp-2); color: var(--c-ink-2); }
.colophon__meta { gap: var(--sp-1) var(--sp-4); }
.colophon__line > :is(svg, .icon) { width: 16px; height: 16px; }
.colophon__item { display: inline-flex; align-items: center; gap: 6px; }
.colophon__item :is(svg, .icon) { width: 14px; height: 14px; }
.colophon :is(code, samp) { font-family: var(--font-mono); font-size: 0.95em; }

/* ---------- Session banner slot (outside .app-root, pinned under the shell) ---------- */
body { --shell-sticky-top: 0px; }

@media (min-width: 600px) {
  body { --shell-sticky-top: calc(var(--masthead-h) + var(--provenance-h)); }
}

.session-slot { position: fixed; top: var(--shell-sticky-top); right: 0; left: 0; z-index: var(--z-toast); }
.session-slot:empty { display: none; }
.session-slot > .banner { box-shadow: var(--e-2); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: var(--control-h); padding: 0 var(--sp-4); border: 1px solid var(--c-line-strong);
  border-radius: var(--r-2); background: var(--c-surface); color: var(--c-ink); font: inherit;
  font-size: var(--fs-ui); font-weight: var(--fw-medium); line-height: 1.2; text-align: center;
  text-decoration: none; white-space: nowrap; cursor: pointer;
  transition: background-color var(--dur-1) var(--ease-out), border-color var(--dur-1) var(--ease-out),
    color var(--dur-1) var(--ease-out);
}
.btn:hover { background: var(--c-surface-2); }
.btn :is(svg, .icon) { width: 18px; height: 18px; }
.btn--secondary { border-color: var(--c-line-strong); background: var(--c-surface); color: var(--c-ink); }
.btn--primary { border-color: var(--c-accent); background: var(--c-accent); color: var(--c-on-accent); }
.btn--primary:hover { border-color: var(--c-accent-hover); background: var(--c-accent-hover); }
.btn--ghost { border-color: transparent; background: transparent; color: var(--c-accent-ink); }
.btn--ghost:hover { background: var(--c-accent-wash); }
.btn--danger { border-color: var(--c-critical-ink); background: var(--c-critical-wash); color: var(--c-critical-ink); }
.btn--danger:hover { background: color-mix(in oklch, var(--c-critical-wash), var(--c-critical-base) 14%); }
.btn--sm { gap: 6px; min-height: var(--hit); padding: 0 var(--sp-3); font-size: var(--fs-small); }
.btn--sm :is(svg, .icon) { width: 16px; height: 16px; }
.btn--block { display: flex; width: 100%; }
.btn:is(:disabled, [aria-disabled="true"]):not([aria-busy="true"]) {
  border-color: var(--c-line); background: var(--c-surface-2); color: var(--c-muted); cursor: not-allowed;
}
.btn[aria-busy="true"] { cursor: progress; }
.btn[aria-busy="true"] > :is(svg, .icon) { display: none; }
.btn[aria-busy="true"]:not(:has(.spinner))::before {
  content: ""; flex: none; width: 1em; height: 1em; border: 2px solid currentColor;
  border-right-color: transparent; border-radius: 50%;
}

/* ---------- Icon button ---------- */
.icon-btn {
  display: inline-grid; flex: none; place-items: center; width: var(--control-h); height: var(--control-h);
  padding: 0; border: 1px solid transparent; border-radius: var(--r-2); background: transparent;
  color: var(--c-ink-2); font: inherit; text-decoration: none; cursor: pointer;
  transition: background-color var(--dur-1) var(--ease-out), color var(--dur-1) var(--ease-out);
}
.icon-btn:hover { background: var(--c-surface-2); color: var(--c-ink); }
.icon-btn[aria-expanded="true"] { background: var(--c-surface-3); color: var(--c-ink); }
.icon-btn[aria-pressed="true"] { border-color: var(--c-accent-line); background: var(--c-accent-wash); color: var(--c-accent-ink); }
.icon-btn:is(:disabled, [aria-disabled="true"]) { background: transparent; color: var(--c-muted); cursor: not-allowed; }
.icon-btn :is(svg, .icon) { width: 20px; height: 20px; }
.icon-btn--sm { width: var(--hit); height: var(--hit); border-radius: var(--r-1); }
.icon-btn--sm :is(svg, .icon) { width: 18px; height: 18px; }

/* ---------- Fields, search, switch ---------- */
.field { display: grid; align-content: start; gap: var(--sp-1); min-width: 0; }
.field__label { color: var(--c-ink-2); font-size: var(--fs-small); font-weight: var(--fw-semibold); }
.field__hint { margin: 0; color: var(--c-muted); font-size: var(--fs-small); line-height: var(--lh-small); }
.field__error {
  display: flex; align-items: flex-start; gap: var(--sp-1); color: var(--c-critical-ink); font-size: var(--fs-small);
  font-weight: var(--fw-medium);
}
.field__error:empty { display: none; }
.field__error :is(svg, .icon) { width: 16px; height: 16px; margin-top: 1px; }
.input, .select, .textarea {
  width: 100%; min-height: var(--control-h); padding: 0 var(--sp-3); border: 1px solid var(--c-line-strong);
  border-radius: var(--r-1); background: var(--c-surface); color: var(--c-ink); font: inherit; font-size: var(--fs-ui);
}
.textarea { min-height: 5.5rem; padding: var(--sp-2) var(--sp-3); line-height: 1.5; resize: vertical; }
.input::placeholder, .textarea::placeholder { color: var(--c-placeholder); opacity: 1; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--c-muted); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { border-color: var(--c-accent-ink); outline-offset: 1px; }
:is(.input, .select, .textarea)[aria-invalid="true"] { border-color: var(--c-critical-base); }
:is(.input, .select, .textarea)[aria-invalid="true"]:focus-visible { outline-color: var(--c-critical-ink); }
:is(.input, .select, .textarea):disabled {
  border-color: var(--c-line); background: var(--c-surface-2); color: var(--c-muted); cursor: not-allowed;
}
.select {
  appearance: none; padding-right: 2rem;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%; background-size: 5px 5px;
  background-repeat: no-repeat;
}
.select[multiple] { padding: var(--sp-1); background-image: none; }
:where(input[type="checkbox"], input[type="radio"]) { accent-color: var(--c-accent); }

.search { position: relative; display: flex; align-items: center; min-width: 0; }
.search > :is(svg, .icon):first-child {
  position: absolute; left: var(--sp-3); width: 18px; height: 18px; color: var(--c-muted); pointer-events: none;
}
.search :is(input, .input) { padding-right: 2.5rem; padding-left: 2.25rem; }
.search input::-webkit-search-cancel-button { appearance: none; }
.search :is(.search__clear, button) { position: absolute; right: 2px; }

input[type="checkbox"][role="switch"] {
  position: relative; flex: none; width: 36px; height: 20px; margin: 0; border: 1px solid var(--c-line-strong);
  border-radius: var(--r-pill); background: var(--c-surface-3); vertical-align: middle; cursor: pointer;
  appearance: none;
}
input[type="checkbox"][role="switch"]::before {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--c-surface); box-shadow: 0 0 0 1px var(--c-line-strong);
}
input[type="checkbox"][role="switch"]:checked { border-color: var(--c-accent); background: var(--c-accent); }
input[type="checkbox"][role="switch"]:checked::before {
  background: var(--c-on-accent); box-shadow: none; transform: translateX(16px);
}
input[type="checkbox"][role="switch"]:disabled { background: var(--c-surface-2); cursor: not-allowed; }

/* ---------- Segmented control ---------- */
.seg {
  display: inline-flex; gap: 2px; max-width: 100%; padding: 2px; border: 1px solid var(--c-line-strong);
  border-radius: var(--r-2); background: var(--c-surface-2);
}
.seg__item {
  position: relative; display: inline-flex; flex: 1 1 auto; align-items: center; justify-content: center;
  gap: var(--sp-1); min-height: var(--hit); padding: 0 var(--sp-3); border: 1px solid transparent;
  border-radius: calc(var(--r-2) - 2px); background: transparent; color: var(--c-ink-2); font: inherit;
  font-size: var(--fs-ui); font-weight: var(--fw-medium); white-space: nowrap; cursor: pointer;
}
.seg__item:hover { background: var(--c-surface-3); color: var(--c-ink); }
.seg__item:focus-visible { outline-offset: 0; }
.seg__item :is(svg, .icon) { width: 16px; height: 16px; }
.seg__item:is([aria-checked="true"], [aria-pressed="true"], :has(> input:checked)) {
  border-color: var(--c-line-strong); background: var(--c-surface); color: var(--c-ink); box-shadow: var(--e-1);
}
.seg__item:is(:disabled, [aria-disabled="true"], :has(> input:disabled)) {
  background: transparent; color: var(--c-muted); cursor: not-allowed;
}
.seg__item > input[type="radio"] { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; }
.seg__item:has(> input:focus-visible) { outline: var(--focus-ring); outline-offset: 0; }

/* ---------- Tabs ---------- */
.tabs {
  position: relative; display: flex; gap: var(--sp-1); overflow-x: auto; overscroll-behavior-x: contain;
  border-bottom: 1px solid var(--c-line); scrollbar-width: thin;
}
.tab {
  position: relative; display: inline-flex; flex: none; align-items: center; gap: var(--sp-2);
  min-height: max(40px, var(--hit)); padding: 0 var(--sp-3); border: 0; border-radius: var(--r-1) var(--r-1) 0 0;
  background: transparent; color: var(--c-ink-2); font: inherit; font-size: var(--fs-ui);
  font-weight: var(--fw-medium); text-decoration: none; white-space: nowrap; cursor: pointer;
}
.tab:hover { background: var(--c-surface-2); color: var(--c-ink); }
.tab:focus-visible { outline-offset: -2px; }
.tab[aria-selected="true"] { color: var(--c-accent-ink); font-weight: var(--fw-semibold); }
.tab :is(svg, .icon) { width: 18px; height: 18px; }
.tabs__indicator {
  position: absolute; bottom: 0; left: 0; width: 0; height: 3px; border-radius: 3px 3px 0 0;
  background: var(--c-accent); pointer-events: none;
}
.tabs:not(:has(.tabs__indicator)) .tab[aria-selected="true"]::after {
  content: ""; position: absolute; right: var(--sp-2); bottom: 0; left: var(--sp-2); height: 3px;
  border-radius: 3px 3px 0 0; background: var(--c-accent);
}

/* ---------- Chips, badges, status pills ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%; min-height: 28px; padding: 0 var(--sp-3);
  border: 1px solid var(--c-line-strong); border-radius: var(--r-pill); background: var(--c-surface);
  color: var(--c-ink-2); font: inherit; font-size: var(--fs-small); font-weight: var(--fw-medium); line-height: 1.2;
  text-decoration: none; white-space: nowrap;
}
:is(button, a).chip { min-height: var(--hit); cursor: pointer; }
:is(button, a).chip:not([class*="chip--state-"]):hover {
  border-color: var(--c-ink-2); background: var(--c-surface-2); color: var(--c-ink);
}
:is(button, a).chip[class*="chip--state-"]:hover { box-shadow: inset 0 0 0 1px currentColor; }
.chip[aria-pressed="true"]:not([class*="chip--state-"]) {
  border-color: var(--c-accent-ink); background: var(--c-accent-wash); color: var(--c-ink);
  font-weight: var(--fw-semibold); box-shadow: inset 0 0 0 1px var(--c-accent-ink);
}
.chip:is(:disabled, [aria-disabled="true"]) { border-color: var(--c-line); color: var(--c-muted); cursor: not-allowed; }
.chip :is(svg, .icon) { width: 14px; height: 14px; }
.chip__count { color: var(--c-muted); font-variant-numeric: tabular-nums; }
.chip--removable { padding-right: 2px; }
.chip--removable > button {
  display: inline-grid; flex: none; place-items: center; width: 24px; height: 24px; padding: 0; border: 0;
  border-radius: 50%; background: transparent; color: inherit; cursor: pointer;
}
.chip--removable > button:hover { background: var(--c-surface-3); }
.chip[class*="chip--state-"] { --chip-dot: currentColor; border-color: transparent; }
.chip[class*="chip--state-"]::before {
  content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--chip-dot);
}
.chip--state-new { --chip-dot: var(--new); background: var(--new-bg); color: var(--new-ink); }
.chip--state-emerging { --chip-dot: var(--emerging); background: var(--emerging-bg); color: var(--emerging-ink); }
.chip--state-worsening { --chip-dot: var(--worsening); background: var(--worsening-bg); color: var(--worsening-ink); }
.chip--state-recurring { --chip-dot: var(--recurring); background: var(--recurring-bg); color: var(--recurring-ink); }
.chip--state-improving { --chip-dot: var(--improving); background: var(--improving-bg); color: var(--improving-ink); }
.chip--state-stable { --chip-dot: var(--stable); background: var(--stable-bg); color: var(--stable-ink); }
.chip--quiet::before { background: transparent; box-shadow: inset 0 0 0 1.5px var(--chip-dot); }
.chip[class*="chip--state-"][aria-pressed="true"] { font-weight: var(--fw-semibold); box-shadow: inset 0 0 0 2px currentColor; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; min-height: 20px; padding: 0 6px;
  border: 1px solid color-mix(in oklch, var(--tone) 55%, transparent); border-radius: var(--r-1);
  background: var(--tone-wash); color: var(--tone-ink); font-size: var(--fs-label); font-weight: var(--fw-semibold);
  letter-spacing: 0.02em; line-height: var(--lh-label); white-space: nowrap; vertical-align: middle;
}
.badge :is(svg, .icon) { width: 14px; height: 14px; }
.badge--admin { border-color: var(--c-accent-ink); background: var(--c-surface); color: var(--c-accent-ink); }
.badge--ai { border-color: var(--c-accent-line); background: var(--c-accent-wash); color: var(--c-ink); }
.badge--notmodeled {
  border-style: dashed; border-color: var(--c-line-strong); background: var(--c-surface); color: var(--c-ink-2);
}

.status-pill {
  display: inline-flex; align-items: center; gap: 6px; min-height: 24px; padding: 0 var(--sp-2);
  border: 1px solid var(--c-line); border-radius: var(--r-pill); background: var(--c-surface);
  color: var(--c-ink-2); font: inherit; font-size: var(--fs-small); font-weight: var(--fw-medium);
  line-height: 1.2; white-space: nowrap;
}
.status-pill__dot, .status-pill:not(:has(.status-pill__dot))::before {
  content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--tone);
}
.status-pill--off :is(.status-pill__dot), .status-pill--off::before {
  background: transparent; box-shadow: inset 0 0 0 1.5px var(--tone);
}
button.status-pill { border-color: var(--c-line-strong); cursor: pointer; }
button.status-pill:hover { background: var(--c-surface-2); color: var(--c-ink); }
button.status-pill[aria-expanded="true"] { background: var(--c-surface-3); color: var(--c-ink); }

/* ---------- Cards and story cards ---------- */
.card, .story {
  display: flex; flex-direction: column; min-width: 0; border: 1px solid var(--c-line); border-radius: var(--r-2);
  background: var(--c-surface); box-shadow: var(--e-1);
}
.card__head {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-1) var(--sp-3); padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--c-line);
}
.card__head > :is(div, hgroup):first-child { flex: 1 1 14rem; min-width: 0; }
.card__kicker {
  display: block; color: var(--c-accent-ink); font-size: var(--fs-label); font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-label); text-transform: uppercase;
}
.card__title {
  margin: 0; color: var(--c-ink); font-size: var(--fs-h2); font-weight: var(--fw-semibold);
  line-height: var(--lh-h2);
}
.card__hint { color: var(--c-muted); font-size: var(--fs-small); }
.card__actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); margin-left: auto; }
.card__body { flex: 1 1 auto; min-width: 0; padding: var(--sp-4); }
.card__foot {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-1) var(--sp-3); padding: var(--sp-2) var(--sp-4);
  border-top: 1px solid var(--c-line); color: var(--c-muted); font-size: var(--fs-small);
}
details.card > summary.card__head { list-style: none; cursor: pointer; }
details.card > summary.card__head::-webkit-details-marker { display: none; }
details.card:not([open]) > summary.card__head { border-bottom: 0; }
.story { gap: var(--sp-3); padding: var(--sp-5); border-radius: var(--r-3); }
.story--lead { padding: var(--sp-6); border-top: 3px solid var(--c-accent); border-radius: var(--r-4); }

@media (max-width: 599.98px) {
  .story, .story--lead { padding: var(--sp-4); }
}

/* ---------- Notes, banners, footnotes, glossary terms, definition lists ---------- */
.alert {
  display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: start; gap: var(--sp-1) var(--sp-3);
  margin: 0; padding: var(--sp-3) var(--sp-4); border: 1px solid color-mix(in oklch, var(--tone) 50%, transparent);
  border-left: 4px solid var(--tone); border-radius: var(--r-2); background: var(--tone-wash); color: var(--c-ink);
  font-size: var(--fs-ui); line-height: 1.5;
}
.alert:not(:has(> :is(svg, .icon):first-child)) { grid-template-columns: minmax(0, 1fr); }
.alert > :is(svg, .icon):first-child { width: 20px; height: 20px; margin-top: 1px; color: var(--tone); }
.alert > :not(:is(svg, .icon):first-child) { grid-column: -2 / -1; min-width: 0; }
.alert p { margin: 0; }
.alert strong { font-weight: var(--fw-semibold); }
.alert :is(.btn, .alert__action) { justify-self: start; margin-top: var(--sp-1); }
.alert--compact { padding: var(--sp-2) var(--sp-3); font-size: var(--fs-small); }
.alert--compact > :is(svg, .icon):first-child { width: 16px; height: 16px; }

.banner {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3); padding: var(--sp-2) var(--gutter);
  border-block: 1px solid color-mix(in oklch, var(--tone) 45%, transparent); background: var(--tone-wash);
  color: var(--c-ink); font-size: var(--fs-ui); line-height: var(--lh-ui);
}
.banner > :is(svg, .icon):first-child, .banner__icon { flex: none; width: 20px; height: 20px; color: var(--tone); }
.banner__text, .banner > p { flex: 1 1 18rem; min-width: 0; margin: 0; }
.banner__lead, .banner strong { font-weight: var(--fw-semibold); }
.banner__actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); margin-left: auto; }
.banner__action { flex: none; }
.banner :is(code, samp) { font-family: var(--font-mono); font-size: 0.92em; overflow-wrap: anywhere; }

.footnote { margin-top: var(--sp-2); color: var(--c-ink-2); font-size: var(--fs-small); line-height: 1.5; }
.footnote > :is(summary, button) {
  display: inline-flex; align-items: center; gap: 6px; min-height: 24px; padding: 0; border: 0;
  border-radius: var(--r-1); background: none; color: var(--c-accent-ink); font: inherit;
  font-weight: var(--fw-semibold); list-style: none; cursor: pointer;
}
.footnote > summary::-webkit-details-marker { display: none; }
.footnote > :is(summary, button)::before {
  content: ""; width: 0.4em; height: 0.4em; border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor; transform: rotate(-45deg);
}
.footnote[open] > summary::before, .footnote > button[aria-expanded="true"]::before { transform: rotate(45deg); }
.footnote > :not(summary, button) {
  margin-top: var(--sp-2); padding: var(--sp-2) var(--sp-3); border-left: 2px solid var(--c-line-strong);
  border-radius: 0 var(--r-1) var(--r-1) 0; background: var(--c-surface-2);
}
/* Default disclosure: the footnote's chevron and link color in place of the native triangle, at the
   surrounding text size. Zero specificity, so a component's own summary color or weight still wins;
   icon-led summaries and those that draw their own chevron are left alone. */
:where(details:not(.footnote, .rc-book-about__more, .rc-panel__more) > summary:not([class], :has(> .icon))) {
  list-style: none; color: var(--c-accent-ink); font-weight: var(--fw-semibold);
  cursor: pointer;
}
:where(details:not(.footnote, .rc-book-about__more, .rc-panel__more) > summary:not([class], :has(> .icon)))::-webkit-details-marker { display: none; }
:where(details:not(.footnote, .rc-book-about__more, .rc-panel__more) > summary:not([class], :has(> .icon)))::before {
  content: ""; display: inline-block; width: 0.4em; height: 0.4em; margin: 0 0.6em 0.15em 0.1em;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; vertical-align: middle;
  transform: rotate(-45deg); transition: transform var(--dur-1) var(--ease-out);
}
:where(details[open]:not(.footnote, .rc-book-about__more, .rc-panel__more) > summary:not([class], :has(> .icon)))::before {
  transform: rotate(45deg);
}
@media (prefers-reduced-motion: reduce) {
  :where(details > summary)::before { transition: none; }
}

.footnote p { margin: 0; }
.footnote p + p { margin-top: var(--sp-1); }

.term {
  display: inline; margin: 0; padding: 0; border: 0; border-radius: 2px; background: none; color: inherit;
  font: inherit; text-decoration: underline dotted; text-decoration-thickness: 1px; text-underline-offset: 3px;
  cursor: help;
}
.term:hover { color: var(--c-accent-ink); }
.term[aria-expanded="true"] { background: var(--c-accent-wash); }

.deflist {
  display: grid; grid-template-columns: minmax(7rem, max-content) minmax(0, 1fr); gap: var(--sp-2) var(--sp-4);
  margin: 0; font-size: var(--fs-ui);
}
.deflist > div { display: contents; }
.deflist dt { color: var(--c-muted); font-weight: var(--fw-semibold); }
.deflist dd { margin: 0; color: var(--c-ink); overflow-wrap: anywhere; }
.deflist dd > p { margin: 0; }

@media (max-width: 599.98px) {
  .deflist { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .deflist dd + dt { margin-top: var(--sp-2); }
}

/* ---------- State blocks, skeletons, refetch ---------- */
.state {
  display: grid; place-content: center; justify-items: center; gap: var(--sp-2); min-height: 12.5rem;
  padding: var(--sp-6) var(--sp-5); border: 1px solid var(--c-line); border-radius: var(--r-2);
  background: var(--c-surface); color: var(--c-ink); text-align: center;
}
.state__icon {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: var(--tone-wash);
  color: var(--tone-ink);
}
.state__icon :is(svg, .icon) { width: 22px; height: 22px; }
.state__icon .spinner { width: 20px; height: 20px; }
.state__title {
  margin: 0; color: var(--c-ink); font-size: var(--fs-h3); font-weight: var(--fw-semibold);
  line-height: var(--lh-h3);
}
.state__body { max-width: 52ch; margin: 0; color: var(--c-ink-2); font-size: var(--fs-ui); line-height: 1.5; }
.state__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--sp-2); margin-top: var(--sp-2); }
.state__details { width: min(100%, 40rem); margin-top: var(--sp-2); font-size: var(--fs-small); text-align: left; }
.state__details > summary { color: var(--c-accent-ink); font-weight: var(--fw-semibold); cursor: pointer; }
.state__details pre {
  max-height: 12.5rem; margin: var(--sp-2) 0 0; padding: var(--sp-2) var(--sp-3); overflow: auto;
  border-radius: var(--r-1); background: var(--c-surface-2); color: var(--c-ink-2); font-family: var(--font-mono);
  font-size: var(--fs-small); white-space: pre-wrap; overflow-wrap: anywhere;
}
.state--error, .state--unavailable { border-color: color-mix(in oklch, var(--tone) 45%, transparent); }
.state--locked .state__icon { background: var(--c-surface-2); color: var(--c-ink-2); }
.state--compact {
  min-height: 0; padding: var(--sp-4); border-style: dashed; border-color: var(--c-line-strong); background: transparent;
}
.state--compact .state__icon { width: 32px; height: 32px; }
.popover .state { min-height: 0; padding: var(--sp-3); border: 0; }

.skeleton { display: block; min-height: 1em; border-radius: var(--r-1); background-color: var(--c-surface-3); }
.skeleton:not(.skeleton--text) + .skeleton:not(.skeleton--text) { margin-top: var(--sp-3); }
.skeleton--text { height: 0.8em; min-height: 0; margin-block: 0.4em; }
.skeleton--text:nth-of-type(3n + 2) { width: 88%; }
.skeleton--text:nth-of-type(3n) { width: 64%; }
.skeleton--kpi { height: 6rem; border-radius: var(--r-2); }
.skeleton--chart { height: 13.75rem; border-radius: var(--r-2); }
.skeleton--row { height: 2.25rem; }
.skeleton.skeleton--row + .skeleton.skeleton--row { margin-top: 2px; }
.skeleton--card { height: 10rem; border-radius: var(--r-2); }
.skeleton--story { height: 16rem; border-radius: var(--r-3); }

:is([role="tabpanel"], [role="region"], section, .card, .card__body, .drawer__body)[aria-busy="true"]:not(:has(.skeleton)) {
  opacity: 0.6; transition: opacity var(--dur-2) var(--ease-out);
}

.progress-line { position: relative; display: block; height: 2px; overflow: hidden; background: var(--c-accent-wash); }
.progress-line::before { content: ""; position: absolute; top: 0; bottom: 0; left: 0; width: 30%; background: var(--c-accent); }

/* ---------- Toasts ---------- */
.toast-region {
  position: fixed; right: var(--sp-5); bottom: var(--sp-5); z-index: var(--z-toast); display: flex;
  flex-direction: column; align-items: flex-end; gap: var(--sp-2); width: min(27.5rem, calc(100vw - 2 * var(--sp-4)));
  pointer-events: none;
}
body[data-page="briefing"] .toast-region {
  right: 50%; bottom: var(--toast-offset, 9.5rem); align-items: center; transform: translateX(50%);
}
.toast {
  display: flex; align-items: flex-start; gap: var(--sp-3); width: 100%; min-height: 48px;
  padding: var(--sp-3) var(--sp-2) var(--sp-3) var(--sp-4); border: 1px solid transparent;
  border-left: 4px solid var(--tone); border-radius: var(--r-2); background: var(--c-inverse);
  color: var(--c-on-inverse); font-size: var(--fs-ui); line-height: var(--lh-ui); box-shadow: var(--e-3);
  pointer-events: auto;
}
.toast__icon { flex: none; width: 20px; height: 20px; margin-top: 1px; }
.toast__body { flex: 1 1 auto; min-width: 0; padding-top: 1px; overflow-wrap: anywhere; }
.toast__body > p { margin: 0; }
.toast__title { font-weight: var(--fw-semibold); }
.toast__detail { margin-top: 2px; font-size: var(--fs-small); opacity: 0.85; }
.toast :is(.btn, .icon-btn) { border-color: transparent; background: transparent; color: inherit; }
.toast .toast__action { flex: none; margin-block: -6px; border-color: currentColor; font-weight: var(--fw-semibold); }
.toast .toast__close { margin-block: -6px; }
.toast :is(button, a):hover { background: color-mix(in oklch, var(--c-on-inverse) 14%, transparent); }
.toast :focus-visible { outline-color: var(--c-on-inverse); }

@media (max-width: 599.98px) {
  .toast-region, body[data-page="briefing"] .toast-region {
    right: var(--sp-3); bottom: var(--sp-3); left: var(--sp-3); align-items: stretch; width: auto; transform: none;
  }
  body[data-page="briefing"] .toast-region { bottom: var(--toast-offset, 9.5rem); }
}

/* ---------- Layers: scrim, drawer, dialog ---------- */
.scrim { position: fixed; inset: 0; z-index: var(--z-overlay); background: var(--c-scrim); }
body:has(:is(.dialog, .palette):not(dialog):not([hidden])) .scrim:not([hidden]) { z-index: calc(var(--z-dialog) - 1); }

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; left: auto; z-index: var(--z-drawer);
  width: min(var(--drawer-w, 28rem), 100vw); max-width: 100vw; height: auto; max-height: none; margin: 0;
  padding: 0; border: 1px solid var(--c-line); border-right: 0; border-radius: var(--r-3) 0 0 var(--r-3);
  background: var(--c-surface); color: var(--c-ink); box-shadow: var(--e-3);
}
.drawer:is(:not(dialog), [open]) { display: flex; flex-direction: column; }
.drawer::backdrop { background: var(--c-scrim); }
.drawer--left {
  right: auto; left: 0; border-right: 1px solid var(--c-line); border-left: 0;
  border-radius: 0 var(--r-3) var(--r-3) 0;
}
.drawer__head {
  display: flex; flex: none; flex-wrap: wrap; align-items: flex-start; gap: var(--sp-2) var(--sp-3);
  padding: var(--sp-4) var(--sp-3) var(--sp-3) var(--sp-5); border-bottom: 1px solid var(--c-line);
}
.drawer__head :is(h1, h2, h3, .drawer__title) {
  flex: 1 1 12rem; min-width: 0; margin: 0; color: var(--c-ink); font-size: var(--fs-h2);
  font-weight: var(--fw-semibold); line-height: 1.3; overflow-wrap: anywhere;
}
.drawer__close { margin-left: auto; }
.drawer__crumbs {
  display: flex; flex-basis: 100%; flex-wrap: wrap; align-items: center; gap: var(--sp-1); order: -1;
  color: var(--c-muted); font-size: var(--fs-small);
}
.drawer__head > .micro-label { flex-basis: 100%; }
.drawer__body { flex: 1 1 auto; min-height: 0; padding: var(--sp-4) var(--sp-5); overflow: auto; overscroll-behavior: contain; }
.drawer__foot {
  display: flex; flex: none; flex-wrap: wrap; justify-content: flex-end; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-5) max(var(--sp-3), env(safe-area-inset-bottom)); border-top: 1px solid var(--c-line);
  background: var(--c-surface-2);
}

.dialog {
  position: fixed; inset: 0; z-index: var(--z-dialog); width: min(35rem, calc(100vw - 2 * var(--sp-4)));
  max-width: none; height: fit-content; max-height: min(85vh, 45rem); margin: auto; padding: 0; overflow: hidden;
  border: 1px solid var(--c-line); border-radius: var(--r-3); background: var(--c-surface); color: var(--c-ink);
  box-shadow: var(--e-4);
}
.dialog:is(:not(dialog), [open]) { display: flex; flex-direction: column; }
.dialog::backdrop { background: var(--c-scrim); }
.dialog--confirm { width: min(27.5rem, calc(100vw - 2 * var(--sp-4))); }
.dialog__head {
  display: flex; flex: none; align-items: flex-start; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-3) var(--sp-2) var(--sp-5);
}
.dialog__head :is(h1, h2, h3, .dialog__title) {
  flex: 1 1 auto; min-width: 0; margin: 0; font-size: var(--fs-h2); font-weight: var(--fw-semibold);
  line-height: 1.3; overflow-wrap: anywhere;
}
.dialog__body {
  flex: 1 1 auto; min-height: 0; padding: var(--sp-2) var(--sp-5) var(--sp-4); overflow: auto;
  overscroll-behavior: contain;
}
.dialog__body > p { margin: 0 0 var(--sp-3); }
.dialog__foot {
  display: flex; flex: none; flex-wrap: wrap; justify-content: flex-end; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--c-line); background: var(--c-surface-2);
}

@media (max-width: 599.98px) {
  .drawer, .drawer--left { width: 100vw; border: 0; border-radius: 0; }
  .dialog, .dialog--confirm {
    inset: auto 0 0 0; width: 100%; max-height: 90vh; margin: 0; border-width: 1px 0 0;
    border-radius: var(--r-3) var(--r-3) 0 0;
  }
  .dialog__foot { padding-bottom: max(var(--sp-3), env(safe-area-inset-bottom)); }
  .dialog__foot > .btn { flex: 1 1 auto; }
}

/* ---------- Menus, popovers, tooltips, About ---------- */
.menu, .popover, .tooltip { position: fixed; margin: 0; }
:is(.menu, .popover, .tooltip, .coach)[popover] { inset: auto; }
.menu {
  z-index: var(--z-menu); min-width: 12rem; max-width: min(20rem, calc(100vw - 2 * var(--sp-4)));
  max-height: min(70vh, 32rem); padding: var(--sp-1); overflow: auto; border: 1px solid var(--c-line);
  border-radius: var(--r-2); background: var(--c-surface); color: var(--c-ink); font-size: var(--fs-ui);
  line-height: var(--lh-ui); box-shadow: var(--e-2);
}
.menu:is(:not([popover]), :popover-open) { display: flex; flex-direction: column; }
.menu__list { display: flex; flex-direction: column; margin: 0; padding: 0; list-style: none; }
.menu__list > li { display: flex; flex-direction: column; }
.menu__item, .menu [role^="menuitem"] {
  display: flex; align-items: center; gap: var(--sp-2); width: 100%; min-height: var(--hit); padding: 0 var(--sp-3);
  border: 0; border-radius: var(--r-1); background: transparent; color: var(--c-ink); font: inherit; text-align: left;
  text-decoration: none; white-space: nowrap; cursor: pointer;
}
:is(.menu__item, .menu [role^="menuitem"]):is(:hover, :focus-visible) { background: var(--c-surface-2); }
:is(.menu__item, .menu [role^="menuitem"]):focus-visible { outline-offset: -2px; }
:is(.menu__item, .menu [role^="menuitem"]):is(:disabled, [aria-disabled="true"]) {
  background: transparent; color: var(--c-muted); cursor: not-allowed;
}
:is(.menu__item, .menu [role^="menuitem"])[aria-checked="true"]::after {
  content: "\2713"; margin-left: auto; color: var(--c-accent-ink); font-weight: var(--fw-bold);
}
:is(.menu__item, .menu [role^="menuitem"]) :is(svg, .icon) { flex: none; width: 18px; height: 18px; color: var(--c-ink-2); }
.menu__item--danger, .menu__item--danger :is(svg, .icon) { color: var(--c-critical-ink); }
.menu__sep { flex: none; height: 1px; margin: var(--sp-1) 0; border: 0; background: var(--c-line); }
.menu .menu__identity { margin: 0 0 var(--sp-1); padding: var(--sp-2) var(--sp-3); border-bottom: 1px solid var(--c-line); }
.menu__label {
  padding: var(--sp-2) var(--sp-3) var(--sp-1); color: var(--c-muted); font-size: var(--fs-label);
  font-weight: var(--fw-semibold); letter-spacing: var(--ls-label); text-transform: uppercase;
}
.menu__group { display: flex; flex-direction: column; }
.menu__group > .menu__label { margin: 0; }
.menu__hint { margin-left: var(--sp-1); color: var(--c-muted); font-size: var(--fs-small); }
.menu__note {
  max-width: 18rem; margin: 0; padding: 0 var(--sp-3) var(--sp-2); color: var(--c-ink-2); font-size: var(--fs-small);
  line-height: var(--lh-small); white-space: normal;
}

.popover {
  z-index: var(--z-menu); width: max-content; max-width: min(22.5rem, calc(100vw - 2 * var(--sp-4)));
  max-height: min(75vh, 36rem); padding: var(--sp-3) var(--sp-4); overflow: auto; border: 1px solid var(--c-line);
  border-radius: var(--r-2); background: var(--c-surface); color: var(--c-ink); font-size: var(--fs-small);
  line-height: 1.5; box-shadow: var(--e-2);
}
.popover__head {
  display: flex; align-items: flex-start; gap: var(--sp-2);
  margin: calc(-1 * var(--sp-1)) calc(-1 * var(--sp-2)) var(--sp-2) 0;
}
.popover__title { flex: 1 1 auto; margin: 0; color: var(--c-ink); font-size: var(--fs-ui); font-weight: var(--fw-semibold); }
.popover__close { flex: none; }
.popover__body > * { margin: 0; }
.popover__body > * + * { margin-top: var(--sp-3); }
.popover__body .deflist { gap: var(--sp-2) var(--sp-3); font-size: var(--fs-small); }
.popover__note { color: var(--c-muted); }
.popover__note code { overflow-wrap: anywhere; }
.popover__reason {
  padding: var(--sp-2) var(--sp-3); border-left: 2px solid var(--c-watch-base); border-radius: 0 var(--r-1) var(--r-1) 0;
  background: var(--c-surface-2); color: var(--c-ink); overflow-wrap: anywhere;
}
html:has(:is(.drawer, .dialog):not([hidden]):not(dialog:not([open]))) :is(.menu, .popover) {
  z-index: calc(var(--z-palette) - 1);
}

.tooltip {
  z-index: var(--z-tour); max-width: min(18rem, calc(100vw - 2 * var(--sp-4))); padding: 4px var(--sp-2);
  border: 1px solid transparent; border-radius: var(--r-1); background: var(--c-inverse); color: var(--c-on-inverse);
  font-size: var(--fs-small); line-height: 1.35; box-shadow: var(--e-2); pointer-events: none;
}

.popover > .popover__title { margin: 0 0 var(--sp-2); }
.popover__head .popover__title { padding-top: 6px; }
.popover:has(> .about) { width: min(25rem, calc(100vw - 2 * var(--sp-4))); }
.about { display: grid; gap: var(--sp-3); }
.about > * { margin: 0; }
.about__section + .about__section, .about > .alert + .about__section {
  padding-top: var(--sp-3); border-top: 1px solid var(--c-line);
}
.about__section > * { margin: 0; }
.about__section > * + * { margin-top: var(--sp-2); }
.about__section :is(h3, h4), .about__subhead {
  margin: 0; color: var(--c-muted); font-size: var(--fs-label); font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-label); line-height: var(--lh-label); text-transform: uppercase;
}
.about__id { overflow-wrap: anywhere; }
.about__section ul, .about__checklist, .about__links { display: grid; gap: var(--sp-1); margin: 0; padding: 0; list-style: none; }
.about__check { display: flex; align-items: flex-start; gap: var(--sp-2); color: var(--c-ink); }
.about__check > :is(svg, .icon) { flex: none; width: 16px; height: 16px; margin-top: 2px; color: var(--tone); }
.about__section .about__links, .about__links { display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-2); }
.about__link {
  display: inline-flex; align-items: center; gap: 6px; min-height: var(--hit); padding: 0; border: 0; background: none;
  color: var(--c-accent-ink); font: inherit; font-weight: var(--fw-semibold); text-decoration: none; cursor: pointer;
}
.about__link:hover { text-decoration: underline; text-underline-offset: 3px; }
.about__link :is(svg, .icon) { width: 16px; height: 16px; }

/* ---------- Command palette ---------- */
.palette {
  position: fixed; inset: 12vh 0 auto 0; z-index: var(--z-palette); width: min(40rem, calc(100vw - 2 * var(--sp-4)));
  max-width: none; height: auto; max-height: min(70vh, 34rem); margin: 0 auto; padding: 0; overflow: hidden;
  border: 1px solid var(--c-line); border-radius: var(--r-3); background: var(--c-surface); color: var(--c-ink);
  box-shadow: var(--e-4);
}
.palette:is(:not(dialog), [open]) { display: flex; flex-direction: column; }
.palette::backdrop { background: var(--c-scrim); }
.palette :is(.palette__input, [role="combobox"]) {
  flex: none; width: 100%; min-height: 52px; padding: 0 var(--sp-4); border: 0; border-bottom: 1px solid var(--c-line);
  border-radius: 0; background: transparent; color: var(--c-ink); font: inherit; font-size: var(--fs-body);
}
.palette :is(.palette__input, [role="combobox"])::placeholder { color: var(--c-placeholder); opacity: 1; }
.palette :is(.palette__input, [role="combobox"]):focus-visible { outline: none; box-shadow: inset 0 -2px 0 var(--c-focus); }
.palette :is(.palette__list, [role="listbox"]) {
  flex: 1 1 auto; min-height: 0; margin: 0; padding: var(--sp-1) var(--sp-2) var(--sp-2); overflow: auto;
  overscroll-behavior: contain; list-style: none;
}
.palette__group {
  margin: 0; padding: var(--sp-3) var(--sp-2) var(--sp-1); color: var(--c-muted); font-size: var(--fs-label);
  font-weight: var(--fw-semibold); letter-spacing: var(--ls-label); text-transform: uppercase;
}
.palette :is(.palette__option, [role="option"]) {
  display: flex; align-items: center; gap: var(--sp-3); min-height: max(40px, var(--hit)); padding: var(--sp-1) var(--sp-3);
  border-radius: var(--r-2); color: var(--c-ink); font-size: var(--fs-ui); cursor: pointer;
}
.palette :is(.palette__option, [role="option"]):hover { background: var(--c-surface-2); }
.palette :is(.palette__option, [role="option"])[aria-selected="true"] {
  background: var(--c-accent-wash); box-shadow: inset 3px 0 0 var(--c-accent);
}
.palette :is(.palette__option, [role="option"]) :is(svg, .icon) { flex: none; width: 18px; height: 18px; color: var(--c-ink-2); }
.palette mark {
  background: none; color: inherit; font-weight: var(--fw-bold); text-decoration: underline;
  text-underline-offset: 2px;
}
.palette__label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette__meta { margin-left: auto; color: var(--c-muted); font-size: var(--fs-small); white-space: nowrap; }
.palette__empty { padding: var(--sp-5) var(--sp-4); color: var(--c-muted); font-size: var(--fs-ui); text-align: center; }
.palette__foot {
  display: flex; flex: none; flex-wrap: wrap; gap: var(--sp-1) var(--sp-4); padding: var(--sp-2) var(--sp-4);
  border-top: 1px solid var(--c-line); background: var(--c-surface-2); color: var(--c-muted); font-size: var(--fs-small);
}

@media (max-width: 599.98px) {
  .palette { inset: var(--sp-2) 0 auto 0; max-height: calc(100dvh - 2 * var(--sp-2)); }
  .palette__foot { display: none; }
}

/* ---------- Coach marks and shortcuts sheet ---------- */
.coach {
  position: fixed; z-index: var(--z-tour); width: min(20rem, calc(100vw - 2 * var(--sp-4))); margin: 0;
  padding: var(--sp-4); border: 1px solid var(--c-line); border-top: 3px solid var(--c-accent); border-radius: var(--r-2);
  background: var(--c-surface); color: var(--c-ink); font-size: var(--fs-small); line-height: 1.5; box-shadow: var(--e-4);
}
body:has([aria-modal="true"]:not([hidden])) .coach--offer { display: none; }
/* The tour offer never covers a menu the user opened. */
body:has(.menu:is(:not([popover]):not([hidden]), :popover-open)) .coach--offer { display: none; }
.coach__step {
  color: var(--c-accent-ink); font-size: var(--fs-label); font-weight: var(--fw-semibold); letter-spacing: var(--ls-label);
  text-transform: uppercase;
}
.coach :is(h2, h3, .coach__title) {
  margin: var(--sp-1) 0 var(--sp-2); color: var(--c-ink); font-size: var(--fs-h3);
  font-weight: var(--fw-semibold);
}
.coach__body { margin: 0; color: var(--c-ink-2); }
.coach__actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); margin-top: var(--sp-3); }
.coach__actions > :first-child { margin-right: auto; }
/* Phones: the tour offer is a slim strip along the bottom edge. */
@media (max-width: 599.98px) {
  .coach--offer {
    left: var(--sp-4); display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3);
    width: auto; padding: var(--sp-2) var(--sp-3);
  }
  .coach--offer .coach__body { flex: 1 1 10rem; }
  .coach--offer .coach__actions { flex-wrap: nowrap; margin-top: 0; }
}
.coach-ring {
  position: fixed; z-index: calc(var(--z-tour) - 1); border-radius: var(--r-2);
  box-shadow: 0 0 0 2px var(--c-surface), 0 0 0 5px var(--c-focus); pointer-events: none;
}

.shortcuts label:has(> input[role="switch"]), .shortcuts__switch {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-1) var(--sp-3); padding: var(--sp-3);
  border-radius: var(--r-2); background: var(--c-surface-2); font-size: var(--fs-ui); font-weight: var(--fw-semibold);
  cursor: pointer;
}
.shortcuts__switch > .field__hint { flex-basis: 100%; font-weight: var(--fw-regular); }
.shortcuts .dialog__body > .field__hint { margin: var(--sp-2) 0 var(--sp-1); }
.shortcuts section + section { margin-top: var(--sp-4); }
.shortcuts section > :is(h3, h4) {
  margin: var(--sp-3) 0 var(--sp-2); color: var(--c-muted); font-size: var(--fs-label); font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-label); text-transform: uppercase;
}
.shortcuts dl {
  display: grid; grid-template-columns: minmax(7rem, max-content) minmax(0, 1fr); align-items: baseline;
  gap: var(--sp-2) var(--sp-4); margin: 0;
}
.shortcuts dl > div { display: contents; }
.shortcuts dt { display: flex; flex-wrap: wrap; gap: 4px; }
.shortcuts dd { margin: 0; color: var(--c-ink-2); font-size: var(--fs-ui); }

/* ---------- Code card ---------- */
.code-card {
  position: relative; margin: var(--sp-3) 0; overflow: hidden; border: 1px solid var(--c-line);
  border-radius: var(--r-2); background: var(--c-surface-2);
}
.code-card__head {
  display: flex; align-items: center; gap: var(--sp-1); min-height: var(--control-h); padding: 2px var(--sp-1) 2px var(--sp-3);
  border-bottom: 1px solid var(--c-line); background: var(--c-surface-3);
}
.code-card__lang {
  margin-right: auto; color: var(--c-muted); font-size: var(--fs-label); font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-label); text-transform: uppercase;
}
.code-card :is(pre, .code-card__body) {
  margin: 0; padding: var(--sp-3) var(--sp-4); overflow: auto; background: transparent; color: var(--c-ink);
  font-family: var(--font-mono); font-size: var(--fs-small); line-height: 1.6; white-space: pre; tab-size: 2;
  counter-reset: cmp-line;
}
.code-card code { padding: 0; background: none; color: inherit; font: inherit; }
.code-card .line { position: relative; display: block; padding-left: 3em; counter-increment: cmp-line; }
.code-card .line::before {
  content: counter(cmp-line); position: absolute; left: 0; width: 2.2em; color: var(--c-muted); text-align: right;
  user-select: none;
}
.code-card:has(.code-card__toggle[aria-expanded="false"]) :is(pre, .code-card__body) {
  max-height: calc(8 * 1.6em + 2 * var(--sp-3)); overflow: hidden;
  mask-image: linear-gradient(to bottom, currentColor 70%, transparent);
}
.code-card[aria-busy="true"] { border-style: dashed; }
.tok-kw { color: var(--c-accent-ink); font-weight: var(--fw-semibold); }
.tok-fn { color: var(--c-ink); font-weight: var(--fw-display); }
.tok-str { color: var(--c-ink-2); }
.tok-num { color: var(--c-accent-ink); font-variant-numeric: tabular-nums; }
.tok-com { color: var(--c-muted); font-style: italic; }

/* ---------- Coarse pointers ---------- */
@media (pointer: coarse) {
  .masthead__link, .masthead__nav-link, .toast .toast__action { min-height: var(--hit); }
  .chip--removable > button { width: 36px; height: 36px; }
  .input, .select, .textarea, .palette :is(.palette__input, [role="combobox"]) { font-size: max(1rem, 16px); }
  /* Below 16px, phone browsers zoom the page when a field takes focus; this also covers fields without a component class. */
  :is(input:not([type="checkbox"], [type="radio"], [type="range"], [type="color"], [type="file"], [type="hidden"],
    [type="button"], [type="submit"], [type="reset"], [type="image"]), select, textarea) { font-size: max(1rem, 16px); }
}

/* ---------- Motion (only when the user has not asked for less) ---------- */
@media (prefers-reduced-motion: no-preference) {
  :is(.user-btn, .user-menu__trigger) > :is(svg, .icon):last-child, .footnote > :is(summary, button)::before {
    transition: transform var(--dur-2) var(--ease-out);
  }
  input[type="checkbox"][role="switch"]::before { transition: transform var(--dur-1) var(--ease-out); }
  .tabs__indicator { transition: transform var(--dur-2) var(--ease-out), width var(--dur-2) var(--ease-out); }
  .coach-ring {
    transition: top var(--dur-3) var(--ease-out), left var(--dur-3) var(--ease-out), width var(--dur-3) var(--ease-out),
      height var(--dur-3) var(--ease-out);
  }
  .spinner, .btn[aria-busy="true"]::before { animation: cmp-spin 0.8s linear infinite; }
  .scrim { animation: cmp-fade var(--dur-2) var(--ease-out); }
  .drawer { animation: cmp-in-right var(--dur-3) var(--ease-out); }
  .drawer--left { animation-name: cmp-in-left; }
  .dialog, .palette { animation: cmp-pop var(--dur-2) var(--ease-out); }
  .menu, .popover, .coach { animation: cmp-drop var(--dur-2) var(--ease-out); }
  .tooltip { animation: cmp-fade var(--dur-1) var(--ease-out); }
  .toast { animation: cmp-rise var(--dur-2) var(--ease-out); }
  .skeleton {
    background-image: linear-gradient(90deg, transparent, color-mix(in oklch, var(--c-surface) 55%, transparent), transparent);
    background-repeat: no-repeat; background-size: 50% 100%; animation: cmp-shimmer 1.6s var(--ease-in-out) infinite;
  }
  .progress-line::before { animation: cmp-progress 1.2s var(--ease-in-out) infinite; }

  @media (max-width: 599.98px) {
    .dialog, .drawer, .drawer--left { animation-name: cmp-sheet; animation-duration: var(--dur-3); }
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner, .btn[aria-busy="true"]::before { border-style: dotted; border-right-color: currentColor; }
  .progress-line::before { width: 100%; opacity: 0.6; }
}

@keyframes cmp-fade { from { opacity: 0; } }
@keyframes cmp-in-right { from { transform: translateX(100%); } }
@keyframes cmp-in-left { from { transform: translateX(-100%); } }
@keyframes cmp-sheet { from { transform: translateY(100%); } }
@keyframes cmp-pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
@keyframes cmp-drop { from { opacity: 0; transform: translateY(-4px); } }
@keyframes cmp-rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes cmp-spin { to { transform: rotate(360deg); } }
@keyframes cmp-shimmer { from { background-position: -100% 0; } to { background-position: 200% 0; } }
@keyframes cmp-progress { from { transform: translateX(-100%); } to { transform: translateX(340%); } }

/* ---------- Forced colors (foundation maps the tokens; these keep painted marks visible) ---------- */
@media (forced-colors: active) {
  .seg__item:is([aria-checked="true"], [aria-pressed="true"], :has(> input:checked)), .chip[aria-pressed="true"],
  .icon-btn[aria-pressed="true"] { border: 2px solid Highlight; }
  .tab[aria-selected="true"] { border-bottom: 2px solid Highlight; }
  .tabs__indicator, .tab[aria-selected="true"]::after, :is(.masthead__link, .masthead__nav-link)[aria-current]::after,
  .progress-line::before { background: Highlight; forced-color-adjust: none; }
  .status-pill__dot, .status-pill::before, .chip[class*="chip--state-"]::before {
    background: CanvasText; forced-color-adjust: none;
  }
  .status-pill--off :is(.status-pill__dot), .status-pill--off::before, .chip--quiet::before {
    border: 1px solid CanvasText; background: Canvas;
  }
  .avatar { border: 1px solid CanvasText; }
  .skeleton { border: 1px solid GrayText; }
  .toast, .tooltip, .menu, .popover, .coach, .dialog, .drawer, .palette { border: 1px solid CanvasText; }
  .spinner, .btn[aria-busy="true"]::before { border-color: Highlight; border-right-color: transparent; }
  .palette :is(.palette__option, [role="option"])[aria-selected="true"] { outline: 2px solid Highlight; outline-offset: -2px; }
  .coach-ring { box-shadow: none; outline: 3px solid Highlight; }
  input[type="checkbox"][role="switch"] { border-color: ButtonText; background: ButtonFace; forced-color-adjust: none; }
  input[type="checkbox"][role="switch"]::before { background: ButtonText; box-shadow: none; }
  input[type="checkbox"][role="switch"]:checked { border-color: Highlight; background: Highlight; }
  input[type="checkbox"][role="switch"]:checked::before { background: HighlightText; }
  .btn:is(:disabled, [aria-disabled="true"]), .icon-btn:disabled { border-color: GrayText; color: GrayText; }
  .code-card:has(.code-card__toggle[aria-expanded="false"]) :is(pre, .code-card__body) { mask-image: none; }
}

/* ---------- Print (foundation hides buttons, menus, layers and toasts) ---------- */
@media print {
  .masthead__tools, .masthead__actions, .masthead__menu-btn, .dataset-pill__info, .session-slot, .layer-host {
    display: none !important;
  }
  .masthead, .provenance-bar, .provenance { position: static; }
  .provenance-bar, .provenance, .colophon { background: none; }
  .alert, .banner, .state, .deflist, .footnote, .story { break-inside: avoid; }
  .code-card :is(pre, .code-card__body) {
    max-height: none !important; overflow: visible; white-space: pre-wrap; mask-image: none !important;
  }
}
