/* =============================================================================
   CSA MODULE (Customer Success Aftersales)
   Intake page: campaign cards with the latest pull, team divisions; campaign page:
   calls and pull history. Colours come from variables.css tokens only, so light and
   dark themes both work.
   ============================================================================= */

.csa-campaigns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.csa-campaign {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
}
.csa-campaign.is-failed { border-color: var(--err-line); box-shadow: inset 4px 0 0 var(--err); }

.csa-campaign-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
}
.csa-campaign-head h2, .csa-section-head h2 { margin: 0; font-size: var(--text-lg); }
.csa-campaign-head p, .csa-section-head p { margin: var(--space-1) 0 0; font-size: var(--text-sm); }
.csa-section-head { margin-bottom: var(--space-3); }

.csa-facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2) var(--space-4);
  margin: 0;
}
.csa-facts dt { font-size: var(--text-xs); color: var(--muted); }
.csa-facts dd { margin: var(--space-half) 0 0; font-size: var(--text-sm); color: var(--ink); overflow-wrap: anywhere; }

.csa-last-run {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
  font-size: var(--text-sm);
  background: var(--neutral-soft);
  border-radius: var(--radius-md);
}
.csa-last-run .form-msg { margin: 0; }

.csa-campaign-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--space-2); margin-top: auto; }

/* Pull result badges */
.pill.csa-run.is-ok { color: var(--ok); background: var(--ok-soft); }
.pill.csa-run.is-failed { color: var(--err); background: var(--err-soft); }
.pill.csa-run.is-running { color: var(--info); background: var(--info-soft); }
.pill.csa-run.is-none { color: var(--muted); background: var(--neutral-soft); }
table.grid tbody tr.csa-run-failed td { background: var(--err-soft); }

/* Team divisions */
.csa-team { padding: var(--space-4); }
.csa-check { display: inline-flex; align-items: center; gap: var(--space-2); cursor: pointer; font-size: var(--text-sm); }

/* Calls list and pull history */
.csa-list > .csa-section-head { padding: var(--space-4) var(--space-4) 0; }
.csa-list + .csa-list { margin-top: var(--space-4); }
table.grid td.csa-contact-cell { max-width: 240px; white-space: normal; overflow-wrap: anywhere; }
table.grid td.csa-customer-cell { min-width: 180px; max-width: 280px; white-space: normal; }
table.grid td.csa-items-cell { min-width: 220px; max-width: 320px; white-space: normal; }
.csa-items { margin: 0; padding: 0; list-style: none; }
.csa-items li + li { margin-top: var(--space-1); }
.csa-overdue { color: var(--err); font-weight: 600; }
.phone-link { color: var(--accent); text-decoration: none; white-space: nowrap; font-variant-numeric: tabular-nums; }
.phone-link:hover { text-decoration: underline; }
.phone-link:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; border-radius: var(--radius-xs); }

/* ---------- Working calls: queue ---------- */
.csa-counts {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.csa-count {
  display: flex;
  flex-direction: column;
  gap: var(--space-half);
  padding: var(--space-3) var(--space-4);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}
.csa-count b { font-size: var(--text-xl); font-variant-numeric: tabular-nums; color: var(--ink); }
.csa-count span { font-size: var(--text-xs); color: var(--muted); }
.csa-count.is-flagged { border-color: var(--err-line); background: var(--err-soft); }
.csa-count.is-flagged b, .csa-count.is-flagged span { color: var(--err); }

.csa-queue { margin: 0; padding: 0; list-style: none; }
.csa-queue-item + .csa-queue-item { border-top: 1px solid var(--line-soft); }
.csa-queue-link {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1.3fr) minmax(0, 1.3fr) minmax(0, 1.2fr) 168px;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  color: inherit;
  text-decoration: none;
  transition: background var(--duration-fast) var(--ease-out);
}
.csa-queue-link:hover { background: var(--neutral-soft); }
.csa-queue-link:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -2px; }
.csa-queue-link > span { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-half); min-width: 0; font-size: var(--text-sm); }
.csa-q-customer b { overflow-wrap: anywhere; }
.csa-queue-item.is-flagged .csa-queue-link { box-shadow: inset 4px 0 0 var(--err); }
.csa-queue-item.is-held .csa-queue-link { background: var(--neutral-soft); }
.csa-flag { display: inline-flex; align-items: center; gap: var(--space-1); color: var(--err); font-weight: 600; }

