/* ============================================================
   MB Soluciones — demo del panel de KPIs (/demo/dashboard)
   Dirección: "sala de mando". Un solo panel enmarcado sobre el héroe
   oscuro, con una única secuencia de carga orquestada: las fuentes se
   sincronizan, los KPIs suben, el gráfico se dibuja y cruza la línea
   de HOY hacia la previsión, el ranking crece y las alertas van
   entrando una a una. Sin librerías: SVG + CSS + JS vanilla.
   Depende de los tokens de style.css (se carga después de él).
   ============================================================ */

.demo-stage {
  background:
    radial-gradient(900px 520px at 85% -5%, rgba(31,122,255,.30), transparent 60%),
    radial-gradient(640px 460px at -5% 105%, rgba(13,95,214,.22), transparent 60%),
    linear-gradient(180deg, var(--surface), var(--navy) 90%);
  padding: 40px 0 96px; color: #fff; position: relative; overflow: hidden;
}
.demo-stage::after {
  content: ''; position: absolute; inset: 0; pointer-events: none; opacity: .45;
  background-image: linear-gradient(rgba(255,255,255,.04) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.04) 1px, transparent 1px);
  background-size: 64px 64px;
}
.demo-stage .wrap { position: relative; z-index: 1; }

/* ---------- Marco del panel ---------- */
.dash {
  background: linear-gradient(180deg, rgba(20,31,60,.92), rgba(12,18,38,.96));
  border: 1px solid rgba(255,255,255,.09); border-radius: 14px; overflow: hidden;
  box-shadow: 0 40px 90px -30px rgba(0,0,0,.7), 0 0 0 1px rgba(31,122,255,.08) inset;
  backdrop-filter: blur(6px);
}
.dash::before {
  content: ''; display: block; height: 5px;
  background: linear-gradient(90deg, var(--blue-deep), var(--blue) 50%, var(--blue-2));
}

