/* Hosted Network brand: Rubik, purple + lavender palette, headings in the
   main text colour, purple small-caps labels. No gradients, shadows or emoji.
   Dark is the default theme; the dark palette is built from the brand purples.
   Logo rule: white logo on dark, colour logo on light. */
@font-face { font-family: Rubik; src: url(fonts/Rubik-Regular.ttf) format('truetype'); font-weight: 400; font-display: swap; }
@font-face { font-family: Rubik; src: url(fonts/Rubik-Medium.ttf) format('truetype'); font-weight: 500; font-display: swap; }
@font-face { font-family: Rubik; src: url(fonts/Rubik-Bold.ttf) format('truetype'); font-weight: 700; font-display: swap; }

/* ---------- Theme tokens ---------- */
:root, :root[data-theme="dark"] {
  --bg: #120818;
  --surface: #1B0F22;
  --surface-2: #24152D;
  --line: #3A2745;
  --line-strong: #56386A;
  --text: #F3ECF6;
  --text-soft: rgb(243 236 246 / 0.64);
  --label: #CDAEDD;            /* small-caps labels, links */
  --primary: #5D1A78;          /* buttons, active chips */
  --primary-hover: #6E2A8B;
  --primary-ink: #FFFFFF;
  --focus: rgb(205 174 221 / 0.28);
  --bubble-agent: #2A1834;
  --bubble-caller: transparent;
  --code-bg: #2A1834;
  --danger: #E63312;
  --pill: rgb(93 26 120 / 0.5);      --pill-ink: #E6D9EC;
  --pill-green: rgb(31 107 58 / 0.32); --pill-green-ink: #8FDCA8;
  --pill-amber: rgb(163 107 0 / 0.3);  --pill-amber-ink: #F2C76E;
  --pill-red: rgb(160 41 34 / 0.38);   --pill-red-ink: #F7A8A1;
  --pill-grey: #24152D;                --pill-grey-ink: rgb(243 236 246 / 0.64);
  --dot-listen: #8FDCA8; --dot-caller: #CDAEDD; --dot-agent: #F2C76E;
  --urg-critical: #E63312;
  --bar: #B27ACF;              /* chart bars; validated against --surface */
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #FAF7FB;
  --surface: #FFFFFF;
  --surface-2: #FFFFFF;
  --line: #E6D9EC;
  --line-strong: #5D1A78;
  --text: #1A1A1A;
  --text-soft: rgb(26 26 26 / 0.62);
  --label: #5D1A78;
  --primary: #42025D;
  --primary-hover: #53036D;
  --primary-ink: #FFFFFF;
  --focus: #F3ECF6;
  --bubble-agent: #F3ECF6;
  --bubble-caller: #FFFFFF;
  --code-bg: #F3ECF6;
  --danger: #E63312;
  --pill: #F3ECF6;       --pill-ink: #5D1A78;
  --pill-green: #E3F1E9; --pill-green-ink: #1F6B3A;
  --pill-amber: #FFF2D6; --pill-amber-ink: #A36B00;
  --pill-red: #FAC3C2;   --pill-red-ink: #A02922;
  --pill-grey: #FAF7FB;  --pill-grey-ink: rgb(26 26 26 / 0.62);
  --dot-listen: #1F6B3A; --dot-caller: #5D1A78; --dot-agent: #A36B00;
  --bar: #8A3FAD;
  color-scheme: light;
}
:root { --radius: 8px; }
.logo.logo-light { display: none; }
:root[data-theme="light"] .logo.logo-light { display: block; }
:root[data-theme="light"] .logo.logo-dark { display: none; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 400 14px/1.5 Rubik, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
h2 { font-size: 22px; font-weight: 700; margin: 0 0 6px; letter-spacing: -0.01em; }
h3 { font-size: 17px; font-weight: 700; margin: 0; }
code, .mono { font-family: ui-monospace, "Cascadia Code", Menlo, Consolas, monospace; font-size: 12.5px; }
code { background: var(--code-bg); color: var(--label); padding: 1px 5px; border-radius: 3px; }
a { color: var(--label); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.hidden { display: none !important; }

.eyebrow {
  font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--label); margin-bottom: 8px;
}
.lede { color: var(--text-soft); margin: 0 0 24px; max-width: 70ch; }
.hint { color: var(--text-soft); font-size: 12.5px; margin: 6px 0 0; }
.hint.top { margin: -2px 0 10px; }
.muted { color: var(--text-soft); }
.section { margin-top: 28px; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 16px; min-width: 0; flex-wrap: wrap; }
.logo { height: 26px; width: auto; display: block; }
.divider { width: 1px; height: 30px; background: var(--line); }
.product { display: flex; flex-direction: column; line-height: 1.2; }
.product .eyebrow { margin: 0 0 2px; font-size: 10px; }
.product-name { font-weight: 700; font-size: 15px; }
.views { display: flex; gap: 4px; margin-left: 12px; }
.views a {
  text-decoration: none; color: var(--text-soft); font-weight: 500; padding: 7px 12px; border-radius: 6px;
}
.views a:hover { color: var(--text); }
.views a.active { color: var(--text); background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line); }
.top-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
@media (max-width: 760px) {
  .topbar { padding: 10px 16px; position: static; }
  .divider, .product { display: none; }
  .views { margin-left: 0; }
}

