/* ===================================================================
 * Beyond Brain — native web app styles
 * Modern dark theme with subtle gradient/glow accents.
 * ================================================================= */

:root {
  --bg: #0b0d12;
  --bg-elev: #11141b;
  --bg-elev-2: #161a23;
  --line: #232838;
  --text: #e7eaf1;
  --text-dim: #9aa3b2;
  --text-faint: #6b7280;
  --accent: #7aa2ff;
  --accent-2: #a78bfa;
  --accent-glow: rgba(122, 162, 255, 0.35);
  --user-bubble: linear-gradient(135deg, #2a3656 0%, #2a3a5f 100%);
  --assistant-bubble: #161a23;
  --danger: #ef4444;
  --success: #10b981;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-md: 0 6px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 18px 60px rgba(0, 0, 0, 0.55);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  position: relative;
}

/* ----- Topbar ------------------------------------------------------ */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
  background: rgba(11, 13, 18, 0.7);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}
.brand-mark {
  font-size: 26px;
  filter: drop-shadow(0 0 12px var(--accent-glow));
}
.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}
.brand-text strong {
  font-size: 15px;
  letter-spacing: 0.2px;
}
.brand-sub {
  font-size: 11px;
  color: var(--text-dim);
}

.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.pill {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text-dim);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.15s ease;
}
.pill:hover {
  color: var(--text);
  border-color: #2f364a;
}
.pill-active {
  background: linear-gradient(
    135deg,
    rgba(122, 162, 255, 0.15) 0%,
    rgba(167, 139, 250, 0.15) 100%
  );
  border-color: rgba(122, 162, 255, 0.4);
  color: var(--text);
}
.pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
}
.pill.muted .dot {
  background: var(--text-faint);
  box-shadow: none;
}

/* ----- Chat area --------------------------------------------------- */

.chat-area {
  flex: 1 1 auto;
  overflow-y: auto;
  scroll-behavior: smooth;
  padding: 24px 22px 8px;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 24px;
}

.empty-state {
  text-align: center;
  padding: 70px 16px 40px;
  position: relative;
}
.empty-state h1 {
  font-size: 28px;
  margin: 0 0 8px;
  background: linear-gradient(135deg, #fff 30%, #9aa3b2 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.empty-state p {
  color: var(--text-dim);
  margin: 0 auto 26px;
  max-width: 460px;
}
.empty-glow {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(
    circle at 50% 0%,
    var(--accent-glow) 0%,
    transparent 55%
  );
  opacity: 0.3;
}
.suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}
.suggestion {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s ease;
}
.suggestion:hover {
  border-color: var(--accent);
  background: var(--bg-elev-2);
  transform: translateY(-1px);
}

/* ----- Bubbles ----------------------------------------------------- */

.msg {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  animation: fadeIn 0.25s ease both;
}
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.msg.user {
  justify-content: flex-end;
}

.bubble {
  max-width: 78%;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 14.5px;
  word-wrap: break-word;
  white-space: pre-wrap;
  line-height: 1.55;
  box-shadow: var(--shadow-md);
  position: relative;
}
.msg.user .bubble {
  background: var(--user-bubble);
  border: 1px solid rgba(122, 162, 255, 0.25);
  border-bottom-right-radius: 6px;
}
.msg.assistant .bubble {
  background: var(--assistant-bubble);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}

/* ----- User-recording playback bubble (legacy minimalist row) ------ */
.bubble .audio-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
}
.bubble .audio-row.standalone,
.bubble.audio-only-bubble .audio-row,
.bubble.user-audio-bubble .audio-row {
  margin-top: 0;
}
.bubble.audio-only-bubble {
  padding: 8px;
}
.bubble.user-audio-bubble {
  padding: 8px;
  min-width: 220px;
}
.bubble.user-audio-bubble .audio-row {
  background: rgba(0, 0, 0, 0.18);
  border-color: rgba(122, 162, 255, 0.25);
}
.bubble .audio-row .play-btn {
  appearance: none;
  border: none;
  background: var(--accent);
  color: #0b0d12;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.15s ease;
  flex-shrink: 0;
}
.bubble .audio-row .play-btn:hover {
  box-shadow: 0 0 14px var(--accent-glow);
  transform: scale(1.05);
}
.bubble .audio-row .play-btn.playing {
  background: var(--accent-2);
}
.bubble .audio-row .play-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.bubble .audio-row .meter {
  flex: 1;
  height: 4px;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}
