/* Panel de utilización — tokens del método dataviz (paleta de referencia
   validada; modo claro y oscuro seleccionados, no volteados). */

:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  /* categórica (orden fijo — el orden ES el mecanismo de seguridad CVD) */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --otros: #898781;
  /* estado (reservada) */
  --st-good: #0ca30c; --st-warning: #fab219;
  --st-serious: #ec835a; --st-critical: #d03b3b;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { font-weight: 600; }
.brand-group { display: flex; align-items: center; gap: 12px; }
.tenant-select {
  font: inherit;
  font-size: 13px;
  color: var(--text-primary);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 8px;
}
.tenant-select:focus-visible { outline: 2px solid var(--s1); outline-offset: 1px; }

.filtros { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.filtros .recargar {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 15px;
  padding: 4px 10px;
  cursor: pointer;
}
.filtros .recargar:hover { color: var(--text-primary); }

body.cargando .card, body.cargando .kpis { opacity: 0.55; transition: opacity 0.2s; }
.card, .kpis { transition: opacity 0.2s; }
.filtros .grupo {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.filtros button {
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  padding: 5px 11px;
  font: inherit;
  cursor: pointer;
}
.filtros button:hover { background: color-mix(in srgb, var(--text-muted) 12%, transparent); }
.filtros button[aria-pressed="true"] {
  background: var(--s1);
  color: #fff;
  font-weight: 600;
}
.filtros button:focus-visible { outline: 2px solid var(--s1); outline-offset: 1px; }

.content { max-width: 1180px; margin: 0 auto; padding: 20px; }

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
.tile-label { color: var(--text-secondary); font-size: 12px; }
.tile-value { font-size: 30px; font-weight: 600; margin-top: 2px; }
.tile-value-sm { font-size: 20px; }
.tile-hero { grid-column: span 2; }
.hero-num { font-size: 48px; }
.tile-foot { color: var(--text-secondary); font-size: 13px; margin-top: 2px; }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  margin-bottom: 16px;
}
.card h2 { font-size: 15px; margin: 0 0 10px; }
.card h2 .sub { color: var(--text-muted); font-weight: 400; font-size: 13px; }
.hint { color: var(--text-muted); font-size: 12px; margin: 0 0 8px; }

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

.chart-wrap { position: relative; height: 300px; }
.chart-wrap.tall { height: 380px; }

details { margin-top: 8px; color: var(--text-secondary); }
details summary { cursor: pointer; font-size: 12px; }

.table-scroll { overflow-x: auto; }
table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}
th, td {
  text-align: left;
  padding: 5px 10px;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
}
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
th { color: var(--text-secondary); font-weight: 600; }

.embudos .barra {
  display: flex;
  height: 14px;
  min-width: 180px;
  border-radius: 4px;
  overflow: hidden;
  background: var(--grid);
}
.embudos .barra span { display: block; height: 100%; }
.embudos .barra span + span { border-left: 2px solid var(--surface-1); }
.seg-ok { background: var(--st-good); }
.seg-rechazo { background: var(--st-serious); }
.seg-abandono { background: var(--text-muted); }
.leyenda-embudo {
  display: flex;
  gap: 14px;
  color: var(--text-secondary);
  font-size: 12px;
  padding: 6px 10px 0;
}
.leyenda-embudo i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 4px;
}

.digest {
  white-space: pre-wrap;
  font-family: inherit;
  color: var(--text-secondary);
  margin: 0;
  max-height: 420px;
  overflow-y: auto;
}
.vacio { color: var(--text-muted); font-style: italic; }
.vacio-chart {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-style: italic;
}
.tile-value.mal { color: var(--st-critical); }
tbody tr:hover { background: color-mix(in srgb, var(--text-muted) 7%, transparent); }

/* Elementos clicables con drill-down */
.clicable { cursor: pointer; }
.tile.clicable:hover { border-color: var(--s1); }
tr.clicable:hover td { text-decoration: underline dotted; }

/* Modal de detalle de eventos */
.detalle-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 20px;
}
.detalle {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 900px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  padding: 16px 18px;
}
.detalle-cabecera { display: flex; justify-content: space-between; align-items: center; }
.detalle-cabecera h3 { margin: 0; font-size: 15px; }
.detalle-cerrar {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 3px 9px;
}
.detalle-cuerpo { overflow-y: auto; margin-top: 8px; }
.detalle .meta-col {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  font-size: 12px;
}
