/* VoiceBot dashboard. Plain CSS, no external assets.
   Sections: tokens, base, shell, page, cards, tables, pills, buttons, forms,
   modal, toasts, charts, tabs, detail views, responsive. */

/* ---------- Tokens ---------- */
:root {
  color-scheme: light;

  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f4f5f7;
  --surface-hover: #eef0f4;
  --border: #e2e5e9;
  --border-strong: #cdd2d9;

  --text: #1b1f24;
  --text-2: #57606c;
  --text-3: #666e7a;
  --link: #2a4bc4;

  --accent: #3355d1;
  --accent-hover: #2947b8;
  --accent-soft: #e9eefc;
  --on-accent: #ffffff;
  --danger: #c4302b;
  --danger-hover: #a82722;
  --danger-text: #c4302b;
  --danger-soft: #fdecec;
  --focus: #3355d1;

  --overlay: rgba(15, 18, 24, 0.45);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-lg: 0 16px 40px rgba(16, 24, 40, 0.2);

  /* Status pills: background / text / dot */
  --green-bg: #e4f4e9;  --green-fg: #1a6b33;  --green-dot: #2f9e4f;
  --gray-bg: #eceef1;   --gray-fg: #4b5360;   --gray-dot: #8a919c;
  --blue-bg: #e5eefd;   --blue-fg: #1c4fb5;   --blue-dot: #3b7de0;
  --amber-bg: #fcefd3;  --amber-fg: #855600;  --amber-dot: #d99a00;
  --red-bg: #fde8e8;    --red-fg: #b02a2a;    --red-dot: #dc3c3d;

  --banner-warn-bg: #fdf3dc;  --banner-warn-fg: #6f4800;  --banner-warn-border: #f1dca6;
  --banner-error-bg: #fde8e8; --banner-error-fg: #8f1f1f; --banner-error-border: #f3c4c4;

  /* Chart series (calls, answered, qualified) and chrome */
  --series-1: #257de0;
  --series-2: #f47230;
  --series-3: #00b894;
  --grid: #e7e9ec;
  --axis: #c2c6cc;
  --chart-hover: rgba(27, 31, 36, 0.05);
  --funnel-link: rgba(37, 125, 224, 0.16);

  --radius: 8px;
  --radius-sm: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --bg: #0f1114;
    --surface: #181a1e;
    --surface-2: #1f2227;
    --surface-hover: #252930;
    --border: #2a2e35;
    --border-strong: #3a3f48;

    --text: #e7e9ec;
    --text-2: #a4acb8;
    --text-3: #858d99;
    --link: #8ea6ff;

    --accent: #4466e0;
    --accent-hover: #5676ea;
    --accent-soft: #1c2748;
    --on-accent: #ffffff;
    --danger: #cf3b36;
    --danger-hover: #dc4a45;
    --danger-text: #f28b85;
    --danger-soft: #3d1717;
    --focus: #8ea6ff;

    --overlay: rgba(0, 0, 0, 0.6);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.55);

    --green-bg: #143321;  --green-fg: #74d391;  --green-dot: #3fb564;
    --gray-bg: #282c33;   --gray-fg: #b6bdc8;   --gray-dot: #7b8490;
    --blue-bg: #16294a;   --blue-fg: #93bbf8;   --blue-dot: #4c8fe8;
    --amber-bg: #3a2d0c;  --amber-fg: #efc264;  --amber-dot: #d99a00;
    --red-bg: #421a1a;    --red-fg: #f6a0a0;    --red-dot: #e05656;

    --banner-warn-bg: #33280b;  --banner-warn-fg: #f3d28a;  --banner-warn-border: #4d3c10;
    --banner-error-bg: #3d1717; --banner-error-fg: #f6b0b0; --banner-error-border: #5a2222;

    --series-1: #338ced;
    --series-2: #e76624;
    --series-3: #00a888;
    --grid: #2a2e35;
    --axis: #444a54;
    --chart-hover: rgba(231, 233, 236, 0.06);
    --funnel-link: rgba(51, 140, 237, 0.2);
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p, dl, dd, ol, ul { margin: 0; }
ol, ul { padding: 0; list-style: none; }

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
a:focus-visible { border-radius: 3px; }
/* Containers that only receive focus from scripts (skip link, dialog fallback) show no ring. */
#main:focus-visible, .modal:focus-visible { outline: none; }

.muted { color: var(--text-3); }
.mono { font-family: var(--mono); font-size: 12px; }
.error-text { color: var(--danger-text); }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 8px; top: -48px;
  z-index: 300;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}
