/* ============================================================
   AaliaTalk — design tokens & full app stylesheet
   See DESIGN.md for the thesis: color belongs to the orb, the
   rest of the canvas stays monochrome. Tokens below map AaliaTalk's
   real charte graphique (blue/cyan) onto that system, in both a
   light and a dark variant (auto via prefers-color-scheme).
   ============================================================ */

/* ---------- Reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
img { max-width: 100%; display: block; }
button, input, textarea, select { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; touch-action: manipulation; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
ul { margin: 0; padding: 0; list-style: none; }
svg { display: block; }

/* First paint is frozen: no transitions/animations until main.js strips this
   class after the first rAF. */
body.booting, body.booting * {
  transition: none !important;
  animation: none !important;
}

/* ---------- Root tokens ---------- */
:root {
  /* Neutrals — light (AaliaTalk charte, light mode) */
  --bg: #F3F9FC;
  --bg-elev: #FFFFFF;
  --bg-elev-2: #EEF5F9;
  --border: #DEE7EF;
  --border-soft: #E9F0F5;
  --border-strong: rgba(100, 116, 139, .35);
  --text: #0B1220;
  --text-dim: #3A4756;
  --text-faint: #64748B;
  --link: #1E5976;

  /* Brand hues — theme-invariant, from AaliaTalk's charte graphique */
  --brand-blue: #3399CC;
  --brand-blue-dark: #297AA3;
  --brand-blue-dark-ultra: #1E5976;
  --brand-blue-navy: #002D57;
  --brand-green: #19DDD5;
  --brand-green-logo: #33CCCC;
  --brand-green-dark: #1F7A7A;
  --brand-gradient: linear-gradient(135deg, #3399CC, #33CCCC);

  /* Orb state -> glow. Built from the brand blue/cyan family; red is kept only
     for error, a deliberate non-brand accessibility exception (see DESIGN.md). */
  --glow-idle: var(--brand-blue);
  --glow-connecting: var(--brand-blue-dark);
  --glow-queued: var(--brand-blue-dark-ultra);
  --glow-your-turn: var(--brand-green);
  --glow-listening: var(--brand-green);
  --glow-user-speaking: var(--brand-green-logo);
  --glow-processing: #33B2CC;
  --glow-ai-speaking: var(--brand-blue);
  --glow-error: #E5484D;

  /* Role echoes — word-sized transcript accents, mirror the orb states they
     represent. Never used as fills, only as small text/icon color. */
  --voice-user: var(--glow-listening);
  --voice-assistant: var(--glow-ai-speaking);
  --voice-tool: var(--glow-processing);

  /* Radii */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --radius-full: 999px;

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(2, 6, 23, .06);
  --shadow-md: 0 8px 28px rgba(2, 6, 23, .10);

  /* Type — single face per AaliaTalk's charte ("Police unique dans toute l'app") */
  --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #081821;
    --bg-elev: #0E232D;
    --bg-elev-2: #0A1B23;
    --border: #1C3944;
    --border-soft: #16303A;
    --border-strong: rgba(234, 246, 250, .22);
    --text: #EAF6FA;
    --text-dim: #B9CEDA;
    --text-faint: #7FA0B0;
    --link: #6FC6E8;

    --shadow-sm: 0 2px 10px rgba(0, 0, 0, .45);
    --shadow-md: 0 10px 34px rgba(0, 0, 0, .55);
  }
}

/* ---------- Layout shell ---------- */
.shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 20px;
  position: relative;
  z-index: 50;
}

/* Kept in the DOM only because main.js unconditionally wires a click listener
   to it (see index.html comment); the mobile sidebar it used to open is gone,
   so it must never render. [hidden] alone loses to .icon-btn's `display: flex`
   at equal specificity (author rule beats the UA stylesheet), hence this. */
