/* ===========================================================
   reports.css — Reportes v2: KPI tiles, gráficas SVG, tooltip
   =========================================================== */

/* OJO: .view-heading la usan TODAS las toolbars (visitas, actividad, flujo…),
   no solo Reportes — vive aquí por historia, no mover sin migrar. */
.view-heading { font-size: 16px; font-weight: 600; margin: 0; }

.dashboard { max-width: 1280px; margin: 0 auto; }

/* Slots categóricos de series — VALIDADOS con el validador de paleta en ambos
   modos (banda de luminosidad, cromía, separación CVD, contraste). El aqua en
   claro queda a 2.74:1 → siempre acompañado de leyenda + valores (relief). */
:root {
  --ch-s1: #2a78d6;   /* azul   */
  --ch-s2: #eb6834;   /* naranja*/
  --ch-s3: #1baf7a;   /* aqua   */
}
[data-theme="dark"] {
  --ch-s1: #3987e5;
  --ch-s2: #d95926;
  --ch-s3: #199e70;
}

/* ---- selector de periodo (toolbar) ---------------------------------------- */

.dash-period {
  display: inline-flex;
  gap: 2px;
  background: var(--bg-alt);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
}
.dash-period-btn {
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-muted);
  background: transparent;
  border: 0;
  border-radius: 999px;
  padding: 4px 12px;
  cursor: pointer;
  transition: background .12s var(--ease), color .12s var(--ease);
}
.dash-period-btn:hover { color: var(--fg); }
.dash-period-btn.active {
  background: var(--bg-elev);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

/* ---- KPI tiles -------------------------------------------------------------- */

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.kpi-card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow-sm);
}
.kpi-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
}
.kpi-value {
  font-size: 24px;
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}
.kpi-label {
  margin-top: 2px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--fg-muted);
}
.kpi-sub {
  margin-top: 2px;
  font-size: 10.5px;
  color: var(--fg-subtle);
}
.kpi-card.kpi-accent { border-top: 3px solid var(--accent); }
.kpi-card.kpi-warn   { border-top: 3px solid var(--warn); }

/* Delta vs periodo anterior — verde bueno / rojo malo (semántica ya invertida
   por JS donde subir es malo, p.ej. descartes). Texto siempre junto al color. */
.kpi-delta {
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  border-radius: 999px;
  padding: 1px 7px;
  white-space: nowrap;
}
.kpi-delta.good { color: #1d6f52; background: rgba(47, 156, 116, .14); }
.kpi-delta.bad  { color: #8a2a20; background: rgba(171, 48, 37, .12); }
.kpi-delta.flat { color: var(--fg-subtle); background: var(--hover); }
[data-theme="dark"] .kpi-delta.good { color: #5fd3a6; }
[data-theme="dark"] .kpi-delta.bad  { color: #f2988e; }

/* ---- grid de paneles ---------------------------------------------------------- */

.dash-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.dash-panel {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.dash-panel.span-2 { grid-column: span 2; }
.dash-panel-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 12px 16px 0;
}
.dash-panel-head h3 {
  font-size: 13px;
  font-weight: 650;
  color: var(--fg);
}
.dash-panel-sub { font-size: 11px; color: var(--fg-subtle); }
.dash-panel-body { padding: 10px 16px 14px; }

.chart-empty {
  padding: 26px 10px;
  text-align: center;
  font-size: 12px;
  color: var(--fg-subtle);
}
.ch-foot {
  margin-top: 6px;
  font-size: 10.5px;
  color: var(--fg-subtle);
}

/* ---- SVG: ejes recesivos, leyenda, crosshair ------------------------------------ */

.ch-svg { width: 100%; height: auto; display: block; }
.ch-grid  { stroke: var(--line); stroke-width: 1; }
.ch-axis  { stroke: var(--line-strong); stroke-width: 1; }
.ch-ytick, .ch-xtick {
  font-size: 10px;
  fill: var(--fg-subtle);
  font-family: var(--font-sans);
}
.ch-direct {
  font-size: 10px;
  font-weight: 700;
  fill: var(--fg-muted);
  font-family: var(--font-sans);
}
.ch-cross { stroke: var(--fg-subtle); }
.ch-hit:hover { fill: color-mix(in srgb, var(--accent) 6%, transparent); }

.ch-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin: 2px 0 8px;
}
.ch-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--fg-muted);   /* identidad en el punto, texto en tinta */
}
.ch-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ---- tooltip compartido ----------------------------------------------------------- */

.dash-tip {
  position: fixed;
  z-index: 3200;
  max-width: 260px;
  background: var(--bg-elev);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 8px 10px;
  font-size: 11.5px;
  color: var(--fg);
  pointer-events: none;
}
.dash-tip strong { display: block; margin-bottom: 4px; font-size: 11px; }
.tip-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  color: var(--fg-muted);
}
.tip-row b { margin-left: auto; color: var(--fg); font-variant-numeric: tabular-nums; }

