:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --border: #e0e0e0;
  --text: #1a1a1a;
  --muted: #666;
  --accent: #1a56db;
  --accent-light: #e8f0fe;
  --green: #0d7a47;
  --green-bg: #d1fae5;
  --yellow: #854d0e;
  --yellow-bg: #fef9c3;
  --orange: #c2410c;
  --orange-bg: #ffedd5;
  --red: #991b1b;
  --red-bg: #fee2e2;
  --neg: #c0392b;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* Nav */
nav {
  background: #111;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
}
.nav-brand {
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  font-size: 15px;
}
.nav-links a {
  color: #ccc;
  text-decoration: none;
  font-size: 13px;
}
.nav-links a:hover { color: #fff; }

/* Main layout */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

/* Page header */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
}
.page-header h1 {
  font-size: 22px;
  font-weight: 700;
}
.subtitle { color: var(--muted); font-size: 13px; margin-top: 2px; }
.back {
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
  display: block;
  margin-bottom: 4px;
}
.back:hover { text-decoration: underline; }

/* Upload */
.upload-btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}
.upload-btn input { display: none; }
.upload-btn:hover { background: #1648c5; }

/* Grid layouts */
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}
.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}
@media (max-width: 900px) {
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
}

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 16px;
}
.card h2 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 14px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.full-width { width: 100%; }

/* File list */
.file-list {
  list-style: none;
}
.file-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.file-list li:last-child { border-bottom: none; }
.file-list a { color: var(--accent); text-decoration: none; }
.file-list a:hover { text-decoration: underline; }
.filename { flex: 1; }
.filesize { color: var(--muted); font-size: 12px; }
.empty { color: var(--muted); font-size: 13px; }

/* Financial tables */
.fin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.fin-table tr { border-bottom: 1px solid var(--border); }
.fin-table tr:last-child { border-bottom: none; }
.fin-table td { padding: 6px 4px; }
.fin-table td:last-child { text-align: right; }
.fin-table tr.subtotal {
  font-weight: 600;
  background: var(--bg);
}
.fin-table tr.section-head td {
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding-top: 14px;
  font-weight: 600;
}
.fin-table.compact td { padding: 5px 4px; }

.num { font-variant-numeric: tabular-nums; font-family: "SF Mono", monospace; }
.neg { color: var(--neg); }

.derived-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 4px 0;
  margin-top: 8px;
  border-top: 2px solid var(--border);
  font-weight: 600;
  font-size: 13px;
}

/* Ratio grid */
.ratio-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 24px;
}
.ratio-category h3 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 10px;
}
.ratio-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.ratio-row:last-child { border-bottom: none; }
.ratio-label { flex: 1; color: var(--text); }
.ratio-val { font-weight: 600; font-family: "SF Mono", monospace; font-size: 12px; padding: 2px 8px; border-radius: 12px; }
.ratio-assessment { font-size: 11px; color: var(--muted); width: 70px; text-align: right; }

/* Badges */
.badge-strong { background: var(--green-bg); color: var(--green); }
.badge-acceptable { background: var(--yellow-bg); color: var(--yellow); }
.badge-watch { background: var(--orange-bg); color: var(--orange); }
.badge-concern { background: var(--red-bg); color: var(--red); }
.badge-unrated { background: var(--bg); color: var(--muted); }
.badge-NA { background: var(--bg); color: var(--muted); }

/* Flags */
.flag-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.flag-list li {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.5;
}
.flag-value { display: inline-block; margin-left: 8px; font-size: 12px; color: var(--accent); font-weight: 500; }
.flag-reason { margin-top: 4px; font-weight: 400; }
.flag-source { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* Compact flagged items (categorised, collapsible) */
.flag-section details summary { cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; padding: 4px 0; }
.flag-section details summary::-webkit-details-marker { display: none; }
.flag-section details summary::before { content: "▸"; margin-right: 8px; font-size: 10px; color: var(--muted); transition: transform 0.15s; display: inline-block; }
.flag-section details[open] summary::before { transform: rotate(90deg); }
.flag-summary-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); flex: 1; }
.flag-summary-counts { display: flex; gap: 6px; }
.flag-pill { font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: 10px; }
.flag-pill-material { background: var(--red-bg); color: var(--red); }
.flag-pill-methodology { background: var(--accent-light); color: var(--accent); }
.flag-pill-info { background: var(--bg); color: var(--muted); }

.flag-group { margin-top: 14px; }
.flag-group-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px; padding-left: 8px; border-left: 3px solid; }
.flag-group-title.flag-material { border-color: var(--red); color: var(--red); }
.flag-group-title.flag-methodology { border-color: var(--accent); color: var(--accent); }
.flag-group-title.flag-info { border-color: var(--muted); color: var(--muted); }

.flag-list-compact { list-style: none; display: flex; flex-direction: column; gap: 4px; }
.flag-item { padding: 6px 10px; font-size: 12px; line-height: 1.5; background: var(--bg); border-radius: 4px; }
.flag-field { font-weight: 600; font-size: 12px; display: inline; }
.flag-field::after { content: " — "; color: var(--muted); font-weight: 400; }
.flag-note { display: inline; color: var(--text); }

/* ── Memo (rich-text rendered Markdown) ────────────────────────────────── */

/* Old monospace pre-wrap style kept for any legacy callers.
   The new memo.html uses .memo-doc (below) instead. */
.memo-card { overflow-x: auto; }
.memo-content {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
  max-width: 900px;
}

/* The proper credit-memo document: looks like an actual deliverable.
   Goal is "this could go to a credit committee" — generous whitespace,
   real typography, banded financial tables with right-aligned numerics. */
.memo-doc {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  max-width: 900px;
  margin: 0 auto 32px;
  padding: 56px 64px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 14.5px;
  line-height: 1.65;
  color: #1f2937;
}

@media (max-width: 700px) {
  .memo-doc { padding: 32px 22px; }
}

