:root {
  --bg: #f6f7f9;
  --panel-bg: #ffffff;
  --border: #dde1e6;
  --text: #1f2430;
  --text-muted: #6b7280;
  --funnel-1: #16324f;
  --funnel-2: #1f4e79;
  --funnel-3: #2e6da4;
  --funnel-4: #4f94c4;
  --funnel-5: #7fb3d9;
  --funnel-6: #aed0e8;
  --warm-1: #c9822a;
  --warm-2: #e8a94d;
  --neutral-card: #eef0f3;
  --neutral-card-border: #d7dbe1;
}

* { box-sizing: border-box; }

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

h1, h2 { margin: 0 0 12px 0; }
h1 { font-size: 20px; }
h2 { font-size: 15px; color: var(--text); }

main { max-width: 1200px; margin: 0 auto; padding: 20px; }

/* Tabs */
.tab-nav { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.tab-btn {
  border: none;
  background: none;
  padding: 8px 16px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--funnel-3); border-bottom-color: var(--funnel-3); }

/* Filter bar */
.filter-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
}
.filter-bar-row {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 20px;
  max-width: 1200px;
  margin: 0 auto;
}
.filter-field { display: flex; flex-direction: column; gap: 4px; }
.filter-field label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.filter-field select { padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: white; font-size: 13px; min-width: 180px; }
.filter-field-range .range-inputs { display: flex; align-items: center; gap: 6px; }
.filter-field-range input[type="date"] { padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; background: white; font-size: 13px; }
.filter-field-range span { color: var(--text-muted); font-size: 12px; }
.filter-field-range #applyRangeBtn {
  padding: 5px 12px;
  border: 1px solid var(--funnel-3);
  border-radius: 6px;
  background: var(--funnel-3);
  color: white;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.filter-field-range #applyRangeBtn:disabled {
  border-color: var(--border);
  background: var(--neutral-card);
  color: var(--text-muted);
  cursor: not-allowed;
}
.filter-field-range .clear-link {
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 12px;
  text-decoration: underline;
  cursor: pointer;
  padding: 4px 2px;
}
.filter-field-range .clear-link:hover { color: var(--text); }
.filter-field-range.range-active #applyRangeBtn:not(:disabled) {
  border-color: #2f6b47;
  background: #2f6b47;
}
.range-error { color: #a34a43; font-size: 11.5px; margin-top: 4px; }
.filter-status { color: var(--text-muted); font-size: 12px; margin-left: auto; align-self: center; }

.refresh-group { display: flex; align-items: center; gap: 10px; }
.update-btn {
  border: 1px solid var(--funnel-3);
  background: var(--funnel-3);
  color: white;
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.update-btn:hover:not(:disabled) { filter: brightness(1.08); }
.update-btn:disabled { background: var(--neutral-card); border-color: var(--border); color: var(--text-muted); cursor: not-allowed; }
.last-updated { color: var(--text-muted); font-size: 11.5px; white-space: nowrap; }
.refresh-error { color: #a34a43; font-size: 11.5px; }
.filter-note {
  max-width: 1200px;
  margin: 10px auto 0;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
}
.filter-note code { background: var(--neutral-card); padding: 1px 4px; border-radius: 3px; }

/* Funnel + source row */
.funnel-row { display: flex; gap: 24px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 28px; }
.funnel-col { flex: 1 1 620px; min-width: 320px; }
.source-col { flex: 0 1 320px; min-width: 260px; background: var(--panel-bg); border: 1px solid var(--border); border-radius: 10px; padding: 16px; }

.flow-note { margin: 4px 0 20px; font-size: 12px; color: var(--text-muted); line-height: 1.6; max-width: 700px; }
.flow-note code { background: var(--neutral-card); padding: 1px 4px; border-radius: 3px; }

.funnel { display: flex; flex-direction: column; }

/* Bands */
.band-wrap { margin-bottom: 2px; }
.funnel-band {
  cursor: pointer;
  border: none;
  border-radius: 6px;
  color: white;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  min-width: 240px;
  width: 100%;
  transition: filter 0.1s ease;
}
.funnel-band:hover { filter: brightness(1.08); }
.funnel-band .band-name { font-weight: 600; font-size: 13.5px; }
.funnel-band .band-count { font-size: 17px; font-weight: 700; }
.funnel-band .band-pcts { font-size: 11px; opacity: 0.9; text-align: right; }
.band-1 { background: var(--funnel-1); }
.band-2 { background: var(--funnel-2); }
.band-3 { background: var(--funnel-3); }
.band-4 { background: var(--funnel-4); }
.band-5 { background: var(--funnel-5); color: #0e1a26; }
.band-6 { background: var(--funnel-6); color: #0e1a26; }
.band-7 { background: #2f6b47; }

/* Gaps */
.gap-wrap { padding: 6px 6px 6px 14px; }
.gap-row { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--text-muted); }
.gap-arrow { opacity: 0.6; }
.gap-badge {
  cursor: pointer;
  border: 1px solid var(--neutral-card-border);
  border-radius: 20px;
  padding: 3px 11px;
  font: inherit;
  font-size: 11.5px;
  background: var(--neutral-card);
  color: var(--text);
}
.gap-badge:hover { border-color: var(--funnel-3); }
.gap-badge.lost { color: var(--text-muted); }
.gap-badge.stalled { background: #fbf1e3; border-color: #ecd4a8; color: var(--warm-1); font-weight: 600; }
.gap-badge.expanded { box-shadow: 0 0 0 1px currentColor inset; }

.gap-wrap.highlight {
  background: #fbf1e3;
  border: 1px solid #ecd4a8;
  border-radius: 10px;
  padding: 14px 16px;
  margin: 10px 0;
}
.gap-wrap.highlight .gap-row { font-size: 13.5px; }
.gap-wrap.highlight .headline-tag {
  display: block;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--warm-1);
  font-weight: 700;
  margin-bottom: 6px;
}
.gap-wrap.highlight .gap-badge.stalled { font-size: 14px; padding: 6px 16px; }

/* Expansion panels (band or gap) */
.expansion-panel {
  background: var(--panel-bg);
  border: 1px solid var(--neutral-card-border);
  border-radius: 8px;
  padding: 14px 16px;
  margin: 6px 0 10px;
}
.expansion-title { font-size: 12.5px; color: var(--text); margin-bottom: 12px; line-height: 1.5; }
.expansion-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.breakdown-block h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); margin: 0 0 6px; }
.breakdown-row {
  display: flex;
  justify-content: space-between;
  width: 100%;
  border: none;
  background: none;
  font: inherit;
  padding: 4px 6px;
  cursor: pointer;
  font-size: 12px;
  border-radius: 4px;
}
.breakdown-row:hover { background: var(--neutral-card); }
.breakdown-row .bd-value { color: var(--text-muted); }
.expansion-actions { margin-top: 12px; }

/* Stalled-lead aging breakdown */
.aging-block { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--neutral-card-border); }
.aging-block h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-muted); margin: 0 0 8px; }
.aging-bars { display: flex; flex-direction: column; gap: 5px; }
.aging-row {
  display: grid;
  grid-template-columns: 90px 1fr 40px;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: none;
  background: none;
  font: inherit;
  padding: 3px 4px;
  cursor: pointer;
  border-radius: 4px;
  text-align: left;
}
.aging-row:hover { background: var(--neutral-card); }
.aging-label { font-size: 11.5px; color: var(--text-muted); }
.aging-track { height: 8px; background: var(--neutral-card); border-radius: 4px; overflow: hidden; }
.aging-fill { display: block; height: 100%; background: var(--warm-1); }
.aging-count { text-align: right; font-size: 12px; font-weight: 600; }

