:root {
  --bg: #0b0f14;
  --panel: #121820;
  --panel-2: #171f29;
  --line: #223041;
  --text: #e6edf5;
  --muted: #8ba0b8;
  --accent: #3ddc97;
  --accent-dim: #1f6f52;
  --danger: #ff5f61;
  --caller: #4aa8ff;
  --radius: 14px;
}

* { box-sizing: border-box; }

/* Author `display:` beats the UA stylesheet's [hidden]{display:none}, so every
   view rendered at once and the app looked like one long stacked page. This wins. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: radial-gradient(1200px 600px at 20% -10%, #16202c 0%, var(--bg) 60%);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}

/* ── Top bar ─────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 16px 24px; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 16px; font-weight: 600; margin: 0; letter-spacing: .2px; }
.dot {
  width: 9px; height: 9px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}
.badges { display: flex; gap: 8px; flex-wrap: wrap; }
.badge {
  font-size: 12px; color: var(--muted); background: var(--panel);
  border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px;
}
.badge.good { color: var(--accent); border-color: var(--accent-dim); }
.badge.bad { color: var(--danger); border-color: #5b2427; }

/* ── Layout ──────────────────────────────────────────── */
.layout {
  display: grid; gap: 18px; padding: 22px;
  grid-template-columns: 320px minmax(0, 1fr) 300px;
  max-width: 1500px; margin: 0 auto; align-items: start;
}
@media (max-width: 1150px) { .layout { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px;
}
.panel h2 { margin: 0 0 4px; font-size: 14px; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); }
.panel h3 { margin: 22px 0 4px; font-size: 13px; color: var(--text); }
.hint { color: var(--muted); font-size: 12.5px; margin: 4px 0 12px; }

/* ── Form ────────────────────────────────────────────── */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px;
  font: inherit; font-size: 14px; resize: vertical;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-dim); border-color: var(--accent-dim); }
.agent-blurb { font-size: 12.5px; color: var(--muted); background: var(--panel-2);
  border-left: 2px solid var(--accent-dim); padding: 9px 11px; border-radius: 0 8px 8px 0; margin: 0 0 4px; }