/* ---- barras horizontales ------------------------------------------------------------ */

.hbars { list-style: none; display: flex; flex-direction: column; gap: 7px; }
.hbar-row {
  display: grid;
  grid-template-columns: 130px 1fr 64px;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
}
.hbar-label {
  color: var(--fg-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hbar-track {
  position: relative;
  height: 12px;
  background: var(--bg-alt);
  border-radius: 4px;
  overflow: hidden;
}
.hbar-fill {
  display: block;
  height: 100%;
  border-radius: 0 4px 4px 0;   /* extremo del dato redondeado, base anclada */
  transition: width .3s var(--ease-out);
}
.hbar-mark {
  position: absolute;
  top: 0; bottom: 0;
  width: 2px;
  background: var(--fg-subtle);
  opacity: .7;
}
.hbar-val {
  text-align: right;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}
.hbar-flag {
  font-size: 9.5px;
  font-weight: 700;
  color: #8a2a20;
}
[data-theme="dark"] .hbar-flag { color: #f2988e; }

/* ---- embudo de cohorte ---------------------------------------------------------------- */

.funnel { list-style: none; display: flex; flex-direction: column; gap: 7px; }
.funnel-row {
  display: grid;
  grid-template-columns: 10px 150px 1fr 72px 56px;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
}
.funnel-dot { width: 9px; height: 9px; border-radius: 50%; }
.funnel-name {
  color: var(--fg-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.funnel-track {
  height: 14px;
  background: var(--bg-alt);
  border-radius: 4px;
  overflow: hidden;
}
.funnel-fill {
  display: block;
  height: 100%;
  border-radius: 0 4px 4px 0;
  transition: width .3s var(--ease-out);
}
.funnel-rate {
  font-size: 10.5px;
  color: var(--fg-subtle);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.funnel-val {
  text-align: right;
  color: var(--fg);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ---- semáforo BD viva ------------------------------------------------------------------- */

.sem-tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.sem-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: var(--bg-alt);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 8px;
}
.sem-dot { width: 10px; height: 10px; border-radius: 50%; }
.sem-val {
  font-size: 22px;
  font-weight: 650;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}
.sem-label { font-size: 10.5px; color: var(--fg-muted); font-weight: 600; }

/* ---- listas (visitas próximas / actividad) ------------------------------------------------ */

.dash-list { list-style: none; display: flex; flex-direction: column; }
.dash-list-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}
.dash-list-item:last-child { border-bottom: 0; }
.dli-main { color: var(--fg); font-weight: 550; }
.dli-meta { color: var(--fg-subtle); white-space: nowrap; }

.activity-feed { list-style: none; display: flex; flex-direction: column; }
.activity-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}
.activity-item:last-child { border-bottom: 0; }
.activity-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  transform: translateY(-1px);
}
.activity-text {
  flex: 1;
  color: var(--fg-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.activity-time { color: var(--fg-subtle); font-size: 10.5px; white-space: nowrap; }

/* ---- pie + loading --------------------------------------------------------------------------- */

.dash-foot {
  margin-top: 14px;
  font-size: 11px;
  color: var(--fg-subtle);
  text-align: center;
}
.dash-loading {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 30px 0;
}
.skeleton-line {
  height: 14px;
  border-radius: 6px;
  background: var(--hover);
  animation: sk-pulse 1.2s ease-in-out infinite;
}
@keyframes sk-pulse { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }

/* ---- responsive ------------------------------------------------------------------------------- */

@media (max-width: 1024px) {
  .dash-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-panel.span-2 { grid-column: span 2; }
}
@media (max-width: 680px) {
  .dash-grid { grid-template-columns: 1fr; }
  .dash-panel.span-2 { grid-column: span 1; }
  .hbar-row { grid-template-columns: 96px 1fr 56px; }
  .funnel-row { grid-template-columns: 8px 104px 1fr 50px 44px; }
}
