/* =========================================================================
 * componentes.css — piezas reutilizables, solo CSS.
 * Layout siempre con flexbox. Las gráficas se controlan con variables:
 *   style="--v: 64"  → valor en % (0–100)
 * ========================================================================= */

@property --grow { syntax: '<number>'; inherits: true; initial-value: 1; }
@property --p    { syntax: '<number>'; inherits: true; initial-value: 0; }
@property --rv   { syntax: '<number>'; inherits: true; initial-value: 1; }
@property --spin { syntax: '<angle>';  inherits: false; initial-value: 0deg; }

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
    min-height: 100vh;
    background: var(--bg-grad), var(--bg);
    background-attachment: fixed;
    color: var(--ink);
    font: 400 15px/1.45 var(--font);
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
.num, .mono { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); letter-spacing: -.02em; }

/* ---------- Flex utilitario ---------- */
.flex   { display: flex; }
.col    { display: flex; flex-direction: column; }
.row    { display: flex; flex-wrap: wrap; gap: var(--gap); }
.row > * { min-width: 0; }
.wrap   { flex-wrap: wrap; }
.center { align-items: center; }
.between{ justify-content: space-between; }
.grow   { flex: 1 1 0; }
.gap-s  { gap: 8px; }
.gap-m  { gap: 14px; }
.f-20 { flex: 1 1 calc(20% - var(--gap)); min-width: 180px; }
.f-25 { flex: 1 1 calc(25% - var(--gap)); min-width: 200px; }
.f-33 { flex: 1 1 calc(33.333% - var(--gap)); min-width: 260px; }
.f-40 { flex: 1 1 calc(40% - var(--gap)); min-width: 280px; }
.f-50 { flex: 1 1 calc(50% - var(--gap)); min-width: 300px; }
.f-60 { flex: 1 1 calc(60% - var(--gap)); min-width: 320px; }
.f-66 { flex: 2 1 calc(66.666% - var(--gap)); min-width: 320px; }
.f-100{ flex: 1 1 100%; }

/* ---------- Panel ---------- */
.panel {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 20px;
    background: var(--panel);
    border: 1px solid var(--panel-border);
    border-radius: var(--r-lg);
    box-shadow: var(--glow);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    overflow: hidden;
    animation: panel-in .9s var(--ease) both;
}
.theme-dark .panel::before {               /* filo de luz superior */
    content: '';
    position: absolute;
    left: 18px; right: 18px; top: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--fx-glow), transparent);
    opacity: .7;
}
.panel--flat { box-shadow: none; }
.panel--accent { background: linear-gradient(150deg, var(--ba-blue), var(--ba-blue-dark)); color: #fff; border-color: transparent; }
.panel--accent .panel__title, .panel--accent .kpi__label { color: rgba(255, 255, 255, .75); }

/* Esquinas tipo HUD */
.panel--hud { border-radius: var(--r-sm); }
.panel--hud::after {
    content: '';
    position: absolute; inset: 6px;
    pointer-events: none;
    --c: var(--fx-glow);
    background:
        linear-gradient(var(--c), var(--c)) top left / 14px 1px,
        linear-gradient(var(--c), var(--c)) top left / 1px 14px,
        linear-gradient(var(--c), var(--c)) top right / 14px 1px,
        linear-gradient(var(--c), var(--c)) top right / 1px 14px,
        linear-gradient(var(--c), var(--c)) bottom left / 14px 1px,
        linear-gradient(var(--c), var(--c)) bottom left / 1px 14px,
        linear-gradient(var(--c), var(--c)) bottom right / 14px 1px,
        linear-gradient(var(--c), var(--c)) bottom right / 1px 14px;
    background-repeat: no-repeat;
    opacity: .8;
}

.panel__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.panel__title { font-size: 12px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-2); }
.panel__sub { font-size: 13px; color: var(--ink-3); }
.panel__body { display: flex; flex-direction: column; gap: 12px; flex: 1; }

