/*
 * Haberdash - Modular Component System
 * Generated by build.py
 */

/* ========== TOKENS.CSS ========== */
/*
 * Haberdash Design Tokens — SPECTRA EDITION
 * All visual & emotional tokens driven by the 4 VRGB dimensions
 */

:root {
  /* ==================================== */
  /* 1. CORE VRGB INPUTS — injected by the builder */
  /* ==================================== */
  --d1_h: 210;          /* Hue from Color Harmony */
  --d1_s: 70%;          /* Saturation from Color Harmony */
  --d1_l: 50%;          /* Lightness from Color Harmony */
  --d2_l: 50;           /* L* from Edge Definition */
  --d3_l: 50;           /* L* from Spatial Density */
  --d4_l: 50;           /* L* from Visual Hierarchy */

  /* ==================================== */
  /* 2. PRIMARY PALETTE — derived from D1 */
  /* ==================================== */
  --primary:        hsl(var(--d1_h), calc(var(--d1_s) * 1.1), calc(var(--d1_l) + 12%));
  --primary-hover:  hsl(var(--d1_h), calc(var(--d1_s) * 1.2), calc(var(--d1_l) + 18%));
  --primary-light:  hsl(var(--d1_h), calc(var(--d1_s) * 0.6), calc(var(--d1_l) + 40%));
  --secondary:      hsl(var(--d1_h), 20%, 40%);

  /* Background / surface — inverted lightness from D1 + breathing from D3 */
  --background:     hsl(var(--d1_h), 15%, calc(98% - (var(--d1_l) * 0.9) + (var(--d3_l) * 0.1)));
  --surface:        hsl(var(--d1_h), 12%, calc(96% - (var(--d1_l) * 0.8) + (var(--d3_l) * 0.15)));
  --surface-light:  hsl(var(--d1_h), 10%, calc(97% - (var(--d1_l) * 0.7) + (var(--d3_l) * 0.2)));

  --text:           hsl(var(--d1_h), 10%, calc(10% + (var(--d1_l) * 0.3)));
  --text-heading:   hsl(var(--d1_h), 15%, calc(5% + (var(--d1_l) * 0.25)));
  --text-secondary: hsl(var(--d1_h), 10%, calc(40% + (var(--d1_l) * 0.35)));

  --border:         hsl(var(--d1_h), 15%, calc(80% - (var(--d1_l) * 0.6)));
  --border-light:   hsl(var(--d1_h), 10%, calc(85% - (var(--d1_l) * 0.5)));

  /* ==================================== */
  /* 3. SPACING — driven by Spatial Density (D3) */
  /* ==================================== */
  --space-unit: 1rem;
  --space-multiplier: calc(0.8 + (var(--d3_l) / 200)); /* 0.8 → 1.3 */
  --space-2xs: calc(0.125rem * var(--space-multiplier));
  --space-xs:  calc(0.25rem  * var(--space-multiplier));
  --space-sm:  calc(0.5rem   * var(--space-multiplier));
  --space-md:  calc(0.75rem  * var(--space-multiplier));
  --space-lg:  calc(1rem     * var(--space-multiplier));
  --space-xl:  calc(1.5rem   * var(--space-multiplier));
  --space-2xl: calc(2rem     * var(--space-multiplier));
  --space-3xl: calc(2.5rem   * var(--space-multiplier));

  /* ==================================== */
  /* 4. BORDER RADIUS — curvature follows saturation (D1) + edge softness (D2) */
  /* ==================================== */
  --radius-base: calc(4px + (var(--d1_s) / 8) + ((100 - var(--d2_l)) / 10));
  --radius-sm:   calc(var(--radius-base) * 0.5);
  --radius-md:   var(--radius-base);
  --radius-lg:   calc(var(--radius-base) * 1.5);
  --radius-xl:   calc(var(--radius-base) * 2);
  --radius-full: 9999px;

  /* ==================================== */
  /* 5. SHADOWS — depth from Edge Definition (D2) + mood lightness */
  /* ==================================== */
  --shadow-intensity: calc((100 - var(--d2_l)) / 8);
  --shadow-sm: 0 calc(1px * var(--shadow-intensity)) calc(2px * var(--shadow-intensity)) rgba(0,0,0,0.05);
  --shadow-md: 0 calc(4px * var(--shadow-intensity)) calc(6px * var(--shadow-intensity)) rgba(0,0,0,0.1);
  --shadow-lg: 0 calc(10px * var(--shadow-intensity)) calc(20px * var(--shadow-intensity)) rgba(0,0,0,0.15);

  /* ==================================== */
  /* 6. TYPOGRAPHY — fully alive */
  /* ==================================== */
  --type-lightness: calc((var(--d1_l) * 0.7) + (var(--d3_l) * 0.3));
  --font-size-base: calc(1rem + (var(--type-lightness) / 320));

  --line-height-normal:  calc(1.5 + (var(--d3_l) / 140));
  --line-height-tight:   calc(1.25 + (var(--d3_l) / 400));
  --line-height-relaxed: calc(1.75 + (var(--d3_l) / 120));

  --letter-spacing-tight:   calc(-0.02em + (var(--d3_l) / -1500));
  --letter-spacing-normal:  calc(0em + (var(--d3_l) / 1200));

  --edge-sharpness: calc(100 - var(--d2_l));
  --font-weight-medium: calc(500 + (var(--edge-sharpness) * 1.4));
  --font-weight-bold:   calc(700 + (var(--edge-sharpness) * 1.8));

  --hierarchy-strength: calc(100 - var(--d4_l));
  --heading-scale:      calc(1.18 + (var(--hierarchy-strength) / 160));

  --font-size-lg:    calc(var(--font-size-base) * var(--heading-scale));
  --font-size-xl:    calc(var(--font-size-lg)    * var(--heading-scale));
  --font-size-2xl:   calc(var(--font-size-xl)    * var(--heading-scale));
  --font-size-3xl:   calc(var(--font-size-2xl)   * calc(var(--heading-scale) * 1.12));

  /* ==================================== */
  /* 7. TRANSITIONS — energy from hue warmth + density */
  /* ==================================== */
  --transition-base: calc(180ms + (var(--d1_h) / 360 * 300ms) + (var(--d3_l) / 200 * 200ms)) cubic-bezier(0.16, 1, 0.3, 1);
  --transition-fast: calc(var(--transition-base) * 0.6);
  --transition-slow: calc(var(--transition-base) * 1.6);

  /* ==================================== */
  /* 8. SEMANTIC FEEDBACK COLORS */
  /* ==================================== */
  --success: hsl(140, 60%, 50%);
  --warning: hsl(45, 90%, 55%);
  --error: hsl(0, 70%, 55%);
  --info: hsl(200, 70%, 55%);

  /* ==================================== */
  /* 8b. PIPELINE / STATUS STATES */
  /* ==================================== */
  /* A live-process palette: the phases a running agent moves through, plus
     generic status. Derived from the semantic feedback colors so a theme
     (or Spectra) only has to re-point --success/--warning/--error/--info and
     the whole pipeline re-themes with it. Idle keys off the live hue so it
     reads as "present but quiet", not dead grey. Synthing/holding are their
     own hues — the two phases with no semantic equivalent. */
  --state-idle:        hsl(var(--d1_h), 8%, 48%);
  --state-recording:   var(--error);
  --state-transcribing: var(--warning);
  --state-thinking:    var(--info);
  --state-speaking:    var(--success);
  --state-synthing:    hsl(182, 78%, 43%);
  --state-holding:     hsl(40, 55%, 58%);
  /* Generic status (non-pipeline surfaces) */
  --state-loading:     var(--warning);
  --state-ready:       var(--success);
  --state-error:       var(--error);

  /* ==================================== */
  /* 9. COMPONENT INFRASTRUCTURE — Required by component API */
  /* ==================================== */
  /* Form controls */
  --checkbox-size: 1.125rem;
  --radio-size: 1.125rem;
  --toggle-width: 48px;
  --toggle-height: 24px;
  --toggle-thumb-size: 20px;
  --toggle-thumb-offset: 2px;
  --slider-track-height: 8px;
  --slider-thumb-size: 18px;
  /* State dot — one indicator, three sizes. --sm is the inline status role
     (what used to be a separate 12px dot); default is the hero dot. */
  --state-dot-size: 100px;
  --state-dot-size-sm: 12px;
  --state-dot-size-md: 44px;

  /* Loading indicators */
  --spinner-size: 2rem;
  --spinner-size-sm: 1.25rem;
  --spinner-size-lg: 3rem;
  --progress-height: 0.5rem;

  /* Badges and icons */
  --badge-rank-size: 2rem;
  --icon-size-sm: 1rem;
  --icon-size-md: 1.5rem;
  --icon-size-lg: 2rem;
  --icon-size-xl: 2.5rem;
  --icon-size-2xl: 3rem;
  --icon-size-3xl: 3rem;

  /* ==================================== */
  /* 10. INTERACTION UTILITIES */
  /* ==================================== */
  --color-white: white;
  --border-width-sm: 1px;
  --border-width-md: 2px;
  --border-width-lg: 3px;
  --border-width-xl: 4px;
  --opacity-hover: 0.92;
  --opacity-disabled: 0.5;
  --hover-lift: -1px;
  --hover-lift-lg: -2px;
  --focus-ring-shadow: 0 0 0 3px hsla(var(--d1_h), 70%, 50%, 0.25);
}


/* ========== RESET.CSS ========== */
/*
 * Haberdash Reset
 * Browser reset and foundational styles
 */

*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
}

body {
  line-height: var(--line-height-normal, 1.5);
  -webkit-font-smoothing: antialiased;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color: var(--text, hsl(0, 0%, 10%));
  background-color: var(--background, hsl(0, 0%, 98%));
}

img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}

input,
button,
textarea,
select {
  font: inherit;
}

p,
h1,
h2,
h3,
h4,
h5,
h6 {
  overflow-wrap: break-word;
  text-wrap: pretty;
}

a {
  color: var(--primary, hsl(210, 70%, 50%));
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

code {
  font-family: 'Courier New', Courier, monospace;
  background: var(--surface, hsl(0, 0%, 95%));
  padding: 0.125rem 0.25rem;
  border-radius: var(--radius-sm, 4px);
  font-size: 0.9em;
}


/* ========== UTILITIES.CSS ========== */
/*
 * Haberdash Utility Classes
 * Layout, spacing, and helper utilities
 */

/* Layout utilities */
.flex {
  display: flex;
}

.flex--wrap {
  flex-wrap: wrap;
}

.flex--column,
.flex--col {
  flex-direction: column;
}

.items-center {
  align-items: center;
}

.justify-center {
  justify-content: center;
}

.justify-between {
  justify-content: space-between;
}

.grid {
  display: grid;
}

.grid--2 {
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-lg, 1rem);
}

.grid--3 {
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-lg, 1rem);
}

/* Spacing utilities */
.gap-xs {
  gap: var(--space-xs, 0.25rem);
}

.gap-sm {
  gap: var(--space-sm, 0.5rem);
}

.gap-md {
  gap: var(--space-md, 0.75rem);
}

.gap-lg {
  gap: var(--space-lg, 1rem);
}

.gap-xl {
  gap: var(--space-xl, 1.5rem);
}

/* Margin utilities */
.m-0 { margin: 0; }
.mt-xs { margin-top: var(--space-xs, 0.25rem); }
.mt-sm { margin-top: var(--space-sm, 0.5rem); }
.mt-md { margin-top: var(--space-md, 0.75rem); }
.mt-lg { margin-top: var(--space-lg, 1rem); }
.mt-xl { margin-top: var(--space-xl, 1.5rem); }

.mb-xs { margin-bottom: var(--space-xs, 0.25rem); }
.mb-sm { margin-bottom: var(--space-sm, 0.5rem); }
.mb-md { margin-bottom: var(--space-md, 0.75rem); }
.mb-lg { margin-bottom: var(--space-lg, 1rem); }
.mb-xl { margin-bottom: var(--space-xl, 1.5rem); }

.ml-xs { margin-left: var(--space-xs, 0.25rem); }
.ml-sm { margin-left: var(--space-sm, 0.5rem); }
.ml-md { margin-left: var(--space-md, 0.75rem); }
.ml-lg { margin-left: var(--space-lg, 1rem); }
.ml-xl { margin-left: var(--space-xl, 1.5rem); }

.mr-xs { margin-right: var(--space-xs, 0.25rem); }
.mr-sm { margin-right: var(--space-sm, 0.5rem); }
.mr-md { margin-right: var(--space-md, 0.75rem); }
.mr-lg { margin-right: var(--space-lg, 1rem); }
.mr-xl { margin-right: var(--space-xl, 1.5rem); }

/* Padding utilities */
.p-0 { padding: 0; }
.pt-xs { padding-top: var(--space-xs, 0.25rem); }
.pt-sm { padding-top: var(--space-sm, 0.5rem); }
.pt-md { padding-top: var(--space-md, 0.75rem); }
.pt-lg { padding-top: var(--space-lg, 1rem); }
.pt-xl { padding-top: var(--space-xl, 1.5rem); }

.pb-xs { padding-bottom: var(--space-xs, 0.25rem); }
.pb-sm { padding-bottom: var(--space-sm, 0.5rem); }
.pb-md { padding-bottom: var(--space-md, 0.75rem); }
.pb-lg { padding-bottom: var(--space-lg, 1rem); }
.pb-xl { padding-bottom: var(--space-xl, 1.5rem); }

/* Display utilities */
.hidden {
  display: none;
}

.visible {
  display: block;
}

/* Width utilities */
.w-full {
  width: 100%;
}

/* Text utilities */
.text-center {
  text-align: center;
}

.text-left {
  text-align: left;
}

.text-right {
  text-align: right;
}

.text-secondary {
  color: var(--text-secondary, hsl(0, 0%, 40%));
}