#about-btn-m { display: none; }

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}
.brand:hover { text-decoration: none; }
.brand-mark { width: 28px; height: 28px; object-fit: contain; flex-shrink: 0; }
.brand-name { font-size: 16px; font-weight: 600; letter-spacing: -.01em; }
.brand-name em { font-style: normal; color: var(--brand-blue); }

.topbar-spacer { flex: 1; }

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: color .2s, border-color .2s, background .2s;
  flex-shrink: 0;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }
.icon-btn:focus-visible { outline: 2px solid var(--text-dim); outline-offset: 2px; }

.chat-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text);
  opacity: 0;
  transform: scale(.4);
  transition: opacity .2s, transform .2s;
}
.chat-badge.visible { opacity: 1; transform: scale(1); }

.account { display: flex; align-items: center; }

/* ---------- Stage ---------- */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 24px 20px 48px;
  text-align: center;
}

.stage-eyebrow {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--text-faint);
}

/* ---------- Orb ---------- */
.orb-wrap {
  position: relative;
  width: min(320px, 62vw);
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.circle {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, var(--brand-blue-navy), #01131f 72%);
  box-shadow:
    0 0 0 1px var(--border-strong),
    var(--shadow-md),
    0 0 60px 2px color-mix(in srgb, var(--glow) 40%, transparent);
  transition: box-shadow .4s ease;
  padding: 0;
}
.circle:focus-visible {
  outline: 2px solid var(--glow);
  outline-offset: 4px;
}
.circle:disabled { cursor: default; }

.circle-dial {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.dial-tick-ring {
  fill: none;
  stroke: rgba(255, 255, 255, .07);
  stroke-width: 1;
}
.dial-ring {
  fill: none;
  stroke: var(--glow);
  stroke-width: 1.5;
  stroke-dasharray: 6 10;
  opacity: 0;
  transform-origin: 100px 100px;
  transition: opacity .3s ease;
}
.circle.state-connecting .dial-ring,
.circle.state-queued .dial-ring,
.circle.state-processing .dial-ring {
  opacity: .8;
  animation: orb-dial-spin 3.2s linear infinite;
}
.dial-ring-2 { animation-direction: reverse; animation-duration: 4.4s; }
@keyframes orb-dial-spin {
  to { transform: rotate(360deg); }
}

.circle-pulse {
  position: absolute;
  inset: 6%;
  border-radius: 50%;
  border: 1px solid var(--glow);
  opacity: 0;
  transition: border-color .4s ease;
  animation: orb-breathe 2.4s ease-out infinite;
}
.circle-pulse.p2 { animation-delay: 1.2s; }
@keyframes orb-breathe {
  0% { transform: scale(.94); opacity: .5; }
  70% { opacity: 0; }
  100% { transform: scale(1.14); opacity: 0; }
}
/* Audio-reactive: the pulses stay subordinate to the live level meter, not
   just the timer, while a voice signal is present (listening/speaking). */
.circle.state-listening .circle-pulse,
.circle.state-user-speaking .circle-pulse,
.circle.state-ai-speaking .circle-pulse {
  transform: scale(calc(1 + (var(--bar0, 0) + var(--bar1, 0) + var(--bar2, 0) + var(--bar3, 0) + var(--bar4, 0)) * 0.03));
}
.circle.state-ai-speaking {
  box-shadow:
    0 0 0 1px var(--border-strong),
    var(--shadow-md),
    0 0 calc(60px + var(--ai-audio-level, 0) * 46px) 2px color-mix(in srgb, var(--glow) 55%, transparent);
}

/* One --glow per real app state (main.js STATE_CLASS, 9 values) */
.circle.state-idle          { --glow: var(--glow-idle); }
.circle.state-connecting    { --glow: var(--glow-connecting); }
.circle.state-queued        { --glow: var(--glow-queued); }
.circle.state-your-turn     { --glow: var(--glow-your-turn); }
.circle.state-listening     { --glow: var(--glow-listening); }
.circle.state-user-speaking { --glow: var(--glow-user-speaking); }
.circle.state-processing    { --glow: var(--glow-processing); }
.circle.state-ai-speaking   { --glow: var(--glow-ai-speaking); }
.circle.state-error         { --glow: var(--glow-error); }

.circle-core {
  position: absolute;
  inset: 19%;
  border-radius: 50%;
  display: grid;
}
.circle-core > * { grid-area: 1 / 1; }

/* The AaliaTalk mark: full presence at idle/your-turn (no icon competes there
   any more), dims to a watermark once a state icon takes over, per the "logo
   in the middle, orb in the middle" brief — always present, never competing. */
.orb-mark {
  width: 62%;
  height: 62%;
  object-fit: contain;
  margin: auto;
  opacity: .92;
  transition: opacity .35s ease;
  filter: drop-shadow(0 2px 10px rgba(0, 0, 0, .35));
}
.circle.state-connecting .orb-mark,
.circle.state-queued .orb-mark,
.circle.state-processing .orb-mark,
.circle.state-listening .orb-mark,
.circle.state-user-speaking .orb-mark,
.circle.state-ai-speaking .orb-mark,
.circle.state-error .orb-mark { opacity: .14; }

.circle-indicator {
  position: relative;
  width: 100%;
  height: 100%;
}
.ind {
  position: absolute;
  inset: 0;
  margin: auto;
  display: grid;
  place-items: center;
  opacity: 0;
  transform: scale(.8);
  transition: opacity .25s ease, transform .25s ease;
  color: var(--glow);
}
/* ind-error and ind-voice are <svg class="ind ind-*"> themselves, not a
   wrapper around one — size the element directly (inset+margin:auto above
   centers it). */
svg.ind { width: 48%; height: 48%; }

/* State -> icon mapping (design decision; see DESIGN.md). idle/your-turn show
   no indicator icon at all — just the (now larger) AaliaTalk mark. */
.circle.state-connecting .ind-spinner,
.circle.state-queued .ind-spinner { opacity: 1; transform: scale(1); }
.circle.state-processing .ind-thinking { opacity: 1; transform: scale(1); }
.circle.state-listening .ind-bars,
.circle.state-user-speaking .ind-bars { opacity: 1; transform: scale(1); }
.circle.state-ai-speaking .ind-voice { opacity: 1; transform: scale(1); }
.circle.state-error .ind-error { opacity: 1; transform: scale(1); }

.ind-spinner {
  width: 30%;
  height: 30%;
  border-radius: 50%;
  border: 2.5px solid color-mix(in srgb, var(--glow) 30%, transparent);
  border-top-color: var(--glow);
  animation: orb-spin .9s linear infinite;
}
@keyframes orb-spin { to { transform: rotate(360deg); } }

.ind-thinking { display: flex; justify-content: center; gap: 6px; }
.ind-thinking .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--glow);
  animation: orb-thinking-bounce 1.1s ease-in-out infinite;
}
.ind-thinking .dot:nth-child(2) { animation-delay: .15s; }
.ind-thinking .dot:nth-child(3) { animation-delay: .3s; }
@keyframes orb-thinking-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: .5; }
  40% { transform: translateY(-5px); opacity: 1; }
}