.bubble .audio-row .meter .meter-fill {
  position: absolute;
  inset: 0 100% 0 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: right 0.15s linear;
}
.bubble .audio-row .audio-status {
  font-size: 11.5px;
  color: var(--text-dim);
  flex-shrink: 0;
  min-width: 60px;
  text-align: right;
}

/* ----- TTS audio player (assistant bubbles) ----------------------- */

.bubble .tts-player {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  user-select: none;
}
.bubble .tts-player.standalone,
.bubble.audio-only-bubble .tts-player {
  margin-top: 0;
}

/* Buttons */
.bubble .tts-player .tp-btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease,
    border-color 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
}
.bubble .tts-player .tp-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.06);
}
.bubble .tts-player .tp-btn:active:not(:disabled) {
  transform: scale(0.95);
}
.bubble .tts-player .tp-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.bubble .tts-player .tp-play {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #0b0d12;
  border-color: transparent;
}
.bubble .tts-player .tp-play:hover:not(:disabled) {
  background: var(--accent);
  box-shadow: 0 0 14px var(--accent-glow);
}
.bubble .tts-player .tp-play.playing {
  background: var(--accent-2);
}

.bubble .tts-player .tp-stop {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border-color: var(--line);
  color: var(--text-dim);
}
.bubble .tts-player .tp-stop:hover:not(:disabled) {
  color: #ff8c42;
  border-color: rgba(255, 140, 66, 0.6);
  background: rgba(255, 140, 66, 0.08);
}

.bubble .tts-player .tp-replay {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border-color: var(--line);
  color: var(--text-dim);
}
.bubble .tts-player .tp-replay:hover:not(:disabled) {
  color: var(--accent);
  border-color: rgba(122, 162, 255, 0.5);
  background: rgba(122, 162, 255, 0.08);
}

/* Time labels */
.bubble .tts-player .tp-time {
  font-variant-numeric: tabular-nums;
  font-size: 11.5px;
  color: var(--text-dim);
  flex-shrink: 0;
  min-width: 30px;
  text-align: center;
}
.bubble .tts-player .tp-time-tot {
  text-align: right;
}

/* Track / progress bar */
.bubble .tts-player .tp-track {
  flex: 1;
  position: relative;
  height: 6px;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 999px;
  cursor: pointer;
  overflow: visible;
}
.bubble .tts-player .tp-track-fill {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.1s linear;
  pointer-events: none;
}
.bubble .tts-player .tp-track-handle {
  position: absolute;
  top: 50%;
  left: 0%;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--bg-elev), 0 0 8px var(--accent-glow);
  transform: translate(-50%, -50%);
  transition: left 0.1s linear, opacity 0.15s ease;
  pointer-events: none;
  opacity: 0;
}
.bubble .tts-player:hover .tp-track-handle,
.bubble .tts-player:not(.streaming) .tp-track-handle {
  opacity: 1;
}

/* Streaming state — track shimmer instead of a static fill background */
.bubble .tts-player.streaming .tp-track-fill {
  background: linear-gradient(
    90deg,
    var(--accent) 0%,
    var(--accent-2) 50%,
    var(--accent) 100%
  );
  background-size: 200% 100%;
  animation: streamingShine 1.6s linear infinite;
}
@keyframes streamingShine {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Loading state — empty track with subtle pulse, all controls dim */
.bubble .tts-player.loading .tp-track {
  position: relative;
}
.bubble .tts-player.loading .tp-track::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.08) 50%,
    transparent 100%
  );
  background-size: 200% 100%;
  animation: streamingShine 1.4s linear infinite;
}

