:root {
  --bg: #0e1013;
  --surface: #14171c;
  --panel: #191d24;
  --panel-2: #1f242c;
  --border: #262b34;
  --border-strong: #333a46;
  --text: #e8ebf0;
  --text-dim: #98a1b0;
  --text-faint: #616a78;
  --accent: #3b82f6;
  --accent-strong: #2563eb;
  --accent-soft: rgba(59, 130, 246, 0.14);
  --green: #34c275;
  --red: #e5534b;
  --amber: #d9a441;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

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

:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: 4px; }

html, body { height: 100%; }

body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.app { display: flex; flex-direction: column; height: 100vh; }

/* left sidebar */
.app-body { flex: 1; display: flex; min-height: 0; }
.rail {
  width: 56px; flex-shrink: 0; display: flex; flex-direction: column;
  padding: 10px 7px;
  background: var(--surface); border-right: 1px solid var(--border);
  overflow: hidden;
  transition: width 0.18s ease;
}
.rail:hover, .rail.open { width: 200px; }
.rail-actions { display: flex; flex-direction: column; gap: 4px; flex-shrink: 0; }
.rail .rail-btn {
  width: 100%; height: 40px; border-radius: 8px; flex-shrink: 0;
  background: transparent; border: 1px solid transparent;
  color: var(--text-dim); cursor: pointer;
  display: flex; align-items: center; gap: 12px; padding: 0 11px;
  transition: background 0.12s, color 0.12s; white-space: nowrap;
}
.rail .rail-btn svg { width: 18px; height: 18px; flex-shrink: 0; }
.rail .rail-btn:hover { background: var(--panel); color: var(--text); }
.rail .rail-btn.active { color: var(--accent); background: var(--accent-soft); }
.rail-label {
  font-size: 13px; opacity: 0; transition: opacity 0.15s ease 0.03s;
  overflow: hidden; text-overflow: ellipsis;
}
.rail:hover .rail-label, .rail.open .rail-label { opacity: 1; }
.rail-camera {
  margin-top: auto; padding: 4px 0;
  display: flex; flex-direction: column; gap: 4px;
}
.rail-camera .camera-panel { width: 100%; border-radius: 8px; }
.app-content { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }

/* ---------- chats sidebar ---------- */
.chats-sidebar {
  width: 0; flex-shrink: 0; display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); border-right: 1px solid var(--border);
  overflow: hidden; transition: width 0.18s ease;
}
.chats-sidebar.open { width: 240px; }
.chats-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 14px 6px; font-size: 13px; font-weight: 700;
  color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em;
}
.chats-head .icon-btn { border: none; background: transparent; color: var(--text-faint); cursor: pointer; font-size: 14px; }
.chats-head .icon-btn:hover { color: var(--text); }
.new-chat-btn {
  margin: 4px 12px 10px; padding: 9px 12px; border-radius: 8px;
  border: 1px solid var(--accent-soft); background: var(--accent-soft);
  color: var(--accent); font-size: 13.5px; font-weight: 600; cursor: pointer;
  transition: filter 0.12s;
}
.new-chat-btn:hover { filter: brightness(1.1); }
.chats-list { flex: 1; overflow-y: auto; padding: 0 8px 12px; display: flex; flex-direction: column; gap: 3px; }
.chat-item {
  display: flex; align-items: center; gap: 6px; padding: 9px 10px; border-radius: 8px;
  cursor: pointer; color: var(--text-dim); border: 1px solid transparent;
  transition: background 0.12s, color 0.12s;
}
.chat-item:hover { background: var(--panel); color: var(--text); }
.chat-item.active { background: var(--accent-soft); color: var(--text); border-color: var(--accent-soft); }
.chat-title { flex: 1; font-size: 13px; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.chat-del { border: none; background: transparent; color: var(--text-faint); cursor: pointer; font-size: 12px; padding: 4px; border-radius: 5px; opacity: 0; }
.chat-item:hover .chat-del { opacity: 1; }
.chat-del:hover { color: #ff6b6b; }

.view-seg { width: 150px; flex-shrink: 0; }

.flow-title {
  font-size: 13px; font-weight: 600; color: var(--text);
  padding: 0 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  flex-shrink: 0; max-width: 200px;
}

/* ---------- voice view ---------- */
.voice-view {
  flex: 1; display: none; align-items: center; justify-content: center;
  gap: 44px; min-height: 0; padding: 28px; order: 1;
  background:
    radial-gradient(700px 420px at 50% 120%, rgba(59, 130, 246, 0.07), transparent 60%),
    var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.app.voice-mode .chat { display: none; }
.app.voice-mode .voice-view { display: flex; }
.side { order: 2; }

.vv-panel {
  flex: 1; max-width: 320px; min-width: 0;
  display: flex; flex-direction: column; align-items: center; gap: 16px; text-align: center;
}
.vv-name { font-size: 15px; font-weight: 650; }
.vv-state { font-size: 12px; color: var(--text-faint); text-transform: capitalize; }

.avatar {
  position: relative; width: 168px; height: 168px; border-radius: 50%;
  border: 2px solid var(--border-strong); background: var(--panel);
  display: grid; place-items: center; overflow: hidden;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.35);
  transition: box-shadow 0.3s, border-color 0.3s;
}
.user-avatar img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; transform: scaleX(-1); display: none;
}
.user-avatar img[src] { display: block; }
.avatar-fallback { width: 100%; height: 100%; display: grid; place-items: center; color: var(--text-faint); }
.avatar-fallback svg { width: 62px; height: 62px; }

.vv-panel.active .avatar {
  border: 2px solid transparent;
  background:
    linear-gradient(var(--panel), var(--panel)) padding-box,
    conic-gradient(from 0deg, var(--accent), var(--accent2), var(--accent)) border-box;
  box-shadow: 0 0 44px rgba(59, 130, 246, 0.5), inset 0 0 40px rgba(0, 0, 0, 0.3);
  animation: ringPulse 1.5s ease-in-out infinite;
}
@keyframes ringPulse {
  50% { box-shadow: 0 0 70px rgba(59, 130, 246, 0.75), inset 0 0 40px rgba(0, 0, 0, 0.3); }
}

.core-orb {
  position: relative; width: 168px; height: 168px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #9cc0ff, var(--accent) 55%, var(--accent-strong));
  box-shadow: 0 0 44px rgba(59, 130, 246, 0.35), inset 0 0 32px rgba(0, 0, 0, 0.45);
  opacity: 0.3; transition: opacity 0.3s;
}
.core-orb::before {
  content: ""; position: absolute; inset: -12px; border-radius: 50%;
  border: 2px dashed rgba(59, 130, 246, 0.55); opacity: 0;
}
.vv-panel.active .core-orb { opacity: 1; animation: orbPulse 1.3s ease-in-out infinite; }
.vv-panel.active .core-orb::before { opacity: 1; animation: orbSpin 7s linear infinite; }
@keyframes orbPulse { 50% { transform: scale(1.06); } }
@keyframes orbSpin { to { transform: rotate(360deg); } }

.vv-flow {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 5px;
  font-size: 12px; color: var(--text-faint); max-width: 250px;
}
.vv-sep { color: var(--text-faint); }
.vv-flow [data-stage] { padding: 3px 8px; border-radius: 999px; border: 1px solid var(--border); transition: all 0.15s; }
.vv-flow [data-stage].active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.ai-face { width: 100%; height: 100%; }
.ai-face .face-bg { fill: var(--panel-2); stroke: var(--border-strong); stroke-width: 2; }
.ai-face .eye { fill: var(--accent); filter: drop-shadow(0 0 4px var(--accent)); transform-origin: center; animation: blink 4s infinite; }
.ai-face .mouth { fill: var(--accent); filter: drop-shadow(0 0 5px var(--accent)); transform-origin: 60px 80px; }
.ai-avatar.speaking .mouth { animation: talk 0.26s infinite alternate ease-in-out; }
@keyframes talk { from { transform: scaleY(0.35); } to { transform: scaleY(2); } }
@keyframes blink { 0%, 93%, 100% { transform: scaleY(1); } 96% { transform: scaleY(0.08); } }
.ai-avatar.thinking .eye { animation: think 0.9s infinite; }
@keyframes think { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 14px;
  height: 52px; padding: 0 16px; flex-shrink: 0;
  background: var(--surface); border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 26px; height: 26px; border-radius: 7px;
  display: grid; place-items: center; overflow: hidden; flex-shrink: 0;
}
.logo svg { width: 26px; height: 26px; }
.brand-text h1 { font-size: 14px; font-weight: 650; letter-spacing: 0.2px; }
.brand-text span { font-size: 11px; color: var(--text-faint); }

.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.status {
  display: flex; align-items: center; gap: 7px;
  height: 26px; padding: 0 11px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--border);
  font-size: 12px; font-weight: 500; color: var(--text-dim);
}
.status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); }
.status[data-state="capturing"] .dot { background: var(--green); }
.status[data-state="generating"] .dot { background: var(--accent); }
.status[data-state="error"] .dot { background: var(--red); }
.status[data-state="capturing"] .label,
.status[data-state="generating"] .label { color: var(--text); }