.ind-bars { display: flex; align-items: center; justify-content: center; gap: 4px; height: 34%; }
.ind-bars .bar {
  width: 4px;
  border-radius: 2px;
  background: var(--glow);
  height: 100%;
  transform-origin: center;
}
.ind-bars .bar:nth-child(1) { transform: scaleY(calc(.18 + var(--bar0, 0) * .82)); }
.ind-bars .bar:nth-child(2) { transform: scaleY(calc(.18 + var(--bar1, 0) * .82)); }
.ind-bars .bar:nth-child(3) { transform: scaleY(calc(.18 + var(--bar2, 0) * .82)); }
.ind-bars .bar:nth-child(4) { transform: scaleY(calc(.18 + var(--bar3, 0) * .82)); }
.ind-bars .bar:nth-child(5) { transform: scaleY(calc(.18 + var(--bar4, 0) * .82)); }

.ind-voice .wave { opacity: .5; animation: orb-wave-ripple 1.8s ease-in-out infinite; }
.ind-voice .wave-2 { animation-delay: .3s; }
@keyframes orb-wave-ripple {
  0%, 100% { opacity: .35; }
  50% { opacity: 1; }
}

/* ---------- Mic-gate arc (wraps #mic-btn, left of the orb) ---------- */
.mic-gate {
  position: absolute;
  left: -58px;
  top: 50%;
  width: 96px;
  height: 96px;
  transform: translateY(-50%) scale(.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
}
.orb-wrap.live .mic-gate { opacity: 1; pointer-events: auto; transform: translateY(-50%) scale(1); }

.mic-gate-arc { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.mga-track { stroke: var(--border-strong); stroke-width: 4; stroke-linecap: round; }
.mga-fill {
  stroke: var(--glow-listening);
  stroke-width: 4;
  stroke-linecap: round;
  transition: stroke .3s ease;
}
.mic-gate.gate-open .mga-fill { filter: drop-shadow(0 0 4px var(--glow-listening)); }
.mic-gate.gate-off .mga-fill,
.mic-gate.gate-off .mga-handle { opacity: .3; }
.mga-hit { stroke: transparent; stroke-width: 16; fill: none; pointer-events: stroke; cursor: pointer; }
.mga-handle {
  fill: var(--bg-elev);
  stroke: var(--glow-listening);
  stroke-width: 2;
  cursor: grab;
}

/* ---------- Side buttons (mic toggle, stop) ---------- */
.side-btn {
  position: absolute;
  top: 50%;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease, color .2s ease;
}
#mic-btn { position: absolute; inset: 0; margin: auto; transform: none; }
#stop-btn {
  right: -58px;
  transform: translateY(-50%) scale(.6);
}
.orb-wrap.live #stop-btn { opacity: 1; pointer-events: auto; transform: translateY(-50%) scale(1); }
.orb-wrap.live #mic-btn { opacity: 1; pointer-events: auto; }
#mic-btn svg, #stop-btn svg { width: 18px; height: 18px; }
#stop-btn:hover { color: var(--glow-error); border-color: var(--glow-error); }
#mic-btn:hover { color: var(--text); }

.mic-off { display: none; }
#mic-btn.muted .mic-on { display: none; }
#mic-btn.muted .mic-off { display: block; }
#mic-btn.muted { color: var(--glow-error); border-color: var(--glow-error); }

/* ---------- Captions & queue actions ---------- */
.circle-caption {
  margin: 0;
  min-height: 1.4em;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .01em;
  color: var(--text);
  transition: color .2s ease, opacity .2s ease;
}
.circle-caption.empty { opacity: 0; }
.circle-caption.muted { color: var(--text-faint); font-weight: 500; }
.circle-caption.error { color: var(--glow-error); }

.circle-subcaption {
  margin: -12px 0 0;
  font-size: 13px;
  color: var(--text-faint);
}

.queue-actions { display: flex; gap: 10px; }
.join-queue-btn,
.leave-queue-btn {
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text-dim);
  transition: background .2s, color .2s, border-color .2s;
}
.join-queue-btn {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}
.join-queue-btn:hover { opacity: .88; }
.leave-queue-btn:hover { color: var(--text); border-color: var(--border-strong); }

