/* ============================================================
   Axion · Panel de métricas — estilos
   Tema OSCURO premium SaaS. Superficies navy estratificadas.
   Acentos CATEGÓRICOS: cyan (primario) · esmeralda (ingreso) · violeta (3ª serie).
   Máximo 3 acentos visibles; cyan domina, los otros solo diferencian series.
   Layout: rail izquierdo + contenido borde a borde. Sin frameworks.
   ============================================================ */
:root {
  /* Superficies (oscuro, jamás blanco) — estratificadas por profundidad.
     Página = capa más oscura; cards y tiles suben en pasos visibles para que
     se separen incluso en proyector / videollamada. */
  --bg-page:    #0A1019;   /* la superficie más profunda */
  --bg-sidebar: #0A1628;   /* navy de marca */
  --bg-card:    #121C28;   /* tarjeta — claramente por encima de la página */
  --bg-tile:    #18232F;   /* tile / KPI / tracks — un paso más arriba */
  --border:     #243441;   /* borde visible */
  --border-2:   #2F4253;   /* borde hover, un paso más claro */
  --grid:       #1C2C3E;

  /* Texto */
  --text-1: #E8EEF4;
  --text-2: #8294A6;
  --text-3: #6B7C8F;

  /* Acentos categóricos (cada color = una entidad fija, nunca decorativo) */
  --acc-cyan:    #00B4F0;   /* primario / citas */
  --acc-emerald: #2DD4A7;   /* positivo / ingreso */
  --acc-violet:  #7C6FF0;   /* tercer serie / canal chat */

  /* Tintes a 10% para áreas / fondos de chip (planos) */
  --acc-cyan-10:    rgba(0, 180, 240, .10);
  --acc-emerald-12: rgba(45, 212, 167, .12);
  --acc-violet-12:  rgba(124, 111, 240, .12);

  /* Estado de deltas */
  --good: #2DD4A7;
  --bad:  #F0616D;
  --good-bg: rgba(45, 212, 167, .12);
  --bad-bg:  rgba(240, 97, 109, .12);

  /* Sistema de espaciado / radios */
  --rail:        232px;
  --radius-card: 12px;
  --radius-tile: 10px;
  --pad:         18px;
  --gap:         14px;
  --section-gap: 22px;
  --shadow-soft: 0 1px 2px rgba(0, 0, 0, .25);

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg-page);
  color: var(--text-1);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  line-height: 1.45;
}

