/* ════════════════════════════════════════
   Analytics Page — D3.js Chart Styles
   ════════════════════════════════════════ */

/* ── KPI Strip ── */
.analytics-kpi-strip {
  display: flex; flex-wrap: wrap; gap: var(--space-lg);
  margin-bottom: var(--space-xl);
  padding: var(--space-lg) var(--space-xl);
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid rgba(255,255,255,0.06);
}
.a-kpi { display: flex; flex-direction: column; gap: 4px; min-width: 90px; }
.a-val { font-size: 1.5rem; font-weight: 700; font-family: 'Syne', sans-serif; }
.a-lbl { font-size: 0.75rem; color: var(--text-muted); }
.a-delta { font-size: 0.72rem; }
.a-delta.up { color: var(--emerald); }
.a-delta.down { color: var(--rose, #fb7185); }

/* ── Grid layouts ── */
.analytics-grid {
  display: grid;
  gap: var(--space-lg);
  margin-bottom: var(--space-lg);
}
/* Row 1: single full-width area chart */
.analytics-grid:not(.analytics-3col):not(.analytics-2col-alt):not(.analytics-4col) {
  grid-template-columns: 1fr;
}
/* Row 2: bar + donut + funnel */
.analytics-3col { grid-template-columns: 1.6fr 1fr 1fr; }
/* Row 3: radar + forecast */
.analytics-2col-alt { grid-template-columns: 1fr 1.4fr; }
/* Row 4: bottom 4 cards */
.analytics-4col { grid-template-columns: repeat(4, 1fr); }

/* ── Chart hosts ── */
.an-chart-host {
  width: 100%;
  min-height: 200px;
  position: relative;
}
.an-chart-host.short { min-height: 180px; }
.an-chart-host.radar-host { min-height: 260px; display: flex; align-items: center; justify-content: center; }
.an-area-card .an-chart-host { min-height: 200px; }

/* ── Chart legend row ── */
.chart-legend-row { display: flex; gap: 16px; align-items: center; }
.chart-legend-item { display: flex; align-items: center; gap: 6px; font-size: 0.75rem; color: var(--text-muted); }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }

/* ── D3 Tooltip (shared with agents.css) ── */
.d3-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(14,14,20,0.92);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  padding: 10px 14px;
  backdrop-filter: blur(12px);
  font-family: 'Syne', sans-serif;
  z-index: 10;
  min-width: 140px;
  transition: opacity 0.12s;
  box-shadow: 0 8px 32px rgba(0,0,0,0.55);
}

/* ── Donut ── */
.donut-wrap-d3 {
  position: relative;
  display: flex;
  justify-content: center;
  padding: 8px 0;
}
.donut-wrap-d3 svg { filter: drop-shadow(0 0 12px rgba(245,166,35,0.15)); }
.device-legend { display: flex; flex-direction: column; gap: 6px; padding: 0 4px; }
.leg-item { display: flex; align-items: center; gap: 8px; font-size: 0.8rem; color: var(--text-secondary, rgba(255,255,255,0.65)); }
.leg-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* ── A/B Tests ── */
.ab-list { display: flex; flex-direction: column; gap: 12px; }
.ab-row { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; border: 1px solid rgba(255,255,255,0.05); }
.ab-row-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.ab-name { font-size: 0.82rem; font-weight: 600; color: var(--text-primary); }
.ab-status { font-size: 0.68rem; padding: 2px 7px; border-radius: 20px; font-weight: 600; }
.ab-status.done    { background: rgba(52,211,153,0.12); color: #34d399; }
.ab-status.running { background: rgba(245,166,35,0.12); color: #f5a623; }
.ab-bar-track { background: rgba(255,255,255,0.06); border-radius: 4px; height: 4px; margin-bottom: 8px; overflow: hidden; }
.ab-bar-fill  { height: 100%; background: linear-gradient(90deg, #f5a623, #fbbf24); border-radius: 4px; transition: width 1s ease; }
.ab-row-foot  { display: flex; justify-content: space-between; }
.ab-winner    { font-size: 0.72rem; color: var(--text-muted); }
.ab-lift      { font-size: 0.72rem; font-weight: 700; color: #34d399; }

/* ── Top Topics ── */
.top-topics-list { display: flex; flex-direction: column; gap: 10px; }
.topic-row { display: flex; align-items: center; gap: 8px; }
.topic-name { font-size: 0.8rem; width: 90px; flex-shrink: 0; color: var(--text-secondary, rgba(255,255,255,0.7)); }
.topic-bar-track { flex: 1; height: 4px; background: rgba(255,255,255,0.06); border-radius: 4px; overflow: hidden; }
.topic-bar-fill  { height: 100%; border-radius: 4px; transition: width 1s ease; }
.topic-score { font-size: 0.72rem; font-weight: 700; width: 28px; text-align: right; flex-shrink: 0; }

/* ── Geo Distribution ── */
.geo-list { display: flex; flex-direction: column; gap: 8px; }
.geo-row { display: flex; align-items: center; gap: 8px; }
.geo-country { font-size: 0.78rem; width: 130px; flex-shrink: 0; color: var(--text-secondary, rgba(255,255,255,0.7)); white-space: nowrap; }
.geo-bar-track { flex: 1; height: 16px; background: rgba(255,255,255,0.04); border-radius: 3px; overflow: hidden; }
.geo-bar-fill  { height: 100%; border-radius: 3px; transition: width 1s ease; }
.geo-pct { font-size: 0.72rem; font-weight: 700; width: 32px; text-align: right; flex-shrink: 0; }

/* ── Send Streak ── */
.streak-host { padding: 4px 0; }
.streak-label { font-size: 0.72rem; color: var(--text-muted); margin-bottom: 12px; }
.streak-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 12px;
}
.streak-cell {
  aspect-ratio: 1;
  border-radius: 3px;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.15s;
}
.streak-cell:hover { transform: scale(1.3); opacity: 1 !important; }
.streak-foot { display: flex; justify-content: space-between; }
.streak-stat { font-size: 0.75rem; color: var(--text-muted); }

/* ── Responsive ── */
@media (max-width: 1280px) {
  .analytics-4col { grid-template-columns: repeat(2, 1fr); }
  .analytics-3col { grid-template-columns: 1fr 1fr; }
  .analytics-3col .funnel-card { grid-column: 1 / -1; }
}
@media (max-width: 900px) {
  .analytics-3col, .analytics-2col-alt, .analytics-4col { grid-template-columns: 1fr; }
}
