:root {
  /* Light theme, matched to the borrower-facing checkout page so the two
     read as one product. Every pair below is WCAG-AA-verified (4.5:1 for
     text, 3:1 for interactive-element borders) against the surface it is
     actually used on; the check lives in the commit that set them. */
  --ink: #ffffff;          /* topbar */
  --bg: #f4f6f8;           /* page background, 13.9:1 with --text */
  --panel: #ffffff;        /* cards, table, modals */
  --border: #e2e6ea;       /* decorative dividers - intentionally subtle */
  --border-strong: #78828f; /* input/interactive boundaries, 3:1+ on bg and panel */
  --hover: #eef1f5;        /* row / nav hover surface */
  --raised: #e6eaef;       /* chips, bars, code - one step up from panel */
  --text: #1c2430;         /* primary text */
  --subtle: #5b6470;       /* secondary text, 5.9:1 on panel */

  --accent: #3564c7;       /* primary button fill - white text is 5.5:1 on this */
  --accent-hover: #2a53ad;
  --accent-text: #2452b3;  /* accent used as foreground text/links, 7.0:1 on panel */

  --overlay: rgba(20, 28, 40, 0.45);
  --shadow: 0 18px 48px rgba(20, 28, 40, 0.18);

  /* Status colours: dark text on a light tint of the same hue. */
  --green: #166534;   --green-bg: #dcfce7;   --green-border: #86efac;
  --amber: #92400e;   --amber-bg: #fef3c7;
  --blue: #1e40af;    --blue-bg: #dbeafe;
  --red: #991b1b;     --red-bg: #fee2e2;     --red-border: #fca5a5;
  --teal: #115e59;    --teal-bg: #ccfbf1;

  /* Community/segment palette (8 slots, cycled by community % 8). Single
     source of truth for both the .segment-badge.cN rules below and the
     network canvas + legend in dashboard/app.js (read via getComputedStyle),
     so the two never drift out of sync. The --cN value doubles as the node
     fill on the canvas, which is why these are the dark end of each hue. */
  --c0: #1e40af; --c0-bg: #dbeafe;
  --c1: #115e59; --c1-bg: #ccfbf1;
  --c2: #92400e; --c2-bg: #fef3c7;
  --c3: #991b1b; --c3-bg: #fee2e2;
  --c4: #6b21a8; --c4-bg: #f3e8ff;
  --c5: #166534; --c5-bg: #dcfce7;
  --c6: #854d0e; --c6-bg: #fef9c3;
  --c7: #155e75; --c7-bg: #cffafe;

  /* Type scale - 9 sizes, each with one job, replacing what used to be 12
     scattered hardcoded values with no consistent logic. */
  --fs-2xs: 11px;   /* tertiary meta: timestamps, tool names */
  --fs-xs: 12px;    /* labels, badges, table headers */
  --fs-sm: 13px;    /* default body/secondary text */
  --fs-base: 14px;  /* content that wants slight emphasis over body */
  --fs-md: 15px;    /* emphasized body, submit buttons */
  --fs-lg: 18px;    /* card/modal headings */
  --fs-xl: 20px;    /* view-level headings */
  --fs-2xl: 24px;   /* page-level headings, stat values */
  --fs-display: 36px; /* the one hero number (checkout amount) */

  /* Control metrics. The type scale above gave font sizes one job each; the
     gaps between buttons never got the same treatment, so the four places
     buttons sit side by side had drifted to three different values (a 6px
     margin hack, 8px and 10px) plus a stray 4px margin on the delete icon.
     One gap token, and one height token so a cluster's buttons are the same
     box whatever tier they are. */
  --gap-actions: 8px;   /* between sibling controls, everywhere */
  --control-h: 30px;    /* standard button height */
  --control-h-sm: 26px; /* the compact in-table variant */
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--ink);
  color: var(--text);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
}

.brand {
  font-weight: 700;
  font-size: var(--fs-lg);
  letter-spacing: -0.02em;
}

.clock {
  display: flex;
  align-items: center;
  gap: var(--gap-actions);
  font-size: var(--fs-sm);
}

