:root {
  --bg: #07090f; --panel: rgba(17, 22, 35, .72); --panel-2: rgba(26, 33, 52, .8); --line: rgba(148, 163, 184, .14);
  --text: #e6eaf3; --muted: #8b95ad; --ok: #22c55e; --warn: #f59e0b; --crit: #ef4444; --accent: #7c5cff; --accent-2: #22d3ee;
  --r: 18px; --font: 'Inter', system-ui, sans-serif; --mono: 'JetBrains Mono', ui-monospace, monospace;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); }
body { min-height: 100dvh; overflow-x: hidden; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
a { color: inherit; text-decoration: none; }
.mono { font-family: var(--mono); }

.bg-glow { position: fixed; inset: -20% -10% auto; height: 70vh; z-index: -1; pointer-events: none;
  background: radial-gradient(40% 50% at 20% 20%, rgba(124, 92, 255, .25), transparent 70%),
              radial-gradient(35% 45% at 85% 10%, rgba(34, 211, 238, .16), transparent 70%);
  animation: drift 18s ease-in-out infinite alternate; }
@keyframes drift { to { transform: translate3d(0, 4vh, 0) scale(1.05); } }

/* ---------- Login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 24px; padding: 32px 24px;
  backdrop-filter: blur(16px); display: grid; gap: 12px; text-align: center; animation: rise .5s cubic-bezier(.2, .8, .2, 1); }
.login-card h1 { margin: 6px 0 0; font-size: 26px; }
.pw-wrap { position: relative; }
.pw-wrap input { width: 100%; padding-right: 48px !important; }
.eye { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); width: 38px; height: 38px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); cursor: pointer; display: grid; place-items: center; }
.eye:hover { color: var(--text); background: var(--panel-2); }
.eye svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; }
.eye.on { color: var(--accent-2); }
.login-card input[type=password], .login-card input[type=text] { padding: 14px 16px; border-radius: 12px; border: 1px solid var(--line); background: #0b0f1a; color: var(--text); font-size: 16px; }
.check { display: flex; gap: 8px; align-items: center; justify-content: center; font-size: 13px; color: var(--muted); }
.err { color: var(--crit); min-height: 1em; margin: 0; font-size: 13px; }
.logo-big { position: relative; width: 72px; height: 72px; margin: 0 auto; border-radius: 22px; display: grid; place-items: center; font: 800 26px var(--mono);
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
.pulse-ring { position: absolute; inset: -6px; border-radius: 26px; border: 2px solid var(--accent); animation: ring 2.4s ease-out infinite; }
@keyframes ring { from { opacity: .8; transform: scale(.9); } to { opacity: 0; transform: scale(1.25); } }

/* ---------- Layout ---------- */
#app { max-width: 1100px; margin: 0 auto; padding: max(12px, env(safe-area-inset-top)) 16px calc(90px + env(safe-area-inset-bottom)); }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0 14px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; }
.logo { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; font: 800 13px var(--mono); color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.status-pill { display: flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font-size: 13px; font-weight: 600; transition: .3s; }
.beat { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 currentColor; color: var(--ok); animation: beat 1.6s infinite; }
.status-pill.warn .beat { background: var(--warn); color: var(--warn); } .status-pill.crit .beat { background: var(--crit); color: var(--crit); animation-duration: .8s; }
@keyframes beat { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 60%, transparent); } 70% { box-shadow: 0 0 0 9px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

.tabs { position: fixed; z-index: 20; left: 50%; bottom: max(12px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; gap: 4px; padding: 6px;
  border-radius: 20px; background: rgba(12, 16, 27, .82); border: 1px solid var(--line); backdrop-filter: blur(18px); box-shadow: 0 12px 40px rgba(0, 0, 0, .45); }
.tabs a { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 76px; padding: 8px 10px; border-radius: 14px; font-size: 11px; color: var(--muted); transition: .25s; }
.tabs a svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabs a.on { color: #fff; background: linear-gradient(135deg, rgba(124, 92, 255, .35), rgba(34, 211, 238, .2)); }
.badge { position: absolute; top: 2px; right: 14px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--crit); color: #fff; font-size: 11px; line-height: 18px; animation: pop .3s; }
@media (min-width: 900px) { .tabs { top: 14px; bottom: auto; left: auto; right: calc(50% - 550px + 220px); transform: none; flex-direction: row; } .tabs a { flex-direction: row; gap: 8px; font-size: 13px; min-width: 0; padding: 8px 14px; } .tabs a svg { width: 18px; height: 18px; } .badge { position: static; } #app { padding-bottom: 40px; } }

.grid { display: grid; gap: 14px; }
@media (min-width: 900px) { .grid.two { grid-template-columns: 1.3fr 1fr; } }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; backdrop-filter: blur(14px); animation: rise .45s cubic-bezier(.2, .8, .2, 1) both; }
.card h2 { margin: 0 0 12px; font-size: 15px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card h2 small { font-weight: 500; color: var(--muted); font-size: 12px; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
@keyframes pop { from { transform: scale(.4); } }
.grid > .card:nth-child(2) { animation-delay: .06s; } .grid > .card:nth-child(3) { animation-delay: .12s; } .grid > .card:nth-child(4) { animation-delay: .18s; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 700px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi { padding: 14px; border-radius: 16px; background: var(--panel-2); border: 1px solid var(--line); }
.kpi b { display: block; font: 700 22px var(--mono); margin-top: 2px; }
.kpi span { font-size: 12px; color: var(--muted); }

/* ---------- Barras apiladas por página ---------- */
.meter { margin: 14px 0 4px; }
.meter-head { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
.meter-head b { font-family: var(--mono); }
.bar { position: relative; height: 16px; border-radius: 9px; background: rgba(148, 163, 184, .12); overflow: hidden; display: flex; }
.seg { height: 100%; transition: width .8s cubic-bezier(.2, .8, .2, 1), filter .2s, opacity .2s; cursor: pointer; position: relative; }
.seg + .seg { box-shadow: inset 1px 0 0 rgba(7, 9, 15, .6); }
.bar .limit { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--warn); opacity: .8; }
.bar.warn { outline: 1px solid var(--warn); } .bar.crit { outline: 1px solid var(--crit); animation: blink 1.2s infinite; }
@keyframes blink { 50% { outline-color: transparent; } }
.dim .seg:not(.hl) { opacity: .22; filter: saturate(.4); }
.seg.hl { filter: brightness(1.25) drop-shadow(0 0 8px currentColor); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 10px; font-size: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); cursor: pointer; transition: color .2s; }
.legend i { width: 9px; height: 9px; border-radius: 3px; }
.legend span.hl { color: var(--text); }
.hint { font-size: 12px; color: var(--muted); margin: 8px 0 0; }
.hint.warn { color: var(--warn); }

/* ---------- Lista de páginas ---------- */
.apps { display: grid; gap: 8px; }
.app { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding: 12px; border-radius: 14px; background: var(--panel-2); border: 1px solid var(--line);
  transition: transform .2s, border-color .2s, background .2s; cursor: pointer; }
.app:hover, .app.hl { transform: translateY(-2px); border-color: color-mix(in srgb, var(--c) 70%, transparent); background: color-mix(in srgb, var(--c) 10%, var(--panel-2)); }
.app .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); box-shadow: 0 0 12px var(--c); }
.app .dot.down { background: var(--crit); box-shadow: 0 0 12px var(--crit); animation: beat .8s infinite; color: var(--crit); }
.app .dot.na { background: #475569; box-shadow: none; }
.app h3 { margin: 0; font-size: 14px; } .app p { margin: 0; font-size: 12px; color: var(--muted); }
.app .nums { text-align: right; font: 600 12px var(--mono); color: var(--muted); }
.app .nums b { color: var(--text); font-size: 13px; }
.spark { width: 70px; height: 24px; display: block; margin-left: auto; }

/* ---------- Servicios ---------- */
.svc { display: grid; gap: 4px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.svc:last-child { border: 0; }
.svc-top { display: flex; justify-content: space-between; gap: 12px; }
.svc b.price { font-family: var(--mono); white-space: nowrap; }
.free { color: var(--ok); }
.cost-row { display: grid; grid-template-columns: 12px 1fr auto; gap: 10px; align-items: center; padding: 8px 0; font-size: 14px; }
.cost-row i { width: 12px; height: 12px; border-radius: 4px; }
.cost-row .pbar { grid-column: 2 / 4; height: 6px; border-radius: 4px; background: rgba(148, 163, 184, .12); overflow: hidden; }
.cost-row .pbar div { height: 100%; transition: width .8s; }

/* ---------- Avisos ---------- */
.alert { display: grid; grid-template-columns: auto 1fr; gap: 10px; padding: 12px; border-radius: 14px; background: var(--panel-2); border: 1px solid var(--line); margin-bottom: 8px; animation: rise .35s both; }
.alert.critical { border-color: rgba(239, 68, 68, .5); background: rgba(239, 68, 68, .08); }
.alert.warn { border-color: rgba(245, 158, 11, .45); background: rgba(245, 158, 11, .07); }
.alert h4 { margin: 0; font-size: 14px; } .alert p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.empty { text-align: center; padding: 26px 10px; color: var(--muted); }
.empty .big { font-size: 34px; display: block; margin-bottom: 6px; animation: pop .5s; }
.rules { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.rules label { min-width: 0; display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.rules input { width: 100%; min-width: 0; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: #0b0f1a; color: var(--text); font: 14px var(--mono); }

.btn { border: 0; border-radius: 12px; padding: 12px 16px; font: 600 14px var(--font); cursor: pointer; transition: transform .15s, filter .2s; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); }
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(135deg, var(--accent), #5b8cff); color: #fff; border: 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Detalle (hoja inferior) ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; display: grid; align-items: end; }
.sheet-bg { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); animation: fade .25s; }
.sheet-card { display: flex; flex-direction: column; position: relative; max-height: 90dvh; overflow: hidden; transition: transform .22s ease; width: min(720px, 100%); margin: 0 auto; background: #0d1220; border: 1px solid var(--line); border-radius: 24px 24px 0 0; padding: 18px 16px calc(24px + env(safe-area-inset-bottom)); animation: up .35s cubic-bezier(.2, .8, .2, 1); }
.sheet-card .grab { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); width: 44px; height: 5px; border-radius: 3px; background: #334155; }
.sheet-head { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 0 10px; touch-action: none; cursor: grab; }
.sheet-body { overflow-y: auto; overscroll-behavior: contain; margin-right: -10px; padding-right: 10px; -webkit-overflow-scrolling: touch; }
.sheet-x { flex: none; width: 38px; height: 38px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel-2); color: var(--muted); display: grid; place-items: center; cursor: pointer; transition: .2s; }
.sheet-x:hover { color: #fff; background: #1f2a44; transform: rotate(90deg); }
.sheet-x svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.sheet.closing .sheet-card { transform: translateY(100%) !important; opacity: 0; transition: transform .22s ease, opacity .22s; }
.sheet.closing .sheet-bg { opacity: 0; transition: opacity .22s; }
body.noscroll { overflow: hidden; }
/* Barra de desplazamiento con el estilo de la app */
* { scrollbar-width: thin; scrollbar-color: #334155 transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2b3650; border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: #3b4a6b; background-clip: padding-box; }
@media (min-width: 900px) { .sheet { align-items: center; } .sheet-card { border-radius: 24px; } }
@keyframes up { from { transform: translateY(40%); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
.seg-tabs { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--panel-2); gap: 2px; }
.seg-tabs button { border: 0; background: none; color: var(--muted); padding: 6px 10px; border-radius: 8px; font: 600 12px var(--font); cursor: pointer; }
.seg-tabs button.on { background: #1f2a44; color: #fff; }
.chart { width: 100%; height: 150px; display: block; }
.chart path.area { opacity: .18; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 12px 0; }
@media (min-width: 600px) { .stats { grid-template-columns: repeat(4, 1fr); } }

.toast { position: fixed; left: 50%; bottom: 100px; transform: translate(-50%, 30px); opacity: 0; padding: 10px 16px; border-radius: 12px; background: #1e293b; border: 1px solid var(--line); font-size: 13px; transition: .3s; z-index: 60; pointer-events: none; }
.toast.on { transform: translate(-50%, 0); opacity: 1; }
.foot { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 11px; margin-top: 18px; }
.ring { width: 16px; height: 16px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 2.5; stroke: rgba(148, 163, 184, .2); }
.ring #ringFg { stroke: var(--accent-2); stroke-dasharray: 50.27; stroke-dashoffset: 0; stroke-linecap: round; }
.ring.run #ringFg { animation: ringrun var(--dur, 15s) linear forwards; }
.ring.busy { animation: spin .8s linear infinite; } .ring.busy #ringFg { stroke-dasharray: 18 50; animation: none; }
@keyframes ringrun { to { stroke-dashoffset: 50.27; } }
@keyframes spin { to { transform: rotate(270deg); } }
.top-right { display: flex; align-items: center; gap: 8px; }
.icon-btn { width: 36px; height: 36px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); color: var(--muted); display: grid; place-items: center; cursor: pointer; transition: .2s; }
.icon-btn:hover { color: var(--crit); border-color: rgba(239, 68, 68, .4); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
/* Tras la primera carga no se repiten animaciones de entrada (evita el parpadeo al actualizar). */
body.ready .card, body.ready .alert, body.ready .badge { animation: none; }
.skeleton { height: 120px; border-radius: var(--r); background: linear-gradient(90deg, var(--panel) 25%, var(--panel-2) 50%, var(--panel) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

.card, .grid > * { min-width: 0; }

/* Gráficas interactivas */
.chart-card { margin: 12px 0 4px; padding: 12px 12px 6px; border-radius: 14px; background: var(--panel-2); border: 1px solid var(--line); }
.chart-title { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 12px; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.chart-stats { display: flex; gap: 10px; font: 500 11px var(--mono); color: var(--muted); }
.chart-stats b { color: var(--text); font-weight: 700; }
.uchart { width: 100%; touch-action: pan-y; }
.uplot, .uplot * { font-family: var(--font); }
.uplot .u-legend { font-size: 12px; color: var(--muted); text-align: left; margin-top: 2px; }
.uplot .u-legend .u-marker { border-radius: 3px; }
.uplot .u-legend th { font-weight: 500; }
.uplot .u-legend td { font-family: var(--mono); color: var(--text); }
.uplot .u-cursor-x { border-right: 1px dashed rgba(229, 231, 235, .55) !important; }
.uplot .u-cursor-y { border-bottom: 1px dashed rgba(229, 231, 235, .25) !important; }
.uplot .u-select { background: rgba(34, 211, 238, .14); }

/* Capacidad / En vivo */
.home-tabs { display: inline-flex; gap: 4px; padding: 4px; margin-bottom: 14px; border-radius: 12px; background: rgba(148,163,184,.1); }
.home-tabs button { border: 0; background: none; color: var(--muted); font: 600 14px inherit; padding: 8px 16px; border-radius: 9px; cursor: pointer; }
.home-tabs button.on { background: var(--accent); color: #fff; }
.cap-hero { display: flex; gap: 18px; align-items: center; }
.cap-hero h2 { margin: 0 0 4px; }
.cap-big { font: 800 56px/1 var(--mono); color: var(--ok); min-width: 64px; text-align: center; }
.cap-big.crit { color: var(--crit); }
.cap-res { margin: 14px 0 6px; }
.cap-res .bar { position: relative; }
.pill { font-style: normal; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; margin-left: 6px; background: rgba(34,197,94,.15); color: var(--ok); }
.pill.warn { background: rgba(245,158,11,.15); color: var(--warn); }
.pill.crit { background: rgba(239,68,68,.15); color: var(--crit); }
.seg.peak { background: repeating-linear-gradient(45deg, rgba(124,92,255,.55) 0 4px, rgba(124,92,255,.15) 4px 8px); }
.cap-line { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--warn); opacity: .8; }
.cap-sub { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
@media (max-width: 600px) { .cap-big { font-size: 42px; min-width: 48px; } .cap-res .meter-head { flex-direction: column; align-items: flex-start; gap: 2px; } }

/* Logo */
.logo { background: none; padding: 0; object-fit: contain; }
.logo-big img { width: 100%; height: 100%; border-radius: inherit; display: block; }
.logo-big { background: none; }

.cost-row[data-app] { border-radius: 8px; padding-left: 6px; padding-right: 6px; transition: background .15s; }
.cost-row[data-app]:hover, .cost-row.hl { background: rgba(148,163,184,.1); }
.cap-res .seg { transition: opacity .2s, filter .2s; }