/* Status pills (tasteful-ui: one accent, otherwise neutral or a semantic status pair; the word
   always carries the meaning, colour only reinforces it) */
.pill.csa-status { color: var(--ink-soft); background: var(--neutral-soft); }
.pill.csa-status.is-callback { color: var(--info); background: var(--info-soft); }
.pill.csa-status.is-completed { color: var(--ok); background: var(--ok-soft); }
.pill.csa-held { display: inline-flex; align-items: center; gap: var(--space-1); color: var(--warn); background: var(--warn-soft); }
.pill.csa-held.is-mine { color: var(--accent); background: var(--accent-soft); }
/* A call reopened for a retry (queue, call page, call log) */
.pill.csa-retry { display: inline-flex; align-items: center; gap: var(--space-1); margin-left: var(--space-1); color: var(--accent); background: var(--accent-soft); }
.csa-retry-was { color: var(--muted); }
.csa-retry-note { display: flex; align-items: flex-start; gap: var(--space-2); }
.csa-retry-note .ic { flex: none; margin-top: 3px; }
.csa-retry-lead { margin: 0 0 var(--space-2); font-weight: 600; }
.csa-retry-facts { display: grid; gap: var(--space-1); margin: 0; }
.csa-retry-facts div { display: grid; grid-template-columns: 110px 1fr; gap: var(--space-3); }
.csa-retry-facts dt { color: var(--muted); }
.csa-retry-facts dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 480px) { .csa-retry-facts div { grid-template-columns: 1fr; gap: 0; } }

/* Supervisors' tick boxes on the call log, and the bar that acts on the ticked calls */
.csa-select-col { width: 44px; }
.csa-select { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; margin: calc(-1 * var(--space-2)) 0; cursor: pointer; }
.csa-select input { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.csa-select input:disabled { cursor: not-allowed; opacity: 0.4; }
.csa-bulk { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-4); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--line); min-height: 52px; }
.csa-bulk:empty { display: none; }
.csa-bulk-count { font-weight: 600; font-variant-numeric: tabular-nums; }
.csa-bulk .btn { margin-left: auto; }
.btn-link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.btn-link:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; border-radius: 4px; }
.csa-retry-counts { list-style: none; margin: 0 0 var(--space-3); padding: 0; border: 1px solid var(--line); border-radius: 8px; }
.csa-retry-counts li { display: flex; justify-content: space-between; padding: var(--space-2) var(--space-3); font-variant-numeric: tabular-nums; }
.csa-retry-counts li + li { border-top: 1px solid var(--line); }
/* On phones the log turns into cards: the tick box sits at the top of each card */
@media (max-width: 720px) {
  .csa-cards.has-select td.csa-select-col { width: auto; }
}

.pill.csa-edited { display: inline-flex; align-items: center; gap: var(--space-1); color: var(--ink-soft); background: var(--neutral-soft); }
.pill.csa-run { display: inline-flex; align-items: center; gap: var(--space-1); }

/* ---------- Working calls: one call ---------- */
.csa-call-status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-4);
  margin-bottom: var(--space-3);
  font-size: var(--text-sm);
}
.csa-reserved { margin-bottom: var(--space-3); }
.csa-call-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 1fr);
  gap: var(--space-4);
  align-items: start;
}
.csa-call-main, .csa-call-side { display: flex; flex-direction: column; gap: var(--space-4); min-width: 0; }
.csa-call-side { position: sticky; top: var(--space-4); }
.csa-card { padding: var(--space-4); }
.csa-card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-1) var(--space-3); margin-bottom: var(--space-3); }
.csa-card-head h2 { margin: 0; font-size: var(--text-lg); }
.csa-card-head h3 { margin: var(--space-4) 0 0; font-size: var(--text-base); }

