/* Agentify console — InspireTel Workspace look (October 2026)
   Rounded side menu and page panels on a light frame, white cards, pill buttons,
   DM Sans and Manrope. Colours are the Workspace's tokens (inspiretel-superapp
   src/app/globals.css), mapped onto the names this stylesheet already uses.
   Shared components below also style the Voice Lab page. */

/* ================= Tokens ================= */

:root {
  color-scheme: light;
  font-family: "DM Sans", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;

  --frame: #ffffff;           /* around the side menu and the page panel */
  --bg: #f2f5f5;              /* the page panel, which white cards sit on */
  --rail-bg: #f2f5f5;
  --surface: #ffffff;
  --surface-2: #f7f9f6;
  --surface-hover: #f4f7f2;
  --nav-hover: #e4eaea;
  --border: #e0e6e3;
  --border-strong: #cbd5d0;
  --text: #172c2b;
  --text-muted: #5b6e6b;
  --text-faint: #566a65;
  --eyebrow: #3b6f78;

  --accent: #0692a1;          /* icons, focus rings, active marks */
  --accent-hover: #056a76;
  --accent-ink: #057582;      /* links and accent text */
  --accent-soft: #dcedf0;
  --accent-contrast: #ffffff;
  --button: #06808e;          /* white text on #0692a1 is only 3.7:1, so fills use the deeper hue */
  --button-hover: #056a76;

  --good: #1f5130;
  --good-soft: #e3f1e6;
  --warn: #5d4510;
  --warn-soft: #f6f0dd;
  --bad: #a12a2a;
  --bad-soft: #f6dede;

  --code-bg: #0f1720;
  --code-text: #d5e3ea;

  --heading: "Manrope", "DM Sans", sans-serif;
  --mono: ui-monospace, Menlo, Consolas, monospace;

  --radius: 20px;
  --radius-sm: 12px;
  --radius-panel: 28px;
  --shadow-sm: none;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 16px -6px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 24px 64px -16px rgba(16, 24, 40, 0.28);
  --rail-w: 264px;
  --focus: 0 0 0 2px var(--accent);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --frame: #0a0b0d;
    --bg: #121417;
    --rail-bg: #121417;
    --surface: #1a1d21;
    --surface-2: #16181c;
    --surface-hover: #1f2226;
    --nav-hover: #23272c;
    --border: #2b2f35;
    --border-strong: #3e434b;
    --text: #ececef;
    --text-muted: #9ca1a9;
    --text-faint: #a3a8af;
    --eyebrow: #6fc3cf;
    --accent: #1fb0bf;
    --accent-hover: #0b96a6;
    --accent-ink: #5cc6d3;
    --accent-soft: #15333a;
    --accent-contrast: #ffffff;
    --button: #06808e;
    --button-hover: #0b96a6;
    --good: #a6dcb4;
    --good-soft: #17331f;
    --warn: #ecd18d;
    --warn-soft: #3a3115;
    --bad: #f0b3b3;
    --bad-soft: #3b1f1f;
    --code-bg: #0a0b0d;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px -6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 24px 64px -16px rgba(0, 0, 0, 0.6);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --frame: #0a0b0d;
  --bg: #121417;
  --rail-bg: #121417;
  --surface: #1a1d21;
  --surface-2: #16181c;
  --surface-hover: #1f2226;
  --nav-hover: #23272c;
  --border: #2b2f35;
  --border-strong: #3e434b;
  --text: #ececef;
  --text-muted: #9ca1a9;
  --text-faint: #a3a8af;
  --eyebrow: #6fc3cf;
  --accent: #1fb0bf;
  --accent-hover: #0b96a6;
  --accent-ink: #5cc6d3;
  --accent-soft: #15333a;
  --accent-contrast: #ffffff;
  --button: #06808e;
  --button-hover: #0b96a6;
  --good: #a6dcb4;
  --good-soft: #17331f;
  --warn: #ecd18d;
  --warn-soft: #3a3115;
  --bad: #f0b3b3;
  --bad-soft: #3b1f1f;
  --code-bg: #0a0b0d;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px -6px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 24px 64px -16px rgba(0, 0, 0, 0.6);
}

/* ================= Base ================= */

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--frame);
  color: var(--text);
}

a {
  color: var(--accent-ink);
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

::selection {
  background: var(--accent-soft);
}

:is(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.icon {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ================= Shell ================= */

/* The side menu and the page are rounded panels on a light frame, as in the Workspace. */
.console {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  gap: 14px;
  min-height: 100vh;
  padding: 14px;
  background: var(--frame);
}

/* ---------- Sidebar ---------- */

.rail {
  position: sticky;
  top: 14px;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 18px;
  height: calc(100vh - 28px);
  padding: 26px 16px 16px;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: thin;
  border-radius: var(--radius-panel);
  background: var(--rail-bg);
}

.brand {
  display: block;
  padding: 0 10px 14px;
  text-decoration: none;
  color: var(--text);
}

/* The Workspace wordmark, with the app name where the Workspace has WORKSPACE. */
.wordmark {
  display: block;
  font: 800 26px/1 var(--heading);
  letter-spacing: -1.2px;
}

.wordmark span {
  color: var(--accent);
  font-weight: 500;
}

.wordmark small {
  display: block;
  margin-top: 8px;
  font: 600 10px/1 "DM Sans", sans-serif;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--text-faint);
}

.rail-nav {
  display: grid;
  gap: 2px;
  align-content: start;
}

.rail-group-title {
  margin: 18px 0 6px;
  padding: 0 12px;
  font-size: 11.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1.3px;
  color: var(--text-muted);
}

.rail-group-title:first-child {
  margin-top: 0;
}

.rail-nav a {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 42px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-muted);
  font-size: 14px;
  transition: background-color 150ms ease, color 150ms ease;
}

.rail-nav a .icon {
  width: 18px;
  height: 18px;
}

.rail-nav a:hover {
  background: var(--nav-hover);
  color: var(--text);
}

.rail-nav a[data-active="true"] {
  color: var(--text);
  font-weight: 600;
}

.rail-nav a[data-active="true"] .icon {
  color: var(--accent);
}

/* The page you are on gets a bar on the menu's left edge. */
.rail-nav a[data-active="true"]::before {
  content: "";
  position: absolute;
  top: 6px;
  bottom: 6px;
  left: -16px;
  width: 5px;
  border-radius: 0 6px 6px 0;
  background: var(--accent);
}

/* Voice Lab numbers its sections instead of using icons */
.rail-nav-key {
  min-width: 18px;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-faint);
}

