/* IVAI VoIP dashboard — tokens first, light + dark (OS setting or the in-app toggle). */
:root {
  color-scheme: light;
  --page: #f6f6f3;
  --surface: #fcfcfb;
  --surface-2: #f2f1ed;
  --surface-hover: #efeee9;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #7a7873;
  --hairline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-wash: rgba(42, 120, 214, 0.10);
  --on-accent: #ffffff;
  --good: #0ca30c;
  --good-ink: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --critical-ink: #b42c2c;
  --s-human: #2a78d6;
  --s-ai: #eb6834;
  --s-voicemail: #1baf7a;
  --s-missed: #eda100;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.06), 0 8px 24px rgba(11, 11, 11, 0.06);
  --radius: 12px;
  --radius-sm: 8px;
  --nav-w: 232px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --surface-hover: #262624;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #9a988f;
    --hairline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --accent-wash: rgba(57, 135, 229, 0.16);
    --good-ink: #0ca30c;
    --critical-ink: #e66767;
    --s-human: #3987e5;
    --s-ai: #d95926;
    --s-voicemail: #199e70;
    --s-missed: #c98500;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --surface-hover: #262624;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #9a988f;
  --hairline: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --accent-ink: #86b6ef;
  --accent-wash: rgba(57, 135, 229, 0.16);
  --good-ink: #0ca30c;
  --critical-ink: #e66767;
  --s-human: #3987e5;
  --s-ai: #d95926;
  --s-voicemail: #199e70;
  --s-missed: #c98500;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.muted { color: var(--muted); }
.ink-2 { color: var(--ink-2); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.nums { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stack { display: grid; gap: 12px; }
.hidden { display: none !important; }

/* ---------- boot + login ---------- */
.boot { min-height: 100vh; display: grid; place-items: center; }
.boot-mark { width: 36px; height: 36px; border-radius: 10px; background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; transform: scale(.92); } }
@media (prefers-reduced-motion: reduce) { .boot-mark { animation: none; } }

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); }
.login-card .brand { margin-bottom: 20px; }
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card form { display: grid; gap: 12px; margin-top: 20px; }
.code-input { font-family: var(--mono); font-size: 24px !important; letter-spacing: 8px; text-align: center; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: var(--nav-w) minmax(0, 1fr); min-height: 100vh; }
.nav {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--hairline);
  display: flex; flex-direction: column; padding: 16px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; flex: none; }
.brand-name { font-weight: 650; font-size: 15px; line-height: 1.15; }
.brand-sub { font-size: 12px; color: var(--muted); }
.nav a.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--ink-2); font-weight: 500; text-decoration: none; margin-bottom: 2px;
}
.nav a.nav-item:hover { background: var(--surface-hover); color: var(--ink); }
.nav a.nav-item[aria-current="page"] { background: var(--accent-wash); color: var(--accent-ink); }
.nav a.nav-item svg { width: 18px; height: 18px; flex: none; }
.nav .badge { margin-left: auto; }
.nav-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--hairline); display: grid; gap: 8px; }
.nav-user { font-size: 13px; }
.nav-user .email { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { min-width: 0; padding: 24px 28px 64px; max-width: 1320px; width: 100%; }
.main:focus { outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head p { color: var(--muted); margin-top: 2px; }

.topbar { display: none; }
.scrim { display: none; }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .nav {
    position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 40; transform: translateX(-100%);
    transition: transform .2s ease; box-shadow: var(--shadow);
  }
  .shell.nav-open .nav { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 30; display: none; }
  .shell.nav-open .scrim { display: block; }
  .topbar {
    display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 20;
    background: var(--surface); border-bottom: 1px solid var(--hairline); padding: 10px 16px;
    padding-top: max(10px, env(safe-area-inset-top));
  }
  .main { padding: 16px 16px 72px; }
}

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 34px; padding: 6px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  font-weight: 500; cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-hover); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--critical-ink); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-hover); }
.btn.sm { min-height: 28px; padding: 3px 9px; font-size: 13px; }
.btn svg { width: 16px; height: 16px; }
.icon-btn { width: 34px; padding: 0; }