.csa-contact, .csa-answers {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3) var(--space-4);
  margin: 0;
}
.csa-contact dt, .csa-answers dt { font-size: var(--text-xs); color: var(--muted); }
.csa-contact dd, .csa-answers dd { margin: var(--space-half) 0 0; font-size: var(--text-sm); color: var(--ink); overflow-wrap: anywhere; }
.csa-answers { margin-top: var(--space-2); padding: var(--space-3); background: var(--neutral-soft); border-radius: var(--radius-md); }
.csa-contact-form .inline-row { justify-content: flex-end; }
.csa-fabric { margin-bottom: var(--space-3); }
table.grid td.csa-wrap { white-space: normal; min-width: 120px; max-width: 320px; }

.csa-attempts { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: var(--space-3); }
.csa-attempts > li { padding: var(--space-3); border: 1px solid var(--line); border-radius: var(--radius-md); font-size: var(--text-sm); }
.csa-remarks { margin-top: var(--space-1); white-space: pre-wrap; overflow-wrap: anywhere; }

.csa-log fieldset { margin: 0 0 var(--space-3); padding: var(--space-3); border: 1px solid var(--line); border-radius: var(--radius-md); }
.csa-log legend { padding: 0 var(--space-1); font-size: var(--text-sm); font-weight: 600; }
.csa-log .form-msg { margin-bottom: var(--space-3); }
.csa-log-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--space-2); }

/* One column (phones, small tablets): who the customer is and what they received, then
   the form to log the call, then earlier attempts */
@media (max-width: 1024px) {
  .csa-call-grid { display: flex; flex-direction: column; }
  .csa-call-main, .csa-call-side { display: contents; }
  .csa-call-grid [aria-labelledby="contactHeading"] { order: 1; }
  .csa-call-grid [aria-labelledby="fabricHeading"] { order: 2; }
  .csa-call-grid .csa-log { order: 3; }
  .csa-call-grid [aria-labelledby="historyHeading"] { order: 4; }
}

@media (max-width: 640px) {
  .csa-campaigns { grid-template-columns: 1fr; }
  .csa-facts { grid-template-columns: 1fr; }
  .csa-counts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .csa-queue-link { grid-template-columns: 1fr auto; }
  .csa-q-campaign, .csa-q-deadline { grid-column: 1; }
  .csa-q-status, .csa-q-held { grid-column: 2; grid-row: 1; align-items: flex-end; }
  .csa-q-held { grid-row: 2; }
  .csa-contact, .csa-answers { grid-template-columns: 1fr; }
}

/* ---------- Campaign tags: 24-HOUR / 30-DAY ----------
   Outlined and neutral (tasteful-ui allows one accent only): the clock / calendar icon and
   the bold uppercase word make the campaign stand out without a colour of its own. */
.csa-tag {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  gap: var(--space-1);
  padding: var(--space-half) var(--space-2);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1.5;
  white-space: nowrap;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
}
.csa-tag .ic { color: var(--ink-soft); }
.csa-tag.is-big { padding: var(--space-1) var(--space-3); font-size: var(--text-sm); vertical-align: middle; }
.csa-call-title { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
/* Sales rep and invoicing branch under a call's title (and on customer history cards) */
.csa-sales-line { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-4); margin-top: var(--space-2); color: var(--muted); }
.csa-sales-line span { display: inline-flex; align-items: center; gap: var(--space-1); }
.csa-sales-line b { color: var(--ink); font-weight: 600; }
.csa-cust-call .csa-sales-line { margin-top: var(--space-3); }
.csa-q-customer .csa-tag { margin-bottom: var(--space-1); }