/* ---------- Layout ---------- */
.layout {
  display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(360px, 1fr); gap: 20px;
  padding: 20px 24px; max-width: 1640px; margin: 0 auto; align-items: start;
}
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); min-width: 0; }
.settings { padding: 0 24px 28px; }
.calls {
  display: flex; flex-direction: column; position: sticky; top: 80px;
  height: calc(100vh - 100px); min-height: 520px; overflow: hidden;
}
@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .calls { position: static; height: 80vh; }
  .settings { padding: 0 16px 24px; }
}

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 0 -24px 24px; padding: 0 16px; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; }
.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px;
  padding: 16px 12px 13px; color: var(--text-soft); cursor: pointer; font: inherit; font-weight: 500; white-space: nowrap;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--label); border-bottom-color: var(--label); }
@media (max-width: 1100px) { .tabs { margin: 0 -16px 20px; padding: 0 8px; } }

/* ---------- Forms ---------- */
label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 500; color: var(--text); }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; width: 100%; min-width: 0;
}
input::placeholder, textarea::placeholder { color: var(--text-soft); opacity: 0.75; }
select.auto { width: auto; }
textarea { resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--label); box-shadow: 0 0 0 3px var(--focus); }
input:disabled { opacity: 0.6; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 760px) { .grid4, .grid3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 480px) { .grid4, .grid3, .grid2 { grid-template-columns: 1fr; } }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-weight: 500; cursor: pointer; border-radius: 6px; padding: 8px 14px; text-decoration: none;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--label); white-space: nowrap; display: inline-block;
}
.btn:hover { border-color: var(--label); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #FFFFFF; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 12.5px; }
.btn.link { border: 0; background: none; padding: 4px 6px; color: var(--text-soft); }
.btn.link:hover { color: var(--pill-red-ink); }
#saveBtn.clean { background: transparent; color: var(--text-soft); border-color: var(--line); }

/* ---------- Toggle ---------- */
.toggle { flex-direction: row; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle .track { width: 34px; height: 20px; border-radius: 10px; background: var(--line); position: relative; flex: none; transition: background .15s; }
.toggle .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #FFFFFF; transition: transform .15s; }
.toggle input:checked + .track { background: var(--primary); }
.toggle input:checked + .track::after { transform: translateX(14px); }
.toggle input:focus-visible + .track { box-shadow: 0 0 0 3px var(--focus); }

/* ---------- Pills ---------- */
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill {
  display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  padding: 3px 7px; border-radius: 3px; white-space: nowrap; background: var(--pill); color: var(--pill-ink); line-height: 1.3;
}
.pill.green { background: var(--pill-green); color: var(--pill-green-ink); }
.pill.amber { background: var(--pill-amber); color: var(--pill-amber-ink); }
.pill.red { background: var(--pill-red); color: var(--pill-red-ink); }
.pill.grey { background: var(--pill-grey); color: var(--pill-grey-ink); box-shadow: inset 0 0 0 1px var(--line); }

/* ---------- Tables ---------- */
table.rows { width: 100%; border-collapse: collapse; margin-bottom: 10px; table-layout: fixed; }
table.rows th {
  text-align: left; font-size: 10.5px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--label); padding: 0 4px 6px;
}
table.rows td { padding: 3px 4px; }
table.rows td:last-child, table.rows th:last-child { width: 72px; text-align: right; }
#categories th:nth-child(1) { width: 18%; }
#categories th:nth-child(2) { width: 24%; }
#contacts th:nth-child(1) { width: 20%; }

/* ---------- Chips (multi-select) ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { flex-direction: row; font-weight: 400; }
.chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chip span {
  border: 1px solid var(--line); border-radius: 99px; padding: 4px 11px; font-size: 12.5px;
  cursor: pointer; user-select: none; background: var(--surface-2); color: var(--text);
}
.chip span:hover { border-color: var(--label); }
.chip input:checked + span { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.chip input:focus-visible + span { box-shadow: 0 0 0 3px var(--focus); }

/* ---------- Routing rules ---------- */
.rule { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.rule-name { font-weight: 700; border-color: transparent; background: transparent; padding-left: 0; font-size: 15px; }
.rule-name:hover { border-color: var(--line); padding-left: 10px; }
.rule-name:focus { padding-left: 10px; }
.rule-grid { display: grid; grid-template-columns: 100px 1fr; gap: 10px 12px; align-items: start; margin-top: 10px; }
.rule-grid .eyebrow { margin: 5px 0 0; font-size: 10px; }
@media (max-width: 600px) { .rule-grid { grid-template-columns: 1fr; gap: 6px; } }
#previewResult { font-size: 13px; }

/* ---------- Destinations ---------- */
.dest-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.dest-card.off { opacity: 0.7; }
.dest-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.dest-top .eyebrow { margin: 0; min-width: 76px; }
.dest-top .dest-name { flex: 1; min-width: 160px; font-weight: 700; }
.dest-actions { display: flex; gap: 6px; align-items: center; margin-left: auto; }
.dest-card .grid2 { margin-top: 12px; }
.grid2 > label:only-child { grid-column: 1 / -1; }
.dest-card .hint { margin-top: 10px; }
.add-dest { margin-top: 4px; }

/* ---------- Connect (numbered steps) ---------- */
.steps { list-style: none; padding: 0; margin: 0; counter-reset: step; }
.steps li { display: grid; grid-template-columns: 34px 1fr; gap: 14px; margin-bottom: 14px; position: relative; }
.steps li::before {
  counter-increment: step; content: counter(step);
  width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--label); color: var(--label);
  font-weight: 700; display: grid; place-items: center; background: var(--surface); position: relative; z-index: 1;
}
.steps li:not(:last-child)::after { content: ""; position: absolute; left: 16px; top: 34px; bottom: -14px; width: 2px; background: var(--label); }
.step-box { border: 1px solid var(--line); border-radius: 6px; padding: 12px 14px; min-width: 0; }
.step-box b { display: block; margin-bottom: 4px; }
.step-box p { margin: 0 0 6px; }
.copy { display: flex; gap: 6px; align-items: center; margin: 8px 0 4px; }
.copy code { flex: 1; min-width: 0; overflow-x: auto; white-space: nowrap; padding: 8px 10px; border-radius: 6px; font-size: 12.5px; }
.callout { background: var(--bubble-agent); border-left: 3px solid var(--label); padding: 12px 14px; border-radius: 0 6px 6px 0; margin: 0 0 24px; }
details.alt { margin-top: 28px; border-top: 1px solid var(--line); padding-top: 18px; }
details.alt summary { cursor: pointer; font-weight: 700; font-size: 15px; }

/* ---------- Live calls panel ---------- */
.test { padding: 18px 20px 14px; border-bottom: 1px solid var(--line); }
.test-row { display: flex; gap: 10px; align-items: flex-end; }
.test-row .btn { min-width: 138px; }
.test-status { height: 22px; margin-top: 8px; display: flex; align-items: center; }
.test-status .hint { margin: 0; }
.call-head { padding: 14px 20px 12px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.call-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-height: 22px; font-size: 13px; }
.call-meta .cid { font-weight: 700; font-size: 15px; letter-spacing: 0.02em; }
.call-meta .eyebrow { margin: 0; font-size: 10px; }
.call-meta .sep { width: 1px; height: 14px; background: var(--line); }
.speaking { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-soft); min-width: 118px; }
.speaking::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.speaking.is-listening::before { background: var(--dot-listen); }
.speaking.is-caller::before { background: var(--dot-caller); }
.speaking.is-agent::before { background: var(--dot-agent); }