.clock-label { color: var(--subtle); }

#clockValue {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

/* ---- Buttons: three tiers, consistent everywhere ----------------------
   Primary (bare <button>) = the routine, expected action in context.
   Secondary (.ghost) = anything else that isn't destructive.
   Danger (.btn-danger) = irreversible or high-consequence - always red,
   never blends in with the buttons beside it. */

button {
  font: inherit;
  font-size: var(--fs-sm);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  padding: 6px 12px;
  min-height: var(--control-h);
  border-radius: 6px;
  cursor: pointer;
}

button:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button:disabled { opacity: 0.6; cursor: default; }

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

button.ghost:hover { background: var(--hover); }

/* An <a> styled as a ghost button, for links that sit in a button cluster. */
.button-link {
  display: inline-flex;
  align-items: center;
  min-height: var(--control-h);
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-size: var(--fs-sm);
  color: var(--text);
  text-decoration: none;
}
.button-link:hover { background: var(--hover); }

.btn-danger {
  background: var(--red-bg);
  color: var(--red);
  border-color: transparent;
}

.btn-danger:hover { background: var(--red); color: #fff; }

#app { max-width: 1100px; margin: 0 auto; padding: 24px; }

.hidden { display: none !important; }

.metrics-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}

.metric .value { font-size: var(--fs-2xl); font-weight: 700; }
.metric .label { font-size: var(--fs-xs); color: var(--subtle); text-transform: uppercase; letter-spacing: 0.04em; }

.debt-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.debt-table th {
  text-align: left;
  font-size: var(--fs-xs);
  color: var(--subtle);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.debt-table td {
  padding: 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.debt-table tr:last-child td { border-bottom: none; }
.debt-table tr.clickable { cursor: pointer; }
.debt-table tr.clickable:hover { background: var(--hover); }

.borrower-name { font-weight: 600; }
.subtle { color: var(--subtle); font-size: var(--fs-sm); }

/* Shared pill shape for .status, .count-badge, .segment-badge below. */
.status, .count-badge, .segment-badge {
  display: inline-block;
  border-radius: 999px;
  font-size: var(--fs-xs);
}

.status {
  padding: 3px 9px;
  font-weight: 600;
  text-transform: none;
}

.status.new, .status.scheduled { background: var(--blue-bg); color: var(--blue); }
.status.calling { background: var(--teal-bg); color: var(--teal); }
.status.no_answer, .status.missed { background: var(--amber-bg); color: var(--amber); }
.status.promised, .status.link_sent { background: var(--blue-bg); color: var(--blue); }
.status.paid { background: var(--green-bg); color: var(--green); }
.status.needs_review { background: var(--red-bg); color: var(--red); }

.row-run {
  font-size: var(--fs-xs);
  padding: 5px 10px;
  min-height: var(--control-h-sm);
  white-space: nowrap;
}

/* The actions column is narrow enough that its buttons wrap to two lines on
   most widths. They used to be inline-blocks separated by `.row-run +
   .row-run { margin-left }`, and that margin kept applying after the wrap -
   so the stacked button sat 6px right of the one above it, at its own
   intrinsic width. Flex + gap spaces them without leaking into the wrapped
   line, and the shared min-width keeps both edges flush either way. */
.row-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--gap-actions);
}

.row-actions .row-run { min-width: 54px; }

.progress-actions { display: flex; gap: var(--gap-actions); align-items: center; }

/* Neutral until hover/focus, so a destructive action doesn't compete
   visually with the routine Call/Edit buttons beside it - discoverable,
   not alarming, until you actually reach for it. */
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--control-h);
  height: var(--control-h);
  padding: 0;
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--subtle);
}

.icon-button:hover {
  background: var(--red-bg);
  border-color: var(--red-bg);
  color: var(--red);
}

.icon-button:disabled { opacity: 0.5; cursor: default; }

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin: 16px 0;
}

.progress-header h1 { margin: 0 0 4px; font-size: var(--fs-2xl); }

#backButton { margin-top: 8px; }

.call-status {
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: var(--fs-base);
  font-weight: 600;
}