/* ---------- Ephemeral bubble stack ---------- */
.bubble-stack {
  position: fixed;
  /* Sits below the topbar's button row (68px tall) so it never overlaps the
     icon buttons, regardless of stacking order. */
  top: 80px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 340px;
  z-index: 40;
  pointer-events: none;
}
.bubble {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  box-shadow: var(--shadow-sm);
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity .3s ease, transform .3s ease;
  font-size: 13px;
  line-height: 1.45;
}
.bubble.in { opacity: 1; transform: translateY(0); }
.bubble.out { opacity: 0; transform: translateY(-6px); }
.bubble-role {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .09em;
  margin-bottom: 2px;
}
.bubble.user .bubble-role { color: var(--voice-user); }
.bubble.assistant .bubble-role { color: var(--voice-assistant); }
.bubble-body { color: var(--text); word-wrap: break-word; }
.bubble.tool {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--voice-tool);
  font-size: 12px;
  font-weight: 500;
}
.bubble-tool-icon { width: 16px; height: 16px; flex-shrink: 0; }

@media (max-width: 600px) {
  .bubble-stack { display: none; }
}

/* ---------- Camera preview ---------- */
.cam-pip {
  position: fixed;
  left: 20px;
  bottom: 20px;
  width: 160px;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  background: var(--bg-elev);
  opacity: 0;
  pointer-events: none;
  transform: scale(.92);
  transition: opacity .25s ease, transform .25s ease;
  z-index: 30;
}
.cam-pip.visible { opacity: 1; pointer-events: auto; transform: scale(1); }
.cam-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}
.cam-flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
}
.cam-flash.flash { animation: cam-flash-pop .35s ease-out; }
@keyframes cam-flash-pop {
  0% { opacity: .9; }
  100% { opacity: 0; }
}
.cam-label {
  position: absolute;
  bottom: 4px;
  left: 6px;
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .6);
}
@media (max-width: 600px) {
  .cam-pip { width: 108px; }
}

