:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0eee9;
  --text: #1d1d1b;
  --muted: #6b6a66;
  --border: #e2dfd8;
  --accent: #0f6e56;
  --accent-soft: #e2f1ec;
  --danger: #c2352b;
  --warn-bg: #fff4dc;
  --warn-text: #7a5300;
  --agent-bubble: #e9f2ef;
  --patient-bubble: #f1efe9;
  --phone-bg: #15201d;
  --phone-text: #f2f5f4;
  --radius: 12px;
  font-family: "Inter", "Hind Siliguri", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121413; --surface: #1b1e1d; --surface-2: #232726; --text: #e9ecea; --muted: #9aa19e;
    --border: #2e3331; --accent: #3fbf98; --accent-soft: #183a31; --danger: #ef6a5f;
    --warn-bg: #3a2f14; --warn-text: #f3d48a; --agent-bubble: #1f3530; --patient-bubble: #2a2d2b;
    --phone-bg: #0b100e; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121413; --surface: #1b1e1d; --surface-2: #232726; --text: #e9ecea; --muted: #9aa19e;
  --border: #2e3331; --accent: #3fbf98; --accent-soft: #183a31; --danger: #ef6a5f;
  --warn-bg: #3a2f14; --warn-text: #f3d48a; --agent-bubble: #1f3530; --patient-bubble: #2a2d2b;
  --phone-bg: #0b100e; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%; padding: 7px 9px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
}
textarea { font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
label { display: block; margin: 8px 0; color: var(--muted); font-size: 13px; }
label > input, label > select, label > textarea { margin-top: 4px; color: var(--text); }
label.check, label.radio { display: flex; gap: 8px; align-items: center; color: var(--text); }
label.check input, label.radio input { width: auto; margin: 0; }
fieldset { border: 1px solid var(--border); border-radius: 10px; margin: 12px 0; padding: 6px 12px 10px; }
legend { color: var(--muted); font-size: 12px; padding: 0 4px; }
button { cursor: pointer; border: 0; border-radius: 8px; padding: 8px 12px; background: var(--accent); color: #fff; font-weight: 500; }
button.ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
button:disabled { opacity: .5; cursor: default; }
pre { background: var(--surface-2); border-radius: 8px; padding: 10px; overflow: auto; font-size: 12px; max-height: 320px; margin: 0; }
pre.mini { max-height: 160px; margin-top: 8px; }
pre.mini:empty { display: none; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.row.space { justify-content: space-between; align-items: center; }
.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0; }
.tags { display: flex; gap: 4px; flex-wrap: wrap; }
.tags span { font-size: 11px; background: var(--accent-soft); color: var(--accent); border-radius: 99px; padding: 2px 8px; }

.topbar {
  display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; flex-wrap: wrap;
}
.brand { font-weight: 600; }
.brand span { color: var(--muted); font-weight: 400; margin-left: 6px; }
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tabs button { background: transparent; color: var(--muted); }
.tabs button.active { background: var(--accent-soft); color: var(--accent); }
.switch { display: flex; align-items: center; gap: 6px; margin: 0; color: var(--text); }
.switch input { width: auto; }

main { padding: 16px; max-width: 1500px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; min-width: 0; }

.call-grid { display: grid; grid-template-columns: 320px minmax(300px, 380px) 1fr; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .call-grid { grid-template-columns: 1fr 1fr; } .live { grid-column: 1 / -1; } }
@media (max-width: 720px) { .call-grid { grid-template-columns: 1fr; } }

/* ---------- phone ---------- */
.phone-wrap { display: flex; justify-content: center; }
.phone {
  width: 100%; max-width: 360px; min-height: 620px; background: var(--phone-bg); color: var(--phone-text);
  border-radius: 36px; padding: 28px 22px; display: flex; flex-direction: column; align-items: center; gap: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.18);
}
.phone-status { font-size: 13px; opacity: .75; min-height: 18px; text-align: center; }
.caller { text-align: center; }
.avatar { width: 84px; height: 84px; border-radius: 50%; background: #24443b; display: grid; place-items: center; font-size: 36px; margin: 8px auto; }
.caller-name { font-family: "Hind Siliguri", sans-serif; font-size: 20px; font-weight: 600; }
.caller-sub { opacity: .6; font-size: 13px; }
.timer { font-variant-numeric: tabular-nums; opacity: .8; margin-top: 4px; }
.level { width: 70%; height: 4px; background: rgba(255,255,255,.12); border-radius: 4px; overflow: hidden; }
.level div { height: 100%; width: 0; background: #3fbf98; transition: width 80ms linear; }
.captions { font-family: "Hind Siliguri", sans-serif; font-size: 18px; line-height: 1.5; text-align: center; flex: 1; overflow: auto; width: 100%; padding: 4px; }
.captions .who { display: block; font-family: "Inter", sans-serif; font-size: 11px; opacity: .55; margin-top: 8px; }
.agent-state { font-size: 12px; opacity: .6; min-height: 16px; }
.phone-actions { display: flex; gap: 28px; justify-content: center; }
.round { width: 76px; height: 76px; border-radius: 50%; font-weight: 600; font-size: 13px; }
.round.green { background: #1fa971; }
.round.red { background: #d9453b; }
.phone[data-state="ringing"] .avatar { animation: ring 1s infinite; }
@keyframes ring { 0%,100% { transform: scale(1); } 50% { transform: scale(1.08); } }
.ptt { width: 100%; padding: 18px; font-size: 16px; background: #24443b; border-radius: 14px; user-select: none; touch-action: none; }
.ptt.down { background: #1fa971; }
.text-say { display: flex; gap: 6px; width: 100%; }
.text-say input { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.15); color: var(--phone-text); }

/* ---------- live panel ---------- */
.transcript { display: flex; flex-direction: column; gap: 6px; max-height: 420px; overflow: auto; padding-right: 4px; }
.bubble { max-width: 85%; padding: 8px 11px; border-radius: 12px; font-family: "Hind Siliguri", "Inter", sans-serif; font-size: 15px; }
.bubble.Agent { background: var(--agent-bubble); align-self: flex-start; }
.bubble.Patient { background: var(--patient-bubble); align-self: flex-end; }
.bubble.partial { opacity: .6; }
.bubble .meta { display: block; font-family: "Inter", sans-serif; font-size: 11px; color: var(--muted); margin-top: 3px; }
.latency { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.latency span { font-size: 11.5px; background: var(--surface-2); border-radius: 6px; padding: 3px 7px; font-variant-numeric: tabular-nums; }
.latency span.slow { background: var(--warn-bg); color: var(--warn-text); }
.warn { background: var(--warn-bg); color: var(--warn-text); border-radius: 8px; padding: 7px 10px; margin-bottom: 6px; font-size: 12.5px; }
.err { background: var(--danger); color: #fff; border-radius: 8px; padding: 7px 10px; margin-bottom: 6px; font-size: 12.5px; }

.rating .scales { display: grid; gap: 6px; }
.scale { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.scale span { color: var(--text); font-size: 13px; }
.scale .opts { display: flex; gap: 3px; flex-shrink: 0; }
.scale .opts label { margin: 0; }
.scale .opts input { display: none; }
.scale .opts span { display: inline-grid; place-items: center; width: 28px; height: 28px; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; font-size: 12px; }
.scale .opts input:checked + span { background: var(--accent); color: #fff; border-color: var(--accent); }
.checks { margin: 8px 0; }
.saved { margin-left: 8px; color: var(--accent); }

/* ---------- history / dashboard ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
#callDetail { margin-top: 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; }

/* ---------- participant mode ---------- */
body.participant .topbar .tabs, body.participant .setup, body.participant .live { display: none; }
body.participant .call-grid { grid-template-columns: 1fr; }
body.participant main { padding: 8px; }
@media (max-width: 720px) {
  body.participant .phone { border-radius: 0; min-height: calc(100vh - 70px); max-width: none; }
}

dialog { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); }
dialog form { display: grid; gap: 10px; min-width: 260px; }