.call-status.connecting { background: var(--amber-bg); color: var(--amber); }
.call-status.connected { background: var(--green-bg); color: var(--green); }
.call-status.error { background: var(--red-bg); color: var(--red); }

.progress-bar-wrap { margin-bottom: 24px; }

.progress-bar {
  background: var(--border);
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--green);
  width: 0%;
  transition: width 0.3s ease;
}

.columns {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

.columns h3 {
  font-size: var(--fs-sm);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--subtle);
  margin-bottom: 10px;
}

.feed { display: flex; flex-direction: column; gap: 8px; }

.feed-item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: var(--fs-sm);
}

.feed-item .feed-title { font-weight: 600; margin-bottom: 2px; }
.feed-item .feed-meta { color: var(--subtle); font-size: var(--fs-xs); margin-bottom: 4px; }
.feed-item a { color: var(--accent-text); }

.feed-empty { color: var(--subtle); font-size: var(--fs-sm); font-style: italic; }

@media (max-width: 760px) {
  .columns { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: flex-start; gap: 10px; }
}

/* --- Latest call panel: what the agent actually did --- */

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 24px;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}

.panel-head h3 {
  margin: 0;
  font-size: var(--fs-sm);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--subtle);
}

.call-summary {
  font-size: var(--fs-md);
  line-height: 1.5;
  margin-bottom: 18px;
}

.call-summary:empty { display: none; }

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.split h4 {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--subtle);
  margin: 0 0 10px;
}

.steps {
  list-style: none;
  margin: 0;
  padding: 0;
  /* The trace can run long on a multi-turn call; keep the panel a sane
     height and let the steps scroll instead of pushing the page down. */
  max-height: 340px;
  overflow-y: auto;
}

.step {
  position: relative;
  padding: 0 0 14px 18px;
  border-left: 2px solid var(--border);
  font-size: var(--fs-sm);
}

.step:last-child { border-left-color: transparent; padding-bottom: 0; }

.step::before {
  content: "";
  position: absolute;
  left: -5px;
  top: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border-strong);
}

/* A lookup and a state change read very differently - colour tells them
   apart at a glance. */
.step.read::before { background: var(--blue); }
.step.write::before { background: var(--teal); }

.step-title { font-weight: 600; }
.step-detail { color: var(--text); opacity: 0.75; margin-top: 1px; }
.step-tool {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: var(--fs-2xs);
  color: var(--subtle);
  margin-top: 2px;
}

.transcript {
  max-height: 340px;
  overflow-y: auto;
  font-size: var(--fs-sm);
  line-height: 1.5;
}

.turn { margin-bottom: 10px; }
.turn .who {
  display: block;
  font-size: var(--fs-2xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--subtle);
  margin-bottom: 1px;
}
.turn.agent .who { color: var(--teal); }

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

/* Account reference - staff-only. Shown so whoever is testing a call knows
   which digits to give when the agent asks; the agent itself never sees it. */
.ref-hint {
  font-size: var(--fs-xs);
  color: var(--subtle);
  margin-top: 2px;
}
.ref-hint strong {
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* --- Key facts strip on the borrower page --- */

.facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin: 0 0 20px;
}

.fact {
  background: var(--panel);
  padding: 12px 14px;
}

.fact dt {
  font-size: var(--fs-2xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--subtle);
  margin-bottom: 4px;
}

.fact dd {
  margin: 0;
  font-size: var(--fs-base);
  font-weight: 600;
  text-transform: none;
}

/* How close a date is matters more than the date itself when triaging, so
   urgency is colour-coded rather than left for the reader to work out. */
.due-note {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--subtle);
  text-transform: none;
}

.due-note.urgent { color: var(--amber); }
.due-note.overdue { color: var(--red); }

.next-action {
  font-size: var(--fs-sm);
  text-transform: none;
}

.debt-table td .subtle { text-transform: none; font-weight: 400; }

/* A status badge alone doesn't say why. Show the reason with it so
   "needs review" isn't mistaken for something about the dates next to it. */
