/* Monochrome theme in the style of the xAI console: white/black, soft grey surfaces, pill controls. */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f6f5f3;      /* soft warm grey, like xAI's cards */
  --surface-3: #eeedea;
  --border: #ebeae7;
  --border-strong: #d9d8d4;
  --text: #0a0a0a;
  --text-2: #55554f;
  --muted: #8b8a85;
  --accent: #0a0a0a;         /* primary actions are black */
  --accent-ink: #ffffff;
  --series-1: #1f1f1f;
  --focus: rgba(10, 10, 10, .14);
  --good: #137a3c;  --good-bg: #e9f6ee;
  --warn: #8a5a00;  --warn-bg: #fbf2dc;
  --bad: #c4291c;   --bad-bg: #fdecea;
  --info: #0a0a0a;  --info-bg: #efeeeb;
  --live: #1fa34a;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, .14);
  --radius: 16px;
  --radius-sm: 10px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0a0a0a; --surface: #0f0f0f; --surface-2: #171717; --surface-3: #202020;
    --border: #232323; --border-strong: #333333;
    --text: #f5f5f4; --text-2: #b4b3ae; --muted: #85847f;
    --accent: #f5f5f4; --accent-ink: #0a0a0a; --series-1: #e7e6e2; --focus: rgba(255, 255, 255, .16);
    --good: #4cc775; --good-bg: #12261a; --warn: #f0b84a; --warn-bg: #2a2110; --bad: #ff7b72; --bad-bg: #2e1513;
    --info: #f5f5f4; --info-bg: #1f1f1f; --live: #4cc775;
    --shadow: none; --shadow-lg: 0 24px 60px rgba(0, 0, 0, .6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0a0a; --surface: #0f0f0f; --surface-2: #171717; --surface-3: #202020;
  --border: #232323; --border-strong: #333333;
  --text: #f5f5f4; --text-2: #b4b3ae; --muted: #85847f;
  --accent: #f5f5f4; --accent-ink: #0a0a0a; --series-1: #e7e6e2; --focus: rgba(255, 255, 255, .16);
  --good: #4cc775; --good-bg: #12261a; --warn: #f0b84a; --warn-bg: #2a2110; --bad: #ff7b72; --bad-bg: #2e1513;
  --info: #f5f5f4; --info-bg: #1f1f1f; --live: #4cc775;
  --shadow: none; --shadow-lg: 0 24px 60px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; letter-spacing: -0.005em; }
.hidden { display: none !important; }
h1, h2, h3 { margin: 0 0 12px; line-height: 1.25; letter-spacing: -0.015em; font-weight: 600; }
h1 { font-size: 22px; }
h2 { font-size: 20px; margin-top: 4px; }
h3 { font-size: 15px; margin-top: 24px; }
a { color: var(--text); text-underline-offset: 3px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
code { background: var(--surface-2); padding: 2px 6px; border-radius: 6px; word-break: break-all; }
pre { background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px 14px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--bad); min-height: 1em; }
::selection { background: var(--text); color: var(--bg); }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 20px; padding: 12px 28px;
  background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: saturate(1.4) blur(12px); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 10px; white-space: nowrap; letter-spacing: -0.02em; }
.logo { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--text); color: var(--bg); }
.logo svg { width: 15px; height: 15px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { background: none; border: 0; color: var(--text-2); padding: 7px 14px; border-radius: 999px; cursor: pointer; font: inherit; font-weight: 500; white-space: nowrap; transition: background .15s, color .15s; }
.tabs button:hover { color: var(--text); background: var(--surface-2); }
.tabs button.active { background: var(--surface-2); color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.conn { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-2); white-space: nowrap; padding: 5px 11px; border: 1px solid var(--border); border-radius: 999px; }
.conn::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--live); box-shadow: 0 0 0 3px color-mix(in srgb, var(--live) 22%, transparent); }
.conn.off::before { background: var(--bad); box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 22%, transparent); }
.pill { display: inline-block; min-width: 18px; padding: 0 6px; margin-left: 2px; border-radius: 999px; background: var(--text); color: var(--bg); font-size: 11px; font-weight: 600; text-align: center; line-height: 18px; }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }

main { padding: 28px; max-width: 1360px; margin: 0 auto; }
.tab { display: none; animation: fade .18s ease; }
.tab.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }

/* ---------- surfaces & buttons ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.btn { font: inherit; font-weight: 500; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); padding: 8px 16px; border-radius: 999px; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, transform .05s; }
.btn:hover { background: var(--surface-2); }
a.btn { display: inline-block; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 86%, var(--bg)); }
.btn.danger { background: #d0321f; border-color: #d0321f; color: #fff; }
.btn.danger:hover { background: #b82a19; border-color: #b82a19; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.small { padding: 5px 12px; font-size: 12.5px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn:focus-visible, .tabs button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus); }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

/* ---------- stat tiles (like xAI Insights) ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(138px, 1fr)); gap: 12px; margin-bottom: 28px; }
.stat { background: var(--surface-2); border-radius: 14px; padding: 16px 18px; min-height: 104px; }
.stat .label { color: var(--text-2); font-size: 13px; }
.stat .value { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 6px; letter-spacing: -0.03em; }
.stat .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ---------- status badges: icon + label, never colour alone ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; border: 1px solid transparent; }
.badge.completed, .badge.success { background: var(--good-bg); color: var(--good); }
.badge.active, .badge.ringing { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.badge.active > span:first-child { color: var(--live); }
.badge.failed, .badge.dead { background: var(--bad-bg); color: var(--bad); }
.badge.missed, .badge.pending { background: var(--warn-bg); color: var(--warn); }
.badge.neutral { background: var(--surface-2); color: var(--text-2); }

/* ---------- live calls ---------- */
.live-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.live-card { display: flex; flex-direction: column; gap: 12px; }
.live-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.live-num { font-weight: 600; font-size: 17px; letter-spacing: -0.02em; }
.timer { font-size: 34px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.04em; }
.timer.near { color: var(--warn); }
.timer.over { color: var(--bad); }
.limitbar { height: 4px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.limitbar > div { height: 100%; background: var(--text); border-radius: 999px; transition: width .9s linear; }
.limitbar > div.near { background: var(--warn); }
.limitbar > div.over { background: var(--bad); }
.mini-transcript { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; font-size: 13px; max-height: 160px; overflow-y: auto; }
.mini-transcript p { margin: 3px 0; }
.who { font-weight: 600; color: var(--text); }
.empty { padding: 56px 20px; text-align: center; color: var(--muted); background: var(--surface-2); border-radius: var(--radius); }

/* ---------- forms ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 8px 12px; transition: border-color .15s, box-shadow .15s; }
input:hover, select:hover, textarea:hover { border-color: color-mix(in srgb, var(--text) 30%, var(--border-strong)); }
input::placeholder, textarea::placeholder { color: var(--muted); }
select { appearance: none; padding-right: 32px; background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%); background-position: calc(100% - 16px) 52%, calc(100% - 11px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }
.filters input, .filters select { border-radius: 999px; background-color: var(--surface-2); border-color: transparent; }
.filters input:hover, .filters select:hover { border-color: var(--border-strong); }
input[type="search"] { min-width: 260px; }
textarea { width: 100%; resize: vertical; font-family: inherit; line-height: 1.5; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: 12.5px; font-weight: 500; color: var(--muted); white-space: nowrap; background: transparent; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .12s; }
.table tbody tr.click { cursor: pointer; }
.table tbody tr.click:hover { background: var(--surface-2); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.clip { max-width: 400px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; }

/* ---------- drawers (call detail, agent editor) ---------- */
.drawer { position: fixed; inset: 0; z-index: 50; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .28); backdrop-filter: blur(2px); animation: fade .15s ease; }
.drawer-panel { position: absolute; right: 10px; top: 10px; bottom: 10px; width: min(700px, calc(100% - 20px)); background: var(--surface); border: 1px solid var(--border); border-radius: 20px; overflow-y: auto; padding: 28px; box-shadow: var(--shadow-lg); animation: slide .2s ease; }
.drawer-panel.wide { width: min(880px, calc(100% - 20px)); }
@keyframes slide { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer-close { position: absolute; right: 18px; top: 18px; }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 10px 16px; margin: 18px 0; padding: 16px 18px; background: var(--surface-2); border-radius: 14px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; word-break: break-word; }
.transcript { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.turn { max-width: 82%; padding: 10px 14px; border-radius: 16px; background: var(--surface-2); }
.turn.assistant { align-self: flex-start; border-bottom-left-radius: 6px; }
.turn.user { align-self: flex-end; background: var(--text); color: var(--bg); border-bottom-right-radius: 6px; }
.turn.user .t { color: color-mix(in srgb, var(--bg) 65%, transparent); }
.turn.system, .turn.dtmf, .turn.tool { align-self: center; background: transparent; color: var(--muted); font-size: 12px; text-align: center; max-width: 90%; padding: 2px 10px; }
.turn.tool { font-family: var(--mono); font-size: 11.5px; }
.turn .t { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.summary-box { background: var(--surface-2); border-radius: 14px; padding: 16px 18px; margin-top: 14px; }
.summary-box ul { margin: 8px 0 0; padding-left: 18px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0; }

/* ---------- agents ---------- */
.agent-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.agent-card { display: flex; flex-direction: column; }
.agent-card h3 { margin: 0 0 4px; font-size: 17px; }
.agent-card .actions { margin-top: auto; padding-top: 6px; }
.agent-meta { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; margin: 14px 0; }
.agent-meta span:nth-child(odd) { color: var(--muted); }

form.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
form.grid .full { grid-column: 1 / -1; }
form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; color: var(--text); }
form label .hint { font-weight: 400; }
form label input, form label select, form label textarea { color: var(--text); font-weight: 400; }
form label.check { flex-direction: row; align-items: center; gap: 4px 10px; font-weight: 500; flex-wrap: wrap; }
form label.check .hint { flex-basis: 100%; padding-left: 46px; }
form label.check .btn { margin-left: auto; }
/* Sections instead of boxes, like the xAI editor */
fieldset { border: 0; border-top: 1px solid var(--border); border-radius: 0; margin: 10px 0 0; padding: 26px 0 6px; grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; min-width: 0; }
fieldset legend { float: left; width: 100%; grid-column: 1 / -1; font-size: 16px; font-weight: 600; letter-spacing: -0.015em; padding: 0; margin-bottom: 2px; }
.hint { font-size: 12px; color: var(--muted); font-weight: 400; }

/* Toggle switches for checkboxes (xAI style) */
input[type="checkbox"] { appearance: none; -webkit-appearance: none; flex: none; width: 36px; height: 20px; padding: 0; margin: 0; border-radius: 999px; border: 0; background: var(--surface-3); position: relative; cursor: pointer; transition: background .18s; }
input[type="checkbox"]::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: transform .18s; }
input[type="checkbox"]:checked { background: var(--text); }
input[type="checkbox"]:checked::after { transform: translateX(16px); background: var(--bg); }
:root[data-theme="dark"] input[type="checkbox"]:not(:checked)::after { background: #8b8a85; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) input[type="checkbox"]:not(:checked)::after { background: #8b8a85; } }

/* ---------- chart ---------- */
.chart-card { margin-bottom: 8px; }
.chart-card h3 { margin-top: 0; }
.chart { position: relative; height: 230px; display: flex; align-items: flex-end; gap: 3px; padding: 8px 0 24px 44px; }
.chart .axis { position: absolute; left: 0; top: 8px; bottom: 24px; width: 36px; display: flex; flex-direction: column; justify-content: space-between; font-size: 11px; color: var(--muted); text-align: right; }
.chart .grid { position: absolute; left: 44px; right: 0; top: 8px; bottom: 24px; display: flex; flex-direction: column; justify-content: space-between; pointer-events: none; }
.chart .grid div { border-top: 1px dashed var(--border); }
.chart .col { position: relative; flex: 1; height: 100%; display: flex; align-items: flex-end; justify-content: center; }
.chart .bar { width: 100%; max-width: 26px; background: var(--series-1); border-radius: 4px 4px 0 0; }
.chart .col:hover .bar { opacity: .75; }
.chart .xl { position: absolute; bottom: -22px; font-size: 11px; color: var(--muted); white-space: nowrap; }
.chart .tip { position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 7px 10px; border-radius: 10px; font-size: 12px; white-space: nowrap; pointer-events: none; display: none; z-index: 2; }
.chart .col:hover .tip { display: block; }

/* ---------- setup & misc ---------- */
.steps { display: grid; gap: 14px; }
.steps .card h3 { margin-top: 0; }
.copy { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 4px 0; }
.alert { padding: 14px 18px; border-radius: 14px; margin-bottom: 16px; border: 1px solid transparent; }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.bad { background: var(--bad-bg); color: var(--bad); }
.alert.info { background: var(--surface-2); color: var(--text); }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; z-index: 100; box-shadow: var(--shadow-lg); max-width: calc(100% - 32px); font-weight: 500; }
.tool-row { border: 1px solid var(--border); background: var(--surface-2); border-radius: 14px; padding: 14px 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; grid-column: 1 / -1; }
.tool-row .full { grid-column: 1 / -1; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--surface-2); }
.login-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 32px; border-radius: 22px; }
.login-card h1 { margin: 6px 0 0; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; }
.login-card .btn { padding: 10px; }