/* Qualifying-value tiers (band/gap expansions) */
.tier-heading {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 14px 0 4px;
}
.tier-heading:first-of-type { margin-top: 0; }
.qualifying-rows { display: flex; flex-direction: column; }
.qualifying-row {
  display: grid;
  grid-template-columns: 130px 1fr 70px 56px;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: none;
  background: none;
  font: inherit;
  padding: 5px 6px;
  cursor: pointer;
  font-size: 12.5px;
  border-radius: 4px;
  text-align: left;
}
.qualifying-row:hover { background: var(--neutral-card); }
.qualifying-row .qr-field { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; color: var(--text-muted); }
.qualifying-row .qr-value { font-weight: 600; }
.qualifying-row .qr-count { text-align: right; }
.qualifying-row .qr-pct { text-align: right; color: var(--text-muted); font-size: 11.5px; }

/* Collapsed "Who these leads are" */
.who-details { margin-top: 16px; border-top: 1px solid var(--neutral-card-border); padding-top: 10px; }
.who-details summary {
  cursor: pointer;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  font-weight: 700;
}
.who-details summary:hover { color: var(--text); }
.who-details .who-grid { margin-top: 10px; }
.view-list-btn {
  border: 1px solid var(--border);
  background: white;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12.5px;
  cursor: pointer;
}
.view-list-btn:hover { background: var(--neutral-card); }

