:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e3e6ea;
  --text: #16191d;
  --muted: #5d6670;
  --faint: #8b949e;
  --accent: #0d6e5f;
  --accent-hover: #0a5a4e;
  --accent-soft: #e3f2ef;
  --accent-text: #ffffff;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #8a5a00;
  --warn-soft: #fdf3dc;
  --ok-soft: #e3f2ef;
  --caller-bubble: #eef1f4;
  --assistant-bubble: #e3f2ef;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --radius: 10px;
  --sidebar: #12161b;
  --sidebar-text: #c9d1d9;
  --sidebar-active: #1f2730;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #161b22;
    --surface-2: #1b2129;
    --border: #2a313b;
    --text: #e6e9ed;
    --muted: #9aa4af;
    --faint: #6e7781;
    --accent: #2bb39b;
    --accent-hover: #3cc7ae;
    --accent-soft: #12332d;
    --accent-text: #06201b;
    --danger: #f26d63;
    --danger-soft: #3a1714;
    --warn: #e0a83a;
    --warn-soft: #33270f;
    --ok-soft: #12332d;
    --caller-bubble: #222a33;
    --assistant-bubble: #12332d;
    --shadow: none;
    --sidebar: #0a0d11;
    --sidebar-text: #b5bec8;
    --sidebar-active: #1a2129;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
p { margin: 0 0 10px; }
code { font-size: 13px; background: var(--surface-2); border: 1px solid var(--border); padding: 1px 5px; border-radius: 5px; word-break: break-all; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }

/* ---------- layout */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar); color: var(--sidebar-text);
  display: flex; flex-direction: column; padding: 18px 12px; gap: 4px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 650; padding: 4px 10px 16px; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: #2bb39b; display: grid; place-items: center; color: #06201b; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar a.nav {
  color: var(--sidebar-text); padding: 8px 10px; border-radius: 7px; display: flex; align-items: center; gap: 10px; font-size: 14px;
}
.sidebar a.nav:hover { background: var(--sidebar-active); text-decoration: none; color: #fff; }
.sidebar a.nav.active { background: var(--sidebar-active); color: #fff; }
.sidebar .section { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #6e7781; padding: 16px 10px 6px; }
.sidebar .grow { flex: 1; }
.sidebar svg { width: 17px; height: 17px; flex: none; }
.badge { margin-left: auto; background: #2bb39b; color: #06201b; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 99px; }
.switcher { padding: 0 6px 8px; }
.switcher select { width: 100%; background: var(--sidebar-active); color: #fff; border: 1px solid #2a313b; }
.main { padding: 28px 32px 60px; min-width: 0; max-width: 1240px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.mobile-bar { display: none; }

/* ---------- cards & grids */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.main-side { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 28px; font-weight: 650; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .hint { color: var(--faint); font-size: 12px; }

/* ---------- bar chart */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 120px; padding-top: 6px; }
.bars .bar { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .9; position: relative; }
.bars .bar.zero { background: var(--border); }
.bars .bar:hover { opacity: 1; }
.bars .bar:hover::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--surface); font-size: 12px; padding: 3px 7px; border-radius: 5px; white-space: nowrap; z-index: 2;
}
.bars-axis { display: flex; justify-content: space-between; color: var(--faint); font-size: 12px; margin-top: 6px; }
.outcomes { list-style: none; margin: 0; padding: 0; }
.outcomes li { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 6px 0; font-size: 14px; }
.outcomes .track { grid-column: 1 / -1; height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--border); }
.outcomes .fill { height: 100%; background: var(--accent); }

/* ---------- tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 20px; border-bottom: 1px solid var(--border); vertical-align: top; font-size: 14px; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }
.summary-cell { color: var(--muted); max-width: 460px; }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); }

/* ---------- pills */
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.pill.green { background: var(--ok-soft); color: var(--accent); border-color: transparent; }
.pill.red { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.pill.amber { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.live { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.pill.live::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: currentColor; margin-right: 5px; animation: pulse 1.2s infinite; vertical-align: 1px; }
@keyframes pulse { 50% { opacity: .3; } }

/* ---------- forms */
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 5px; }
.help { color: var(--muted); font-size: 12.5px; font-weight: 400; margin: 3px 0 0; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=search], select, textarea {
  width: 100%; font: inherit; font-size: 14px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px;
}
textarea { min-height: 96px; resize: vertical; line-height: 1.45; }
textarea.tall { min-height: 200px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.field { margin-bottom: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 160px; }
.check { display: flex; gap: 9px; align-items: flex-start; font-weight: 500; font-size: 14px; }
.check input { margin-top: 4px; }
fieldset { border: 0; padding: 0; margin: 0; }
.form-section { padding: 20px 0; border-top: 1px solid var(--border); }
.form-section:first-of-type { border-top: 0; padding-top: 0; }
.form-section > h2 { margin-bottom: 4px; }
.form-section > .help { margin-bottom: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; font: inherit; font-size: 14px; font-weight: 600;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.sticky-save { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--border); margin: 0 -20px -18px; padding: 12px 20px; display: flex; gap: 10px; justify-content: flex-end; border-radius: 0 0 var(--radius) var(--radius); }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 18px; font-size: 14px; background: var(--ok-soft); color: var(--accent); }
.flash.error { background: var(--danger-soft); color: var(--danger); }
.flash.warn { background: var(--warn-soft); color: var(--warn); }
.callout { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; font-size: 14px; }
.callout.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.secret { font-family: ui-monospace, Consolas, monospace; font-size: 15px; background: var(--surface); border: 1px dashed var(--accent); padding: 8px 12px; border-radius: 8px; display: inline-block; margin-top: 6px; }

/* ---------- transcript */
.transcript { display: flex; flex-direction: column; gap: 10px; padding: 20px; }
.msg { max-width: 78%; display: flex; flex-direction: column; gap: 3px; }
.msg .who { font-size: 12px; color: var(--faint); }
.msg .bubble { padding: 9px 13px; border-radius: 14px; font-size: 14.5px; white-space: pre-wrap; word-wrap: break-word; }
.msg.caller { align-self: flex-start; }
.msg.caller .bubble { background: var(--caller-bubble); border-top-left-radius: 4px; }
.msg.assistant { align-self: flex-end; align-items: flex-end; }
.msg.assistant .bubble { background: var(--assistant-bubble); border-top-right-radius: 4px; }
.msg.event { align-self: center; max-width: 90%; }
.msg.event .bubble { background: transparent; color: var(--muted); font-size: 13px; border: 1px dashed var(--border); border-radius: 99px; padding: 4px 12px; text-align: center; }
.meta-list { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; font-size: 14px; margin: 0; }
.meta-list dt { color: var(--muted); }
.meta-list dd { margin: 0; }
.action-item { padding: 12px 0; border-top: 1px solid var(--border); font-size: 14px; }
.action-item:first-of-type { border-top: 0; padding-top: 0; }

/* ---------- inbox */
.inbox-item { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.inbox-item:last-child { border-bottom: 0; }
.inbox-item .title { font-weight: 600; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inbox-item .body { grid-column: 1; color: var(--text); font-size: 14px; }
.inbox-item .facts { grid-column: 1; color: var(--muted); font-size: 13px; display: flex; gap: 14px; flex-wrap: wrap; }
.inbox-item .side { grid-row: 1 / span 3; grid-column: 2; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--border); padding: 3px; border-radius: 9px; }
.tabs a { padding: 5px 12px; border-radius: 7px; color: var(--muted); font-size: 13px; font-weight: 600; }
.tabs a.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tabs a:hover { text-decoration: none; color: var(--text); }

/* ---------- test line */
.phone { max-width: 760px; }
.phone .transcript { min-height: 340px; max-height: 58vh; overflow-y: auto; }
.phone-controls { display: flex; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); align-items: center; flex-wrap: wrap; }
.phone-controls input[type=text] { flex: 1; min-width: 200px; }
.mic { width: 44px; height: 44px; border-radius: 50%; padding: 0; }
.mic.listening { background: var(--danger); border-color: var(--danger); color: #fff; animation: pulse 1.2s infinite; }
.status-line { font-size: 13px; color: var(--muted); padding: 0 20px 12px; min-height: 20px; }

/* ---------- login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { color: var(--text); padding: 0 0 18px; font-size: 18px; }

/* ---------- responsive */
@media (max-width: 1000px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.main-side { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 30% 0 0; z-index: 20; transform: translateX(-105%); transition: transform .2s; height: 100%; }
  body.nav-open .sidebar { transform: none; }
  .mobile-bar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--sidebar); color: #fff; position: sticky; top: 0; z-index: 10; }
  .mobile-bar button { background: none; border: 0; color: #fff; padding: 4px; cursor: pointer; }
  .main { padding: 20px 16px 48px; }
  .grid.cols-2 { grid-template-columns: 1fr; }
  th, td { padding: 10px 12px; }
  .hide-sm { display: none; }
  .msg { max-width: 92%; }
  .inbox-item { grid-template-columns: 1fr; }
  .inbox-item .side { grid-row: auto; grid-column: 1; flex-direction: row; align-items: center; }
}