/* Stopped state — slightly desaturated palette */
.bubble .tts-player.stopped .tp-track-fill {
  background: rgba(255, 255, 255, 0.25);
  animation: none;
}

/* Failed state — red accent on the track */
.bubble .tts-player.failed .tp-track-fill {
  background: linear-gradient(90deg, #ff5f6d, #ff8c42) !important;
  width: 100% !important;
  animation: none !important;
}
.bubble .tts-player.failed .tp-time-tot::before {
  content: "tts failed";
  color: #ff8c42;
}
.bubble .tts-player.failed .tp-time-tot {
  color: transparent;
}

.bubble.streaming-text::after {
  content: "▍";
  display: inline-block;
  animation: blink 1s steps(2) infinite;
  margin-left: 2px;
  color: var(--text-dim);
}
@keyframes blink {
  0%, 50% { opacity: 1; }
  50.01%, 100% { opacity: 0; }
}

.thinking {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  color: var(--text-dim);
  font-size: 13px;
}
.thinking span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: bounce 1.2s ease-in-out infinite both;
}
.thinking span:nth-child(2) { animation-delay: 0.15s; }
.thinking span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ----- Generating orb (playful "I'm thinking" indicator) ----------- */
/*
 * Used while we wait for the first LLM token / first TTS PCM chunk.
 * In audio-only mode this is the ONLY visual feedback the user gets,
 * so it has to feel alive: a glowing core, an emoji that morphs through
 * themed glyphs, four rainbow particles orbiting around it, and a
 * cycling shimmer-text strip with a curated list of playful phrases.
 */