.status-reason {
  font-size: var(--fs-xs);
  font-weight: 400;
  color: var(--subtle);
  text-transform: none;
  margin-top: 4px;
  max-width: 260px;
  line-height: 1.4;
}

/* Account reference: masked to the last 4, which is all the agent ever asks
   for. Monospace so the visible digits are easy to read off during a call. */
.ref-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text);
  letter-spacing: 0.5px;
}

/* --- Collapsible call details --- */

.call-details {
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

/* Styled as an obvious control, not a heading. The first version used the
   same small grey uppercase treatment as the section titles around it, so it
   read as a label and nobody realised it could be clicked. */
.call-details summary {
  cursor: pointer;
  margin-top: 12px;
  padding: 8px 14px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--accent-text);
  background: var(--blue-bg);
  border: 1px solid transparent;
  border-radius: 999px;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}

.call-details summary:hover { background: var(--blue-bg); }

/* Replace the default marker with one that rotates, so the control reads the
   same in every browser. */
.call-details summary::-webkit-details-marker { display: none; }

.call-details summary::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.15s ease;
}

.call-details[open] summary::before { transform: rotate(90deg); }

/* Spell out the action rather than relying on the caret alone. */
.call-details summary::after { content: "Show"; opacity: 0.7; }
.call-details[open] summary::after { content: "Hide"; }

.call-details .split { padding-top: 14px; }

/* Nothing to show in the actions column - let the transcript use the space. */
.split.single { grid-template-columns: 1fr; }

/* ---- Checkout modal ------------------------------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.overlay.hidden { display: none; }

.pay-modal {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
  animation: pay-in 0.16s ease-out;
}

@keyframes pay-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.overlay-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 28px;
  height: 28px;
  min-height: 0;
  padding: 0;
  font-size: var(--fs-xl);
  line-height: 1;
  border-radius: 8px;
  background: transparent;
  border: none;
  color: var(--subtle);
}

.overlay-close:hover { background: var(--border); color: var(--text); }

.pay-brand { font-weight: 700; font-size: var(--fs-lg); letter-spacing: -0.02em; }
.pay-sub { color: var(--subtle); font-size: var(--fs-sm); margin-bottom: 20px; }

.pay-amount-label {
  font-size: var(--fs-2xs);
  color: var(--subtle);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}

.pay-amount { font-size: var(--fs-display); font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }

.pay-rows { border-top: 1px solid var(--border); margin: 20px 0; padding-top: 12px; }

.pay-row {
  display: flex;
  justify-content: space-between;
  font-size: var(--fs-sm);
  padding: 4px 0;
}

.pay-row span:first-child { color: var(--subtle); }

.pay-modal button.pay-submit { width: 100%; padding: 13px; font-size: var(--fs-md); }

.pay-note {
  font-size: var(--fs-2xs);
  color: var(--subtle);
  text-align: center;
  margin-top: 12px;
  line-height: 1.5;
}

.pay-error {
  background: var(--red-bg);
  color: var(--red);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: var(--fs-sm);
  margin-top: 12px;
}

.pay-done { text-align: center; }

.pay-tick {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--green-bg);
  color: var(--green);
  font-size: var(--fs-2xl);
  line-height: 54px;
  margin: 0 auto 12px;
}

.pay-done h3 { margin: 0 0 6px; font-size: var(--fs-lg); }

.pay-shortfall {
  background: var(--amber-bg);
  color: var(--amber);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: var(--fs-sm);
  margin: 0 0 14px;
}

/* The payment link in the message feed - a button, not a link out of the app. */
.pay-open { margin-top: 6px; }
.pay-open button { padding: 6px 12px; font-size: var(--fs-xs); }
.paid-tag { color: var(--green); font-size: var(--fs-xs); font-weight: 600; margin-top: 6px; }

/* ---- Add customer / edit repayment terms forms ---------------------- */

.view-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.view-head h1 { margin: 0; font-size: var(--fs-xl); }

.view-head-actions { display: flex; align-items: center; gap: var(--gap-actions); }

