:root {
  --bg: #0a0e14;
  --bg-2: #0f1520;
  --panel: #121a27;
  --line: #1d2836;
  --text: #dbe4ee;
  --dim: #7c8b9d;
  --accent: #00e5ff;
  --accent-2: #7c4dff;
  --danger: #ff5470;
  --user-bubble: #16283c;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 "Segoe UI", system-ui, sans-serif;
}

#app { display: flex; height: 100%; }

#sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 14px 12px;
  gap: 12px;
}

.brand {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 6px 10px;
}
.brand-mark { color: var(--accent); font-size: 18px; }
.brand-name { font-weight: 700; letter-spacing: 2px; font-size: 13px; }
.brand-name .lite {
  color: var(--accent);
  margin-left: 6px;
  font-size: 10px;
  letter-spacing: 3px;
  vertical-align: middle;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #04121a;
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
  font-size: 14px;
}
.btn-primary:hover { filter: brightness(1.12); }
.btn-ghost {
  background: transparent;
  color: var(--dim);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
}
.btn-ghost:hover { color: var(--text); border-color: var(--dim); }
.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 12px;
}

#conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.conv-item {
  text-align: left;
  background: transparent;
  color: var(--dim);
  border: none;
  border-radius: 8px;
  padding: 9px 10px;
  cursor: pointer;
  font-size: 13.5px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}
.conv-item:hover { background: var(--panel); color: var(--text); }
.conv-item.active { background: var(--panel); color: var(--text); border-left: 2px solid var(--accent); }
.conv-del { opacity: 0; color: var(--danger); padding: 0 4px; }
.conv-item:hover .conv-del { opacity: 1; }

.sidebar-foot { display: flex; flex-direction: column; gap: 8px; }
#engine-badge {
  font-size: 11px;
  color: var(--accent);
  letter-spacing: 1px;
  text-transform: uppercase;
  padding-left: 4px;
}

#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

#topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(5, 8, 15, 0.85);
  backdrop-filter: blur(8px);
}
#topbar #menu-toggle { justify-self: start; }
#topbar #privacy-badge { justify-self: end; }
#menu-toggle { display: none; }
#privacy-badge { margin-left: auto; }
#privacy-badge { font-size: 11px; color: var(--accent); border: 1px solid var(--line); border-radius: 99px; padding: 3px 10px; white-space: nowrap; }

#chat { flex: 1; overflow-y: auto; padding: 24px 16px; scroll-behavior: smooth; }
#chat > * { max-width: 780px; margin-inline: auto; }

.empty-state { text-align: center; margin-top: 18vh; color: var(--dim); }
.empty-state .glyph { font-size: 42px; color: var(--accent); text-shadow: 0 0 24px var(--accent); }
.empty-state h2 { color: var(--text); font-weight: 600; margin: 12px 0 4px; }

.msg { display: flex; margin-bottom: 14px; }
.msg.user { justify-content: flex-end; }
.msg.error .bubble { border-color: var(--danger); color: #ffb3c0; background: rgba(255, 84, 112, 0.06); }
.bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  overflow-wrap: break-word;
}
.msg.user .bubble { background: var(--user-bubble); border-color: #23405c; }
.msg.assistant .bubble code, .msg.user .bubble code {
  background: #0a111a;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 13px;
  font-family: Consolas, monospace;
}
pre {
  background: #0a111a;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
}
pre code { background: none; padding: 0; font-family: Consolas, monospace; font-size: 13px; }
.cursor { display: inline-block; width: 8px; height: 15px; background: var(--accent); animation: blink 1s steps(1) infinite; vertical-align: text-bottom; }
@keyframes blink { 50% { opacity: 0; } }

#composer {
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--bg-2);
}
.composer-pill {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 780px;
  margin-inline: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 26px;
  padding: 8px 10px 8px 18px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.composer-pill:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 229, 255, 0.1);
}
#input {
  flex: 1;
  resize: none;
  background: transparent;
  color: var(--text);
  border: none;
  padding: 8px 0;
  font: inherit;
  outline: none;
  max-height: 200px;
}
.btn-icon, .btn-send {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s ease, filter 0.15s ease;
}
.btn-icon {
  background: transparent;
  color: var(--dim);
}
.btn-icon:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }
.btn-icon.recording {
  color: #fff;
  background: var(--danger);
  animation: pulse 1.2s ease infinite;
  box-shadow: 0 0 0 3px rgba(255, 84, 112, 0.35);
}
.btn-icon.listening {
  color: var(--accent);
  background: rgba(0, 229, 255, 0.12);
  border: 1px solid var(--accent);
  animation: pulse-cyan 1s ease infinite;
}
@keyframes pulse-cyan {
  0%, 100% { box-shadow: 0 0 0 0 rgba(0, 229, 255, 0.4); }
  50% { box-shadow: 0 0 0 9px rgba(0, 229, 255, 0); }
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 84, 112, 0.5); }
  50% { box-shadow: 0 0 0 8px rgba(255, 84, 112, 0); }
}
.btn-send {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #04121a;
  font-size: 19px;
  font-weight: 700;
}
.btn-send:hover { filter: brightness(1.15); }
.btn-send:active { transform: scale(0.92); }