/* Queue: campaign filter and the "live" marker */
.csa-filter { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-3); }
.csa-filter button {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  font: inherit;
  font-size: var(--text-sm);
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  cursor: pointer;
}
.csa-filter button[aria-selected="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.csa-filter button:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.csa-live { display: inline-flex; align-items: center; gap: var(--space-1); margin-left: var(--space-2); font-size: var(--text-xs); color: var(--ok); }
.csa-live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
@media (prefers-reduced-motion: no-preference) {
  .csa-live-dot { animation: csa-pulse 2s var(--ease-in-out) infinite; }
}
@keyframes csa-pulse { 50% { opacity: 0.3; } }
/* The taken-call row is a <button>: reset it to look exactly like the link rows */
button.csa-queue-link { width: 100%; font: inherit; text-align: left; color: inherit; background: none; border: 0; cursor: not-allowed; }
button.csa-queue-link:active { scale: 1; }
.csa-queue-item.is-held button.csa-queue-link { background: var(--neutral-soft); }

/* Call form: filled in automatically, hints, parts that don't apply yet */
.csa-auto {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2);
  margin: 0 0 var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--neutral-soft);
  border-radius: var(--radius-md);
}
.csa-auto dt { font-size: var(--text-xs); color: var(--muted); }
.csa-auto dd { margin: 0; font-size: var(--text-sm); font-weight: 600; color: var(--ink); }
.csa-hint { margin: 0 0 var(--space-2); color: var(--muted); }
table.grid td.csa-result-cell { min-width: 170px; white-space: normal; }

/* =============================================================================
   PHASE 3: SUPERVISOR SCREENS (team dashboard, escalations, call settings)
   tasteful-ui: neutral surfaces and ink; the one accent only for chart marks
   (--chart-mark), selection and focus; spacing from --space-*; tabular figures in columns.
   ============================================================================= */

/* ---------- Filters: one row above everything they scope ---------- */
.csa-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.csa-filter-custom { display: contents; }
.csa-filter-custom[hidden] { display: none; }
.csa-filter-field { display: flex; flex-direction: column; gap: var(--space-1); min-width: 150px; }
.csa-filter-field > span { font-size: var(--text-xs); font-weight: 600; color: var(--muted); }
.csa-filter-field select, .csa-filter-field input {
  min-height: 40px;
  padding: var(--space-2) var(--space-3);
  font: inherit;
  font-size: var(--text-sm);
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}
.csa-filter-field select:focus-visible, .csa-filter-field input:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}
@media (max-width: 640px) {
  .csa-filter-field { flex: 1 1 140px; min-width: 0; }
  .csa-filter-field select, .csa-filter-field input { font-size: var(--text-base); }   /* no iOS zoom on focus */
}

/* Refetch keeps the frame: the old figures stay, dimmed, until the new ones arrive */
#csaDashBody { transition: opacity var(--duration-fast) var(--ease-out); }
#csaDashBody.is-refreshing, #meBody.is-refreshing { opacity: 0.55; pointer-events: none; }

.csa-section { margin-bottom: var(--space-5); }
.csa-section-title { margin-bottom: var(--space-3); }
.csa-section-title h2 { margin: 0; font-size: var(--text-lg); }
.csa-section-title p { margin: var(--space-1) 0 0; }

/* ---------- Stat tiles: label, value, what it means. Neutral, never coloured ---------- */
.csa-tile-group { margin-bottom: var(--space-4); }
.csa-tile-group h3 {
  margin: 0 0 var(--space-2);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.csa-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: var(--space-3); }
.csa-tile {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-3) var(--space-4);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}
.csa-tile-label { font-size: var(--text-sm); color: var(--ink-soft); }
.csa-tile-value { font-size: var(--text-xl); font-weight: 600; line-height: 1.2; color: var(--ink); }
.csa-tile-caption { font-size: var(--text-xs); color: var(--muted); }
.csa-tile.is-skeleton { min-height: 96px; gap: var(--space-3); }
.csa-sk-label { width: 55%; height: 12px; }
.csa-sk-value { width: 35%; height: 22px; }

