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

:root {
  --bg: #0f1420;
  --panel: #171e2e;
  --panel-2: #1d2638;
  --border: #2a3550;
  --text: #e8edf7;
  --muted: #8b97b1;
  --accent: #4f8cff;
  --green: #2ecc71;
  --red: #e74c3c;
  --amber: #f1c40f;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Devanagari", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 22px; border-bottom: 1px solid var(--border); background: var(--panel);
  flex-wrap: wrap; gap: 10px;
}
.brand { display: flex; gap: 12px; align-items: center; }
.logo { font-size: 30px; }
h1 { font-size: 17px; }
.tag { background: var(--accent); color: #fff; font-size: 11px; padding: 2px 8px; border-radius: 10px; vertical-align: middle; }
header p { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.key-status { font-size: 12.5px; color: var(--muted); }
.key-status .ok { color: var(--green); }
.key-status .bad { color: var(--red); font-weight: 600; }

main {
  display: grid; grid-template-columns: 330px 1fr; gap: 16px;
  padding: 16px 22px; max-width: 1300px; margin: 0 auto;
}
@media (max-width: 900px) { main { grid-template-columns: 1fr; } }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.panel h2 { font-size: 14px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-bottom: 12px; }

fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 14px; }
legend { font-size: 12px; color: var(--accent); padding: 0 6px; font-weight: 600; }
label { display: block; font-size: 12.5px; color: var(--text); margin-bottom: 10px; }
label.row { display: flex; align-items: flex-start; gap: 8px; line-height: 1.4; }
label.row input { margin-top: 2px; }
.hint { color: var(--muted); font-size: 11px; display: block; margin-top: 2px; }
output { float: right; color: var(--accent); font-weight: 600; }
input[type="text"], select {
  width: 100%; margin-top: 4px; padding: 7px 9px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text); font-size: 13px;
}
input[type="range"] { width: 100%; margin-top: 6px; accent-color: var(--accent); }
.hidden { display: none !important; }

.call { display: flex; flex-direction: column; min-height: 78vh; }
.call-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; flex-wrap: wrap; gap: 10px; }
.callee { font-size: 14px; font-weight: 600; }
.timer { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; margin-top: 3px; }

.btn {
  border: none; border-radius: 9px; padding: 10px 20px; font-size: 14px; font-weight: 700;
  cursor: pointer; color: #fff; transition: opacity .15s;
}
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn.start { background: var(--green); }
.btn.end { background: var(--red); margin-left: 8px; }
.btn.small { padding: 8px 14px; font-size: 13px; background: var(--accent); }

.status-bar { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.pill { font-size: 12px; font-weight: 700; padding: 5px 14px; border-radius: 999px; white-space: nowrap; }
.pill.idle      { background: #2a3550; color: var(--muted); }
.pill.speaking  { background: rgba(79,140,255,.18); color: var(--accent); }
.pill.listening { background: rgba(46,204,113,.15); color: var(--green); animation: pulse 1.4s infinite; }
.pill.thinking  { background: rgba(241,196,15,.15); color: var(--amber); }
@keyframes pulse { 50% { opacity: .55; } }

.meter { flex: 1; height: 8px; background: var(--panel-2); border-radius: 4px; overflow: hidden; position: relative; }
#micLevel { height: 100%; width: 0%; background: linear-gradient(90deg, var(--green), var(--amber)); transition: width .08s linear; }
.th-marker { position: absolute; top: 0; left: 0; width: 2px; height: 100%; background: var(--red); opacity: .8; }

.transcript {
  flex: 1; overflow-y: auto; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px; display: flex; flex-direction: column; gap: 10px; min-height: 300px;
}
.placeholder { color: var(--muted); font-size: 13.5px; line-height: 1.6; margin: auto; max-width: 480px; text-align: center; }
.bubble { max-width: 78%; padding: 10px 14px; border-radius: 14px; font-size: 14.5px; line-height: 1.55; }
.bubble .who { display: block; font-size: 10.5px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; margin-bottom: 3px; opacity: .7; }
.bubble.bot  { align-self: flex-start; background: #24304a; border-bottom-left-radius: 4px; }
.bubble.user { align-self: flex-end; background: #2e4a33; border-bottom-right-radius: 4px; }
.bubble.sys  { align-self: center; background: transparent; color: var(--muted); font-size: 12px; padding: 2px; }

.error { margin-top: 10px; background: rgba(231,76,60,.12); border: 1px solid rgba(231,76,60,.4); color: #ff9d92; padding: 10px 14px; border-radius: 9px; font-size: 13px; }

.manual-row { display: flex; gap: 8px; margin-top: 12px; }
.manual-row input { flex: 1; margin-top: 0; }

.history { display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow-y: auto; }
.history-item {
  text-align: left; font-size: 11.5px; padding: 7px 9px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  font-variant-numeric: tabular-nums;
}
.history-item:hover { border-color: var(--accent); background: rgba(79,140,255,.08); }

/* ---------- Latency debug panel ---------- */
.lat-panel { display: flex; flex-direction: column; gap: 8px; max-height: 260px; overflow-y: auto; font-variant-numeric: tabular-nums; }
.lat-row { display: flex; flex-direction: column; gap: 3px; }
.lat-head { font-size: 11.5px; color: var(--text); }
.lat-head .hint { display: inline; font-size: 10.5px; }
.lat-avg { font-size: 11.5px; color: var(--muted); padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.lat-bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--panel-2); }
.lat-seg { display: inline-block; height: 100%; min-width: 2px; }
.lat-legend { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 10.5px; color: var(--muted); margin-bottom: 8px; }
.lat-legend span { display: inline-flex; align-items: center; gap: 4px; }
.lat-legend .lat-seg { width: 10px; height: 8px; border-radius: 2px; }
.lat-wait { background: #6b7280; }
.lat-stt  { background: #4f8cff; }
.lat-llm  { background: #a78bfa; }
.lat-tts  { background: #f59e0b; }
.lat-net  { background: #34d399; }