.transcript { flex: 1; min-height: 0; overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 10px; }
.transcript > * { flex: none; }
.empty { color: var(--text-soft); text-align: center; margin: auto; max-width: 320px; padding: 24px; }
.msg { max-width: 82%; padding: 9px 13px; border-radius: 10px; overflow-wrap: anywhere; }
.msg .who { display: block; font-size: 10px; font-weight: 500; letter-spacing: 0.12em; text-transform: uppercase; color: var(--label); margin-bottom: 2px; }
.msg.agent { background: var(--bubble-agent); align-self: flex-start; border-top-left-radius: 3px; }
.msg.caller { background: var(--bubble-caller); border: 1px solid var(--line); align-self: flex-end; border-top-right-radius: 3px; }
.msg.partial .text { color: var(--text-soft); }
.msg .typing { color: var(--text-soft); font-style: italic; }
.note-line { align-self: center; font-size: 12px; color: var(--text-soft); text-align: center; }
.note-line.err { color: var(--pill-red-ink); }
.ticket { background: var(--bubble-agent); border-radius: var(--radius); padding: 14px 16px; border-left: 3px solid var(--label); }
.ticket.urg-critical { border-left-color: var(--urg-critical); }
.ticket .t-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.ticket .t-title { font-weight: 700; font-size: 15px; margin: 2px 0 10px; }
.ticket p { margin: 0; font-size: 13px; white-space: pre-wrap; }
.sent { display: flex; flex-direction: column; gap: 5px; font-size: 13px; }
.sent div { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
dl.kv { display: grid; grid-template-columns: 96px 1fr; gap: 4px 12px; margin: 0 0 10px; font-size: 13px; }
dl.kv dt { color: var(--label); font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.1em; padding-top: 2px; }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }

.composer { display: flex; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--line); }
.composer input { flex: 1; }

/* ---------- History ---------- */
#view-history { padding: 20px 24px; max-width: 1640px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.filters { padding: 16px 18px; }
.filter-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.filter-row label { min-width: 120px; }
.filter-row .search { min-width: 240px; flex: 2; }
.filter-actions { display: flex; gap: 6px; margin-left: auto; }
.history { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 16px; align-items: start; }
.history-list { display: flex; flex-direction: column; max-height: calc(100vh - 230px); min-height: 360px; }
.list-head { padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.h-rows { overflow-y: auto; flex: 1; }
.h-row {
  display: grid; grid-template-columns: 92px minmax(0, 1fr) auto; gap: 4px 14px; padding: 12px 16px;
  border-bottom: 1px solid var(--line); cursor: pointer; text-decoration: none; color: inherit;
}
.h-row:hover { background: var(--surface-2); }
.h-row.active { background: var(--bubble-agent); box-shadow: inset 3px 0 0 var(--label); }
.h-when { font-size: 12.5px; color: var(--text-soft); line-height: 1.35; }
.h-when b { display: block; color: var(--text); font-weight: 500; }
.h-main { min-width: 0; }
.h-who { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.h-who .muted { font-weight: 400; }
.h-sum { font-size: 13px; color: var(--text-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.h-tags { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.more { margin: 12px auto; }

.history-detail { padding: 22px 24px; max-height: calc(100vh - 230px); min-height: 360px; overflow-y: auto; }
.d-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 18px; }
.d-head h2 { margin: 0 0 2px; }
.d-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.d-section { margin-top: 26px; }
.d-section > .eyebrow { margin-bottom: 10px; }
.d-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 18px; }
.d-grid div { min-width: 0; }
.d-grid .eyebrow { font-size: 10px; margin-bottom: 2px; }
.d-grid span { overflow-wrap: anywhere; }
.d-transcript { display: flex; flex-direction: column; gap: 10px; }
.results { border: 1px solid var(--line); border-radius: var(--radius); }
.results > div { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); align-items: center; }
.results > div:last-child { border-bottom: 0; }
.results small { grid-column: 1 / -1; color: var(--text-soft); }
.link-list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius); }
.link-list a { display: flex; justify-content: space-between; gap: 12px; padding: 9px 14px; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--text); }
.link-list a:last-child { border-bottom: 0; }
.link-list a:hover { background: var(--surface-2); }
.link-list .muted { font-size: 12.5px; white-space: nowrap; }
.log { font-size: 12px; font-family: ui-monospace, Menlo, Consolas, monospace; color: var(--text-soft); display: flex; flex-direction: column; gap: 3px; margin-top: 10px; }
.log div { overflow-wrap: anywhere; }
details.d-section summary { cursor: pointer; }
details.d-section summary .eyebrow { display: inline; }
@media (max-width: 1100px) {
  #view-history { padding: 16px; }
  .history { grid-template-columns: 1fr; }
  .history-list, .history-detail { max-height: none; }
  .h-rows { max-height: 60vh; }
  .d-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 480px) {
  .h-row { grid-template-columns: minmax(0, 1fr) auto; }
  .h-when { grid-column: 1 / -1; display: flex; gap: 8px; }
  .h-when b { display: inline; }
  .d-grid { grid-template-columns: 1fr; }
  .filter-actions { margin-left: 0; }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 10;
  background: var(--primary); color: var(--primary-ink); padding: 10px 16px; border-radius: 6px; max-width: calc(100vw - 32px);
  border: 1px solid var(--line-strong);
}
.toast.err { background: #A02922; border-color: #A02922; color: #FFFFFF; }

/* ---------- Dashboard ---------- */
.dash { padding: 20px 24px; max-width: 1640px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }
.tiles { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.tile { padding: 14px 16px; }
.tile .eyebrow { margin-bottom: 6px; }
.tile-value { font-size: 30px; font-weight: 700; line-height: 1.1; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.tile-sub { font-size: 12.5px; margin-top: 4px; }
.tile.is-live { border-color: var(--pill-green-ink); }
.tile.is-live .tile-value { color: var(--pill-green-ink); }
.tile.is-warn .tile-value { color: var(--pill-amber-ink); }
.tile.is-bad { border-color: var(--pill-red-ink); }
.tile.is-bad .tile-value { color: var(--pill-red-ink); }
@media (max-width: 1100px) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 560px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } .tile-value { font-size: 24px; } }

.dash-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr); gap: 20px; align-items: start; }
.dash-col { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.dash-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: stretch; }
.dash-card { padding: 16px 18px 18px; }
@media (max-width: 1100px) { .dash-grid { grid-template-columns: 1fr; } }
@media (max-width: 760px) { .dash { padding: 16px; } .dash-pair { grid-template-columns: 1fr; } }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.card-head a { font-size: 12.5px; text-decoration: none; }
.card-head .muted { font-size: 12.5px; }
.dash .empty { margin: 8px auto; padding: 16px; font-size: 13px; }