.generating-orb {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 2px 2px;
  /* The bubble is white-space: pre-wrap; force a clean line for the orb. */
  width: 100%;
  min-height: 38px;
}
.generating-orb.orb-dismissing {
  opacity: 0;
  transform: translateY(-3px) scale(0.96);
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.generating-orb .orb-stage {
  position: relative;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

.generating-orb .orb-core {
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 30% 28%, rgba(255, 255, 255, 0.55), transparent 55%),
    linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  box-shadow:
    0 0 18px var(--accent-glow),
    inset 0 -3px 8px rgba(0, 0, 0, 0.25),
    inset 0 2px 4px rgba(255, 255, 255, 0.35);
  animation: orb-breathe 2.2s ease-in-out infinite;
}
@keyframes orb-breathe {
  0%, 100% {
    transform: scale(1);
    box-shadow:
      0 0 14px var(--accent-glow),
      inset 0 -3px 8px rgba(0, 0, 0, 0.25),
      inset 0 2px 4px rgba(255, 255, 255, 0.35);
  }
  50% {
    transform: scale(1.07);
    box-shadow:
      0 0 26px var(--accent-glow),
      inset 0 -3px 8px rgba(0, 0, 0, 0.25),
      inset 0 2px 4px rgba(255, 255, 255, 0.35);
  }
}

.generating-orb .orb-emoji {
  font-size: 16px;
  line-height: 1;
  filter: drop-shadow(0 0 3px rgba(255, 255, 255, 0.45));
  animation: orb-wiggle 2.6s ease-in-out infinite;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.generating-orb .orb-emoji.swapping {
  opacity: 0;
  transform: scale(0.6) rotate(-30deg);
}
@keyframes orb-wiggle {
  0%, 100% { transform: rotate(-6deg); }
  50%      { transform: rotate(8deg) translateY(-1px); }
}

/* Four-particle constellation orbiting the core. */
.generating-orb .orb-particles {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.generating-orb .orb-particles span {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 5px;
  height: 5px;
  margin: -2.5px 0 0 -2.5px;
  border-radius: 50%;
  animation: orb-orbit 2.6s linear infinite;
  opacity: 0.9;
}
.generating-orb .orb-particles span:nth-child(1) {
  background: #7aa2ff;
  box-shadow: 0 0 8px rgba(122, 162, 255, 0.85);
  animation-delay: 0s;
}
.generating-orb .orb-particles span:nth-child(2) {
  background: #a78bfa;
  box-shadow: 0 0 8px rgba(167, 139, 250, 0.85);
  animation-delay: -0.65s;
}
.generating-orb .orb-particles span:nth-child(3) {
  background: #ff8c42;
  box-shadow: 0 0 8px rgba(255, 140, 66, 0.85);
  animation-delay: -1.3s;
}
.generating-orb .orb-particles span:nth-child(4) {
  background: #10b981;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.85);
  animation-delay: -1.95s;
}
@keyframes orb-orbit {
  0%   { transform: rotate(0deg)   translateX(22px) rotate(0deg);   opacity: 0.95; }
  50%  { opacity: 0.35; }
  100% { transform: rotate(360deg) translateX(22px) rotate(-360deg); opacity: 0.95; }
}

/* Rotating phrase strip with a moving sheen. */
.generating-orb .orb-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  flex: 1;
}
.generating-orb .orb-status-text {
  display: inline-block;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: linear-gradient(
    90deg,
    var(--text-dim) 0%,
    var(--text) 25%,
    var(--accent) 50%,
    var(--accent-2) 75%,
    var(--text-dim) 100%
  );
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: orb-shine 3s linear infinite;
  transition: opacity 0.18s ease, transform 0.18s ease;
  transform-origin: left center;
}
.generating-orb .orb-status-text.swapping {
  opacity: 0;
  transform: translateY(4px);
}
.generating-orb .orb-status-dots {
  display: inline-flex;
  gap: 2px;
}
.generating-orb .orb-status-dots span {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.5;
  animation: orb-dot 1.2s ease-in-out infinite;
}
.generating-orb .orb-status-dots span:nth-child(2) { animation-delay: 0.15s; }
.generating-orb .orb-status-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes orb-dot {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40%           { opacity: 1;    transform: translateY(-2px); }
}
@keyframes orb-shine {
  0%   { background-position: 220% 0; }
  100% { background-position: -120% 0; }
}

/* Audio-only bubble: the orb sits inside the player frame so the bubble
 * stays compact and obviously "in progress". */
.bubble.audio-only-bubble .generating-orb {
  padding: 6px 4px 8px;
  margin-bottom: 4px;
  border-bottom: 1px dashed var(--line);
}

/* Respect users who don't want motion. */
@media (prefers-reduced-motion: reduce) {
  .generating-orb .orb-core,
  .generating-orb .orb-emoji,
  .generating-orb .orb-particles span,
  .generating-orb .orb-status-text,
  .generating-orb .orb-status-dots span {
    animation-duration: 4s;
  }
}

/* ----- Composer ---------------------------------------------------- */

.composer {
  border-top: 1px solid var(--line);
  background: rgba(11, 13, 18, 0.85);
  backdrop-filter: blur(12px);
  padding: 14px 18px 18px;
  position: sticky;
  bottom: 0;
}
.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 6px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.composer-row:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.input {
  flex: 1;
  appearance: none;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  resize: none;
  padding: 10px 8px;
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.5;
  max-height: 180px;
  overflow-y: auto;
}
.input::placeholder {
  color: var(--text-faint);
}

.send-btn,
.mic-btn {
  appearance: none;
  border: none;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, color 0.15s ease;
}
.send-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0b0d12;
}
.send-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 18px var(--accent-glow);
}
.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}
/* Stop-while-generating mode — visually distinct from "send" so the user
 * knows clicking will abort, not send a fresh message. */