/* ============================================================
   CHAT PANEL
   ============================================================ */
.chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 420px;
  max-width: 90vw;
  height: 100vh;
  z-index: 1000;
  pointer-events: none;
  visibility: hidden;
  opacity: 0;
  transition: visibility 0.3s ease, opacity 0.3s ease;
}

.chat-panel.open {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}

.chat-panel-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.chat-panel-inner {
  position: absolute;
  top: 0;
  right: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-elev);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-panel.open .chat-panel-inner {
  transform: translateX(0);
}

.chat-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  flex-shrink: 0;
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-header-left svg { color: var(--text-faint); }

.chat-header-left h3 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  color: var(--text);
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Persistent history rows (.hist-msg / .hist-*) and ephemeral bubbles share
   the same shape (see ui/chat.js `_buildMessageEl`). */
.hist-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.5;
  animation: chatSlideIn 0.3s ease;
  word-wrap: break-word;
}

@keyframes chatSlideIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.hist-msg.user {
  align-self: flex-end;
  background: var(--bg-elev-2);
  color: var(--text);
  border-bottom-right-radius: 4px;
}

.hist-msg.assistant {
  align-self: flex-start;
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.hist-msg.tool {
  align-self: stretch;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
}

.hist-role {
  display: block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-faint);
  margin-bottom: 4px;
}
.hist-msg.user .hist-role { color: var(--voice-user); }
.hist-msg.assistant .hist-role { color: var(--voice-assistant); }
.hist-msg.tool .hist-role { color: var(--voice-tool); }

.hist-body { color: var(--text); }
.hist-body.partial { opacity: 0.6; }

.hist-msg.interrupted { opacity: 0.75; }
.hist-note {
  margin-top: 6px;
  font-size: 11px;
  font-style: italic;
  color: var(--text-faint);
}

/* Tool-call rows: collapsible input/output block */
.hist-tool-header {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 0;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
}
.hist-tool-icon { width: 15px; height: 15px; color: var(--voice-tool); flex-shrink: 0; }
.hist-tool-name { flex: 1; text-align: left; }
.hist-tool-chevron { width: 14px; height: 14px; color: var(--text-faint); transition: transform .2s ease; }
.hist-tool-header[aria-expanded="true"] .hist-tool-chevron { transform: rotate(180deg); }
.hist-tool-body {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  transition: grid-template-rows .25s ease, opacity .2s ease;
}
.hist-tool-body.open { grid-template-rows: 1fr; opacity: 1; margin-top: 8px; }
.hist-tool-body > * { overflow: hidden; }
.hist-tool-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin: 6px 0 2px;
}
.hist-tool-block {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--bg-elev-2);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text-dim);
}