/* Source breakdown */
.source-bars { display: flex; flex-direction: column; gap: 8px; }
.source-bar-row { display: flex; flex-direction: column; gap: 3px; }
.source-bar-label { display: flex; justify-content: space-between; font-size: 12px; }
.source-bar-label .src-name { color: var(--text); }
.source-bar-label .src-count { color: var(--text-muted); }
.source-bar-track { background: var(--neutral-card); border-radius: 4px; height: 8px; overflow: hidden; }
.source-bar-fill { background: var(--funnel-3); height: 100%; }
.source-bar-fill.no-source { background: var(--text-muted); }

/* Detail panel */
.detail-panel { background: var(--panel-bg); border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin-top: 8px; }
.detail-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.detail-actions { display: flex; gap: 8px; }
.detail-actions button {
  border: 1px solid var(--border);
  background: white;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12.5px;
  cursor: pointer;
}
.detail-actions button:hover { background: var(--neutral-card); }
.detail-table-wrap { overflow-x: auto; max-height: 520px; overflow-y: auto; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
th { position: sticky; top: 0; background: var(--panel-bg); cursor: pointer; user-select: none; color: var(--text-muted); font-weight: 600; }
th:hover { color: var(--text); }
th .sort-arrow { font-size: 10px; margin-left: 3px; }
td.null-cell { color: var(--text-muted); }
td.truncatable-cell { white-space: normal; max-width: 320px; }
td.truncatable-cell.expandable { cursor: pointer; }
td.truncatable-cell.expandable:hover { background: var(--neutral-card); }

/* Follow-up date rule violations */
tr.row-violation td { background: #fbe9e9; }
tr.row-violation td.null-cell { color: #8a5a52; }
.violation-legend {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0 0 10px;
}
.legend-swatch {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: #fbe9e9;
  border: 1px solid #ecd0ce;
}
td.truncatable-cell.is-expanded { max-width: 480px; background: var(--neutral-card); }

/* Source x Stage cross-tab */
.crosstab-wrap { overflow-x: auto; background: var(--panel-bg); border: 1px solid var(--border); border-radius: 10px; padding: 16px; }
#sourceStageTable { border-collapse: collapse; width: 100%; font-size: 12.5px; }
#sourceStageTable th, #sourceStageTable td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
#sourceStageTable thead th { color: var(--text-muted); font-weight: 600; text-align: right; }
#sourceStageTable thead th:first-child, #sourceStageTable td.crosstab-source-name { text-align: left; }
.crosstab-source-name { font-weight: 600; }
.crosstab-total-cell { font-weight: 700; }
.crosstab-cell {
  border: none;
  background: none;
  font: inherit;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  display: inline-flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.3;
}
.crosstab-cell:hover { background: var(--neutral-card); }
.crosstab-cell-pct { font-size: 10.5px; color: var(--text-muted); }

/* Graphs tab */
.graph-mode-toggle { display: flex; gap: 6px; margin-bottom: 14px; }
.mode-btn {
  border: 1px solid var(--border);
  background: var(--panel-bg);
  border-radius: 20px;
  padding: 5px 14px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}
.mode-btn:hover { color: var(--text); }
.mode-btn.active { background: var(--funnel-3); border-color: var(--funnel-3); color: white; }

.graph-hint { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--text-muted); font-size: 10.5px; }

.graph-exclude-partial {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 4px 0 14px;
  cursor: pointer;
}

.graph-footnote { margin-top: 10px; font-size: 11.5px; color: var(--text-muted); }

.graph-controls {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  margin-bottom: 20px;
}
.graph-control-block { flex: 1 1 260px; min-width: 220px; }
.graph-control-block h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin: 0 0 8px;
}
.graph-control-block h3:not(:first-child) { margin-top: 16px; }

.graph-metric-list { display: flex; flex-direction: column; gap: 6px; }
.graph-metric-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.graph-metric-row input[type="color"] {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: none;
  cursor: pointer;
}
.graph-metric-row input[type="color"]:disabled { opacity: 0.35; cursor: not-allowed; }
.graph-metric-row label { display: flex; align-items: center; gap: 6px; cursor: pointer; flex: 1; }
.graph-metric-row select.axis-select {
  font-size: 11px;
  padding: 2px 4px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: white;
  color: var(--text-muted);
}
.graph-metric-row select.axis-select:disabled { opacity: 0.35; }

.graph-granularity { display: flex; gap: 16px; font-size: 13px; margin-bottom: 4px; }
.graph-granularity label { display: flex; align-items: center; gap: 5px; cursor: pointer; }

.graph-period-actions { display: flex; gap: 10px; margin-bottom: 6px; }
.graph-period-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--neutral-card-border);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fafbfc;
}
.graph-period-row { display: flex; align-items: center; gap: 7px; font-size: 12.5px; cursor: pointer; }

