/* =====================================================================
   Casework — modern clean design system (light).
   White surfaces, soft shadows, one indigo accent, generous spacing.
   Server-rendered pages keep their class names; this stylesheet gives the
   whole app its look. Interactivity lives in app.js.
   ===================================================================== */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --surface-3: #f3f4f6;
  --border: #e5e7eb;
  --border-strong: #d0d5dd;

  --text: #101828;
  --text-soft: #667085;
  --text-mute: #98a2b3;

  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --accent-ring: rgba(79, 70, 229, 0.25);

  --green: #15803d;  --green-soft: #dcfce7;
  --amber: #b45309;  --amber-soft: #fef3c7;
  --red: #b42318;    --red-soft: #fee4e2;
  --blue: #1d4ed8;   --blue-soft: #dbeafe;
  --gray: #475467;   --gray-soft: #eef0f3;

  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --r: 14px;
  --r-sm: 9px;
  --r-xs: 6px;
  --tap: 42px;

  --shadow-sm: 0 1px 2px rgba(16,24,40,0.06), 0 1px 3px rgba(16,24,40,0.10);
  --shadow-md: 0 4px 16px -2px rgba(16,24,40,0.10), 0 2px 6px -2px rgba(16,24,40,0.06);
  --shadow-lg: 0 12px 32px -8px rgba(16,24,40,0.18);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

main {
  max-width: 1040px;
  margin: 0 auto;
  padding: 1.6rem 1.25rem 5rem;
}

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

h1, h2, h3, h4 { font-weight: 650; color: var(--text); margin: 0 0 0.5rem; line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; letter-spacing: -0.02em; }
h2 { font-size: 1.12rem; }
h3 { font-size: 1rem; }
h4 { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-soft); font-weight: 600; margin-bottom: 0.5rem; }

p { margin: 0 0 0.7rem; }
.muted { color: var(--text-mute); font-weight: 400; }
.backlink { display: inline-flex; align-items: center; gap: 0.3rem; color: var(--text-soft); font-size: 0.85rem; margin: 0 0 0.6rem; font-weight: 500; }
.backlink:hover { color: var(--accent); text-decoration: none; }
.status { font-size: 0.9rem; color: var(--text-soft); }
main > p.status { color: var(--text-soft); }

/* ---------------------------------------------------------------------
   Top bar + navigation (collapses to a bottom tab bar on phones)
   ------------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 0.75rem;
  height: 56px; padding: 0 1rem;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: saturate(1.5) blur(14px);
  -webkit-backdrop-filter: saturate(1.5) blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand { display: inline-flex; align-items: center; gap: 0.55rem; min-width: 0; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-grid; place-items: center;
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(140deg, var(--accent), #8079f2);
  color: #fff; font-size: 0.9rem; box-shadow: 0 3px 10px -3px var(--accent-ring);
}
.brand-name { font-weight: 700; font-size: 1.08rem; letter-spacing: -0.03em; color: var(--text); }

.topnav { margin-left: auto; display: flex; align-items: center; gap: 0.15rem; }
.navlink {
  padding: 0.42rem 0.8rem; border-radius: 8px;
  font-size: 0.88rem; font-weight: 550; color: var(--text-soft);
  transition: background-color 0.12s ease, color 0.12s ease;
}
.navlink:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.navlink.active { color: var(--accent); background: var(--accent-soft); }

.topbar-logout { margin-left: 0.15rem; display: inline-flex; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 38px; height: 38px; min-height: 0; padding: 0; margin: 0;
  border-radius: 9px; border: 1px solid transparent; background: transparent;
  color: var(--text-mute); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn svg { width: 19px; height: 19px; }

/* Bottom tab bar — shown only on phones (see the responsive block) */
.tabbar { display: none; }

/* ---------------------------------------------------------------------
   Cards
   ------------------------------------------------------------------- */
.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
  padding: 1.35rem 1.4rem;
  margin: 1.1rem 0;
}
.card > :first-child { margin-top: 0; }
.card > :last-child { margin-bottom: 0; }
.card .status { color: var(--text-soft); }
/* Left accent variants become a subtle top-tinted header stripe */
.card-accent-green { border-top: 3px solid var(--green); }
.card-accent-amber { border-top: 3px solid var(--amber); }

main > h1 { margin-top: 0.25rem; }
main > h2 { margin-top: 1.75rem; padding-bottom: 0.4rem; border-bottom: 1px solid var(--border); }