.select-col { width: 36px; text-align: center; }
.select-col input[type="checkbox"] { width: 15px; height: 15px; cursor: pointer; accent-color: var(--accent); }

.row-delete-button {
  font-size: var(--fs-sm);
  padding: 6px 12px;
}

.form-modal { max-width: 460px; text-align: left; }

.field { margin-bottom: 14px; }

.field label {
  display: block;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--subtle);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 5px;
}

.field input {
  width: 100%;
  font: inherit;
  font-size: var(--fs-sm);
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}

.field input:focus {
  outline: none;
  border-color: var(--accent-text);
  box-shadow: 0 0 0 3px var(--blue-bg);
}

.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 12px;
}

.field-group {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  margin-top: 4px;
}

.field-group-label {
  font-size: var(--fs-xs);
  font-weight: 600;
  margin-bottom: 10px;
}

.field-group-label .subtle { font-weight: 400; text-transform: none; }

.field-actions {
  display: flex;
  gap: var(--gap-actions);
  margin-top: 4px;
}

/* Repayment terms panel on the person progress page. */
.facts-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  font-size: var(--fs-sm);
}

.facts-inline .term-label { color: var(--subtle); margin-right: 4px; }
.facts-inline .term-value { font-weight: 600; }
.facts-inline .term-value.custom { color: var(--teal); }

#repaymentForm.hidden { display: none; }
#repaymentForm { margin-top: 12px; }

.schedule { margin-top: 14px; }

.schedule-summary {
  font-size: var(--fs-xs);
  color: var(--subtle);
  margin-bottom: 8px;
}

.schedule-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 7px 0;
  border-top: 1px solid var(--border);
  font-size: var(--fs-sm);
}

.schedule-row:first-of-type { border-top: none; }
.schedule-row .due-note { margin-left: 6px; }

.schedule-more {
  padding-top: 6px;
  font-style: italic;
}

/* --- Intelligence layer ----------------------------------------------- */

.brand-wrap { display: flex; align-items: center; gap: 22px; }
.topnav { display: flex; gap: 4px; }
.topnav a {
  color: var(--subtle);
  text-decoration: none;
  font-size: var(--fs-sm);
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 6px;
}
.topnav a:hover { color: var(--text); background: var(--hover); }
.topnav a.active { color: var(--text); background: var(--raised); }

/* Handoff queue */
.review-queue { border-color: var(--red-border); }
.review-queue .panel-head h3 { color: var(--red); display: flex; align-items: center; gap: 8px; }
.count-badge {
  min-width: 20px;
  padding: 1px 7px;
  background: var(--red-bg);
  color: var(--red);
  font-weight: 700;
  text-align: center;
}
.review-list { display: flex; flex-direction: column; gap: 6px; }
.review-item {
  display: grid;
  grid-template-columns: 1.2fr 2fr auto auto;
  gap: 14px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
}
.review-item:hover { border-color: var(--border-strong); }
.review-item .reason { color: var(--text); font-size: var(--fs-sm); }
.review-item .reason.human { color: var(--amber); font-weight: 600; }
.review-item .when { color: var(--subtle); font-size: var(--fs-xs); white-space: nowrap; }

/* Segment badge in the table + on the borrower page */
.segment-badge {
  padding: 2px 8px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--raised);
  color: var(--text);
  border: 1px solid transparent;
}
.segment-badge.c0 { background: var(--c0-bg); color: var(--c0); }
.segment-badge.c1 { background: var(--c1-bg); color: var(--c1); }
.segment-badge.c2 { background: var(--c2-bg); color: var(--c2); }
.segment-badge.c3 { background: var(--c3-bg); color: var(--c3); }
.segment-badge.c4 { background: var(--c4-bg); color: var(--c4); }
.segment-badge.c5 { background: var(--c5-bg); color: var(--c5); }
.segment-badge.c6 { background: var(--c6-bg); color: var(--c6); }
.segment-badge.c7 { background: var(--c7-bg); color: var(--c7); }
.segment-badge.bridge::after { content: " · bridge"; font-weight: 400; opacity: 0.8; }
.segment-badge.none { color: var(--subtle); background: transparent; border-color: var(--border); }