.live-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.live-call { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.live-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.live-who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--pill-green-ink); flex: none; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .live-dot { animation: none; } }
.live-timer { margin-left: auto; color: var(--text-soft); flex: none; }
.live-tags { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.live-sum { font-size: 13px; }
.live-last { font-size: 13px; color: var(--text); background: var(--bubble-agent); border-radius: 6px; padding: 8px 10px; min-height: 38px; overflow-wrap: anywhere; }
.live-last .clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.live-last .who { font-size: 10px; font-weight: 500; letter-spacing: 0.12em; text-transform: uppercase; color: var(--label); margin-right: 4px; }
.live-call .btn { align-self: flex-start; }

.d-list { display: flex; flex-direction: column; }
.d-row { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 8px 6px; border-radius: 6px; text-decoration: none; color: var(--text); }
.d-row + .d-row { border-top: 1px solid var(--line); }
.d-row:hover { background: var(--surface-2); }
.d-when { font-size: 12.5px; display: flex; flex-direction: column; line-height: 1.3; }
.d-when .muted { font-size: 11.5px; }
.d-who, .d-sum { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.d-who { font-weight: 500; }
.d-sum { font-size: 12.5px; color: var(--text-soft); }
.d-tags { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }

.trend { position: relative; }
.trend-plot { position: relative; display: grid; grid-template-columns: repeat(14, minmax(0, 1fr)); height: 150px; border-bottom: 1px solid var(--line); padding-top: 16px; }
.trend-max { position: absolute; top: 0; left: 0; font-size: 11px; }
.bar-slot { display: flex; align-items: flex-end; justify-content: center; height: 100%; padding: 0 1px; cursor: default; outline: none; }
.bar-slot:hover, .bar-slot:focus-visible { background: var(--focus); border-radius: 4px 4px 0 0; }
.bar { width: 100%; max-width: 22px; background: var(--bar); border-radius: 4px 4px 0 0; opacity: 0.75; }
.bar.today { opacity: 1; }
.trend-axis { display: flex; justify-content: space-between; font-size: 11.5px; margin-top: 6px; }
.bar-tip { position: absolute; top: -6px; transform: translateX(-50%); background: var(--surface-2); border: 1px solid var(--line-strong); color: var(--text);
  font-size: 12px; padding: 4px 8px; border-radius: 4px; white-space: nowrap; pointer-events: none; z-index: 2; }

.cat-bars { display: flex; flex-direction: column; gap: 4px; }
.cat-row { display: grid; grid-template-columns: minmax(90px, 40%) 1fr 28px; gap: 10px; align-items: center; text-decoration: none; color: var(--text); padding: 5px 6px; border-radius: 6px; font-size: 13px; }
.cat-row:hover { background: var(--surface-2); }
.cat-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-track { height: 10px; }
.cat-fill { display: block; height: 100%; background: var(--bar); border-radius: 0 4px 4px 0; min-width: 3px; }
.cat-n { text-align: right; font-variant-numeric: tabular-nums; }

.d-system { display: flex; flex-direction: column; gap: 10px; }
.sys-row { display: grid; grid-template-columns: 50px 1fr; gap: 10px; align-items: start; font-size: 13px; }
.sys-row .pill { text-align: center; margin-top: 2px; }
.sys-row .mono { overflow-wrap: anywhere; }

/* ---------- Sign-in ---------- */
.user-box { display: flex; align-items: center; gap: 8px; }
.user-box:empty { display: none; }
.user-name { font-size: 13px; color: var(--text-soft); max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 360px; padding: 40px 32px; display: flex; flex-direction: column; align-items: center; text-align: center; }
.auth-card .logo { height: 30px; margin-bottom: 24px; }
.auth-title { font-size: 22px; font-weight: 700; margin: 0 0 28px; letter-spacing: -0.01em; }
.auth-msg { color: var(--pill-red-ink); font-size: 13px; margin: -12px 0 20px; }
/* Google's neutral sign-in button: white, grey outline, 40px tall, official G mark. */
.g-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 12px; height: 40px; padding: 0 16px 0 12px;
  background: #FFFFFF; color: #1F1F1F; border: 1px solid #747775; border-radius: 4px; text-decoration: none;
  font: 500 14px/20px Roboto, Rubik, Arial, sans-serif; letter-spacing: 0.25px; min-width: 220px;
}
.g-btn:hover { background: #F8F9FA; box-shadow: 0 1px 2px rgb(60 64 67 / 0.3); }
.g-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus); }
.g-mark { width: 20px; height: 20px; flex: none; }