.graph-chart {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  min-height: 380px;
}
.graph-empty { color: var(--text-muted); font-size: 13px; padding: 40px 0; text-align: center; }
/* SVGs clip to their viewBox by default -- a full-length rotated week
   label ("Aug 30 – Sep 5, 2026") on the leftmost/rightmost bar extends
   past that box and would otherwise get cut off mid-text. */
.graph-svg { overflow: visible; }
.graph-svg text { font-size: 10.5px; fill: var(--text-muted); font-family: -apple-system, BlinkMacSystemFont, sans-serif; }
.graph-svg .grid-line { stroke: var(--neutral-card-border); stroke-width: 1; }
.graph-svg .series-line { fill: none; stroke-width: 2; }
.graph-svg .series-line.partial-segment { stroke-dasharray: 5 4; }
.graph-svg .series-point { cursor: pointer; }
.graph-svg .series-point:hover { r: 5; }
.graph-svg .series-point.partial-point { stroke: white; stroke-width: 1.5; }
.graph-svg .data-label { font-size: 10px; font-weight: 700; text-anchor: middle; }
.graph-svg .partial-band { fill: var(--neutral-card); opacity: 0.6; }
.graph-svg .right-axis-tick { fill: var(--text-muted); }
.graph-legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 12px; font-size: 12px; }
.graph-legend-item { display: flex; align-items: center; gap: 6px; }
.graph-legend-swatch { width: 12px; height: 12px; border-radius: 3px; flex: 0 0 auto; }

/* Follow-up tab */
.followup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.followup-chart-block { background: var(--panel-bg); border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px; }
.followup-chart-block h2 { font-size: 14px; margin-bottom: 10px; }
.followup-chart { min-height: 280px; padding: 0; border: none; }
.graph-svg .followup-bar { cursor: pointer; }
.graph-svg .followup-bar:hover { filter: brightness(1.1); }

@media (max-width: 900px) {
  .funnel-row { flex-direction: column; }
  .source-col { width: 100%; }
  .followup-grid { grid-template-columns: 1fr; }
}
