/* ============================================================================
   SafeGTM Stats page (SGM-430)
   Conventions:
     - All colors come from CSS variables — no raw hex
     - Light + dark theme via existing --bg / --text / --primary tokens
     - Touch targets ≥36px tall, ≥40px wide
   ============================================================================ */

.stats-page { padding: 0; }

.stats-header { margin-bottom: 16px; }
.stats-header h2 {
  display: flex; align-items: center; gap: 10px;
  font-size: 22px; font-weight: 700; color: var(--text); margin: 0 0 4px;
}
.stats-h-icon { width: 22px; height: 22px; color: var(--primary); }
.stats-sub { font-size: 13px; color: var(--text-muted); margin: 0; }

/* Filter bar */
.stats-filter-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-bottom: 16px; padding: 10px 12px;
  background: var(--primary-bg);
  border: 1px solid var(--primary-border);
  border-radius: var(--radius);
}
.stats-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; min-height: 32px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-full); font-size: 12px; font-weight: 500;
  color: var(--text-secondary); cursor: pointer;
}
.stats-chip:hover { background: var(--bg-card-hover); }
.stats-chip.is-active { background: var(--primary); color: var(--text-inverse); border-color: var(--primary); }
.stats-chip.stats-toggle.is-on { background: var(--success-bg); color: var(--success); border-color: var(--success-border); }
.stats-chip.stats-toggle i { width: 14px; height: 14px; }
.stats-toggle-help {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--bg-code); color: var(--text-muted);
  font-size: 11px; font-weight: 600; cursor: help;
}
.stats-date-input {
  padding: 6px 8px; min-height: 32px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-input); color: var(--text); font-size: 12px;
}
.stats-date-sep { color: var(--text-muted); font-family: var(--font-family-mono); }
.stats-flex-spacer { flex: 1; }
.stats-meta {
  font-size: 11px; color: var(--text-muted);
  font-family: var(--font-family-mono);
}

/* Tabs */
.stats-tabs {
  display: flex; gap: 2px; border-bottom: 1px solid var(--border);
  margin-bottom: 16px; overflow-x: auto;
}
.stats-tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 14px; min-height: 40px;
  background: transparent; border: 0;
  border-bottom: 2px solid transparent;
  font-size: 13px; font-weight: 600; color: var(--text-muted); cursor: pointer;
  white-space: nowrap;
}
.stats-tab i { width: 14px; height: 14px; }
.stats-tab:hover { color: var(--text); background: var(--bg-card-hover); }
.stats-tab.is-active { color: var(--primary); border-bottom-color: var(--primary); }

/* KPI cards */
.stats-kpi-row {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px;
  margin-bottom: 16px;
}
@media (max-width: 1280px) { .stats-kpi-row { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 720px)  { .stats-kpi-row { grid-template-columns: repeat(2, 1fr); } }

.stats-kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex; flex-direction: column; gap: 6px;
  min-height: 90px;
}
.stats-kpi-label {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-muted);
}
.stats-kpi-value {
  font-size: 22px; font-weight: 700;
  color: var(--text); line-height: 1.1;
}
.stats-kpi-delta {
  display: inline-flex; align-items: center;
  gap: 4px;
  font-size: 11px; font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: var(--bg-code); color: var(--text-muted);
  align-self: flex-start;
  font-family: var(--font-family-mono);
}
.stats-delta--good   { color: var(--success); background: var(--success-bg); }
.stats-delta--warn   { color: var(--warning); background: var(--warning-bg); }
.stats-delta--danger { color: var(--danger);  background: var(--danger-bg); }
.stats-delta--flat   { color: var(--text-muted); background: var(--bg-code); }

/* Panel */
.stats-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 16px;
}
.stats-panel-h {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 12px;
}
.stats-panel-h h3 {
  font-size: 14px; font-weight: 700; color: var(--text); margin: 0;
}
.stats-meta-small {
  font-size: 11px; color: var(--text-muted);
  font-family: var(--font-family-mono);
}
.stats-chart { min-height: 280px; }

.stats-grid-2 {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
}
@media (max-width: 900px) { .stats-grid-2 { grid-template-columns: 1fr; } }

/* Funnel */
.stats-funnel { display: flex; flex-direction: column; gap: 8px; }
.stats-funnel-row {
  display: grid;
  grid-template-columns: 90px 1fr 80px 50px;
  gap: 10px; align-items: center;
  font-size: 12px;
}
.stats-funnel-label { color: var(--text-secondary); font-weight: 500; }
.stats-funnel-bar { height: 10px; background: var(--primary-bg); border-radius: 5px; overflow: hidden; }
.stats-funnel-bar > span { display: block; height: 100%; background: var(--primary); border-radius: 5px; }
.stats-funnel-count {
  color: var(--text); font-weight: 600;
  font-family: var(--font-family-mono); text-align: right; font-size: 11px;
}
.stats-funnel-pct {
  color: var(--text-muted);
  font-family: var(--font-family-mono); text-align: right; font-size: 11px;
}

