:root {
  --ink: #0d2b3e;
  --ink-soft: #47606f;
  --line: #e2e8ec;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --brand: #0f8a8a;
  --brand-deep: #0b6d6d;
  --brand-tint: #e7f4f4;
  --agent-bubble: #f0f7f7;
  --user-bubble: #0d2b3e;
  --accent-amber: #c47f17;
  --good: #1a8f5a;
  --warn: #c47f17;
  --bad: #c0392b;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(13, 43, 62, .04), 0 8px 30px rgba(13, 43, 62, .06);
  --mono: "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.app { display: flex; flex-direction: column; height: 100vh; max-width: 1180px; margin: 0 auto; }

/* Header */
.header {
  display: flex; align-items: center; gap: 18px;
  padding: 16px 22px; background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--brand), var(--brand-deep));
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 15px;
  box-shadow: 0 2px 8px rgba(15, 138, 138, .35);
}
.brand-name { font-weight: 650; font-size: 15px; letter-spacing: -.01em; }
.brand-sub { font-size: 12px; color: var(--ink-soft); margin-top: 1px; }
.header-spacer { flex: 1; }

.toggle-wrap { display: flex; align-items: center; gap: 9px; font-size: 13px; color: var(--ink-soft); }
.switch { position: relative; width: 42px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; cursor: pointer;
  background: #cbd6dc; border-radius: 999px; transition: .18s;
}
.slider:before {
  content: ""; position: absolute; height: 18px; width: 18px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: .18s; box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.switch input:checked + .slider { background: var(--brand); }
.switch input:checked + .slider:before { transform: translateX(18px); }

/* Body layout */
.body { display: flex; flex: 1; min-height: 0; }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.side {
  width: 300px; border-left: 1px solid var(--line); background: var(--surface);
  display: flex; flex-direction: column; min-height: 0;
}
.side.trace-mode { width: 380px; }

/* Member switcher */
.members { padding: 16px; border-bottom: 1px solid var(--line); }
.side-label { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-soft); font-weight: 600; margin-bottom: 10px; }
.member-card {
  border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; margin-bottom: 8px;
  cursor: pointer; transition: .14s; background: var(--surface);
}
.member-card:hover { border-color: var(--brand); }
.member-card.active { border-color: var(--brand); background: var(--brand-tint); }
.member-top { display: flex; justify-content: space-between; align-items: center; }
.member-name { font-weight: 600; font-size: 14px; }
.member-id { font-size: 11px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.member-state { font-size: 12px; color: var(--ink-soft); margin-top: 4px; line-height: 1.35; }
.meter { margin-top: 9px; }
.meter-row { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-soft); margin-bottom: 3px; }
.bar { height: 6px; background: #eef2f4; border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brand); border-radius: 999px; }

.side-note { padding: 14px 16px; font-size: 12px; color: var(--ink-soft); line-height: 1.5; }

/* Chat */
.transcript { flex: 1; overflow-y: auto; padding: 24px 22px; display: flex; flex-direction: column; gap: 16px; }
.msg { display: flex; gap: 11px; max-width: 82%; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.avatar { width: 30px; height: 30px; border-radius: 8px; flex: none; display: grid; place-items: center; font-size: 13px; font-weight: 600; }
.avatar.mira { background: linear-gradient(135deg, var(--brand), var(--brand-deep)); color: #fff; }
.avatar.member { background: var(--ink); color: #fff; }
.bubble { padding: 12px 15px; border-radius: 14px; font-size: 14.5px; line-height: 1.5; }
.msg.mira .bubble { background: var(--agent-bubble); border-top-left-radius: 4px; }
.msg.user .bubble { background: var(--user-bubble); color: #fff; border-top-right-radius: 4px; }
.bubble.escalation { border: 1px dashed var(--brand); background: #fff; }

.intro { text-align: center; margin: auto; max-width: 440px; color: var(--ink-soft); }
.intro h2 { color: var(--ink); font-weight: 650; font-size: 19px; margin-bottom: 8px; }
.intro p { font-size: 14px; line-height: 1.55; }

.typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.typing span { width: 7px; height: 7px; background: var(--brand); border-radius: 50%; opacity: .4; animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .3; } 30% { opacity: 1; } }

/* Composer */
.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 22px 12px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-soft);
  padding: 7px 12px; border-radius: 999px; font-size: 13px; cursor: pointer; transition: .14s; font-family: inherit;
}
.chip:hover { border-color: var(--brand); color: var(--brand-deep); }

.composer { display: flex; gap: 10px; padding: 14px 22px 20px; border-top: 1px solid var(--line); background: var(--surface); align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; font-family: inherit; font-size: 14.5px; color: var(--ink); max-height: 120px;
  outline: none; transition: .14s; line-height: 1.4;
}
.composer textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-tint); }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  cursor: pointer; display: grid; place-items: center; transition: .14s; flex: none; color: var(--ink-soft);
}
.icon-btn:hover { border-color: var(--brand); color: var(--brand-deep); }
.icon-btn.send { background: var(--brand); border-color: var(--brand); color: #fff; }
.icon-btn.send:hover { background: var(--brand-deep); }
.icon-btn.mic.listening { background: var(--bad); border-color: var(--bad); color: #fff; animation: pulse 1.3s infinite; }
.icon-btn.voice-on { background: var(--brand-tint); border-color: var(--brand); color: var(--brand-deep); }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(192,57,43,.4); } 50% { box-shadow: 0 0 0 7px rgba(192,57,43,0); } }
.icon-btn svg { width: 20px; height: 20px; }

