/* =====================================================================
   BALANCE GROUP · SISTEMA VISUAL BASE DE PLANTILLAS DE GRÁFICOS · v3.0
   ---------------------------------------------------------------------
   Este bloque se inyecta (inline) en cada plantilla al compilar.
   Si cambiás un token acá, recompilá todas las plantillas (build.py).

   Reglas del sistema:
   - Tema por defecto: CLARO (fondos claros, texto negro).
   - Tema oscuro opcional: <html data-theme="dark">.
   - Tipografía: Inter (Google Fonts, eje óptico + pesos 400–700).
     Si no hay conexión, cae a la fuente del sistema sin romper el diseño.
   - Marca: NARANJA (acento y serie principal), NEGRO (texto y serie
     neutra), BLANCO (fondos) + VERDE como color complementario.
   - Series de datos (validadas para daltonismo y contraste):
       s1 naranja (principal) · s2 verde · s3 negro grafito (neutra).
     Cada serie tiene variantes -hi / -lo para degradés.
   - Profundidad: sombras en capas (cards, tiles, tooltips) y filtros
     de sombra/brillo en las marcas SVG (BG.defs crea los gradientes).
     Máximo 3 series: el resto se agrupa en "Otros" (gris claro).
   - Estados reservados (good/warn/crit): nunca como serie, siempre con
     ícono + texto.
   - El texto nunca usa el color de la serie: la identidad la da un
     punto/swatch al lado del texto.
   ===================================================================== */

/* ---------- 1. TOKENS · TEMA CLARO (por defecto) ---------- */
:root {
  color-scheme: light;

  /* Planos de fondo */
  --page:      #f7f7f5;   /* fondo de la página (blanco cálido) */
  --surface:   #ffffff;   /* card y área del gráfico */
  --surface-2: #fafaf8;   /* paneles internos */
  --surface-3: #f1f1ee;   /* pista de controles, hover */
  --border:    #e8e8e4;   /* bordes de card y paneles */
  --border-strong: #d6d6d1;
  --grid:      #efefeb;   /* grilla (hairline, sólida) */
  --axis:      #d2d2cc;   /* línea base */

  /* Tintas (texto) — negro real para títulos y valores */
  --ink:   #0a0a0b;
  --ink-2: #3f3f46;       /* contraste 10:1 */
  --muted: #6e6e76;       /* contraste 5:1 */

  /* Acento de marca: NARANJA (botones, selección, "hoy", foco) */
  --accent:      #f26b1d;
  --accent-2:    #ff9a3c;                      /* extremo claro del degradé */
  --accent-deep: #d4540a;                      /* extremo oscuro del degradé */
  --accent-ink:  #ffffff;
  --accent-wash: rgba(242, 107, 29, 0.08);
  --accent-glow: rgba(242, 107, 29, 0.35);

  /* Series de datos (validadas: naranja ↔ verde ΔE CVD 9,4 · contraste ≥ 3:1) */
  --s1: #e8650a;          /* naranja · principal */
  --s1-hi: #ff9a3c;       /* naranja claro (degradé) */
  --s1-lo: #c24f05;       /* naranja profundo (degradé) */
  --s2: #16996c;          /* verde · secundaria */
  --s2-hi: #3ec496;
  --s2-lo: #0e7a55;
  --s3: #27272a;          /* negro grafito · neutra (contraste por luminosidad) */
  --s3-hi: #5a5a62;
  --s3-lo: #0a0a0b;
  --s-other: #cfcfca;     /* "Otros" / contexto */
  --s1-wash: rgba(232, 101, 10, 0.12);
  --s2-wash: rgba(22, 153, 108, 0.12);

  /* Estados (reservados) */
  --good: #16a34a;  --good-ink: #15803d;
  --warn: #f2a900;  --warn-ink: #8a5a00;
  --crit: #dc2626;  --crit-ink: #b91c1c;

  /* Rampa secuencial naranja (magnitud) y texto legible por escalón */
  --seq-0: #fdf6f0; --seq-1: #fde4cf; --seq-2: #fbc89f; --seq-3: #f7a365;
  --seq-4: #ef7a2a; --seq-5: #d85d0c; --seq-6: #9e3f04;
  --seq-ink-0: #0a0a0b; --seq-ink-1: #0a0a0b; --seq-ink-2: #0a0a0b; --seq-ink-3: #0a0a0b;
  --seq-ink-4: #ffffff; --seq-ink-5: #ffffff; --seq-ink-6: #ffffff;

  /* Forma y sombras (profundidad en capas) */
  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(10,10,11,.04), 0 12px 32px -14px rgba(10,10,11,.14);
  --shadow-lift: 0 2px 4px rgba(10,10,11,.04), 0 24px 48px -20px rgba(10,10,11,.22);
  --shadow-pop: 0 1px 2px rgba(10,10,11,.06), 0 16px 40px -10px rgba(10,10,11,.22);
  --shadow-accent: 0 8px 20px -8px var(--accent-glow);

  /* Tipografía */
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ---------- 2. TOKENS · TEMA OSCURO (opcional) ---------- */
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:      #0b0b0c;
  --surface:   #151517;
  --surface-2: #1b1b1e;
  --surface-3: #25252a;
  --border:    #2a2a2f;
  --border-strong: #3a3a41;
  --grid:      #232327;
  --axis:      #3c3c44;
  --ink:   #f5f5f4;
  --ink-2: #c9c9cf;
  --muted: #8e8e97;
  --accent:      #ff7a24;
  --accent-2:    #ffa54f;
  --accent-deep: #e0600f;
  --accent-ink:  #0a0a0b;
  --accent-wash: rgba(255, 122, 36, 0.12);
  --accent-glow: rgba(255, 122, 36, 0.45);
  --s1: #ee6f14;  --s1-hi: #ffa54f;  --s1-lo: #b84d05;
  --s2: #19a476;  --s2-hi: #4fd4a6;  --s2-lo: #0f7a56;
  --s3: #d4d4d8;  --s3-hi: #ffffff;  --s3-lo: #8e8e97;
  --s-other: #46464d;
  --s1-wash: rgba(238, 111, 20, 0.16);
  --s2-wash: rgba(25, 164, 118, 0.16);
  --good: #22c55e;  --good-ink: #4ade80;
  --warn: #f2a900;  --warn-ink: #f2b84b;
  --crit: #ef4444;  --crit-ink: #f87171;
  --seq-0: #1d1917; --seq-1: #3a2315; --seq-2: #5d3113; --seq-3: #8a4612;
  --seq-4: #bf5c10; --seq-5: #ee6f14; --seq-6: #ffa54f;
  --seq-ink-0: #f5f5f4; --seq-ink-1: #f5f5f4; --seq-ink-2: #f5f5f4; --seq-ink-3: #ffffff;
  --seq-ink-4: #ffffff; --seq-ink-5: #ffffff; --seq-ink-6: #0a0a0b;
  --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 16px 40px -20px rgba(0,0,0,.7);
  --shadow-lift: 0 1px 0 rgba(255,255,255,.04) inset, 0 28px 56px -24px rgba(0,0,0,.8);
  --shadow-pop: 0 14px 36px -8px rgba(0,0,0,.7);
}