.rail-nav-grow {
  flex: 1;
}

.rail-customers {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  flex: 1;
}

.rail-customers-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px 0 12px;
}

.rail-customers-header h2 {
  margin: 0;
  font-size: 11.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1.3px;
  color: var(--text-muted);
}

.rail-add {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 999px;
  border: 0;
  background: var(--surface);
  color: var(--text-muted);
  transition: background-color 150ms ease, color 150ms ease;
}

.rail-add:hover {
  background: var(--nav-hover);
  color: var(--text);
}

.rail-note {
  margin: 0;
  padding: 0 12px;
  font-size: 0.8rem;
  color: var(--text-faint);
}

.rail-lab-link {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
}

.rail-lab-link:hover {
  background: var(--nav-hover);
}

.rail .tenant-list {
  display: grid;
  gap: 4px;
  overflow-y: auto;
  margin: 0;
}

/* Customers look like the Workspace's organisation card: white and rounded when chosen. */
.rail .tenant-item {
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  border-radius: 18px;
  border: 0;
  background: transparent;
  transition: background-color 150ms ease;
}

.rail .tenant-item:hover {
  background: var(--nav-hover);
}

.rail .tenant-item.active {
  background: var(--surface);
}

.rail .tenant-item strong,
.rail .tenant-item span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rail .tenant-item strong {
  font-size: 14px;
  font-weight: 600;
}

.rail .tenant-item span {
  margin-top: 2px;
  font-size: 11.5px;
  color: var(--text-muted);
}

/* ---------- Page panel & header ---------- */

.stage {
  display: grid;
  gap: 20px;
  align-content: start;
  min-width: 0;
  padding: 0 max(28px, calc((100% - 1400px) / 2)) 48px;
  border-radius: var(--radius-panel);
  background: var(--bg);
}

.stage section {
  scroll-margin-top: 140px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px 32px;
  flex-wrap: wrap;
  margin: 0 calc(-1 * max(28px, calc((100% - 1400px) / 2)));
  padding: 34px max(28px, calc((100% - 1400px) / 2)) 18px;
  border-radius: var(--radius-panel) var(--radius-panel) 0 0;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
}

.topbar-eyebrow {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--eyebrow);
}

.topbar h1 {
  margin: 0;
  font: 700 34px/1.15 var(--heading);
  letter-spacing: -1.3px;
}

.topbar-summary {
  margin: 8px 0 0;
  max-width: 640px;
  color: var(--text-muted);
  font-size: 14px;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.topbar-status {
  margin: 0;
  max-width: 340px;
  text-align: right;
}

/* ---------- Status strip ---------- */

.readout {
  display: grid;
  /* One row of however many cells are showing (advanced adds Engine). */
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.readout-cell {
  padding: 14px 18px;
  border-left: 1px solid var(--border);
  min-width: 0;
}

.readout-cell:first-child {
  border-left: none;
}

.readout-cell .label {
  display: block;
  font-size: 12.5px;
  color: var(--text-muted);
}

.readout-cell strong {
  display: block;
  margin-top: 2px;
  font-size: 14.5px;
  font-weight: 600;
  /* Wrap rather than cut off: agent names are long. */
  overflow-wrap: anywhere;
}

/* ================= Dashboard ================= */

.kpi-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 16px;
}

.kpi-tile {
  display: grid;
  gap: 4px;
  align-content: start;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 0;
}

.kpi-label {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
}

.kpi-value {
  font: 700 1.9rem/1.15 var(--heading);
  letter-spacing: -0.03em;
}

.kpi-sub {
  font-size: 12.5px;
  color: var(--text-muted);
}

.kpi-tile.is-loading .kpi-value {
  color: var(--text-faint);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr);
  gap: 20px;
  align-items: start;
}

.dashboard-main,
.dashboard-side {
  display: grid;
  gap: 20px;
  min-width: 0;
}

/* ---------- Bar chart (single series: calls per day) ---------- */

.bar-chart {
  position: relative;
  margin-top: 14px;
}

.bar-plot {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 168px;
  padding-top: 20px;
  border-bottom: 1px solid var(--border-strong);
}

.bar-gridline {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px solid var(--border);
  pointer-events: none;
}