.send-btn.stop-mode {
  background: linear-gradient(135deg, #ff5f6d, #ff8c42);
  color: #fff;
  animation: stop-pulse 1.6s ease-in-out infinite;
}
.send-btn.stop-mode:hover {
  box-shadow: 0 0 18px rgba(255, 95, 109, 0.45);
}
@keyframes stop-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 95, 109, 0.5); }
  50%      { box-shadow: 0 0 0 6px rgba(255, 95, 109, 0); }
}
.mic-btn {
  background: var(--bg-elev-2);
  color: var(--text-dim);
  border: 1px solid var(--line);
}
.mic-btn:hover {
  color: var(--text);
}
.mic-btn.recording {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
  animation: pulseRec 1.1s ease-in-out infinite;
}
.mic-btn.listening {
  background: linear-gradient(
    135deg,
    rgba(122, 162, 255, 0.95),
    rgba(167, 139, 250, 0.95)
  );
  color: #0b0d12;
  border-color: rgba(122, 162, 255, 0.65);
  animation: pulseListenMic 1.35s ease-in-out infinite;
}
/* Persistent wake-word session (tap mic again to leave). */
.mic-btn.voice-session {
  box-shadow: 0 0 0 2px rgba(122, 162, 255, 0.55);
}
/* Between phrases (server VAD idle): same live session, quieter appearance. */
.mic-btn.listening.vad-silence {
  opacity: 0.48;
  filter: grayscale(0.25);
  animation: none;
  box-shadow: none;
}
@keyframes pulseListenMic {
  0%, 100% { box-shadow: 0 0 0 0 rgba(122, 162, 255, 0.45); }
  50% { box-shadow: 0 0 0 10px rgba(122, 162, 255, 0); }
}
@keyframes pulseRec {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.55); }
  50% { box-shadow: 0 0 0 12px rgba(239, 68, 68, 0); }
}

.rec-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--danger);
  font-size: 12.5px;
  margin-top: 10px;
  padding-left: 6px;
}
.rec-dot {
  width: 10px;
  height: 10px;
  background: var(--danger);
  border-radius: 50%;
  animation: pulseRec 1.1s ease-in-out infinite;
}
.rec-indicator.vad-live {
  color: var(--accent);
}
.rec-indicator.vad-live .rec-dot {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
  animation: pulseListenMic 1.35s ease-in-out infinite;
}
.rec-indicator.vad-live.vad-silence {
  color: var(--text-dim);
  opacity: 0.75;
}
.rec-indicator.vad-live.vad-silence .rec-dot {
  animation: none;
  opacity: 0.55;
  box-shadow: none;
}
.rec-hint {
  color: var(--text-faint);
  margin-left: auto;
}

.hidden {
  display: none !important;
}

/* ----- Drawer ----------------------------------------------------- */

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 420px;
  max-width: 92vw;
  background: var(--bg-elev);
  border-left: 1px solid var(--line);
  z-index: 12;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.drawer:not(.hidden) {
  transform: translateX(0);
}
.drawer .drawer-inner {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  height: 100%;
  padding: 18px 20px 24px;
  gap: 12px;
}
.drawer header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.drawer h2 {
  margin: 0;
  font-size: 17px;
}
.drawer h3 {
  margin: 18px 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
}
.drawer label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--text-dim);
}
.drawer label.row {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  color: var(--text);
}
.drawer small.hint {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  opacity: 0.8;
  line-height: 1.4;
}
.drawer small.hint.vad-options-hint {
  margin: -4px 0 14px 28px;
}
.drawer input[type="text"],
.drawer input[type="number"],
.drawer select {
  appearance: none;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13px;
  font-family: inherit;
}
.drawer input:focus,
.drawer select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.ghost {
  appearance: none;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-dim);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12.5px;
  cursor: pointer;
}
.ghost:hover {
  color: var(--text);
}

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
  z-index: 11;
}

/* ----- Toasts ------------------------------------------------------ */