/* Color utilities */
.text-primary { color: var(--primary); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-error { color: var(--error); }
.text-info { color: var(--info); }

.bg-primary { background-color: var(--primary); }
.bg-secondary { background-color: var(--secondary); }
.bg-success { background-color: var(--success); }
.bg-warning { background-color: var(--warning); }
.bg-error { background-color: var(--error); }
.bg-info { background-color: var(--info); }
.bg-surface { background-color: var(--surface); }
.bg-background { background-color: var(--background); }

/* Border utilities */
.border { border: var(--border-width-sm) solid var(--border); }
.border-primary { border-color: var(--primary); }
.border-success { border-color: var(--success); }
.border-warning { border-color: var(--warning); }
.border-error { border-color: var(--error); }

/* Border radius utilities */
.radius-sm { border-radius: var(--radius-sm); }
.radius-md { border-radius: var(--radius-md); }
.radius-lg { border-radius: var(--radius-lg); }
.radius-xl { border-radius: var(--radius-xl); }
.radius-full { border-radius: var(--radius-full); }

/* Shadow utilities */
.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow-md { box-shadow: var(--shadow-md); }
.shadow-lg { box-shadow: var(--shadow-lg); }

/* Typography utilities */
.font-sm { font-size: var(--font-size-sm); }
.font-base { font-size: var(--font-size-base); }
.font-lg { font-size: var(--font-size-lg); }
.font-xl { font-size: var(--font-size-xl); }
.font-2xl { font-size: var(--font-size-2xl); }
.font-3xl { font-size: var(--font-size-3xl); }

.font-normal { font-weight: var(--font-weight-normal); }
.font-medium { font-weight: var(--font-weight-medium); }
.font-bold { font-weight: var(--font-weight-bold); }


/* ========== COMPONENT: ACTIVITY-STREAM ========== */
/*
 * Activity Stream + Cue Card
 * A narrow right-rail ribbon of decaying activity. Each event the app fires
 * slides in at the top as a cue card — a coloured dot, a label, an age — and
 * dims to a resting opacity so the rail reads as peripheral until you look.
 * Hover brings the whole rail (or a single card) to full presence. Bursty
 * events of the same track collapse into a cue pile: a header with a live
 * count that expands to reveal its members.
 *
 * The dot colour is driven by the --state-* token palette (tokens.css §8b),
 * the same palette state-dot reads, so an activity type re-themes with
 * Spectra and never hardcodes a pipeline colour.
 *
 * Structure:
 *   .activity-stream              — block; the fixed right-rail, mask-faded
 *     .cue-card[data-type]        — one event; data-type picks the dot colour
 *       .cue-card__dot            — the type swatch
 *       .cue-card__label          — the truncating description
 *       .cue-card__age            — relative age, right-aligned
 *     .cue-pile[data-track]       — a grouped burst of one track
 *       .cue-pile__header         — click target (count + name)
 *         .cue-pile__name
 *         .cue-pile__count
 *       .cue-pile__viewport       — the featured card when collapsed
 *       .cue-pile__members        — the full list when .cue-pile--expanded
 *
 * Modifiers:
 *   .cue-card--fading             — app sets this one beat before removal; the
 *                                   card fades + slides out, then the app drops it
 *   .cue-pile--expanded           — members shown, viewport hidden
 *
 * Behaviour (spawning cards, inserting at top, toggling --expanded, setting
 * --fading before removal, rotating the featured card) belongs to the app.
 * This sheet owns structure, colour, and the slide/fade motion vocabulary.
 */

.activity-stream {
  position: fixed;
  right: var(--space-lg, 1rem);
  top: 0;
  bottom: 0;
  width: var(--activity-stream-width, 180px);
  display: flex;
  flex-direction: column;
  gap: var(--space-xs, 0.25rem);
  z-index: 1;
  overflow-y: auto;
  overflow-x: hidden;
  /* The ribbon fades into the page at its foot so the oldest entries dissolve
     rather than hitting a hard edge. */
  -webkit-mask-image: linear-gradient(to bottom, hsl(0 0% 0% / 1) 0%, hsl(0 0% 0% / 0) 100%);
  mask-image: linear-gradient(to bottom, hsl(0 0% 0% / 1) 0%, hsl(0 0% 0% / 0) 100%);
  transition: padding-top var(--transition-base, 300ms);
}

/* A hairline scrollbar — present on scroll, never a chrome bar. */
.activity-stream::-webkit-scrollbar { width: var(--border-width-xl, 4px); }
.activity-stream::-webkit-scrollbar-thumb {
  background: var(--border, hsl(0 0% 100% / 0.15));
  border-radius: var(--radius-sm, 4px);
}

/* ---- Cue card — one event in the ribbon ---- */
.cue-card {
  display: flex;
  align-items: center;
  gap: var(--space-xs, 0.25rem);
  padding: var(--space-2xs, 0.125rem) var(--space-xs, 0.25rem);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm, 4px);
  /* Idle-dim; the ribbon is peripheral until attended to. */
  opacity: var(--activity-stream-idle-opacity, 0.35);
  cursor: pointer;
  animation: activity-stream-slide-in var(--transition-base, 300ms) ease forwards;
  transition: opacity var(--transition-slow, 500ms);
}

/* Full presence on hover — either a single card or the whole rail. */
.cue-card:hover,
.activity-stream:hover .cue-card { opacity: 1; }

