:root {
  --bg: #080a0f;
  --panel: #0f1219;
  --panel-2: #131722;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --text: #e9ecf4;
  --muted: #8791a5;
  --dim: #5c6579;
  --accent: #b6f36a;
  --accent-soft: rgba(182, 243, 106, 0.12);
  --warn: #ffb454;
  --danger: #ff6b6b;
  --sans: ui-sans-serif, -apple-system, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  --radius: 14px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.glow {
  position: fixed;
  inset: -20% 20% auto -20%;
  height: 60vh;
  background: radial-gradient(60% 60% at 30% 20%, rgba(182, 243, 106, 0.10), transparent 70%),
    radial-gradient(50% 50% at 80% 0%, rgba(90, 150, 255, 0.10), transparent 70%);
  filter: blur(20px);
  pointer-events: none;
  z-index: 0;
}

.shell {
  position: relative;
  z-index: 1;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 1500px;
  margin: 0 auto;
  padding: 18px 22px 22px;
  gap: 14px;
}

/* ------------------------------- top bar ------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex: 0 0 auto;
}

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

.mark {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 11px;
  background: var(--accent);
  color: #0a0c11;
  box-shadow: 0 6px 24px rgba(182, 243, 106, 0.22);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 17px; letter-spacing: -0.2px; }
.brand-text span { color: var(--muted); font-size: 12.5px; }

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

.mode {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.02);
}

.mode .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--dim);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.04);
}

.mode.live { color: var(--accent); border-color: rgba(182, 243, 106, 0.28); }
.mode.live .dot { background: var(--accent); animation: pulse 2s infinite; }
.mode.mock { color: var(--warn); border-color: rgba(255, 180, 84, 0.28); }
.mode.mock .dot { background: var(--warn); }
.mode.error { color: var(--danger); border-color: rgba(255, 107, 107, 0.3); }
.mode.error .dot { background: var(--danger); }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(182, 243, 106, 0.35); }
  50% { box-shadow: 0 0 0 5px rgba(182, 243, 106, 0); }
}

.clock {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  min-width: 62px;
  text-align: center;
}

/* -------------------------------- layout -------------------------------- */

.grid {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 372px;
  gap: 14px;
}

.panel {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.022), rgba(255, 255, 255, 0.008));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(6px);
}

.console {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* ------------------------------- console -------------------------------- */

.console-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.who { display: flex; align-items: center; gap: 11px; }

.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft);
  border: 1px solid rgba(182, 243, 106, 0.35);
  color: var(--accent);
  font-weight: 650;
  font-size: 15px;
}

.who div { display: flex; flex-direction: column; line-height: 1.3; }
.who strong { font-size: 14px; font-weight: 600; }
.who span { font-size: 12px; color: var(--muted); }

.models-mini { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.models-mini code {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--dim);
  border: 1px solid var(--line);
  padding: 3px 7px;
  border-radius: 6px;
  white-space: nowrap;
}

.transcript {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 18px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.transcript::-webkit-scrollbar { width: 8px; }
.transcript::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.09); border-radius: 99px; }
.transcript::-webkit-scrollbar-track { background: transparent; }

.empty {
  margin: auto;
  max-width: 560px;
  text-align: center;
  padding: 24px 8px;
  animation: rise 0.4s ease both;
}

.empty h2 { font-size: 20px; margin: 0 0 8px; letter-spacing: -0.3px; }
.empty p { color: var(--muted); font-size: 13.5px; margin: 0 0 20px; }

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