.skip-link:focus { top: 8px; }

.icon {
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.noscript { padding: 24px; text-align: center; }

/* ---------- Sign in ---------- */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(360px, 100%);
  display: grid;
  gap: 14px;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.login-card h1 { font-size: 18px; font-weight: 600; }

/* ---------- Shell ---------- */
.shell {
  display: grid;
  grid-template-columns: 212px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 10px 12px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 4px 8px 12px;
  color: var(--text);
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; }
.brand-lg { padding: 0; font-size: 18px; }
.brand-mark rect { fill: var(--accent); }
.brand-mark path { fill: none; stroke: #ffffff; stroke-width: 1.5; stroke-linecap: round; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex;
  align-items: center;
  gap: 9px;
  height: 32px;
  padding: 0 9px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-weight: 500;
  white-space: nowrap;
}
.nav a:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--text); }
.nav a[aria-current="page"] .icon { color: var(--link); }

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 8px;
  padding: 10px 8px 0;
  border-top: 1px solid var(--border);
}
.session-info { display: grid; gap: 1px; color: var(--text-3); font-size: 12px; overflow-wrap: anywhere; }
.sidebar-footer .btn { justify-self: start; margin-left: -8px; }

.main { min-width: 0; display: flex; flex-direction: column; }

.banner {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 24px;
  font-size: 12.5px;
  font-weight: 500;
  border-bottom: 1px solid;
}
.banner-warn { background: var(--banner-warn-bg); color: var(--banner-warn-fg); border-color: var(--banner-warn-border); }
.banner-error { background: var(--banner-error-bg); color: var(--banner-error-fg); border-color: var(--banner-error-border); }

/* ---------- Page ---------- */
.page {
  width: 100%;
  max-width: 1440px;
  padding: 20px 24px 48px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.page-header { display: grid; gap: 6px; }
.page-header-top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px 16px;
  flex-wrap: wrap;
}
.page-heading { min-width: 0; display: grid; gap: 3px; }
.page-meta:empty { display: none; }
.page-title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.page-header h1 { font-size: 18px; line-height: 1.3; font-weight: 600; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.page-meta { color: var(--text-2); font-size: 12.5px; display: flex; flex-wrap: wrap; gap: 2px 14px; }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.action-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.crumb { display: inline-flex; align-items: center; gap: 4px; color: var(--text-2); font-size: 12px; justify-self: start; }

.cols-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.cols-detail { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 16px; align-items: start; }
.stack { display: grid; gap: 16px; min-width: 0; }

.note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 9px 12px;
  border: 1px solid var(--banner-warn-border);
  border-radius: var(--radius);
  background: var(--banner-warn-bg);
  color: var(--banner-warn-fg);
}
.note .icon { margin-top: 2px; }

.state {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  color: var(--text-2);
}
/* First load failed: show only the header and the error, not a skeleton that will never fill. */
.page.load-failed > :not(.page-header):not(.state-error) { display: none; }
.state-error {
  border: 1px solid var(--banner-error-border);
  border-radius: var(--radius);
  background: var(--banner-error-bg);
  color: var(--banner-error-fg);
}

/* ---------- Cards ---------- */
.card {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  flex-wrap: wrap;
  min-height: 42px;
  padding: 6px 14px;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: 13px; font-weight: 600; }