dialog {
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px;
  width: min(420px, 92vw);
}
dialog::backdrop { background: rgba(4, 8, 14, 0.7); backdrop-filter: blur(3px); }
dialog h2 { margin: 0 0 6px; font-size: 18px; }
dialog label { display: block; margin-top: 14px; font-size: 12.5px; color: var(--dim); }
dialog input, dialog select {
  width: 100%;
  margin-top: 5px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  font: inherit;
  outline: none;
}
dialog input:focus, dialog select:focus { border-color: var(--accent); }
.hint { font-size: 12.5px; color: var(--dim); margin: 0 0 4px; }
.hint.warn { color: #ffd166; margin-top: 8px; }
.dialog-actions { display: flex; align-items: center; gap: 8px; margin-top: 22px; }
.spacer { flex: 1; }

@media (max-width: 720px) {
  #sidebar {
    position: fixed;
    z-index: 10;
    inset: 0 auto 0 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  body.sidebar-open #sidebar { transform: translateX(0); box-shadow: 0 0 60px rgba(0, 0, 0, 0.6); }
  #menu-toggle { display: block; }
  .bubble { max-width: 95%; }
}

.topbar-selects { display: flex; gap: 8px; flex: 1; min-width: 0; }
#qs-engine, #qs-model {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  font: inherit;
  font-size: 13px;
  outline: none;
  cursor: pointer;
  max-width: 200px;
}
#qs-engine:focus, #qs-model:focus { border-color: var(--accent); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 10px 0 14px; }
.tab-btn {
  background: none; border: none; color: var(--dim);
  padding: 8px 14px; cursor: pointer; font: inherit; font-size: 13.5px;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.check-row { display: flex !important; align-items: center; gap: 10px; flex-direction: row !important; }
.check-row input { width: auto !important; margin: 0 !important; }

#tts-rate { padding: 0 !important; border: none !important; background: transparent !important; accent-color: var(--accent); }
#tts-voice { max-height: 120px; }

.msg-actions { display: flex; gap: 2px; margin-top: 4px; opacity: 0; transition: opacity 0.15s ease; }
.msg:hover .msg-actions { opacity: 1; }
.act-btn {
  background: none; border: none; color: var(--dim);
  cursor: pointer; font-size: 13px; padding: 2px 6px; border-radius: 6px;
}
.act-btn:hover { color: var(--accent); background: rgba(255,255,255,0.05); }

.regen-row { display: flex; justify-content: center; margin: 4px 0 14px; }
.regen-btn { font-size: 16px; border: 1px solid var(--line); border-radius: 50%; padding: 6px 12px; }
.regen-btn:hover { border-color: var(--accent); }

.codeblock { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin: 8px 0; }
.codebar {
  display: flex; justify-content: space-between; align-items: center;
  background: #0d1420; padding: 4px 10px;
  font-size: 11px; color: var(--dim); letter-spacing: 1px;
}
.copy-btn {
  background: none; border: 1px solid var(--line); color: var(--dim);
  border-radius: 5px; padding: 2px 8px; cursor: pointer; font-size: 11px;
}
.copy-btn:hover { color: var(--accent); border-color: var(--accent); }
.codeblock pre { border: none; border-radius: 0; margin: 0; }

.tablewrap { overflow-x: auto; margin: 8px 0; }
table { border-collapse: collapse; font-size: 13.5px; width: 100%; }
th, td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
th { background: var(--panel); color: var(--text); }

.bubble p { margin: 0 0 8px; } 
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 4px 0 8px; padding-left: 22px; }
.bubble li { margin: 2px 0; }
.bubble h3, .bubble h4 { margin: 10px 0 4px; }
.bubble a { color: var(--accent); }

.brand-mark svg { display: block; filter: drop-shadow(0 0 6px var(--glow)); animation: breathe 4s ease-in-out infinite; }
@keyframes breathe {
  0%, 100% { opacity: 0.8; filter: drop-shadow(0 0 4px var(--glow)); }
  50% { opacity: 1; filter: drop-shadow(0 0 12px var(--glow)); }
}