.conn span {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--red);
}
.conn.on span { background: var(--green); }

.icon-btn {
  width: 32px; height: 32px; border-radius: 8px;
  background: transparent; border: 1px solid transparent;
  color: var(--text-dim); cursor: pointer;
  display: grid; place-items: center; transition: all 0.12s;
}
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn:hover { background: var(--panel); color: var(--text); border-color: var(--border); }
.icon-btn.active { color: var(--accent); background: var(--accent-soft); border-color: transparent; }

/* ---------- pipeline flow ---------- */
.flow {
  display: flex; align-items: center; gap: 12px;
  padding: 7px 16px; flex-shrink: 0;
  border-bottom: 1px solid var(--border); background: var(--surface);
  font-size: 11.5px; color: var(--text-faint);
}
.flow-stages { flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px; }
.flow-node {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--panel);
  transition: all 0.15s; white-space: nowrap;
}
.flow-node .f-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-faint); transition: all 0.15s; }
.flow-node .f-label { color: var(--text-dim); }
.flow-sep { color: var(--text-faint); font-size: 13px; }
.flow-node.active { border-color: var(--accent); background: var(--accent-soft); }
.flow-node.active .f-dot { background: var(--accent); box-shadow: 0 0 6px var(--accent); animation: fpulse 1s infinite; }
.flow-node.active .f-label { color: var(--text); }
@keyframes fpulse { 50% { opacity: 0.4; } }

/* ---------- main ---------- */
.main { flex: 1; display: flex; min-height: 0; gap: 12px; padding: 12px 16px; }

.chat {
  flex: 1; display: flex; flex-direction: column; min-width: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}

.messages {
  flex: 1; overflow-y: auto; padding: 16px 18px;
  display: flex; flex-direction: column; gap: 12px;
}
.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
.messages::-webkit-scrollbar-track { background: transparent; }

/* welcome / empty state */
.welcome {
  margin: auto; text-align: center; display: flex; flex-direction: column;
  align-items: center; gap: 12px; max-width: 420px; padding: 20px;
}
.welcome-mark {
  width: 52px; height: 52px; border-radius: 14px;
  display: grid; place-items: center; overflow: hidden;
}
.welcome-mark svg { width: 52px; height: 52px; }
.welcome h2 { font-size: 17px; font-weight: 650; }
.welcome p { font-size: 13.5px; color: var(--text-dim); }

.welcome-suggestions {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 8px;
}
.welcome-suggestion {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--panel);
  color: var(--text-dim); font-size: 12.5px; cursor: pointer;
  transition: all 0.15s;
}
.welcome-suggestion:hover {
  border-color: var(--accent); color: var(--text);
  background: var(--accent-soft);
}
.ws-icon { font-size: 14px; }