/* ---------- 3. RESET Y PÁGINA ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  /* Esfumados de marca muy suaves en las esquinas (naranja y verde) */
  background-image:
    radial-gradient(900px 520px at -8% -10%, rgba(242,107,29,.10), transparent 60%),
    radial-gradient(760px 480px at 108% 0%, rgba(22,153,108,.07), transparent 60%);
  background-attachment: fixed;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  font-optical-sizing: auto;               /* Inter ajusta el dibujo según el tamaño */
  font-feature-settings: "cv11", "ss03";   /* "a" de un piso y comillas/flechas más limpias */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
button, input { font: inherit; color: inherit; }
h1, h2, h3 { color: var(--ink); }

/* Contenedor de página tipo AdminLTE: encabezado + contenido */
.bg-page { max-width: 1240px; margin: 0 auto; padding: 28px 16px 56px; }
.bg-page__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 20px;
}
.bg-brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 14px; letter-spacing: -0.01em; }
.bg-brand__mark {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent-2), var(--accent-deep));
  color: #fff; font-weight: 700; font-size: 12px; letter-spacing: 0.02em;
  box-shadow: var(--shadow-accent);
}
.bg-brand small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; letter-spacing: 0; }
.bg-crumb { color: var(--muted); font-size: 12.5px; }
.bg-crumb b { color: var(--ink); font-weight: 500; }