@media (max-width: 720px) {
  main { padding: 16px; }
  .topbar { padding: 10px 16px; gap: 10px; }
  .tabs { order: 3; flex-basis: 100%; }
  form.grid, fieldset, .tool-row { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
  .live-grid, .agent-list { grid-template-columns: 1fr; }
  input[type="search"] { min-width: 0; flex: 1; }
  .drawer-panel, .drawer-panel.wide { right: 0; top: 0; bottom: 0; width: 100%; border-radius: 0; padding: 20px 16px; }
  .timer { font-size: 30px; }
}

/* segmented radio control (e.g. web search: Any site / Only these / Exclude) */
.seg-control { display: inline-flex; background: var(--surface-3); border-radius: 999px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg-control label { display: inline-flex; cursor: pointer; font-weight: 500; }
.seg-control input { position: absolute; opacity: 0; pointer-events: none; }
.seg-control span { padding: 6px 16px; border-radius: 999px; color: var(--text-2); font-size: 13px; }
.seg-control input:checked + span { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.seg-control input:focus-visible + span { box-shadow: 0 0 0 3px var(--focus); }

/* tags & comments */
.tag-row { display: flex; gap: 6px; flex-wrap: wrap; }
.tag-chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-size: 12px; font-weight: 500; }
.tag-chip button { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0 0 0 2px; font-size: 11px; }
.tag-chip button:hover { color: var(--text); }
.comments { display: grid; gap: 8px; }
.comment { background: var(--surface-2); border-radius: 12px; padding: 10px 14px; }

/* enquiries */
.enquiry-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 14px; padding: 12px 16px; border-radius: 14px; background: var(--warn-bg); }
.enquiry-bar.done { background: var(--good-bg); }
.trail-event { font-size: 12px; color: var(--muted); padding: 2px 4px; }
.comment.hidden-comment { opacity: .6; border: 1px dashed var(--border-strong); }
.seg-control b { font-weight: 600; margin-left: 4px; color: var(--muted); }