/* ---------- Right now ---------- */
.csa-rightnow { padding: var(--space-4); margin-bottom: var(--space-5); }
.csa-rightnow-head { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-3); }
.csa-rightnow-head h2 { margin: 0; font-size: var(--text-lg); }
.csa-rightnow-figs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-3); margin: 0 0 var(--space-3); }
.csa-rightnow-figs dt { font-size: var(--text-xs); color: var(--muted); }
.csa-rightnow-figs dd { margin: 0; font-size: var(--text-xl); font-weight: 600; color: var(--ink); }
.csa-oncall { display: flex; flex-direction: column; gap: var(--space-2); margin: 0; padding: 0; list-style: none; font-size: var(--text-sm); }
.csa-oncall li { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-2); }
@media (max-width: 640px) { .csa-rightnow-figs { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ---------- Column charts (dataviz: bars at most 24px wide, 4px rounded data end, hairline axes) ---------- */
.csa-charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: var(--space-3); }
.csa-chart { margin: 0; padding: var(--space-3) var(--space-4) var(--space-2); background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.csa-chart figcaption { margin-bottom: var(--space-2); font-size: var(--text-sm); font-weight: 600; color: var(--ink); }
.csa-chart-box { position: relative; }
.csa-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.csa-bar { fill: var(--chart-mark); pointer-events: none; }
.csa-hit { fill: transparent; cursor: default; }
.csa-hit:focus { outline: none; }
.csa-hit:focus-visible, .csa-hit.is-on { fill: var(--accent-soft); }
.csa-grid, .csa-baseline { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.csa-axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.csa-tip {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-xs);
  font-weight: 600;
  white-space: nowrap;
  color: var(--tooltip-ink);
  background: var(--tooltip-bg);
  border-radius: var(--radius-sm);
  pointer-events: none;
}
.csa-table-view { margin-top: var(--space-3); }
.csa-table-view summary { cursor: pointer; font-size: var(--text-sm); color: var(--accent); }
.csa-table-view summary:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; border-radius: var(--radius-xs); }
.csa-table-view .grid-wrap { margin-top: var(--space-2); }

/* Tables with long lists keep their header in view */
.csa-sticky thead th { position: sticky; top: 0; z-index: 1; }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Survey results: one bar list per question ---------- */
.csa-survey { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: var(--space-3); }
.csa-survey-group { padding: var(--space-4); }
.csa-survey-group h3 { margin: 0 0 var(--space-3); font-size: var(--text-base); }
.csa-q + .csa-q { margin-top: var(--space-4); }
.csa-q-label { margin-bottom: var(--space-2); font-size: var(--text-sm); font-weight: 600; color: var(--ink); }
.csa-bars { display: flex; flex-direction: column; gap: var(--space-2); margin: 0; padding: 0; list-style: none; }
.csa-bars li { display: grid; grid-template-columns: minmax(110px, 1.2fr) minmax(0, 2fr) auto; align-items: center; gap: var(--space-3); font-size: var(--text-sm); }
.csa-bar-label { color: var(--ink-soft); overflow-wrap: anywhere; }
.csa-bar-track { height: 10px; background: var(--neutral-soft); border-radius: var(--radius-xs); overflow: hidden; }
.csa-bar-fill { display: block; height: 100%; background: var(--chart-mark); border-radius: 0 var(--radius-xs) var(--radius-xs) 0; }
.csa-bar-value { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; color: var(--ink); }

/* State text with an icon, never colour alone */
.csa-state { display: inline-flex; align-items: center; gap: var(--space-1); font-size: var(--text-sm); color: var(--ink-soft); }
.csa-state.is-warn { color: var(--warn); }

/* ---------- Call settings ---------- */
/* On a phone the tabs scroll sideways inside their strip, never the page */
.csa-tabs { display: flex; gap: var(--space-1); margin-bottom: var(--space-4); border-bottom: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: thin; }
.csa-tabs button { flex: none; white-space: nowrap; }
.csa-tabs button {
  padding: var(--space-2) var(--space-4);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--muted);
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
}
.csa-tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.csa-tabs button:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; border-radius: var(--radius-xs); }
.csa-set-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: var(--space-4); }
.csa-set-card h2, .csa-card > h2 { margin: 0 0 var(--space-3); font-size: var(--text-lg); }
.csa-card + .csa-card { margin-top: var(--space-4); }
.csa-set-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--space-3); }
.csa-set-divs { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); margin: var(--space-3) 0; padding: var(--space-3); border: 1px solid var(--line); border-radius: var(--radius-md); }
.csa-set-divs legend { padding: 0 var(--space-1); font-size: var(--text-sm); font-weight: 600; }
.csa-set-actions { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-3); }
.csa-set-list { margin: 0; padding: 0; list-style: none; }
.csa-set-list > li { padding: var(--space-3) 0; border-bottom: 1px solid var(--line-soft); }
.csa-set-item { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2) var(--space-3); }
.csa-set-main { display: flex; flex-direction: column; gap: var(--space-half); min-width: 0; }
.csa-set-tools { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.csa-set-inline { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-2); margin-top: var(--space-3); }
.csa-set-inline .field { flex: 1 1 220px; margin: 0; }
.csa-readonly { margin: var(--space-1) 0 0; padding: var(--space-2) var(--space-3); background: var(--neutral-soft); border-radius: var(--radius-md); font-size: var(--text-sm); }
.csa-field-label { font-size: var(--text-sm); font-weight: 600; }