/* Trace panel */
.trace { flex: 1; overflow-y: auto; padding: 16px; font-size: 12.5px; }
.trace-empty { color: var(--ink-soft); line-height: 1.5; padding-top: 6px; }
.trace-block { margin-bottom: 16px; }
.trace-h { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); font-weight: 600; margin-bottom: 7px; display: flex; align-items: center; gap: 6px; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.pill.good { background: #e4f4ec; color: var(--good); }
.pill.warn { background: #fbf0dd; color: var(--warn); }
.pill.info { background: var(--brand-tint); color: var(--brand-deep); }
.trace-card { background: #f8fafb; border: 1px solid var(--line); border-radius: 10px; padding: 10px 11px; margin-bottom: 8px; }
.trace-card code { font-family: var(--mono); font-size: 11.5px; color: var(--ink); }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 2px 0; }
.kv .k { color: var(--ink-soft); }
.kv .v { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.tag-list { display: flex; flex-wrap: wrap; gap: 5px; }
.tag { font-family: var(--mono); font-size: 11px; background: #eef3f5; color: var(--ink-soft); padding: 2px 7px; border-radius: 6px; }
.supervisor-line { display: flex; align-items: flex-start; gap: 8px; line-height: 1.45; }
.kv .v.strong { font-weight: 700; color: var(--ink); }

.meta-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.mbadge { font-family: var(--mono); font-size: 11px; background: #eef3f5; color: var(--ink-soft); padding: 3px 8px; border-radius: 6px; }

.timeline { display: flex; flex-direction: column; gap: 0; }
.tl-row { display: flex; gap: 10px; padding: 7px 0; position: relative; }
.tl-row:not(:last-child) .tl-dot:after { content: ""; position: absolute; left: 4px; top: 16px; bottom: -7px; width: 2px; background: var(--line); }
.tl-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 4px; flex: none; position: relative; background: var(--ink-soft); }
.tl-dot.reason { background: var(--brand); }
.tl-dot.tool { background: var(--accent-amber); }
.tl-dot.ok { background: var(--good); }
.tl-dot.warn { background: var(--warn); }
.tl-body { flex: 1; min-width: 0; }
.tl-title { font-size: 12.5px; font-weight: 600; display: flex; justify-content: space-between; gap: 8px; }
.tl-ms { font-family: var(--mono); font-weight: 400; color: var(--ink-soft); font-size: 11px; }
.tl-sub { font-size: 12px; color: var(--ink-soft); line-height: 1.4; margin-top: 2px; }

.fig-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.fig { font-family: var(--mono); font-size: 11.5px; padding: 2px 8px; border-radius: 6px; font-weight: 600; }
.fig.ok { background: #e4f4ec; color: var(--good); }
.fig.bad { background: #fce8e6; color: var(--bad); }

.guard-row { display: flex; align-items: flex-start; gap: 8px; font-size: 12.5px; color: var(--ink-soft); padding: 4px 0; line-height: 1.4; }
.guard-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--brand); margin-top: 6px; flex: none; }
.trace-card.fired { border-color: var(--warn); background: #fdf6ea; color: var(--ink); margin-top: 8px; }

.plan-pdf-btn { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 11px 13px; border: 1px solid var(--brand); background: var(--brand-tint); color: var(--brand-deep); border-radius: 10px; text-decoration: none; font-weight: 600; font-size: 13.5px; transition: .14s; }
.plan-pdf-btn:hover { background: var(--brand); color: #fff; }
.pdf-arrow { font-size: 14px; }

/* Call mode */
.call-bar { display: none; align-items: center; gap: 14px; padding: 14px 22px 18px; border-top: 1px solid var(--line); background: var(--surface); }
.call-bar.active { display: flex; }
.call-orb { position: relative; width: 54px; height: 54px; border-radius: 50%; border: none; cursor: pointer; background: var(--brand-tint); display: grid; place-items: center; flex: none; }
.call-orb:before { content: ""; position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--brand); opacity: .45; }
.orb-core { width: 18px; height: 18px; border-radius: 50%; background: var(--brand); transition: .2s; }
.call-bar.listening .call-orb { animation: orbPulse 1.5s infinite; }
.call-bar.thinking .orb-core { background: var(--warn); animation: orbBreathe 1s ease-in-out infinite; }
.call-bar.thinking .call-orb:before { border-color: var(--warn); }
.call-bar.speaking .call-orb { animation: orbSpeak .6s ease-in-out infinite; }
.call-bar.speaking .orb-core { background: var(--good); }
.call-bar.speaking .call-orb:before { border-color: var(--good); }
@keyframes orbPulse { 0%,100% { box-shadow: 0 0 0 0 rgba(15,138,138,.4); } 50% { box-shadow: 0 0 0 12px rgba(15,138,138,0); } }
@keyframes orbSpeak { 0%,100% { transform: scale(1); } 50% { transform: scale(1.09); } }
@keyframes orbBreathe { 0%,100% { transform: scale(1); opacity: 1; } 50% { transform: scale(.8); opacity: .6; } }
.call-info { flex: 1; min-width: 0; }
.call-state { font-weight: 650; font-size: 14px; }
.call-transcript { font-size: 13px; color: var(--ink-soft); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.call-end { background: var(--bad); color: #fff; border: none; border-radius: 999px; padding: 10px 18px; font-weight: 600; font-size: 14px; cursor: pointer; font-family: inherit; flex: none; }
.call-end:hover { filter: brightness(.94); }
.icon-btn.call.in-call { background: var(--bad); border-color: var(--bad); color: #fff; }

.credit { padding: 12px 16px; font-size: 12px; color: var(--ink-soft); border-top: 1px solid var(--line); margin-top: auto; }
.credit strong { color: var(--ink); font-weight: 600; }
.intro .byline { margin-top: 14px; font-size: 12px; color: var(--ink-soft); }

@media (max-width: 820px) {
  .side { display: none; }
  .msg { max-width: 92%; }
}