/* ---------------------------------------------------------------------
   Forms
   ------------------------------------------------------------------- */
label {
  display: block;
  font-size: 0.78rem; font-weight: 600; color: var(--text-soft);
  margin-bottom: 0.85rem;
}
label input, label textarea, label select { margin-top: 0.35rem; }

input, textarea, select {
  width: 100%;
  font: inherit; font-size: 0.92rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  padding: 0.55rem 0.7rem;
  min-height: var(--tap);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
input::placeholder, textarea::placeholder { color: var(--text-mute); }
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type="file"] { min-height: 0; padding: 0.4rem; background: var(--surface-2); cursor: pointer; }
input[type="checkbox"] { width: auto; min-height: 0; display: inline-block; margin-right: 0.5rem; vertical-align: middle; transform: scale(1.15); accent-color: var(--accent); }
label:has(input[type="checkbox"]) { display: flex; align-items: center; font-weight: 500; font-size: 0.9rem; color: var(--text); }
textarea { min-height: 150px; line-height: 1.5; resize: vertical; font-family: var(--mono); font-size: 0.85rem; }
select { cursor: pointer; }

@media (min-width: 641px) {
  .field-narrow input, .field-narrow select { max-width: 440px; }
}

/* Buttons */
button, .btn {
  font-family: var(--sans); font-weight: 600; font-size: 0.86rem;
  cursor: pointer; border-radius: var(--r-sm);
  padding: 0.55rem 1rem; min-height: var(--tap);
  margin: 0; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text);
  transition: background-color 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease, transform 0.04s ease;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  text-decoration: none; white-space: nowrap;
}
button:hover, .btn:hover { background: var(--surface-3); text-decoration: none; }
button:active, .btn:active { transform: translateY(1px); }
button:disabled { opacity: 0.55; cursor: default; }

button.primary, .btn.primary, button[type="submit"].primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: var(--shadow-sm);
}
button.primary:hover, .btn.primary:hover, button[type="submit"].primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

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

/* In a card, a lone submit reads as the affirmative accent action */
.card form:not(.inline-form) button[type="submit"]:not(.danger):not(.primary):only-of-type,
.card .btn-row button[type="submit"]:not(.danger):not(.primary):first-child {
  border-color: var(--accent); color: var(--accent);
}
.card .btn-row button[type="submit"]:not(.danger):not(.primary):first-child:hover { background: var(--accent); color: #fff; }

.inline { display: inline; }
.inline-form { border-top: 1px solid var(--border); padding-top: 1.1rem; margin-top: 1.1rem; }
.inline-form:first-of-type { border-top: none; margin-top: 0; padding-top: 0; }
.btn-row { display: flex; flex-wrap: wrap; gap: 0.55rem; align-items: center; }

/* Task / Personal segmented toggle in the compose-call form */
.mode-toggle { display: flex; gap: 0.55rem; margin: 0.15rem 0 0.6rem; max-width: 440px; }
.mode-opt {
  flex: 1 1 0; display: flex; flex-direction: column; gap: 0.1rem;
  padding: 0.5rem 0.7rem; border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; user-select: none; transition: border-color .12s, background .12s;
}
.mode-opt span { font-weight: 600; }
.mode-opt small { color: var(--text-soft); font-size: 0.82rem; }
.mode-opt input { position: absolute; opacity: 0; pointer-events: none; }
.mode-opt:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }

/* Button spinner (added by app.js while a form submits) */
.btn-spin::before {
  content: ""; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin 0.6s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------------
   Badges — soft status pills
   ------------------------------------------------------------------- */
.badge {
  --c: var(--gray); --bg: var(--gray-soft);
  display: inline-flex; align-items: center;
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.01em;
  color: var(--c); background: var(--bg);
  border-radius: 999px; padding: 0.12rem 0.6rem;
  white-space: nowrap; text-transform: capitalize;
  border: 1px solid color-mix(in srgb, var(--c) 22%, transparent);
}
.badge.draft, .badge.queued, .badge.pending, .badge.not_placed, .badge.call { --c: var(--amber); --bg: var(--amber-soft); }
.badge.extracted, .badge.strategized, .badge.lettered, .badge.in_progress, .badge.letter { --c: var(--blue); --bg: var(--blue-soft); }
.badge.approved, .badge.completed, .badge.sent, .badge.both { --c: var(--green); --bg: var(--green-soft); }
.badge.failed, .badge.rejected, .badge.skip { --c: var(--gray); --bg: var(--gray-soft); }
.badge.outcome-reached, .badge.outcome-resolved { --c: var(--green); --bg: var(--green-soft); }
.badge.outcome-voicemail, .badge.outcome-other { --c: var(--blue); --bg: var(--blue-soft); }
.badge.outcome-no_answer, .badge.outcome-refused { --c: var(--red); --bg: var(--red-soft); }
/* Dispute-result outcomes: deletion is the win (green); verified is a loss (red) */
.badge.outcome-deleted { --c: var(--green); --bg: var(--green-soft); }
.badge.outcome-verified { --c: var(--red); --bg: var(--red-soft); }
.badge.outcome-updated { --c: var(--amber); --bg: var(--amber-soft); }
.badge.outcome-no_response { --c: var(--gray); --bg: var(--gray-soft); }
.badge.impact { --c: var(--blue); --bg: var(--blue-soft); }
.badge.prob-high { --c: var(--green); --bg: var(--green-soft); }
.badge.prob-medium { --c: var(--amber); --bg: var(--amber-soft); }
.badge.prob-low { --c: var(--gray); --bg: var(--gray-soft); }

/* Report-change list (deletions vs new items) */
.change-list { list-style: none; margin: 0 0 0.5rem; padding: 0; }
.change-row { display: flex; align-items: center; gap: 0.5rem; padding: 0.35rem 0; }
.change-row .ch-mark { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 6px; font-weight: 800; font-size: 0.9rem; }
.change-row.removed .ch-mark { background: var(--green-soft); color: var(--green); }
.change-row.added .ch-mark { background: var(--red-soft); color: var(--red); }
.doc-analyze { margin: 0; }
.doc-analyze button { min-height: 0; padding: 0.25rem 0.55rem; font-size: 0.75rem; }

/* Dispute lifecycle dashboard (per-tradeline, round-by-round) */
.lifecycle-item { border: 1px solid var(--border); border-radius: var(--r-sm); padding: 0.75rem 0.9rem; margin: 0.6rem 0; }
.lifecycle-item.resolved { opacity: 0.7; }
.lifecycle-head { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.lifecycle-rounds { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; margin: 0.5rem 0; font-size: 0.8rem; }
.lifecycle-round { display: inline-flex; align-items: center; gap: 0.3rem; }
.lifecycle-arrow { color: var(--gray); }
.lifecycle-next { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  margin-top: 0.5rem; padding: 0.6rem 0.75rem; border-radius: var(--r-sm); background: var(--blue-soft); border-left: 3px solid var(--blue); }
.lifecycle-next.urgency-high { background: var(--red-soft); border-left-color: var(--red); }
.lifecycle-next.urgency-low { background: var(--gray-soft); border-left-color: var(--gray); }
.lifecycle-next-label { font-weight: 700; font-size: 0.9rem; }
.lifecycle-next p { margin: 0.25rem 0 0; font-size: 0.8rem; }
.lifecycle-next form { border: none; margin: 0; padding: 0; flex-shrink: 0; }
.lifecycle-next button { min-height: 0; padding: 0.4rem 0.8rem; font-size: 0.8rem; white-space: nowrap; }
.lifecycle-link { font-size: 0.72rem; margin-left: 0.2rem; }

/* Deterministic score-impact simulator card (8.5) */
.score-sim { border: 1px solid var(--border); border-radius: var(--r-sm); padding: 0.75rem 0.9rem; margin: 0.6rem 0; background: var(--green-soft); }
.score-sim-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.score-sim-title { font-weight: 700; }
.score-sim-range { font-size: 1.1rem; font-weight: 800; color: var(--green); }
.sim-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; margin: 0.5rem 0; }
.sim-table th { text-align: left; font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-mute); padding: 0.25rem 0.4rem; }
.sim-table td { padding: 0.25rem 0.4rem; border-top: 1px solid var(--border); }
.sim-disclaimer { font-size: 0.72rem; color: var(--text-mute); margin: 0.4rem 0 0; font-style: italic; }