.hist-image {
  max-width: 100%;
  border-radius: 8px;
  margin-top: 6px;
}

/* Empty state — two shapes exist: the static French placeholder baked into
   index.html, and the JS-generated .chat-empty-title/.chat-empty-hint markup
   (ui/chat.js EMPTY_STATE_HTML) used whenever the panel is programmatically
   cleared. Both share the outer .chat-empty container. */
.chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-faint);
  text-align: center;
  padding: 20px;
}
.chat-empty svg { color: var(--border-strong); margin-bottom: 12px; }
.chat-empty p,
.chat-empty-title {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-dim);
  margin: 0 0 4px 0;
}
.chat-empty span,
.chat-empty-hint {
  font-size: 13px;
  color: var(--text-faint);
}

.chat-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-count {
  font-size: 12px;
  color: var(--text-faint);
}

.chat-history::-webkit-scrollbar { width: 4px; }
.chat-history::-webkit-scrollbar-track { background: transparent; }
.chat-history::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

@media (max-width: 640px) {
  .chat-panel { width: 100vw; max-width: 100vw; }
  .chat-panel-inner { border-radius: 0; }
  .hist-msg { max-width: 92%; }
}

/* ============================================================
   MODALS (about / settings / tools / limit)
   ============================================================ */
dialog.modal {
  border: none;
  padding: 0;
  border-radius: var(--radius-md);
  background: var(--bg-elev);
  color: var(--text);
  box-shadow: var(--shadow-md);
  width: min(460px, calc(100vw - 32px));
  max-height: min(680px, calc(100vh - 48px));
}
dialog.modal::backdrop {
  background: rgba(2, 6, 23, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-content {
  display: flex;
  flex-direction: column;
  max-height: min(680px, calc(100vh - 48px));
  overflow-y: auto;
  padding: 0 24px 24px;
}

.modal-header {
  position: sticky;
  top: 0;
  background: var(--bg-elev);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0 16px;
  margin-bottom: 4px;
  z-index: 1;
}
.modal-header h2 { margin: 0; font-size: 17px; font-weight: 600; }

.modal-footer {
  padding: 16px 24px;
  display: flex;
  justify-content: flex-end;
}

/* Buttons */
.btn {
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  transition: background .2s, opacity .2s, border-color .2s;
}
.btn:hover { border-color: var(--border-strong); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}
.btn.primary:hover { opacity: .88; }
.btn.wide { width: 100%; text-align: center; }

/* Form fields */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; }
.field > span:first-child,
.field-head {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.field-value { font-weight: 500; color: var(--text-faint); font-size: 12px; }
.field small,
.field-row + small { font-size: 12px; color: var(--text-faint); line-height: 1.5; }
.field small code {
  font-family: ui-monospace, monospace;
  background: var(--bg-elev-2);
  padding: 1px 4px;
  border-radius: 4px;
}
.field-row { display: flex; gap: 12px; margin-bottom: 18px; }
.field-row .field { flex: 1; margin-bottom: 0; }

input[type="text"],
input[type="password"],
textarea,
select {
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13px;
  color: var(--text);
  width: 100%;
}
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--text-dim);
  outline-offset: 1px;
}
textarea { resize: vertical; font-family: var(--font-sans); }

#conn-hint.error { color: var(--glow-error); }

/* Noise-gate slider */
.gate-track { position: relative; height: 28px; display: flex; align-items: center; }
.gate-meter-fill {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  height: 4px;
  border-radius: 2px;
  background: var(--glow-listening);
  width: 0%;
  pointer-events: none;
}
#noise-gate {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  position: relative;
}
#noise-gate::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--bg-elev);
  border: 2px solid var(--brand-blue);
  cursor: pointer;
}
#noise-gate::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--bg-elev);
  border: 2px solid var(--brand-blue);
  cursor: pointer;
}
.gate-ends {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 4px;
}