.welcome-tips {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 4px;
}
.welcome-tips span {
  font-size: 11.5px; color: var(--text-faint); padding: 5px 10px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--panel);
}

.msg {
  max-width: 76%; padding: 9px 13px; border-radius: 10px;
  font-size: 14px; line-height: 1.55; white-space: pre-wrap; word-break: break-word;
  position: relative;
  animation: msgFadeIn 0.2s ease;
}
@keyframes msgFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.msg.user {
  align-self: flex-end; background: var(--accent-strong); color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.assistant {
  align-self: flex-start; background: var(--panel-2);
  border: 1px solid var(--border); border-bottom-left-radius: 4px;
}
.msg.assistant .cursor::after {
  content: "▍"; color: var(--accent); margin-left: 1px;
  animation: blink 0.8s infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.msg.system {
  align-self: center; background: transparent; color: var(--text-faint);
  font-size: 12px; text-align: center; max-width: 90%;
}
.msg.error {
  align-self: center; background: rgba(229, 83, 75, 0.08);
  color: var(--red); border: 1px solid rgba(229, 83, 75, 0.25);
  font-size: 12.5px;
}

/* message hover actions */
.msg-actions {
  position: absolute; top: -10px; right: 6px; display: flex; gap: 3px;
  opacity: 0; transition: opacity 0.12s;
}
.msg:hover .msg-actions { opacity: 1; }
.msg-actions button {
  width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--panel); color: var(--text-faint); cursor: pointer;
  display: grid; place-items: center; transition: all 0.12s;
}
.msg-actions button svg { width: 13px; height: 13px; }
.msg-actions button:hover { color: var(--text); border-color: var(--border-strong); background: var(--panel-2); }
.msg-actions button.copied { color: var(--green); border-color: var(--green); }

.composer {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-top: 1px solid var(--border);
}
.mic-btn {
  width: 40px; height: 40px; flex-shrink: 0; border-radius: 50%;
  background: var(--panel); border: 1px solid var(--border);
  color: var(--text-dim); cursor: pointer;
  display: grid; place-items: center; transition: all 0.12s;
}
.mic-btn svg { width: 19px; height: 19px; }
.mic-btn:hover { color: var(--text); border-color: var(--border-strong); }
.mic-btn .ic-stop { display: none; }
.mic-btn.recording { background: var(--red); border-color: var(--red); color: #fff; }
.mic-btn.speaking { background: var(--accent); border-color: var(--accent); color: #fff; }
.mic-btn.speaking .ic-mic { display: none; }
.mic-btn.speaking .ic-stop { display: block; }

.composer input {
  flex: 1; height: 40px; padding: 0 13px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--border);
  color: var(--text); font-size: 14px; outline: none; min-width: 0;
}
.composer input::placeholder { color: var(--text-faint); }
.composer input:focus { border-color: var(--border-strong); }

.send-btn {
  width: 40px; height: 40px; flex-shrink: 0; border-radius: 10px; border: none;
  background: var(--accent); color: #fff; cursor: pointer;
  display: grid; place-items: center; transition: background 0.12s;
}
.send-btn svg { width: 17px; height: 17px; }
.send-btn:hover { background: var(--accent-strong); }

.stop-btn {
  width: 40px; height: 40px; flex-shrink: 0; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--border);
  color: var(--text-dim); cursor: pointer;
  display: grid; place-items: center; transition: all 0.12s;
}
.stop-btn svg { width: 15px; height: 15px; }
.stop-btn:hover { color: var(--red); border-color: var(--red); }

.hint { padding: 0 12px 10px; font-size: 11.5px; color: var(--text-faint); }

/* ---------- side panel ---------- */
.side { width: 282px; flex-shrink: 0; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
.side::-webkit-scrollbar { width: 8px; }

.camera-panel {
  position: relative; aspect-ratio: 4/3; border-radius: var(--radius);
  background: #000; border: 1px solid var(--border); overflow: hidden;
}
.camera-panel img { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); display: block; }
.camera-off {
  position: absolute; inset: 0; display: none; place-items: center;
  flex-direction: column; gap: 4px;
  color: var(--text-faint); font-size: 11px; background: var(--surface);
}
.cam-off-icon { width: 18px; height: 18px; }
.cam-off-text { white-space: nowrap; display: none; }
.rail:hover .cam-off-text, .rail.open .cam-off-text { display: block; }
.camera-panel.off img { display: none; }
.camera-panel.off .camera-off { display: flex; }

.meter { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 11px 13px; }
.meter-track { position: relative; height: 6px; border-radius: 999px; background: var(--panel-2); overflow: hidden; }
.meter-fill {
  height: 100%; width: 0%; border-radius: 999px; background: var(--green);
  transition: width 0.08s linear;
}
.meter-thresh {
  position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--amber);
  left: 20%; transition: left 0.3s;
}
.meter-labels { display: flex; justify-content: space-between; margin-top: 7px; font-size: 11px; color: var(--text-faint); }
.meter-labels span:last-child { color: var(--text-dim); font-variant-numeric: tabular-nums; }