/* Metro 2 code annotations on tradelines (8.6) */
.metro2-notes { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.35rem; }
.metro2-code { display: inline-block; font-size: 0.68rem; padding: 0.1rem 0.4rem; border-radius: 6px;
  background: var(--blue-soft); color: var(--blue); cursor: help; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.queue-banner { background: var(--blue-soft); border-left: 3px solid var(--blue); color: var(--text); }
.pager { display: flex; align-items: center; justify-content: center; gap: 1rem; margin: 1.1rem 0 0.25rem; }
.pager-btn { text-decoration: none; font-weight: 600; font-size: 0.85rem; padding: 0.4rem 0.8rem; border: 1px solid var(--border); border-radius: var(--r-sm); color: var(--text); }
.pager-btn:hover { border-color: var(--border-strong); }
.pager-info { font-size: 0.8rem; color: var(--text-mute); }

/* Live-analysis panel: streams the model's output token-by-token */
.live-panel { margin-top: 0.6rem; border: 1px solid var(--border); border-radius: var(--r-sm); background: #0e1116; }
.live-panel > summary { cursor: pointer; padding: 0.5rem 0.75rem; font-size: 0.8rem; font-weight: 600; color: #cbd5e1; list-style: none; display: flex; align-items: center; gap: 0.5rem; }
.live-panel > summary::-webkit-details-marker { display: none; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #ef4444; box-shadow: 0 0 0 0 rgba(239,68,68,0.5); animation: livepulse 1.4s infinite; }
@keyframes livepulse { 0% { box-shadow: 0 0 0 0 rgba(239,68,68,0.5); } 70% { box-shadow: 0 0 0 7px rgba(239,68,68,0); } 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0); } }
.live-text { margin: 0; padding: 0.6rem 0.85rem; max-height: 320px; overflow: auto; font-family: var(--mono); font-size: 0.72rem; line-height: 1.5; color: #b9c2d0; white-space: pre-wrap; word-break: break-word; border-top: 1px solid #1e2430; }

/* Executive report summary (top of a run) */
.report-summary { border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: var(--r-sm); padding: 0.8rem 1rem; margin: 0.6rem 0; background: var(--surface-2, var(--surface)); }
.rs-headline { font-weight: 700; font-size: 0.98rem; margin-bottom: 0.35rem; }
.rs-overview { margin: 0.2rem 0 0.5rem; font-size: 0.9rem; }
.rs-findings { margin: 0.2rem 0 0.5rem 1.1rem; padding: 0; }
.rs-findings li { margin: 0.2rem 0; font-size: 0.86rem; }
.rs-rec { margin: 0.4rem 0 0; font-size: 0.88rem; }

/* Activity page: analysis queue rows + live-call blocks */
.q-row { display: flex; align-items: center; gap: 0.7rem; padding: 0.5rem 0; border-top: 1px solid var(--border); }
.q-row:first-child { border-top: none; }
.q-num { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--surface-3); color: var(--text-soft); font-size: 0.72rem; font-weight: 700; }
.q-client { font-weight: 600; }
.q-stage { font-size: 0.82rem; margin-left: auto; text-align: right; }
.live-call-block { border-top: 1px solid var(--border); padding-top: 0.75rem; margin-top: 0.75rem; }
.live-call-block:first-of-type { border-top: none; margin-top: 0; padding-top: 0; }
.lc-head { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.4rem; }
.doc-analyze { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.doc-analyze-opt { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.72rem; color: var(--text-mute); font-weight: 500; }
.doc-analyze-opt input { width: auto; min-height: 0; margin: 0; }

/* ---------------------------------------------------------------------
   Tables
   ------------------------------------------------------------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-sm); margin: 0.5rem 0; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
thead th {
  text-align: left; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-soft); font-weight: 600; padding: 0.6rem 0.8rem;
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
tbody td { padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }

pre {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 0.9rem 1rem;
  font-family: var(--mono); font-size: 0.82rem; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word; overflow-x: auto; margin: 0.5rem 0;
}

/* ---------------------------------------------------------------------
   Dashboard
   ------------------------------------------------------------------- */
.stat-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.75rem; margin: 1.25rem 0 1.5rem; }
.stat {
  display: flex; flex-direction: column; gap: 0.2rem;
  padding: 1rem 1.05rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r);
  box-shadow: var(--shadow-sm); text-decoration: none;
  transition: transform 0.1s ease, box-shadow 0.14s ease, border-color 0.14s ease;
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); text-decoration: none; border-color: var(--border-strong); }
.stat-n { font-size: 1.9rem; font-weight: 700; line-height: 1; color: var(--text); letter-spacing: -0.02em; }
.stat-l { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-soft); font-weight: 600; }
.stat-alert { border-color: color-mix(in srgb, var(--red) 40%, var(--border)); background: linear-gradient(180deg, var(--red-soft), var(--surface) 60%); }
.stat-alert .stat-n { color: var(--red); }