/* ---------- 4. CARD ---------- */
.bg-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
/* Filete naranja superior: la marca sin invadir el contenido */
.bg-card::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 3px;
  background: linear-gradient(90deg, var(--accent-deep), var(--accent-2) 55%, var(--s2) 100%);
}
.bg-card__head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  padding: 20px 24px 18px; border-bottom: 1px solid var(--border);
}
/* Jerarquía tipográfica: eyebrow → título → bajada */
.bg-eyebrow { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.bg-title { margin: 4px 0 0; font-size: 22px; font-weight: 650; letter-spacing: -0.022em; line-height: 1.2; }
.bg-sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.bg-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.bg-card__body { padding: 20px 24px 24px; }
@media (max-width: 640px) {
  .bg-card__head { padding: 16px 16px 14px; }
  .bg-card__body { padding: 16px; }
  .bg-title { font-size: 20px; }
}

/* Layout de 2 columnas: gráfico + panel lateral (colapsa en móvil) */
.bg-split { display: grid; grid-template-columns: minmax(0, 1fr) 304px; gap: 20px; }
@media (max-width: 920px) { .bg-split { grid-template-columns: minmax(0, 1fr); } }

.bg-panel {
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 18px;
  box-shadow: 0 1px 2px rgba(10,10,11,.03), 0 10px 24px -16px rgba(10,10,11,.16);
}
.bg-panel h3 { margin: 0 0 10px; font-size: 13px; font-weight: 600; letter-spacing: -0.005em; }

/* ---------- 5. CONTROLES ---------- */
/* Control segmentado: pista gris + opción activa blanca con sombra */
.bg-seg {
  display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px;
  background: var(--surface-3); border: 1px solid var(--border);
}
.bg-seg button {
  border: 0; background: transparent; padding: 5px 12px; border-radius: 7px;
  font-size: 12.5px; font-weight: 500; color: var(--muted); cursor: pointer;
  transition: color .15s, background-color .15s, box-shadow .15s;
}
.bg-seg button:hover { color: var(--ink); }
.bg-seg button[aria-pressed="true"] {
  background: var(--surface); color: var(--ink); font-weight: 600;
  box-shadow: 0 1px 2px rgba(10,10,11,.08), 0 0 0 1px var(--border);
}

/* Botones */
.bg-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface);
  padding: 6px 11px; border-radius: 9px; font-size: 12.5px; font-weight: 500;
  cursor: pointer; color: var(--ink); line-height: 1.4;
  box-shadow: 0 1px 1px rgba(10,10,11,.03);
  transition: background-color .15s, border-color .15s;
}
.bg-btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
.bg-btn--primary {
  background: linear-gradient(180deg, var(--accent-2), var(--accent)); border-color: transparent;
  color: #fff; font-weight: 600; box-shadow: var(--shadow-accent);
}
.bg-btn--primary:hover { background: linear-gradient(180deg, var(--accent), var(--accent-deep)); border-color: transparent; }
.bg-btn svg { width: 15px; height: 15px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* Slider con acento de la serie principal */
.bg-range { width: 100%; accent-color: var(--accent); }

/* ---------- 6. KPIs, BADGES, LEYENDA ---------- */
.bg-kpi__label { font-size: 12px; font-weight: 500; color: var(--muted); }
.bg-kpi__value { font-size: 28px; font-weight: 650; letter-spacing: -0.028em; line-height: 1.15; color: var(--ink); }
/* Tile de KPI con brillo superior y elevación al pasar el mouse */
.bg-tile {
  position: relative; overflow: hidden;
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: 0 1px 2px rgba(10,10,11,.03), 0 10px 24px -16px rgba(10,10,11,.18);
  transition: transform .2s, box-shadow .2s;
}
.bg-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.bg-tile::after {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 60px; pointer-events: none;
  background: linear-gradient(180deg, rgba(255,255,255,.55), transparent);
}
:root[data-theme="dark"] .bg-tile::after { background: linear-gradient(180deg, rgba(255,255,255,.04), transparent); }
.bg-hero { font-size: 56px; font-weight: 650; letter-spacing: -0.045em; line-height: 1; color: var(--ink); }
.bg-delta { font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.bg-delta--up { color: var(--good-ink); }
.bg-delta--down { color: var(--crit-ink); }

.bg-badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600;
  padding: 2px 8px 2px 7px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink-2); white-space: nowrap; line-height: 1.5;
}
.bg-badge i { width: 7px; height: 7px; border-radius: 50%; display: inline-block; background: var(--s-other); }
.bg-badge--good i { background: var(--good); }
.bg-badge--good { color: var(--good-ink); }
.bg-badge--warn i { background: var(--warn); }
.bg-badge--warn { color: var(--warn-ink); }
.bg-badge--crit i { background: var(--crit); }
.bg-badge--crit { color: var(--crit-ink); }

