:root {
  --bg: #0f1116;
  --panel: #161922;
  --panel-2: #1d212c;
  --line: #272c3a;
  --text: #e6e8ee;
  --muted: #9096a6;
  --accent: #7c9cff;
  --danger: #e8725f;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--line); }
button.primary { background: var(--accent); border-color: var(--accent); color: #0f1116; font-weight: 600; padding: 8px 16px; }
button.primary:hover { filter: brightness(1.1); }
button.ghost { background: transparent; color: var(--muted); padding: 7px 12px; }
button.ghost:hover { color: var(--text); border-color: var(--muted); }
button.ghost.danger:hover { color: var(--danger); border-color: var(--danger); }
button:disabled { opacity: .45; cursor: not-allowed; }

#app { display: flex; height: 100%; }

/* ---------- sidebar ---------- */
#sidebar {
  width: 270px;
  flex: none;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}
.side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px; border-bottom: 1px solid var(--line);
}
.side-head h1 { font-size: 17px; margin: 0; letter-spacing: .5px; }
.side-actions { display: flex; align-items: center; gap: 6px; }
.side-actions .ghost { font-size: 12px; padding: 6px 9px; }
#conv-list { overflow-y: auto; padding: 8px; flex: 1; }

.conv {
  padding: 10px 12px; border-radius: var(--radius); cursor: pointer;
  border: 1px solid transparent; margin-bottom: 4px;
}
.conv:hover { background: var(--panel-2); }
.conv.active { background: var(--panel-2); border-color: var(--line); }
.conv .name { font-weight: 500; font-size: 14px; }
.conv .meta { color: var(--muted); font-size: 12px; margin-top: 3px; }

/* ---------- main ---------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.empty {
  margin: auto; text-align: center; color: var(--muted); max-width: 400px; padding: 24px;
}
.empty h2 { color: var(--text); margin-bottom: 6px; }
.empty p { margin-top: 0; }

#room { display: flex; flex-direction: column; height: 100%; min-height: 0; }

#room-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  padding: 14px 20px; border-bottom: 1px solid var(--line); flex: none;
}
#room-name { margin: 0 0 6px; font-size: 16px; }
.room-tools { display: flex; align-items: center; gap: 8px; flex: none; }
.room-tools select {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 9px; font: inherit; font-size: 13px;
}
.toggle { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; cursor: pointer; }

.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  font-size: 11.5px; padding: 2px 9px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line);
}
.chip .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; }

/* ---------- messages ---------- */
#messages { flex: 1; overflow-y: auto; padding: 22px 20px; scroll-behavior: smooth; }

.msg { max-width: 780px; margin: 0 auto 18px; }
.msg.user { text-align: right; }
.msg.user .body {
  display: inline-block; text-align: left; background: var(--accent); color: #0f1116;
  padding: 10px 14px; border-radius: var(--radius); max-width: 75%; font-weight: 500;
}

.msg.agent .who {
  display: flex; align-items: center; gap: 7px;
  font-size: 12.5px; font-weight: 600; margin-bottom: 5px;
}
.msg.agent .who .dot { width: 8px; height: 8px; border-radius: 50%; }
.msg.agent .body {
  background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--line);
  padding: 11px 14px; border-radius: var(--radius); white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.agent.error .body { border-color: var(--danger); color: #f2a99b; }
.msg .speak {
  background: none; border: none; color: var(--muted); font-size: 13px;
  padding: 2px 5px; opacity: .55;
}
.msg .speak:hover { opacity: 1; color: var(--text); }
.msg .speak.playing { opacity: 1; color: var(--accent); }

.thinking { color: var(--muted); font-style: italic; }
.thinking::after {
  content: "▍"; animation: blink 1s steps(2, start) infinite; font-style: normal;
}
@keyframes blink { to { visibility: hidden; } }

.warn { color: #d9b168; font-size: 12px; margin-top: 6px; }

/* ---------- composer ---------- */
#composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 14px 20px; border-top: 1px solid var(--line); flex: none;
}
#input {
  flex: 1; resize: none; max-height: 180px;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 11px 13px; font: inherit;
}
#input:focus { outline: none; border-color: var(--accent); }

.mic {
  background: var(--panel); border: 1px solid var(--line);
  width: 42px; height: 42px; border-radius: 50%; font-size: 17px; flex: none;
}
.mic.recording { background: var(--danger); border-color: var(--danger); animation: pulse 1.2s infinite; }
.mic.busy { opacity: .5; }
@keyframes pulse { 50% { filter: brightness(1.35); } }

/* ---------- picker ---------- */
dialog {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 14px;
  padding: 22px; width: min(640px, 92vw);
}
dialog::backdrop { background: rgba(0,0,0,.62); }
dialog h3 { margin: 0 0 14px; }
#picker-name {
  width: 100%; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px;
  font: inherit; margin-bottom: 14px;
}
#picker-name:focus { outline: none; border-color: var(--accent); }

.picker-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 8px; max-height: 46vh; overflow-y: auto;
}
.pick {
  display: flex; gap: 9px; align-items: flex-start;
  padding: 10px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel-2); cursor: pointer;
}
.pick:hover { border-color: var(--muted); }
.pick.on { border-color: var(--accent); background: #1b2236; }
.pick input { margin: 3px 0 0; accent-color: var(--accent); }
.pick .label { font-size: 13.5px; font-weight: 600; }
.pick .blurb { font-size: 11.5px; color: var(--muted); line-height: 1.4; }
.pick .kind { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 18px 0 0; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--danger); color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 14px; z-index: 50;
}