/* ---------- Call screen: supervisor panel; campaign page export ---------- */
.csa-supervisor .field { margin-bottom: var(--space-2); }
.csa-supervisor > .btn, .csa-supervisor form { margin-bottom: var(--space-3); }
.csa-sup-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2); margin: var(--space-3) 0; font-size: var(--text-sm); }
.csa-export-row { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--space-3); }
.csa-export { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--space-2); }

/* Panels in the dashboard keep the same breathing room as the sections around them */
#csaDashBody > .csa-list { margin-bottom: var(--space-5); }

/* ---------- Intake: automation status (phase 4) ---------- */
.csa-auto-panel { margin-bottom: var(--space-4); }
.csa-auto-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--space-3) var(--space-5); margin: 0 0 var(--space-3); }
.csa-auto-facts dt { font-size: var(--text-xs); font-weight: 600; color: var(--muted); }
.csa-auto-facts dd { margin: var(--space-1) 0 0; font-size: var(--text-sm); color: var(--ink); overflow-wrap: anywhere; }
/* Side-by-side cards in a grid need no stacking gap */
.csa-set-cards > .csa-card + .csa-card { margin-top: 0; }


/* ---------- Phase 5: loading skeletons (layout-accurate; shimmer comes from .skeleton-bar) ---------- */
.csa-skel { display: flex; flex-direction: column; gap: var(--space-3); }
.csa-skel .skeleton-bar { display: block; height: 12px; border-radius: var(--radius-xs); }
.csa-sk-title { width: 40%; height: 18px !important; }
.csa-sk-line { width: 70%; }
.csa-sk-block { width: 100%; height: 56px !important; }
.csa-skel-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
.csa-skel-row .skeleton-bar { display: block; height: 12px; width: 70%; }
.csa-skel-row > span { gap: var(--space-2); }
.csa-sk-tag { width: 64px !important; height: 18px !important; }
.csa-sk-name { width: 85% !important; }
.csa-sk-short { width: 45% !important; }

/* Phones: every CSA form field at 16px or larger, so iOS does not zoom the page on focus */
@media (max-width: 640px) {
  .csa-log :is(input, select, textarea),
  .csa-contact-form :is(input, select, textarea),
  .csa-supervisor :is(input, select, textarea),
  #setPanel :is(input, select, textarea),
  .table-search-box input { font-size: var(--text-base); }
}


/* ---------- Escalation email (the agent's pre-filled subject and message) ---------- */
/* Tall enough to read the whole email without scrolling the box; the agent's own text wraps */
/* (.field textarea and the portal's phone rule fix textareas at 44-72px; this is stronger) */
.field textarea.csa-esc-message { min-height: 22rem; line-height: 1.5; resize: vertical; }
@media (max-width: 640px) { .field textarea.csa-esc-message { min-height: 18rem; } }
.csa-hint { margin-top: var(--space-1); }
.csa-esc-reset { margin-top: var(--space-2); }
/* The email as it went, in the call's escalation history */
.csa-esc-subject { margin-top: var(--space-1); font-weight: 600; overflow-wrap: anywhere; }
.csa-esc-body { color: var(--ink-soft); }