.toast-container {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 50;
  pointer-events: none;
}
.toast {
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--line);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 13px;
  box-shadow: var(--shadow-md);
  animation: toastIn 0.18s ease both;
  max-width: min(80vw, 480px);
  pointer-events: auto;
}
.toast.error {
  border-color: rgba(239, 68, 68, 0.4);
  background: linear-gradient(
    180deg,
    rgba(239, 68, 68, 0.12),
    var(--bg-elev-2)
  );
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ----- Responsive -------------------------------------------------- */

@media (max-width: 600px) {
  .topbar { padding: 14px 14px 10px; }
  .chat-area { padding: 16px 12px 6px; }
  .composer { padding: 10px 12px 14px; }
  .bubble { max-width: 88%; }
  .brand-sub { display: none; }
  .pill { padding: 6px 10px; font-size: 12px; }
}

/* ----- Markdown rendering inside assistant bubbles ----------------- */

/*
 * Most of this block scopes styles to ``.markdown .md-body`` so user
 * messages (rendered as plain text) and audio-only bubbles are not
 * affected. The first/last child margin reset makes a bubble that's
 * just a paragraph look identical to the old plain-text rendering.
 */
.bubble .md-body > *:first-child { margin-top: 0; }
.bubble .md-body > *:last-child { margin-bottom: 0; }

.bubble .md-body p {
  margin: 0 0 8px;
  line-height: 1.55;
}
.bubble .md-body h1,
.bubble .md-body h2,
.bubble .md-body h3,
.bubble .md-body h4 {
  margin: 14px 0 6px;
  line-height: 1.3;
  font-weight: 600;
}
.bubble .md-body h1 { font-size: 18px; }
.bubble .md-body h2 { font-size: 16px; }
.bubble .md-body h3 { font-size: 15px; }
.bubble .md-body h4 { font-size: 14px; color: var(--text-dim); }

.bubble .md-body ul,
.bubble .md-body ol {
  margin: 4px 0 8px;
  padding-left: 22px;
}
.bubble .md-body li { margin: 2px 0; line-height: 1.5; }
.bubble .md-body li > p { margin: 0 0 4px; }
.bubble .md-body li > ul,
.bubble .md-body li > ol { margin: 2px 0 2px; }

.bubble .md-body blockquote {
  margin: 6px 0;
  padding: 4px 12px;
  border-left: 3px solid var(--accent);
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.02);
  border-radius: 0 6px 6px 0;
}

.bubble .md-body hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 10px 0;
}

.bubble .md-body table {
  border-collapse: collapse;
  margin: 8px 0;
  display: block;
  overflow-x: auto;
  max-width: 100%;
  font-size: 13px;
}
.bubble .md-body th,
.bubble .md-body td {
  border: 1px solid var(--line);
  padding: 6px 10px;
  text-align: left;
}
.bubble .md-body th {
  background: rgba(255, 255, 255, 0.04);
  font-weight: 600;
}

.bubble .md-body strong { font-weight: 600; }
.bubble .md-body em { font-style: italic; }

/* Inline code -- keep the existing soft-pill look. */
.bubble code {
  background: rgba(255, 255, 255, 0.06);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 13px;
}

/* Fenced code blocks: dark slab, scroll horizontally on overflow. */
.bubble .md-body pre {
  background: #0d1117;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 8px 0;
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.5;
}
.bubble .md-body pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
  color: #e6edf3;
  font-size: 12.5px;
  white-space: pre;
}

.bubble a {
  color: var(--accent);
  text-decoration: none;
}
.bubble a:hover {
  text-decoration: underline;
}

.bubble .stopped-note {
  margin-top: 8px;
  padding: 4px 10px;
  font-size: 11px;
  color: #ff8c42;
  background: rgba(255, 140, 66, 0.08);
  border: 1px solid rgba(255, 140, 66, 0.25);
  border-radius: 999px;
  display: inline-block;
  letter-spacing: 0.2px;
}