.card-hint { color: var(--text-3); font-size: 12px; font-weight: 400; margin-left: 8px; }
.card-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-body { padding: 14px; }
.card-flush > .card-body { padding: 0; }
.card-flush .table-wrap { border-radius: 0 0 var(--radius) var(--radius); }
.card-section { padding: 14px; border-top: 1px solid var(--border); }
.card-footer { padding: 8px 14px; border-top: 1px solid var(--border); }
.subhead { margin: 14px 0 6px; font-size: 12px; font-weight: 600; color: var(--text-2); }
.card-section > .subhead { margin-top: 0; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.kpi {
  min-width: 0;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.kpi-label { color: var(--text-2); font-size: 12px; }
.kpi-value { margin-top: 2px; font-size: 22px; line-height: 1.25; font-weight: 600; letter-spacing: -0.01em; }
.kpi-sub { margin-top: 1px; color: var(--text-3); font-size: 12px; }
.kpis-compact .kpi { box-shadow: none; background: var(--surface-2); }
/* Fixed column counts on wide screens so tiles form complete rows. */
@media (min-width: 1081px) {
  .kpis-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .kpis-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}
@media (min-width: 561px) and (max-width: 1080px) {
  .kpis-6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ---------- Tables ---------- */
.table-wrap {
  overflow: auto;
  max-height: max(320px, calc(100vh - 230px));
}
.table-wrap.short { max-height: 340px; }

.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-variant-numeric: tabular-nums;
}
.table th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 7px 10px;
  background: var(--surface-2);
  box-shadow: inset 0 -1px 0 var(--border);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
}
.table th:first-child, .table td:first-child { padding-left: 14px; }
.table th:last-child, .table td:last-child { padding-right: 14px; }
.table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  white-space: nowrap;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; }
.table td.wrap { white-space: normal; overflow-wrap: anywhere; }
/* A "grow" column takes the leftover width and truncates instead of widening the table. */
.table td.grow { width: 26%; max-width: 0; }
.table th.grow { min-width: 130px; }
.table td.actions { text-align: right; overflow: visible; }
.table td.actions > .row-actions { justify-content: flex-end; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--surface-hover); }
.table .empty-row td {
  padding: 28px 16px;
  color: var(--text-3);
  text-align: center;
  white-space: normal;
  max-width: none;
}
.row-actions { display: inline-flex; align-items: center; gap: 6px; }
.cell-main { font-weight: 500; color: var(--text); }
a.cell-main { color: var(--text); }
a.cell-main:hover { color: var(--link); }

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  color: var(--text-2);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.pager-buttons { display: flex; gap: 6px; }

.filters {
  display: flex;
  align-items: flex-end;
  gap: 10px 12px;
  flex-wrap: wrap;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.filters .field { flex: 0 1 190px; width: auto; min-width: 130px; }
.filters .field-grow { flex: 1 1 220px; max-width: 340px; }

/* ---------- Pills, chips, progress ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 20px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  vertical-align: middle;
}
.pill::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.pill-green { background: var(--green-bg); color: var(--green-fg); }
.pill-green::before { background: var(--green-dot); }
.pill-gray { background: var(--gray-bg); color: var(--gray-fg); }
.pill-gray::before { background: var(--gray-dot); }
.pill-blue { background: var(--blue-bg); color: var(--blue-fg); }
.pill-blue::before { background: var(--blue-dot); }
.pill-amber { background: var(--amber-bg); color: var(--amber-fg); }
.pill-amber::before { background: var(--amber-dot); }
.pill-red { background: var(--red-bg); color: var(--red-fg); }
.pill-red::before { background: var(--red-dot); }

.chips { display: inline-flex; flex-wrap: wrap; gap: 4px; vertical-align: middle; }
.table td:not(.wrap) .chips { flex-wrap: nowrap; }
.chip {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 11.5px;
  white-space: nowrap;
}

.progress-cell { display: flex; align-items: center; gap: 10px; min-width: 132px; }
.progress {
  flex: 1 1 80px;
  min-width: 48px;
  height: 6px;
  border-radius: 3px;
  background: var(--accent-soft);
  overflow: hidden;
}
.progress-fill { height: 100%; border-radius: 3px; background: var(--accent); }
.progress-text { color: var(--text-2); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }

.campaign-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.campaign-row:last-child { border-bottom: 0; }
.campaign-row-title { display: flex; align-items: center; gap: 8px; min-width: 0; }
.campaign-row-title .cell-main { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.campaign-row-progress { grid-column: 1 / -1; display: flex; align-items: center; gap: 14px; min-width: 0; }
.campaign-row-progress .progress-cell { flex: 1 1 auto; min-width: 0; }
.campaign-row-note { grid-column: 1 / -1; font-size: 12px; }

.line-strip { display: flex; flex-wrap: wrap; gap: 8px; }
.line-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
}
.line-chip:hover { background: var(--surface-hover); text-decoration: none; }
.line-chip .muted { font-size: 12px; }

.stat-links { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.stat-link {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-2);
}
.stat-link:hover { background: var(--surface-hover); text-decoration: none; }
.stat-link strong { color: var(--text); font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-link.is-bad { border-color: var(--banner-error-border); background: var(--banner-error-bg); color: var(--banner-error-fg); }
.stat-link.is-bad strong { color: inherit; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 30px;
  padding: 0 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.btn:hover { background: var(--surface-hover); text-decoration: none; }
.btn:disabled, .btn[aria-busy="true"] { opacity: 0.55; cursor: default; }
.btn[aria-busy="true"] { cursor: progress; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--danger-text); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #ffffff; }
.btn-danger-solid:hover { background: var(--danger-hover); border-color: var(--danger-hover); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-sm { height: 26px; padding: 0 8px; font-size: 12px; }
.btn-icon { width: 30px; padding: 0; }
.btn-icon.btn-sm { width: 26px; }
.btn-block { width: 100%; }

.switch {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 2px;
  border: 0;
  background: none;
  color: var(--text-2);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.switch-track {
  position: relative;
  width: 28px; height: 16px;
  border-radius: 8px;
  background: var(--border-strong);
  transition: background 0.12s;
}
.switch-knob {
  position: absolute;
  top: 2px; left: 2px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #ffffff;
  transition: transform 0.12s;
}
.switch[aria-checked="true"] { color: var(--text); }
.switch[aria-checked="true"] .switch-track { background: var(--accent); }
.switch[aria-checked="true"] .switch-knob { transform: translateX(12px); }
.switch-text { min-width: 20px; text-align: left; }

/* ---------- Forms ---------- */
.form { display: grid; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form-grid-4 > .span-2 { grid-column: span 2; }
.field-inline { max-width: 320px; }

.field { display: grid; gap: 4px; width: 100%; min-width: 0; align-content: start; }
.field-label { display: flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 12px; font-weight: 500; }
.field-hint { color: var(--text-3); font-size: 12px; }

input[type="text"], input[type="password"], input[type="url"], input[type="number"],
input[type="time"], input[type="search"], input[type="tel"], input[type="file"],
select, textarea {
  width: 100%;
  min-width: 0;
  height: 30px;
  padding: 0 9px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
input[type="file"] { height: auto; padding: 5px 6px; }
input::placeholder { color: var(--text-3); opacity: 1; }
input:disabled, select:disabled { background: var(--surface-2); color: var(--text-3); }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 0;
  border-color: var(--focus);
  border-radius: var(--radius-sm);
}
input[type="checkbox"] { width: 15px; height: 15px; margin: 0; accent-color: var(--accent); flex: none; }

fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
legend { padding: 0; margin-bottom: 6px; color: var(--text-2); font-size: 12px; font-weight: 500; }

.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; }
.check-list { display: grid; gap: 7px; }
.check-list .check { align-items: flex-start; }
.check-list .check input { margin-top: 2px; }
.check-desc { display: block; color: var(--text-3); font-size: 12px; }
.weekdays { display: flex; flex-wrap: wrap; gap: 6px 14px; }

.kv-rows { display: grid; gap: 6px; margin-bottom: 8px; }
.kv-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr) auto; gap: 6px; }