.chip {
  font: inherit;
  font-size: 12.5px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 13px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.chip:hover { color: var(--text); border-color: var(--line-strong); background: rgba(255, 255, 255, 0.06); }

.turn { display: flex; gap: 10px; animation: rise 0.25s ease both; }
.turn .role {
  flex: 0 0 52px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.7px;
  color: var(--dim);
  padding-top: 4px;
  text-transform: uppercase;
}

.turn .text { font-size: 14.5px; }
.turn.caller .text { color: #cfd6e6; }
.turn.agent .text { color: var(--text); }

.turn.agent {
  border-left: 2px solid rgba(182, 243, 106, 0.45);
  padding-left: 10px;
  margin-left: -12px;
}
.turn.agent .role { color: rgba(182, 243, 106, 0.7); }

.caret {
  display: inline-block;
  width: 7px; height: 15px;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: -2px;
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink { 50% { opacity: 0; } }

.thinking { display: flex; align-items: center; gap: 8px; color: var(--dim); font-size: 12.5px; }
.thinking i {
  width: 5px; height: 5px; border-radius: 50%; background: var(--dim);
  animation: bounce 1.2s infinite;
}
.thinking i:nth-child(2) { animation-delay: 0.15s; }
.thinking i:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce { 0%, 60%, 100% { opacity: 0.25; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
@keyframes rise { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

/* ------------------------------- composer ------------------------------- */

.composer {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.18);
}

.composer textarea {
  flex: 1 1 auto;
  resize: none;
  max-height: 132px;
  min-height: 46px;
  padding: 12px 14px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  font: inherit;
  font-size: 14.5px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.composer textarea::placeholder { color: var(--dim); }
.composer textarea:focus {
  border-color: rgba(182, 243, 106, 0.45);
  box-shadow: 0 0 0 3px rgba(182, 243, 106, 0.09);
}

.btn {
  font: inherit;
  font-size: 13.5px;
  font-weight: 550;
  border-radius: 10px;
  padding: 11px 16px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s, background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.38; cursor: not-allowed; }

.btn.primary {
  background: var(--accent);
  color: #0a0c11;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
}
.btn.primary:hover:not(:disabled) { background: #c4ff7f; }

.btn.primary kbd {
  font-family: var(--mono);
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(10, 12, 17, 0.16);
}

.btn.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
}
.btn.ghost:hover:not(:disabled) { color: var(--text); border-color: var(--line-strong); background: rgba(255, 255, 255, 0.04); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  font-size: 12.5px;
  border-radius: 9px;
}
.icon-btn[aria-pressed="false"] { color: var(--dim); opacity: 0.65; }
.icon-btn[aria-pressed="false"] .wave { display: none; }

.mic {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  color: var(--muted);
}
.mic:hover:not(:disabled) { color: var(--text); border-color: var(--line-strong); }
.mic.listening {
  color: var(--danger);
  border-color: rgba(255, 107, 107, 0.45);
  background: rgba(255, 107, 107, 0.1);
  animation: mic-pulse 1.4s infinite;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 107, 107, 0.3); }
  50% { box-shadow: 0 0 0 7px rgba(255, 107, 107, 0); }
}

/* --------------------------------- rail --------------------------------- */

.rail {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
}

.rail::-webkit-scrollbar { width: 7px; }
.rail::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.08); border-radius: 99px; }

.card { padding: 15px 16px; flex: 0 0 auto; }

.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  margin-bottom: 13px;
}
.card-head h3 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--muted);
}

.tag {
  font-family: var(--mono);
  font-size: 10.5px;
  padding: 3px 8px;
  border-radius: 6px;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(182, 243, 106, 0.22);
}
.tag.quiet {
  color: var(--dim);
  background: rgba(255, 255, 255, 0.03);
  border-color: var(--line);
}

.intent-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.intent {
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.4px;
  color: var(--text);
  font-family: var(--mono);
}
.intent.flash { animation: flash 0.5s ease; }
@keyframes flash { 0% { color: var(--accent); } 100% { color: var(--text); } }

.escalate {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.8px;
  color: var(--danger);
  border: 1px solid rgba(255, 107, 107, 0.35);
  background: rgba(255, 107, 107, 0.1);
  padding: 3px 8px;
  border-radius: 6px;
  animation: pulse-red 1.6s infinite;
}
@keyframes pulse-red {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 107, 107, 0.25); }
  50% { box-shadow: 0 0 0 5px rgba(255, 107, 107, 0); }
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin: 14px 0;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 9px 10px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid var(--line);
  min-width: 0;
}
.stat .label { font-size: 10.5px; color: var(--dim); letter-spacing: 0.3px; text-transform: uppercase; }
.stat .value { font-size: 13px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat .value.mono { font-family: var(--mono); font-size: 12px; }

.meter { display: flex; gap: 3px; align-items: center; height: 18px; }
.meter i {
  flex: 1;
  height: 6px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.08);
  transition: background 0.25s;
}
.meter i.on { background: var(--accent); }
.meter[data-level="4"] i.on { background: var(--warn); }
.meter[data-level="5"] i.on { background: var(--danger); }

