/* ============================================================
   funnel.css - Funnel / pipeline page (funnel-*, fcd-*)
                and Financial Breakdown modal
   ============================================================ */

/* ── Page shell ── */
.funnel-section {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px 20px 24px;
}

/* ── Page header ── */
.funnel-page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 28px;
}

.funnel-title-block { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.funnel-subtitle    { font-size: 13px; color: var(--text-2); font-family: var(--font-mono); }

/* ── Toolbar ── */
.funnel-toolbar       { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
.funnel-toolbar-group { display: flex; align-items: center; gap: 6px; }
.funnel-toolbar-label { font-size: 11px; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.07em; font-family: var(--font-mono); white-space: nowrap; }

.funnel-period-btns,
.funnel-sort-btns {
  display: flex;
  gap: 2px;
  background: var(--bg-3);
  border-radius: 8px;
  padding: 3px;
}

.funnel-period-btn,
.funnel-sort-btn {
  background: transparent;
  border: none;
  color: var(--text-2);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.funnel-period-btn:hover,
.funnel-sort-btn:hover { color: var(--text); background: var(--bg-4); }
.funnel-period-btn.active { background: var(--accent-dim); color: var(--accent); }
.funnel-sort-btn.active   { background: var(--bg-4); color: var(--text); }

.funnel-search-group  { flex: 1; min-width: 180px; }
.funnel-search-input  {
  width: 100%;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  padding: 6px 12px;
  outline: none;
  transition: border-color 0.15s;
}
.funnel-search-input:focus { border-color: var(--border-light); }
.funnel-action-group  { gap: 8px; }
.funnel-email-btn     { display: flex; align-items: center; gap: 6px; white-space: nowrap; }

/* ── Body ── */
.funnel-body { display: flex; flex-direction: column; gap: 16px; }

/* ── Section blocks ── */
.funnel-section-block {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: box-shadow 0.2s;
}
.funnel-section-block:hover { box-shadow: var(--shadow-sm); }

.funnel-block-high    { border-left: 3px solid var(--red); }
.funnel-block-med     { border-left: 3px solid var(--amber); }
.funnel-block-stable  { border-left: 3px solid var(--accent); }
.funnel-block-leads   { border-left: 3px solid var(--accent-2); }
.funnel-block-unfunded{ border-left: 3px solid var(--red); }

/* ── Section header ── */
.funnel-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
  gap: 12px;
}
.funnel-section-header:hover { background: var(--bg-3); }

.funnel-section-title-group { display: flex; align-items: center; gap: 10px; }
.funnel-section-meta        { display: flex; align-items: center; gap: 12px; }
.funnel-section-hint        { font-size: 11px; color: var(--text-2); font-family: var(--font-mono); }

.funnel-section-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.dot-high    { background: var(--red);    box-shadow: 0 0 6px var(--red); }
.dot-med     { background: var(--amber);  box-shadow: 0 0 6px var(--amber); }
.dot-stable  { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.dot-lead    { background: var(--accent-2); box-shadow: 0 0 6px var(--accent-2); }
.dot-unfunded{ background: var(--red);    box-shadow: 0 0 6px var(--red); }

.funnel-section-title { font-family: var(--font-display); font-size: 15px; font-weight: 700; color: var(--text); }

.funnel-section-badge { font-family: var(--font-mono); font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: 20px; }
.funnel-badge-high    { background: var(--red-dim);        color: var(--red); }
.funnel-badge-med     { background: var(--amber-dim);      color: var(--amber); }
.funnel-badge-stable  { background: var(--accent-dim);     color: var(--accent); }
.funnel-badge-lead    { background: var(--accent-2-dim);   color: var(--accent-2); }
.funnel-badge-unfunded{ background: var(--red-dim);        color: var(--red); }

.funnel-chevron { color: var(--text-2); transition: transform 0.2s; flex-shrink: 0; }
.funnel-collapsed { display: none !important; }

/* ── Table head ── */
.funnel-table-head {
  display: grid;
  grid-template-columns: 150px 100px 1fr 120px 185px;
  padding: 6px 20px;
  background: var(--bg-3);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.funnel-th { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-2); font-family: var(--font-mono); }

/* ── Rows ── */
.funnel-row { border-bottom: 1px solid var(--border); transition: background 0.12s; }
.funnel-row:last-child   { border-bottom: none; }
.funnel-row:hover        { background: rgba(255,255,255,0.02); }
.funnel-row-contacted    { opacity: 0.6; }
.funnel-row-contacted:hover { opacity: 0.9; }
.funnel-row[onclick]     { cursor: pointer; }

.funnel-row-main {
  display: grid;
  grid-template-columns: 150px 100px 1fr 120px 185px;
  align-items: center;
  padding: 12px 20px;
  gap: 12px;
}

/* ── Columns ── */
.funnel-col       { display: flex; flex-direction: column; gap: 4px; }
.funnel-col-name  { gap: 5px; }

.funnel-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.funnel-col-spark  { align-items: center; justify-content: center; gap: 3px; }
.funnel-sparkline  { width: 60px; height: 24px; border-radius: 4px; display: block; image-rendering: pixelated; }
.funnel-spark-label{ font-size: 9px; color: var(--text-2); font-family: var(--font-mono); text-align: center; }

.funnel-row-lead .funnel-col-spark { align-items: flex-start; justify-content: center; gap: 3px; overflow: hidden; }
.funnel-row-lead .funnel-col-spark .funnel-stat-row { flex-wrap: nowrap; gap: 4px; }

.funnel-stat-row  { display: flex; align-items: baseline; gap: 6px; flex-wrap: nowrap; }
.funnel-stat-lbl  { font-size: 10px; color: var(--text-2); white-space: nowrap; font-family: var(--font-mono); min-width: 68px; }
.funnel-stat-val  { font-size: 12px; color: var(--text); white-space: nowrap; }

.funnel-notes-preview { font-size: 11px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

/* ── Risk column ── */
.funnel-col-risk   { gap: 5px; }
.funnel-risk-label { font-size: 10px; color: var(--text-2); font-family: var(--font-mono); }
.funnel-risk-bar-wrap { width: 100%; height: 4px; background: var(--bg-4); border-radius: 2px; overflow: hidden; }
.funnel-risk-bar   { height: 100%; border-radius: 2px; transition: width 0.4s ease; }
.funnel-risk-bar[data-bucket="high"]   { background: var(--red); }
.funnel-risk-bar[data-bucket="medium"] { background: var(--amber); }
.funnel-risk-bar[data-bucket="low"]    { background: var(--accent); }
.funnel-risk-value { font-size: 12px; color: var(--text-2); font-family: var(--font-mono); }

/* ── Action column ── */
.funnel-col-action    { gap: 7px; }
.funnel-action-text   { font-size: 12px; color: var(--text); line-height: 1.4; }
.funnel-action-btns   { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.funnel-check-label   { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.funnel-contacted-check { accent-color: var(--accent); width: 13px; height: 13px; cursor: pointer; }
.funnel-check-text    { font-size: 11px; color: var(--text-2); font-family: var(--font-mono); white-space: nowrap; }

.funnel-btn-hide,
.funnel-btn-icon {
  font-size: 11px;
  color: var(--text-2);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px 8px;
  cursor: pointer;
  font-family: var(--font-mono);
  transition: all 0.12s;
  white-space: nowrap;
}
.funnel-btn-hide:hover,
.funnel-btn-icon:hover { background: var(--bg-4); color: var(--text); }
.funnel-btn-icon.danger { color: var(--red); border-color: var(--red-dim); }
.funnel-btn-icon.danger:hover { background: var(--red-dim); }

/* ── Empty messages ── */
.funnel-empty-msg { padding: 20px; color: var(--text-2); font-size: 13px; text-align: center; font-style: italic; }

/* ── Add lead button ── */
.funnel-add-lead-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--accent-2-dim);
  border: 1px solid rgba(91,196,255,0.2);
  color: var(--accent-2);
  font-size: 11px;
  font-family: var(--font-mono);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  transition: background 0.15s;
}
.funnel-add-lead-btn:hover { background: rgba(91,196,255,0.18); }

/* ── Footer ── */
.funnel-footer {
  margin-top: 24px;
  padding: 14px 20px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.funnel-footer-stats  { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.funnel-footer-stat   { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); font-family: var(--font-mono); }
.funnel-footer-stat strong { color: var(--text); }
.funnel-footer-dot    { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.high-dot   { background: var(--red); }
.med-dot    { background: var(--amber); }
.stable-dot { background: var(--accent); }
.lead-dot   { background: var(--accent-2); }
.funnel-footer-divider{ width: 1px; height: 14px; background: var(--border); flex-shrink: 0; }

/* ── Email summary modal ── */
.modal-lg { max-width: 680px; }

.funnel-email-subject {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: var(--bg-3);
  border-radius: 8px;
  border: 1px solid var(--border);
}
.funnel-email-label        { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-2); font-family: var(--font-mono); white-space: nowrap; }
.funnel-email-subject-text { font-size: 13px; color: var(--text); font-family: var(--font-mono); }

.funnel-email-body {
  width: 100%;
  min-height: 320px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  padding: 14px;
  resize: vertical;
  outline: none;
}
.funnel-email-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  align-items: center;
  flex-wrap: wrap;
}
.funnel-email-actions .btn-ghost { display: flex; align-items: center; gap: 6px; text-decoration: none; }
.funnel-email-copied { font-size: 12px; color: var(--accent); font-family: var(--font-mono); margin-top: 8px; }

/* ── Funnel filter-bar group ── */
.filter-group-funnel { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; flex: 1; }
.filter-group-funnel #funnelSearch { flex: 1; width: auto; }
.filter-funnel-sort  { display: flex; align-items: center; gap: 5px; }
.funnel-email-btn { display: flex; align-items: center; gap: 5px; font-size: 12px; padding: 5px 12px; white-space: nowrap; }

/* ── Client detail dialog ── */
.fcd-modal { max-width: 560px; width: 100%; }

.fcd-header { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.fcd-title-block { flex: 1; min-width: 0; }
.fcd-name { font-family: var(--font-display); font-size: 20px; font-weight: 800; color: var(--text); line-height: 1.2; }
.fcd-meta { font-size: 12px; color: var(--text-2); font-family: var(--font-mono); margin-top: 3px; }

.fcd-score-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 20px;
  letter-spacing: 0.06em;
  white-space: nowrap;
  flex-shrink: 0;
  align-self: center;
}

.fcd-body { display: flex; flex-direction: column; gap: 18px; padding-top: 4px; }

.fcd-narrative {
  font-size: 13px;
  color: var(--text);
  line-height: 1.6;
  padding: 12px 14px;
  background: var(--bg-3);
  border-radius: 8px;
  border-left: 3px solid var(--border-light);
}

.fcd-stats-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.fcd-stat      { display: flex; flex-direction: column; gap: 3px; }
.fcd-stat-wide { grid-column: 1 / -1; }
.fcd-stat-label{ font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-2); font-family: var(--font-mono); }
.fcd-stat-value{ font-size: 14px; font-family: var(--font-mono); color: var(--text); font-weight: 500; }

.fcd-section-label {
  display: flex;
  align-items: center;
  gap: 0;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-2);
  font-family: var(--font-mono);
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}
.fcd-section-hint { font-size: 10px; color: var(--text-2); text-transform: none; letter-spacing: 0; opacity: 0.7; }

.fcd-timeline {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 280px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.fcd-timeline::-webkit-scrollbar       { width: 4px; }
.fcd-timeline::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.fcd-session-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 7px;
  background: var(--bg-3);
  transition: background 0.12s;
}
.fcd-session-row:hover { background: var(--bg-4); }

.fcd-session-date { display: flex; flex-direction: column; gap: 1px; min-width: 120px; }
.fcd-day { font-size: 13px; font-family: var(--font-mono); color: var(--text); font-weight: 500; }
.fcd-ago { font-size: 10px; color: var(--text-2); font-family: var(--font-mono); }

.fcd-chip       { font-size: 11px; font-family: var(--font-mono); padding: 3px 9px; border-radius: 20px; font-weight: 500; }
.fcd-chip-green { background: var(--accent-dim); color: var(--accent); }
.fcd-chip-amber { background: var(--amber-dim);  color: var(--amber); }
.fcd-chip-red   { background: var(--red-dim);    color: var(--red); }

.fcd-paid   { margin-left: auto; font-size: 10px; color: var(--accent); font-family: var(--font-mono); opacity: 0.7; }
.fcd-unpaid { margin-left: auto; font-size: 10px; color: var(--text-2); font-family: var(--font-mono); opacity: 0.7; }
.fcd-empty  { font-size: 13px; color: var(--text-2); text-align: center; padding: 16px; font-style: italic; }

.fcd-notes {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.6;
  padding: 12px 14px;
  background: var(--bg-3);
  border-radius: 8px;
  white-space: pre-wrap;
  border-left: 3px solid var(--accent-2);
  max-height: 120px;
  overflow-y: auto;
}

.fcd-notes-preview-list   { display: flex; flex-direction: column; gap: 6px; margin-bottom: 4px; }
.fcd-note-preview-entry   { background: var(--bg-3); border-radius: 7px; padding: 8px 11px; border: 1px solid var(--border); }
.fcd-note-preview-meta    { display: flex; align-items: center; gap: 5px; margin-bottom: 3px; }
.fcd-note-preview-date    { font-size: 10px; color: var(--text-2); font-family: var(--font-mono); }
.fcd-note-preview-text    { font-size: 12px; color: var(--text); line-height: 1.5; }

.fcd-notes-open-btn {
  background: none;
  border: none;
  color: var(--accent-2);
  font-size: 11px;
  font-family: var(--font-mono);
  cursor: pointer;
  padding: 0;
  margin-left: 8px;
  opacity: 0.8;
  transition: opacity 0.15s;
}
.fcd-notes-open-btn:hover { opacity: 1; }

/* ── Lead pipeline steps ── */
.funnel-pipeline-steps { display: flex; flex-direction: column; gap: 3px; margin-top: 4px; }
.lead-pipeline-step { display: flex; align-items: center; gap: 5px; cursor: pointer; padding: 1px 0; }
.lead-pipeline-step:hover .funnel-check-text { color: var(--text); }
.funnel-check-text.step-done {
  color: var(--accent);
  text-decoration: line-through;
  text-decoration-color: rgba(126,232,162,0.5);
}

/* ── Lead badge ── */
.funnel-lead-badge { background: var(--accent-2-dim); color: var(--accent-2); }

/* ===== FINANCIAL BREAKDOWN MODAL ===== */
.fin-breakdown-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}
.fin-breakdown-card { background: var(--bg-3); border-radius: 10px; padding: 14px 16px; border: 1px solid var(--border); }
.fin-breakdown-card.accent-card { background: var(--accent-dim); border-color: rgba(126,232,162,0.2); }
.fin-breakdown-card.amber-card  { background: var(--amber-dim);  border-color: rgba(255,201,92,0.2); }
.fin-bd-label   { font-size: 10px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-2); margin-bottom: 4px; }
.fin-bd-value   { font-family: var(--font-mono); font-size: 18px; font-weight: 600; color: var(--text); }
.fin-bd-value.green { color: var(--accent); }
.fin-bd-value.amber { color: var(--amber); }
.fin-bd-sub     { font-size: 11px; color: var(--text-2); margin-top: 2px; }

