:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1c2230;
  --line: #2a313c;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #e20074; /* T-Mobile magenta */
  --ok: #2ea043;
  --warn: #d29922;
  --bad: #f85149;
  --radius: 12px;
}

* { box-sizing: border-box; }

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

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 16px; margin: 0; font-weight: 600; letter-spacing: .2px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }

.chip {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  white-space: nowrap;
}
.chip.ok   { color: #7ee787; border-color: #2ea04355; background: #2ea04315; }
.chip.warn { color: #e3b341; border-color: #d2992255; background: #d2992215; }
.chip.bad  { color: #ff7b72; border-color: #f8514955; background: #f8514915; }
.chip.busy { color: #79c0ff; border-color: #388bfd55; background: #388bfd15; }
.chip.idle { color: var(--muted); }

main {
  max-width: 780px;
  margin: 0 auto;
  padding: 24px 20px 64px;
  display: grid;
  gap: 18px;
}

/* --- call stage --- */

.stage {
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: 34px 20px 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

/* ── Avatar ─────────────────────────────────────────────────────────────────
   The centrepiece. Everything is driven by two things set from JS:

     [data-state]  idle | connecting | listening | speaking
     --level       live audio amplitude, 0..1

   Animating from a CSS custom property rather than rewriting styles per frame
   keeps the work on the compositor. This runs while audio is being scheduled on
   the same thread, so a layout-thrashing avatar would show up as stutter in the
   call itself, not just as a janky graphic.
*/
.avatar-wrap {
  display: grid;
  justify-items: center;
  gap: 6px;
  margin: 4px 0 2px;
}

.avatar {
  --level: 0;
  position: relative;
  width: 168px;
  height: 168px;
  display: grid;
  place-items: center;
}

/* Outer glow. Scales with amplitude, so the agent visibly "speaks". */
.avatar__halo {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(226, 0, 116, .38) 0%, rgba(226, 0, 116, 0) 68%);
  transform: scale(calc(.82 + var(--level) * .5));
  opacity: calc(.28 + var(--level) * .72);
  transition: transform .09s ease-out, opacity .09s ease-out;
}

.avatar__ring {
  position: absolute;
  inset: 12px;
  border-radius: 50%;
  border: 2px solid var(--line);
  transition: border-color .25s ease, transform .09s ease-out;
}

.avatar__face {
  position: relative;
  width: 116px;
  height: 116px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, #1d2430, var(--panel-2));
  border: 1px solid var(--line);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .04);
  transition: border-color .25s ease, box-shadow .25s ease;
}

.avatar__monogram {
  font-size: 34px;
  font-weight: 650;
  letter-spacing: .5px;
  color: var(--text);
}

.avatar__name {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.avatar__status {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  min-height: 18px;
}

/* Idle: no glow at all, so "not on a call" is unambiguous. */
.avatar[data-state="idle"] .avatar__halo { opacity: 0; }

/* Connecting: slow sweep on the ring — progress without a spinner. */
.avatar[data-state="connecting"] .avatar__ring {
  border-color: var(--warn);
  border-top-color: transparent;
  animation: avatar-spin 1.1s linear infinite;
}

/* Listening: calm breathing, tinted by the caller's own mic level. */
.avatar[data-state="listening"] .avatar__ring { border-color: #3b4250; }
.avatar[data-state="listening"] .avatar__face {
  border-color: rgba(46, 160, 67, .45);
  animation: avatar-breathe 3.4s ease-in-out infinite;
}

/* Speaking: magenta, scaled by amplitude. */
.avatar[data-state="speaking"] .avatar__ring { border-color: var(--accent); }
.avatar[data-state="speaking"] .avatar__face {
  border-color: var(--accent);
  box-shadow: 0 0 calc(10px + var(--level) * 26px) rgba(226, 0, 116, .5);
  transform: scale(calc(1 + var(--level) * .045));
  transition: transform .09s ease-out, box-shadow .09s ease-out;
}

@keyframes avatar-spin { to { transform: rotate(360deg); } }
@keyframes avatar-breathe {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.018); }
}

/* Amplitude-reactive scaling is motion. Honour the preference: state still reads
   from colour, which carries the same information without moving anything. */
@media (prefers-reduced-motion: reduce) {
  .avatar__halo,
  .avatar[data-state="speaking"] .avatar__face { transform: none; }
  .avatar[data-state="connecting"] .avatar__ring,
  .avatar[data-state="listening"] .avatar__face { animation: none; }
}

/* ── Business picker ─────────────────────────────────────────────────────── */

.picker {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.picker label {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .08em;
}

.picker select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 15px;
  font-weight: 550;
  min-width: 210px;
  cursor: pointer;
}
.picker select:hover:not(:disabled) { border-color: #3b4250; }
.picker select:disabled { opacity: .55; cursor: not-allowed; }

.mic {
  position: relative;
  width: 108px;
  height: 108px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform .12s ease, background .2s ease, border-color .2s ease;
}
.mic:hover { transform: translateY(-1px); border-color: #3b4250; }
.mic:active { transform: scale(.97); }
.mic svg {
  width: 42px; height: 42px;
  fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
}

/* Live call: magenta, with a breathing ring so it is obvious the mic is open. */
.mic.live {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.mic .pulse { display: none; }
.mic.live .pulse {
  display: block;
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  animation: pulse 1.8s ease-out infinite;
}
@keyframes pulse {
  0%   { transform: scale(1);    opacity: .7; }
  100% { transform: scale(1.28); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .mic.live .pulse { animation: none; opacity: .5; }
}

.hint { margin: 0; color: var(--muted); font-size: 14px; }

.interim {
  margin: 0;
  min-height: 20px;
  color: var(--muted);
  font-style: italic;
  text-align: center;
}

.call-meta {
  display: flex;
  gap: 22px;
  flex-wrap: wrap;
  justify-content: center;
  padding-top: 4px;
}
.call-meta > div { display: grid; gap: 2px; text-align: center; }
.call-meta .k { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.call-meta .v { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

/* --- cards --- */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.card h2 { font-size: 14px; margin: 0; font-weight: 600; }
.card summary { cursor: pointer; list-style: none; }
.card summary::-webkit-details-marker { display: none; }
.card summary h2 { display: inline-block; }
.card summary::after { content: " ▾"; color: var(--muted); }
.card[open] summary::after { content: " ▴"; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row-actions { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.sub { color: var(--muted); font-size: 13px; margin: 6px 0 0; }

/* --- transcript --- */

.transcript {
  margin-top: 12px;
  max-height: 320px;
  overflow-y: auto;
  display: grid;
  gap: 10px;
}
.transcript .empty { color: var(--muted); font-size: 13px; margin: 0; }

.turn { display: grid; gap: 3px; }
.turn .who {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
}
.turn p {
  margin: 0;
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}
.turn.you { justify-items: end; }
.turn.you p { background: #1f2a3a; border-color: #2c3a50; }
.turn.you .who { text-align: right; }

/* --- forms --- */

input[type="text"], select {
  width: 100%;
  padding: 9px 11px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); margin-top: 12px; }
.grid label { display: grid; gap: 5px; font-size: 13px; color: var(--muted); }
.grid small { color: #6e7681; font-size: 11.5px; }

.text-row { display: flex; gap: 10px; margin-top: 12px; }
.text-row input { flex: 1; }

button {
  padding: 9px 15px;
  border-radius: 9px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
button:hover { filter: brightness(1.08); }
button.ghost { background: transparent; color: var(--muted); border-color: var(--line); }
button.ghost:hover { color: var(--text); }

.toggle { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); }
.toggle input { accent-color: var(--accent); }

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: var(--panel-2);
  padding: 1px 5px;
  border-radius: 5px;
}

pre#log {
  margin: 12px 0 0;
  max-height: 240px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 11px;
}
