:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e3e6eb;
  --text: #16191f;
  --muted: #667085;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --user-bubble: #eef2ff;
  --bot-bubble: #f2f4f7;
  --ok: #16a34a;
  --warn: #d97706;
  --bar: #cbd5e1;
  --overlay: rgb(15 18 24 / 55%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #161a21;
    --border: #262c36;
    --text: #e6e8ec;
    --muted: #8b93a1;
    --accent: #3b82f6;
    --user-bubble: #1c2540;
    --bot-bubble: #1d222b;
    --bar: #334155;
    --overlay: rgb(0 0 0 / 65%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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

.shell { max-width: 1100px; margin: 0 auto; padding: 20px 16px; }

.bar {
  display: flex; flex-wrap: wrap; gap: 12px;
  align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 18px; margin: 0; }
.status { color: var(--muted); font-size: 13px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--bar); }
.dot.live { background: var(--ok); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 20%, transparent); }
.dot.connecting { background: var(--warn); }

.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.field { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 4px; }
select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-width: 190px;
}
.call {
  font: inherit; font-weight: 600; border: 0; border-radius: 8px;
  padding: 9px 18px; background: var(--accent); color: var(--accent-text); cursor: pointer;
}
.call.hangup { background: var(--danger); }
.call.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.call.secondary.active { background: var(--danger); color: #fff; border-color: var(--danger); }
.chat-bar { display: flex; gap: 8px; margin-top: 12px; }
.chat-bar input {
  flex: 1; min-width: 0; font: inherit; color: var(--text); background: var(--bg, var(--surface));
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px;
}
.transcript .decision {
  align-self: flex-start; max-width: 80%; margin-top: -4px; padding: 0 12px; font-size: 12px; color: var(--muted);
  background: none;
}
.transcript .decision summary { cursor: pointer; }
.transcript .decision .agree { color: var(--ok); }
.transcript .decision .disagree { color: var(--warn); }
.transcript .decision pre { white-space: pre-wrap; margin: 6px 0 0; font: inherit; }

.direction { color: var(--muted); font-weight: 400; text-transform: none; letter-spacing: 0; }
#agent { min-width: 18rem; max-width: 100%; }
.contact { margin: -6px 0 14px; font-size: 13px; color: var(--muted); min-height: 1.5em; }

.incoming {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: var(--overlay); padding: 16px; z-index: 10;
}
.incoming[hidden] { display: none; }
.incoming-card {
  width: min(340px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 28px 24px 24px; text-align: center;
  box-shadow: 0 20px 50px rgb(0 0 0 / 25%);
}
.ring-icon {
  display: block; width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 50%;
  background: var(--ok); animation: ring 1.5s ease-out infinite;
}
.ring-icon::after {
  content: ""; display: block; width: 100%; height: 100%; background: var(--accent-text);
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6.6 10.8a15.1 15.1 0 0 0 6.6 6.6l2.2-2.2c.3-.3.7-.4 1-.2 1.1.4 2.3.6 3.6.6.6 0 1 .4 1 1V20c0 .6-.4 1-1 1A17 17 0 0 1 3 4c0-.6.4-1 1-1h3.5c.6 0 1 .4 1 1 0 1.3.2 2.5.6 3.6.1.3 0 .7-.2 1z'/%3E%3C/svg%3E") center / 50% no-repeat;
}
@keyframes ring {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 50%, transparent); }
  100% { box-shadow: 0 0 0 18px transparent; }
}
@media (prefers-reduced-motion: reduce) { .ring-icon { animation: none; } }
.incoming-label { margin: 0; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.incoming-card h2 { margin: 4px 0 6px; font-size: 22px; }
.incoming-detail { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
.incoming-actions { display: flex; justify-content: center; gap: 16px; }
.round {
  font: inherit; font-weight: 600; color: #fff; border: 0; border-radius: 999px;
  padding: 11px 22px; min-width: 110px; cursor: pointer;
}
.round.accept { background: var(--ok); }
.round.decline { background: var(--danger); }
.call:disabled { opacity: .6; cursor: progress; }

.panes { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; }
@media (max-width: 800px) { .panes { grid-template-columns: 1fr; } }

.pane { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.pane-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.pane h2 { font-size: 14px; margin: 0; }
.pane h3 { font-size: 12px; color: var(--muted); margin: 18px 0 6px; font-weight: 600; }
.hint, .speaking { font-size: 12px; color: var(--muted); }

.transcript {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 8px;
  height: 60vh; min-height: 320px; overflow-y: auto;
}
.transcript li { max-width: 80%; padding: 8px 12px; border-radius: 12px; }
.transcript .user { align-self: flex-end; background: var(--user-bubble); }
.transcript .bot { align-self: flex-start; background: var(--bot-bubble); }
.transcript .user.interim { opacity: .6; font-style: italic; }
.transcript .system, .transcript .empty {
  align-self: center; max-width: 100%; color: var(--muted); font-size: 12px; background: none;
}

.latency-now { display: flex; align-items: baseline; gap: 4px; }
.latency-now .value { font-size: 40px; font-weight: 700; font-variant-numeric: tabular-nums; }
.latency-now .unit { color: var(--muted); }
.latency-now .value.good { color: var(--ok); }
.latency-now .value.slow { color: var(--warn); }

.parts, .history { list-style: none; margin: 8px 0 0; padding: 0; font-size: 12px; }
.parts li { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; margin-bottom: 8px; }
.parts .meter { grid-column: 1 / -1; height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.parts .meter span { display: block; height: 100%; background: var(--accent); }
.parts .ms, .history li { font-variant-numeric: tabular-nums; }
.history { max-height: 160px; overflow-y: auto; color: var(--muted); }
.history li { display: flex; justify-content: space-between; padding: 2px 0; }

.section { margin-top: 22px; padding-top: 14px; border-top: 1px solid var(--border); }
.muted { color: var(--muted); font-size: 12px; }
.signals { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; margin: 0; font-size: 13px; }
.signals dt { color: var(--muted); }
.signals dd { margin: 0; font-weight: 600; }
.actions { list-style: none; margin: 0; padding: 0; font-size: 12px; display: flex; flex-direction: column; gap: 6px; }
.actions li code { font-weight: 600; color: var(--text); }
.actions .detail { color: var(--muted); word-break: break-word; }
.summary { font-size: 13px; }
.summary p { margin: 0 0 8px; }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--user-bubble); color: var(--text); margin-right: 6px;
}