/* Typography */
.memo-doc h1 {
  font-size: 26px;
  font-weight: 700;
  margin: 0 0 24px;
  padding-bottom: 14px;
  border-bottom: 2px solid #1f2937;
  color: #111827;
  letter-spacing: -0.01em;
}
.memo-doc h2 {
  font-size: 19px;
  font-weight: 700;
  margin: 36px 0 14px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  color: #111827;
  letter-spacing: -0.005em;
}
.memo-doc h3 {
  font-size: 15.5px;
  font-weight: 600;
  margin: 24px 0 10px;
  color: #374151;
}
.memo-doc h4 {
  font-size: 14px;
  font-weight: 600;
  margin: 18px 0 8px;
  color: #4b5563;
}
.memo-doc p { margin: 10px 0; }
.memo-doc strong { color: #111827; font-weight: 600; }
.memo-doc em { color: #4b5563; }

/* Lead block (the "Obligor / Period / Currency" stack at the top of every memo) */
.memo-doc h1 + p {
  background: #f9fafb;
  border-left: 3px solid var(--accent);
  border-radius: 0 4px 4px 0;
  padding: 14px 18px;
  margin: 0 0 24px;
  font-size: 13.5px;
  line-height: 1.85;
  color: #374151;
}

/* Lists */
.memo-doc ul, .memo-doc ol { margin: 10px 0 14px; padding-left: 24px; }
.memo-doc li { margin: 4px 0; }
.memo-doc li > p { margin: 4px 0; }

/* Block quotes */
.memo-doc blockquote {
  border-left: 3px solid var(--accent);
  background: #f0f6ff;
  margin: 16px 0;
  padding: 12px 18px;
  color: #1f2937;
  border-radius: 0 4px 4px 0;
}

/* Horizontal rules */
.memo-doc hr {
  border: none;
  height: 1px;
  background: var(--border);
  margin: 28px 0;
}

/* Inline code & code blocks */
.memo-doc code {
  font-family: "SF Mono", "Fira Code", "Menlo", monospace;
  font-size: 0.88em;
  background: #f3f4f6;
  color: #c026d3;
  padding: 1px 6px;
  border-radius: 3px;
}
.memo-doc pre {
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px 14px;
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.5;
}
.memo-doc pre code {
  background: none;
  color: #1f2937;
  padding: 0;
}

/* Tables — the centrepiece of a credit memo */
.memo-doc table {
  width: 100%;
  border-collapse: collapse;
  margin: 18px 0;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.memo-doc thead {
  background: #f9fafb;
  border-bottom: 2px solid #1f2937;
}
.memo-doc th {
  text-align: left;
  font-weight: 600;
  color: #1f2937;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 11px;
  padding: 10px 12px;
}
.memo-doc td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.memo-doc tr:last-child td { border-bottom: none; }
.memo-doc tbody tr:nth-child(even) { background: #fafbfc; }
.memo-doc tbody tr:hover { background: #f0f6ff; }
/* Markdown's `---:` syntax produces style="text-align: right" — for numerics. */
.memo-doc th[style*="right"], .memo-doc td[style*="right"] {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 12.5px;
}
/* Bold rows in tables (totals / subtotals — markdown renders `**Net income**` as <strong>) */
.memo-doc td strong { color: #111827; font-weight: 700; }
.memo-doc td:first-child { font-weight: 500; }

/* Negative numbers in parentheses get coloured red. Markdown can't tag these
   itself, so we leave the visual cue to the (12,345) parens — which most
   credit analysts read as negative anyway. */

/* Print: clean document, no chrome */
@media print {
  .memo-doc {
    box-shadow: none;
    border: none;
    padding: 0;
    max-width: none;
    font-size: 11pt;
    color: #000;
  }
  .memo-doc h1 { font-size: 22pt; }
  .memo-doc h2 { font-size: 14pt; }
  .memo-doc h3 { font-size: 12pt; }
  .memo-doc table { page-break-inside: avoid; }
  .memo-doc h2, .memo-doc h3 { page-break-after: avoid; }
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  text-decoration: none;
  line-height: 1.4;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #1648c5; }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }

/* Page header actions */
.page-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Form fields */
.field { margin-bottom: 12px; }
.field-label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.05em; }
.field-input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
}

/* Step description */
.step-desc { font-size: 13px; color: var(--muted); margin-bottom: 14px; line-height: 1.5; }

/* Extraction status */
.extract-status {
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 12px;
  line-height: 1.5;
}
.extract-idle { background: var(--bg); color: var(--muted); }
.extract-running { background: var(--accent-light); color: var(--accent); }
.extract-ok { background: var(--green-bg); color: var(--green); }
.extract-warn { background: var(--yellow-bg); color: var(--yellow); }
.extract-error { background: var(--red-bg); color: var(--red); }

/* Memo generation status */
.memo-status { font-size: 13px; margin-top: 10px; }
.memo-running { color: var(--accent); }
.memo-ok { color: var(--green); }
.memo-error { color: var(--red); }

/* Spinner */
.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 4px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Progress bar */
.progress-wrap {
  margin-top: 8px;
}
.progress-bar-outer {
  width: 100%;
  height: 6px;
  background: #e0e7f1;
  border-radius: 3px;
  overflow: hidden;
}
.progress-bar-inner {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  width: 0%;
  transition: width 1s ease;
}
.progress-step {
  font-size: 12px;
  color: var(--accent);
  margin-top: 6px;
}

/* Button row */
.btn-row { display: flex; gap: 8px; }

/* Companies section */
.company-list { display: flex; flex-direction: column; gap: 12px; }
.company-row-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  background: var(--bg);
}
.company-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.company-name {
  font-weight: 600;
  font-size: 15px;
}
.company-row-body { display: flex; flex-direction: column; gap: 6px; }
.company-section { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.company-section-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); min-width: 80px; }
.btn-delete {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 4px;
  cursor: pointer;
}
.btn-delete:hover { color: var(--red); border-color: var(--red); }
.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
}
.pill-spread { background: var(--accent-light); color: var(--accent); }
.pill-spread:hover { background: #d0e4ff; }
.pill-memo { background: var(--green-bg); color: var(--green); }
.pill-memo:hover { background: #a7f3d0; }
.pill-pdf { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }
.pill-pdf:hover { background: var(--border); }
.no-memo-hint { font-size: 12px; color: var(--muted); font-style: italic; }

/* Search row */
.search-row { display: flex; gap: 8px; }
.search-row .field-input { flex: 1; }

/* CH search results */
.ch-result {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.ch-result:last-child { border-bottom: none; }
.ch-result:hover { background: var(--accent-light); margin: 0 -12px; padding: 12px; border-radius: 6px; }
.ch-result-body { flex: 1; }
.ch-result-name { font-weight: 600; font-size: 14px; }
.ch-result-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.ch-result-address { font-size: 12px; color: var(--muted); margin-top: 3px; line-height: 1.4; }
.ch-result-sep { color: var(--border); padding: 0 4px; }
.ch-status { font-size: 11px; padding: 2px 8px; border-radius: 12px; text-transform: capitalize; flex-shrink: 0; }
.ch-status-active { background: var(--green-bg); color: var(--green); }
.ch-status-other { background: var(--bg); color: var(--muted); }
.ch-status-cached { background: var(--accent-light); color: var(--accent); }

/* Previously-analysed rows on /advisor/ wrap the link + a delete
   button. The inner <a> takes the full row width minus the button so
   clicking anywhere on the metadata still navigates. */
.ch-result-with-actions {
  cursor: default;
  padding-right: 0;
}
.ch-result-with-actions:hover { background: transparent; margin: 0; padding: 12px 0; border-radius: 0; }
.ch-result-link {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
  text-decoration: none;
  color: inherit;
  padding: 4px 8px;
  margin: -4px -8px;
  border-radius: 6px;
}
.ch-result-link:hover { background: var(--accent-light); }
.ch-result-delete {
  flex-shrink: 0;
  margin-left: 8px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.ch-result-delete:hover {
  background: var(--red-bg, #fee);
  color: var(--red, #c00);
  border-color: var(--red, #c00);
}

/* Previously-analysed cards on /advisor/ — small metadata pills below the name */
.ch-result-badges { margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; }
.ch-meta-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
}
.ch-meta-badge-accent { background: var(--accent-light); color: var(--accent); border-color: transparent; }

/* Small "Generated <relative-date>" stamp next to the Refresh button in
   the advisor analysis page header. Sits inline with the action buttons
   but visually subordinate. */
.header-meta-stamp {
  display: inline-block;
  margin-left: 8px;
  font-size: 12px;
  color: var(--muted);
  vertical-align: middle;
}

/* ── Activity panel (background-jobs popover in the nav) ──────────────── */
.nav-activity {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.nav-activity .activity-icon {
  display: inline-block;
  margin-right: 4px;
}
.nav-activity-running .activity-icon {
  /* Steady pulse while at least one job is running */
  animation: activity-pulse 1.5s ease-in-out infinite;
}
@keyframes activity-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.55; transform: scale(1.15); }
}
.nav-activity-flash {
  /* One-shot highlight when a job transitions to done */
  animation: activity-flash 1.8s ease-out;
}
@keyframes activity-flash {
  0%   { background: var(--green-bg); border-radius: 6px; }
  100% { background: transparent; }
}

.activity-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.18);
  z-index: 95;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease-out;
}
.activity-backdrop-open {
  opacity: 1;
  pointer-events: auto;
}

.activity-panel {
  position: fixed;
  top: 56px;
  right: 16px;
  width: 380px;
  max-height: 70vh;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.14);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transform: translateY(-12px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.18s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.18s ease-out;
}
.activity-panel-open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}
.activity-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.activity-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.activity-close:hover { color: #000; }
.activity-section {
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.activity-section:last-child { border-bottom: none; }
.activity-section h4 {
  margin: 6px 14px 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  font-weight: 600;
}
.activity-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
}
.activity-row a {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 14px;
  text-decoration: none;
  color: inherit;
  border-left: 3px solid transparent;
}
.activity-row a:hover { background: var(--accent-light); }
.activity-row-running a { border-left-color: var(--accent); }
.activity-row-queued a  { border-left-color: var(--muted); }
.activity-row-done a    { border-left-color: var(--green); }
.activity-row-error a   { border-left-color: #b91c1c; }
.activity-row-icon { font-size: 16px; line-height: 18px; flex-shrink: 0; }
.activity-row-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}
.activity-row-label {
  font-size: 13px;
  font-weight: 500;
  color: #111;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.activity-row-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 1px;
}
.activity-empty {
  padding: 14px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

/* Inline progress UI for the Download & Spread button. Replaces the
   plain "Downloading…" disabled-button text with an animated stripe
   + an elapsed-seconds counter so the RM can see something IS happening
   while CH's slow download + Postgres bytea write run (typically
   10-30s for a 1-3 MB filing). No real progress is reported by the
   backend; the stripe is purely a heartbeat. */
.dl-progress {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  position: relative;
  padding: 2px 4px;
}
.dl-progress-bar {
  display: inline-block;
  width: 60px;
  height: 4px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
}
.dl-progress-bar::before {
  content: '';
  position: absolute;
  inset: 0;
  width: 30%;
  background: #fff;
  border-radius: 2px;
  animation: dl-stripe 1.2s ease-in-out infinite;
}
@keyframes dl-stripe {
  0%   { transform: translateX(-100%); }
  50%  { transform: translateX(120%); }
  100% { transform: translateX(-100%); }
}
.dl-progress-label { font-size: 12px; }
.dl-elapsed {
  font-variant-numeric: tabular-nums;
  opacity: 0.85;
}

/* Inline error shown next to a Download & Spread button on the
   Companies House filings list when /api/ch/download fails. Replaces
   the previous "Failed" button-label-only treatment which hid the
   actual cause from the user. */
.ch-download-error {
  margin-top: 6px;
  padding: 6px 10px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 4px;
  color: #991b1b;
  font-size: 12px;
  line-height: 1.4;
  max-width: 420px;
}

/* Filing rows */
.filing-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.filing-row:last-child { border-bottom: none; }
.filing-date { font-size: 12px; color: var(--muted); min-width: 90px; font-family: "SF Mono", monospace; }
.filing-desc { flex: 1; font-size: 13px; }
.filing-pages { font-size: 12px; color: var(--muted); min-width: 30px; }
.btn-sm { padding: 5px 12px; font-size: 12px; }

/* Analysis results */
.results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 16px;
}
@media (max-width: 600px) { .results-grid { grid-template-columns: 1fr; } }
.result-group h3 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 8px;
}
.result-link {
  display: block;
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 6px;
  margin-bottom: 4px;
  text-transform: capitalize;
}
.result-link:hover { background: var(--accent-light); }
.result-link-memo {
  font-weight: 600;
  color: var(--green);
}
.result-link-memo:hover { background: var(--green-bg); }
/* Placeholder used while the memo SSE stream is still running but the
   spread is already ready (non-blocking handover on the PDF page). */
.result-link-pending {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 6px;
  color: var(--muted);
  font-style: italic;
}
.result-note { font-size: 12px; color: var(--muted); font-style: italic; margin-top: 6px; }

/* Agent hub cards */
.agent-card {
  padding: 24px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  text-decoration: none;
  display: block;
  color: var(--text);
}
.grid-4 .agent-card h3 { font-size: 16px; }
.grid-4 .agent-card p { font-size: 12px; }
.agent-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 12px rgba(26, 86, 219, 0.12);
}
.agent-card h3 { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.agent-card p { color: var(--muted); font-size: 13px; line-height: 1.5; }
.agent-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 14px;
}
.agent-icon-credit { background: var(--accent-light); color: var(--accent); }
.agent-icon-directors { background: var(--green-bg); color: var(--green); }
.agent-icon-charges { background: #ffedd5; color: #c2410c; }
.agent-icon-advisor { background: #e0e7ff; color: #4338ca; }
.agent-icon-crm { background: #e0e7ff; color: #4338ca; font-size: 12px; }

.hub-section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 24px 0 10px;
}
.hub-section-title:first-child { margin-top: 0; }
.grid-1 { display: grid; grid-template-columns: 1fr; gap: 16px; margin-bottom: 16px; }
.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .grid-4 { grid-template-columns: 1fr; } }

/* Officer list */
.officer-list { display: flex; flex-direction: column; }
.officer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.officer-row:last-child { border-bottom: none; }
.officer-resigned { opacity: 0.5; }
.officer-info { flex: 1; }
.officer-name { font-weight: 600; font-size: 14px; }
.officer-meta { font-size: 12px; color: var(--muted); margin-top: 2px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.officer-role-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  background: var(--accent-light);
  color: var(--accent);
  margin-right: 4px;
}

/* Network graph */
#network-graph {
  width: 100%;
  height: 600px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}
.graph-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.graph-legend { display: flex; flex-wrap: wrap; gap: 10px 16px; font-size: 13px; color: var(--muted); align-items: center; }
.graph-legend-item { display: flex; align-items: center; gap: 6px; }
.graph-legend-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.graph-legend-box { width: 14px; height: 10px; border-radius: 2px; flex-shrink: 0; }
/* Prospect list */
.prospect-list { display: flex; flex-direction: column; }
.prospect-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.prospect-row:last-child { border-bottom: none; }
.prospect-info { flex: 1; }
.prospect-name { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.prospect-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.prospect-reason { font-size: 13px; color: var(--text); margin-top: 4px; line-height: 1.5; }
.prospect-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  flex-shrink: 0;
}
.prospect-direct { background: var(--accent-light); color: var(--accent); }
.prospect-introduction { background: #d1fae5; color: #065f46; }
.prospect-overlap { background: #ccfbf1; color: #115e59; }
.prospect-portfolio { background: #ede9fe; color: #5b21b6; }
.prospect-former { background: #fef3c7; color: #92400e; }
.prospect-family { background: #fce7f3; color: #9d174d; }
.prospect-secretary { background: var(--bg); color: var(--muted); }
.prospect-actions { flex-shrink: 0; padding-top: 2px; }

/* Confidence scoring */
.prospect-score-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 48px;
  flex-shrink: 0;
}
.confidence-badge {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  font-family: "SF Mono", monospace;
}
.confidence-label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; margin-top: 2px; }
.confidence-high { background: var(--green-bg); color: var(--green); }
.confidence-high-text { color: var(--green); }
.confidence-medium { background: var(--yellow-bg); color: var(--yellow); }
.confidence-medium-text { color: var(--yellow); }
.confidence-low { background: var(--bg); color: var(--muted); }
.confidence-low-text { color: var(--muted); }

.connection-list { margin-top: 4px; }
.connection-item { font-size: 12px; color: var(--muted); line-height: 1.5; padding: 1px 0; }

/* Peer comparison */
.peer-cards { display: flex; gap: 12px; margin-bottom: 24px; overflow-x: auto; padding-bottom: 4px; }
.peer-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  min-width: 200px;
  flex: 1;
}
.peer-card-name { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.peer-card-reason { font-size: 12px; color: var(--muted); line-height: 1.4; margin-bottom: 6px; }
.peer-card-source { font-size: 11px; color: var(--accent); }

.peer-metrics { display: flex; flex-direction: column; gap: 20px; margin-bottom: 24px; }
.peer-metric-row { }
.peer-metric-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.peer-metric-header-right { display: flex; align-items: center; gap: 8px; }
.metric-direction { font-size: 11px; color: var(--muted); font-style: italic; }
.bar-row-subject { background: var(--accent-light); margin: 0 -8px; padding: 3px 8px; border-radius: 4px; }

/* Peer bar tooltip */
.peer-bar-tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  z-index: 50;
  background: #1a1a1a;
  color: #fff;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.5;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  pointer-events: none;
}
.peer-bar-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 16px;
  border: 5px solid transparent;
  border-top-color: #1a1a1a;
}
.peer-metric-bar-row:hover .peer-bar-tooltip { display: block; }
.peer-metric-label { font-weight: 600; font-size: 13px; }

.peer-metric-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
}
.peer-metric-name { font-size: 12px; color: var(--muted); width: 160px; min-width: 160px; max-width: 160px; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: default; position: relative; }
.peer-metric-name-subject { color: var(--text); font-weight: 600; }
.peer-metric-bar-wrap { flex: 1; min-width: 0; height: 18px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.peer-metric-bar { height: 100%; border-radius: 4px; transition: width 0.6s ease; min-width: 2px; }
.bar-subject { background: var(--accent); }
.bar-peer { background: #94a3b8; }
.peer-metric-val { font-size: 12px; font-family: "SF Mono", monospace; min-width: 60px; text-align: right; flex-shrink: 0; }
.peer-metric-median { border-top: 1px dashed var(--border); padding-top: 4px; margin-top: 2px; }
.peer-metric-median .peer-metric-name { font-style: italic; }

.metric-indicator {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 10px;
}
.metric-up { background: var(--green-bg); color: var(--green); }
.metric-down { background: var(--red-bg); color: var(--red); }
.metric-inline { background: var(--bg); color: var(--muted); }

.peer-summary, .peer-caveats { margin-bottom: 16px; }
.peer-summary h3, .peer-caveats h3 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 8px; }
.peer-summary ul, .peer-caveats ul { list-style: none; }
.peer-summary li { font-size: 13px; line-height: 1.6; padding: 4px 0; padding-left: 16px; position: relative; }
.peer-summary li::before { content: "→"; position: absolute; left: 0; color: var(--accent); }
.peer-caveats li { font-size: 12px; color: var(--muted); line-height: 1.5; padding: 2px 0; padding-left: 16px; position: relative; }
.peer-caveats li::before { content: "·"; position: absolute; left: 4px; }

/* Charges analysis */
.stats-row { display: flex; gap: 12px; flex-wrap: wrap; }
.stat-box { flex: 1; min-width: 100px; text-align: center; padding: 14px 12px; background: var(--bg); border-radius: 8px; }
.stat-value { font-size: 28px; font-weight: 700; font-family: "SF Mono", monospace; }
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-top: 2px; }

.lender-bar { display: flex; height: 32px; border-radius: 6px; overflow: hidden; margin-bottom: 12px; }
.lender-bar-segment { height: 100%; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; color: #fff; min-width: 2px; }
.lender-legend { display: flex; flex-wrap: wrap; gap: 10px 20px; font-size: 12px; color: var(--muted); }
.lender-legend-item { display: flex; align-items: center; gap: 6px; }
.lender-legend-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }

.insight-card { display: flex; gap: 14px; align-items: flex-start; }
.insight-body { flex: 1; }
.insight-label { font-weight: 600; font-size: 14px; margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.insight-explanation { font-size: 13px; color: var(--muted); line-height: 1.5; margin-bottom: 6px; }
.insight-action { font-size: 13px; color: var(--text); padding-left: 16px; position: relative; line-height: 1.5; }
.insight-action::before { content: "→"; position: absolute; left: 0; color: var(--accent); }

.insight-badge-refi { background: var(--orange-bg); color: var(--orange); }
.insight-badge-unencumbered { background: var(--green-bg); color: var(--green); }
.insight-badge-expansion { background: var(--accent-light); color: var(--accent); }
.insight-badge-distress { background: var(--red-bg); color: var(--red); }
.insight-badge-lender { background: #ede9fe; color: #5b21b6; }

.timeline { position: relative; padding-left: 24px; }
.timeline::before { content: ""; position: absolute; left: 7px; top: 0; bottom: 0; width: 2px; background: var(--border); }
.timeline-item { position: relative; padding: 10px 0; border-bottom: 1px solid var(--border); }
.timeline-item:last-child { border-bottom: none; }
.timeline-dot { position: absolute; left: -21px; top: 14px; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--surface); }
.timeline-dot-outstanding { background: var(--orange); }
.timeline-dot-satisfied { background: var(--green); }
.timeline-dot-part-satisfied { background: var(--yellow); }
.timeline-header { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; flex-wrap: wrap; }
.timeline-date { font-size: 12px; color: var(--muted); font-family: "SF Mono", monospace; }
.timeline-lender { font-weight: 600; font-size: 13px; }
.timeline-detail { font-size: 12px; color: var(--muted); line-height: 1.4; }

.charge-status { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11px; font-weight: 500; }
.charge-outstanding { background: var(--orange-bg); color: var(--orange); }
.charge-satisfied { background: var(--green-bg); color: var(--green); }
.charge-part-satisfied { background: var(--yellow-bg); color: var(--yellow); }

.lender-cat-badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 10px; font-weight: 500; color: #fff; text-transform: capitalize; }

.graph-legend-pill { width: 16px; height: 10px; border-radius: 10px; flex-shrink: 0; }
.graph-legend-line { width: 20px; height: 2px; flex-shrink: 0; border-radius: 1px; }
.graph-legend-line-dashed { background: repeating-linear-gradient(90deg, #f59e0b 0, #f59e0b 4px, transparent 4px, transparent 7px) !important; height: 2px; }
.graph-toggle { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; margin-left: auto; }
.graph-toggle input { cursor: pointer; }

/* ── CRM ───────────────────────────────────────────────────────────────── */

/* Pipeline bar chart on dashboard */
.pipeline-bar-wrap {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  overflow-x: auto;
  padding: 12px 4px;
  min-height: 180px;
}
.pipeline-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 100px;
  flex: 1;
}
.pipeline-stage-bar {
  width: 60%;
  background: var(--accent);
  border-radius: 4px 4px 0 0;
  min-height: 12px;
  transition: all 0.3s;
}
.pipeline-stage-count {
  font-weight: 700;
  font-size: 14px;
  margin-top: 6px;
}
.pipeline-stage-label {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  margin-top: 4px;
  line-height: 1.3;
}

/* Activity list */
.activity-list { list-style: none; display: flex; flex-direction: column; }
.activity-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.activity-item:last-child { border-bottom: none; }
.activity-item a { color: var(--accent); text-decoration: none; flex: 1; }
.activity-item a:hover { text-decoration: underline; }
.activity-ts { font-size: 12px; color: var(--muted); font-family: "SF Mono", monospace; }

/* Getting started */
.getting-started { display: flex; flex-direction: column; gap: 12px; }
.gs-step { display: flex; gap: 12px; align-items: flex-start; font-size: 13px; line-height: 1.5; }
.gs-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 700;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* CRM stage badges / phase colours */
.phase-origination { background: var(--accent-light); color: var(--accent); }
.phase-fulfilment { background: #ffedd5; color: #c2410c; }
.phase-servicing { background: var(--green-bg); color: var(--green); }

/* CRM tables */
.crm-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.crm-table th {
  text-align: left;
  padding: 8px 10px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.crm-table td { padding: 10px; border-bottom: 1px solid var(--border); }
.crm-table tbody tr:hover { background: var(--bg); cursor: pointer; }
.crm-table tbody tr:last-child td { border-bottom: none; }
.crm-table a { color: var(--accent); text-decoration: none; font-weight: 500; }
.crm-table a:hover { text-decoration: underline; }

/* Source badges */
.source-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
}
.source-directors_agent { background: var(--green-bg); color: var(--green); }
.source-charges_agent { background: #ffedd5; color: #c2410c; }
.source-manual { background: var(--bg); color: var(--muted); }

/* Agent snapshot cards on customer detail */
.crm-snapshot-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.crm-snapshot-card {
  flex: 1;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
}
.crm-snapshot-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 6px;
}
.crm-snapshot-value { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.crm-snapshot-meta { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.crm-snapshot-link { font-size: 12px; color: var(--accent); text-decoration: none; }
.crm-snapshot-link:hover { text-decoration: underline; }

/* Kanban pipeline */
.kanban-wrap {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 12px;
}
.kanban-col {
  background: var(--bg);
  border-radius: 8px;
  padding: 12px;
  min-width: 240px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.kanban-col-header {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}
.kanban-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  cursor: grab;
  text-decoration: none;
  color: var(--text);
  display: block;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.kanban-card:hover { border-color: var(--accent); box-shadow: 0 2px 6px rgba(26,86,219,0.08); }
.kanban-card.dragging { opacity: 0.4; }
.kanban-col.drop-target { background: var(--accent-light); outline: 2px dashed var(--accent); outline-offset: -4px; }
.kanban-card-title { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.kanban-card-meta { font-size: 11px; color: var(--muted); }
.kanban-card-amount { font-weight: 700; font-size: 13px; color: var(--accent); }

/* 17-stage tracker */
.stage-tracker {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 8px 0 20px;
}
.stage-phase-row { display: flex; align-items: center; gap: 6px; }
.stage-phase-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  min-width: 90px;
  padding: 3px 8px;
  border-radius: 4px;
}
.stage-phase-label.phase-origination { background: var(--accent-light); color: var(--accent); }
.stage-phase-label.phase-fulfilment { background: #ffedd5; color: #c2410c; }
.stage-phase-label.phase-servicing { background: var(--green-bg); color: var(--green); }
.stage-dots { display: flex; gap: 8px; align-items: center; flex: 1; flex-wrap: wrap; }
.stage-dot {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.stage-dot-complete { background: var(--green-bg); color: var(--green); border-color: var(--green); }
.stage-dot-current { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.stage-dot-current::before { content: "●"; font-size: 8px; animation: pulse 1.5s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

/* Product picker */
.product-picker-layout { display: grid; grid-template-columns: 200px 1fr; gap: 16px; }
@media (max-width: 700px) { .product-picker-layout { grid-template-columns: 1fr; } }
.product-categories { display: flex; flex-direction: column; gap: 4px; }
.product-cat-btn {
  text-align: left;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
}
.product-cat-btn:hover { background: var(--accent-light); }
.product-cat-btn.active { background: var(--accent); color: #fff; }
.product-grid { display: flex; flex-direction: column; gap: 8px; }
.product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.1s;
}
.product-card:hover { border-color: var(--accent); }
.product-card.selected { border-color: var(--accent); background: var(--accent-light); }
.product-card-name { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.product-card-desc { font-size: 12px; color: var(--muted); line-height: 1.5; }
.product-card-use { font-size: 12px; color: var(--text); margin-top: 6px; }
.product-card-use strong { color: var(--accent); }
.product-card-meta { font-size: 11px; color: var(--muted); margin-top: 6px; display: flex; gap: 12px; }
.product-cat-count { color: var(--muted); font-size: 11px; margin-left: 4px; }
.product-cat-heading { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.product-cat-intro { font-size: 13px; color: var(--muted); margin-bottom: 16px; line-height: 1.5; }

/* CRM forms */
.crm-form .form-row { display: flex; gap: 12px; }
.crm-form .form-row .field { flex: 1; }
.crm-dl { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; font-size: 13px; }
.crm-dl dt { color: var(--muted); font-weight: 500; }
.crm-dl dd { color: var(--text); }

/* Notes */
.note-list { display: flex; flex-direction: column; gap: 10px; }
.note-item {
  background: var(--bg);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
}
.note-meta { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.note-text { line-height: 1.5; }

/* ── Salesforce/nCino-style page header & chevron path ────────────────── */

.sf-page-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px 8px 0 0;
  border-bottom: none;
  padding: 16px 20px;
  margin-bottom: 0;
}
.sf-page-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}
.sf-page-header-title { flex: 1; }
.sf-page-header-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
}
.sf-page-header-icon {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  background: #f5a623;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}
.sf-page-header-icon-loan { background: #0d9b7c; }
.sf-page-header-title h1 { font-size: 20px; font-weight: 600; color: #16325c; margin: 0; }
.sf-page-header-title .sf-back { display: block; font-size: 12px; color: var(--accent); text-decoration: none; margin-bottom: 4px; }
.sf-page-header-title .sf-back:hover { text-decoration: underline; }

.sf-page-header-meta {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.sf-meta-cell {}
.sf-meta-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 2px;
}
.sf-meta-value { font-size: 13px; color: var(--text); font-weight: 500; }
.sf-meta-value a { color: var(--accent); text-decoration: none; }
.sf-meta-value a:hover { text-decoration: underline; }

/* Chevron path bar */
.sf-path-wrap {
  background: #f3f4f6;
  border: 1px solid var(--border);
  border-top: none;
  padding: 14px 16px;
  margin-bottom: 20px;
  border-radius: 0 0 8px 8px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}
.sf-path {
  display: flex;
  min-width: 0;
  gap: 2px;
  overflow-x: auto;
  padding-bottom: 2px;
}
.sf-path-step {
  flex: 1;
  min-width: 90px;
  background: #dfe3e8;
  color: #54698d;
  padding: 10px 22px 10px 24px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  position: relative;
  clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 50%, calc(100% - 10px) 100%, 0 100%, 10px 50%);
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: flex-start;
}
.sf-path-step:first-child {
  clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 50%, calc(100% - 10px) 100%, 0 100%);
  padding-left: 14px;
}
.sf-path-step:last-child {
  clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 10px 50%);
  padding-right: 14px;
}
/* Give the current stage more room */
.sf-path-step-current { flex: 2; font-weight: 600; }
.sf-path-step-complete {
  background: #4bca81;
  color: #fff;
  font-weight: 500;
}
.sf-path-step-complete::before { content: "✓"; font-weight: 700; font-size: 11px; }
.sf-path-step-current {
  background: #1589ee;
  color: #fff;
  font-weight: 600;
}
.sf-path-step-future {}

.sf-path-mark-complete {
  background: #1589ee;
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.sf-path-mark-complete:hover { background: #0070d2; }
.sf-path-mark-complete:disabled { background: #c9c9c9; cursor: not-allowed; }
.sf-path-mark-complete.success { background: #4bca81; }
.sf-path-mark-complete.success:hover { background: #04844b; }

/* Tabs */
.sf-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  gap: 0;
}
.sf-tab {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  background: none;
  border-left: none;
  border-right: none;
  border-top: none;
  transition: all 0.1s;
}
.sf-tab:hover { color: var(--text); }
.sf-tab-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.sf-tab-pane { display: none; }
.sf-tab-pane.sf-tab-pane-active { display: block; }

/* Actions button group (right of header) */
.sf-header-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.sf-btn-outline {
  background: #fff;
  border: 1px solid #dddbda;
  color: var(--accent);
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}
.sf-btn-outline:hover { background: #f4f6f9; }

/* Funded success card */
.sf-funded-card {
  background: #e9f6ed;
  border: 1px solid #4bca81;
  border-radius: 6px;
  padding: 16px 20px;
  margin-bottom: 16px;
}
.sf-funded-title { font-weight: 600; color: #04844b; font-size: 15px; margin-bottom: 4px; }
.sf-funded-account { font-family: "SF Mono", monospace; font-size: 14px; letter-spacing: 0.5px; }

/* ── Product Advisor ───────────────────────────────────────────────────── */

.advisor-subtitle {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 6px;
}

/* Macro bullets */
.macro-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.macro-bullet {
  background: var(--bg);
  border-left: 3px solid var(--accent);
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.5;
  border-radius: 0 6px 6px 0;
}

/* Recommendation cards */
.recommendation-card {
  display: flex;
  gap: 16px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 12px;
  background: var(--surface);
  border-left-width: 4px;
}
.recommendation-card.priority-high { border-left-color: var(--green); }
.recommendation-card.priority-medium { border-left-color: #f59e0b; }
.recommendation-card.priority-low { border-left-color: var(--muted); }

.rec-rank {
  font-size: 22px;
  font-weight: 700;
  color: var(--muted);
  min-width: 40px;
  font-family: "SF Mono", monospace;
}
.rec-body { flex: 1; min-width: 0; }
.rec-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.recommendation-priority {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.recommendation-priority.priority-high { background: var(--green-bg); color: var(--green); }
.recommendation-priority.priority-medium { background: #fef3c7; color: #92400e; }
.recommendation-priority.priority-low { background: var(--bg); color: var(--muted); }
.rec-category {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.rec-name { font-size: 15px; font-weight: 600; color: var(--text); }
.rec-desc { font-size: 12px; color: var(--muted); margin-bottom: 8px; line-height: 1.5; }
.rec-reasoning { font-size: 13px; color: var(--text); line-height: 1.6; margin-bottom: 8px; }
.rec-reasoning strong { color: var(--accent); }
.rec-meta {
  display: flex;
  gap: 18px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.rec-meta strong { color: var(--text); font-weight: 600; }
.rec-actions { margin-top: 4px; }
.rec-note { font-size: 12px; color: var(--muted); font-style: italic; }

/* Not recommended */
.not-recommended-item {
  font-size: 12px;
  color: var(--muted);
  padding: 6px 0;
  border-bottom: 1px dashed var(--border);
}
.not-recommended-item:last-child { border-bottom: none; }
.not-recommended-item strong { color: var(--text); font-weight: 600; }
.muted { color: var(--muted); }

/* Inline advisor cards on CRM customer page */
.advisor-inline-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
@media (max-width: 800px) { .advisor-inline-row { grid-template-columns: 1fr; } }
.advisor-inline-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  display: flex;
  flex-direction: column;
}
.advisor-inline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 6px;
}
.advisor-inline-name { font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.advisor-inline-reason { font-size: 12px; color: var(--text); line-height: 1.5; flex: 1; margin-bottom: 6px; }
.advisor-inline-meta { font-size: 11px; color: var(--muted); font-family: "SF Mono", monospace; }

/* ── Watchlist Agent ───────────────────────────────────────────────────── */

/* Hub agent card variants */
.agent-icon-watchlist { background: #fee2e2; color: #b91c1c; }
.agent-card-watchlist {
  background: linear-gradient(180deg, #fff 0%, #fff7f7 100%);
  border-color: #fecaca;
}
.agent-card-watchlist:hover { border-color: #fca5a5; }
.agent-card-body { flex: 1; }
.agent-card-actions {
  display: flex; align-items: center; gap: 12px; margin-top: 10px;
}
.agent-card-cta {
  font-size: 13px; font-weight: 600; color: var(--accent);
}
.agent-card-badge {
  display: inline-block; padding: 2px 10px; border-radius: 12px;
  background: #fee2e2; color: #b91c1c; font-size: 11px; font-weight: 600;
}

/* Source-badge additions for the watchlist source column */
.source-advisor_agent { background: #e0e7ff; color: #4338ca; }
.source-crm { background: var(--accent-light); color: var(--accent); }

/* Nav badge (Inbox count) */
.nav-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  border-radius: 10px;
  background: #b91c1c;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  vertical-align: 1px;
}

/* Watchlist index page table */
.watchlist-table { width: 100%; border-collapse: collapse; }
.watchlist-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}
.watchlist-table td {
  padding: 14px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.watchlist-row:hover td { background: var(--bg); }
.watchlist-customer-link {
  display: inline-block;
  margin-left: 8px;
  font-size: 11px;
  color: var(--accent);
  text-decoration: none;
}
.watchlist-customer-link:hover { text-decoration: underline; }

/* Inbox filters */
.inbox-filters { margin-bottom: 16px; }
.inbox-filter-form {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
}
.inbox-filter-form select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  font-size: 13px;
}

/* Inbox event list */
.inbox-list { display: flex; flex-direction: column; gap: 10px; }
.inbox-event {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  background: var(--surface);
  transition: background 0.1s;
}
.inbox-event:hover { background: #fafbfc; }
.inbox-event-undone { opacity: 0.55; background: var(--bg); }
.inbox-event-failed { border-color: #fca5a5; background: #fef2f2; }

.inbox-event-header {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; margin-bottom: 8px; flex-wrap: wrap;
}
.inbox-event-meta {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.inbox-event-company {
  font-weight: 600; color: var(--text); text-decoration: none; font-size: 13px;
}
.inbox-event-company:hover { color: var(--accent); }
.inbox-event-ts { font-size: 11px; color: var(--muted); font-family: "SF Mono", monospace; }
.inbox-event-body { font-size: 14px; line-height: 1.5; color: var(--text); }
.inbox-event-links { margin-top: 8px; display: flex; gap: 12px; flex-wrap: wrap; }
.inbox-event-link {
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
  padding: 3px 10px;
  background: var(--accent-light);
  border-radius: 12px;
}
.inbox-event-link:hover { background: #d4e3fb; }
.inbox-event-details {
  margin-top: 8px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}
.inbox-event-details summary {
  cursor: pointer;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.inbox-event-details pre {
  margin-top: 6px;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: 4px;
  font-size: 11px;
  font-family: "SF Mono", monospace;
  overflow-x: auto;
  max-height: 200px;
  color: var(--text);
}
.inbox-event-actions { margin-top: 10px; }

/* Signal pills (severity-coloured) */
.signal-pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.signal-pill-high { background: #fee2e2; color: #b91c1c; }
.signal-pill-medium { background: #fef9c3; color: #854d0e; }
.signal-pill-low { background: var(--accent-light); color: var(--accent); }

/* Action pills (status-of-event) */
.action-pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.action-pill-action { background: var(--green-bg); color: var(--green); }
.action-pill-log { background: var(--bg); color: var(--muted); }
.action-pill-undone { background: #f3e8ff; color: #6b21a8; }
.action-pill-failed { background: #fee2e2; color: #b91c1c; }

/* Extract-success status (used on inbox flash messages) */
.extract-success {
  background: var(--green-bg);
  color: var(--green);
  border: 1px solid #a7f3d0;
}

/* ── Memo history dropdown (older memos collapsed behind +N earlier) ─────── */
.memo-history { position: relative; }
.memo-history summary::-webkit-details-marker { display: none; }
.memo-history summary { user-select: none; }
.memo-history[open] summary { background: var(--border); }
.memo-history-list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 280px;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
  padding: 6px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.memo-history-item {
  display: block;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--text);
  text-decoration: none;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.memo-history-item:hover {
  background: var(--accent-light);
  color: var(--accent);
}

/* ── Advisor checklist (loading UI) ─────────────────────────────────────── */
.advisor-checklist-wrap { /* uses .card.full-width already */ }
.advisor-checklist-sub {
  color: var(--muted);
  font-size: 13px;
  margin: -4px 0 18px;
  line-height: 1.55;
  max-width: 720px;
}
.advisor-checklist {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.checklist-row {
  display: flex;
  flex-direction: column;
  padding: 10px 4px;
  font-size: 14px;
  line-height: 1.4;
  border-bottom: 1px solid var(--border);
  transition: color 0.2s ease;
}
.checklist-row:last-child { border-bottom: none; }
.checklist-row-main {
  display: flex;
  align-items: center;
  gap: 12px;
}
.checklist-icon {
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 12px;
  line-height: 1;
}
.checklist-label { flex: 1; }
.checklist-row-elapsed {
  flex: 0 0 auto;
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 12px;
  color: var(--muted);
  min-width: 36px;
  text-align: right;
}

/* Pending — empty circle, muted text */
.checklist-pending { color: var(--muted); }
.checklist-pending .checklist-icon {
  border: 1.5px solid #d1d5db;
  background: transparent;
}

/* Active — accent-blue spinner-style ring, bold text */
.checklist-active { color: var(--accent); font-weight: 600; }
.checklist-active .checklist-icon {
  border: 2px solid var(--accent-light);
  border-top-color: var(--accent);
  background: transparent;
  animation: spin 0.9s linear infinite;
}
.checklist-active .checklist-row-elapsed {
  color: var(--accent);
  font-weight: 600;
}

/* Complete — green ✓, normal-weight text */
.checklist-complete { color: var(--text); }
.checklist-complete .checklist-icon {
  background: var(--green);
  color: #fff;
  border: none;
  font-weight: 700;
}
.checklist-complete .checklist-icon::before {
  content: "✓";
  font-size: 11px;
  line-height: 1;
}

/* Error — red filled circle with "!", used when the spread or memo pipeline
   fails partway through. The row's elapsed slot holds a short error label
   so the user can see where the pipeline stopped. */
.checklist-error { color: var(--red); font-weight: 600; }
.checklist-error .checklist-icon {
  background: var(--red);
  color: #fff;
  border: none;
  font-weight: 700;
}
.checklist-error .checklist-icon::before {
  content: "!";
  font-size: 11px;
  line-height: 1;
}
.checklist-error .checklist-row-elapsed {
  color: var(--red);
  font-weight: 600;
  text-align: right;
  white-space: normal;
  min-width: 120px;
}

/* ── Advisor checklist: collapsible sub-steps ──────────────────────────── */
/* Substeps under each main checklist row. Collapsed by default; expanded
   when the parent row is .checklist-active. Cycles individual substeps
   through pending → substep-active → substep-complete states on a JS
   timer for demo flair. */
.checklist-substeps {
  list-style: none;
  margin: 0;
  padding-left: 30px; /* aligns under the icon */
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s ease, margin-top 0.25s ease;
}
.checklist-active .checklist-substeps {
  max-height: 320px;
  margin-top: 8px;
}
.checklist-substeps > li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  font-size: 12.5px;
  color: #94a3b8;
  font-weight: 400;
  line-height: 1.5;
  transition: color 0.2s ease;
}
.checklist-substeps > li::before {
  content: "○";
  font-size: 10px;
  color: #cbd5e1;
  flex: 0 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 12px;
  height: 12px;
}
.checklist-substeps > li.substep-active {
  color: var(--accent);
  font-weight: 500;
}
.checklist-substeps > li.substep-active::before {
  content: "";
  border: 1.5px solid var(--accent-light);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.checklist-substeps > li.substep-complete {
  color: var(--muted);
}
.checklist-substeps > li.substep-complete::before {
  content: "✓";
  color: var(--green);
  font-weight: 700;
}
.checklist-substeps em {
  font-style: normal;
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 11.5px;
  color: var(--accent);
  background: var(--accent-light);
  padding: 1px 6px;
  border-radius: 3px;
}
.checklist-substeps > li.substep-complete em {
  color: var(--muted);
  background: var(--bg);
}

/* ── Advisor: Recent Public News cards ─────────────────────────────────── */
.advisor-section-sub {
  color: var(--muted);
  font-size: 13px;
  margin-top: -8px;
  margin-bottom: 14px;
  line-height: 1.5;
}
.news-card {
  border: 1px solid var(--border);
  border-left: 3px solid var(--muted);
  border-radius: 6px;
  padding: 14px 16px;
  margin-bottom: 10px;
  background: var(--surface);
  transition: box-shadow 0.15s ease;
}
.news-card:hover { box-shadow: 0 2px 6px rgba(0,0,0,0.04); }
.news-card:last-child { margin-bottom: 0; }
.news-card-positive { border-left-color: var(--green); }
.news-card-negative { border-left-color: var(--red); }
.news-card-neutral  { border-left-color: var(--accent); }
.news-card-mixed    { border-left-color: var(--orange); }

.news-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 11px;
}
.news-sentiment {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.news-sentiment-positive { background: var(--green-bg); color: var(--green); }
.news-sentiment-negative { background: var(--red-bg);   color: var(--red); }
.news-sentiment-neutral  { background: var(--accent-light); color: var(--accent); }
.news-sentiment-mixed    { background: var(--orange-bg); color: var(--orange); }

.news-source {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 11px;
  color: var(--muted);
}
.news-date {
  margin-left: auto;
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 11px;
  color: var(--muted);
}
.news-title {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  margin-bottom: 6px;
  line-height: 1.4;
}
.news-title:hover { text-decoration: underline; }
.news-summary {
  font-size: 13px;
  color: var(--text);
  line-height: 1.55;
  margin-bottom: 8px;
}
.news-relevance {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.55;
  padding: 6px 10px;
  background: var(--bg);
  border-radius: 4px;
}
.news-relevance strong { color: var(--text); }

/* ── Chat drawer: floating tab + slide-out side panel ──────────────────── */

/* Floating tab on the right edge — always visible while on the advisor page.
   Vertical text reads bottom-to-top so the panel slides cleanly. */
.chat-tab {
  position: fixed;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: 90;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 18px 12px;
  cursor: pointer;
  border-radius: 8px 0 0 8px;
  box-shadow: -2px 2px 12px rgba(0,0,0,0.15);
  font-size: 13px;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.chat-tab:hover {
  transform: translateY(-50%) translateX(-3px);
  box-shadow: -3px 3px 14px rgba(26, 86, 219, 0.35);
}
.chat-tab-icon { font-size: 20px; line-height: 1; }
.chat-tab-text {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  letter-spacing: 0.02em;
}
/* Subtle pulsing ring to draw attention on first page load */
.chat-tab::before {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 8px 0 0 8px;
  border: 2px solid var(--accent);
  opacity: 0;
  animation: chat-tab-pulse 2.6s ease-out infinite;
  pointer-events: none;
}
@keyframes chat-tab-pulse {
  0%   { opacity: 0.55; transform: scale(1); }
  60%  { opacity: 0;    transform: scale(1.04, 1.03); }
  100% { opacity: 0; }
}

/* Backdrop — semi-transparent, click closes drawer. Doesn't block the page
   underneath (we want the RM to keep seeing the analysis). Pointer events
   off when closed so it doesn't catch stray clicks. */
.chat-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.12);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 95;
}
.chat-backdrop-open {
  opacity: 1;
  pointer-events: auto;
}

/* The drawer panel itself — anchored to the bottom-right corner so the
   page underneath stays mostly visible. Default height is 1/3 of the
   viewport; the user can drag the top edge handle to resize between
   min and max bounds. Slides in from the right with the existing
   translate animation. */
.chat-drawer {
  position: fixed;
  right: 0;
  bottom: 0;
  width: 440px;
  max-width: 95vw;
  /* Default to ~1/3 of viewport height. Once the user drags the
     resize handle, the JS writes the new size to element style.height
     which takes precedence. */
  height: 33vh;
  min-height: 240px;
  max-height: 92vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  border-top: 1px solid var(--border);
  border-radius: 10px 0 0 0;
  box-shadow: -6px -6px 24px rgba(0,0,0,0.10);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
.chat-drawer-open { transform: translateX(0); }

/* Top-edge drag handle for vertical resize. Visible thin grab indicator;
   cursor changes to row-resize. JS handlers in the template translate
   drag delta into element height. */
.chat-drawer-resize-handle {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 10px;
  cursor: row-resize;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}
.chat-drawer-resize-handle::before {
  content: "";
  width: 44px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  transition: background 0.12s ease, width 0.12s ease;
}
.chat-drawer-resize-handle:hover::before,
.chat-drawer-resize-handle:active::before {
  background: var(--accent);
  width: 60px;
}
/* While dragging, disable the slide-in transition so resize feels
   instant. JS toggles .chat-drawer-resizing on <body>. */
body.chat-drawer-resizing .chat-drawer {
  transition: none;
  user-select: none;
}
body.chat-drawer-resizing,
body.chat-drawer-resizing * {
  cursor: row-resize !important;
}

.chat-drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.chat-drawer-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}
.chat-drawer-subtitle {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.45;
}
.chat-drawer-close {
  background: none;
  border: none;
  font-size: 26px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 0 4px;
  flex-shrink: 0;
}
.chat-drawer-close:hover { color: var(--text); }

/* Empty state: example prompts. Takes the available space; chips stick to
   the top, with a small helper hint at the bottom to indicate where the
   conversation will appear. Hidden once the user sends the first message. */
.chat-empty-state {
  padding: 10px 16px 4px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.chat-empty-state p {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
  flex-shrink: 0;
}
.chat-prompts {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
  flex-shrink: 0;
}
/* Helper hint pushed to the bottom of the empty area so the panel doesn't
   show a featureless gap between the chips and the input field. */
.chat-empty-state-hint {
  margin-top: auto;
  padding: 14px 8px 6px;
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  font-style: italic;
  opacity: 0.7;
}
/* Hide the messages container entirely when there are no messages yet —
   prevents an empty <div class="chat-messages"> from claiming flex space
   above the input row. */
.chat-messages:empty { display: none; }
.chat-prompt-chip {
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 11px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  line-height: 1.35;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.06s ease;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.chat-prompt-chip:hover {
  background: var(--accent-light);
  border-color: var(--accent);
  transform: translateX(2px);
}
.chat-prompt-sub {
  font-size: 11px;
  color: var(--muted);
  font-weight: 400;
}
.chat-prompt-chip-highlight {
  border-color: var(--accent);
  background: linear-gradient(180deg, var(--accent-light), var(--surface) 60%);
}
.chat-prompt-chip-highlight .chat-prompt-sub {
  color: var(--accent);
  font-weight: 500;
}

/* Messages list */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-message {
  font-size: 13.5px;
  line-height: 1.55;
  padding: 10px 14px;
  border-radius: 12px;
  max-width: 86%;
  word-wrap: break-word;
}
.chat-message-user {
  background: var(--accent);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.chat-message-assistant {
  background: var(--bg);
  color: var(--text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.chat-message-assistant p { margin: 0 0 6px 0; }
.chat-message-assistant p:last-child { margin-bottom: 0; }
.chat-message-assistant ul {
  margin: 6px 0;
  padding-left: 20px;
}
.chat-message-assistant li { margin-bottom: 3px; }
.chat-message-assistant code {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.88em;
  background: rgba(0,0,0,0.06);
  padding: 1px 5px;
  border-radius: 3px;
}
.chat-message-error {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid #fca5a5;
}

.chat-thinking {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-style: italic;
  font-size: 13px;
}

/* Input row at the bottom */
.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 12px 16px 4px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.chat-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13.5px;
  font-family: inherit;
  resize: vertical;
  min-height: 44px;
  max-height: 140px;
  background: var(--bg);
}
.chat-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
}
.chat-send-btn {
  flex-shrink: 0;
  align-self: flex-end;
  padding: 9px 16px;
}
.chat-input-hint {
  text-align: center;
  font-size: 10.5px;
  color: var(--muted);
  padding: 4px 0 10px;
  letter-spacing: 0.02em;
}

/* ── Internal Data Insights (mock transactional banking data) ──────────── */
/* Yellow banner at the top of the section makes the synthetic nature
   of the data unmistakable to any reviewer. */
.internal-data-banner {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-left: 3px solid var(--yellow);
  border-radius: 4px;
  padding: 10px 14px;
  font-size: 12.5px;
  line-height: 1.5;
  color: #713f12;
  margin-bottom: 14px;
}
.internal-data-banner strong {
  color: var(--yellow);
}

/* Insight card — mirrors news-card layout with sentiment-coloured rail
   but uses opportunity/risk/neutral classifications.
   All rules scoped to #internal-data-list because .insight-card is also
   used by the Charges Analysis page (with a flex/sidebar layout); without
   scoping our advisor cards inherit that flex layout, which collapses the
   intended vertical stack into a horizontal-columns mess. */
#internal-data-list .insight-card {
  display: block;
  border: 1px solid var(--border);
  border-left: 3px solid var(--muted);
  border-radius: 6px;
  padding: 14px 16px;
  margin-bottom: 10px;
  background: var(--surface);
  transition: box-shadow 0.15s ease;
}
#internal-data-list .insight-card:hover { box-shadow: 0 2px 6px rgba(0,0,0,0.04); }
#internal-data-list .insight-card:last-child { margin-bottom: 0; }
#internal-data-list .insight-card-opportunity { border-left-color: var(--green); }
#internal-data-list .insight-card-risk        { border-left-color: var(--red); }
#internal-data-list .insight-card-neutral     { border-left-color: var(--accent); }

#internal-data-list .insight-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 11px;
}
#internal-data-list .insight-sentiment {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
#internal-data-list .insight-sentiment-opportunity { background: var(--green-bg); color: var(--green); }
#internal-data-list .insight-sentiment-risk        { background: var(--red-bg);   color: var(--red); }
#internal-data-list .insight-sentiment-neutral     { background: var(--accent-light); color: var(--accent); }

#internal-data-list .insight-category {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}
#internal-data-list .insight-title {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
  line-height: 1.35;
}
#internal-data-list .insight-data-point {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 12px;
  color: var(--accent);
  background: var(--accent-light);
  padding: 6px 10px;
  border-radius: 4px;
  margin-bottom: 8px;
  display: inline-block;
  line-height: 1.4;
  max-width: 100%;
  white-space: normal;
  word-break: break-word;
}
#internal-data-list .insight-summary {
  font-size: 13px;
  color: var(--text);
  line-height: 1.55;
  margin-bottom: 8px;
}
#internal-data-list .insight-relevance {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.55;
  padding: 6px 10px;
  background: var(--bg);
  border-radius: 4px;
}
#internal-data-list .insight-relevance strong { color: var(--text); }

/* ── Full Credit Assessment — swarm UI + result sections ─────────────────── */

/* Model-tier badge on each specialist swarm row */
.specialist-model-badge {
  font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 10px;
  background: var(--accent-light); color: var(--accent);
  margin-left: 8px; white-space: nowrap;
}

/* Hub card + nav icon for the assessment front door */
.agent-icon-assessment { background: linear-gradient(135deg, #4f46e5, #7c3aed); color: #fff; }
.agent-card-assessment { border-left: 3px solid #4f46e5; }

/* Overall credit view — risk flags */
.risk-flags { margin-top: 12px; }
.risk-flags ul { margin: 6px 0 0 18px; }

/* Company snapshot grid */
.snapshot-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.snapshot-cell { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.snapshot-label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 3px; }

/* Ratio pills */
.ratio-pills { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.ratio-pill { font-size: 12px; font-family: ui-monospace, "SF Mono", monospace; background: var(--bg); border: 1px solid var(--border); border-radius: 12px; padding: 3px 10px; text-transform: capitalize; }

/* Recommendation cards (assessment markup) */
.recommendation-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.recommendation-name { font-weight: 600; font-size: 15px; }
.recommendation-reasoning { margin: 6px 0; }
.recommendation-meta { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.recommendation-priority { font-size: 11px; font-weight: 700; padding: 2px 10px; border-radius: 12px; text-transform: uppercase; flex-shrink: 0; }
.recommendation-priority-high { background: var(--green-bg); color: var(--green); }
.recommendation-priority-medium { background: var(--accent-light); color: var(--accent); }
.recommendation-priority-low { background: var(--bg); color: var(--muted); }

/* News + insight heads (assessment markup) */
.news-head, .insight-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.news-source-pill { font-size: 11px; color: var(--muted); white-space: nowrap; }
.macro-list { margin: 0 0 0 18px; }

/* ── Semantic memory: precedent cards ─────────────────────────────────────── */
.precedent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.precedent-card {
  display: block; text-decoration: none; color: inherit;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 14px; transition: border-color .15s, box-shadow .15s;
}
.precedent-card:hover { border-color: var(--accent); box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.precedent-name { font-weight: 600; font-size: 14px; }
.precedent-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.precedent-score { font-size: 11px; color: var(--accent); font-weight: 600; margin-top: 6px; }

/* ── Voice: briefing button + ask box ─────────────────────────────────────── */
.section-head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.btn-voice { white-space: nowrap; }

.ask-messages { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; max-height: 320px; overflow-y: auto; }
.ask-bubble { max-width: 80%; padding: 8px 12px; border-radius: 12px; font-size: 14px; line-height: 1.45; white-space: pre-wrap; }
.ask-bubble-user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 3px; }
.ask-bubble-assistant { align-self: flex-start; background: var(--bg); border: 1px solid var(--border); border-bottom-left-radius: 3px; }

.ask-input-row { display: flex; align-items: center; gap: 8px; }
.ask-input-row .field-input { flex: 1; }
.ask-mic {
  flex-shrink: 0; width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--bg); cursor: pointer;
  font-size: 18px; line-height: 1; transition: all .15s;
}
.ask-mic:hover { border-color: var(--accent); }
.ask-mic-recording {
  background: var(--red, #c00); border-color: var(--red, #c00); color: #fff;
  animation: ask-mic-pulse 1.2s ease-in-out infinite;
}
@keyframes ask-mic-pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(200,0,0,.5); } 50% { box-shadow: 0 0 0 6px rgba(200,0,0,0); } }
.ask-speak { font-size: 12px; color: var(--muted); white-space: nowrap; display: flex; align-items: center; gap: 4px; cursor: pointer; }

/* "Semantically matched" note on the recommendations (vector RAG) */
.semantic-note {
  font-size: 12px; color: var(--accent);
  background: var(--accent-light); border-radius: 6px;
  padding: 6px 10px; margin: 0 0 12px; display: inline-block;
}
.semantic-note strong { color: var(--accent); }

/* Briefing audio player (play/pause + scrubber) */
.voice-player { display: inline-flex; align-items: center; gap: 10px; }
.voice-play-btn {
  width: 34px; height: 34px; border-radius: 50%; border: none;
  background: var(--accent); color: #fff; font-size: 13px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: filter 0.15s;
}
.voice-play-btn:hover { filter: brightness(1.1); }
.voice-play-btn.is-loading { opacity: 0.6; cursor: wait; }
.voice-scrubber { width: 130px; accent-color: var(--accent); cursor: pointer; vertical-align: middle; }
.voice-scrubber:disabled { opacity: 0.4; cursor: default; }
.voice-time { font-size: 12px; color: var(--muted); min-width: 96px; font-variant-numeric: tabular-nums; }

/* Key credit ratios + peer benchmarking tables */
.sub-h { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 16px 0 8px; }
.ratio-table, .peer-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ratio-table th, .peer-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); padding: 6px 10px; border-bottom: 1px solid var(--border); }
.ratio-table td, .peer-table td { padding: 7px 10px; border-bottom: 1px solid var(--border); }
.ratio-table tr:last-child td, .peer-table tr:last-child td { border-bottom: none; }
.ratio-table .rt-val, .peer-table td:not(:first-child) { font-variant-numeric: tabular-nums; }
.ratio-table { max-width: 460px; }
.rt-badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; text-transform: capitalize; }
.rt-strong { background: var(--green-bg); color: var(--green); }
.rt-acceptable { background: var(--accent-light); color: var(--accent); }
.rt-watch { background: #fef3c7; color: #92400e; }
.rt-concern { background: var(--red-bg); color: var(--red); }
.rt-unrated, .rt-N\/A { background: var(--bg); color: var(--muted); }

.table-scroll { overflow-x: auto; }
.peer-subject td { background: var(--accent-light); font-weight: 600; }
.peer-tag { font-size: 10px; font-weight: 600; color: var(--accent); text-transform: uppercase; }
.peer-est { font-size: 10px; color: var(--muted); }
.peer-summary { margin: 6px 0 0; padding-left: 18px; font-size: 13px; }
.peer-summary li { margin-bottom: 4px; }

/* Drill-down links rendered as buttons (clearly new functionality) */
.drill-links { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.drill-btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 500; text-decoration: none;
  color: var(--accent); background: var(--accent-light);
  border: 1px solid var(--accent); border-radius: 6px; padding: 6px 12px;
  transition: all 0.15s;
}
.drill-btn:hover { background: var(--accent); color: #fff; }