.bar-gridline span {
  position: absolute;
  left: 0;
  top: -18px;
  font-size: 0.72rem;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.bar-col {
  position: relative;
  flex: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  height: 100%;
  border-radius: 6px 6px 0 0;
  cursor: default;
  outline: none;
}

.bar-col:hover,
.bar-col:focus-visible {
  background: var(--surface-hover);
}

.bar-col:focus-visible {
  box-shadow: var(--focus);
}

.bar {
  width: min(24px, 70%);
  border-radius: 4px 4px 0 0;
  background: var(--accent);
  transition: background-color 120ms ease;
}

.bar-col:hover .bar,
.bar-col:focus-visible .bar {
  background: var(--accent-hover);
}

.bar-axis {
  display: flex;
  gap: 2px;
  margin-top: 6px;
}

.bar-axis span {
  flex: 1;
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-faint);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.bar-tip {
  position: absolute;
  z-index: 5;
  transform: translate(-50%, calc(-100% - 8px));
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: var(--text);
  color: var(--bg);
  font-size: 0.78rem;
  line-height: 1.35;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: var(--shadow);
}

.bar-tip strong {
  display: block;
  font-size: 0.9rem;
}

.bar-chart-empty {
  display: grid;
  place-items: center;
  height: 168px;
  color: var(--text-faint);
  font-size: 0.88rem;
}

/* ================= Panels & shared components ================= */

.tab-panel {
  display: grid;
  gap: 20px;
  align-content: start;
  min-width: 0;
}

.tab-panel[hidden] {
  display: none;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 26px;
  min-width: 0;
}

.panel-header,
.subsection-header,
.control-row,
.sidebar-actions,
.editor-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.panel-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

/* Section numbers were dropped in v3 */
.panel-index {
  display: none;
}

.panel-header h2,
.subsection-header h3 {
  margin: 0;
  font: 600 18px/1.3 var(--heading);
  letter-spacing: -0.01em;
}

.panel-header h3 {
  margin: 0;
  font: 600 15px/1.3 var(--heading);
}

.inline-note {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 0.86rem;
}

.panel-header .inline-note {
  margin: 0;
}

/* ---------- Buttons ---------- */

.primary,
.secondary,
.ghost,
.file-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease, box-shadow 150ms ease;
}

.primary {
  background: var(--button);
  border-color: var(--button);
  color: #fff;
  padding: 0 22px;
}

.primary:hover:not(:disabled) {
  background: var(--button-hover);
  border-color: var(--button-hover);
}

.secondary {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.secondary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}

.ghost {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}

.ghost:hover:not(:disabled) {
  background: var(--surface-hover);
}

.icon-button {
  width: 40px;
  padding: 0;
}

.link-button {
  text-decoration: none;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

/* ---------- Forms ---------- */

.stacked-field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-size: 0.9rem;
}

.stacked-field .label,
.status-grid .label,
.editor-label {
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.status-grid .label {
  color: var(--text-muted);
  font-weight: 500;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 9px 12px;
  font-size: 14px;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

input:hover,
select:hover,
textarea:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border-strong));
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus);
}

.checkbox-field input[type="checkbox"] {
  width: 16px;
  height: 16px;
  min-height: 0;
  margin: 0;
  box-shadow: none;
  accent-color: var(--accent);
}

textarea {
  resize: vertical;
  min-height: 150px;
}

.editor-textarea {
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.6;
  background: var(--surface-2);
}

.short-textarea {
  min-height: 84px;
}

.inline-select {
  grid-auto-flow: column;
  align-items: center;
  gap: 10px;
}

.tenant-form {
  display: grid;
  gap: 24px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.full-width {
  grid-column: 1 / -1;
}

.subsection {
  border-top: 1px solid var(--border);
  padding-top: 20px;
}

/* ---------- Mode card ---------- */

.mode-bar-row {
  align-items: flex-end;
  margin-top: 14px;
}

.mode-field {
  flex: 1;
  min-width: 0;
}

/* ---------- Status ---------- */

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.status-grid > div {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 9px 12px;
  min-width: 0;
}

.status-grid strong {
  display: block;
  margin-top: 2px;
  font-size: 0.9rem;
  font-weight: 600;
  word-break: break-word;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--surface-hover);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.status-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.8;
}

.status-badge[data-tone="success"] {
  background: var(--good-soft);
  color: var(--good);
}

.status-badge[data-tone="danger"] {
  background: var(--bad-soft);
  color: var(--bad);
}

.status-badge[data-tone="warning"] {
  background: var(--warn-soft);
  color: var(--warn);
}

.status-badge[data-tone="neutral"] {
  background: var(--surface-hover);
  color: var(--text-muted);
}

.pbx-status-panel {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.pbx-status-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-console {
  margin: 12px 0 0;
  padding: 14px;
  min-height: 84px;
  overflow: auto;
  border-radius: var(--radius-sm);
  background: var(--code-bg);
  color: var(--code-text);
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.status-console:empty::before {
  content: "// no output yet";
  opacity: 0.5;
}

/* ---------- Routes ---------- */

.route-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.route-list:empty::before {
  content: "No transfer routes yet. Add one to route callers to a person.";
  color: var(--text-faint);
  font-size: 0.86rem;
}

.route-row {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) minmax(200px, 1.4fr) auto;
  gap: 10px;
  align-items: center;
}

.route-destination {
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.route-destination select,
.route-destination input {
  flex: 1 1 0;
  min-width: 0;
}

/* Online dot next to a picked Yeastar extension. */
.presence-dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--border-strong);
}

.presence-dot[data-online="true"] {
  background: var(--good);
}

@media (max-width: 640px) {
  .route-row {
    grid-template-columns: 1fr;
  }
}

/* Business facts as plain fields (the JSON stays under Advanced). */
.facts-editor {
  display: grid;
  gap: 16px;
}

.facts-group {
  display: grid;
  gap: 10px;
}