/* Next best action panel */
.intel-panel .intel-empty { color: var(--subtle); font-size: var(--fs-sm); }
.intel-panel .intel-empty code { color: var(--text); background: var(--raised); padding: 1px 5px; border-radius: 4px; }
.nba {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 24px;
}
.nba-main { display: flex; flex-direction: column; gap: 14px; }
.nba-headline { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.nba-action {
  font-size: var(--fs-xl);
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
}
.nba-action.human_review { background: var(--red-bg); color: var(--red); }
/* .sms is kept for recommendations stored before email replaced it. */
.nba-action.email,
.nba-action.sms { background: var(--teal-bg); color: var(--teal); }
.nba-action.none { background: var(--green-bg); color: var(--green); }
.nba-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px 18px; }
.nba-fact .k { font-size: var(--fs-2xs); text-transform: uppercase; letter-spacing: 0.04em; color: var(--subtle); }
.nba-fact .v { font-size: var(--fs-md); font-weight: 600; margin-top: 2px; }
.nba-fact .v.prob { font-size: var(--fs-2xl); }
.nba-fact .v .flag { font-size: var(--fs-xs); color: var(--amber); font-weight: 500; margin-left: 6px; }
.nba-why h4, .nba-side h4 {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--subtle);
  margin: 0 0 8px;
}
.nba-why ol { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 5px; font-size: var(--fs-sm); line-height: 1.45; }
.nba-why li.contrib-up { color: var(--green); }
.nba-why li.contrib-down { color: var(--amber); }
.nba-note {
  font-size: var(--fs-xs);
  color: var(--subtle);
  border-left: 3px solid var(--border-strong);
  padding-left: 10px;
}
.neighbors { display: flex; flex-direction: column; gap: 4px; }
.neighbor {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
  font-size: var(--fs-sm);
  padding: 5px 8px;
  border-radius: 6px;
  background: var(--bg);
}
.neighbor .sim { color: var(--subtle); font-size: var(--fs-2xs); }
.neighbor .out.paid { color: var(--green); }
.neighbor .out.unpaid { color: var(--subtle); }
.neighbor-summary { font-size: var(--fs-sm); margin-bottom: 8px; }
.evidence-ids { margin-top: 10px; font-size: var(--fs-2xs); color: var(--subtle); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; }

/* Intelligence view */
.intel-intro { max-width: 760px; margin: -6px 0 18px; }
.intel-copy { max-width: 760px; margin: 10px 0 0; line-height: 1.5; }
.intel-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 20px; }
#networkCanvas, #robustnessCanvas, #epiCurveCanvas { width: 100%; height: auto; background: var(--bg); border-radius: 8px; display: block; }
.network-legend { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 10px; font-size: var(--fs-xs); }
.network-legend .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.network-legend .swatch.line { border-radius: 2px; width: 14px; height: 3px; }
.network-hover { min-height: 18px; margin-top: 6px; font-size: var(--fs-xs); }
.network-def { margin-top: 6px; font-size: var(--fs-2xs); line-height: 1.4; }

.intel-callout {
  font-size: var(--fs-xs);
  color: var(--text);
  background: var(--raised);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 10px;
  line-height: 1.4;
}