.bg-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12px; color: var(--ink-2); }
.bg-legend span { display: inline-flex; align-items: center; gap: 6px; }
.bg-key { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.bg-key--line { width: 14px; height: 2px; border-radius: 2px; }

/* Barra de proporción / medidor */
.bg-meter { height: 8px; border-radius: 99px; background: var(--surface-3); overflow: hidden; display: flex; gap: 2px; }
.bg-meter > i { display: block; height: 100%; border-radius: 99px; box-shadow: 0 1px 2px rgba(10,10,11,.12) inset; }
.bg-meter > i[style*="--s1"], .bg-meter > i.m-s1 { background: linear-gradient(90deg, var(--s1-lo), var(--s1-hi)) !important; }

/* ---------- 7. SVG DE GRÁFICOS ---------- */
.bg-chart { position: relative; width: 100%; }
.bg-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.bg-chart text { font-family: var(--font); fill: var(--muted); font-size: 11px; font-weight: 450; }
.bg-chart .tick-num, .tick-num { font-variant-numeric: tabular-nums; }
/* Etiquetas directas sobre el gráfico: halo del color de la superficie para que
   nunca se pisen con líneas o marcas que pasan por detrás */
.bg-chart text.lbl { paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; }
.bg-grid line { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.bg-axis { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
/* Sombras suaves para marcas (filtros definidos por BG.defs en cada <svg>) */
.bg-chart .mk-shadow { filter: drop-shadow(0 6px 10px rgba(10,10,11,.16)); }
.bg-chart .mk-glow-s1 { filter: drop-shadow(0 0 6px var(--accent-glow)); }
.bg-chart .mk-glow-s2 { filter: drop-shadow(0 0 6px rgba(22,153,108,.45)); }
.bg-chart .mk-glow-crit { filter: drop-shadow(0 0 6px rgba(220,38,38,.5)); }
.bg-chart .ln-shadow { filter: drop-shadow(0 4px 6px rgba(10,10,11,.18)); }

/* ---------- 8. TOOLTIP ---------- */
.bg-tip {
  position: fixed; z-index: 50; pointer-events: none; min-width: 168px; max-width: 280px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; font-size: 12px; line-height: 1.5;
  box-shadow: var(--shadow-pop);
  opacity: 0; transform: translateY(4px); transition: opacity .12s, transform .12s;
}
.bg-tip.is-on { opacity: 1; transform: none; }
.bg-tip__t { font-weight: 600; margin-bottom: 6px; padding-bottom: 6px; border-bottom: 1px solid var(--border); letter-spacing: -0.005em; }
.bg-tip__r { display: flex; justify-content: space-between; gap: 16px; color: var(--muted); }
.bg-tip__r b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.bg-tip__r span { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- 9. VISTA TABLA ---------- */
.bg-table-wrap { display: none; max-height: 440px; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.bg-card.is-table .bg-table-wrap { display: block; }
.bg-card.is-table .bg-viz { display: none; }
.bg-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.bg-table th, .bg-table td { padding: 9px 14px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.bg-table th { position: sticky; top: 0; background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: 11.5px; letter-spacing: 0.02em; }
.bg-table tbody tr:hover td { background: var(--surface-2); }
.bg-table td.num, .bg-table th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- 10. ANIMACIONES (respetan "reducir movimiento") ---------- */
@keyframes bg-draw { from { stroke-dashoffset: var(--len, 2000); } to { stroke-dashoffset: 0; } }
@keyframes bg-grow { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes bg-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes bg-pulse { 0% { r: 6; opacity: .6; } 100% { r: 16; opacity: 0; } }
.anim-draw { stroke-dasharray: var(--len, 2000); animation: bg-draw 1.1s cubic-bezier(.3,.7,.2,1) both; }
.anim-grow { transform-box: fill-box; transform-origin: bottom; animation: bg-grow .7s cubic-bezier(.3,.7,.2,1) both; }
.anim-fade { animation: bg-fade .6s ease both; }
@media (prefers-reduced-motion: reduce) {
  .anim-draw, .anim-grow, .anim-fade { animation: none !important; }
}

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