/* ---------- Permissions ---------- */
.layout.single { grid-template-columns: minmax(0, 1fr); max-width: 1100px; }
.readonly-note { margin: -8px 0 20px; }
.settings.readonly input:disabled, .settings.readonly select:disabled, .settings.readonly textarea:disabled { opacity: 0.85; cursor: default; }

/* ---------- Users ---------- */
.users-view { padding: 24px; max-width: 960px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.users-head .lede { margin: 0; }
.users-card { padding: 4px 20px; }
.add-user { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; padding: 16px 0; }
.add-user .grow { flex: 1; min-width: 220px; }
.add-user select { min-width: 130px; }
.u-row {
  display: grid; grid-template-columns: 40px minmax(0, 1fr) 150px 72px; grid-template-areas: "av who role act" ". sum sum sum" "feat feat feat feat";
  gap: 4px 14px; align-items: center; padding: 16px 0;
}
.u-row + .u-row { border-top: 1px solid var(--line); }
.u-avatar { grid-area: av; width: 40px; height: 40px; border-radius: 50%; background: var(--pill); color: var(--pill-ink); display: grid; place-items: center; font-weight: 700; font-size: 14px; }
.u-who { grid-area: who; min-width: 0; }
.u-name { font-weight: 700; font-size: 15px; }
.u-meta { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.u-role-wrap { grid-area: role; }
.u-actions { grid-area: act; text-align: right; }
.u-summary { grid-area: sum; font-size: 13px; }
.u-features { grid-area: feat; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 12px; }
.u-group { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px 12px; margin: 0; min-width: 0; }
.u-group legend { font-size: 10.5px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.12em; color: var(--label); padding: 0 6px; }
.u-check { flex-direction: row; align-items: flex-start; gap: 10px; padding: 7px 0; cursor: pointer; font-weight: 400; }
.u-check input { width: 16px; height: 16px; margin-top: 2px; flex: none; accent-color: var(--primary); cursor: pointer; }
.u-check span { display: flex; flex-direction: column; min-width: 0; }
.u-check b { font-weight: 500; font-size: 13.5px; }
.u-check small { color: var(--text-soft); font-size: 12px; line-height: 1.4; }
.u-check.locked { cursor: default; }
.u-check.locked input { cursor: default; }
.u-check.locked small { color: var(--label); }
.roles-hint { margin: 0 4px; }
@media (max-width: 700px) {
  .users-view { padding: 16px; }
  .users-card { padding: 4px 16px; }
  .u-row { grid-template-columns: 40px minmax(0, 1fr) auto; grid-template-areas: "av who act" "role role role" "sum sum sum" "feat feat feat"; }
  .u-role-wrap select { width: 100%; }
  .u-features { grid-template-columns: 1fr; }
}

/* ---------- Jarvis ---------- */
.jarvis-card { display: flex; gap: 14px; align-items: center; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; flex-wrap: wrap; }
.jarvis-card .grow { flex: 1; min-width: 220px; }
.jarvis-card .muted { font-size: 13px; }
.err-text { color: var(--pill-red-ink); font-size: 13px; }
.jarvis-test { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.jarvis-test label:first-child { width: 170px; }
.jarvis-test .grow { flex: 1; min-width: 220px; }
.jarvis-result { margin-top: 14px; font-size: 13.5px; }
.jarvis-result table.rows td { padding: 4px; overflow-wrap: anywhere; }
.jarvis-result table.rows td:last-child, .jarvis-result table.rows th:last-child { width: auto; text-align: left; }

/* ---------- Business hours ---------- */
.bh-section { margin-top: 0; margin-bottom: 28px; }
.bh-days { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.bh-day { display: grid; grid-template-columns: 170px 130px auto 130px; justify-content: start; gap: 10px; align-items: center; }
.bh-day input[type=time] { padding: 6px 8px; }
.bh-day input[type=time]:disabled { opacity: 0.4; }
.bh-extra { align-items: start; }
@media (max-width: 560px) { .bh-day { grid-template-columns: 1fr 1fr; } .bh-day .muted { display: none; } }

/* ---------- Webhook log ---------- */
.requests-view { padding: 24px; max-width: 1280px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.rq-card { padding: 4px 0 8px; }
.rq-filters { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.rq-live { margin-left: auto; padding-bottom: 6px; }
.rq-rows { display: flex; flex-direction: column; }
.rq-row + .rq-row { border-top: 1px solid var(--line); }
.rq-head {
  all: unset; box-sizing: border-box; cursor: pointer; width: 100%; padding: 10px 20px;
  display: grid; grid-template-columns: 96px 92px 150px 210px minmax(0, 1fr) 84px; gap: 12px; align-items: center; font-size: 13px;
}
.rq-head:hover, .rq-row.open .rq-head { background: var(--surface-2); }
.rq-head:focus-visible { box-shadow: inset 0 0 0 2px var(--focus); }
.rq-head .pill { justify-self: start; }
.rq-head .pill:last-child { justify-self: end; }
.rq-when { display: flex; flex-direction: column; line-height: 1.3; }
.rq-when .muted { font-size: 11.5px; }
.rq-kind { font-weight: 500; }
.rq-who { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rq-sum { color: var(--text-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rq-row.open .rq-sum { white-space: normal; }
.rq-detail { padding: 6px 20px 18px 128px; }
.rq-detail table.sip { margin-top: 8px; }
.rq-detail table.sip td { vertical-align: top; overflow-wrap: anywhere; font-size: 12.5px; }
.rq-detail table.sip td:first-child, .rq-detail table.sip th:first-child { width: 200px; text-align: left; }
.rq-detail table.sip td:last-child, .rq-detail table.sip th:last-child { width: auto; text-align: left; }
.rq-json { background: var(--code-bg); border-radius: 6px; padding: 10px 12px; font-size: 12px; overflow-x: auto; margin: 10px 0 0; }
@media (max-width: 900px) {
  .rq-head { grid-template-columns: 80px minmax(0, 1fr) auto; }
  .rq-head .pill:nth-of-type(1), .rq-kind, .rq-who { display: none; }
  .rq-detail { padding-left: 20px; }
}