.cue-card__dot {
  width: var(--cue-card-dot-size, 6px);
  height: var(--cue-card-dot-size, 6px);
  flex-shrink: 0;
  border-radius: var(--radius-full, 9999px);
  background: var(--cue-card-dot-color, var(--state-idle, #6b7280));
  opacity: 0.5;
}

/* data-type → colour. One attribute on the card picks the swatch; every
   entry maps to the shared state/semantic palette so it re-themes for free. */
.cue-card[data-type="yes_no_response"]   { --cue-card-dot-color: var(--state-speaking, #10b981); }
.cue-card[data-type="scalar_param"]      { --cue-card-dot-color: var(--state-transcribing, #f59e0b); }
.cue-card[data-type="text_input"]        { --cue-card-dot-color: var(--state-thinking, #3b82f6); }
.cue-card[data-type="approval_response"] { --cue-card-dot-color: var(--state-recording, #ef4444); }
.cue-card[data-type="cue_dispatch"]      { --cue-card-dot-color: var(--accent, var(--info, #38bdf8)); }
.cue-card[data-type="gallery"]           { --cue-card-dot-color: var(--state-synthing, #17c3c3); }
.cue-card[data-type="cuesheet_receipt"]  { --cue-card-dot-color: var(--success, #10b981); }
.cue-card[data-type="timing"]            { --cue-card-dot-color: var(--text-secondary, #888); }
.cue-card[data-type="model_signal"]      { --cue-card-dot-color: var(--state-transcribing, #f59e0b); }
.cue-card[data-type="chip_op"]           { --cue-card-dot-color: var(--state-holding, #d0a85a); }
.cue-card[data-type="chip_status"]       { --cue-card-dot-color: var(--state-holding, #d0a85a); }

/* The faintest types read quieter still — they are telemetry, not events. */
.cue-card[data-type="timing"] .cue-card__dot      { opacity: 0.3; }
.cue-card[data-type="model_signal"] .cue-card__dot { opacity: 0.4; }

.cue-card__label {
  flex: 1;
  min-width: 0;
  font-size: var(--font-size-xs, 0.75rem);
  color: var(--text-secondary, #888);
  opacity: 0.7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cue-card__age {
  flex-shrink: 0;
  font-size: var(--font-size-xs, 0.75rem);
  color: var(--text-secondary, #888);
  opacity: 0.4;
  white-space: nowrap;
}

/* ---- Cue pile — a grouped burst of one track ---- */
.cue-pile {
  margin-bottom: var(--space-xs, 0.25rem);
  border-left: var(--border-width-md, 2px) solid var(--border, hsl(0 0% 100% / 0.15));
  border-radius: var(--radius-sm, 4px);
}

.cue-pile__header {
  display: flex;
  align-items: center;
  gap: var(--space-xs, 0.25rem);
  padding: var(--space-2xs, 0.125rem) var(--space-xs, 0.25rem);
  opacity: var(--activity-stream-idle-opacity, 0.35);
  cursor: pointer;
}
.cue-pile:hover .cue-pile__header,
.activity-stream:hover .cue-pile__header { opacity: 1; }

.cue-pile__name {
  font-size: var(--font-size-xs, 0.75rem);
  font-weight: var(--font-weight-bold, 600);
  color: var(--text-secondary, hsl(0 0% 100% / 0.5));
  text-transform: lowercase;
  letter-spacing: var(--letter-spacing-wide, 0.04em);
}

.cue-pile__count {
  font-size: var(--font-size-xs, 0.75rem);
  color: var(--text-secondary, hsl(0 0% 100% / 0.35));
  opacity: 0.7;
}

.cue-pile__viewport { padding: 0 var(--space-2xs, 0.125rem); }

.cue-pile__members {
  display: none;
  flex-direction: column;
  gap: var(--space-2xs, 0.125rem);
  padding: 0 var(--space-2xs, 0.125rem);
}

/* Expanded: the list replaces the single featured card. */
.cue-pile--expanded .cue-pile__members { display: flex; }
.cue-pile--expanded .cue-pile__viewport { display: none; }

/* ---- Motion vocabulary — enter slides in from the rail, leave fades out ---- */
@keyframes activity-stream-slide-in {
  from { opacity: 0; transform: translateX(var(--activity-stream-slide-distance, 30px)); }
  to   { opacity: var(--activity-stream-idle-opacity, 0.35); transform: translateX(0); }
}
@keyframes activity-stream-fade-out {
  from { opacity: var(--activity-stream-idle-opacity, 0.35); transform: translateX(0); }
  to   { opacity: 0; transform: translateX(calc(var(--activity-stream-slide-distance, 30px) * 0.66)); }
}

/* App sets --fading one beat before removing the node. */
.cue-card--fading {
  pointer-events: none;
  animation: activity-stream-fade-out var(--transition-base, 300ms) ease forwards;
}

/* ---- Accessibility: no slide, fade, or crossfade motion. ---- */
@media (prefers-reduced-motion: reduce) {
  .cue-card,
  .cue-card--fading { animation: none !important; }
  .activity-stream,
  .cue-card { transition: none; }
}


/* ========== COMPONENT: ALERT ========== */
/*
 * Alert Component
 * Notification messages with contextual variants
 */

.alert {
  padding: var(--space-lg, 1rem);
  border-radius: var(--radius-md, 8px);
  border-left: var(--border-width-xl) solid;
  margin-bottom: var(--space-lg, 1rem);
}

.alert__title {
  font-weight: var(--font-weight-bold, 700);
  margin-bottom: var(--space-sm, 0.5rem);
}

.alert__message {
  margin: 0;
}

.alert--success {
  background: var(--success-bg);
  border-color: var(--success, #22c55e);
  color: var(--success-text);
}

.alert--warning {
  background: var(--warning-bg);
  border-color: var(--warning, #eab308);
  color: var(--warning-text);
}

.alert--error {
  background: var(--error-bg);
  border-color: var(--error, #ef4444);
  color: var(--error-text);
}

.alert--info {
  background: var(--info-bg);
  border-color: var(--info, #3b82f6);
  color: var(--info-text);
}


/* ========== COMPONENT: BADGE ========== */
/*
 * Badge Component
 * Small status indicators and labels
 */

.badge {
  display: inline-block;
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--font-size-sm, 0.875rem);
  font-weight: var(--font-weight-medium, 500);
  border-radius: var(--radius-full, 9999px);
  background: var(--surface, #f5f5f5);
  color: var(--text, #1a1a1a);
  border: var(--border-width-sm) solid var(--border, #d4d4d4);
}

.badge--primary {
  background: var(--primary-light, #dbeafe);
  color: var(--primary, #3b82f6);
  border-color: var(--primary, #3b82f6);
}

.badge--success {
  background: var(--success-bg);
  color: var(--success, #22c55e);
  border-color: var(--success, #22c55e);
}

.badge--warning {
  background: var(--warning-bg);
  color: var(--warning, #eab308);
  border-color: var(--warning, #eab308);
}

.badge--error {
  background: var(--error-bg);
  color: var(--error, #ef4444);
  border-color: var(--error, #ef4444);
}

.badge--info {
  background: var(--info-bg);
  color: var(--info, #3b82f6);
  border-color: var(--info, #3b82f6);
}

.badge--neutral {
  background: var(--surface, #f5f5f5);
  color: var(--text-secondary, #666);
  border-color: var(--border, #d4d4d4);
}

.badge--rank {
  background: var(--primary, #3b82f6);
  color: var(--color-white);
  border-color: var(--primary, #3b82f6);
  font-weight: var(--font-weight-bold, 700);
  min-width: var(--badge-rank-size);
  text-align: center;
}


/* ========== COMPONENT: BUTTON ========== */
/*
 * Button Component
 * Versatile button styles with variants and sizes
 */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-sm) var(--space-lg);
  font-size: var(--font-size-base, 1rem);
  font-weight: var(--font-weight-medium, 500);
  line-height: var(--line-height-normal);
  text-decoration: none;
  border: var(--border-width-sm) solid transparent;
  border-radius: var(--radius-md, 8px);
  cursor: pointer;
  transition: all var(--transition-base, 200ms ease);
  background: var(--surface, hsl(0, 0%, 95%));
  color: var(--text, hsl(0, 0%, 10%));
}

.btn:hover {
  opacity: var(--opacity-hover);
  transform: translateY(var(--hover-lift));
}

.btn:active {
  transform: translateY(0);
}

.btn:disabled {
  opacity: var(--opacity-disabled);
  cursor: not-allowed;
}

/* Primary variant */
.btn--primary {
  background: var(--primary, hsl(210, 70%, 50%));
  color: var(--color-white);
  border-color: var(--primary, hsl(210, 70%, 50%));
}

.btn--primary:hover {
  background: var(--primary-hover, hsl(210, 70%, 60%));
}

/* Secondary variant */
.btn--secondary {
  background: var(--secondary, hsl(0, 0%, 40%));
  color: var(--color-white);
  border-color: var(--secondary, hsl(0, 0%, 40%));
}

.btn--secondary:hover {
  background: var(--secondary-hover, hsl(0, 0%, 50%));
}

/* Success variant */
.btn--success {
  background: var(--success, hsl(140, 60%, 50%));
  color: var(--color-white);
  border-color: var(--success, hsl(140, 60%, 50%));
}

/* Warning variant */
.btn--warning {
  background: var(--warning, hsl(45, 90%, 55%));
  color: var(--text);
  border-color: var(--warning, hsl(45, 90%, 55%));
}

/* Error variant */
.btn--error {
  background: var(--error, hsl(0, 70%, 55%));
  color: var(--color-white);
  border-color: var(--error, hsl(0, 70%, 55%));
}

/* Size variants */
.btn--sm {
  padding: var(--space-xs) var(--space-md);
  font-size: var(--font-size-sm, 0.875rem);
}

.btn--lg {
  padding: var(--space-md) var(--space-xl);
  font-size: var(--font-size-lg, 1.125rem);
}

.btn--xl {
  padding: var(--space-lg) var(--space-2xl);
  font-size: var(--font-size-xl, 1.25rem);
}


/* ========== COMPONENT: CARD ========== */
/*
 * Card Component
 * Container for grouped content with header, body, and actions
 */

.card {
  background: var(--surface, #f5f5f5);
  border: var(--border-width-sm) solid var(--border, #d4d4d4);
  border-radius: var(--radius-md, 8px);
  overflow: hidden;
  transition: all var(--transition-base, 200ms);
}

.card:hover {
  box-shadow: var(--shadow-md, 0 4px 6px rgba(0,0,0,0.1));
  transform: translateY(var(--hover-lift-lg));
}

.card__header {
  padding: var(--space-lg, 1rem);
  border-bottom: var(--border-width-sm) solid var(--border-light, #e5e5e5);
}

.card__icon {
  font-size: var(--font-size-2xl, 1.5rem);
  margin-bottom: var(--space-sm, 0.5rem);
}

.card__title {
  font-size: var(--font-size-lg, 1.125rem);
  font-weight: var(--font-weight-bold, 700);
  color: var(--text-heading, #000);
  margin: 0;
}

.card__body {
  padding: var(--space-lg, 1rem);
}

.card__description {
  color: var(--text-secondary, #666);
  margin: 0;
}

.card__actions {
  padding: var(--space-lg, 1rem);
  border-top: var(--border-width-sm) solid var(--border-light, #e5e5e5);
  display: flex;
  gap: var(--space-sm, 0.5rem);
}


/* ========== COMPONENT: CHAT-CARD ========== */
/*
 * Chat Card
 * A single conversation message, built on the base card vocabulary. One card is
 * one turn: a user turn aligns left, an assistant turn aligns right, both share
 * a header (speaker + timestamp), a speakable body, and an actions/reactions rail.
 *
 * This is the ELEVATE card for conversation — it does NOT restyle .card; it
 * composes alongside it. Put both classes on the element:
 *   <article class="card chat-card chat-card--assistant">
 *
 * Alignment, mute state, and the "speaking" highlight are all driven by the app
 * (adding a modifier class / toggling .is-speaking). This sheet owns structure,
 * presentation, and the motion vocabulary only — zero JavaScript.
 *
 * Structure:
 *   .chat-card .chat-card--user | --assistant   — block; modifier picks the side
 *     .chat-card__header                        — speaker row (name + timestamp + status dot)
 *       .chat-card__timestamp                   — relative/absolute time, muted
 *     .chat-card__body                          — the message
 *       .tts-speakable                          — one paragraph; hover + .is-speaking highlight
 *     .chat-card__actions                       — mute / pin rail (opacity-reveal on hover)
 *       .chat-card__action                      — one <button>
 *     .chat-card__reactions                     — emoji reaction row
 *       .chat-card__reaction                    — one <button>
 *   .chat-card--muted                           — dimmed, de-emphasised turn
 *
 * Hooks the app drives:
 *   - .chat-card--user / --assistant   alignment (set once at build)
 *   - .chat-card--muted                mute treatment (toggled by the mute button)
 *   - .tts-speakable.is-speaking       the paragraph currently being spoken
 *   - a composed state-dot (state-dot state-dot--sm) may sit in the header slot
 */

.chat-card {
  /* The turn claims most of the column but never the full width, so the
     opposite side reads as "the other speaker". One variable, two alignments. */
  width: var(--chat-card-width, 80%);
  max-width: var(--chat-card-width, 80%);
  display: block;
  box-sizing: border-box;
  position: relative;
}

/* ---- Alignment. The modifier picks the side; margin does the work. ---- */
.chat-card--user      { margin-right: auto; margin-left: 0; }
.chat-card--assistant { margin-left: auto;  margin-right: 0; }

/* ---- Header: speaker, time, and an optional live status dot. ---- */
/* The base .card__header has a divider + big padding meant for document cards;
   a chat header is a quiet one-liner, so we override to a tight flex row. */
.chat-card__header {
  display: flex;
  align-items: center;
  gap: var(--space-sm, 0.5rem);
  padding: var(--space-sm, 0.5rem) var(--space-lg, 1rem);
  border-bottom: 0;
}

.chat-card__speaker {
  font-size: var(--font-size-sm, 0.875rem);
  font-weight: var(--font-weight-medium, 500);
  color: var(--text-secondary, #666);
  margin: 0;
}

/* Timestamp sits to the far side of the header and stays out of the way. */
.chat-card__timestamp {
  margin-left: auto;
  font-size: var(--font-size-sm, 0.875rem);
  color: var(--text-secondary, #888);
  opacity: 0.65;
}

/* ---- Body: markdown prose inherits Haberdash typography. ---- */
.chat-card__body {
  padding: var(--space-md, 0.75rem) var(--space-lg, 1rem) var(--space-lg, 1rem);
  line-height: var(--line-height-normal, 1.5);
}

/* Paragraph-level TTS. Each speakable block is its own click target; hover
   previews it, and .is-speaking (app-driven) marks the one being read now. */
.tts-speakable {
  cursor: pointer;
  border-radius: var(--radius-sm, 4px);
  padding: var(--space-xs, 0.25rem) var(--space-sm, 0.5rem);
  /* Pull the hit area out to the body edge so the padding reads as hover,
     not indent. */
  margin-left: calc(-1 * var(--space-sm, 0.5rem));
  margin-right: calc(-1 * var(--space-sm, 0.5rem));
  transition: background-color var(--transition-fast, 150ms);
}

.tts-speakable:hover {
  background: var(--surface-hover,
    color-mix(in srgb, var(--text, #000) 6%, transparent));
}

/* The spoken paragraph: a calmer, longer settle so the highlight tracks the
   voice rather than a pointer. Two hooks, one treatment: .is-speaking is this
   component's name; .tts-speaking is the pre-existing app convention (cue-vox
   toggles it), so an existing surface migrates by swapping classes without
   losing its spoken highlight. */
.tts-speakable.is-speaking,
.tts-speakable.tts-speaking {
  background: var(--surface-active,
    color-mix(in srgb, var(--primary, #4f46e5) 14%, transparent));
  transition: background-color var(--transition-slow, 600ms);
}

/* ---- Actions rail: mute / pin. Hidden until the turn is hovered. ---- */
.chat-card__actions {
  list-style: none;
  display: flex;
  gap: var(--space-2xs, 0.125rem);
  margin: 0;
  padding: 0;
  position: absolute;
  top: var(--space-xs, 0.25rem);
  right: var(--space-xs, 0.25rem);
  opacity: 0;
  transition: opacity var(--transition-fast, 150ms);
}

/* Reveal the rail on hover or focus-within (keyboard reaches it too). */
.chat-card:hover .chat-card__actions,
.chat-card__actions:focus-within {
  opacity: 1;
}

.chat-card__action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: var(--border-width-sm, 1px) solid var(--border, #d4d4d4);
  border-radius: var(--radius-sm, 4px);
  padding: var(--space-2xs, 0.125rem) var(--space-xs, 0.25rem);
  color: var(--text-secondary, #888);
  cursor: pointer;
  opacity: 0.55;
  transition: opacity var(--transition-fast, 150ms),
              transform var(--transition-fast, 150ms),
              color var(--transition-fast, 150ms);
}

.chat-card__action:hover  { opacity: 1; transform: scale(1.15); color: var(--text, #000); }
.chat-card__action:active { transform: scale(0.92); }

/* A toggled action (mute/pin ON) stays lit so state reads without hover. */
.chat-card__action[aria-pressed="true"] {
  opacity: 1;
  color: var(--primary, #4f46e5);
  border-color: var(--primary, #4f46e5);
}

/* ---- Reactions row. Emoji responses, trailing the body. ---- */
.chat-card__reactions {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs, 0.25rem);
  margin: var(--space-sm, 0.5rem) var(--space-lg, 1rem) var(--space-md, 0.75rem);
  padding: 0;
}

/* User turns are right-aligned, so their reaction row trails to the left. */
.chat-card--user .chat-card__reactions { justify-content: flex-start; }
.chat-card--assistant .chat-card__reactions { justify-content: flex-end; }

.chat-card__reaction {
  background: none;
  border: var(--border-width-sm, 1px) solid var(--border, #d4d4d4);
  border-radius: var(--radius-sm, 4px);
  padding: var(--space-2xs, 0.125rem) var(--space-xs, 0.25rem);
  font-size: var(--font-size-base, 1rem);
  line-height: 1;
  cursor: pointer;
  opacity: 0.45;
  transition: opacity var(--transition-fast, 150ms),
              transform var(--transition-fast, 150ms);
}

.chat-card__reaction:hover  { opacity: 1; transform: scale(1.2); }
.chat-card__reaction:active { transform: scale(0.9); }

/* A reaction the user has already given reads as selected. */
.chat-card__reaction[aria-pressed="true"] {
  opacity: 1;
  border-color: var(--primary, #4f46e5);
  background: color-mix(in srgb, var(--primary, #4f46e5) 12%, transparent);
}

/* ---- Muted turn: a dimmed, slightly shrunk echo of a de-emphasised turn
   (the same treatment pulled history gets). ---- */
.chat-card--muted {
  opacity: 0.55;
}

.chat-card--muted .chat-card__body {
  font-size: 0.92em;
}

/* ---- Arrival motion: a new turn settles in from its own side. The app adds
   .chat-card--enter when it appends the node; the class may stay on — the
   animation runs once. ---- */
.chat-card--enter {
  animation: chat-card-arrive var(--transition-base, 300ms) both;
}
.chat-card--user.chat-card--enter      { animation-name: chat-card-arrive-left; }
.chat-card--assistant.chat-card--enter { animation-name: chat-card-arrive-right; }

@keyframes chat-card-arrive {
  from { opacity: 0; transform: translateY(var(--space-xs, 0.25rem)); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes chat-card-arrive-left {
  from { opacity: 0; transform: translateX(calc(-1 * var(--space-sm, 0.5rem))); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes chat-card-arrive-right {
  from { opacity: 0; transform: translateX(var(--space-sm, 0.5rem)); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ---- Accessibility: the rail stays reachable, but nothing animates and the
   speaking highlight snaps instead of fading. ---- */
@media (prefers-reduced-motion: reduce) {
  .chat-card--enter { animation: none; }
  .tts-speakable,
  .tts-speakable.is-speaking,
  .tts-speakable.tts-speaking,
  .chat-card__actions,
  .chat-card__action,
  .chat-card__reaction { transition: none; }
}


/* ========== COMPONENT: DIALOG ========== */
/*
 * Dialog / Lightbox
 * One modal surface for the whole system. A backdrop plus a centred content
 * panel — header (title + close), scrollable body, action footer. It is the
 * keystone that replaces five hand-rolled modals: a plain dialog, a big
 * yes/no decision, and a full-bleed media gallery are the same component
 * wearing three modifiers.
 *
 * Every colour, space, radius, shadow and motion value is a token with a
 * fallback, so the modal re-themes with Spectra for free and never hardcodes
 * a surface colour. The sheet owns structure, presentation and a motion
 * vocabulary only.
 *
 * Structure:
 *   .dialog[open|data-open]              — block; the full-viewport layer
 *     .dialog__backdrop                  — the dimmed, blurred scrim
 *     .dialog__content                   — the panel (header/body/footer stack)
 *       .dialog__header                  — title row
 *         .dialog__title                 — the heading
 *         .dialog__close                 — the dismiss button (× / aria-label)
 *       .dialog__body                    — scrollable content region
 *       .dialog__footer                  — right-aligned actions
 *
 * Variants (modifiers on .dialog):
 *   .dialog--yes-no    — one big question + two 50/50 action buttons
 *   .dialog--gallery   — full-bleed stage, prev/next nav, caption footer
 *   .dialog--compact   — a narrow panel for short forms / confirmations
 *
 * Migration from maestro-js: the legacy classes map one-to-one, so a swap is
 * mechanical, not a rewrite.
 *   .lightbox          → .dialog
 *   .lightbox__*       → .dialog__*
 *   .yesno-lightbox    → .dialog.dialog--yes-no  (question = .dialog__question)
 *   .gallery-lightbox  → .dialog.dialog--gallery (chrome = .dialog__content;
 *                        stage/image/nav/counter/caption are __stage/__image/
 *                        __nav/__counter/__caption)
 *
 * Behaviour — spawning the node, toggling visibility, moving the gallery index,
 * trapping focus, locking body scroll — belongs to the app. The app shows the
 * modal by adding [open] (on a <dialog>) or the data-open attribute, and locks
 * the page by adding the .dialog-scroll-lock hook to <body>. This sheet owns
 * structure, colour and the open/close motion only.
 */

.dialog {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal, 1000);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg, 1.5rem);
}

/* Hidden by default; the app opens it via [open] (native <dialog>) or
   [data-open]. Either hook flips display + runs the enter motion. */
.dialog:not([open]):not([data-open="true"]) {
  display: none;
}

.dialog__backdrop {
  position: absolute;
  inset: 0;
  background: var(--dialog-backdrop, rgba(0, 0, 0, 0.6));
  backdrop-filter: blur(var(--dialog-backdrop-blur, 4px));
  -webkit-backdrop-filter: blur(var(--dialog-backdrop-blur, 4px));
  animation: dialog-fade-in var(--transition-base, 300ms) both;
}

.dialog__content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: var(--dialog-width, 640px);
  max-height: calc(100vh - var(--space-2xl, 3rem));
  background: var(--surface, #1a1a1a);
  border: var(--border-width-sm, 1px) solid var(--border, rgba(255, 255, 255, 0.1));
  border-radius: var(--radius-lg, 12px);
  box-shadow: var(--shadow-lg, 0 10px 20px rgba(0, 0, 0, 0.3));
  overflow: hidden;
  animation: dialog-rise var(--transition-base, 300ms) both;
}

.dialog__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm, 0.5rem);
  flex-shrink: 0;
  padding: var(--space-lg, 1.5rem) var(--space-xl, 2rem);
  border-bottom: var(--border-width-sm, 1px) solid var(--border, rgba(255, 255, 255, 0.1));
}

.dialog__title {
  margin: 0;
  flex: 1;
  font-size: var(--font-size-lg, 1.125rem);
  font-weight: var(--font-weight-bold, 700);
  line-height: var(--line-height-tight, 1.25);
  letter-spacing: var(--letter-spacing-tight, -0.01em);
  color: var(--text-heading, var(--text, #fff));
}

.dialog__close {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--dialog-close-size, 2rem);
  height: var(--dialog-close-size, 2rem);
  padding: 0;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm, 4px);
  color: var(--text-secondary, #888);
  font-size: var(--font-size-xl, 1.5rem);
  line-height: 1;
  cursor: pointer;
  transition: color var(--transition-fast, 150ms),
              background-color var(--transition-fast, 150ms);
}

.dialog__close:hover {
  color: var(--text, #fff);
  background: color-mix(in srgb, var(--text, #fff) 8%, transparent);
}

/* Keyboard focus is explicit and visible; pointer focus stays quiet. */
.dialog__close:focus-visible {
  outline: var(--border-width-md, 2px) solid var(--primary, #3b82f6);
  outline-offset: var(--border-width-md, 2px);
}

.dialog__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--space-lg, 1.5rem) var(--space-xl, 2rem);
  font-size: var(--font-size-base, 1rem);
  line-height: var(--line-height-relaxed, 1.7);
  color: var(--text, #fff);
}

.dialog__footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-sm, 0.5rem);
  flex-shrink: 0;
  padding: var(--space-md, 0.75rem) var(--space-xl, 2rem);
  border-top: var(--border-width-sm, 1px) solid var(--border, rgba(255, 255, 255, 0.1));
}

/* ======================================================================
   Variant: --compact — a narrow panel for short forms and confirmations.
   ====================================================================== */
.dialog--compact .dialog__content {
  max-width: var(--dialog-width-compact, 420px);
}

/* ======================================================================
   Variant: --yes-no — one big question with two 50/50 action buttons.
   The decision is the whole modal: centred question, buttons that fill
   the footer so either answer is a large, equal, hands-free target.
   ====================================================================== */
.dialog--yes-no .dialog__content {
  max-width: var(--dialog-width-compact, 420px);
  text-align: center;
}

/* The oversized prompt that stands in for a header title. */
.dialog--yes-no .dialog__question {
  margin: 0;
  padding: var(--space-2xl, 3rem) var(--space-xl, 2rem) var(--space-lg, 1.5rem);
  font-size: var(--font-size-xl, 1.5rem);
  font-weight: var(--font-weight-bold, 700);
  line-height: var(--line-height-tight, 1.25);
  color: var(--text-heading, var(--text, #fff));
}

/* Two equal targets, no right-alignment — a decision, not a toolbar. */
.dialog--yes-no .dialog__footer {
  justify-content: flex-start;
  flex-wrap: nowrap;
  gap: var(--space-md, 0.75rem);
  padding: var(--space-xl, 2rem);
  border-top: none;
}

.dialog--yes-no .dialog__footer > .btn {
  flex: 1 1 0;
  min-height: var(--dialog-action-height, 4.5rem);
  font-size: var(--font-size-lg, 1.125rem);
  font-weight: var(--font-weight-bold, 700);
}

/* ======================================================================
   Variant: --gallery — a full-bleed media viewer. The backdrop goes near
   opaque, the panel fills the viewport, and the body becomes a stage with
   prev/next nav and a quiet caption footer.
   ====================================================================== */
.dialog--gallery {
  padding: 0;
}

.dialog--gallery .dialog__backdrop {
  background: var(--dialog-backdrop-strong, rgba(0, 0, 0, 0.92));
  backdrop-filter: blur(var(--dialog-backdrop-blur-strong, 8px));
  -webkit-backdrop-filter: blur(var(--dialog-backdrop-blur-strong, 8px));
}

.dialog--gallery .dialog__content {
  width: 100%;
  height: 100%;
  max-width: 100vw;
  max-height: 100vh;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

.dialog--gallery .dialog__header {
  border-bottom: none;
  padding: var(--space-md, 0.75rem) var(--space-lg, 1.5rem);
}

/* A running count ("3 / 12") beside the title. */
.dialog__counter {
  flex-shrink: 0;
  font-size: var(--font-size-sm, 0.875rem);
  color: var(--text-secondary, #888);
  white-space: nowrap;
}

/* The stage: the media sits centred and contained; nav rides its edges. */
.dialog__stage {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0 var(--space-2xl, 3rem);
}

.dialog__image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--radius-sm, 4px);
}

.dialog__nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--dialog-nav-size, 2.75rem);
  height: var(--dialog-nav-size, 2.75rem);
  border: var(--border-width-sm, 1px) solid var(--border, rgba(255, 255, 255, 0.15));
  border-radius: var(--radius-full, 9999px);
  background: var(--dialog-nav-bg, rgba(0, 0, 0, 0.5));
  color: var(--text, #fff);
  font-size: var(--font-size-xl, 1.5rem);
  line-height: 1;
  cursor: pointer;
  transition: background-color var(--transition-fast, 150ms),
              border-color var(--transition-fast, 150ms);
}

.dialog__nav:hover {
  background: color-mix(in srgb, var(--text, #fff) 12%, transparent);
  border-color: color-mix(in srgb, var(--text, #fff) 30%, transparent);
}

.dialog__nav:focus-visible {
  outline: var(--border-width-md, 2px) solid var(--primary, #3b82f6);
  outline-offset: var(--border-width-md, 2px);
}

.dialog__nav--prev { left: var(--space-md, 0.75rem); }
.dialog__nav--next { right: var(--space-md, 0.75rem); }

/* The gallery footer is a centred caption, not a right-aligned toolbar. */
.dialog--gallery .dialog__footer {
  justify-content: center;
  text-align: center;
  border-top: none;
  padding: var(--space-sm, 0.5rem) var(--space-lg, 1.5rem) var(--space-md, 0.75rem);
}

.dialog__caption {
  margin: 0;
  font-size: var(--font-size-sm, 0.875rem);
  color: var(--text-secondary, #888);
}

/* ======================================================================
   Motion vocabulary. The backdrop fades, the panel rises into place.
   ====================================================================== */
@keyframes dialog-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes dialog-rise {
  from { opacity: 0; transform: translateY(var(--dialog-rise-from, 1rem)) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ======================================================================
   Responsive: on small viewports a default dialog goes full-screen so the
   content and its footer are reachable (gallery already fills the screen).
   ====================================================================== */
@media (max-width: 640px) {
  .dialog:not(.dialog--yes-no):not(.dialog--gallery) {
    padding: 0;
  }

  .dialog:not(.dialog--yes-no):not(.dialog--gallery) .dialog__content {
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
  }

  /* Keep the footer clear of the home indicator on notched phones. */
  .dialog:not(.dialog--gallery) .dialog__footer {
    padding-bottom: calc(var(--space-md, 0.75rem) + env(safe-area-inset-bottom, 0px));
  }
}

/* ======================================================================
   Accessibility: kill the enter motion; show the modal instantly.
   ====================================================================== */
@media (prefers-reduced-motion: reduce) {
  .dialog__backdrop,
  .dialog__content {
    animation: none;
  }
}


/* ========== COMPONENT: DROP-ZONE ========== */
/*
 * Drop Zone
 * A full-viewport drag-and-drop capture overlay. When a drag enters the
 * window, the app reveals this sheet: it dims everything, paints a dashed
 * frame from edge to edge, and centres a single prompt. Release to drop,
 * leave to dismiss. It is the WHOLE-WINDOW target — distinct from the inline
 * .upload component (a card-sized picker), which stays as-is.
 *
 * Hidden by default; the app opts it in with the --active modifier on a real
 * dragenter, so a mis-fire never leaves a dead curtain over the page. The
 * curtain itself is pointer-events: none so it can sit above the app without
 * stealing clicks; the app's own dragover/drop handlers live on the surface
 * underneath (or on this block, re-enabled when active).
 *
 * Colour is driven by the semantic palette — the dashed frame reads as
 * --primary (the invited action), the dim is a token-mixed scrim — so it
 * re-themes with Spectra and never hardcodes a curtain colour.
 *
 * Structure:
 *   .drop-zone[.drop-zone--active]   — block; the app toggles --active
 *     .drop-zone__label              — the centred prompt ("Drop to view")
 *
 * Behaviour (listening for dragenter/leave/drop, toggling --active, reading
 * the dropped files) belongs to the app. This sheet owns structure,
 * presentation, and the fade/lift motion only.
 */

.drop-zone {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay, 9999);

  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2xl, 3rem);

  /* A token-mixed scrim rather than a bare black — re-themes with the palette. */
  background: color-mix(in srgb, var(--background, #000) 28%, transparent);
  -webkit-backdrop-filter: blur(var(--drop-zone-blur, 2px));
  backdrop-filter: blur(var(--drop-zone-blur, 2px));

  /* The invited frame: dashed, edge-inset, in the primary accent. */
  border: var(--border-width-lg, 3px) dashed
          color-mix(in srgb, var(--primary, #3b82f6) 70%, transparent);
  border-radius: var(--radius-md, 8px);

  /* Hidden until the app opts in; the curtain never steals pointer events. */
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity var(--transition-fast, 150ms) ease,
              visibility var(--transition-fast, 150ms) ease;
}

/* ---- Active: the app sets this on a real dragenter. ---- */
.drop-zone--active {
  opacity: 1;
  visibility: visible;
  /* Re-enabled so the block can carry the drop handler if the app wants it. */
  pointer-events: auto;
  animation: drop-zone-enter var(--transition-fast, 150ms) ease;
}

.drop-zone__label {
  font-size: var(--font-size-lg, 1.25rem);
  letter-spacing: var(--letter-spacing-wide, 0.05em);
  color: var(--text-secondary, rgba(255, 255, 255, 0.6));
  text-align: center;
  user-select: none;
}

/* The label lifts a hair as the curtain fades in — a light "catch" gesture. */
@keyframes drop-zone-enter {
  from { opacity: 0; transform: scale(0.995); }
  to   { opacity: 1; transform: scale(1); }
}

/* ---- Accessibility: no fade/lift, just the state change. ---- */
@media (prefers-reduced-motion: reduce) {
  .drop-zone { transition: none; }
  .drop-zone--active { animation: none; }
}


/* ========== COMPONENT: FORM ========== */
/*
 * Form Component
 * Input fields, selects, textareas, and form controls
 */

.form-group {
  margin-bottom: var(--space-lg, 1rem);
}

.form__label {
  display: block;
  margin-bottom: var(--space-sm, 0.5rem);
  font-weight: var(--font-weight-medium, 500);
  color: var(--text-heading, #000);
}

.form__input,
.form__select,
.form__textarea {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  background: var(--input-bg);
  border: var(--border-width-sm) solid var(--border, #d4d4d4);
  border-radius: var(--radius-md, 8px);
  font-size: var(--font-size-base, 1rem);
  transition: border-color var(--transition-fast, 150ms);
}

.form__input:focus,
.form__select:focus,
.form__textarea:focus {
  outline: none;
  border-color: var(--primary, #3b82f6);
  box-shadow: var(--focus-ring-shadow);
}

.form__textarea {
  min-height: var(--textarea-min-height);
  resize: vertical;
}

.form__hint {
  display: block;
  margin-top: var(--space-xs, 0.25rem);
  font-size: var(--font-size-sm, 0.875rem);
  color: var(--text-secondary, #666);
}

.form__fieldset {
  border: var(--border-width-sm) solid var(--border, #d4d4d4);
  border-radius: var(--radius-md, 8px);
  padding: var(--space-lg, 1rem);
  margin-bottom: var(--space-lg, 1rem);
}

.form__legend {
  font-weight: var(--font-weight-medium, 500);
  color: var(--text-heading, #000);
  padding: 0 var(--space-sm, 0.5rem);
}

.form__choice {
  display: flex;
  align-items: center;
  gap: var(--space-sm, 0.5rem);
  margin-bottom: var(--space-sm, 0.5rem);
  cursor: pointer;
}

.form__choice input[type="checkbox"],
.form__choice input[type="radio"] {
  width: var(--checkbox-size);
  height: var(--checkbox-size);
  cursor: pointer;
}


/* ========== COMPONENT: GALLERY ========== */
/*
 * Gallery
 * In-content media layouts — the three shapes a set of images/video takes
 * inside a card or message, before the lightbox (the dialog--gallery variant)
 * ever opens. One shared element vocabulary (__track, __item, __thumb,
 * __caption) rendered three ways by a layout modifier on the block:
 *
 *   .gallery--strip    — a horizontal snap-scroll row of thumbnails (3+)
 *   .gallery--hero     — a single full-width cover image (1)
 *   .gallery--compare  — a 2-up side-by-side grid (2)
 *
 * All colour comes from the semantic palette (--surface, --border,
 * --border-light, --primary, --text-secondary) so it re-themes with Spectra and
 * never pins a channel. Behaviour —
 * which layout to render, opening the lightbox, flagging a broken image —
 * belongs to the app.
 *
 * Structure:
 *   .gallery[data-gallery-id]                 — block (<figure>); modifier picks the shape
 *     .gallery__header                        — optional caption + action row
 *       .gallery__title                       — the set's label (<figcaption>)
 *     .gallery__track                         — the scroll row / grid / single slot
 *       .gallery__item                        — one media cell (<button>); click → lightbox
 *         .gallery__thumb                     — the <img>, object-fit: cover
 *         .gallery__thumb--video              — placeholder fill for a video with no poster
 *         .gallery__badge                     — play glyph overlaid on a video item
 *         .gallery__caption                   — per-item label
 *     .gallery__count                         — "N images" summary line
 *
 * Behaviour the app drives:
 *   - picks the layout modifier from the item count (1 → hero, 2 → compare, 3+ → strip)
 *   - adds .gallery__item--error to an item whose image failed to load
 *   - opens the lightbox (dialog--gallery) on item click — this sheet owns none of that
 */

.gallery {
  position: relative;
  width: 100%;
  margin-top: var(--space-md, 0.75rem);
}

/* ---- header: the set label on the left, app-supplied actions on the right ---- */
.gallery__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm, 0.5rem);
  margin-bottom: var(--space-xs, 0.25rem);
}

.gallery__title {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: var(--font-size-sm, 0.8125rem);
  color: var(--text-secondary, #888);
  /* One line — long titles ellipsize rather than wrap the header. */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- track: the shape layer. Strip = scroll row; hero/compare restyle it. ---- */
.gallery__track {
  display: flex;
  gap: var(--space-xs, 0.25rem);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  padding-bottom: var(--space-xs, 0.25rem);
}

.gallery__track::-webkit-scrollbar {
  height: var(--border-width-xl, 4px);
}
.gallery__track::-webkit-scrollbar-thumb {
  background: var(--border, rgba(255, 255, 255, 0.15));
  border-radius: var(--radius-full, 9999px);
}

/* ---- item: one tappable media cell. A real <button>, so it is zeroed out. ---- */
.gallery__item {
  position: relative;
  flex: 0 0 120px;
  scroll-snap-align: start;
  appearance: none;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  color: var(--text, #fff);
  background: var(--surface, rgba(255, 255, 255, 0.04));
  border: var(--border-width-sm, 1px) solid var(--border-light, rgba(255, 255, 255, 0.08));
  border-radius: var(--radius-sm, 4px);
  transition: border-color var(--transition-fast, 150ms),
              transform var(--transition-fast, 150ms),
              box-shadow var(--transition-fast, 150ms);
}

/* Hover lift — a hairline accent border, a nudge up, a soft shadow. */
.gallery__item:hover {
  border-color: var(--primary, rgba(255, 255, 255, 0.25));
  transform: translateY(-2px);
  box-shadow: var(--shadow-md, 0 4px 6px rgba(0, 0, 0, 0.1));
}
.gallery__item:focus-visible {
  outline: var(--border-width-md, 2px) solid var(--primary, #6b8afd);
  outline-offset: var(--border-width-md, 2px);
}

.gallery__thumb {
  display: block;
  width: 100%;
  height: 80px;
  object-fit: cover;
}

/* A video with no poster: a flat dark fill behind the play badge. */
.gallery__thumb--video {
  background: var(--surface, #1a1a1a);
}

/* ---- error: the image 404'd. Hide the broken thumb, show a labelled void. ---- */
.gallery__item--error .gallery__thumb {
  display: none;
}
.gallery__item--error {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80px;
  background: var(--surface, rgba(255, 255, 255, 0.02));
}
.gallery__item--error::before {
  content: "Image not found";
  padding: var(--space-xs, 0.25rem);
  font-size: var(--font-size-xs, 0.75rem);
  color: var(--text-secondary, #888);
  text-align: center;
}

/* ---- play badge: a disc + CSS triangle, centred over a video thumb. ---- */
.gallery__badge {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 28px;
  transform: translate(-50%, -60%);
  border-radius: var(--radius-full, 9999px);
  background: var(--gallery-badge-bg, rgba(0, 0, 0, 0.6));
  pointer-events: none;
}
.gallery__badge::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 55%;
  transform: translate(-50%, -50%);
  border-style: solid;
  border-width: 5px 0 5px 8px;
  border-color: transparent transparent transparent currentColor;
  color: var(--gallery-badge-fg, #fff);
}

/* ---- per-item caption: a quiet one-liner under the thumb. ---- */
.gallery__caption {
  display: block;
  padding: var(--space-2xs, 0.125rem) var(--space-xs, 0.25rem);
  font-size: var(--font-size-xs, 0.75rem);
  color: var(--text-secondary, #888);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- count: the summary line under the whole set. ---- */
.gallery__count {
  margin: var(--space-xs, 0.25rem) 0 0;
  font-size: var(--font-size-xs, 0.75rem);
  color: var(--text-secondary, #888);
}

/* ============================================================
   HERO — a single cover image, full width. The track stops
   being a scroll row and the one item fills it.
   ============================================================ */
.gallery--hero .gallery__track {
  display: block;
}
.gallery--hero .gallery__item {
  flex: none;
  width: 100%;
  background: none;
  border: none;
  border-radius: var(--radius-md, 8px);
}
.gallery--hero .gallery__thumb {
  height: 280px;
}
/* Hero/compare are the hero itself — per-item captions and the count line
   would just be noise, so they drop out. */
.gallery--hero .gallery__caption,
.gallery--hero .gallery__count {
  display: none;
}

/* ============================================================
   COMPARE — two images, side by side. The track becomes a
   fixed 2-column grid; items fill their column.
   ============================================================ */
.gallery--compare .gallery__track {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-sm, 0.5rem);
  overflow: visible;
}
.gallery--compare .gallery__item {
  flex: none;
  width: 100%;
  background: none;
  border: none;
  border-radius: var(--radius-md, 8px);
}
.gallery--compare .gallery__thumb {
  height: 200px;
}
.gallery--compare .gallery__caption,
.gallery--compare .gallery__count {
  display: none;
}

/* On a narrow screen the two-up stacks rather than squeezing to slivers. */
@media (max-width: 640px) {
  .gallery--compare .gallery__track {
    grid-template-columns: 1fr;
  }
}

/* ---- Reduced motion: drop the hover lift's travel; keep the colour cue. ---- */
@media (prefers-reduced-motion: reduce) {
  .gallery__item {
    transition: border-color var(--transition-fast, 150ms);
  }
  .gallery__item:hover {
    transform: none;
    box-shadow: none;
  }
}


/* ========== COMPONENT: LIST-CARD ========== */
/*
 * List Card Component
 * Display lists of items with status
 */

.list-card {
  background: var(--surface, #f5f5f5);
  border: var(--border-width-sm) solid var(--border, #d4d4d4);
  border-radius: var(--radius-md, 8px);
  overflow: hidden;
}

.list-card__header {
  padding: var(--space-lg, 1rem);
  border-bottom: var(--border-width-sm) solid var(--border-light, #e5e5e5);
}

.list-card__title {
  font-size: var(--font-size-lg, 1.125rem);
  font-weight: var(--font-weight-bold, 700);
  margin: 0;
}

.list-card__list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.list-card__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg, 1rem);
  border-bottom: var(--border-width-sm) solid var(--border-light, #e5e5e5);
}

.list-card__item:last-child {
  border-bottom: none;
}

.list-card__item-content {
  flex: 1;
}

.list-card__item-title {
  font-weight: var(--font-weight-medium, 500);
  margin-bottom: var(--space-xs, 0.25rem);
}

.list-card__item-subtitle {
  font-size: var(--font-size-sm, 0.875rem);
  color: var(--text-secondary, #666);
  margin: 0;
}

.list-card__item-meta {
  margin-left: var(--space-lg, 1rem);
}

.list-card__item-status {
  display: inline-block;
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--font-size-sm, 0.875rem);
  font-weight: var(--font-weight-medium, 500);
  border-radius: var(--radius-sm, 4px);
}

.list-card__item-status--success {
  background: var(--success-bg);
  color: var(--success, #22c55e);
}

.list-card__item-status--warning {
  background: var(--warning-bg);
  color: var(--warning, #eab308);
}

.list-card__item-status--error {
  background: var(--error-bg);
  color: var(--error, #ef4444);
}


/* ========== COMPONENT: MENU ========== */
/*
 * Menu / Popover
 * A floating action menu anchored to a trigger — the "Do cue-sheet": tap a
 * launcher, a panel lifts over the surface with a header and a list of actions.
 *
 * It does not reinvent the list. A menu IS a floating list-card: it layers on
 * the .list-card vocabulary (list-card.css) and adds only what a popover needs
 * that a static list does not — the lift off the surface (shadow + radius),
 * a header row with a close affordance, and an item shaped for an icon + a
 * title/subtitle pair. Where list-card already says it, we reuse it; the app
 * writes .list-card.menu on the panel and .list-card__list / .list-card__item
 * inside, so migrating a bare list-card into a popover is a class add, not a
 * rewrite.
 *
 * Structure:
 *   .menu                         — block; the floating panel (compose w/ .list-card)
 *     .menu__header               — title row + close
 *       .menu__title              — the prompt ("What would you like to do?")
 *       .menu__close              — dismiss button (app wires the handler)
 *     .menu__list                 — scroll region (compose w/ .list-card__list)
 *       .menu__item               — one action row (compose w/ .list-card__item)
 *         .menu__icon             — leading glyph slot
 *         .menu__item-title       — primary label
 *         .menu__item-subtitle    — secondary line
 *
 * Behaviour (anchoring to a trigger, show/hide, spawning items, running the
 * action on click) belongs to the app. It positions the block, toggles
 * visibility, and fills the list. This sheet owns structure, presentation,
 * and the open/close motion vocabulary only.
 */

.menu {
  /* The lift: a bordered, rounded panel that floats clear of the surface.
     Position (fixed/absolute, anchor coords, z-index) is the app's job —
     a menu reads as a popover wherever it is placed. */
  display: flex;
  flex-direction: column;
  background: var(--surface, #f5f5f5);
  border: var(--border-width-sm, 1px) solid var(--border, #d4d4d4);
  border-radius: var(--radius-md, 8px);
  box-shadow: var(--shadow-lg, 0 8px 24px rgba(0, 0, 0, 0.4));
  overflow: hidden;
  min-width: var(--menu-min-width, 18rem);
  max-height: var(--menu-max-height, 24rem);
  transform-origin: top center;
  /* An explicit duration, not --transition-base: that token carries its own
     cubic-bezier, and two timing functions in one animation shorthand is
     invalid (the whole rule would drop). The transition-* tokens are for the
     transition property, where a trailing timing function is legal. */
  animation: menu-open 180ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---- Header: the prompt and the way out. ---- */
.menu__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md, 1rem);
  padding: var(--space-lg, 1rem);
  border-bottom: var(--border-width-sm, 1px) solid var(--border-light, #e5e5e5);
}

.menu__title {
  font-size: var(--font-size-lg, 1.125rem);
  font-weight: var(--font-weight-bold, 700);
  margin: 0;
}

.menu__close {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: var(--space-xl, 2rem);
  height: var(--space-xl, 2rem);
  padding: 0;
  background: none;
  border: none;
  border-radius: var(--radius-sm, 4px);
  color: var(--text-secondary, #666);
  font-size: var(--font-size-xl, 1.25rem);
  line-height: 1;
  cursor: pointer;
  transition: background-color var(--transition-fast, 150ms),
              color var(--transition-fast, 150ms);
}

.menu__close:hover {
  background: var(--border-light, #e5e5e5);
  color: var(--text, #111);
}

/* ---- List: the scroll region. The header stays put while actions scroll. ---- */
.menu__list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
}

/* ---- Item: one action. A row with a leading icon slot and a label stack. ---- */
.menu__item {
  display: flex;
  align-items: center;
  /* Reset: .list-card__item sets justify-content: space-between, which would
     push the icon and the label stack to opposite edges. A menu row is a
     gap-joined icon + label, left-aligned. */
  justify-content: flex-start;
  gap: var(--space-md, 1rem);
  padding: var(--space-md, 1rem) var(--space-lg, 1rem);
  border-bottom: var(--border-width-sm, 1px) solid var(--border-light, #e5e5e5);
  cursor: pointer;
  transition: background-color var(--transition-fast, 150ms);
}

.menu__item:last-child {
  border-bottom: none;
}

/* The hover wash — reads as "this row is live", themed off the surface. */
.menu__item:hover {
  background: var(--border-light, #e5e5e5);
}

.menu__item:focus-visible {
  outline: var(--border-width-md, 2px) solid var(--primary, #3b82f6);
  outline-offset: calc(-1 * var(--border-width-md, 2px));
}

/* Icon slot — a fixed-width leading column so titles align regardless of glyph. */
.menu__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: var(--space-lg, 1.5rem);
  font-size: var(--font-size-lg, 1.125rem);
  line-height: 1;
}

/* The label stack takes the remaining width and clips long lines. */
.menu__item-title {
  display: block;
  font-weight: var(--font-weight-medium, 500);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu__item-subtitle {
  display: block;
  margin: 0;
  font-size: var(--font-size-sm, 0.875rem);
  color: var(--text-secondary, #666);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Open motion: the panel lifts and fades in from its anchor. ---- */
@keyframes menu-open {
  from { opacity: 0; transform: translateY(calc(-1 * var(--space-xs, 0.5rem))) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---- Accessibility: no entrance animation. ---- */
@media (prefers-reduced-motion: reduce) {
  .menu { animation: none; }
}


/* ========== COMPONENT: PILL-TOGGLE ========== */
/*
 * Pill Toggle
 * A badge-shaped on/off toggle for modes — Expressive, Live, and friends.
 * Distinct from the base toggle (a switch): this is a *labelled pill* that
 * reads as a mode badge. Off is a quiet outline; on is a filled accent with a
 * soft glow. It is a real <button> carrying aria-pressed, so it is
 * keyboard-operable and announces its state for free.
 *
 * Colour is driven by the semantic palette. The default on-state rides the
 * accent role (--primary); the --live modifier rides --success. Re-theming is
 * free — nothing hardcodes a mode colour.
 *
 * Structure:
 *   .pill-toggle[data-on]          — block; a <button aria-pressed>. The app
 *                                    flips data-on (and aria-pressed) on click.
 *     .pill-toggle__dot            — optional leading status dot (fills when on)
 *     .pill-toggle__label          — the mode name (uppercased, tracked)
 *
 * Modifiers:
 *   .pill-toggle--live             — success-tinted "live" variant
 *
 * Behaviour (click handling, flipping data-on / aria-pressed, which modes are
 * mutually exclusive) belongs to the app. This sheet owns structure,
 * presentation, and the motion vocabulary only.
 */

.pill-toggle {
  /* On-colour resolution. The accent role is the default; --live re-points it.
     Everything downstream reads this one variable. */
  --pill-toggle-color: var(--primary, #c9a0d0);

  display: inline-flex;
  align-items: center;
  gap: var(--space-xs, 0.5rem);
  padding: var(--pill-toggle-pad-y, var(--space-xs, 0.35rem))
           var(--pill-toggle-pad-x, var(--space-md, 0.9rem));
  font-family: inherit;
  font-size: var(--font-size-sm, 0.8125rem);
  font-weight: var(--font-weight-medium, 500);
  line-height: 1;
  letter-spacing: var(--pill-toggle-tracking, 0.06em);
  text-transform: uppercase;

  color: var(--text-secondary, #888);
  background: transparent;
  border: var(--border-width-sm, 1px) solid var(--border, #343434);
  border-radius: var(--radius-full, 9999px);
  cursor: pointer;
  user-select: none;

  transition: color var(--transition-fast, 150ms),
              background-color var(--transition-fast, 150ms),
              border-color var(--transition-fast, 150ms),
              box-shadow var(--transition-fast, 150ms);
}

/* Hover (off): the border warms toward the mode's colour — a preview of on. */
.pill-toggle:hover {
  border-color: var(--pill-toggle-color);
}

/* Keyboard focus: a visible ring, never removed. */
.pill-toggle:focus-visible {
  outline: var(--border-width-md, 2px) solid var(--pill-toggle-color);
  outline-offset: var(--border-width-md, 2px);
}

/* ---- On-state. The app sets data-on="true" (and aria-pressed="true"). ----
   Filled accent + on-token text + a soft glow. The glow is the "lit" cue. */
.pill-toggle[data-on="true"] {
  color: var(--background, #161616);
  background: var(--pill-toggle-color);
  border-color: var(--pill-toggle-color);
  box-shadow: 0 0 var(--pill-toggle-glow, 8px)
              color-mix(in srgb, var(--pill-toggle-color) 50%, transparent);
  animation: pill-toggle-light var(--transition-base, 300ms) ease-out;
}

/* ---- Leading status dot (optional). Dim when off, lit + haloed when on. ---- */
.pill-toggle__dot {
  width: var(--pill-toggle-dot-size, 8px);
  height: var(--pill-toggle-dot-size, 8px);
  flex: none;
  border-radius: var(--radius-full, 9999px);
  background: color-mix(in srgb, var(--pill-toggle-color) 45%, transparent);
  transition: background-color var(--transition-fast, 150ms),
              box-shadow var(--transition-fast, 150ms);
}
.pill-toggle[data-on="true"] .pill-toggle__dot {
  background: var(--background, #161616);
  box-shadow: 0 0 var(--pill-toggle-glow, 8px)
              color-mix(in srgb, var(--background, #161616) 50%, transparent);
}

/* ---- Label ---- */
.pill-toggle__label {
  display: inline-block;
}

/* ---- Live variant — re-points the one colour variable to --success. ---- */
.pill-toggle--live {
  --pill-toggle-color: var(--success, #8fb98f);
}

/* ---- Motion vocabulary. A brief flare on turning on; nothing else. ---- */
@keyframes pill-toggle-light {
  0%   { box-shadow: 0 0 0 color-mix(in srgb, var(--pill-toggle-color) 50%, transparent); }
  60%  { box-shadow: 0 0 calc(var(--pill-toggle-glow, 8px) * 1.6)
                     color-mix(in srgb, var(--pill-toggle-color) 65%, transparent); }
  100% { box-shadow: 0 0 var(--pill-toggle-glow, 8px)
                     color-mix(in srgb, var(--pill-toggle-color) 50%, transparent); }
}

/* ---- Accessibility: no flare on state change. ---- */
@media (prefers-reduced-motion: reduce) {
  .pill-toggle { animation: none !important; }
}


/* ========== COMPONENT: PRESENCE-DOT ========== */
/*
 * Presence Dot
 * One indicator for *who is here*, not where a process is. A small dot
 * reports presence — active (here now), away (stepped off), idle (quiet) —
 * and gently breathes while active so "here" reads as alive, not just lit.
 *
 * NOT state-dot. The distinction is deliberate:
 *   .state-dot  answers "where is the running process?" — a pipeline phase
 *               (recording / thinking / speaking) on one agent.
 *   .presence-dot answers "who is on this surface?" — a participant's
 *               availability (active / away / idle), many at once.
 * They share a visual family (a glowing disc) but never the same class, the
 * same data-attr, or the same keyframes. A status bar may carry both.
 *
 * Colour is driven by the semantic palette: active → --success (present),
 * away → --warning (stepped away), idle → --state-idle (quiet). For a
 * multi-source surface — several participants, each their own hue — the app
 * sets --presence-dot-color per dot and the state colours step aside.
 *
 * Structure:
 *   .presence-dot[data-presence]   — block; data-presence picks the colour
 *     .presence-dot__inner         — the visible disc (fill + glow + motion)
 *     .presence-dot__label         — optional inline label ("Nick · here")
 *
 * Behaviour (flipping data-presence, spawning dots per participant, setting
 * --presence-dot-color) belongs to the app. This sheet owns structure,
 * colour, and the motion vocabulary only.
 */

.presence-dot {
  /* Default + colour resolution. data-presence sets --presence-dot-color;
     everything downstream reads the one variable. A multi-source app can
     also set --presence-dot-color inline to override per participant. */
  --presence-dot-color: var(--state-idle, #6b7280);

  display: inline-flex;
  align-items: center;
  gap: var(--space-xs, 0.5rem);
  vertical-align: middle;
}

.presence-dot__inner {
  width: var(--presence-dot-size, 8px);
  height: var(--presence-dot-size, 8px);
  flex-shrink: 0;
  border-radius: var(--radius-full, 9999px);
  background: var(--presence-dot-color);
  /* A soft halo keyed to the dot's own size — a hint at this scale, never a flare. */
  box-shadow: 0 0 calc(var(--presence-dot-size, 8px) * 0.75)
              color-mix(in srgb, var(--presence-dot-color) 50%, transparent);
  transition: background-color var(--transition-base, 300ms),
              box-shadow var(--transition-base, 300ms);
}

/* Size modifiers — a larger step for a prominent "you are here" marker. */
.presence-dot--md .presence-dot__inner { --presence-dot-size: 12px; }
.presence-dot--lg .presence-dot__inner { --presence-dot-size: 16px; }

.presence-dot__label {
  font-size: var(--font-size-base, 1rem);
  color: var(--text-secondary, #888);
  line-height: 1;
}

/* ---- Presence → colour. data-presence on the block sets one variable. ---- */
.presence-dot[data-presence="active"] { --presence-dot-color: var(--success, #10b981); }
.presence-dot[data-presence="away"]   { --presence-dot-color: var(--warning, #f59e0b); }
.presence-dot[data-presence="idle"]   { --presence-dot-color: var(--state-idle, #6b7280); }

/* ---- Motion vocabulary ----
   Active is the only state that moves: a gentle presence-pulse, slow enough
   to read as breathing. Away and idle hold steady — presence is settled, not
   demanding attention. */
.presence-dot[data-presence="active"] .presence-dot__inner {
  animation: presence-dot-pulse 2s ease-in-out infinite;
}
.presence-dot[data-presence="away"] .presence-dot__inner,
.presence-dot[data-presence="idle"] .presence-dot__inner {
  animation: none;
}

/* Idle reads as present-but-dim — a touch of transparency, no glow pull. */
.presence-dot[data-presence="idle"] .presence-dot__inner {
  box-shadow: none;
  opacity: var(--presence-dot-idle-opacity, 0.55);
}

@keyframes presence-dot-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.4; }
}

/* ---- Accessibility: hold the pulse; presence still reads by colour. ---- */
@media (prefers-reduced-motion: reduce) {
  .presence-dot__inner { animation: none !important; }
}


/* ========== COMPONENT: PROGRESS ========== */
/*
 * Progress & Loading Component
 * Progress bars and loading spinners
 */

.spinner {
  border: var(--border-width-lg) solid var(--border-light, #e5e5e5);
  border-top-color: var(--primary, #3b82f6);
  border-radius: var(--radius-full, 9999px);
  width: var(--spinner-size);
  height: var(--spinner-size);
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner--sm {
  width: var(--spinner-size-sm);
  height: var(--spinner-size-sm);
  border-width: var(--border-width-md);
}

.spinner--lg {
  width: var(--spinner-size-lg);
  height: var(--spinner-size-lg);
  border-width: var(--border-width-xl);
}

.progress {
  width: 100%;
  height: var(--progress-height);
  background: var(--surface, #f5f5f5);
  border-radius: var(--radius-full, 9999px);
  overflow: hidden;
}

.progress__bar {
  height: 100%;
  background: var(--primary, #3b82f6);
  border-radius: var(--radius-full, 9999px);
  transition: width var(--transition-slow, 300ms);
}

.progress--success .progress__bar {
  background: var(--success, #22c55e);
}

.progress--warning .progress__bar {
  background: var(--warning, #eab308);
}

/* Example width classes for demonstration */
.progress__bar--45 {
  width: 45%;
}

.progress__bar--75 {
  width: 75%;
}


/* ========== COMPONENT: RESULT-CARD ========== */
/*
 * Result Card Component
 * Display metrics and analysis results
 */

.result-card {
  background: var(--surface, #f5f5f5);
  border: var(--border-width-sm) solid var(--border, #d4d4d4);
  border-radius: var(--radius-md, 8px);
  overflow: hidden;
}

.result-card__header {
  padding: var(--space-lg, 1rem);
  border-bottom: var(--border-width-sm) solid var(--border-light, #e5e5e5);
}

.result-card__title {
  font-size: var(--font-size-xl, 1.25rem);
  font-weight: var(--font-weight-bold, 700);
  margin-bottom: var(--space-xs, 0.25rem);
}

.result-card__subtitle {
  font-size: var(--font-size-sm, 0.875rem);
  color: var(--text-secondary, #666);
  margin: 0;
}

.result-card__metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(var(--metric-min-width), 1fr));
  gap: var(--space-lg, 1rem);
  padding: var(--space-lg, 1rem);
}

.result-card__metric {
  text-align: center;
}

.result-card__metric-label {
  display: block;
  font-size: var(--font-size-sm, 0.875rem);
  color: var(--text-secondary, #666);
  margin-bottom: var(--space-xs, 0.25rem);
}

.result-card__metric-value {
  display: block;
  font-size: var(--font-size-2xl, 1.5rem);
  font-weight: var(--font-weight-bold, 700);
  color: var(--text-heading, #000);
}

.result-card__footer {
  padding: var(--space-lg, 1rem);
  border-top: var(--border-width-sm) solid var(--border-light, #e5e5e5);
  display: flex;
  gap: var(--space-sm, 0.5rem);
}


/* ========== COMPONENT: SLIDER ========== */
/*
 * Slider
 * A range input and everything that frames it — a heading row, end labels,
 * and a live value badge. One component covers the three shapes maestro grew
 * organically: the plain labelled slider, the corner "comfort" slider, and
 * the vertical "aperture" dial. They differ only by modifier, never by block.
 *
 * The thumb takes its colour from --slider-thumb-color so an app driving a
 * VRGB hue ramp can tint it per value (e.g. cold → warm as the value climbs)
 * without touching this sheet. Default resolves to --primary, so re-theming
 * is free and the hook is purely opt-in.
 *
 * Structure:
 *   .slider                         — block; margin + layout owner
 *     .slider__label                — heading row (title left, value right)
 *       .slider__value              — the live number badge (tabular-nums)
 *     .slider__track                — positioning context for the input
 *     .slider__input[type=range]    — the native control (thumb reads the hue)
 *     .slider__labels               — low/high end-label row
 *       .slider__end--low           — left/bottom end caption
 *       .slider__end--high          — right/top end caption
 *
 * Modifiers:
 *   .slider--vertical               — writing-mode vertical; low value at bottom
 *   .slider--inline                 — label + input + value on one flex row
 *
 * Hooks the app drives:
 *   --slider-thumb-color            — set per value for a VRGB hue ramp
 *   data-scale="log|linear"         — declares the value scale for the app;
 *                                     CSS cannot compute the mapping, so this
 *                                     is a structural marker only, never styling
 *
 * Behaviour (reading the value, moving the thumb, recolouring per tick, mapping
 * a log vs linear scale) is the app's job. This sheet owns structure,
 * presentation, and a small motion vocabulary only.
 */

.slider {
  /* One variable feeds every thumb below; data has no reason to know the
     vendor-prefix zoo. App overrides it per value for the VRGB ramp. */
  --slider-thumb-color: var(--slider-thumb-color-base, var(--primary, #3b82f6));

  margin-bottom: var(--space-lg, 1rem);
}

/* Heading row — title on the left, value badge on the right. */
.slider__label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: var(--font-weight-medium, 500);
  margin-bottom: var(--space-sm, 0.5rem);
  color: var(--text-heading, #000);
}

/* Positioning context — lets the app overlay a fill or tick marks later. */
.slider__track {
  position: relative;
}

.slider__input {
  width: 100%;
  height: var(--slider-track-height, 6px);
  border-radius: var(--radius-sm, 4px);
  background: var(--border, #e0e0e0);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  transition: opacity var(--transition-fast, 150ms ease);
}

/* ---- Thumb. Both engines read the one --slider-thumb-color variable. ---- */
.slider__input::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: var(--slider-thumb-size, 18px);
  height: var(--slider-thumb-size, 18px);
  border-radius: var(--radius-full, 9999px);
  background: var(--slider-thumb-color, var(--primary, #3b82f6));
  cursor: pointer;
  box-shadow: var(--shadow-sm, 0 1px 2px rgba(0,0,0,0.05));
  transition: transform var(--transition-fast, 150ms ease),
              background-color var(--transition-fast, 150ms ease),
              box-shadow var(--transition-fast, 150ms ease);
}

.slider__input::-webkit-slider-thumb:hover {
  transform: scale(1.1);
  box-shadow: var(--shadow-md, 0 4px 6px rgba(0,0,0,0.1));
}

.slider__input::-moz-range-thumb {
  width: var(--slider-thumb-size, 18px);
  height: var(--slider-thumb-size, 18px);
  border-radius: var(--radius-full, 9999px);
  background: var(--slider-thumb-color, var(--primary, #3b82f6));
  cursor: pointer;
  border: none;
  box-shadow: var(--shadow-sm, 0 1px 2px rgba(0,0,0,0.05));
  transition: transform var(--transition-fast, 150ms ease),
              background-color var(--transition-fast, 150ms ease),
              box-shadow var(--transition-fast, 150ms ease);
}

.slider__input::-moz-range-thumb:hover {
  transform: scale(1.1);
  box-shadow: var(--shadow-md, 0 4px 6px rgba(0,0,0,0.1));
}

/* Disabled — dim and inert, via class (app-toggled) or the native attribute. */
.slider__input:disabled,
.slider__input--disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* ---- End labels. Low sits left/bottom, high sits right/top. ---- */
.slider__labels {
  display: flex;
  justify-content: space-between;
  margin-top: var(--space-xs, 0.25rem);
  font-size: var(--font-size-sm, 0.875rem);
  color: var(--text-secondary, #666);
}

.slider__end--low  { text-align: left; }
.slider__end--high { text-align: right; }

/* ---- Value badge. Tabular figures keep the number from reflowing as it
       counts — the width is reserved for the widest digit. ---- */
.slider__value {
  min-width: var(--slider-value-width, 3rem);
  text-align: center;
  font-weight: var(--font-weight-bold, 700);
  font-variant-numeric: tabular-nums;
  color: var(--text-heading, #000);
  padding: var(--space-2xs, 0.25rem) var(--space-xs, 0.5rem);
  background: var(--surface-secondary, color-mix(in srgb, var(--border, #e0e0e0) 40%, transparent));
  border-radius: var(--radius-sm, 4px);
}

/* The legacy block-level output — kept so existing markup never breaks. */
.slider__output {
  display: block;
  margin-top: var(--space-sm, 0.5rem);
  font-weight: var(--font-weight-medium, 500);
  color: var(--text-heading, #000);
}

/* ---- Inline shape (the "comfort" slider): one flex row, no heading. ---- */
.slider--inline {
  display: flex;
  align-items: center;
  gap: var(--space-sm, 0.5rem);
  margin-bottom: 0;
}
.slider--inline .slider__input { flex: 1; }
.slider--inline .slider__labels { margin-top: 0; }

/* ---- Vertical shape (the "aperture" dial) ----
   writing-mode stands the range up; the rtl flow puts the low value at the
   BOTTOM, the high value at the top — the intuitive reading for a dial. */
.slider--vertical {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  height: var(--slider-vertical-height, 240px);
  margin-bottom: 0;
}
.slider--vertical .slider__input {
  writing-mode: vertical-lr;
  direction: rtl;
  width: var(--slider-track-height, 6px);
  height: 100%;
  flex: 1;
}
/* Stack the end labels and give the whole column the quiet caption colour. */
.slider--vertical .slider__labels {
  flex-direction: column-reverse;
  align-items: center;
  margin-top: 0;
}

/* ---- Accessibility: the hover scale is non-essential flourish. ---- */
@media (prefers-reduced-motion: reduce) {
  .slider__input { transition: none !important; }
  .slider__input::-webkit-slider-thumb { transition: none !important; }
  .slider__input::-moz-range-thumb { transition: none !important; }
  .slider__input::-webkit-slider-thumb:hover { transform: none !important; }
  .slider__input::-moz-range-thumb:hover { transform: none !important; }
}


/* ========== COMPONENT: STATE-DOT ========== */
/*
 * State Dot
 * One status indicator for a live process. A single dot reports where a
 * running agent is — idle, recording, transcribing, thinking, speaking,
 * synthing, holding — plus generic loading / ready / error.
 *
 * It is the whole family: the hero dot at the centre of a canvas and the
 * 12px dot inline in a status bar are the same component at two sizes.
 * Colour is driven entirely by the --state-* token palette (tokens.css §8b),
 * so it re-themes with Spectra and never hardcodes a pipeline colour.
 *
 * Structure:
 *   .state-dot[data-state]        — block; data-state picks the colour
 *     .state-dot__inner           — the visible disc (fill + glow + motion)
 *     .state-dot__particles       — optional emitter; JS spawns .p while audio sounds
 *
 * Behaviour (recording toggle, particle spawning, live breathing) belongs to
 * the app: it sets data-state and adds .state-dot--breathe / .p nodes. This
 * sheet owns structure, colour, and the motion vocabulary only.
 */

.state-dot {
  /* Default state + colour resolution. data-state overrides --state-dot-color;
     everything downstream reads the one variable. */
  --state-dot-color: var(--state-idle, #6b7280);

  position: relative;
  width: var(--state-dot-size, 100px);
  height: var(--state-dot-size, 100px);
  flex-shrink: 0;
  border-radius: var(--radius-full, 9999px);
}

/* Size modifiers — the inline status role and a medium step. */
.state-dot--sm { width: var(--state-dot-size-sm, 12px); height: var(--state-dot-size-sm, 12px); }
.state-dot--md { width: var(--state-dot-size-md, 44px); height: var(--state-dot-size-md, 44px); }

.state-dot__inner {
  width: 100%;
  height: 100%;
  border-radius: var(--radius-full, 9999px);
  background: var(--state-dot-color);
  /* Glow scales with the dot: a hairline at --sm, a halo at the hero size. */
  box-shadow: 0 0 calc(var(--state-dot-size, 100px) * 0.12)
              color-mix(in srgb, var(--state-dot-color) 55%, transparent);
  transition: background-color var(--transition-base, 300ms),
              box-shadow var(--transition-base, 300ms),
              transform var(--transition-base, 300ms);
  cursor: pointer;
  user-select: none;
}

/* Idle reads as present-but-quiet: a soft ring, no glow. */
.state-dot[data-state="idle"] .state-dot__inner {
  box-shadow: inset 0 0 0 var(--border-width-md, 2px)
              color-mix(in srgb, var(--state-dot-color) 55%, white);
}

/* ---- State → colour. data-state on the block sets one variable. ---- */
.state-dot[data-state="idle"]         { --state-dot-color: var(--state-idle, #6b7280); }
.state-dot[data-state="recording"]    { --state-dot-color: var(--state-recording, #ef4444); }
.state-dot[data-state="transcribing"] { --state-dot-color: var(--state-transcribing, #f59e0b); }
.state-dot[data-state="thinking"]     { --state-dot-color: var(--state-thinking, #3b82f6); }
.state-dot[data-state="speaking"]     { --state-dot-color: var(--state-speaking, #10b981); }
.state-dot[data-state="synthing"]     { --state-dot-color: var(--state-synthing, #17c3c3); }
.state-dot[data-state="holding"]      { --state-dot-color: var(--state-holding, #d0a85a); }
.state-dot[data-state="loading"]      { --state-dot-color: var(--state-loading, #f59e0b); }
.state-dot[data-state="ready"]        { --state-dot-color: var(--state-ready, #10b981); }
.state-dot[data-state="error"]        { --state-dot-color: var(--state-error, #ef4444); }

/* ---- Motion vocabulary. Phases that are "working" pulse; loading too. ---- */
.state-dot[data-state="synthing"] .state-dot__inner { animation: state-dot-pulse 1s ease-in-out infinite; }
.state-dot[data-state="holding"]  .state-dot__inner { animation: state-dot-pulse 0.7s ease-in-out infinite; }
.state-dot[data-state="loading"]  .state-dot__inner { animation: state-dot-pulse 1.2s ease-in-out infinite; }

/* Breathing — opt-in (e.g. a hands-free "live" session). App toggles the class. */
.state-dot--breathe .state-dot__inner {
  animation: state-dot-breathe 3.2s ease-in-out infinite;
}

@keyframes state-dot-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.45; }
}
@keyframes state-dot-breathe {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.06); }
}

/* ---- Particle emitter ----
   An emitter tied to the audio, not a spinner: while a clip sounds, the app
   appends .p nodes. Each animates ONCE and removes itself, so silence just
   stops spawning new ones — the dots in flight never freeze. The app
   randomizes each dot's angle (--a), reach (--reach), size (--sz),
   duration (--dur) and peak opacity (--op). */
.state-dot__particles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}
.state-dot__particles .p {
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--sz, 5px);
  height: var(--sz, 5px);
  margin: calc(var(--sz, 5px) / -2) 0 0 calc(var(--sz, 5px) / -2);
  border-radius: var(--radius-full, 9999px);
  background: var(--state-dot-color);
  filter: blur(0.6px);
  opacity: 0;
  will-change: transform, opacity;
  animation: state-dot-particle var(--dur, 1.4s) ease-out forwards;
}
@keyframes state-dot-particle {
  0%   { opacity: 0; transform: rotate(var(--a, 0deg)) translateX(38px) scale(0.3); }
  18%  { opacity: var(--op, 0.7); }
  100% { opacity: 0; transform: rotate(var(--a, 0deg)) translateX(var(--reach, 78px)) scale(1); }
}

/* ---- Accessibility: no pulsing, breathing, or particles. ---- */
@media (prefers-reduced-motion: reduce) {
  .state-dot__inner { animation: none !important; }
  .state-dot__particles { display: none; }
}


/* ========== COMPONENT: STRUCTURED-QUESTION ========== */
/*
 * Structured Question
 * The frame around a bounded ask: an agent poses one question with a fixed set
 * of answers and waits. It is the shell, not the controls — the controls are
 * borrowed. A yes/no question composes .btn in the choices row; a scalar one
 * drops a .slider inside; a free-text one drops a .form__textarea. This sheet
 * owns only what those pieces cannot: the wrapper's spacing, the large-target
 * choices row, the chosen-indicator that replaces the controls once answered,
 * and the approval gate — a weightier variant for "may I do this?".
 *
 * The four input primitives (yes/no, scalar→slider, text, doc→approval) all
 * live under one block so an app can swap between them by swapping a child,
 * never a wrapper.
 *
 * Structure:
 *   .structured-question                   — block; width + top spacing
 *     .structured-question__choices        — the answer row (button-group)
 *     .structured-question__indicator      — the chosen answer, shown after
 *       .structured-question__indicator--text — left-aligned, for a text reply
 *         .structured-question__submitted  — the echoed reply, clamped to 2 lines
 *   .structured-question.approval-gate     — the approval variant (see below)
 *
 * Approval gate (the "may I run this?" variant):
 *   .approval-gate                         — left-accent + tinted panel
 *     .approval-gate__title                — the proposed action
 *     .approval-gate__target               — what it acts on (path, name)
 *     .approval-gate__preview              — the diff/body, fade-masked if long
 *       .approval-gate__preview-text       — monospace payload
 *
 * Hooks the app drives: toggling .structured-question__indicator in once an
 * answer lands; disabling controls via :disabled or --disabled; mapping intent
 * ("yes" = primary, "reject" = error) to .btn modifiers in its own markup.
 * Behaviour (spawning the node, reading the answer, confirming) is the app's
 * job. This sheet owns structure, presentation, and the reveal motion only.
 */

.structured-question {
  width: 100%;
  margin-top: var(--space-md, 0.75rem);
}

/* First question in a card body needs no top gap — the body already pads. */
.card__body > .structured-question:first-child {
  margin-top: 0;
}

/* ---- Choices row ----
   The answer buttons. Large targets, generous gap — this is a decision point,
   not a toolbar. .btn (+ its own modifiers) supplies the button surface; this
   row only lays them out. flex-wrap keeps three-plus options honest on narrow
   widths instead of overflowing. */
.structured-question__choices {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm, 0.5rem);
  margin-top: var(--space-md, 0.75rem);
}

/* Each choice earns a comfortable minimum so yes/no reads as a pair of
   deliberate targets, not two cramped links. */
.structured-question__choices .btn {
  flex: 1 1 auto;
  min-width: var(--structured-question-choice-min, 7rem);
}

/* Spent controls dim and go inert once the question is answered. Works via the
   native attribute or the app-toggled class, like the other form primitives. */
.structured-question :disabled,
.structured-question .btn--disabled,
.structured-question__choices .btn.disabled {
  opacity: var(--opacity-disabled, 0.4);
  cursor: not-allowed;
  pointer-events: none;
}

/* ---- Chosen indicator ----
   After an answer lands the app reveals this in place of the live controls:
   a quiet, right-aligned echo of what was chosen. */
.structured-question__indicator {
  margin-top: var(--space-sm, 0.5rem);
  font-size: var(--font-size-sm, 0.875rem);
  color: var(--text-secondary, #888);
  text-align: right;
  animation: structured-question-reveal var(--transition-base, 300ms) ease;
}

/* A text reply reads left-to-right as prose, not as a right-aligned tag. */
.structured-question__indicator--text {
  display: block;
  text-align: left;
  line-height: var(--line-height-tight, 1.4);
}

/* Clamp a long submitted answer to two lines — the indicator is an echo, not
   the record. The full text lives wherever the app persisted it. */
.structured-question__indicator--text .structured-question__submitted {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  word-wrap: break-word;
}

/* ============================================================
   APPROVAL GATE — the heaviest variant.
   "May I do this?" carries more consequence than "yes or no?", so it gets a
   visible frame: a left accent bar and a tinted panel that lift it out of the
   conversation. The accent colour is the semantic primary by default; an app
   can re-point it to --warning for a destructive gate without touching markup.
   ============================================================ */
.approval-gate {
  --approval-gate-accent: var(--primary, #3b82f6);

  padding: var(--space-md, 0.75rem);
  background: var(--surface-secondary,
              color-mix(in srgb, var(--approval-gate-accent) 6%, transparent));
  border-left: var(--border-width-lg, 3px) solid var(--approval-gate-accent);
  border-radius: var(--radius-sm, 4px);
}

/* A destructive action (delete, overwrite, force-push) earns the warning hue —
   same frame, different weight. */
.approval-gate--danger {
  --approval-gate-accent: var(--warning, #f59e0b);
}

.approval-gate__title {
  margin: 0;
  font-size: var(--font-size-md, 1rem);
  font-weight: var(--font-weight-medium, 500);
  color: var(--text-heading, #000);
}

/* What the action acts on — a path, a name, a count. Quiet, under the title. */
.approval-gate__target {
  margin: var(--space-2xs, 0.25rem) 0 0 0;
  font-size: var(--font-size-sm, 0.875rem);
  color: var(--text-secondary, #888);
}

/* ---- Preview ----
   The payload the agent wants to commit: a diff, a file body, a command.
   Capped in height; a long payload fades out at the bottom rather than hard-
   cropping, so the reader knows there is more below the fold. */
.approval-gate__preview {
  position: relative;
  margin-top: var(--space-md, 0.75rem);
  padding: var(--space-md, 0.75rem);
  max-height: var(--approval-gate-preview-max, 7.5rem);
  overflow: hidden;
  background: var(--surface-secondary,
              color-mix(in srgb, var(--approval-gate-accent) 6%, transparent));
  border-radius: var(--radius-sm, 4px);
  font-size: var(--font-size-sm, 0.875rem);
}

/* The fade-mask. Pinned to the bottom edge, it dissolves the last lines into
   the panel colour — the "there is more" signal. Non-interactive. */
.approval-gate__preview::after {
  content: '';
  position: absolute;
  inset: auto 0 0 0;
  height: var(--space-xl, 2rem);
  pointer-events: none;
  background: linear-gradient(to bottom, transparent,
              var(--surface-secondary,
              color-mix(in srgb, var(--approval-gate-accent) 6%, transparent)));
}

.approval-gate__preview-text {
  margin: 0;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: var(--font-size-sm, 0.875rem);
  line-height: var(--line-height-tight, 1.4);
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* ---- Reveal keyframe ---- */
@keyframes structured-question-reveal {
  from { opacity: 0; transform: translateY(var(--space-2xs, 0.25rem)); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---- Accessibility: the reveal is non-essential flourish. ---- */
@media (prefers-reduced-motion: reduce) {
  .structured-question__indicator { animation: none; }
}


/* ========== COMPONENT: TOAST ========== */
/*
 * Toast Component
 * Temporary notification messages
 */

.toast-container {
  position: fixed;
  top: var(--space-lg, 1rem);
  right: var(--space-lg, 1rem);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm, 0.5rem);
  max-width: var(--toast-max-width);
}

.toast {
  display: flex;
  align-items: start;
  gap: var(--space-sm, 0.5rem);
  padding: var(--space-lg, 1rem);
  background: var(--color-white);
  border-radius: var(--radius-md, 8px);
  box-shadow: var(--shadow-lg, 0 10px 15px rgba(0,0,0,0.15));
  border-left: var(--border-width-xl) solid;
  animation: slideIn var(--transition-base) ease;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.toast__icon {
  font-size: var(--font-size-xl, 1.25rem);
  flex-shrink: 0;
}

.toast__content {
  flex: 1;
}

.toast__title {
  font-weight: var(--font-weight-bold, 700);
  margin-bottom: var(--space-xs, 0.25rem);
}

.toast__message {
  font-size: var(--font-size-sm, 0.875rem);
  color: var(--text-secondary, #666);
  margin: 0;
}

.toast__close {
  background: none;
  border: none;
  font-size: var(--icon-size-md);
  line-height: 1;
  cursor: pointer;
  color: var(--text-secondary, #666);
  padding: 0;
  width: var(--icon-size-md);
  height: var(--icon-size-md);
}

.toast--success { border-color: var(--success, #22c55e); }
.toast--warning { border-color: var(--warning, #eab308); }
.toast--error { border-color: var(--error, #ef4444); }
.toast--info { border-color: var(--info, #3b82f6); }


/* ========== COMPONENT: TOGGLE ========== */
/*
 * Toggle Switch Component
 * On/off switch control
 */

.toggle {
  display: flex;
  align-items: center;
  gap: var(--space-sm, 0.5rem);
  cursor: pointer;
}

.toggle__input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle__track {
  position: relative;
  width: var(--toggle-width);
  height: var(--toggle-height);
  background: var(--border, #d4d4d4);
  border-radius: var(--radius-full, 9999px);
  transition: background var(--transition-fast, 150ms);
}

.toggle__input:checked + .toggle__track {
  background: var(--primary, #3b82f6);
}

.toggle__thumb {
  position: absolute;
  top: var(--toggle-thumb-offset);
  left: var(--toggle-thumb-offset);
  width: var(--toggle-thumb-size);
  height: var(--toggle-thumb-size);
  background: var(--color-white);
  border-radius: var(--radius-full, 9999px);
  transition: transform var(--transition-fast, 150ms);
  box-shadow: var(--shadow-sm, 0 1px 2px rgba(0,0,0,0.05));
}

.toggle__input:checked + .toggle__track .toggle__thumb {
  transform: translateX(calc(var(--toggle-width) - var(--toggle-thumb-size) - var(--toggle-thumb-offset) * 2));
}

.toggle__label {
  font-weight: var(--font-weight-medium, 500);
  color: var(--text, #1a1a1a);
}


/* ========== COMPONENT: TOKEN-CHIP ========== */
/*
 * Token Chip
 * A pinned-token thumbnail card. One chip shows a single thermal token the
 * user has pinned to the edge of the screen — its type (a coloured dot), a
 * label, the current value, and a live decay countdown. It is the glance
 * surface for "what's still warm."
 *
 * Colour is driven entirely by one variable, --token-chip-color, which the
 * block's data-type resolves from the state / semantic palette (tokens.css
 * §8b / §8). Re-theming is free: Spectra re-points --state-* / --success /
 * --info and the whole stack of chips follows.
 *
 * Structure:
 *   .token-chip[data-type]          — block; data-type picks the dot colour
 *     .token-chip__dot              — the type-coloured status dot
 *     .token-chip__info             — the clipping column (label/value/ttl)
 *       .token-chip__label          — bold title, ellipsis overflow
 *       .token-chip__value          — current value, ellipsis overflow
 *       .token-chip__ttl            — decay countdown (click target: renew)
 *     .token-chip__view             — optional "view" action (gallery etc.)
 *
 * data-type accepts both the short enum (yes_no, scalar, text, approval,
 * dispatch, gallery, receipt) and the legacy long form the app emits
 * (yes_no_response, scalar_param, …) so migration is a class swap.
 *
 * Behaviour (spawning chips, ticking the countdown, renew-on-click, toggling
 * the view button) belongs to the app. This sheet owns structure, colour,
 * and the entrance/lift motion only.
 */

.token-chip {
  /* Default + colour resolution. data-type overrides this one variable;
     every coloured part downstream reads it. */
  --token-chip-color: var(--state-idle, #6b7280);

  display: flex;
  align-items: center;
  gap: var(--space-sm, 0.5rem);
  width: var(--token-chip-width, 180px);
  padding: var(--space-sm, 0.5rem) var(--space-md, 0.75rem);

  background: var(--surface, rgba(26, 26, 26, 0.92));
  /* Frosted backdrop so chips float over content without hiding it. */
  backdrop-filter: blur(var(--token-chip-blur, 16px));
  -webkit-backdrop-filter: blur(var(--token-chip-blur, 16px));
  border: var(--border-width-sm, 1px) solid var(--border, rgba(255, 255, 255, 0.12));
  border-radius: var(--radius-sm, 4px);
  box-shadow: var(--shadow-md, 0 4px 16px rgba(0, 0, 0, 0.4));

  opacity: 0.95;
  cursor: pointer;
  transition: opacity var(--transition-fast, 160ms),
              border-color var(--transition-fast, 160ms),
              box-shadow var(--transition-base, 300ms),
              transform var(--transition-base, 300ms);
  animation: token-chip-in var(--transition-base, 300ms) ease-out;
}

/* Hover lift: fully opaque, brighter edge, raised a hair. */
.token-chip:hover {
  opacity: 1;
  border-color: var(--border-light, rgba(255, 255, 255, 0.2));
  box-shadow: var(--shadow-lg, 0 6px 20px rgba(0, 0, 0, 0.5));
  transform: translateY(calc(var(--space-2xs, 0.125rem) * -0.5));
}

/* ---- The type dot. One variable, set by data-type below. ---- */
.token-chip__dot {
  width: var(--token-chip-dot-size, 8px);
  height: var(--token-chip-dot-size, 8px);
  flex-shrink: 0;
  border-radius: var(--radius-full, 9999px);
  background: var(--token-chip-color);
  box-shadow: 0 0 calc(var(--token-chip-dot-size, 8px) * 0.6)
              color-mix(in srgb, var(--token-chip-color) 55%, transparent);
}

/* ---- Type → colour. data-type on the block sets one variable. ----
   Short enum and legacy long form resolve to the same palette slot. */
.token-chip[data-type="yes_no"],
.token-chip[data-type="yes_no_response"]   { --token-chip-color: var(--state-speaking, #10b981); }

.token-chip[data-type="scalar"],
.token-chip[data-type="scalar_param"]      { --token-chip-color: var(--state-transcribing, #f59e0b); }

.token-chip[data-type="text"],
.token-chip[data-type="text_input"]        { --token-chip-color: var(--state-thinking, #3b82f6); }

.token-chip[data-type="approval"],
.token-chip[data-type="approval_response"] { --token-chip-color: var(--state-recording, #ef4444); }

.token-chip[data-type="dispatch"],
.token-chip[data-type="cue_dispatch"]      { --token-chip-color: var(--info, #38bdf8); }

/* Gallery has no dedicated state slot; it borrows --primary so it still
   re-themes with Spectra (the palette has no violet to point at). */
.token-chip[data-type="gallery"]           { --token-chip-color: var(--primary, #a855f7); }

.token-chip[data-type="receipt"],
.token-chip[data-type="cuesheet_receipt"]  { --token-chip-color: var(--success, #10b981); }

/* ---- The clipping column. Everything inside truncates, never wraps. ---- */
.token-chip__info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.token-chip__label {
  margin: 0;
  font-size: var(--font-size-sm, 0.875rem);
  font-weight: var(--font-weight-bold, 700);
  color: var(--text, #fff);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.token-chip__value {
  margin: 0;
  font-size: var(--font-size-xs, 0.75rem);
  color: var(--text-secondary, #888);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* The decay readout. Its own click target (the app renews the token). */
.token-chip__ttl {
  margin: var(--space-2xs, 0.125rem) 0 0 0;
  font-size: var(--font-size-xs, 0.75rem);
  color: var(--text-secondary, #888);
  opacity: 0.7;
  cursor: pointer;
  transition: opacity var(--transition-fast, 160ms),
              color var(--transition-fast, 160ms);
}

.token-chip__ttl:hover {
  opacity: 1;
  color: var(--text, #fff);
}

/* Optional action (e.g. gallery "view in chat"). Tinted to the type colour,
   so it carries the same semantic as the dot. App toggles [hidden]. */
.token-chip__view {
  margin: var(--space-2xs, 0.125rem) 0 0 0;
  padding: var(--space-2xs, 0.125rem) var(--space-xs, 0.25rem);
  font-size: var(--font-size-xs, 0.75rem);
  line-height: 1;
  color: var(--token-chip-color);
  background: none;
  border: var(--border-width-sm, 1px) solid
           color-mix(in srgb, var(--token-chip-color) 30%, transparent);
  border-radius: var(--radius-sm, 4px);
  cursor: pointer;
  transition: background var(--transition-fast, 160ms),
              color var(--transition-fast, 160ms);
}

.token-chip__view:hover {
  background: color-mix(in srgb, var(--token-chip-color) 15%, transparent);
  color: color-mix(in srgb, var(--token-chip-color) 70%, white);
}

/* ---- Entrance: a chip slides up into the pinned column on spawn. ---- */
@keyframes token-chip-in {
  from { opacity: 0; transform: translateY(var(--space-sm, 0.5rem)); }
  to   { opacity: 0.95; transform: translateY(0); }
}

/* ---- Accessibility: no entrance slide, no lift. ---- */
@media (prefers-reduced-motion: reduce) {
  .token-chip { animation: none; }
  .token-chip:hover { transform: none; }
}


/* ========== COMPONENT: TYPOGRAPHY ========== */
/*
 * Typography Component
 * Heading and text styles
 */

h1, h2, h3, h4, h5, h6 {
  color: var(--text-heading, #000);
  font-weight: var(--font-weight-bold, 700);
  line-height: var(--line-height-tight, 1.25);
  margin-bottom: var(--space-md, 0.75rem);
}

h1 { font-size: var(--font-size-3xl, 1.875rem); }
h2 { font-size: var(--font-size-2xl, 1.5rem); }
h3 { font-size: var(--font-size-xl, 1.25rem); }
h4 { font-size: var(--font-size-lg, 1.125rem); }
h5 { font-size: var(--font-size-base, 1rem); }
h6 { font-size: var(--font-size-sm, 0.875rem); }

p {
  margin-bottom: var(--space-lg, 1rem);
  line-height: var(--line-height-normal, 1.5);
}

.text--gradient {
  background: linear-gradient(135deg, var(--primary, #3b82f6), var(--secondary, #8b5cf6));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}


/* ========== COMPONENT: UPLOAD ========== */
/*
 * File Upload Component
 * Drag and drop file upload area
 */

.upload {
  border: var(--border-width-md) dashed var(--border, #d4d4d4);
  border-radius: var(--radius-md, 8px);
  padding: var(--space-2xl, 2rem);
  text-align: center;
  transition: all var(--transition-base, 200ms);
}

.upload--dragover {
  border-color: var(--primary, #3b82f6);
  background: var(--primary-light, #dbeafe);
}

.upload__input {
  display: none;
}

.upload__label {
  display: block;
  cursor: pointer;
}

.upload__icon {
  font-size: var(--icon-size-3xl);
  display: block;
  margin-bottom: var(--space-sm, 0.5rem);
}

.upload__text {
  display: block;
  font-weight: var(--font-weight-medium, 500);
  margin-bottom: var(--space-xs, 0.25rem);
}

.upload__hint {
  display: block;
  font-size: var(--font-size-sm, 0.875rem);
  color: var(--text-secondary, #666);
  margin-bottom: var(--space-lg, 1rem);
}

.upload__button {
  pointer-events: none;
}

.upload__file-list {
  margin-top: var(--space-lg, 1rem);
}

.upload__file {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm, 0.5rem);
  background: var(--surface, #f5f5f5);
  border-radius: var(--radius-sm, 4px);
  margin-bottom: var(--space-sm, 0.5rem);
}

.upload__file-name {
  font-weight: var(--font-weight-medium, 500);
}

.upload__file-size {
  font-size: var(--font-size-sm, 0.875rem);
  color: var(--text-secondary, #666);
}

.upload__file-remove {
  background: none;
  border: none;
  font-size: var(--icon-size-md);
  line-height: 1;
  cursor: pointer;
  color: var(--error, #ef4444);
  padding: 0;
  width: var(--icon-size-md);
  height: var(--icon-size-md);
}