.controls {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 14px;
  display: flex; flex-direction: column; gap: 12px;
}
.control-row { display: flex; flex-direction: column; gap: 6px; }
.control-row > label {
  font-size: 11px; font-weight: 600; color: var(--text-dim);
  letter-spacing: 0.3px; text-transform: uppercase;
  display: flex; justify-content: space-between; align-items: baseline;
}
.control-row > label span { color: var(--text-faint); font-weight: 500; text-transform: none; }

select { width: 100%; height: 32px; padding: 0 9px; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--border); color: var(--text); font-size: 13px; outline: none; }
select:focus { border-color: var(--border-strong); }
select option { background: var(--panel-2); color: var(--text); }

.text-input {
  width: 100%; height: 32px; padding: 0 10px; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); font-size: 13px; outline: none;
}
.text-input:focus { border-color: var(--border-strong); }

.text-area {
  width: 100%; padding: 9px 11px; border-radius: 8px; resize: vertical;
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); font-size: 13px; line-height: 1.5; outline: none;
  font-family: inherit;
}
.text-area:focus { border-color: var(--border-strong); }

.select-wrap { display: flex; gap: 6px; }
.select-wrap select { flex: 1; min-width: 0; }
.mini-btn {
  width: 32px; height: 32px; flex-shrink: 0; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text-dim); cursor: pointer; display: grid; place-items: center;
  transition: all 0.12s;
}
.mini-btn svg { width: 15px; height: 15px; }
.mini-btn:hover { color: var(--text); border-color: var(--border-strong); }

.dl-btn {
  width: 100%; height: 34px; margin-top: 2px; border-radius: 8px;
  background: var(--panel-2); border: 1px dashed var(--border-strong);
  color: var(--text-dim); cursor: pointer; font-size: 13px;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  transition: all 0.12s;
}
.dl-btn svg { width: 15px; height: 15px; }
.dl-btn:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

.seg { display: flex; background: var(--panel-2); border-radius: 8px; padding: 2px; }
.seg button {
  flex: 1; height: 28px; border: none; border-radius: 6px; cursor: pointer;
  background: transparent; color: var(--text-dim); font-size: 12.5px; transition: all 0.12s;
}
.seg button.active { background: var(--panel); color: var(--text); box-shadow: inset 0 0 0 1px var(--border); }

input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 4px;
  border-radius: 999px; background: var(--panel-2); outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 14px; height: 14px;
  border-radius: 50%; background: var(--accent); border: 2px solid var(--panel);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 50%; background: var(--accent);
  border: 2px solid var(--panel); cursor: pointer;
}