/* ── Buttons ─────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 12px 16px; border: 0; border-radius: 11px;
  font: inherit; font-weight: 600; cursor: pointer; transition: filter .15s, opacity .15s;
}
.btn svg { width: 18px; height: 18px; fill: currentColor; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn:not(:disabled):hover { filter: brightness(1.12); }
.btn.call { background: var(--accent); color: #08160f; margin-top: 18px; }
.btn.hangup { background: var(--danger); color: #2a0709; max-width: 190px; }
.btn.ghost { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); width: auto; padding: 9px 16px; }

/* ── Call screen ─────────────────────────────────────── */
.callscreen { display: flex; flex-direction: column; min-height: 640px; }
.callhead { display: flex; align-items: center; gap: 14px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.avatar {
  position: relative; width: 50px; height: 50px; border-radius: 50%;
  background: linear-gradient(145deg, #2b3a4d, #1b2531);
  display: grid; place-items: center; font-weight: 700; font-size: 19px; flex-shrink: 0;
}
.pulse { position: absolute; inset: -5px; border-radius: 50%; border: 2px solid var(--accent); opacity: 0; }
.avatar.speaking .pulse { animation: pulse 1.15s ease-out infinite; }
@keyframes pulse { 0% { opacity: .75; transform: scale(.9); } 100% { opacity: 0; transform: scale(1.28); } }
.callmeta { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }
.callmeta strong { font-size: 15px; }
.status { font-size: 12px; color: var(--muted); }
.status.live { color: var(--accent); }
.status.listening { color: var(--caller); }
.status.error { color: var(--danger); }
.timer { font-variant-numeric: tabular-nums; font-size: 20px; color: var(--muted); }

/* ── Transcript ──────────────────────────────────────── */
.transcript { flex: 1; overflow-y: auto; padding: 16px 2px; display: flex; flex-direction: column; gap: 10px; }
.empty { color: var(--muted); text-align: center; margin: auto 0; font-size: 13.5px; }
.empty b { color: var(--text); }
.line { max-width: 82%; padding: 10px 13px; border-radius: 13px; font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.line.agent { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.line.caller { align-self: flex-end; background: #14304d; border: 1px solid #1e4870; border-bottom-right-radius: 4px; }
.line .who { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-bottom: 3px; }
.line.partial { opacity: .55; font-style: italic; }
.line.system { align-self: center; background: transparent; color: var(--muted); font-size: 12px; max-width: 100%; }
.line.system.err { color: var(--danger); }

/* ── Composer + controls ─────────────────────────────── */
.composer { display: flex; gap: 8px; padding-top: 12px; border-top: 1px solid var(--line); }
.composer input { flex: 1; }
.controls { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-top: 14px; }
.meters { display: flex; align-items: center; gap: 14px; }
.meter { display: flex; align-items: center; gap: 8px; }
.meter label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.bar { width: 90px; height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0%; background: var(--accent); transition: width .08s linear; }
.usage { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ── Activity ────────────────────────────────────────── */
/* ── Codex brain ─────────────────────────────────────── */
.brain { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.brain-empty { color: var(--muted); font-size: 12.5px; font-style: italic; }
.brain .run {
  background: var(--panel-2); border: 1px solid var(--line);
  border-left: 2px solid var(--caller); border-radius: 0 10px 10px 0; padding: 10px 12px; font-size: 12.5px;
}
.brain .run.done { border-left-color: var(--accent); }
.brain .run.failed { border-left-color: var(--danger); }
.brain .run .label { font-weight: 600; word-break: break-word; }
.brain .run .steps { margin-top: 7px; display: flex; flex-direction: column; gap: 4px; }
.brain .run .step {
  color: var(--muted); font-size: 11.5px; display: flex; gap: 6px; align-items: baseline;
}
.brain .run .step .k {
  color: var(--caller); font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 10px; text-transform: uppercase; letter-spacing: .06em; flex-shrink: 0;
}
.brain .run .step .t { word-break: break-word; }
.brain .run .took { color: var(--accent); font-size: 11px; margin-top: 6px; }
.brain .run.running .label::after {
  content: ''; display: inline-block; width: 6px; height: 6px; margin-left: 7px;
  border-radius: 50%; background: var(--caller); animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }

.tools { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.tools li { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 12.5px; }
.tools .name { color: var(--accent); font-weight: 600; font-family: ui-monospace, SFMono-Regular, monospace; }
.tools .args { color: var(--muted); margin-top: 5px; word-break: break-word; font-family: ui-monospace, SFMono-Regular, monospace; font-size: 11.5px; }
.summary { margin-top: 16px; padding: 13px; background: var(--panel-2); border: 1px solid var(--accent-dim); border-radius: 10px; font-size: 12.5px; }
.summary h4 { margin: 0 0 7px; font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--accent); }
.summary dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; margin: 0; }
.summary dt { color: var(--muted); }
.summary dd { margin: 0; }

/* ── Settings panel ──────────────────────────────────── */
.live-badge {
  float: right; font-size: 10px; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--accent); border: 1px solid var(--accent-dim);
  border-radius: 999px; padding: 2px 8px;
}
.setting-note { margin: 5px 0 0; font-size: 11.5px; line-height: 1.45; }
.setting-note.warn { color: #f0b849; }
.setting-note.bad { color: var(--danger); }

input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 4px; padding: 0;
  background: var(--panel-2); border: 0; border-radius: 2px; margin: 8px 0 2px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 15px; height: 15px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: 0;
}
input[type="range"]::-moz-range-thumb {
  width: 15px; height: 15px; border-radius: 50%; background: var(--accent);
  cursor: pointer; border: 0;
}
.field > span b { float: right; color: var(--text); font-variant-numeric: tabular-nums; }

.advanced { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.advanced summary {
  cursor: pointer; font-size: 12px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .07em; user-select: none;
}
.advanced summary:hover { color: var(--text); }
.advanced[open] summary { margin-bottom: 12px; }

/* ── Auth page ───────────────────────────────────────── */
.auth-body { display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 28px;
}
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.auth-brand h1 { font-size: 16px; margin: 0; font-weight: 600; }
.auth-sub { color: var(--muted); font-size: 13px; margin: 0 0 20px; }
.auth-tabs { display: flex; gap: 4px; background: var(--panel-2); border-radius: 10px; padding: 4px; margin-bottom: 20px; }
.auth-tab {
  flex: 1; padding: 8px; border: 0; border-radius: 7px; background: transparent;
  color: var(--muted); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
}
.auth-tab.active { background: var(--panel); color: var(--text); }
.auth-errors {
  list-style: none; margin: 0 0 14px; padding: 10px 12px; font-size: 12.5px;
  background: #2a0e10; border: 1px solid #5b2427; border-radius: 9px; color: #ffb4b5;
}
.auth-errors li + li { margin-top: 4px; }
.auth-foot { color: var(--muted); font-size: 12px; margin: 16px 0 0; text-align: center; line-height: 1.5; }

/* ── Views + tabs ────────────────────────────────────── */
.tabs { display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 4px; }
.tab {
  padding: 7px 16px; border: 0; border-radius: 7px; background: transparent;
  color: var(--muted); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
}
.tab.active { background: var(--panel-2); color: var(--text); }
.tab:hover:not(.active) { color: var(--text); }
.badge.linkish { cursor: pointer; }
.badge.linkish:hover { color: var(--text); }

/* ── Dialer ──────────────────────────────────────────── */
#view-dialer { display: grid; place-items: start center; padding: 22px; }
.dialer { width: 100%; max-width: 380px; }
.dial-display {
  font-size: 24px !important; text-align: center; letter-spacing: .04em;
  font-variant-numeric: tabular-nums; padding: 14px 12px !important;
}
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 18px 0; }
.keypad button {
  aspect-ratio: 1.5; display: grid; place-content: center; gap: 1px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px;
  color: var(--text); cursor: pointer; transition: background .12s;
}
.keypad button:hover { background: #1e2836; }
.keypad button:active { background: var(--accent-dim); }
.keypad b { font-size: 21px; font-weight: 500; }
.keypad i { font-size: 9px; color: var(--muted); font-style: normal; letter-spacing: .12em; }
.keypad .del b { font-size: 17px; }

/* ── History ─────────────────────────────────────────── */
#view-history { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 18px; padding: 22px; max-width: 1500px; margin: 0 auto; align-items: start; }
@media (max-width: 1000px) { #view-history { grid-template-columns: 1fr; } }
.calls { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 70vh; overflow-y: auto; }
.calls li {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 13px; cursor: pointer; transition: border-color .12s;
}
.calls li:hover { border-color: var(--accent-dim); }
.calls li.active { border-color: var(--accent); }
.calls .row1 { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.calls .who { font-weight: 600; font-size: 13.5px; }
.calls .when { font-size: 11px; color: var(--muted); white-space: nowrap; }
.calls .row2 { margin-top: 4px; font-size: 11.5px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }
.calls .dirpill { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--caller); }

.replay { display: flex; flex-direction: column; gap: 9px; max-height: 68vh; overflow-y: auto; padding-right: 4px; }
.replay .ev { font-size: 13px; }
.replay .ev .t { font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 8px; }
.replay .line { max-width: 88%; }
.replay .meta {
  background: var(--panel-2); border: 1px solid var(--line); border-left: 2px solid var(--caller);
  border-radius: 0 9px 9px 0; padding: 8px 11px; font-size: 12px; color: var(--muted);
}
.replay .meta.ok { border-left-color: var(--accent); }
.replay .meta .k {
  font-family: ui-monospace, SFMono-Regular, monospace; font-size: 10px;
  text-transform: uppercase; letter-spacing: .06em; color: var(--caller); margin-right: 7px;
}
.callsum { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 12.5px; margin-bottom: 16px; }
.callsum dt { color: var(--muted); }
.callsum dd { margin: 0; }

/* ── History filters ─────────────────────────────────── */
.filters { margin-bottom: 12px; }
.filter-row { display: flex; gap: 6px; margin-top: 7px; align-items: center; flex-wrap: wrap; }
.filter-row select { flex: 1; min-width: 110px; font-size: 12.5px; padding: 7px 9px; }
.btn.ghost.export { width: auto; padding: 7px 12px; font-size: 12px; text-decoration: none; white-space: nowrap; }
.scope-all { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.scope-all input { width: auto; }

/* ── Admin ───────────────────────────────────────────── */
#view-admin { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1.3fr); gap: 18px; padding: 22px; max-width: 1500px; margin: 0 auto; align-items: start; }
@media (max-width: 1100px) { #view-admin { grid-template-columns: 1fr; } }
.statgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.stat { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.stat b { display: block; font-size: 21px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }

.trend { display: flex; align-items: flex-end; gap: 4px; height: 110px; padding-top: 8px; }
.trend .bar2 { flex: 1; background: var(--accent-dim); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.trend .bar2:hover { background: var(--accent); }
.trend .bar2 em { position: absolute; bottom: -18px; left: 0; right: 0; text-align: center; font-size: 9px; color: var(--muted); font-style: normal; }

.usertable { display: flex; flex-direction: column; gap: 8px; }
.urow { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; }
.urow.off { opacity: .55; }
.urow .top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.urow .em { font-weight: 600; font-size: 13.5px; word-break: break-all; }
.urow .pill { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); }
.urow .facts { font-size: 11.5px; color: var(--muted); margin-top: 4px; display: flex; gap: 12px; flex-wrap: wrap; }
.urow .acts { display: flex; gap: 6px; margin-top: 9px; align-items: center; }
.urow .acts input { width: 78px; padding: 5px 8px; font-size: 12px; }
.urow .acts button { padding: 5px 11px; font-size: 12px; border-radius: 7px; border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer; }
.urow .acts button:hover { border-color: var(--accent-dim); }

/* ── Live call extras ────────────────────────────────── */
.status.phase { color: #f0b849; }
.barge {
  align-self: flex-start; font-size: 10px; font-weight: 700; letter-spacing: .07em;
  text-transform: uppercase; color: #08160f; background: var(--accent);
  border-radius: 999px; padding: 2px 9px; animation: bargein .3s ease-out;
}
@keyframes bargein { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.usage-detail { font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ── Usage meter ─────────────────────────────────────── */
.meterbadge {
  position: relative; display: inline-flex; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 12px; overflow: hidden; min-width: 150px;
}
.mb-fill {
  position: absolute; inset: 0 auto 0 0; background: var(--accent-dim); opacity: .38;
  transition: width .35s ease;
}
.mb-fill.warn { background: #8a6d1f; opacity: .5; }
.mb-fill.danger { background: #7a2b2e; opacity: .6; }
.mb-text { position: relative; font-size: 12px; color: var(--text); white-space: nowrap; }

/* ── Invites ─────────────────────────────────────────── */
.inviteform { display: flex; gap: 6px; margin-bottom: 10px; }
.inviteform input { flex: 1; }
.inviteform .btn { width: auto; padding: 8px 14px; white-space: nowrap; }
.invitelist { display: flex; flex-direction: column; gap: 6px; }
.inviterow {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 9px; padding: 8px 11px; font-size: 12.5px;
}
.inviterow code {
  font-family: ui-monospace, SFMono-Regular, monospace; font-size: 13px;
  letter-spacing: .06em; color: var(--accent);
}
.inviterow.used code, .inviterow.expired code { color: var(--muted); text-decoration: line-through; }
.inviterow .st { color: var(--muted); flex: 1; }
.inviterow button {
  padding: 4px 10px; font-size: 11.5px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
}
.inviterow button:hover { color: var(--danger); border-color: #5b2427; }

/* Shared setup panel: one column in the dialler, part of the grid in Call. */
#view-dialer { grid-template-columns: 320px minmax(0, 380px); justify-content: center; gap: 18px; }
#view-dialer .setup-host { display: contents; }
#view-call .setup-host { display: contents; }
@media (max-width: 860px) { #view-dialer { grid-template-columns: 1fr; } }
.urow .acts button:disabled { opacity: .35; cursor: not-allowed; }
.urow .acts button:disabled:hover { border-color: var(--line); }

/* Twilio settings — a saved-and-verified state worth seeing at a glance. */
.setting-note.good { color: var(--accent); }
.status-dot {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  background: var(--border); vertical-align: middle; margin-left: 6px;
}
.status-dot.ok { background: var(--accent); }
.status-dot.warn { background: var(--danger); }
.status-dot.unknown { background: #b58900; }

/* Per-tool latency — measured, visible, honest. */
.tool-ms {
  float: right; font-size: 11px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.tool-ms.working { color: #b58900; }
.tool-ms.failed { color: var(--danger); }
#tools .result {
  margin-top: 4px; font-size: 11px; color: var(--muted);
  white-space: pre-wrap; word-break: break-word;
}

/* MCP servers + tool list in the admin panel */
.mcprow, .toolrow {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-bottom: 1px solid var(--border);
  font-size: 12.5px;
}
.mcprow code, .toolrow code { color: var(--text); }
.mcprow .meta, .toolrow .src { color: var(--muted); flex: 1; }
.mcprow .btn.tiny { padding: 2px 8px; font-size: 11px; }
.toolrow .pol { font-size: 10.5px; padding: 1px 6px; border-radius: 8px; border: 1px solid var(--border); color: var(--muted); }
.toolrow .pol.privileged { color: #b58900; border-color: #6b5900; }
.toolrow.skills { color: var(--muted); font-size: 11.5px; }
.checkline { display: flex; gap: 8px; align-items: flex-start; margin: 10px 0; font-size: 12.5px; color: var(--muted); }
.checkline input { margin-top: 2px; }

#brain .run.warn { color: #b58900; font-size: 12px; }

/* The device sign-in code. Big and letter-spaced because it is read off one screen and
   typed on another, and O/0 confusion there costs a fifteen-minute round trip. */
.login-code {
  display: inline-block; font-size: 22px; letter-spacing: 3px; font-weight: 600;
  padding: 8px 14px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); user-select: all;
}