.form-error { color: var(--danger-text); font-size: 12.5px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; }

.inline-form { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.inline-form .field { width: auto; flex: 0 1 240px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 7vh 16px 16px;
  background: var(--overlay);
  overflow-y: auto;
}
.modal {
  width: min(460px, 100%);
  display: flex;
  flex-direction: column;
  max-height: 86vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
}
.modal-wide { width: min(720px, 100%); }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 10px 10px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 14px; font-weight: 600; }
.modal-body { padding: 16px; overflow-y: auto; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
}
.confirm-text { color: var(--text-2); overflow-wrap: anywhere; }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 9px 8px 9px 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-left-width: 3px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
}
.toast > .icon { margin-top: 2px; }
.toast-text { flex: 1 1 auto; overflow-wrap: anywhere; }
.toast-success { border-left-color: var(--green-dot); }
.toast-success > .icon { color: var(--green-fg); }
.toast-error { border-left-color: var(--red-dot); }
.toast-error > .icon { color: var(--red-fg); }
.toast-info { border-left-color: var(--blue-dot); }
.toast-info > .icon { color: var(--blue-fg); }
.toast .btn { margin: -3px 0; }

/* ---------- Charts ---------- */
.chart { width: 100%; overflow: hidden; }
.chart svg { display: block; }
.chart text { font-family: var(--font); font-size: 11px; fill: var(--text-2); font-variant-numeric: tabular-nums; }
.chart .chart-label { font-size: 12px; fill: var(--text); }
.chart .chart-value { font-size: 12px; fill: var(--text-2); }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .axis-line { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .hit { fill: transparent; }
.chart g:hover > .hit { fill: var(--chart-hover); }
.chart .s1 { fill: var(--series-1); }
.chart .s2 { fill: var(--series-2); }
.chart .s3 { fill: var(--series-3); }
.chart .funnel-link { fill: var(--funnel-link); }
.chart .dot-green { fill: var(--green-dot); }
.chart .dot-gray { fill: var(--gray-dot); }
.chart .dot-blue { fill: var(--blue-dot); }
.chart .dot-amber { fill: var(--amber-dot); }
.chart .dot-red { fill: var(--red-dot); }

.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-bottom: 8px; color: var(--text-2); font-size: 12px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; }
.swatch.sw1 { background: var(--series-1); }
.swatch.sw2 { background: var(--series-2); }
.swatch.sw3 { background: var(--series-3); }
.chart-empty { padding: 28px 8px; color: var(--text-3); text-align: center; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; padding: 0 8px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab {
  height: 38px;
  padding: 0 10px;
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  background: none;
  color: var(--text-2);
  font: inherit;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tab:focus-visible { outline-offset: -3px; }

/* ---------- Detail views ---------- */
.dl { display: grid; grid-template-columns: minmax(110px, 38%) minmax(0, 1fr); gap: 7px 14px; }
.dl dt { color: var(--text-2); }
.dl dd { min-width: 0; overflow-wrap: anywhere; }

.bullets { display: grid; gap: 3px; padding-left: 16px; list-style: disc; }
.prose { overflow-wrap: anywhere; white-space: pre-wrap; }
.prose + .dl { margin-top: 12px; }

.transcript { display: flex; flex-direction: column; gap: 10px; }
.msg { display: grid; gap: 2px; max-width: 78%; }
.msg-agent { align-self: flex-start; justify-items: start; }
.msg-caller { align-self: flex-end; justify-items: end; }
.msg-meta { display: flex; gap: 8px; color: var(--text-3); font-size: 11.5px; }
.msg-time { font-variant-numeric: tabular-nums; }
.msg-bubble {
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.msg-agent .msg-bubble { border-top-left-radius: 3px; }
.msg-caller .msg-bubble { border-top-right-radius: 3px; background: var(--accent-soft); border-color: transparent; }
.msg-tool { align-self: stretch; color: var(--text-3); font-size: 12px; }
.msg-tool summary { display: flex; align-items: center; gap: 7px; width: fit-content; max-width: 100%; margin: 0 auto; padding: 1px 6px; border-radius: 4px; cursor: pointer; list-style: none; }
.msg-tool summary::-webkit-details-marker { display: none; }
.msg-tool summary:hover { color: var(--text-2); background: var(--surface-hover); }
.msg-tool .tool-detail { margin: 6px auto 0; max-width: 78%; display: grid; gap: 6px; }

.code {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font: 12px/1.5 var(--mono);
  white-space: pre;
  overflow: auto;
  max-height: 420px;
}
.msg-tool .code { max-height: 220px; }

details.disclosure > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 6px 14px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
details.disclosure > summary::-webkit-details-marker { display: none; }
/* Chevron: points right when closed, down when open. */
details.disclosure > summary::before {
  content: "";
  width: 6px; height: 6px;
  margin: 0 2px 2px 2px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.12s;
}
details.disclosure[open] > summary::before { transform: rotate(45deg); }
details.disclosure > summary:focus-visible { outline-offset: -2px; border-radius: var(--radius); }
details.disclosure[open] > summary { border-bottom: 1px solid var(--border); }
.disclosure-body { display: grid; gap: 12px; padding: 14px; }

.result-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
.preview-note { margin: 6px 0; }
.bordered { border: 1px solid var(--border); border-radius: var(--radius-sm); }
.bordered.table-wrap { max-height: 260px; }

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
  .cols-2, .cols-detail { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 800px) {
  .shell { display: block; }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    overflow: visible;
  }
  .brand { padding: 4px 6px; }
  .brand > span { display: none; }
  .nav { flex: 1 1 auto; flex-direction: row; min-width: 0; overflow-x: auto; padding: 3px; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { padding: 0 9px; }
  .sidebar-footer { margin: 0; padding: 0; border: 0; }
  .sidebar-footer .btn { margin: 0; }
  .session-info { display: none; }
  .banner { padding: 7px 14px; }
  .page { padding: 14px 14px 40px; }
  .form-grid, .form-grid-4 { grid-template-columns: minmax(0, 1fr); }
  .form-grid-4 > .span-2 { grid-column: auto; }
  .result-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .msg { max-width: 92%; }
  .table-wrap { max-height: max(320px, calc(100vh - 160px)); }
  .filters .field, .filters .field-grow { flex: 1 1 140px; max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