.next {
  padding: 11px 12px;
  border-radius: 10px;
  background: var(--accent-soft);
  border: 1px solid rgba(182, 243, 106, 0.16);
}
.next .label { font-size: 10.5px; color: rgba(182, 243, 106, 0.75); text-transform: uppercase; letter-spacing: 0.5px; }
.next p { margin: 4px 0 0; font-size: 13.5px; color: #dbe6c8; }

/* routing */

.routing { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }

.routing li {
  display: grid;
  grid-template-columns: 8px 1fr auto auto;
  align-items: center;
  gap: 9px;
  padding: 8px 9px;
  border-radius: 9px;
  transition: background 0.2s;
}
.routing li .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  transition: background 0.2s, box-shadow 0.2s;
}
.routing li div { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.routing li strong { font-size: 12.5px; font-weight: 600; }
.routing li span { font-size: 10.5px; color: var(--dim); }
.routing li code {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--dim);
  max-width: 118px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  direction: rtl;
  text-align: left;
}
.routing li .ms {
  font-family: var(--mono);
  font-size: 10.5px;
  font-style: normal;
  color: var(--dim);
  min-width: 44px;
  text-align: right;
}

.routing li.active { background: rgba(182, 243, 106, 0.06); }
.routing li.active .dot { background: var(--accent); box-shadow: 0 0 0 3px rgba(182, 243, 106, 0.14); }
.routing li.active .ms { color: var(--accent); }
.routing li.speaking .dot { animation: pulse 1.4s infinite; }

/* context */

.context-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.context-list li { border-left: 2px solid var(--line-strong); padding-left: 9px; }
.context-list a { color: #cfd6e6; font-size: 12.5px; text-decoration: none; display: block; }
.context-list a:hover { color: var(--accent); }
.context-list p { margin: 2px 0 0; font-size: 11.5px; color: var(--dim); line-height: 1.45; }

.footnote p { margin: 0; font-size: 11.5px; color: var(--dim); line-height: 1.5; }

/* --------------------------------- modal -------------------------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 10, 0.72);
  backdrop-filter: blur(7px);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 50;
  animation: fade 0.2s ease both;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: min(720px, 100%);
  max-height: 86dvh;
  display: flex;
  flex-direction: column;
  background: #0c0f16;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  animation: rise 0.25s ease both;
}

.modal-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 8px 0 0; font-size: 19px; letter-spacing: -0.3px; }

.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
}
.modal-foot .mono { font-family: var(--mono); font-size: 11px; color: var(--dim); }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > .label { font-size: 10.5px; letter-spacing: 0.5px; text-transform: uppercase; color: var(--dim); }
.field p { margin: 0; font-size: 13.5px; color: #cfd6e6; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.pill-row { display: flex; gap: 7px; flex-wrap: wrap; }
.pill {
  font-family: var(--mono);
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  color: var(--muted);
}
.pill.danger { color: var(--danger); border-color: rgba(255, 107, 107, 0.35); }
.pill.warn { color: var(--warn); border-color: rgba(255, 180, 84, 0.35); }
.pill.ok { color: var(--accent); border-color: rgba(182, 243, 106, 0.3); }

.actions { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.actions li { display: flex; gap: 9px; align-items: baseline; font-size: 13px; color: #cfd6e6; }
.actions li em {
  font-style: normal;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--dim);
  text-transform: uppercase;
  min-width: 74px;
}

.crm-note {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  color: #b9c2d4;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 13px;
  white-space: pre-wrap;
  word-break: break-word;
}

.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13.5px; padding: 22px 0; }

.spinner {
  width: 15px; height: 15px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------- toast -------------------------------- */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #161b26;
  border: 1px solid var(--line-strong);
  color: var(--text);
  font-size: 13px;
  padding: 10px 16px;
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  z-index: 60;
  animation: rise 0.2s ease both;
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ------------------------------ responsive ------------------------------ */

@media (max-width: 1080px) {
  body { overflow: auto; }
  .shell { height: auto; min-height: 100dvh; }
  .grid { grid-template-columns: 1fr; }
  .console { min-height: 62dvh; }
  .rail { overflow: visible; }
}

@media (max-width: 620px) {
  .shell { padding: 12px; }
  .brand-text span { display: none; }
  .models-mini { display: none; }
  .stats { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .composer .btn.primary kbd { display: none; }
}