.fin-breakdown-section       { margin-bottom: 18px; }
.fin-breakdown-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-2);
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.fin-breakdown-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.fin-breakdown-table th { text-align: left; color: var(--text-2); font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; padding: 4px 8px; border-bottom: 1px solid var(--border); }
.fin-breakdown-table th:not(:first-child) { text-align: right; }
.fin-breakdown-table td { padding: 6px 8px; border-bottom: 1px solid rgba(42,42,53,0.6); font-family: var(--font-mono); color: var(--text); }
.fin-breakdown-table td:first-child { font-family: var(--font-body); }
.fin-breakdown-table td:not(:first-child) { text-align: right; }
.fin-breakdown-table tr:last-child td { border-bottom: none; }
.fin-breakdown-table .total-row td { font-weight: 600; border-top: 1px solid var(--border-light); border-bottom: none; color: var(--text); }

.fin-metrics-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 18px; }
.fin-metric-box  { background: var(--bg-3); border-radius: 8px; padding: 10px 12px; border: 1px solid var(--border); }
.fin-metric-label{ font-size: 10px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-2); margin-bottom: 3px; }
.fin-metric-value{ font-family: var(--font-mono); font-size: 14px; font-weight: 500; color: var(--text); }

/* ── Financial breakdown modal: mobile ── */
@media (max-width: 640px) {
  /* Modal itself: full-width, vertical scroll only */
  #finBreakdownModal .modal {
    max-width: 100%;
    width: 100%;
    margin: 0;
    border-radius: 14px 14px 0 0;
    max-height: 92vh;
    overflow-y: auto;
    overflow-x: hidden;
  }
  #finBreakdownModal.modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  /* Summary cards: stack vertically */
  .fin-breakdown-summary {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  /* Metric boxes: 2 per row */
  .fin-metrics-row {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  /* Revenue flow and session tables: no horizontal overflow */
  .fin-breakdown-table {
    font-size: 11.5px;
  }
  .fin-breakdown-table th,
  .fin-breakdown-table td {
    padding: 5px 5px;
  }

  /* Per-client table: too many columns for mobile - wrap in a horizontal scroller
     but constrain it to the modal width so the modal itself never overflows */
  .fin-client-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    border-radius: 6px;
  }
  .fin-client-table-wrap .fin-breakdown-table {
    min-width: 480px;
  }
}

/* ── Responsive ── */
@media (max-width: 900px) {
  .funnel-table-head { display: none; }
  .funnel-row-main   { grid-template-columns: 1fr 1fr; grid-template-rows: auto auto auto; }
  .funnel-col-name   { grid-column: 1; }
  .funnel-col-spark  { grid-column: 2; align-items: flex-end; }
  .funnel-col-stats  { grid-column: 1 / -1; }
  .funnel-col-risk   { grid-column: 1; }
  .funnel-col-action { grid-column: 2; }
  .funnel-page-header{ flex-direction: column; }
  .funnel-toolbar    { flex-direction: column; align-items: flex-start; }
  .funnel-search-group { width: 100%; }
}

@media (max-width: 600px) {
  .funnel-row-main   { grid-template-columns: 1fr; }
  .funnel-col-spark  { align-items: flex-start; }
  .funnel-col-action { grid-column: 1; }
}