#snow { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
#snow i {
  position: absolute; top: -3vh;
  width: 2px; height: 2px; border-radius: 50%;
  background: rgba(160, 220, 255, 0.35);
  animation: fall linear infinite;
}
#snow i:nth-child(1)  { left: 8%;  animation-duration: 14s; animation-delay: -2s; }
#snow i:nth-child(2)  { left: 21%; animation-duration: 19s; animation-delay: -7s; }
#snow i:nth-child(3)  { left: 33%; animation-duration: 16s; animation-delay: -12s; }
#snow i:nth-child(4)  { left: 46%; animation-duration: 22s; animation-delay: -4s; }
#snow i:nth-child(5)  { left: 58%; animation-duration: 17s; animation-delay: -9s; }
#snow i:nth-child(6)  { left: 67%; animation-duration: 13s; animation-delay: -1s; }
#snow i:nth-child(7)  { left: 74%; animation-duration: 24s; animation-delay: -15s; }
#snow i:nth-child(8)  { left: 82%; animation-duration: 18s; animation-delay: -6s; }
#snow i:nth-child(9)  { left: 91%; animation-duration: 15s; animation-delay: -11s; }
#snow i:nth-child(10) { left: 15%; animation-duration: 21s; animation-delay: -17s; }
#snow i:nth-child(11) { left: 40%; animation-duration: 25s; animation-delay: -3s; }
#snow i:nth-child(12) { left: 52%; animation-duration: 20s; animation-delay: -14s; }
@keyframes fall {
  0%   { transform: translateY(0); opacity: 0; }
  8%   { opacity: 0.5; }
  85%  { opacity: 0.35; }
  100% { transform: translateY(112vh); opacity: 0; }
}

.empty-state .glyph svg { width: 56px; height: 56px; filter: drop-shadow(0 0 18px var(--glow)); animation: floaty 5s ease-in-out infinite; }
@keyframes floaty {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

#app, #settings { position: relative; z-index: 1; }

@media (prefers-reduced-motion: reduce) {
  #snow { display: none; }
  .brand-mark svg, .empty-state .glyph svg { animation: none !important; }
}

#qs-pick {
  background: transparent;
  color: var(--text);
  border: none;
  border-radius: 10px;
  padding: 8px 14px;
  font: 700 15px 'Chakra Petch', sans-serif;
  letter-spacing: 0.5px;
  outline: none;
  cursor: pointer;
  max-width: 300px;
  text-align: center;
}
#qs-pick:hover { background: rgba(255,255,255,0.04); }
#qs-pick option, #qs-pick optgroup { background: var(--bg-2); color: var(--text); font-family: 'Cairo', sans-serif; font-size: 13px; }
#tts-toggle.muted { color: var(--danger); opacity: 0.7; }
#privacy-badge { cursor: default; }
h1, h2, h3, .brand-name { font-family: 'Chakra Petch', 'Cairo', sans-serif; }
.empty-state h2 { letter-spacing: 1px; }





#voice-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: radial-gradient(ellipse at 50% 30%, #0b1526 0%, var(--bg) 65%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 20px;
}
.voice-status { color: var(--dim); font-size: 14px; letter-spacing: 1px; min-height: 20px; }
.voice-orb {
  width: 170px; height: 170px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle, rgba(0,229,255,0.08), transparent 70%);
  border: 1px solid var(--line);
  transition: box-shadow 0.3s ease, border-color 0.3s ease;
}
.voice-orb.listening { border-color: var(--accent); box-shadow: 0 0 40px rgba(0,229,255,0.25), inset 0 0 30px rgba(0,229,255,0.08); animation: pulse-cyan 2s ease infinite; }
.voice-orb.speaking { border-color: var(--accent-2); box-shadow: 0 0 50px rgba(124,77,255,0.35), inset 0 0 34px rgba(124,77,255,0.12); animation: pulse-violet 0.9s ease infinite; }
.voice-orb.muted { border-color: var(--danger); opacity: 0.7; }
@keyframes pulse-violet {
  0%, 100% { box-shadow: 0 0 30px rgba(124,77,255,0.25); }
  50% { box-shadow: 0 0 70px rgba(124,77,255,0.45); }
}
.voice-transcript {
  width: min(560px, 92vw);
  height: 30vh;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 8px;
  font-size: 13.5px;
}
.vt-line { padding: 6px 12px; border-radius: 10px; }
.vt-line.user { background: var(--user-bubble); align-self: flex-end; }
.vt-line.agent { background: var(--panel); border: 1px solid var(--line); align-self: flex-start; }
.voice-controls { display: flex; gap: 16px; }
.voice-ctl {
  width: 56px; height: 56px; border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel); color: var(--text);
  font-size: 20px; cursor: pointer;
}
.voice-ctl:hover { border-color: var(--dim); }
.voice-ctl.end { background: var(--danger); border-color: var(--danger); color: #fff; }
.voice-ctl.muted { background: rgba(255,84,112,0.15); color: var(--danger); border-color: var(--danger); }
.voice-hint { color: var(--dim); font-size: 11.5px; letter-spacing: 0.5px; }

@media (prefers-reduced-motion: reduce) {
  .voice-orb.listening, .voice-orb.speaking { animation: none !important; }
}

#voice-overlay[hidden] { display: none; }

.voice-metrics { color: var(--accent); font-size: 11.5px; letter-spacing: 1px; font-family: 'JetBrains Mono', monospace; min-height: 16px; opacity: 0.85; }

.voice-btn { background: linear-gradient(135deg, var(--accent-2), #ff5470); color: #fff; }