input[type=text], input[type=email], input[type=tel], input[type=search], input[type=number], input[type=time], select, textarea {
  width: 100%; min-height: 36px; padding: 7px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
}
textarea { min-height: 88px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label.field { display: grid; gap: 4px; align-content: start; }
label.field > span, .field-label { font-size: 12.5px; font-weight: 500; color: var(--ink-2); }
.hint { font-size: 12px; color: var(--muted); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); padding: 2px; }
.seg button { border: 0; background: transparent; padding: 4px 10px; border-radius: 6px; cursor: pointer; color: var(--ink-2); font-weight: 500; min-height: 28px; }
.seg button[aria-pressed="true"] { background: var(--accent-wash); color: var(--accent-ink); }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.filters select, .filters input[type=search] { width: auto; min-width: 150px; }
.filters input[type=search] { min-width: 220px; }
@media (max-width: 640px) { .filters select, .filters input[type=search] { flex: 1 1 100%; } }

/* ---------- cards, tiles, pills ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card-pad { padding: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--hairline); }
.card-head h2 { font-size: 14px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 1100px) { .grid-main, .grid-2 { grid-template-columns: 1fr; } }

.tiles { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
@media (max-width: 1200px) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 560px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 2px; text-align: left; }
button.tile { cursor: pointer; font: inherit; color: inherit; }
button.tile:hover { background: var(--surface-hover); }
.tile .label { font-size: 12.5px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.tile .value { font-size: 26px; font-weight: 600; line-height: 1.2; }
.tile .delta { font-size: 12px; color: var(--muted); }
.tile .delta.up-good, .tile .delta.down-good { color: var(--good-ink); }
.tile .delta.up-bad, .tile .delta.down-bad { color: var(--critical-ink); }
.key { width: 10px; height: 10px; border-radius: 3px; flex: none; display: inline-block; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 1px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500; border: 1px solid var(--border); color: var(--ink-2); background: var(--surface); white-space: nowrap;
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.pill.accent { color: var(--accent-ink); border-color: transparent; background: var(--accent-wash); }
.dot.human { background: var(--s-human); } .dot.ai { background: var(--s-ai); }
.dot.voicemail { background: var(--s-voicemail); } .dot.missed { background: var(--s-missed); }
.dot.good { background: var(--good); } .dot.warning { background: var(--warning); }
.dot.serious { background: var(--serious); } .dot.critical { background: var(--critical); }
.dot.live { background: var(--critical); box-shadow: 0 0 0 0 rgba(208,59,59,.5); animation: live 1.6s infinite; }
@keyframes live { 70% { box-shadow: 0 0 0 6px rgba(208,59,59,0); } 100% { box-shadow: 0 0 0 0 rgba(208,59,59,0); } }
@media (prefers-reduced-motion: reduce) { .dot.live { animation: none; } }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: var(--on-accent); font-size: 11.5px; font-weight: 600; display: inline-grid; place-items: center; }

/* ---------- lists & tables ---------- */
.list { display: grid; }
.list-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: start; padding: 12px 16px; border-top: 1px solid var(--hairline); text-align: left; background: none; border-left: 0; border-right: 0; border-bottom: 0; width: 100%; color: inherit; font: inherit; }
.list-item:first-child { border-top: 0; }
button.list-item { cursor: pointer; }
button.list-item:hover { background: var(--surface-hover); }
.list-item .title { font-weight: 600; }
.list-item .sub { color: var(--ink-2); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.list-item .meta { color: var(--muted); font-size: 12.5px; text-align: right; white-space: nowrap; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--ink-2); font-weight: 600; font-size: 12.5px; flex: none; }
.avatar svg { width: 16px; height: 16px; }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }

.table-wrap { overflow-x: auto; position: relative; }
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { text-align: left; padding: 10px 12px; border-top: 1px solid var(--hairline); vertical-align: top; }
table.data thead th { border-top: 0; font-size: 12px; font-weight: 500; color: var(--muted); white-space: nowrap; }
table.data tbody tr.clickable { cursor: pointer; }
table.data tbody tr.clickable:hover { background: var(--surface-hover); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- chart ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--hairline); stroke-width: 1; }
.chart .base-line { stroke: var(--baseline); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .bar-human { fill: var(--s-human); } .chart .bar-ai { fill: var(--s-ai); }
.chart .bar-voicemail { fill: var(--s-voicemail); } .chart .bar-missed { fill: var(--s-missed); }
.chart .col-hit { fill: transparent; cursor: default; }
.chart .col-hit:hover, .chart .col-hit:focus { fill: var(--accent-wash); outline: none; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5; min-width: 150px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow);
  padding: 8px 10px; font-size: 12.5px;
}
.tooltip .t-date { color: var(--muted); margin-bottom: 4px; }
.tooltip .t-row { display: flex; align-items: center; gap: 8px; }
.tooltip .t-row .t-key { width: 12px; height: 2px; border-radius: 1px; }
.tooltip .t-row b { font-variant-numeric: tabular-nums; min-width: 22px; text-align: right; }
.tooltip .t-row span { color: var(--ink-2); }