.scope-select {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: var(--fs-xs);
}
.intel-table table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.intel-table th { text-align: left; font-size: var(--fs-2xs); text-transform: uppercase; letter-spacing: 0.04em; color: var(--subtle); padding: 6px 8px; border-bottom: 1px solid var(--border); }
.intel-table td { padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.intel-table tr:last-child td { border-bottom: none; }
.intel-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ci { color: var(--subtle); font-size: var(--fs-2xs); }
.findings { display: flex; flex-direction: column; gap: 8px; }
.finding {
  display: grid;
  grid-template-columns: 2fr 1.3fr auto;
  gap: 16px;
  align-items: start;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}
.finding .q { font-weight: 600; font-size: var(--fs-sm); }
.finding .seg { font-size: var(--fs-2xs); color: var(--subtle); margin-top: 2px; }
.finding .summary { font-size: var(--fs-sm); color: var(--text); margin-top: 4px; line-height: 1.4; }
.finding .method { font-size: var(--fs-2xs); color: var(--subtle); line-height: 1.4; }
.finding .stat { text-align: right; font-size: var(--fs-xs); white-space: nowrap; }
.finding .stat .p { font-variant-numeric: tabular-nums; }
.finding .stat .sig { display: inline-block; margin-top: 4px; padding: 1px 7px; border-radius: 999px; font-size: var(--fs-2xs); font-weight: 700; }
.finding .stat .sig.yes { background: var(--green-bg); color: var(--green); }
.finding .stat .sig.no { background: var(--raised); color: var(--subtle); }
.finding.null-check { border-color: var(--green-border); }
.finding .limits { grid-column: 1 / -1; font-size: var(--fs-2xs); color: var(--subtle); border-top: 1px dashed var(--border); padding-top: 6px; }
.model-cards { display: flex; flex-direction: column; gap: 8px; }
.model-card { padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.model-card.champion { border-color: var(--accent); }
.model-card .name { font-weight: 600; font-size: var(--fs-sm); display: flex; justify-content: space-between; gap: 10px; }
.model-card .champ { font-size: var(--fs-2xs); color: var(--accent-text); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.model-card .metrics { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 6px; font-size: var(--fs-xs); }
.model-card .metrics span b { font-variant-numeric: tabular-nums; }
.model-card .notes { margin-top: 6px; font-size: var(--fs-2xs); color: var(--subtle); }
.calib { display: flex; align-items: flex-end; gap: 2px; height: 36px; margin-top: 8px; }
.calib .bar { flex: 1; background: var(--raised); position: relative; border-radius: 2px 2px 0 0; }
.calib .bar i { position: absolute; left: 0; right: 0; bottom: 0; background: var(--accent-text); border-radius: 2px 2px 0 0; }

@media (max-width: 900px) {
  .intel-grid { grid-template-columns: 1fr; }
  .nba { grid-template-columns: 1fr; }
  .review-item { grid-template-columns: 1fr; gap: 4px; }
  .finding { grid-template-columns: 1fr; }
}

/* ---- Loading feedback ---------------------------------------------------
   A thin bar across the top while any request is in flight (html.busy is
   toggled by api() in app.js), and placeholder rows so a table or panel
   never sits empty while its data is on the way. */
#loadbar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0;
  background: var(--accent);
  opacity: 0;
  z-index: 1000;
  transition: opacity 0.2s;
}
html.busy #loadbar {
  opacity: 1;
  animation: loadbar 1.2s ease-in-out infinite;
}
@keyframes loadbar {
  0% { width: 0; margin-left: 0; }
  50% { width: 60%; margin-left: 20%; }
  100% { width: 0; margin-left: 100%; }
}
.placeholder { color: var(--subtle); }
.placeholder td { padding: 28px 14px; text-align: center; }

/* The browser-call button sits beside "Call borrower" and is the one that
   works without a carrier, so it reads as a peer rather than a fallback. */
#webCallButton[data-live="1"] { background: var(--danger-bg, #fbeae8); color: var(--danger, #c33a32); }

/* Borrower sub-tabs. Same visual language as the top nav so the page reads as
   one product rather than two navigation systems. */
.subtabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin: 18px 0 20px;
}
.subtabs button {
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--subtle);
  font-size: var(--fs-sm);
  font-weight: 600;
  padding: 8px 12px;
  margin-bottom: -1px;
  cursor: pointer;
}
.subtabs button:hover { color: var(--text); }
.subtabs button.active { color: var(--text); border-bottom-color: var(--accent, var(--text)); }

/* The Overview's short call card: summary only, with a way through to the
   evidence rather than a second copy of it. */
.last-call-brief { display: grid; gap: 10px; }
.last-call-brief .call-summary { margin: 0; }
/* Only the button shrink-wraps. justify-items on the grid squashed the
   panel head too, which put the title and the timestamp against each other. */
.last-call-brief > button { justify-self: start; }