/* números siempre tabulares para que aligneen */
.kpi__value,
.ticket-input input,
.bars__pct,
.delta { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

/* ============================================================
   Shell: rail + contenido
   ============================================================ */
.shell { display: grid; grid-template-columns: var(--rail) 1fr; min-height: 100vh; }
.content { min-width: 0; display: flex; flex-direction: column; }

/* ---------- Sidebar ---------- */
.sidebar {
  position: sticky; top: 0; align-self: start;
  height: 100vh; display: flex; flex-direction: column;
  gap: 6px; padding: 18px 14px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
}
.sidebar__logo {
  display: flex; align-items: center; gap: 11px;
  padding: 6px 8px 14px; text-decoration: none; color: inherit;
  margin-bottom: 6px; border-bottom: 1px solid var(--border);
}
.sidebar__mark {
  width: 36px; height: 36px; border-radius: 10px; flex: none;
  background: linear-gradient(135deg, var(--acc-cyan), #0077a8);
  color: #04121f; font-weight: 800; font-size: 19px;
  display: grid; place-items: center;
}
.sidebar__word { display: flex; flex-direction: column; line-height: 1.15; }
.sidebar__name { font-weight: 700; font-size: 16px; letter-spacing: .2px; color: var(--text-1); }
.sidebar__sub  { font-size: 11.5px; color: var(--text-2); font-weight: 500; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav--foot { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--border); }
.nav__item {
  position: relative; display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: var(--radius-tile);
  text-decoration: none; color: var(--text-2); font-weight: 600; font-size: 13.5px;
  transition: color .15s ease, background .15s ease;
}
.nav__item:hover { color: var(--text-1); background: rgba(255, 255, 255, .03); }
.nav__icon { width: 18px; text-align: center; font-size: 14px; line-height: 1; opacity: .85; }
.nav__item.is-active { color: var(--text-1); background: var(--bg-tile); }
.nav__item.is-active::before {
  content: ""; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 3px; height: 20px; border-radius: 0 3px 3px 0; background: var(--acc-cyan);
}

/* ---------- Header ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  flex-wrap: wrap;
  padding: 14px 32px;
  background: rgba(11, 18, 28, .82);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar__lead { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.topbar__title { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -.2px; color: var(--text-1); }
.topbar__meta { margin: 0; font-size: 12.5px; color: var(--text-2); font-weight: 500; }

.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.control {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-tile);
  border: 1px solid var(--border); border-radius: var(--radius-tile);
  padding: 7px 11px; font-size: 13px; color: var(--text-2);
  font-weight: 500;
}
.control--range { padding: 4px; gap: 2px; }
.seg {
  border: 0; background: transparent; cursor: pointer;
  padding: 6px 13px; border-radius: 8px;
  font: inherit; font-weight: 600; color: var(--text-2);
  transition: color .15s ease, background .15s ease;
}
.seg:hover { color: var(--text-1); }
.seg.is-active { background: var(--acc-cyan-10); color: var(--text-1); box-shadow: inset 0 0 0 1px rgba(0,180,240,.28); }

.control__label { font-weight: 600; }
.ticket-input { display: inline-flex; align-items: center; }
.ticket-input__cur { color: var(--text-2); }
.ticket-input input {
  width: 70px; border: 0; background: transparent;
  font: inherit; font-weight: 700; color: var(--text-1);
  text-align: right; outline: none;
}
.ticket-input input::-webkit-outer-spin-button,
.ticket-input input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* Toggle de fuente — control de producto (switch deslizante) */
.source-toggle {
  display: inline-flex; align-items: center; gap: 9px;
  background: var(--bg-tile); border: 1px solid var(--border); border-radius: var(--radius-tile);
  padding: 6px 12px 6px 9px; cursor: pointer; user-select: none;
  font: inherit; font-size: 13px; font-weight: 600; color: var(--text-2);
  transition: border-color .15s ease, background .15s ease;
}
.source-toggle:hover { border-color: var(--border-2); }
.source-toggle:focus-visible { outline: 2px solid var(--acc-cyan); outline-offset: 2px; }
.source-toggle__track {
  position: relative; width: 34px; height: 19px; border-radius: 999px;
  background: rgba(255, 255, 255, .14); transition: background .2s ease;
  flex: none;
}
.source-toggle__knob {
  position: absolute; top: 2px; left: 2px; width: 15px; height: 15px;
  border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .5);
  transition: transform .2s cubic-bezier(.2, .7, .3, 1);
}
.source-toggle[aria-pressed="true"] .source-toggle__track { background: var(--acc-cyan); }
.source-toggle[aria-pressed="true"] .source-toggle__knob { transform: translateX(15px); }
.source-toggle__label { white-space: nowrap; }

/* ---------- Layout de página (borde a borde) ---------- */
.page { flex: 1; width: 100%; padding: 24px 32px; }
[id] { scroll-margin-top: 86px; } /* compensa header sticky al anclar */

/* ---------- KPIs ---------- */
.kpis {
  display: grid; gap: var(--gap);
  grid-template-columns: repeat(5, 1fr);
  margin-bottom: var(--section-gap);
}
.kpi {
  position: relative;
  background: var(--bg-tile);
  border: 1px solid var(--border);
  border-left: 2px solid var(--text-3);
  border-radius: var(--radius-card); padding: 14px;
  display: flex; flex-direction: column; gap: 10px; min-width: 0;
  transition: border-color .18s ease, background .18s ease;
}
.kpi:hover { background: #162434; }
.kpi[data-accent="cyan"]    { border-left-color: var(--acc-cyan); }
.kpi[data-accent="emerald"] { border-left-color: var(--acc-emerald); }
.kpi[data-accent="violet"]  { border-left-color: var(--acc-violet); }
.kpi[data-accent="neutral"] { border-left-color: var(--text-3); }

.kpi__icon {
  position: absolute; top: 13px; right: 14px;
  font-size: 15px; line-height: 1; opacity: .38;
}
.kpi__label { font-size: 12.5px; color: var(--text-2); font-weight: 600; letter-spacing: .1px; padding-right: 22px; }
.kpi__value { font-size: 28px; font-weight: 500; letter-spacing: -.5px; line-height: 1; color: var(--text-1); }
.kpi__foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: auto; }
.kpi__hint { font-size: 11.5px; color: var(--text-3); font-weight: 400; }

/* Las dos KPI destacadas comparten estilo (sin gimmicks); el tinte sutil del
   acento las separa apenas del resto. Hijos categóricos vía data-accent. */
.kpi--feature[data-accent="cyan"]    { background: linear-gradient(180deg, rgba(0,180,240,.06), transparent), var(--bg-tile); }
.kpi--feature[data-accent="emerald"] { background: linear-gradient(180deg, rgba(45,212,167,.06), transparent), var(--bg-tile); }
.kpi--feature .kpi__value { font-size: 30px; }

/* delta como chip pequeño (verde sube / rojo baja) */
.delta { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; }
.delta__val {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 7px; border-radius: 6px; font-weight: 600; white-space: nowrap;
  background: rgba(255,255,255,.05); color: var(--text-2);
}
.delta__cmp { font-weight: 400; color: var(--text-3); font-size: 11px; white-space: nowrap; }
.delta--up   .delta__val { color: var(--good); background: var(--good-bg); }
.delta--down .delta__val { color: var(--bad);  background: var(--bad-bg); }
.delta--flat .delta__val { color: var(--text-2); }

/* ---------- Charts ---------- */
.charts {
  display: grid; gap: var(--gap);
  grid-template-columns: repeat(2, 1fr);
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: var(--pad); min-width: 0;
  display: flex; flex-direction: column; /* el body llena la altura de la fila */
  box-shadow: var(--shadow-soft);
  transition: border-color .18s ease;
}
.card:hover { border-color: var(--border-2); }
.card--wide { grid-column: 1 / -1; }
.card__head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; margin-bottom: 14px; flex-wrap: wrap;
}
.card__titles { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.card__head h2 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -.1px; color: var(--text-1); }
.card__sub { font-size: 12px; color: var(--text-2); font-weight: 500; }
.card__body { position: relative; height: 268px; flex: 1 1 auto; }
.card__body--center { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; }
.donut { position: relative; flex: 1 1 auto; width: 100%; min-height: 0; }
.card__body--bars { height: auto; display: flex; align-items: center; }
.card--wide .card__body { height: 292px; }