.facts-group h4 {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.facts-group textarea {
  min-height: 0;
  resize: vertical;
}

.advanced-block {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.advanced-block h3 {
  margin: 0 0 6px;
}

/* ---------- Knowledge editor ---------- */

.editor-layout {
  display: grid;
  grid-template-columns: minmax(220px, 260px) minmax(0, 1fr);
  gap: 18px;
  margin-top: 16px;
}

.editor-sidebar,
.editor-main {
  display: grid;
  gap: 10px;
  align-content: start;
}

.file-list {
  display: grid;
  gap: 4px;
}

.file-item {
  width: 100%;
  justify-content: flex-start;
  padding: 8px 12px;
  background: transparent;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.8rem;
}

.file-item:hover {
  background: var(--surface-hover);
}

.file-item.active {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.selected-file {
  min-height: 22px;
  font-family: var(--mono);
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--accent-ink);
}

/* ================= Calls ================= */

.call-list {
  display: grid;
  margin-top: 12px;
}

/* Company logins see minutes, not AI cost: the cost column is dropped. */
body:not([data-role="admin"]) .call-row-cost {
  display: none;
}

@media (min-width: 961px) {
  body:not([data-role="admin"]) .call-row {
    grid-template-columns: 116px minmax(0, 1.3fr) 60px minmax(0, 1.5fr);
  }
}

.call-row {
  display: grid;
  grid-template-columns: 116px minmax(0, 1.3fr) 60px minmax(0, 1.5fr) 56px;
  gap: 14px;
  align-items: center;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-top: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  text-align: left;
  font-size: 0.86rem;
  transition: background-color 100ms ease;
}

button.call-row:hover {
  background: var(--surface-hover);
}

button.call-row:focus-visible {
  border-radius: var(--radius-sm);
}

.call-row-head {
  border-top: none;
  padding-top: 0;
  padding-bottom: 8px;
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--text-faint);
}

.call-row-when,
.call-row-duration {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.call-row-who {
  display: grid;
  min-width: 0;
}

.call-row-who strong,
.call-row-who span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.call-row-who strong {
  font-weight: 600;
}

.call-row-who span {
  font-size: 0.78rem;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.call-row-result {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.call-row-result > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calls-quality {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.calls-quality-head {
  margin: 0;
  font-size: 0.86rem;
  font-weight: 600;
}

.calls-quality-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.quality-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.quality-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 0.86rem;
  color: var(--text-muted);
}

.call-row-cost {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.calls-all-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  font-size: 0.86rem;
  font-weight: 500;
  text-decoration: none;
}

.calls-all-link:hover {
  text-decoration: underline;
}

.calls-more {
  margin-top: 14px;
}

.call-stat {
  display: grid;
  gap: 2px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  min-width: 0;
}

.call-stat strong {
  font: 700 1.15rem/1.2 var(--heading);
  line-height: 1.2;
}

.call-stat span {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.call-card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

/* ---------- Call detail sheet ---------- */

.call-detail {
  margin: 0 0 0 auto;
  width: min(780px, 100vw);
  max-width: 100vw;
  height: 100vh;
  max-height: 100vh;
  padding: 0;
  border: none;
  border-left: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.call-detail[open] {
  animation: sheet-in 180ms ease-out;
}

.call-detail::backdrop {
  background: rgba(10, 16, 24, 0.38);
  backdrop-filter: blur(2px);
}

@keyframes sheet-in {
  from {
    transform: translateX(32px);
    opacity: 0;
  }
}

.call-detail-close {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: flex-end;
  height: 0;
  padding: 0 16px;
}

.call-detail-close button {
  margin-top: 16px;
}

#call-detail-body {
  display: grid;
  gap: 16px;
  padding: 24px 24px 48px;
}

.call-detail-header {
  display: grid;
  gap: 10px;
  padding-right: 48px;
}

.call-detail-header h2 {
  margin: 0;
  font: 700 1.6rem/1.2 var(--heading);
  letter-spacing: -0.02em;
}

.caller-name {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  margin-top: 4px;
  font-size: 0.85rem;
}

.caller-name:empty {
  display: none;
}

.caller-name-source {
  color: var(--text-muted);
}

.caller-name .link-button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent-ink);
  font-weight: 600;
  cursor: pointer;
}

.caller-name-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin-top: 6px;
}

.caller-name-form[hidden] {
  display: none;
}

.caller-name-form .inline-note {
  margin: 0;
}

.caller-name-form .full-row {
  grid-column: 1 / -1;
}

@media (max-width: 640px) {
  .caller-name-form {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
}

.call-detail-sub {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 0.86rem;
  font-variant-numeric: tabular-nums;
}

.call-detail-section {
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}

.call-detail-section h3 {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 600;
}

.call-detail-section h4 {
  margin: 18px 0 8px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-muted);
}

.call-detail-section > .inline-note {
  margin-top: 2px;
  font-size: 0.8rem;
}

.call-detail-summary {
  margin: 10px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.call-detail-facts {
  display: grid;
  grid-template-columns: minmax(110px, max-content) minmax(0, 1fr);
  gap: 7px 18px;
  margin: 12px 0 0;
  font-size: 0.88rem;
}

.call-detail-facts dt {
  color: var(--text-muted);
}

.call-detail-facts dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.call-detail-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.table-scroll {
  overflow-x: auto;
}

.call-detail-table {
  width: 100%;
  margin-top: 12px;
  border-collapse: collapse;
  font-size: 0.84rem;
}

.call-detail-table th,
.call-detail-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.call-detail-table th {
  font-weight: 500;
  font-size: 0.78rem;
  color: var(--text-faint);
}

.call-detail-table tfoot th {
  color: var(--text);
  font-weight: 600;
  font-size: 0.86rem;
  border-bottom: none;
}

.call-detail-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.call-recording {
  display: grid;
  gap: 6px;
  justify-items: start;
  margin-top: 12px;
}

.ghost-link {
  color: var(--accent-ink);
  font-size: 0.86rem;
}

.call-recording audio {
  width: 100%;
  justify-self: stretch;
}

.call-timeline {
  display: grid;
  gap: 0;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.84rem;
}

.call-timeline li {
  position: relative;
  display: grid;
  grid-template-columns: 52px minmax(0, max-content) minmax(0, 1fr);
  gap: 10px;
  align-items: baseline;
  padding: 6px 0 6px 18px;
  border-left: 2px solid var(--border);
  margin-left: 4px;
}

.call-timeline li::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 12px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--border-strong);
}

.call-timeline li[data-tone="success"]::before {
  border-color: var(--good);
  background: var(--good);
}

.call-timeline li[data-tone="warning"]::before {
  border-color: var(--warn);
  background: var(--warn);
}

.call-timeline li > span:last-child {
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.call-timeline-at {
  font-variant-numeric: tabular-nums;
  color: var(--text-faint);
}

.call-technical {
  margin-top: 10px;
}

.call-technical summary,
.preview-step summary,
.sim-ticket summary {
  cursor: pointer;
  font-weight: 500;
  font-size: 0.88rem;
}

/* ---------- Transcripts & logs ---------- */

.sim-log,
.review-transcript {
  display: grid;
  gap: 8px;
  align-content: start;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  overflow-y: auto;
}

.sim-log {
  min-height: 280px;
  max-height: 460px;
}

.review-transcript {
  margin-top: 12px;
  max-height: 520px;
}

.sim-line {
  display: grid;
  gap: 2px;
  max-width: 88%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 0.9rem;
}

.sim-agent {
  justify-self: start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.sim-caller {
  justify-self: end;
  background: var(--accent-soft);
  border-bottom-right-radius: 4px;
}

.sim-speaker {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-faint);
}

.sim-agent .sim-speaker {
  color: var(--accent-ink);
}

.sim-text {
  overflow-wrap: anywhere;
}

.sim-tool {
  justify-self: stretch;
  max-width: none;
  padding: 4px 12px;
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--text-muted);
}

.log {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.log:empty::before {
  content: "Start a browser test to see the live transcript here.";
  color: var(--text-faint);
  font-size: 0.86rem;
}

.log-entry {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  background: var(--surface-2);
}

.log-entry strong {
  display: block;
  margin-bottom: 2px;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-muted);
}

.log-entry p {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.log-entry.system {
  background: var(--accent-soft);
  border-color: transparent;
}

.log-entry.system strong {
  color: var(--accent-ink);
}

.log-entry.error {
  background: var(--bad-soft);
  border-color: transparent;
}

.log-entry.error strong {
  color: var(--bad);
}

/* ================= Call flow editor & simulator ================= */

.flow-settings {
  margin-top: 18px;
}

.category-list {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.category-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.category-card-header {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.category-card-step {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.sim-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(260px, 1fr);
  gap: 18px;
  margin-top: 16px;
}

.sim-chat {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.sim-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
}

.sim-state {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  min-width: 0;
}

.sim-state h3 {
  margin: 0 0 10px;
  font-size: 0.92rem;
  font-weight: 600;
}

.sim-state-list {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 6px 14px;
  margin: 0;
  font-size: 0.86rem;
}

.sim-state-list dt {
  color: var(--text-muted);
}

.sim-state-list dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.sim-warning {
  margin: 10px 0 0;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 0.84rem;
}

.flow-preview {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.preview-step,
.sim-ticket {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  background: var(--surface-2);
}

.sim-ticket {
  margin-top: 12px;
}

.preview-step summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  align-items: baseline;
}

.preview-tools {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-muted);
}

.sim-ticket pre,
.preview-step pre {
  margin: 10px 0 0;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: var(--code-bg);
  color: var(--code-text);
  font-family: var(--mono);
  font-size: 0.76rem;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 420px;
  overflow-y: auto;
}

/* ================= Voice Lab ================= */

.voice-filter-bar,
.greeting-field {
  margin-top: 16px;
}

.voice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.voice-filter-bar {
  display: flex;
  gap: 12px;
}

.voice-filter {
  width: min(240px, 100%);
}

.voice-card {
  padding: 16px;
}

.voice-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.voice-card-badges {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.voice-card h3 {
  margin: 0;
  font-size: 0.96rem;
  font-weight: 600;
}

.voice-card-actions {
  display: flex;
  gap: 8px;
  margin: 14px 0 12px;
}

.voice-label-badge,
.voice-favorite-button {
  display: inline-grid;
  place-items: center;
  width: 28px;
  min-width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1;
}

.voice-favorite-button:hover {
  border-color: var(--accent);
}

.voice-favorite-button[data-active="true"],
.voice-label-badge[data-label="male"],
.voice-label-badge[data-label="female"] {
  border-color: transparent;
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.voice-label-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.voice-label-controls .ghost {
  min-height: 28px;
  padding: 0 10px;
  font-size: 0.78rem;
}

.voice-label-controls .ghost[data-active="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.voice-audio {
  width: 100%;
  margin-top: 12px;
}

/* ================= Responsive ================= */

@media (max-width: 1320px) {
  .kpi-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .readout {
    grid-auto-flow: row;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .readout-cell:nth-child(4) {
    border-left: none;
  }

  .readout-cell:nth-child(n + 4) {
    border-top: 1px solid var(--border);
  }
}

@media (max-width: 1180px) {
  .dashboard-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .sim-layout,
  .category-card-step {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 960px) {
  .console {
    grid-template-columns: 1fr;
  }

  .rail {
    position: static;
    height: auto;
  }

  .rail-nav a[data-active="true"]::before {
    display: none;
  }

  .rail-nav a[data-active="true"] {
    background: var(--surface);
  }

  .rail-nav {
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  }

  .rail-group-title {
    grid-column: 1 / -1;
  }

  .rail .tenant-list {
    max-height: 220px;
  }

  .editor-layout {
    grid-template-columns: 1fr;
  }

  .call-row {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "who cost"
      "when duration"
      "result result";
    gap: 4px 12px;
  }

  .call-row-head {
    display: none;
  }

  .call-row-who {
    grid-area: who;
  }

  .call-row-when {
    grid-area: when;
    font-size: 0.78rem;
  }

  .call-row-duration {
    grid-area: duration;
    text-align: right;
    font-size: 0.78rem;
  }

  .call-row-result {
    grid-area: result;
  }

  .call-row-cost {
    grid-area: cost;
  }
}

@media (max-width: 720px) {
  .console {
    gap: 10px;
    padding: 8px;
  }

  .rail,
  .stage {
    border-radius: 22px;
  }

  .stage {
    padding: 0 16px 48px;
  }

  .topbar {
    position: static;
    margin: 0 -16px;
    padding: 22px 16px 6px;
    border-radius: 22px 22px 0 0;
  }

  .topbar h1 {
    font-size: 28px;
  }

  .topbar-actions {
    width: 100%;
  }

  .topbar-status {
    flex: 1;
    text-align: left;
    max-width: none;
  }

  .kpi-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .kpi-value {
    font-size: 1.4rem;
  }

  .readout {
    grid-template-columns: 1fr 1fr;
  }

  .readout-cell {
    border-left: none;
    border-top: 1px solid var(--border);
  }

  .readout-cell:nth-child(-n + 2) {
    border-top: none;
  }

  .readout-cell:nth-child(even) {
    border-left: 1px solid var(--border);
  }

  .form-grid,
  .route-row,
  .category-card-header,
  .sim-form {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 16px;
  }

  .panel-header,
  .subsection-header,
  .control-row,
  .sidebar-actions,
  .editor-actions,
  .mode-bar-row {
    flex-wrap: wrap;
  }

  .call-detail-kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #call-detail-body {
    padding: 16px 16px 40px;
  }

  .call-detail-facts {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .call-detail-facts dd {
    margin-bottom: 8px;
  }

  .call-timeline li {
    grid-template-columns: 44px minmax(0, 1fr);
  }

  .call-timeline li > span:last-child {
    grid-column: 2;
  }
}

@media (max-width: 720px) {
  /* every fourth day on narrow screens; labelled days are the odd ones from the end */
  .bar-axis span:nth-last-child(4n + 3) {
    visibility: hidden;
  }
}

/* ---------------------------------------------------------------- sign-in and client logins */

[hidden] {
  display: none !important;
}

/* Company logins (manager, user, client) never see admin-only controls;
   [data-roles] lists who may see an element (set up in applyRole). */
body:not([data-role="admin"]) [data-admin-only],
[data-roles-hidden] {
  display: none !important;
}

/* Basic view hides the technical settings; "Show advanced settings" brings them back. */
body:not([data-view="advanced"]) [data-advanced],
body[data-view="advanced"] [data-basic] {
  display: none !important;
}

.sign-in {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px 16px;
}

.sign-in {
  background: var(--bg);
}

.sign-in-card {
  display: grid;
  gap: 16px;
  width: min(400px, 100%);
  padding: 34px 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  background: var(--surface);
}

.sign-in-card .wordmark {
  margin-bottom: 10px;
}

.sign-in-card h1 {
  margin: 0;
  font: 700 26px/1.2 var(--heading);
  letter-spacing: -0.8px;
}

.sign-in-card .primary {
  min-height: 46px;
}

.sign-in-card input {
  width: 100%;
}

.sign-in-error {
  margin: 0;
  min-height: 1.2em;
  color: var(--bad);
  font-size: 0.86rem;
}

.rail-account {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: auto;
  padding: 8px 6px 0;
}

.rail-account-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Light/dark switch, as in the Workspace's top bar. */
.theme-toggle {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
}

.theme-toggle:hover {
  background: var(--nav-hover);
  color: var(--text);
}

.theme-toggle .icon {
  width: 18px;
  height: 18px;
}

.theme-sun {
  display: none;
}

:root[data-theme="dark"] .theme-moon {
  display: none;
}

:root[data-theme="dark"] .theme-sun {
  display: inline;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-moon {
    display: none;
  }

  :root:not([data-theme="light"]) .theme-sun {
    display: inline;
  }
}

.rail-account .rail-note {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.login-create {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin-top: 12px;
}

.login-create .stacked-field {
  flex: 1 1 200px;
}

.login-password {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
}

.login-password p {
  margin: 0;
}

.login-password-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.login-password-row code {
  font-size: 1rem;
  user-select: all;
}

.logins-list {
  display: grid;
  margin-top: 8px;
}

.login-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}

.login-row-who {
  display: grid;
  min-width: 0;
  font-size: 0.86rem;
}

.login-row-who span {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.login-row-actions {
  display: flex;
  gap: 8px;
}

.danger-text {
  color: var(--bad);
}

.agent-form {
  display: grid;
  gap: 14px;
}

/* ---------- Agents page: inbound and outbound in their own sections, never mixed ---------- */

.agents-intro {
  margin: 0;
  max-width: 76ch;
}

#agents-status:empty {
  display: none;
}

.agents-sections {
  display: grid;
  gap: 20px;
  margin: 16px 0 20px;
}

.agents-direction {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.agents-section-head {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.agents-section-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.agents-section-icon .icon {
  width: 20px;
  height: 20px;
}

.agents-section-title {
  flex: 1;
  min-width: 0;
}

.agents-section-title h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-family: var(--heading);
  font-size: 1.15rem;
}

.agents-section-title .inline-note {
  margin: 2px 0 0;
}

.agents-count:empty {
  display: none;
}

.agents-count {
  padding: 1px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: "DM Sans", Arial, sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
}

.agents-new {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
}

/* The section's calls in one strip: an icon, the number, what it is. */
.agents-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.agents-stats:empty {
  display: none;
}

.agents-stat {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 14px 16px;
}

.agents-stat + .agents-stat {
  border-left: 1px solid var(--border);
}

.agents-stat-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--accent-ink);
}

.agents-stat-text {
  display: grid;
  min-width: 0;
}

.agents-stat-value {
  font: 700 1.25rem/1.2 var(--heading);
  letter-spacing: -0.02em;
}

.agents-stat-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
}

.agents-stat-sub {
  font-size: 0.76rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Agent cards: number and name, then one line per setting ---------- */

.agent-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 14px;
}

.agent-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.agent-card.is-default {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
}

.agent-card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.agent-number {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font: 700 1rem/1 var(--heading);
}

.agent-card.is-default .agent-number {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent-ink);
}

.agent-card-title {
  display: grid;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.agent-card-name {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.agent-card-name strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--heading);
  font-size: 1rem;
}

.agent-card-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.agent-card-sub span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-card-sub .icon {
  width: 14px;
  height: 14px;
  color: var(--accent-ink);
}

.agent-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: none;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 0.72rem;
  font-weight: 700;
}

.agent-tag .icon {
  width: 12px;
  height: 12px;
  fill: currentColor;
}

.agent-tag.is-muted {
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* Its settings, one per line: icon, what it is, the value. */
.agent-specs {
  display: grid;
  gap: 0;
  margin: 0;
  border-top: 1px solid var(--border);
}

.agent-spec {
  display: grid;
  grid-template-columns: 18px 104px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.agent-spec .icon {
  color: var(--text-muted);
}

.agent-spec dt {
  color: var(--text-muted);
}

.agent-spec dd {
  margin: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.agent-spec dd.is-off {
  color: var(--text-muted);
  font-weight: 400;
}

/* Its calls in the last 30 days: four figures in a 2 x 2 box. */
.agent-card-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
}

.agent-stat {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  font-size: 0.8rem;
  color: var(--text);
  white-space: nowrap;
}

.agent-stat span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.agent-stat .icon {
  width: 14px;
  height: 14px;
  color: var(--accent-ink);
}

.agent-card-quiet {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.agent-card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: auto;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.agent-card-foot > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-card-foot .ghost {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  height: 34px;
  padding: 0 14px;
  font-size: 0.84rem;
}

.agents-empty {
  margin: 0;
  padding: 18px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.86rem;
  text-align: center;
}

@media (max-width: 1100px) {
  .agents-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .agents-stat:nth-child(3) {
    border-left: 0;
  }

  .agents-stat:nth-child(n + 3) {
    border-top: 1px solid var(--border);
  }
}

@media (max-width: 640px) {
  .agents-section-head {
    flex-wrap: wrap;
  }

  .agents-section-icon {
    display: none;
  }

  .agents-new {
    width: 100%;
    justify-content: center;
  }

  .agent-cards {
    grid-template-columns: minmax(0, 1fr);
  }

  .agent-spec {
    grid-template-columns: 18px 88px minmax(0, 1fr);
  }

  .agents-stat {
    padding: 12px;
    gap: 10px;
  }

  .agents-stat-icon {
    display: none;
  }
}

/* ---------- Overview: inbound and outbound numbers in their own groups ---------- */

.kpi-groups {
  display: grid;
  gap: 18px;
}

.kpi-group {
  display: grid;
  gap: 10px;
}

.kpi-group-title,
.chart-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  margin: 0;
  font-family: var(--heading);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.kpi-group-title span,
.chart-title span {
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
}

.chart-title {
  margin-top: 16px;
  font-size: 0.92rem;
}

/* ---------- Calls page: show all, inbound or outbound ---------- */

.direction-filter {
  display: inline-flex;
  margin-left: auto;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
}

.direction-filter button {
  padding: 5px 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.direction-filter button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 0 0 1px var(--border);
}

.direction-filter button:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

.agent-form textarea {
  min-height: 160px;
}

/* A field with a note under it doesn't stretch its neighbour's box. */
.agent-form .stacked-field {
  align-content: start;
}

.agent-form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* ---------- Outbound calls ---------- */

.outbound-header-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.outbound-attention {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 0.9rem;
  font-weight: 500;
}

.outbound-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.outbound-controls[hidden],
.outbound-controls [hidden] {
  display: none;
}

.outbound-instruct,
.outbound-handback {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: end;
  gap: 12px;
  margin-top: 14px;
}

.outbound-handback {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
}

.outbound-instruct[hidden],
.outbound-handback[hidden] {
  display: none;
}

.outbound-instruct .checkbox-field,
.outbound-handback .checkbox-field {
  min-height: 36px;
  white-space: nowrap;
}

.outbound-transcript {
  margin-top: 16px;
  min-height: 200px;
  max-height: 480px;
}

.sim-line.outbound-paused-turn {
  background: transparent;
  border: 1px dashed var(--border-strong);
}

.outbound-result {
  display: grid;
  gap: 4px;
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--good-soft);
  font-size: 0.9rem;
}

.outbound-result p {
  margin: 0;
  overflow-wrap: anywhere;
}

.outbound-phone-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

#outbound-phone-new {
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.6fr);
}

.outbound-phone-row[hidden] {
  display: none;
}

.outbound-phone-row > .ghost {
  justify-self: start;
}

.outbound-more summary {
  cursor: pointer;
  font-weight: 500;
  font-size: 0.88rem;
}

.outbound-more .form-grid {
  margin-top: 12px;
}

.outbound-row-wrap {
  display: flex;
  gap: 6px;
  align-items: stretch;
}

.outbound-row-wrap .outbound-row {
  flex: 1;
  min-width: 0;
}

.outbound-row-wrap .ghost {
  flex: none;
  font-size: 0.85rem;
}

.outbound-submit-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.outbound-submit-row .inline-note {
  margin: 0;
}

.outbound-list {
  display: grid;
  gap: 6px;
  margin-top: 12px;
}

.outbound-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  text-align: left;
  font-size: 0.88rem;
}

.outbound-row:hover {
  background: var(--surface-hover);
}

.outbound-row span {
  color: var(--text-muted);
}

@media (max-width: 720px) {
  .outbound-instruct,
  .outbound-handback {
    grid-template-columns: minmax(0, 1fr);
  }

  .outbound-row {
    flex-direction: column;
  }

  .outbound-phone-row {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ---------- Outbound questions with conditional follow-ups ---------- */

.question-list {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.question-list:empty {
  display: none;
}

.question-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.question-row,
.follow-up-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.follow-up-list {
  display: grid;
  gap: 8px;
  padding-left: 18px;
  border-left: 2px solid var(--accent-soft);
}

.follow-up-list:empty {
  display: none;
}

.follow-up-row {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
}

.follow-up-add {
  justify-self: start;
}


/* ---------- Make a call: two columns, then a footer to call from ---------- */

.outbound-new-header {
  flex-wrap: wrap;
  gap: 10px 16px;
}

.template-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.template-picker {
  display: flex;
  align-items: center;
  gap: 8px;
}

.template-picker .label {
  margin: 0;
}

.template-picker select {
  min-width: 200px;
}

.template-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.outbound-form {
  display: grid;
  gap: 16px;
  margin-top: 14px;
}

.outbound-columns {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
  gap: 16px;
  align-items: start;
}

.outbound-card {
  display: grid;
  gap: 14px;
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.outbound-card-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-family: var(--heading);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.step-number {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 0.8rem;
}

.label .optional {
  margin-left: 4px;
  font-weight: 400;
  color: var(--text-faint);
}

.outbound-questions {
  display: grid;
  gap: 8px;
}

.outbound-questions .question-list {
  margin-top: 0;
}

.outbound-questions .inline-note {
  margin: 0;
}

.add-row-button {
  justify-self: stretch;
  padding: 10px 12px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--accent-ink);
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}

.add-row-button:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
}

.outbound-more {
  padding: 0 4px;
}

.outbound-column {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.outbound-join {
  gap: 10px;
}

.outbound-join .inline-note {
  margin: 0;
}

.outbound-footer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 14px 24px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.outbound-footer .outbound-more summary {
  padding: 10px 0;
}

.outbound-footer .outbound-submit-row {
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

/* Questions: numbered rows, follow-ups read "If … ask …". */
.question-list {
  counter-reset: question;
}

.question-card {
  counter-increment: question;
}

.question-row {
  grid-template-columns: auto minmax(0, 1fr) auto;
}

.question-number::before {
  content: counter(question) ".";
  font-weight: 700;
  color: var(--text-muted);
}

.follow-up-row {
  grid-template-columns: auto minmax(0, 1fr) auto minmax(0, 1fr) auto;
}

.follow-up-word {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.remove-button {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.remove-button:hover {
  background: var(--bad-soft);
  color: var(--bad);
}

.question-card .follow-up-add {
  justify-self: start;
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--accent-ink);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.outbound-questions > .label {
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.outbound-footer #outbound-submit {
  min-width: 160px;
  padding-block: 12px;
  font-size: 1rem;
}

.outbound-footer .outbound-submit-row .inline-note {
  max-width: 340px;
  text-align: right;
}

@media (max-width: 1000px) {
  .outbound-columns {
    grid-template-columns: minmax(0, 1fr);
  }

  /* One column: who, what, then you. */
  .outbound-column {
    display: contents;
  }

  .outbound-columns .outbound-join {
    order: 1;
  }
}

@media (max-width: 640px) {
  .template-picker,
  .template-picker select {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
  }

  .outbound-footer {
    grid-template-columns: minmax(0, 1fr);
  }

  .outbound-footer .outbound-submit-row {
    align-items: stretch;
    width: 100%;
  }

  /* If [condition] ×
     ask [question] */
  .follow-up-row {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .follow-up-row > :nth-child(3) {
    grid-area: 2 / 1;
  }

  .follow-up-row > :nth-child(4) {
    grid-area: 2 / 2;
  }

  .follow-up-row > :nth-child(5) {
    grid-area: 1 / 3;
  }

  .outbound-footer .outbound-submit-row .inline-note {
    text-align: left;
  }
}

/* ---------- API keys page ---------- */

.settings-keys {
  display: grid;
  margin-top: 8px;
}

.settings-key {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
  gap: 10px 18px;
  align-items: center;
  padding: 14px 0;
  border-top: 1px solid var(--border);
}

.settings-key-who {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.settings-key-who span {
  color: var(--text-muted);
  font-size: 0.86rem;
}

.settings-key-state[data-set="true"] {
  color: var(--good);
}

.settings-key-edit {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.settings-key-edit input {
  flex: 1 1 220px;
  min-width: 0;
}

@media (max-width: 760px) {
  .settings-key {
    grid-template-columns: 1fr;
  }
}