.switch-row { flex-direction: row; align-items: center; justify-content: space-between; }
.switch-row > label:first-child { flex: 1; font-size: 11px; color: var(--text-dim); font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; }
.switch { position: relative; width: 36px; height: 20px; }
.switch input { display: none; }
.switch .slider { position: absolute; inset: 0; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--border); transition: 0.15s; cursor: pointer; }
.switch .slider::before {
  content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%;
  background: var(--text-faint); top: 2px; left: 2px; transition: 0.15s;
}
.switch input:checked + .slider { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(16px); background: #fff; }

/* ---------- generation options (collapsible) ---------- */
.genopts { border: 1px solid var(--border); border-radius: 8px; }
.genopts summary {
  list-style: none; cursor: pointer; padding: 8px 10px;
  font-size: 11px; font-weight: 600; color: var(--text-dim);
  letter-spacing: 0.3px; text-transform: uppercase;
  display: flex; align-items: center; justify-content: space-between;
  user-select: none;
}
.genopts summary::-webkit-details-marker { display: none; }
.genopts summary::after { content: "+"; font-size: 14px; color: var(--text-faint); }
.genopts[open] summary::after { content: "−"; }
.genopts-body { padding: 2px 10px 12px; display: flex; flex-direction: column; gap: 12px; }

.group-label {
  font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.4px;
  color: var(--accent); margin-top: 2px;
}
.group-label:not(:first-child) { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }

/* ---------- download progress ---------- */
.dl-progress { display: flex; flex-direction: column; gap: 7px; }
.dl-stats { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.dl-stats #dlPct { color: var(--accent); font-weight: 600; }

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0; display: none; place-items: center;
  background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(2px); z-index: 50;
}
.modal.open { display: grid; }
#voiceModal, #dlModal { z-index: 60; }
.modal-card {
  width: min(400px, 90vw); background: var(--panel); border: 1px solid var(--border-strong);
  border-radius: 12px; padding: 20px; display: flex; flex-direction: column; gap: 12px;
}
.modal-card h2 { font-size: 15px; font-weight: 650; }
.modal-sub { color: var(--text-dim); font-size: 12.5px; line-height: 1.5; }
.modal-card input {
  height: 36px; padding: 0 12px; border-radius: 8px; background: var(--panel-2);
  border: 1px solid var(--border); color: var(--text); font-size: 13.5px; outline: none;
}
.modal-card input:focus { border-color: var(--border-strong); }
.record-btn {
  height: 38px; border-radius: 8px; border: none; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 13.5px; font-weight: 600; transition: background 0.12s;
}
.record-btn:hover { background: var(--accent-strong); }
.record-btn.recording { background: var(--red); }
.record-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.modal-status { font-size: 12.5px; color: var(--text-dim); min-height: 16px; }
.upload-row { display: flex; gap: 8px; }
.modal-actions { display: flex; justify-content: flex-end; }
.ghost-btn {
  height: 32px; padding: 0 14px; border-radius: 8px; background: var(--panel-2);
  border: 1px solid var(--border); color: var(--text); cursor: pointer; font-size: 12.5px;
}
.ghost-btn:hover { border-color: var(--border-strong); }
.ghost-btn.danger { color: #ff6b6b; border-color: rgba(255,107,107,0.4); }
.ghost-btn.danger:hover { border-color: #ff6b6b; }

.perm-body { display: flex; flex-direction: column; gap: 10px; }
.perm-title { font-size: 14px; font-weight: 600; color: var(--text); }
.perm-args {
  font-family: monospace; font-size: 12px; line-height: 1.5; color: var(--text-dim);
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px; white-space: pre-wrap; word-break: break-all; max-height: 200px; overflow-y: auto;
}

/* ---------- help ---------- */
.help-card { width: min(540px, 92vw); max-height: 85vh; display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.settings-body { overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding-right: 4px; }
.settings-body::-webkit-scrollbar { width: 8px; }
.settings-body::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
.help-body { overflow-y: auto; display: flex; flex-direction: column; gap: 18px; padding-right: 4px; }
.help-body::-webkit-scrollbar { width: 8px; }
.help-body::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
.help-sec h3 {
  font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.4px;
  color: var(--accent); margin-bottom: 7px;
}
.help-sec p { font-size: 13px; color: var(--text-dim); line-height: 1.55; }
.help-sec ul { margin: 7px 0 0 17px; display: flex; flex-direction: column; gap: 6px; }
.help-sec li { font-size: 13px; color: var(--text-dim); line-height: 1.5; }
.help-sec b { color: var(--text); font-weight: 600; }
.help-sec .mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--accent); font-size: 12.5px; margin: 7px 0;
}

/* ---------- knowledge base ---------- */
.kb-row { display: flex; align-items: center; justify-content: space-between; }
.kb-label { font-size: 13px; color: var(--text-dim); }
.kb-list { display: flex; flex-direction: column; gap: 6px; max-height: 40vh; overflow-y: auto; }
.kb-list::-webkit-scrollbar { width: 8px; }
.kb-list::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
.kb-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
}
.kb-item .kb-name { flex: 1; font-size: 13px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kb-item .kb-meta { font-size: 11px; color: var(--text-faint); }
.kb-item button {
  width: 26px; height: 26px; flex-shrink: 0; border-radius: 6px;
  background: transparent; border: 1px solid transparent; color: var(--text-faint);
  cursor: pointer; display: grid; place-items: center;
}
.kb-item button:hover { color: var(--red); background: var(--panel); border-color: var(--border); }
.kb-item button svg { width: 13px; height: 13px; }
.kb-empty { font-size: 12.5px; color: var(--text-faint); text-align: center; padding: 10px; }

.tool-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.tool-chip {
  font-size: 11.5px; color: var(--text-dim); padding: 5px 10px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--panel-2);
}
.tool-chip b { color: var(--accent); font-weight: 600; }

.control-row .hint { flex: 1; font-size: 11.5px; color: var(--text-faint); text-align: right; }

/* ==================== responsive ==================== */

/* Tablet / small laptop */
@media (max-width: 1080px) {
  .side { width: 250px; }
  .avatar { width: 140px; height: 140px; }
  .core-orb { width: 140px; height: 140px; }
  .voice-view { gap: 28px; padding: 20px; }
}

/* Phone / small tablet */
@media (max-width: 760px) {
  #btnSettings { display: grid; }
  .brand-text span { display: none; }
  .view-seg { width: 150px; }
  .flow-title { display: none; }
  .topbar { padding: 0 10px; gap: 8px; }
  .top-actions { gap: 4px; }

  /* flow bar: allow wrapping and hide on very small screens */
  .flow { flex-wrap: wrap; padding: 6px 10px; gap: 5px; }

  /* side panel becomes a slide-in drawer */
  .side {
    position: fixed; top: 52px; right: 0; bottom: 0; width: 300px; max-width: 88vw;
    transform: translateX(100%); transition: transform 0.25s ease;
    z-index: 40; background: var(--surface); border-left: 1px solid var(--border);
    padding: 12px; overflow-y: auto;
  }
  .side.open { transform: translateX(0); }

  .main { padding: 10px; }
  .messages { padding: 12px 14px; }
  .msg { max-width: 88%; }

  /* voice view stacks vertically */
  .voice-view { flex-direction: column; gap: 18px; overflow-y: auto; justify-content: flex-start; padding: 18px; }
  .vv-panel { max-width: none; flex: 0 0 auto; }
  .avatar { width: 110px; height: 110px; }
  .core-orb { width: 110px; height: 110px; }
  .vv-flow { max-width: 100%; }
}

/* Small phone */
@media (max-width: 420px) {
  .brand-text h1 { font-size: 13px; }
  .view-seg { width: 132px; }
  .status .label { display: none; }
  .status { padding: 0 8px; }
  .flow { display: none; }
  .avatar { width: 92px; height: 92px; }
  .core-orb { width: 92px; height: 92px; }
  .icon-btn { width: 30px; height: 30px; }
}