.attn-row {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.7rem 0.35rem; border-bottom: 1px solid var(--border);
  text-decoration: none; color: var(--text); min-height: var(--tap);
  border-radius: var(--r-xs); transition: background 0.1s ease;
}
.attn-row:last-child { border-bottom: none; }
.attn-row:hover { background: var(--surface-2); text-decoration: none; }
.attn-name { font-weight: 650; white-space: nowrap; }
.attn-meta { flex: 1; min-width: 0; color: var(--text-soft); font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attn-date { font-family: var(--mono); font-size: 0.74rem; color: var(--text-mute); white-space: nowrap; }
.fr-go { color: var(--text-mute); font-size: 1.05rem; }
.attn-row:hover .fr-go { color: var(--accent); }
.attn-row.overdue { background: var(--red-soft); }
.attn-row.overdue .attn-date { color: var(--red); font-weight: 700; }

/* ---------------------------------------------------------------------
   Client list
   ------------------------------------------------------------------- */
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.sort-form { margin: 0; }
.sort-label { font-size: 0.78rem; color: var(--text-soft); display: inline-flex; align-items: center; gap: 0.4rem; margin: 0; font-weight: 500; }
.sort-label select { font-size: 0.82rem; padding: 0.3rem 0.5rem; min-height: 0; width: auto; }

.file-list { list-style: none; margin: 0.25rem 0 0; padding: 0; }
.file-row {
  display: flex; align-items: center; gap: 0.85rem;
  padding: 0.8rem 0.5rem; border-bottom: 1px solid var(--border);
  text-decoration: none; color: var(--text); min-height: var(--tap);
  border-radius: var(--r-xs); transition: background 0.1s ease;
}
.file-row:last-child { border-bottom: none; }
.file-row:hover { background: var(--surface-2); text-decoration: none; }
.file-row .fr-tab {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  background: var(--accent-soft); font-size: 0.95rem;
}
.file-row .fr-name { font-weight: 600; flex: 1; min-width: 0; }
.file-row .fr-meta { font-family: var(--mono); font-size: 0.72rem; color: var(--text-mute); white-space: nowrap; }

.collapsible > summary { cursor: pointer; font-weight: 600; color: var(--text); padding: 0.25rem 0; list-style: none; display: flex; align-items: center; gap: 0.4rem; }
.collapsible > summary::before { content: "▸"; color: var(--text-mute); transition: transform 0.15s ease; }
.collapsible[open] > summary::before { transform: rotate(90deg); }
.collapsible > summary::-webkit-details-marker { display: none; }
.empty { color: var(--text-mute); font-style: italic; padding: 0.85rem 0; }

/* Drop-zone */
.dropzone {
  display: block; border: 2px dashed var(--border-strong); border-radius: var(--r);
  background: var(--surface-2); padding: 1.7rem 1.25rem; text-align: center; cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease; margin-bottom: 0.85rem;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .dz-icon { font-size: 1.9rem; display: block; margin-bottom: 0.35rem; }
.dropzone .dz-title { font-weight: 650; font-size: 1rem; color: var(--text); }
.dropzone .dz-hint { font-size: 0.82rem; color: var(--text-soft); margin-top: 0.2rem; }
.dropzone .dz-file { font-family: var(--mono); font-size: 0.82rem; color: var(--accent); margin-top: 0.4rem; word-break: break-all; font-weight: 600; }
.dropzone input[type="file"] { display: none; }

/* ---------------------------------------------------------------------
   Interactive review items
   ------------------------------------------------------------------- */
.review-item { border: 1px solid var(--border); border-radius: var(--r-sm); padding: 0.95rem 1.05rem; margin-bottom: 0.85rem; background: var(--surface-2); }
.review-head { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 0.4rem; }
.review-reason { font-weight: 500; font-size: 0.82rem; margin-bottom: 0.6rem; color: var(--text-soft); }
.review-actions { display: flex; flex-wrap: wrap; gap: 0.75rem 1.25rem; align-items: center; }
.review-actions .chk { margin: 0; }
.review-actions input[inputmode="tel"] { max-width: 240px; min-height: 38px; }

/* ---------------------------------------------------------------------
   To-do list
   ------------------------------------------------------------------- */
.todo-add { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-bottom: 0.5rem; }
.todo-add input[name="text"] { flex: 1 1 240px; }
.todo-add input[name="due_date"] { width: auto; }
.todo-list { list-style: none; margin: 0.5rem 0 0; padding: 0; }
.todo-row { display: flex; align-items: center; gap: 0.65rem; padding: 0.55rem 0.35rem; border-bottom: 1px solid var(--border); border-radius: var(--r-xs); }
.todo-row:last-child { border-bottom: none; }
.todo-row .todo-text { flex: 1; min-width: 0; }
.todo-row.done .todo-text { text-decoration: line-through; color: var(--text-mute); }
.todo-due { font-family: var(--mono); font-size: 0.72rem; color: var(--text-soft); white-space: nowrap; background: var(--surface-3); padding: 0.1rem 0.45rem; border-radius: 999px; }
.todo-toggle, .todo-del { margin: 0; }
.todo-toggle button, .todo-del button {
  background: none; border: none; cursor: pointer; font-size: 1.15rem;
  color: var(--text-mute); padding: 0.1rem 0.35rem; min-height: 0; line-height: 1;
}
.todo-toggle button:hover { color: var(--green); background: none; }
.todo-del button:hover { color: var(--red); background: none; }
.todo-row.done .todo-toggle button { color: var(--green); }

/* ---------------------------------------------------------------------
   Notices
   ------------------------------------------------------------------- */
.notice { padding: 0.7rem 0.9rem; border-radius: var(--r-sm); font-size: 0.88rem; margin: 0.5rem 0; border: 1px solid transparent; }
.notice.error, .error { color: var(--red); }
.notice.error { background: var(--red-soft); border-color: color-mix(in srgb, var(--red) 25%, transparent); }

/* ---------------------------------------------------------------------
   Toasts (app.js)
   ------------------------------------------------------------------- */
#toasts { position: fixed; bottom: 1.1rem; right: 1.1rem; z-index: 60; display: flex; flex-direction: column; gap: 0.5rem; max-width: min(360px, calc(100vw - 2rem)); }
.toast {
  display: flex; align-items: center; gap: 0.55rem;
  background: var(--text); color: #fff; padding: 0.7rem 0.9rem;
  border-radius: var(--r-sm); box-shadow: var(--shadow-lg); font-size: 0.88rem;
  animation: toast-in 0.22s cubic-bezier(0.2,0.8,0.3,1);
}
.toast.ok { background: #0b3d24; }
.toast.err { background: #5b1512; }
.toast::before { content: "✓"; font-weight: 700; }
.toast.err::before { content: "!"; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.toast.leaving { opacity: 0; transform: translateY(8px); transition: opacity 0.2s ease, transform 0.2s ease; }

/* ---------------------------------------------------------------------
   Status bar + activity log drawer
   ------------------------------------------------------------------- */
.statusbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; padding: 0.4rem 1.25rem;
  background: var(--surface); border-bottom: 1px solid var(--border); font-size: 0.78rem;
}
.sb-services { display: flex; gap: 1rem; flex-wrap: wrap; align-items: center; }
.sb-svc { display: inline-flex; align-items: center; gap: 0.4rem; color: var(--text-soft); font-weight: 500; }
.sb-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--text-mute); }
.sb-dot.ok { background: #17b26a; box-shadow: 0 0 0 3px rgba(23,178,106,0.15); }
.sb-dot.down { background: #f04438; box-shadow: 0 0 0 3px rgba(240,68,56,0.15); }
.sb-dot.idle { background: #f79009; box-shadow: 0 0 0 3px rgba(247,144,9,0.15); }
.sb-dot.loading { background: #f79009; }
.sb-testmode {
  display: inline-flex; align-items: center;
  background: var(--amber-soft); color: var(--amber);
  border: 1px solid var(--amber); border-radius: 999px;
  padding: 0.15rem 0.65rem; font-weight: 700; font-size: 0.72rem;
  letter-spacing: 0.02em; white-space: nowrap;
}
.switch-row { display: flex; align-items: center; gap: 0.5rem; font-weight: 500; color: var(--text); }
.sb-actions { display: flex; gap: 0.5rem; }
.sb-btn {
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-xs);
  padding: 0.22rem 0.6rem; font-size: 0.75rem; font-weight: 550; cursor: pointer; color: var(--text); min-height: 0;
}
.sb-btn:hover { background: var(--surface-3); }
.sb-btn:disabled { opacity: 0.6; cursor: default; }

.logdrawer { border-bottom: 1px solid var(--border); background: #0e1116; color: #cdd3de; }
.ld-head { display: flex; align-items: center; justify-content: space-between; padding: 0.45rem 1.25rem; background: #161a22; color: #e6e9ef; }
.ld-head .sb-btn { color: #d5dae2; border-color: #2b3140; background: #1c212b; }
.ld-head .sb-btn:hover { background: #232935; }
.ld-body { margin: 0; padding: 0.75rem 1.25rem; max-height: 260px; overflow: auto; font-family: var(--mono); font-size: 0.72rem; line-height: 1.55; white-space: pre-wrap; word-break: break-word; background: #0e1116; border: none; border-radius: 0; }

/* ---------------------------------------------------------------------
   Login
   ------------------------------------------------------------------- */
.access-wrap { min-height: 80vh; display: flex; align-items: center; justify-content: center; }
.access-card { width: 100%; max-width: 380px; }
.access-card h1 { text-align: center; }
.access-card .status { text-align: center; margin-bottom: 1.4rem; }
.access-card button[type="submit"] { width: 100%; margin-top: 0.3rem; }

/* ---------------------------------------------------------------------
   Responsive — phones get a native-style bottom tab bar
   ------------------------------------------------------------------- */
@media (max-width: 720px) {
  .stat-row { grid-template-columns: repeat(2, 1fr); }

  /* Move primary nav off the crowded top bar and onto the bottom. */
  .topnav { display: none; }
  .topbar-logout { margin-left: auto; }
  main { padding: 1.4rem 1rem calc(76px + env(safe-area-inset-bottom, 0px)); }

  .tabbar {
    display: grid; grid-template-columns: repeat(6, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
    background: color-mix(in srgb, var(--surface) 90%, transparent);
    backdrop-filter: saturate(1.5) blur(16px);
    -webkit-backdrop-filter: saturate(1.5) blur(16px);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-shadow: 0 -6px 20px -12px rgba(16,24,40,0.25);
  }
  .tab {
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 0.5rem 0 0.45rem; text-decoration: none;
    color: var(--text-mute); font-size: 0.6rem; font-weight: 650; letter-spacing: 0;
    -webkit-tap-highlight-color: transparent; min-width: 0;
  }
  .tab span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tab svg { width: 22px; height: 22px; }
  .tab.active { color: var(--accent); }
  .tab:active { background: var(--surface-3); }
}
@media (max-width: 560px) {
  main { padding-left: 0.85rem; padding-right: 0.85rem; }
  h1 { font-size: 1.35rem; }
  .card { padding: 1.1rem; }
  .btn-row button, .btn-row .btn { flex: 1 1 auto; }
  /* New components: keep the follow-up draft button full-width, let the score
     table scroll rather than overflow the viewport, single-column reference. */
  .lifecycle-next { flex-direction: column; align-items: stretch; }
  .lifecycle-next form, .lifecycle-next button { width: 100%; }
  .sim-table { display: block; overflow-x: auto; white-space: nowrap; }
  .two-col { grid-template-columns: 1fr; }
  .score-sim-head { flex-direction: column; align-items: flex-start; gap: 0.25rem; }
}

/* ---------------------------------------------------------------------
   Client documents
   ------------------------------------------------------------------- */
.doc-add { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.doc-add .doc-cat, .doc-add .doc-note-in { margin-bottom: 0; }
.doc-add .doc-note-in { flex: 1 1 180px; }
.doc-list { list-style: none; margin: 0.85rem 0 0; padding: 0; }
.doc-row { display: flex; align-items: center; gap: 0.6rem; padding: 0.55rem 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.doc-row:first-child { border-top: none; }
.doc-file { font-weight: 600; }
.doc-meta { font-family: var(--mono); font-size: 0.72rem; color: var(--text-mute); white-space: nowrap; }
.doc-note { color: var(--text-soft); font-size: 0.85rem; font-style: italic; }
.doc-del { margin: 0 0 0 auto; }
.doc-del button { background: none; border: none; color: var(--text-mute); cursor: pointer; font-size: 1rem; padding: 0.1rem 0.4rem; min-height: 0; }
.doc-del button:hover { color: var(--red); background: none; }

/* ---------------------------------------------------------------------
   Metrics
   ------------------------------------------------------------------- */
.stat-accent { border-top: 3px solid var(--accent); }
.stat-accent .stat-n { color: var(--accent); }
.chip-row { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.rate-cell { display: flex; align-items: center; gap: 0.5rem; }
.rate-bar { flex: 1; min-width: 60px; height: 6px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.rate-bar > i { display: block; height: 100%; background: var(--green); border-radius: 999px; }
.bars { display: flex; align-items: flex-end; gap: 0.6rem; height: 160px; padding-top: 0.5rem; overflow-x: auto; }
.bar-col { display: flex; flex-direction: column; align-items: center; gap: 0.3rem; min-width: 44px; height: 100%; justify-content: flex-end; }
.bar-track { width: 26px; flex: 1; display: flex; align-items: flex-end; background: var(--surface-3); border-radius: 6px 6px 0 0; overflow: hidden; }
.bar-fill { width: 100%; background: linear-gradient(180deg, var(--accent), #8079f2); border-radius: 6px 6px 0 0; min-height: 3px; }
.bar-n { font-family: var(--mono); font-size: 0.72rem; font-weight: 600; }
.bar-l { font-size: 0.64rem; color: var(--text-mute); white-space: nowrap; }

/* ---------------------------------------------------------------------
   Progress bar (PDF import)
   ------------------------------------------------------------------- */
.progress { margin-top: 0.9rem; }
.progress-label { font-size: 0.85rem; color: var(--text-soft); margin-bottom: 0.4rem; font-weight: 500; }
.progress-track { height: 8px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.progress-fill {
  height: 100%; width: 0; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), #8079f2);
  transition: width 0.5s cubic-bezier(.2,.7,.2,1);
}
.progress-fill.error { background: var(--red); }

/* ---------------------------------------------------------------------
   Live call progress + real-time transcript (client detail call card)
   ------------------------------------------------------------------- */
.live-call { margin-top: 0.75rem; padding: 0.75rem 0.9rem; border: 1px solid var(--border, #e5e7eb);
  border-radius: 10px; background: var(--surface-2, #f9fafb); }
.live-stage { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; font-size: 0.9rem; }
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--amber, #b45309);
  box-shadow: 0 0 0 4px rgba(180,83,9,0.14); animation: live-pulse 1.2s ease-in-out infinite; }
.live-dot.stage-ringing { background: var(--blue, #1d4ed8); box-shadow: 0 0 0 4px rgba(29,78,216,0.14); }
.live-dot.stage-talking { background: var(--green, #15803d); box-shadow: 0 0 0 4px rgba(21,128,61,0.16); }
.live-dot.stage-ended { background: var(--text-mute, #98a2b3); animation: none; }
.live-dot.stage-failed { background: var(--red, #b42318); animation: none; }
@keyframes live-pulse { 50% { opacity: 0.45; } }
.live-progress { margin-top: 0.6rem; display: flex; align-items: center; gap: 0.6rem; }
.live-progress-track { flex: 1 1 auto; height: 7px; border-radius: 999px;
  background: var(--surface-3, #f3f4f6); overflow: hidden; }
.live-progress-fill { display: block; height: 100%; width: 0%; border-radius: 999px;
  background: var(--green, #15803d); transition: width 0.9s linear; }
.live-progress-fill.low { background: var(--red, #b42318); }
.live-progress-label { font-size: 0.78rem; font-variant-numeric: tabular-nums;
  color: var(--text-mute, #667085); white-space: nowrap; }
.live-transcript { margin-top: 0.65rem; max-height: 260px; overflow-y: auto; display: flex;
  flex-direction: column; gap: 0.4rem; }
.tline { font-size: 0.9rem; line-height: 1.4; padding: 0.35rem 0.55rem; border-radius: 8px; }
.tline .who { font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  margin-right: 0.4rem; opacity: 0.7; }
.tline.them { background: var(--surface-3, #f3f4f6); align-self: flex-start; max-width: 88%; }
.tline.ai { background: var(--accent-soft, #eef2ff); align-self: flex-end; max-width: 88%; }

/* Score action plan (per pipeline run) */
.score-plan { margin: 0.75rem 0; padding: 0.5rem 0.9rem; border: 1px solid var(--accent, #4f46e5);
  border-radius: 10px; background: var(--accent-soft, #eef2ff); }
.score-plan > summary { cursor: pointer; font-weight: 700; color: var(--accent, #4f46e5); }
.score-plan h4 { margin: 0.7rem 0 0.3rem; }
.score-plan ul, .score-plan ol { margin: 0.2rem 0 0.4rem 1.1rem; }
.score-plan li { margin: 0.15rem 0; font-size: 0.9rem; }
.score-plan .seq li { margin: 0.25rem 0; }