/* ---------- Call settings: escalation email template ---------- */
.csa-set-intro { max-width: 72ch; margin: 0 0 var(--space-4); }
/* Two long editors side by side are cramped: one campaign per row, up to a readable width */
.csa-set-cards.csa-email-cards { grid-template-columns: minmax(0, 1fr); max-width: 960px; }
.csa-ph-list { margin-top: var(--space-1); }
.csa-ph-list summary { cursor: pointer; color: var(--ink-soft); font-size: var(--text-sm); }
.csa-ph-list ul { list-style: none; margin: var(--space-3) 0 0; padding: 0; display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--space-2) var(--space-4); }
.csa-ph-list li { display: flex; align-items: baseline; gap: var(--space-2); min-width: 0; }
/* A placeholder to insert: monospace, so {customer_name} reads as a code to keep intact */
.csa-ph { flex: none; padding: var(--space-half) var(--space-2); font: 600 var(--text-xs)/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
  color: var(--ink); background: var(--neutral-soft); border: 1px solid var(--line); border-radius: var(--radius-sm); cursor: pointer; }
.csa-ph:hover { border-color: var(--line-strong); }
.csa-ph:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
/* The escalations list: subject shown, the message opens on demand */
.csa-esc-read summary { cursor: pointer; color: var(--accent); font-size: var(--text-sm); margin-top: var(--space-1); }
/* An opened email stays readable in the table: a wider column, its own scroll, cells top-aligned */
table.grid.csa-esc-table td { vertical-align: top; }
table.grid.csa-esc-table td.csa-wrap { min-width: 360px; max-width: 480px; }
.csa-esc-read .csa-esc-body { max-height: 16rem; overflow: auto; padding-right: var(--space-2); }

/* ---------- Escalation: who is told what ---------- */
/* Information, not a warning: the components only define err / ok / warn messages */
.form-msg.info { background: var(--info-soft); color: var(--info); }
/* A preview of the customer's own email (it comes from the template; the agent can't edit it) */
.csa-notice-preview { margin-top: var(--space-4); border: 1px solid var(--line); border-radius: var(--radius-md); padding: var(--space-3); }
.csa-notice-preview summary { cursor: pointer; font-weight: 600; font-size: var(--text-sm); }
.csa-notice-body { margin-top: var(--space-2); }
/* Call settings: each campaign's two emails, one under the other */
.csa-email-campaigns { display: flex; flex-direction: column; gap: var(--space-6); }
.csa-email-campaign > h2 { margin: 0 0 var(--space-3); }
.field textarea.csa-esc-message.is-short { min-height: 14rem; }

/* The queue's note when only the first calls are listed (the counts above cover all of them) */
.csa-queue-more { margin: 0; padding: var(--space-3) var(--space-4); border-top: 1px solid var(--line); }

/* =============================================================================
   LOOKING BACK: the call log and a call viewed read-only
   ============================================================================= */

/* ---------- Read-only call ---------- */
/* The "view only" line, with the way into the live call beside it when there is one */
.csa-view-note { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2) var(--space-3); }
.csa-view-note > span { display: inline-flex; align-items: center; gap: var(--space-2); }
/* The attempt history sits in the side column here and can be long: it scrolls with the
   page instead of sticking (a sticky panel taller than the screen would hide its end) */
.csa-call-grid.is-view .csa-call-side { position: static; }

/* ---------- Call log ---------- */
/* The search box gets the room (names and phone numbers are long) */
.csa-filter-search { flex: 1 1 220px; max-width: 320px; }
/* The customer is the way into the call: a real link, in the ink colour so the table stays calm */
.csa-log-link { font-weight: 600; color: var(--ink); text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
.csa-log-link:hover { text-decoration-color: currentColor; }
.csa-log-link:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; border-radius: var(--radius-xs); }
/* Escalation references line up as codes */
.csa-ref { font-size: var(--text-sm); font-variant-numeric: tabular-nums; white-space: nowrap; }
table.grid.csa-log-table td { vertical-align: top; }
/* Under the customer: campaign tag, code and division; under the outcome: where the call is now */
.csa-log-meta, .csa-log-now { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-2); margin-top: var(--space-1); }