/* ---------- Leyendas HTML (la de Chart.js va desactivada) ---------- */
.legend { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.legend--center { gap: 18px; }
.legend__item { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-2); font-weight: 500; }
.legend__dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }

/* ---------- Barras horizontales tipo progress (embudo / por sucursal) ---------- */
.bars { display: flex; flex-direction: column; gap: 14px; width: 100%; }
.bars__row { display: grid; grid-template-columns: 1fr; gap: 6px; }
.bars__head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.bars__label { font-size: 12.5px; color: var(--text-2); font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars__val { font-size: 12.5px; color: var(--text-1); font-weight: 600; }
.bars__track { position: relative; height: 8px; border-radius: 999px; background: var(--bg-tile); overflow: hidden; }
.bars__fill {
  position: absolute; top: 0; left: 0; bottom: 0;
  border-radius: 999px; background: var(--acc-cyan);
  width: 0; transition: width .6s cubic-bezier(.2, .7, .3, 1);
}
.bars__fill--muted { background: var(--text-3); }
.bars__pct { color: var(--text-3); font-weight: 500; margin-left: 6px; }

/* ---------- Tooltip custom (handler externo de Chart.js) ---------- */
.ax-tip {
  position: fixed; z-index: 60; pointer-events: none;
  background: var(--bg-tile); border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 11px; min-width: 120px;
  font-family: var(--font); font-size: 12.5px; color: var(--text-1);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .35);
  opacity: 0; transition: opacity .12s ease;
  transform: translate(-50%, -100%);
}
.ax-tip__title { font-size: 11.5px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.ax-tip__row { display: flex; align-items: center; gap: 8px; }
.ax-tip__row + .ax-tip__row { margin-top: 4px; }
.ax-tip__dot { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.ax-tip__k { color: var(--text-2); margin-right: auto; }
.ax-tip__v { font-weight: 600; font-variant-numeric: tabular-nums; }
.ax-tip__foot { margin-top: 7px; padding-top: 6px; border-top: 1px solid var(--border); font-size: 11.5px; font-weight: 600; }

/* ---------- Estados: carga / vacío ---------- */
@keyframes shimmer { 0% { background-position: -180px 0; } 100% { background-position: 180px 0; } }
.skeleton {
  display: inline-block; min-width: 96px; height: 1em; border-radius: 7px;
  color: transparent !important;
  background: linear-gradient(90deg, rgba(255,255,255,.05) 25%, rgba(255,255,255,.11) 37%, rgba(255,255,255,.05) 63%);
  background-size: 360px 100%;
  animation: shimmer 1.25s ease-in-out infinite;
}
.kpi__value .skeleton { min-width: 120px; height: .9em; }

/* spinner sobrio sobre las gráficas mientras cargan */
@keyframes spin { to { transform: rotate(360deg); } }
.card__body canvas { transition: opacity .35s ease; }
.charts.is-loading .card__body > * { opacity: 0; }
.charts.is-loading .card__body::after {
  content: ""; position: absolute; top: 50%; left: 50%;
  width: 24px; height: 24px; margin: -12px 0 0 -12px;
  border: 2.5px solid rgba(255, 255, 255, .08); border-top-color: var(--acc-cyan);
  border-radius: 50%; animation: spin .7s linear infinite;
}

/* mensaje de estado vacío por gráfica */
.card__empty {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 13px; font-weight: 500; color: var(--text-3);
  pointer-events: none;
}

/* aparición suave de KPIs al pintar */
.kpis.is-loading .kpi__hint, .kpis.is-loading .delta { visibility: hidden; }

/* ---------- Footer / error ---------- */
.page__foot {
  margin-top: var(--section-gap); padding-top: 18px; border-top: 1px solid var(--border);
  text-align: center; font-size: 12px; color: var(--text-3);
  display: flex; align-items: center; justify-content: center; gap: 7px;
}
.page__foot-brand { font-weight: 600; color: var(--text-2); }
.page__foot-sep { opacity: .6; }
.error-banner {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
  background: #281016; color: #ff9aa3; border: 1px solid rgba(240, 97, 109, .4);
  padding: 10px 16px; border-radius: 11px; font-size: 13px; box-shadow: 0 10px 30px rgba(0,0,0,.5);
  z-index: 50; max-width: 90vw;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (min-width: 981px) {
  .kpis { grid-template-columns: 1.25fr 1.25fr 1fr 1fr 1fr; }
}
/* Rail a íconos */
@media (max-width: 1100px) {
  :root { --rail: 64px; }
  .sidebar { padding: 18px 8px; align-items: stretch; }
  .sidebar__word, .nav__text { display: none; }
  .sidebar__logo { justify-content: center; padding: 6px 0 14px; }
  .nav__item { justify-content: center; padding: 11px 0; }
  .nav__item.is-active::before { height: 24px; }
}
@media (max-width: 980px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpi--feature { grid-column: span 2; }
}
/* Rail a barra horizontal superior */
@media (max-width: 620px) {
  :root { --rail: 0; }
  .shell { display: block; }
  .sidebar {
    flex-direction: row; align-items: center; height: auto; gap: 4px;
    padding: 8px 10px; border-right: 0; border-bottom: 1px solid var(--border);
    overflow-x: auto;
  }
  .sidebar__logo { border-bottom: 0; padding: 4px 8px 4px 4px; margin: 0; }
  .sidebar__word { display: flex; }
  .nav { flex-direction: row; }
  .nav--foot { margin: 0 0 0 auto; padding: 0; border-top: 0; }
  .nav__text { display: none; }
  .nav__item { padding: 9px 11px; }
  .nav__item.is-active::before { display: none; }
  .page { padding: 18px; }
  .charts { grid-template-columns: 1fr; }
  .card--wide { grid-column: auto; }
  .topbar { padding: 12px 18px; }
}
@media (max-width: 520px) {
  .kpis { grid-template-columns: 1fr; }
  .kpi--feature { grid-column: auto; }
  .controls { width: 100%; }
}

/* Respeta usuarios con movimiento reducido */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .kpi, .card, .seg, .bars__fill { transition: none; }
}