/* Retardos escalonados para la entrada */
.stagger > *:nth-child(1) { animation-delay: .05s; }
.stagger > *:nth-child(2) { animation-delay: .12s; }
.stagger > *:nth-child(3) { animation-delay: .19s; }
.stagger > *:nth-child(4) { animation-delay: .26s; }
.stagger > *:nth-child(5) { animation-delay: .33s; }
.stagger > *:nth-child(6) { animation-delay: .40s; }
.stagger > *:nth-child(7) { animation-delay: .47s; }
.stagger > *:nth-child(8) { animation-delay: .54s; }

/* ---------- Etiquetas y estados ---------- */
.tag {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 10px;
    border: 1px solid var(--panel-border);
    border-radius: 999px;
    font-size: 12px; color: var(--ink-2);
    white-space: nowrap;
}
.tag--live::before, .dot {
    content: '';
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--st-ok);
    box-shadow: 0 0 0 0 rgba(43, 182, 115, .6);
    animation: pulse 2s infinite;
}
.dot { display: inline-block; flex: none; }
.dot--warn  { background: var(--st-warn);  animation: none; }
.dot--alert { background: var(--st-alert); animation: none; }
.dot--idle  { background: var(--ink-3);    animation: none; }

.seg { display: inline-flex; border: 1px solid var(--panel-border); border-radius: 999px; padding: 3px; gap: 2px; }
.seg span { padding: 4px 12px; border-radius: 999px; font-size: 12px; color: var(--ink-2); cursor: pointer; }
.seg span.on { background: var(--accent); color: #fff; }
.theme-dark .seg span.on { box-shadow: 0 0 14px var(--fx-glow-soft); }

/* ---------- KPI ---------- */
.kpi { display: flex; flex-direction: column; gap: 4px; }
.kpi__label { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }
.kpi__value { font-size: 40px; font-weight: 300; line-height: 1.05; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi__value small { font-size: .5em; color: var(--ink-2); margin-left: 4px; }
.theme-dark .kpi__value { text-shadow: 0 0 22px var(--fx-glow-faint); }
.theme-light .kpi__value { color: var(--ba-blue); font-weight: 600; }
.kpi__delta { font-size: 13px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.kpi__delta::before { font-size: 10px; }
.kpi__delta.up::before   { content: '▲'; color: var(--st-ok); }
.kpi__delta.down::before { content: '▼'; color: var(--st-alert); }
.kpi--xl .kpi__value { font-size: 64px; }

/* ---------- Barras verticales ---------- */
.bars {
    --h: 180px;
    display: flex; align-items: flex-end; gap: 10px;
    height: var(--h);
    padding-top: 18px;
    background: repeating-linear-gradient(to top, var(--grid) 0 1px, transparent 1px calc(var(--h) / 4));
    border-bottom: 1px solid var(--panel-border);
}
.bars > i {
    position: relative;
    flex: 1;
    height: calc(var(--v) * 1% * var(--grow));
    border-radius: 4px 4px 0 0;
    background: linear-gradient(to top, var(--accent-2), var(--accent));
    animation: grow 1.4s var(--ease) both;
}
.theme-dark .bars > i { background: linear-gradient(to top, rgba(60, 140, 192, .35), var(--fx-glow)); box-shadow: 0 0 16px var(--fx-glow-soft); }
.bars > i:nth-child(2n) { animation-delay: .06s; }
.bars > i:nth-child(3n) { animation-delay: .12s; }
.bars > i:nth-child(4n) { animation-delay: .18s; }
.bars > i:hover { filter: brightness(1.25); }
.bars > i[data-l]::after {
    content: attr(data-l);
    position: absolute; left: 50%; bottom: -22px; transform: translateX(-50%);
    font-size: 11px; font-style: normal; color: var(--ink-3);
}
.bars > i.hl { background: linear-gradient(to top, var(--ba-blue), var(--fx-glow)); }
.bars > i.hl::before {
    content: attr(data-v);
    position: absolute; left: 50%; top: -22px; transform: translateX(-50%);
    font-size: 12px; font-style: normal; color: var(--ink); white-space: nowrap;
}
.bars--labels { margin-bottom: 22px; }

/* Barras dobles (dos series por grupo) */
.bars--pair > b { flex: 1; display: flex; align-items: flex-end; gap: 3px; height: 100%; position: relative; }
.bars--pair > b > i { flex: 1; height: calc(var(--v) * 1% * var(--grow)); border-radius: 3px 3px 0 0; animation: grow 1.4s var(--ease) both; }
.bars--pair > b > i:first-child { background: var(--accent-3); }
.bars--pair > b > i:last-child  { background: var(--accent); }
.theme-dark .bars--pair > b > i:last-child { background: var(--fx-glow); box-shadow: 0 0 12px var(--fx-glow-soft); }
.bars--pair > b[data-l]::after {
    content: attr(data-l); position: absolute; left: 50%; bottom: -22px; transform: translateX(-50%);
    font-size: 11px; font-weight: 400; color: var(--ink-3);
}

/* ---------- Barras horizontales ---------- */
.hbars { display: flex; flex-direction: column; gap: 12px; }
.hbar { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.hbar__name { flex: 0 0 120px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar__track { flex: 1; height: 8px; border-radius: 99px; background: var(--track); overflow: hidden; }
.hbar__track > i {
    display: block; height: 100%;
    width: calc(var(--v) * 1% * var(--grow));
    border-radius: 99px;
    background: linear-gradient(90deg, var(--accent-2), var(--accent));
    animation: grow 1.4s var(--ease) both;
}
.theme-dark .hbar__track > i { background: linear-gradient(90deg, var(--ba-sky), var(--fx-glow)); box-shadow: 0 0 10px var(--fx-glow-soft); }
.hbar__val { flex: 0 0 52px; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Área / línea con clip-path ---------- */
/* <div class="area"><b style="--pts: 0% 70%, 10% 55%, ..., 100% 20%"><i></i></b></div>
 * --pts = puntos de la curva (x %, y % desde arriba). El <b> dibuja el trazo con drop-shadow. */
.area {
    --h: 180px;
    position: relative;
    height: var(--h);
    background: repeating-linear-gradient(to top, var(--grid) 0 1px, transparent 1px calc(var(--h) / 4));
    border-bottom: 1px solid var(--panel-border);
}
.area > b, .spark > b {
    position: absolute; inset: 0;
    --line: var(--accent);
    filter: drop-shadow(0 -2px 0 var(--line));
}
.area > b > i, .spark > b > i {
    position: absolute; inset: 0;
    background: linear-gradient(to bottom, color-mix(in srgb, var(--line) 45%, transparent), transparent 95%);
    clip-path: polygon(var(--pts), 100% 100%, 0% 100%);
    -webkit-mask: linear-gradient(#000 0 0) no-repeat left / calc(var(--rv) * 100%) 100%;
            mask: linear-gradient(#000 0 0) no-repeat left / calc(var(--rv) * 100%) 100%;
    animation: reveal 1.8s var(--ease) both;
}
.area > b + b { --line: var(--accent-3); }
.theme-dark .area > b, .theme-dark .spark > b { --line: var(--fx-glow); filter: drop-shadow(0 -2px 0 var(--line)) drop-shadow(0 0 6px var(--fx-glow-soft)); }
.theme-dark .area > b + b { --line: var(--ba-teal); }
.area__axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-3); margin-top: 6px; }

/* Sparkline compacta */
.spark { height: 42px; position: relative; }

/* ---------- Donut con conic-gradient ---------- */
.donut {
    --size: 150px; --th: 16px;
    position: relative;
    width: var(--size); height: var(--size);
    flex: none;
    display: flex; align-items: center; justify-content: center; flex-direction: column;
    border-radius: 50%;
    animation: fill 1.6s var(--ease) both;
}
.donut::before {
    content: '';
    position: absolute; inset: 0;
    border-radius: 50%;
    background: conic-gradient(var(--accent) calc(var(--p) * var(--v) * 1%), var(--track) 0);
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - var(--th)), #000 calc(100% - var(--th) + 1px));
            mask: radial-gradient(farthest-side, transparent calc(100% - var(--th)), #000 calc(100% - var(--th) + 1px));
}
.theme-dark .donut::before { background: conic-gradient(var(--fx-glow) calc(var(--p) * var(--v) * 1%), var(--track) 0); filter: drop-shadow(0 0 8px var(--fx-glow-soft)); }
.donut b { font-size: calc(var(--size) * .22); font-weight: 300; line-height: 1; font-variant-numeric: tabular-nums; }
.donut small { font-size: 11px; color: var(--ink-3); letter-spacing: .1em; text-transform: uppercase; margin-top: 4px; }

/* Donut multisegmento: --a, --b, --c en % acumulados */
.donut--multi::before {
    background: conic-gradient(
        var(--accent) 0 calc(var(--p) * var(--a) * 1%),
        var(--accent-2) 0 calc(var(--p) * var(--b) * 1%),
        var(--accent-3) 0 calc(var(--p) * var(--c) * 1%),
        var(--track) 0);
}
.theme-dark .donut--multi::before {
    background: conic-gradient(
        var(--fx-glow) 0 calc(var(--p) * var(--a) * 1%),
        var(--ba-sky) 0 calc(var(--p) * var(--b) * 1%),
        var(--ba-teal) 0 calc(var(--p) * var(--c) * 1%),
        var(--track) 0);
}

/* ---------- Gauge semicircular ---------- */
.gauge {
    --size: 220px; --th: 18px;
    position: relative;
    width: var(--size); height: calc(var(--size) / 2 + 10px);
    display: flex; align-items: flex-end; justify-content: center;
    overflow: hidden;
    animation: fill 1.6s var(--ease) both;
}
.gauge::before {
    content: '';
    position: absolute; left: 0; top: 0;
    width: var(--size); height: var(--size);
    border-radius: 50%;
    background: conic-gradient(from 270deg, var(--accent) calc(var(--p) * var(--v) * .5%), var(--track) 0 50%, transparent 0);
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - var(--th)), #000 calc(100% - var(--th) + 1px));
            mask: radial-gradient(farthest-side, transparent calc(100% - var(--th)), #000 calc(100% - var(--th) + 1px));
}
.theme-dark .gauge::before {
    background: conic-gradient(from 270deg, var(--ba-sky), var(--fx-glow) calc(var(--p) * var(--v) * .5%), var(--track) 0 50%, transparent 0);
}
.gauge b { position: relative; font-size: 38px; font-weight: 300; line-height: 1; padding-bottom: 6px; }

/* ---------- Progreso ---------- */
.progress { display: flex; flex-direction: column; gap: 6px; }
.progress__top { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink-2); }
.progress__bar { height: 6px; border-radius: 99px; background: var(--track); overflow: hidden; }
.progress__bar > i { display: block; height: 100%; width: calc(var(--v) * 1% * var(--grow)); background: var(--accent); border-radius: 99px; animation: grow 1.4s var(--ease) both; }
.theme-dark .progress__bar > i { background: linear-gradient(90deg, var(--ba-sky), var(--fx-glow)); }

/* Segmentos tipo batería */
.cells { display: flex; gap: 3px; height: 14px; }
.cells > i { flex: 1; border-radius: 2px; background: var(--track); }
.cells > i.on { background: var(--accent); }
.theme-dark .cells > i.on { background: var(--fx-glow); box-shadow: 0 0 8px var(--fx-glow-soft); }

/* ---------- Heatmap ---------- */
.heat { display: flex; gap: 4px; }
.heat > div { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.heat i {
    display: block; aspect-ratio: 1; border-radius: 3px;
    background: color-mix(in oklab, var(--accent) calc(var(--v, 10) * 1%), var(--track));
}

/* ---------- Tabla ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-weight: 600; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); padding: 0 10px 10px 0; border-bottom: 1px solid var(--panel-border); }
.table td { padding: 11px 10px 11px 0; border-bottom: 1px solid var(--grid); color: var(--ink-2); }
.table td:first-child { color: var(--ink); }
.table .r { text-align: right; font-variant-numeric: tabular-nums; }
.table tr:hover td { background: var(--fx-glow-faint); }

/* ---------- Lista de eventos ---------- */
.feed { display: flex; flex-direction: column; }
.feed__item { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--grid); font-size: 13px; }
.feed__item:last-child { border-bottom: 0; }
.feed__time { flex: 0 0 44px; color: var(--ink-3); font-family: var(--font-mono); font-size: 12px; }
.feed__text { flex: 1; color: var(--ink-2); }
.feed__text b { color: var(--ink); font-weight: 600; }

/* ---------- Leyenda ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend span::before { content: ''; width: 9px; height: 9px; border-radius: 2px; background: var(--c, var(--accent)); }

/* ---------- Fondo HUD ---------- */
.grid-bg {
    background-image:
        linear-gradient(var(--grid) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid) 1px, transparent 1px);
    background-size: 40px 40px;
}
.scan { position: relative; }
.scan::after {
    content: '';
    position: absolute; left: 0; right: 0; top: 0; height: 30%;
    background: linear-gradient(to bottom, transparent, var(--fx-glow-faint), transparent);
    animation: scan 5s linear infinite;
    pointer-events: none;
}

/* ---------- Animaciones ---------- */
@keyframes panel-in { from { opacity: 0; transform: translateY(16px); } }
@keyframes grow     { from { --grow: 0; } }
@keyframes fill     { from { --p: 0; } to { --p: 1; } }
@keyframes reveal   { from { --rv: 0; } }
@keyframes pulse    { 70% { box-shadow: 0 0 0 8px rgba(43, 182, 115, 0); } 100% { box-shadow: 0 0 0 0 rgba(43, 182, 115, 0); } }
@keyframes scan     { from { transform: translateY(-100%); } to { transform: translateY(400%); } }
@keyframes spin     { to { transform: rotate(360deg); } }
@keyframes spin-rev { to { transform: rotate(-360deg); } }
@keyframes float    { 50% { transform: translateY(-8px); } }

.donut, .gauge { --p: 1; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .001s !important; animation-iteration-count: 1 !important; }
}

/* ---------- Piezas de estructura comunes ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 16px; line-height: 1.1; white-space: nowrap; }
.brand small { display: block; font-weight: 400; font-size: 12px; color: var(--ink-3); }
.brand__mark {
    width: 36px; height: 36px; flex: none;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700; letter-spacing: .02em; color: #fff;
    background: radial-gradient(circle at 30% 30%, var(--ba-sky), var(--ba-blue) 60%, var(--ba-blue-dark));
    box-shadow: 0 0 0 1px rgba(255, 255, 255, .1), 0 0 18px var(--fx-glow-faint);
}
.page-title { font-size: 28px; font-weight: 300; letter-spacing: -.01em; line-height: 1.1; }
.page-sub { font-size: 13px; color: var(--ink-3); margin-top: 4px; }
.search {
    display: flex; align-items: center; gap: 8px;
    min-width: 220px; padding: 9px 14px;
    border: 1px solid var(--panel-border); border-radius: 999px;
    background: var(--fx-glow-faint);
    color: var(--ink-3); font-size: 13px;
}
.theme-light .search { background: var(--ba-white); }
.search::before { content: '⌕'; font-size: 16px; line-height: 1; }
.avatar {
    width: 36px; height: 36px; border-radius: 50%; flex: none;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 600;
    background: var(--ba-steel); color: #fff;
    border: 2px solid var(--panel-border);
}
.icon-btn {
    width: 36px; height: 36px; border-radius: 10px; flex: none;
    display: flex; align-items: center; justify-content: center;
    border: 1px solid var(--panel-border); color: var(--ink-2); font-size: 15px;
}
.ico { width: 18px; text-align: center; font-style: normal; opacity: .9; }

/* Móvil: todas las columnas flex a ancho completo */
@media (max-width: 560px) {
    :root { --gap: 14px; }
    .row > [class*="f-"] { flex-basis: 100%; min-width: 0; }
    .search { min-width: 0; flex: 1 1 160px; }
    .kpi__value { font-size: 34px; }
}
