:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-2: #f7f9fa;
  --border: #e1e6ea;
  --text: #15202b;
  --muted: #5d6b78;
  --brand: #0f6e6a;
  --brand-ink: #ffffff;
  --brand-soft: #e3f2f1;
  --user-bubble: #0f6e6a;
  --user-ink: #ffffff;
  --agent-bubble: #eef1f4;
  --idle: #8a96a3;
  --listening: #1f9d55;
  --thinking: #d68a00;
  --speaking: #3b5bdb;
  --error: #d6336c;
  --end: #d64545;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 4px 16px rgba(16, 24, 40, 0.06);
  --radius: 16px;
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1418;
    --surface: #151d23;
    --surface-2: #1b252c;
    --border: #26323b;
    --text: #e7edf1;
    --muted: #93a2ae;
    --brand: #2bb3a9;
    --brand-ink: #04211f;
    --brand-soft: #123331;
    --user-bubble: #1f8d86;
    --user-ink: #ffffff;
    --agent-bubble: #1f2a32;
    --shadow: none;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 15px;
  line-height: 1.45;
}

h1,
h2 {
  margin: 0;
  letter-spacing: -0.01em;
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--brand);
  display: grid;
  place-items: center;
}

.brand-mark svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: var(--brand-ink);
  stroke-width: 5;
  stroke-linecap: round;
}

.brand-name {
  font-weight: 700;
  font-size: 18px;
}

.brand-tag {
  font-size: 12px;
  font-weight: 600;
  color: var(--brand);
  background: var(--brand-soft);
  padding: 3px 8px;
  border-radius: 999px;
}

.engine {
  font-size: 12px;
  color: var(--muted);
}

/* ---------- Layout ---------- */

.layout {
  flex: 1;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr) minmax(260px, 320px);
  align-items: start;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}

.card h2 {
  font-size: 15px;
  margin-bottom: 14px;
}

/* ---------- Call card ---------- */

.call {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 16px;
}

.call h1 {
  font-size: 22px;
}

.lead {
  margin: -6px 0 0;
  color: var(--muted);
}

.status {
  --c: var(--idle);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--c) 35%, transparent);
  background: color-mix(in srgb, var(--c) 10%, transparent);
  color: var(--c);
  font-weight: 600;
  font-size: 14px;
}

.status[data-state='connecting'],
.status[data-state='thinking'] {
  --c: var(--thinking);
}
.status[data-state='listening'] {
  --c: var(--listening);
}
.status[data-state='speaking'] {
  --c: var(--speaking);
}
.status[data-state='error'] {
  --c: var(--error);
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--c);
}

.status[data-state='listening'] .status-dot,
.status[data-state='speaking'] .status-dot,
.status[data-state='thinking'] .status-dot,
.status[data-state='connecting'] .status-dot {
  animation: pulse 1.2s ease-in-out infinite;
}

.status-timer {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-weight: 500;
  padding-left: 6px;
  border-left: 1px solid var(--border);
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.45;
    transform: scale(0.8);
  }
}

.call-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 220px;
  padding: 16px 28px;
  border: 0;
  border-radius: 999px;
  background: var(--listening);
  color: #fff;
  font: inherit;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--listening) 35%, transparent);
  transition: transform 0.12s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.call-button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.call-button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--brand) 60%, transparent);
  outline-offset: 3px;
}

.call-button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.call-button[data-active='true'] {
  background: var(--end);
  box-shadow: 0 6px 18px color-mix(in srgb, var(--end) 35%, transparent);
}

.call-button[data-active='true'] .icon-phone {
  transform: rotate(135deg);
}

.icon-phone {
  width: 22px;
  height: 22px;
  fill: currentColor;
  transition: transform 0.2s ease;
}

.mic {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 260px;
  font-size: 12px;
  color: var(--muted);
}

.mic-track {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow: hidden;
}

.mic-level {
  --level: 0;
  display: block;
  height: 100%;
  background: var(--listening);
  transform-origin: left;
  transform: scaleX(var(--level));
  transition: transform 60ms linear;
}

.notice {
  margin: 0;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13.5px;
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.notice[data-kind='error'] {
  color: var(--error);
  background: color-mix(in srgb, var(--error) 8%, transparent);
  border-color: color-mix(in srgb, var(--error) 30%, transparent);
}

.notice[data-kind='warn'] {
  color: var(--thinking);
  background: color-mix(in srgb, var(--thinking) 8%, transparent);
  border-color: color-mix(in srgb, var(--thinking) 30%, transparent);
}

.intent {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--brand-soft);
  font-size: 13.5px;
}

.intent-label {
  color: var(--muted);
}

.intent-value {
  font-weight: 700;
  color: var(--brand);
}

.voice {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  text-align: left;
  font-size: 12px;
  color: var(--muted);
}

.voice select {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 8px;
}

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

/* ---------- Transcript ---------- */

.transcript-card {
  display: flex;
  flex-direction: column;
}

.transcript {
  height: min(62vh, 560px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-right: 4px;
}

.transcript-empty {
  margin: auto;
  color: var(--muted);
  font-size: 14px;
}

.msg {
  max-width: 82%;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.msg-who {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
}

.msg-text {
  padding: 10px 14px;
  border-radius: 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg-meta {
  font-size: 11px;
  color: var(--muted);
}

.msg-meta:empty {
  display: none;
}

.msg-user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg-user .msg-text {
  background: var(--user-bubble);
  color: var(--user-ink);
  border-bottom-right-radius: 4px;
}

.msg-agent {
  align-self: flex-start;
}

.msg-agent .msg-text {
  background: var(--agent-bubble);
  border-bottom-left-radius: 4px;
}

.msg-interim .msg-text {
  background: transparent;
  color: var(--muted);
  border: 1px dashed var(--border);
  font-style: italic;
}

.msg-interrupted .unspoken {
  color: var(--muted);
  text-decoration: line-through;
  opacity: 0.7;
}

.msg-system {
  align-self: center;
  max-width: 100%;
}

.msg-system .msg-who {
  display: none;
}

.msg-system .msg-text {
  padding: 2px 10px;
  font-size: 12px;
  color: var(--muted);
  background: transparent;
  text-align: center;
}

/* ---------- Latency ---------- */

.live-badge {
  margin-left: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--listening);
  background: color-mix(in srgb, var(--listening) 12%, transparent);
  padding: 2px 7px;
  border-radius: 999px;
  vertical-align: 1px;
}

.lat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px 10px;
}

.lat-main {
  grid-column: 1 / -1;
}

.lat-label {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
}

.lat-value {
  font-size: 30px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.lat-value.small {
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
}

.breakdown {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.breakdown:empty {
  display: none;
}

.bd-row {
  display: grid;
  grid-template-columns: 102px 1fr 64px;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.bd-bar {
  --w: 0;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(var(--speaking), var(--speaking)) no-repeat left / calc(var(--w) * 100%) 100%, var(--surface-2);
}

.bd-value {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.lat-turns {
  list-style: none;
  margin: 14px 0 0;
  padding: 10px 0 0;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.lat-turns:empty {
  display: none;
}

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

/* ---------- Footer ---------- */

.footer {
  padding: 14px 24px 22px;
  text-align: center;
}

.footer p {
  display: inline-block;
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
}

/* ---------- Responsive ---------- */

@media (max-width: 1080px) {
  .layout {
    grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  }
  .latency {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 16px;
  }
  .topbar {
    padding: 12px 16px;
  }
  .engine {
    display: none;
  }
  .transcript {
    height: 50vh;
  }
}