/* SGM-434 follow-up: reconciliation banner removed from Overview tab
   per Maddy's direction. The /api/stats/summary endpoint still returns
   the recon block for ops debugging via API, but it isn't rendered. */

/* View toggle (mailbox tab) */
.stats-view-toggle {
  display: inline-flex; border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.stats-view-toggle button {
  width: 36px; height: 32px;
  background: var(--bg-card); border: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-muted); border-right: 1px solid var(--border);
}
.stats-view-toggle button:last-child { border-right: 0; }
.stats-view-toggle button.is-active { background: var(--primary); color: var(--text-inverse); }
.stats-view-toggle button i { width: 14px; height: 14px; }

/* Stats table */
.stats-table {
  width: 100%; border-collapse: collapse; font-size: 12px;
}
.stats-table th, .stats-table td {
  padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border);
}
.stats-table th {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--text-muted); background: var(--bg);
}
.stats-table td.num, .stats-table th.num {
  font-family: var(--font-family-mono); text-align: right;
}
.stats-table tr:hover td { background: var(--bg-card-hover); }

.stats-acc-name { font-weight: 600; color: var(--text); }
.stats-acc-industry { color: var(--text-muted); font-size: 11px; margin-top: 2px; }

/* Empty state */
.stats-empty {
  text-align: center; padding: 60px 20px; color: var(--text-muted);
}
.stats-empty i {
  width: 40px; height: 40px; color: var(--primary);
  margin: 0 auto 12px; display: inline-block;
}
.stats-empty h3 { font-size: 16px; color: var(--text); margin: 0 0 8px; }
.stats-empty p {
  font-size: 13px; max-width: 50ch; margin: 0 auto;
  line-height: 1.5;
}

.text-sm { font-size: 12px; }

/* SGM-430: sidebar — new Campaigns group + new entries */
#sidebar .nav-section-campaigns .nav-icon { color: var(--accent); }

/* ============================================================================
   SGM-432: Geo choropleth world map
   ============================================================================ */

.stats-geo-map {
  width: 100%;
  min-height: 380px;
  position: relative;
  background: var(--bg);
  border-radius: var(--radius);
  overflow: hidden;
}

.stats-geo-map svg path {
  transition: opacity var(--transition);
}

.stats-geo-map svg path:hover {
  opacity: 0.75;
  stroke: var(--primary);
  stroke-width: 1;
}

/* Linear gradient legend bar at the bottom of the map */
.stats-geo-legend {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding: 0 4px;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-family-mono);
}

.stats-geo-legend-gradient {
  flex: 1;
  height: 8px;
  border-radius: 4px;
  background: var(--primary-bg); /* JS overrides with computed gradient */
  border: 1px solid var(--border);
}

.stats-geo-legend-min,
.stats-geo-legend-max {
  white-space: nowrap;
  font-weight: 600;
  color: var(--text);
}

/* Floating tooltip — body-mounted so it isn't clipped by panel overflow */
.stats-geo-tooltip {
  position: fixed;
  z-index: 9999;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text);
  box-shadow: var(--shadow-md);
  pointer-events: none;
  max-width: 240px;
  line-height: 1.4;
}

.stats-geo-tooltip.hidden {
  display: none;
}

.stats-geo-tooltip strong {
  color: var(--text);
  font-weight: 700;
}

/* ── SGM-455: Bot vs Real transparency strip ──────────────────────────── */
.stats-bot-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.stats-bot-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.stats-bot-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: capitalize;
  color: var(--text-muted);
}
.stats-bot-bar-track {
  height: 8px;
  background: var(--bg-input);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
}
.stats-bot-bar-real {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s;
}
.stats-bot-bar-bot {
  height: 100%;
  background: var(--warning);
  transition: width 0.3s;
}
.stats-bot-counts {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}
.stats-bot-real-c strong {
  color: var(--text);
  font-weight: 700;
  font-size: 13px;
}

/* ── Portfolio tab (migration 279 dimensions) ────────────────────────── */
.stats-portfolio { display: flex; flex-direction: column; gap: 16px; }

.stats-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}
.stats-kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.stats-kpi-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 4px;
}
.stats-kpi-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.stats-kpi-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.port-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.port-bar-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 14px 12px;
}
.port-bar-row {
  display: grid;
  grid-template-columns: 160px 1fr 120px;
  gap: 10px;
  align-items: center;
  font-size: 12px;
}
.port-bar-label {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.port-bar-track {
  height: 8px;
  background: var(--bg-code);
  border-radius: 999px;
  overflow: hidden;
}
.port-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width var(--transition);
}
.port-bar-value {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  font-size: 11px;
}
.port-empty {
  padding: 12px 0;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

@media (max-width: 720px) {
  .port-grid-2 { grid-template-columns: 1fr; }
  .port-bar-row { grid-template-columns: 100px 1fr 80px; gap: 6px; font-size: 11px; }
}