/* ---------- drawer & modal ---------- */
.drawer-scrim, .modal-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 50; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(640px, 100vw); z-index: 51;
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow);
  display: flex; flex-direction: column;
}
.drawer-head { display: flex; align-items: flex-start; gap: 12px; padding: 16px; border-bottom: 1px solid var(--hairline); padding-top: max(16px, env(safe-area-inset-top)); }
.drawer-body { overflow-y: auto; padding: 16px; display: grid; gap: 16px; align-content: start; padding-bottom: max(24px, env(safe-area-inset-bottom)); }
.section-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 6px; }
.kv { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 6px 12px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.transcript { white-space: pre-wrap; background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px; font-size: 13.5px; max-height: 360px; overflow-y: auto; }
.timeline { display: grid; gap: 4px; font-size: 12.5px; color: var(--ink-2); }
.timeline div { display: grid; grid-template-columns: 70px 1fr; gap: 8px; }
audio { width: 100%; }
.modal {
  position: fixed; z-index: 51; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(460px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); padding: 20px;
}
.modal h2 { margin-bottom: 4px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.notice { border-radius: var(--radius-sm); padding: 10px 12px; background: var(--surface-2); color: var(--ink-2); font-size: 13px; display: flex; gap: 8px; align-items: flex-start; }
.notice.warn { background: rgba(250, 178, 25, 0.14); color: var(--ink); }
.notice svg { width: 16px; height: 16px; flex: none; margin-top: 2px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--hairline); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 8px 12px; color: var(--ink-2); font-weight: 500; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; align-items: start; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }
.hours { display: grid; gap: 6px; }
.hours-row { display: grid; grid-template-columns: 54px 90px 1fr 1fr; gap: 8px; align-items: center; }
.hours-row input[type=time] { min-height: 32px; padding: 4px 8px; }
.save-bar { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--hairline); }

#toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 10px; font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s; z-index: 60; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.bad { background: var(--critical); color: #fff; }
.loading { opacity: .55; transition: opacity .15s; }

/* ---------- business switcher ---------- */
.biz-wrap { position: relative; margin: 0 0 12px; }
.biz-switch {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); color: var(--ink);
  cursor: pointer; text-align: left;
}
.biz-switch:hover { background: var(--surface-hover); }
.biz-avatar {
  width: 28px; height: 28px; border-radius: 7px; flex: none; display: grid; place-items: center;
  color: #fff; font-size: 12px; font-weight: 650; letter-spacing: .3px;
}
.biz-avatar.all { background: var(--ink-2); }
.biz-avatar.all svg { width: 16px; height: 16px; fill: #fff; }
.biz-avatar.plus { background: transparent; color: var(--ink-2); border: 1px dashed var(--border); font-size: 16px; font-weight: 500; }
.biz-text { display: grid; min-width: 0; flex: 1; }
.biz-name { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.biz-sub { font-size: 12px; color: var(--muted); }
.biz-chevron { color: var(--muted); font-size: 12px; }
.biz-menu {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 50; max-height: min(420px, 70vh); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 6px;
}
.biz-item {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 7px 8px; border: 0; border-radius: 8px;
  background: transparent; color: var(--ink); cursor: pointer; text-align: left;
}
.biz-item:hover, .biz-item:focus-visible { background: var(--surface-hover); }
.biz-item[aria-checked="true"] { background: var(--accent-wash); }
.biz-check { color: var(--accent-ink); font-weight: 700; }
.biz-sep { height: 1px; background: var(--hairline); margin: 6px 4px; }
/* ---------- phone widths ---------- */
@media (max-width: 640px) {
  .main { padding: 16px 16px 48px; }
  .calls-table th:nth-child(4), .calls-table td:nth-child(4),
  .calls-table th:nth-child(5), .calls-table td:nth-child(5),
  .calls-table th:nth-child(6), .calls-table td:nth-child(6),
  .calls-table th:nth-child(7), .calls-table td:nth-child(7) { display: none; }
  .calls-table .avatar { display: none; }
  .kv { grid-template-columns: 110px minmax(0, 1fr); }
  .filters input[type=search] { min-width: 0; }
  .drawer-head, .drawer-body { padding-left: 16px; padding-right: 16px; }
}