/* ---------- Barra superior: fuentes + estado ---------- */
.dash__bar {
  display: flex; align-items: center; justify-content: space-between; gap: 18px; flex-wrap: wrap;
  padding: 16px 24px; border-bottom: 1px solid rgba(255,255,255,.08);
}
.dash__title { font-family: var(--display); font-weight: 700; font-size: 17px; letter-spacing: .04em; text-transform: uppercase; color: #fff; display: flex; align-items: center; gap: 10px; }
.dash__title small { font-family: var(--mono); font-size: 11px; letter-spacing: .06em; color: #8b96b3; text-transform: none; font-weight: 400; }
.dash__sources { display: flex; gap: 8px; flex-wrap: wrap; }
.src {
  display: inline-flex; align-items: center; gap: 7px; padding: 5px 11px; border-radius: 999px;
  border: 1px solid rgba(255,255,255,.12); background: rgba(255,255,255,.04);
  font-family: var(--mono); font-size: 11.5px; color: #c3cbdc;
  opacity: 0; transform: translateY(4px); transition: opacity .45s var(--ease), transform .45s var(--ease);
}
.dash.is-live .src { opacity: 1; transform: none; }
.src i { width: 7px; height: 7px; border-radius: 50%; background: #3fd18f; box-shadow: 0 0 0 0 rgba(63,209,143,.55); animation: srcPulse 2.4s ease-out infinite; }
@keyframes srcPulse { 0% { box-shadow: 0 0 0 0 rgba(63,209,143,.55); } 70% { box-shadow: 0 0 0 7px rgba(63,209,143,0); } 100% { box-shadow: 0 0 0 0 rgba(63,209,143,0); } }
.dash__sync { font-family: var(--mono); font-size: 11.5px; color: #8b96b3; white-space: nowrap; }
.dash__sync b { color: #3fd18f; font-weight: 500; }

/* ---------- Rejilla ---------- */
.dash__grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: rgba(255,255,255,.07); }
.dash__grid > * { background: rgba(10,23,48,.55); }
/* min-width:0 evita que un hijo ancho (la tabla con scroll propio) estire la pista de la rejilla */
.dash__grid > *, .dash__main > *, .dash__model > *, .dash__foot > * { min-width: 0; }

.kpi { padding: 22px 24px 20px; position: relative; opacity: 0; transform: translateY(10px); transition: opacity .5s var(--ease), transform .5s var(--ease); }
.dash.is-live .kpi { opacity: 1; transform: none; }
.kpi:nth-child(2) { transition-delay: .08s; } .kpi:nth-child(3) { transition-delay: .16s; } .kpi:nth-child(4) { transition-delay: .24s; }
.kpi__label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: #8b96b3; font-weight: 600; margin: 0 0 10px; }
.kpi__value {
  font-family: var(--display); font-weight: 700; font-size: clamp(30px, 3.2vw, 42px); line-height: 1; color: #fff;
  font-variant-numeric: tabular-nums; text-shadow: 0 0 24px rgba(31,122,255,.25);
}
.kpi__value small { font-size: .55em; color: #c3cbdc; margin-left: 2px; }
.kpi__foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; }
.kpi__delta { font-family: var(--mono); font-size: 12px; padding: 3px 8px; border-radius: 4px; background: rgba(63,209,143,.14); color: #3fd18f; }
.kpi__delta--bad { background: rgba(224,163,58,.16); color: #f0b656; }
.kpi__spark { width: 84px; height: 28px; overflow: visible; }
.kpi__spark path { fill: none; stroke: var(--blue-2); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.kpi__spark .spark__area { fill: url(#sparkFill); stroke: none; }

/* ---------- Zona central: gráfico + ranking ---------- */
.dash__main { display: grid; grid-template-columns: 1.7fr 1fr; gap: 1px; background: rgba(255,255,255,.07); }
.dash__main > * { background: rgba(10,23,48,.55); }
.panel { padding: 22px 24px 20px; }
.panel__head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.panel__title { font-family: var(--display); font-weight: 700; font-size: 16px; letter-spacing: .03em; text-transform: uppercase; color: #fff; }
.panel__legend { display: flex; gap: 14px; font-family: var(--mono); font-size: 11px; color: #8b96b3; }
.panel__legend i { display: inline-block; width: 14px; height: 0; border-top: 2px solid var(--blue-2); vertical-align: middle; margin-right: 6px; }
.panel__legend i.is-dash { border-top-style: dashed; border-top-color: #9fc0ff; }
.panel__legend i.is-band { width: 14px; height: 8px; border: 0; background: rgba(31,122,255,.22); }

.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { font-family: var(--mono); font-size: 10.5px; fill: #8b96b3; }
.chart .grid line { stroke: rgba(255,255,255,.07); }
.chart .today line { stroke: rgba(255,255,255,.35); stroke-dasharray: 3 4; }
.chart .today text { fill: #c3cbdc; font-weight: 500; }
.chart .area { fill: url(#areaFill); opacity: 0; transition: opacity 1s var(--ease) .9s; }
.chart .line { fill: none; stroke: var(--blue-2); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 0 6px rgba(31,122,255,.55)); }
.chart .fc-line { fill: none; stroke: #9fc0ff; stroke-width: 2; stroke-dasharray: 5 5; stroke-linecap: round; }
.chart .fc-band { fill: rgba(31,122,255,.18); opacity: 0; transition: opacity .9s var(--ease) 2.2s; }
.chart .dot { fill: #fff; stroke: var(--blue-2); stroke-width: 3; opacity: 0; transition: opacity .3s var(--ease) 1.7s; }
.dash.is-live .chart .area, .dash.is-live .chart .fc-band, .dash.is-live .chart .dot { opacity: 1; }
.chart .fc-line { opacity: 1; }

.rank__row { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; padding: 9px 0; border-bottom: 1px solid rgba(255,255,255,.06); }
.rank__row:last-child { border-bottom: 0; }
.rank__name { font-size: 13.5px; color: #e6ebf5; }
.rank__val { font-family: var(--mono); font-size: 12.5px; color: #c3cbdc; }
.rank__bar { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: rgba(255,255,255,.07); overflow: hidden; }
.rank__bar i { display: block; height: 100%; width: 0; border-radius: 3px; background: linear-gradient(90deg, var(--blue), var(--blue-2)); transition: width 1.1s var(--ease); }
.dash.is-live .rank__bar i { width: var(--w); }
.rank__row:nth-child(2) .rank__bar i { transition-delay: .1s; } .rank__row:nth-child(3) .rank__bar i { transition-delay: .2s; }
.rank__row:nth-child(4) .rank__bar i { transition-delay: .3s; } .rank__row:nth-child(5) .rank__bar i { transition-delay: .4s; }

/* ---------- Modelo de deep learning + comportamiento previsto ---------- */
.dash__model { display: grid; grid-template-columns: 1fr 1.7fr; gap: 1px; background: rgba(255,255,255,.07); }
.dash__model > * { background: rgba(10,23,48,.55); }
.model { background: linear-gradient(160deg, rgba(31,122,255,.10), rgba(10,23,48,.55) 60%); }
.model__state { display: inline-flex; align-items: center; gap: 7px; }
.model__state::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: #8b96b3; }
.model__state.is-training::before { background: #f0b656; box-shadow: 0 0 0 0 rgba(240,182,86,.6); animation: srcPulse 1.1s ease-out infinite; }
.model__state.is-ready { color: #3fd18f; }
.model__state.is-ready::before { background: #3fd18f; box-shadow: 0 0 8px rgba(63,209,143,.7); }
.model__desc { font-size: 13.5px; line-height: 1.55; color: #c3cbdc; margin: 0 0 14px; }
.model__desc strong { color: #fff; }
.model__loss { width: 100%; height: auto; display: block; margin-bottom: 12px; }
.model__loss .lgrid line { stroke: rgba(255,255,255,.07); }
.model__loss text { font-family: var(--mono); font-size: 9px; fill: #8b96b3; }
.model__loss .lpath { fill: none; stroke: #f0b656; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 0 5px rgba(240,182,86,.5)); }
.model__loss .lpath--val { stroke: var(--blue-2); filter: drop-shadow(0 0 5px rgba(31,122,255,.5)); }
.model__loss .lcursor { stroke: rgba(255,255,255,.35); stroke-dasharray: 2 3; }
.model__stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; margin: 0; }
.model__stats div { border-top: 1px solid rgba(255,255,255,.08); padding-top: 8px; }
.model__stats dt { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #8b96b3; font-weight: 600; }
.model__stats dd { margin: 3px 0 0; font-family: var(--display); font-weight: 700; font-size: 22px; color: #fff; font-variant-numeric: tabular-nums; }

.pred-wrap { overflow-x: auto; }
.pred { width: 100%; border-collapse: collapse; font-size: 13.5px; color: #e6ebf5; min-width: 520px; }
.pred th { text-align: left; font-family: var(--mono); font-size: 11px; font-weight: 500; letter-spacing: .04em; color: #8b96b3; padding: 0 10px 10px 0; border-bottom: 1px solid rgba(255,255,255,.08); }
.pred td { padding: 10px 22px 10px 0; border-bottom: 1px solid rgba(255,255,255,.06); vertical-align: middle; }
.pred td:last-child, .pred th:last-child { padding-right: 0; text-align: right; }
.pred tr:last-child td { border-bottom: 0; }
.pred tbody tr { opacity: 0; transform: translateY(6px); transition: opacity .45s var(--ease), transform .45s var(--ease); }
.pred tbody tr.is-in { opacity: 1; transform: none; }
.pred .next { font-family: var(--mono); font-size: 12.5px; color: #c3cbdc; white-space: nowrap; }
.prob { display: grid; grid-template-columns: 1fr 44px; align-items: center; gap: 10px; min-width: 120px; }
.prob i { display: block; height: 6px; border-radius: 3px; background: rgba(255,255,255,.07); overflow: hidden; position: relative; }
.prob i::after { content: ''; position: absolute; inset: 0; width: var(--w); border-radius: 3px; background: #3fd18f; transition: width .9s var(--ease) .15s; }
.prob--warn i::after { background: #f0b656; }
.prob--risk i::after { background: #ff7a6b; }
.prob b { font-family: var(--mono); font-size: 12.5px; font-weight: 500; color: #c3cbdc; text-align: right; }
.prob--risk b { color: #ff9b90; }
.pred tbody tr:not(.is-in) .prob i::after { width: 0; }

/* ---------- Zona inferior: alertas + hallazgo ---------- */
.dash__foot { display: grid; grid-template-columns: 1.7fr 1fr; gap: 1px; background: rgba(255,255,255,.07); }
.dash__foot > * { background: rgba(10,23,48,.55); }
.alerts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; min-height: 148px; }
.alert {
  display: grid; grid-template-columns: 10px 1fr auto; gap: 12px; align-items: start;
  padding: 11px 14px; border-radius: 8px; background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.07);
  font-size: 13.5px; color: #dfe5f2; line-height: 1.5;
  opacity: 0; transform: translateX(-8px); transition: opacity .45s var(--ease), transform .45s var(--ease);
}
.alert.is-in { opacity: 1; transform: none; }
.alert i { width: 9px; height: 9px; border-radius: 50%; margin-top: 6px; }
.alert--warn i { background: #f0b656; box-shadow: 0 0 10px rgba(240,182,86,.7); }
.alert--risk i { background: #ff7a6b; box-shadow: 0 0 10px rgba(255,122,107,.7); }
.alert--ok i { background: #3fd18f; box-shadow: 0 0 10px rgba(63,209,143,.7); }
.alert time { font-family: var(--mono); font-size: 11px; color: #8b96b3; white-space: nowrap; }

.insight {
  height: 100%; display: flex; flex-direction: column; justify-content: center; gap: 10px;
  background: linear-gradient(135deg, rgba(31,122,255,.16), rgba(13,95,214,.05));
}
.insight__label { font-family: var(--display); font-weight: 700; font-size: 13px; letter-spacing: .12em; text-transform: uppercase; color: var(--blue-2); }
.insight__text { font-family: var(--display); font-weight: 600; font-size: clamp(19px, 1.7vw, 23px); line-height: 1.3; color: #fff; margin: 0; }
.insight__text b { color: var(--blue-2); }
.insight__note { font-size: 12px; color: #8b96b3; margin: 0; }

/* ---------- Cinta de eventos ---------- */
.ticker { display: flex; align-items: center; gap: 14px; padding: 10px 24px; border-top: 1px solid rgba(255,255,255,.08); font-family: var(--mono); font-size: 11.5px; color: #8b96b3; overflow: hidden; }
.ticker__tag { color: var(--blue-2); letter-spacing: .1em; text-transform: uppercase; white-space: nowrap; }
.ticker__item { color: #c3cbdc; transition: opacity .35s var(--ease); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ticker__item.is-out { opacity: 0; }

.dash__disclaimer { margin: 16px 0 0; font-size: 12.5px; color: #8b96b3; text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* ---------- Bloque de explicación (fondo claro) ---------- */
.demo-explain .pain h3 { font-size: 17px; }
.demo-explain .pain h3 span { font-family: var(--mono); font-size: 12px; color: var(--blue); margin-right: 8px; }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .dash__grid { grid-template-columns: 1fr 1fr; }
  .dash__main, .dash__foot, .dash__model { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .dash__grid { grid-template-columns: 1fr; }
  .dash__bar { padding: 14px 16px; }
  .panel, .kpi { padding: 18px 16px; }
  .ticker { padding: 10px 16px; }
  .chart text { font-size: 17px; } /* el viewBox se escala: hace falta más tamaño para que se lea */
  .alert { grid-template-columns: 10px 1fr; }
  .alert time { grid-column: 2; }
}
@media (prefers-reduced-motion: reduce) {
  .src i { animation: none; }
}