/* Tools panel */
.tools-intro { font-size: 13px; color: var(--text-faint); margin: 0 0 16px; }
.tool-list { display: flex; flex-direction: column; }
.tool-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  transition: opacity .2s;
}
.tool-row.disabled { opacity: .45; pointer-events: none; }
.tool-row-sep { border-top: 1px solid var(--border); margin-top: 4px; }
.tool-info { display: flex; flex-direction: column; gap: 2px; }
.tool-name { font-size: 14px; font-weight: 600; }
.tool-desc { font-size: 12px; color: var(--text-faint); }
.tool-hint { display: block; font-size: 12px; color: var(--text-faint); margin-top: 4px; }
.tools-key { margin-top: 4px; }

.switch { position: relative; width: 40px; height: 24px; flex-shrink: 0; cursor: pointer; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch-track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: var(--radius-full);
  transition: background .2s;
}
.switch-track::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--bg-elev);
  box-shadow: var(--shadow-sm);
  transition: transform .2s ease;
}
.switch input:checked + .switch-track { background: var(--brand-blue); }
.switch input:checked + .switch-track::before { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--text-dim); outline-offset: 2px; }

/* About modal */
.about-logo { width: 200px; margin: 0 auto 18px; }
.about-intro p { font-size: 14px; line-height: 1.6; color: var(--text-dim); margin: 0 0 10px; }
.about-repo {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--link);
}
.about-repo .ext { width: 14px; height: 14px; }

.about-langs { margin: 18px 0; }
.about-langs-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-faint);
  margin-bottom: 8px;
}
.lang-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.lang-tags li {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: var(--radius-full);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.about-pipeline { margin-top: 18px; }
.pipeline-title { font-size: 13px; font-weight: 600; margin: 0 0 10px; }
.pipeline {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-left: 2px solid var(--border);
  padding-left: 14px;
}
.pipe-endpoint {
  font-size: 13px;
  font-weight: 600;
  color: var(--brand-blue);
}
.pipe-stage { display: flex; flex-direction: column; gap: 1px; }
.pipe-tag {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text);
}
.pipe-job { font-size: 12px; color: var(--text-faint); }

.about-credit {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-faint);
}
.ident-row { display: flex; gap: 6px; }
.ident-label { color: var(--text-faint); }
.about-credit a { color: var(--link); font-weight: 600; }

/* Limit modal */
.limit-card { align-items: center; text-align: center; padding-top: 8px; }
.limit-close { position: absolute; top: 16px; right: 16px; }
.limit-badge {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--bg-elev-2);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 12px auto 16px;
}
.limit-logo { width: 40px; height: 40px; }
.limit-title { font-size: 18px; font-weight: 600; margin: 0 0 8px; }
.limit-msg { font-size: 14px; color: var(--text-dim); margin: 0 0 18px; }
.limit-cta { margin-bottom: 10px; }
.limit-note { font-size: 12px; color: var(--text-faint); margin: 0; }

/* ---------- Responsive floor ---------- */
@media (max-width: 600px) {
  .topbar { padding: 12px 14px; }
  .brand-name { font-size: 14px; }
  .stage { gap: 16px; padding: 16px 16px 32px; }
  .orb-wrap { width: min(260px, 66vw); }
  .mic-gate { left: -50px; width: 80px; height: 80px; }
  #stop-btn { right: -50px; }
}

/* ---------- Focus & motion ---------- */
:focus-visible { outline: 2px solid var(--text-dim); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  .circle-pulse,
  .dial-ring,
  .ind-voice .wave,
  .ind-thinking .dot,
  .ind-spinner,
  .hist-msg {
    animation: none !important;
  }
  /* The live audio-reactive bar/pulse scaling stays: it's the signature
     real-time feature, not decorative motion (see DESIGN.md). */
}
