/* Admin BI · Inter American Academy — hoja única (tema claro deliberado; "exhibit" sobrio) */

/* ---------- Fuente de marca (self-hosted, Outfit variable) ---------- */
@font-face {
  font-family: 'Outfit';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('/assets/outfit-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
    U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Outfit';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('/assets/outfit-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ---------- Tokens ---------- */
:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --card: #ffffff;
  --line: #e2ded2;
  --line-2: #b9b4a3;
  --ink: #23263b;
  --ink-2: #565a6f;
  --ink-3: #76725f; /* 4.84:1 sobre blanco (texto ≤ 13 px en tarjetas); sobre el papel se usa --ink-2 */
  --navy: #29338b;
  --navy-d: #1f2769;
  --navy-t: #eaecf7;
  --pos: #1e6b45;
  --pos-t: #e7f4ed;
  --warn: #7e6318;
  --warn-t: #fdf3dc;
  --neg: #b3261e;
  --neg-t: #fbedeb;
  /* series de gráfico validadas (docs/DESIGN.md): 1 navy (paso claro), 2 ocre, 3 pizarra (croma subido) */
  --s1: #3947a1;
  --s2: #b8862b;
  --s3: #7780c2;
  --s1-tenue: #9aa2d6;
  --s1-medio: #6f7ac0;
  /* mobiliario de gráfico */
  --grid: #ebe8df;
  --axis: #cfcbbf;
  --esqueleto: #ece9e0;
  --radio: 10px;
  --sombra: 0 1px 2px rgba(35, 38, 59, 0.04);
  --fuente: 'Outfit', -apple-system, 'Segoe UI', Roboto, sans-serif;
  --lateral: 232px;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--fuente);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; } /* gana a los display:flex de .estado, .grafico, .tarjeta-extra */
button { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
a { color: var(--navy); }
.visualmente-oculto {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.salto {
  position: absolute; left: 8px; top: -48px; padding: 6px 10px; background: var(--card);
  border: 1px solid var(--line-2); border-radius: 6px; z-index: 40;
}
.salto:focus { top: 8px; }
.enlace {
  background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--navy); text-decoration: underline; text-underline-offset: 3px;
}
.enlace:hover { color: var(--navy-d); }
:focus-visible { outline: 2px solid var(--navy); outline-offset: 2px; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: var(--lateral) minmax(0, 1fr); min-height: 100vh; }

.lateral {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  background: var(--card); border-right: 1px solid var(--line);
  padding: 24px 18px 20px;
}
.marca { display: block; margin: 0 4px 22px; }
.marca img { width: 100%; height: auto; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; flex-direction: column; gap: 2px;
  padding: 9px 12px; border-radius: 8px;
  color: var(--ink-2); text-decoration: none; font-weight: 500;
}
.nav-item.activo { background: var(--navy-t); color: var(--navy-d); font-weight: 600; }
.nav-item.deshabilitado { color: var(--ink-3); cursor: default; }
.nav-item small { font-size: 11px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3); }
.lateral-pie { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; }
.usuario { display: flex; flex-direction: column; min-width: 0; }
.usuario-nombre { font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.usuario-email { font-size: 12px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lateral-pie .enlace { align-self: flex-start; font-size: 13px; }

.contenido { max-width: 1240px; width: 100%; padding: 32px; margin: 0 auto; min-width: 0; }
.contenido.recargando .kpis, .contenido.recargando .tarjetas { opacity: 0.55; pointer-events: none; }
.kpis, .tarjetas { transition: opacity 0.2s ease; }

/* ---------- Cabecera del tab ---------- */
.cabecera { margin-bottom: 22px; }
.cabecera-fila { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.cabecera h1 { font-size: 26px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.2; }
.subtitulo { color: var(--ink-2); font-size: 14px; margin-top: 4px; }
.subtitulo-nota { color: var(--warn); font-size: 13px; margin-top: 4px; max-width: 72ch; }
.filtros { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.segmentado { display: inline-flex; flex-wrap: wrap; max-width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 3px; gap: 2px; }
.segmentado button {
  border: 0; background: transparent; border-radius: 6px; padding: 6px 12px;
  color: var(--ink-2); font-weight: 500; cursor: pointer; white-space: nowrap;
}
.segmentado button:hover { color: var(--ink); background: var(--bg); }
.segmentado button[aria-pressed="true"] { background: var(--navy); color: #fff; }
/* Rango personalizado: dos fechas (desde/hasta) junto al control de periodo */
.fechas { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.fechas label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; color: var(--ink-2); }
.fechas input[type="date"] {
  font: inherit; font-size: 13px; color: var(--ink); background: var(--card);
  border: 1px solid var(--line-2); border-radius: 8px; padding: 5px 8px; min-width: 0; font-variant-numeric: tabular-nums;
}
.fechas input[type="date"]:focus { outline: 2px solid var(--navy); outline-offset: 1px; border-color: var(--navy); }
/* texto de 13 px sobre el papel: --ink-2 (--ink-3 no llega a 4.5:1 sobre #f4f1ea) */
.sync { margin-left: auto; color: var(--ink-2); font-size: 13px; white-space: nowrap; cursor: help; }
.sync.warn { color: var(--warn); font-weight: 500; }
.sync.neg { color: var(--neg); font-weight: 500; }

/* ---------- Estado (error) ---------- */
.estado {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; margin-bottom: 18px; border-radius: 8px;
  background: var(--neg-t); color: var(--neg); border: 1px solid rgba(179, 38, 30, 0.18);
}
.estado .enlace { color: inherit; font-weight: 600; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radio);
  box-shadow: var(--sombra); padding: 16px 18px 14px; min-height: 124px;
  display: flex; flex-direction: column; gap: 4px; min-width: 0;
}
/* la etiqueta reserva dos líneas para que los seis números héroe compartan línea base */
.kpi-etiqueta { font-size: 12px; font-weight: 500; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); line-height: 1.4; min-height: 2.8em; display: flex; align-items: flex-end; }
.kpi-valor { font-size: 34px; font-weight: 600; line-height: 1.1; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; color: var(--ink); }
.kpi-delta { font-size: 12.5px; font-variant-numeric: tabular-nums; color: var(--ink-3); }
.kpi-delta.pos { color: var(--pos); }
.kpi-delta.neg { color: var(--neg); }
.kpi-nota { font-size: 12px; color: var(--ink-3); margin-top: auto; padding-top: 4px; line-height: 1.35; }
.kpi-nota.neg { color: var(--neg); }

/* ---------- Tarjetas ---------- */
/* align-items: start → una tarjeta con tabla no estira a la vecina (hueco bajo "Canal de entrada") */
.tarjetas { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; }
.tarjeta {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radio);
  box-shadow: var(--sombra); padding: 20px 22px 14px; min-width: 0;
  display: flex; flex-direction: column; gap: 12px;
}
.tarjeta.ancha { grid-column: span 2; }
.titulo-accion { font-size: 17px; font-weight: 600; line-height: 1.35; letter-spacing: -0.005em; color: var(--ink); }
.tarjeta-sub { font-size: 13px; color: var(--ink-2); margin-top: 4px; }
.tarjeta-cuerpo { min-width: 0; }
.grafico { min-height: 120px; display: flex; flex-direction: column; gap: 10px; }
.grafico-svg { display: block; width: 100%; height: auto; overflow: visible; font-family: inherit; }
.vacio { color: var(--ink-3); font-size: 13px; padding: 36px 0; text-align: center; border: 1px dashed var(--line); border-radius: 8px; }
.tarjeta-pie { display: flex; align-items: center; gap: 12px; justify-content: space-between; margin-top: auto; padding-top: 10px; border-top: 1px solid var(--line); }
.fuente { font-size: 12px; color: var(--ink-3); flex: 1 1 auto; min-width: 0; line-height: 1.4; } /* el pie puede llevar una nota larga y envolver */
.ver-tabla { font-size: 12.5px; white-space: nowrap; flex: none; }

/* Leyenda */
.leyenda { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 0; padding: 0; list-style: none; font-size: 12.5px; color: var(--ink-2); }
.leyenda li { display: inline-flex; align-items: center; gap: 7px; }
.muestra { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.muestra-linea { width: 16px; height: 2px; border-radius: 1px; }

/* SVG: mobiliario y marcas */
.grafico-svg .hairline { stroke: var(--grid); stroke-width: 1; }
.grafico-svg .eje { stroke: var(--axis); stroke-width: 1; }
.grafico-svg .eje-texto { fill: var(--ink-3); font-size: 12px; font-variant-numeric: tabular-nums; }
.grafico-svg .etiqueta-directa { fill: var(--ink-2); font-size: 11.5px; font-weight: 500; font-variant-numeric: tabular-nums; }
.grafico-svg .etiqueta-cat { fill: var(--ink); font-size: 13px; }
.grafico-svg .etiqueta-cat.resaltada { font-weight: 600; }
.grafico-svg .etiqueta-valor { fill: var(--ink-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.grafico-svg .etiqueta-extra { fill: var(--ink); font-size: 13px; font-weight: 500; font-variant-numeric: tabular-nums; }
.grafico-svg .grupo-texto { fill: var(--ink-3); font-size: 11px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; }
.grafico-svg .linea-media { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; opacity: 0.9; pointer-events: none; }
.grafico-svg .hit { fill: transparent; }
.grafico-svg .fila-fondo { fill: var(--navy-t); }
.grafico-svg .marca-activa .barra { filter: brightness(1.14); }
.grafico-svg .marca.parcial .barra { opacity: 0.5; } /* semana incompleta en los extremos del rango */
.grafico-svg:focus-visible { outline: 2px solid var(--navy); outline-offset: 4px; border-radius: 4px; }

/* Tooltip (tarjeta blanca con hairline) */
.tooltip {
  position: fixed; z-index: 30; pointer-events: none;
  background: var(--card); border: 1px solid var(--line-2); border-radius: 8px;
  padding: 8px 11px; font-size: 12.5px; color: var(--ink-2); box-shadow: 0 2px 8px rgba(35, 38, 59, 0.08);
  min-width: 150px; max-width: 300px;
}
.tooltip-titulo { font-weight: 600; color: var(--ink); margin-bottom: 4px; }
.tooltip-nota { font-size: 12px; color: var(--ink-3); margin: -2px 0 4px; }
.tooltip-fila { display: flex; align-items: center; gap: 8px; line-height: 1.6; }
.tooltip-etiqueta { color: var(--ink-2); }
.tooltip-clave { width: 12px; height: 3px; border-radius: 2px; flex: none; }
.tooltip-clave.linea { height: 2px; }
.tooltip-clave.vacia { visibility: hidden; }
.tooltip-valor { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; min-width: 44px; text-align: right; }

/* Tablas */
.tabla-scroll { max-height: 360px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.tabla { width: 100%; border-collapse: collapse; font-size: 13px; }
.tabla th, .tabla td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tabla th { font-size: 11.5px; font-weight: 500; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-3); background: var(--card); position: sticky; top: 0; z-index: 1; }
.tabla td.num, .tabla th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tabla tbody tr:last-child td { border-bottom: 0; }
.tabla .neg { color: var(--neg); }
.tabla .pos { color: var(--pos); }
.tabla .sin-filas { color: var(--ink-3); text-align: center; padding: 18px; white-space: normal; }
.tabla-extra { display: flex; flex-direction: column; gap: 8px; }
.tabla-extra h3, .tarjeta-extra h3 { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.tarjeta-extra { display: flex; flex-direction: column; gap: 8px; min-width: 0; max-width: 100%; }
.tarjeta-extra > div { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
/* tablas extra en tarjetas de media columna: alto acotado con scroll interno */
.tarjeta:not(.ancha) .tarjeta-extra .tabla-scroll { max-height: 220px; }

/* ---------- Esqueletos de carga ---------- */
.bloque { display: block; background: var(--esqueleto); border-radius: 6px; height: 14px; }
.bloque.ancho { width: 60%; }
.bloque.alto { height: 34px; width: 45%; }
.bloque.grafico { height: 220px; width: 100%; }
@media (prefers-reduced-motion: no-preference) {
  .bloque { animation: latido 1.6s ease-in-out infinite; }
  @keyframes latido { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }
}

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-tarjeta {
  width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radio); box-shadow: var(--sombra); padding: 32px 32px 28px;
  display: flex; flex-direction: column; gap: 6px;
}
.login-logo { width: 190px; margin: 0 auto 14px; }
.login-tarjeta h1 { font-size: 20px; font-weight: 600; text-align: center; }
.login-sub { color: var(--ink-2); font-size: 13px; text-align: center; margin-bottom: 14px; }
.login-tarjeta label { font-size: 12px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3); margin-top: 8px; }
.login-tarjeta input {
  font: inherit; color: var(--ink); background: var(--card);
  border: 1px solid var(--line-2); border-radius: 8px; padding: 10px 12px; margin-top: 4px; width: 100%;
}
.login-tarjeta input:focus { outline: 2px solid var(--navy); outline-offset: 1px; border-color: var(--navy); }
.login-error { color: var(--neg); background: var(--neg-t); border-radius: 8px; padding: 8px 12px; font-size: 13px; margin-top: 10px; }
.boton {
  margin-top: 16px; background: var(--navy); color: #fff; border: 0; border-radius: 8px;
  padding: 11px 14px; font-weight: 600; cursor: pointer;
}
.boton:hover { background: var(--navy-d); }
.boton[disabled] { opacity: 0.6; cursor: default; }
.login-pie { text-align: center; font-size: 12px; color: var(--ink-3); margin-top: 14px; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 899px) {
  .app { display: block; }
  .lateral {
    height: auto; flex-direction: row; align-items: center; gap: 12px;
    padding: 8px 16px; border-right: 0; border-bottom: 1px solid var(--line); z-index: 10;
  }
  .marca { margin: 0; flex: none; }
  .marca img { width: auto; height: 34px; }
  .nav { flex-direction: row; flex: 1; min-width: 0; overflow: hidden; }
  .nav-item { padding: 6px 10px; white-space: nowrap; }
  .nav-item.deshabilitado { display: none; }
  .lateral-pie { margin-top: 0; padding-top: 0; border-top: 0; flex-direction: row; align-items: center; gap: 10px; }
  .usuario-email { display: none; }
  .usuario-nombre { max-width: 120px; font-size: 13px; }
  .contenido { padding: 18px 16px 28px; }
  .cabecera h1 { font-size: 22px; }
  .filtros { gap: 8px; }
  .segmentado button { padding: 6px 10px; font-size: 13px; }
  .fechas { width: 100%; }
  .fechas label { flex: 1 1 140px; }
  .fechas input[type="date"] { flex: 1; }
  .sync { margin-left: 0; width: 100%; white-space: normal; }
  .tarjeta:not(.ancha) .tarjeta-extra .tabla-scroll { max-height: 260px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 14px 14px 12px; min-height: 108px; }
  .kpi-valor { font-size: 28px; }
  .tarjetas { grid-template-columns: 1fr; gap: 14px; }
  .tarjeta, .tarjeta.ancha { grid-column: auto; padding: 16px 16px 12px; }
  .titulo-accion { font-size: 16px; }
  .tabla-scroll { max-height: 300px; }
}
@media (max-width: 480px) {
  .usuario-nombre { display: none; }
  .kpi-etiqueta { font-size: 11px; letter-spacing: 0.06em; }
  .segmentado button { padding: 6px 9px; }
}