@media (max-width: 640px) {
  .csa-filter-search { max-width: none; }
}
/* Phones and tablets (call log, customer results): each row becomes a card - the customer as its heading, then labelled
   lines - so nothing hides off the side of a scrolling table */
@media (max-width: 900px) {
  table.grid.csa-cards, table.grid.csa-cards tbody { display: block; }
  table.grid.csa-cards thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.grid.csa-cards tr { display: block; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--line); }
  table.grid.csa-cards td { display: flex; justify-content: space-between; gap: var(--space-3); padding: var(--space-1) 0; border: 0; text-align: left; }
  table.grid.csa-cards td.csa-log-customer { display: block; padding-bottom: var(--space-2); }
  table.grid.csa-cards td[data-label]::before { content: attr(data-label); flex: 0 0 auto; font-size: var(--text-xs); color: var(--muted); }
  table.grid.csa-cards td > * { text-align: right; }
  table.grid.csa-cards td.csa-log-customer > * { text-align: left; }
  .csa-log-now { justify-content: flex-end; }
}

/* ---------- An agent's own dashboard: what is waiting for them ---------- */
.csa-waiting { margin-bottom: var(--space-4); }
.csa-wait-head { margin: var(--space-3) var(--space-4) var(--space-1); font-size: var(--text-sm); font-weight: 600; color: var(--muted); }
.csa-wait { margin: 0; padding: 0; list-style: none; }
/* One line per call: who (tag, customer, code) on the left, when on the right; wraps on phones */
.csa-wait-item {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: var(--space-2) var(--space-4); padding: var(--space-3) var(--space-4); border-top: 1px solid var(--line);
}
.csa-wait-who { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-2); min-width: 0; }
.csa-wait-when { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); font-variant-numeric: tabular-nums; }

/* ---------- Customers: search and one customer's calls ---------- */
.csa-cust-search { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-4); max-width: 640px; }
.csa-cust-label { font-size: var(--text-sm); font-weight: 600; color: var(--ink-soft); }
.csa-cust-box { width: 100%; }
.csa-cust-box input { width: 100%; font-size: var(--text-base); }          /* no iOS zoom on focus */
/* One card per call, newest first */
.csa-cust-calls { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: var(--space-3); }
.csa-cust-call-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--space-2) var(--space-4); }
.csa-cust-call-what { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-2); }
.csa-cust-call-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.csa-cust-call .csa-items { margin: var(--space-3) 0 0; }
.csa-cust-attempts, .csa-cust-esc { margin: var(--space-3) 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: var(--space-2); }
.csa-cust-attempts > li { padding-left: var(--space-3); border-left: 2px solid var(--line); font-size: var(--text-sm); }
.csa-cust-esc > li { display: flex; align-items: flex-start; gap: var(--space-2); font-size: var(--text-sm); }
.csa-cust-esc > li > .ic { flex: 0 0 auto; margin-top: 2px; color: var(--muted); }
/* The calls start clear of the contact panel above them */
.csa-cust-history { margin-top: var(--space-5); }

/* ---------- Email signature (escalation emails) ---------- */
.csa-signature { margin-top: var(--space-5); }
.csa-sig-preview { margin-top: var(--space-3); }
.csa-sig-note { margin-top: var(--space-3); }
/* The signature as the email shows it: the image at email width, then its text line */
.csa-sig-box { margin-top: var(--space-2); padding: var(--space-3); border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--card); }
.csa-sig-img { display: block; width: 100%; max-width: 600px; height: auto; border-radius: var(--radius-xs); }
.csa-sig-lines { margin: var(--space-2) 0 0; font-size: var(--text-xs); line-height: 1.5; color: var(--muted); font-variant-numeric: tabular-nums; }
.csa-sig-preview .form-msg { margin-top: var(--space-2); }
