:root {
  --bg: #0b0b0f;
  --panel: #15151c;
  --panel-2: #1c1c25;
  --line: #2a2a35;
  --text: #ececf2;
  --muted: #9b9bab;
  --brand: #7435e6;
  --ok: #2bb673;
  --warn: #f5a623;
  --crit: #e5484d;
  --info: #5b8def;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: inherit; text-decoration: none; }
.muted { color: var(--muted); }
.txt-crit { color: var(--crit); }

/* Barra superior */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 1;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .18em; }
.topbar-meta { display: flex; align-items: center; gap: 16px; font-size: 13px; }
.btn-ghost { border: 1px solid var(--line); padding: 6px 12px; border-radius: 8px; }
.btn-ghost:hover { border-color: var(--brand); }

.wrap { max-width: 1200px; margin: 0 auto; padding: 24px 16px 48px; }
.page-title { font-size: 24px; margin: 0 0 20px; }
.alert { background: #3a1d20; border: 1px solid var(--crit); padding: 12px 16px; border-radius: var(--radius); margin-bottom: 20px; }
.empty { color: var(--muted); padding: 24px 0; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 24px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; display: flex; flex-direction: column; }
.kpi-value { font-size: 30px; font-weight: 700; line-height: 1.1; }
.kpi-label { color: var(--muted); font-size: 13px; }
.kpi-crit .kpi-value { color: var(--crit); }
.kpi-warn .kpi-value { color: var(--warn); }

/* Tarjetas de cliente */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--ok);
  border-radius: var(--radius); padding: 16px 18px; transition: transform .12s, border-color .12s;
}
.card:hover { transform: translateY(-2px); border-color: var(--brand); }
.card.status-ambar { border-left-color: var(--warn); }
.card.status-rojo { border-left-color: var(--crit); }
.card-head { display: flex; align-items: center; gap: 10px; }
.card-head h2 { margin: 0; font-size: 17px; }
.card-stats { color: var(--muted); font-size: 13px; margin: 6px 0 10px; }
.card-top { margin: 0; font-size: 13px; display: flex; gap: 8px; align-items: baseline; }

.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); flex: none; box-shadow: 0 0 0 4px rgba(43,182,115,.15); }
.dot-ambar { background: var(--warn); box-shadow: 0 0 0 4px rgba(245,166,35,.15); }
.dot-rojo { background: var(--crit); box-shadow: 0 0 0 4px rgba(229,72,77,.18); }
.dot-lg { width: 14px; height: 14px; }

/* Gravedades */
.chip { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; background: var(--line); color: var(--text); }
.sev-info { background: rgba(91,141,239,.18); color: var(--info); }
.sev-warn { background: rgba(245,197,66,.16); color: #f5c542; }
.sev-avg { background: rgba(245,166,35,.18); color: var(--warn); }
.sev-high { background: rgba(229,110,77,.2); color: #ff8a5c; }
.sev-disaster { background: rgba(229,72,77,.22); color: var(--crit); }

/* Detalle de cliente */
.back { color: var(--muted); font-size: 13px; display: inline-block; margin-bottom: 12px; }
.back:hover { color: var(--text); }
.client-head { display: flex; align-items: center; gap: 12px; }
.client-head .page-title { margin-bottom: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-top: 20px; overflow-x: auto; }
.panel h2 { font-size: 15px; margin: 0 0 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--panel-2); }
.host { font-weight: 600; white-space: nowrap; }

.state { font-size: 12px; font-weight: 600; white-space: nowrap; }
.state::before { content: "●"; margin-right: 6px; }
.state-ok { color: var(--ok); }
.state-down { color: var(--crit); }
.state-unknown { color: var(--muted); }

.cell-bar { min-width: 150px; white-space: nowrap; }
.bar-num { font-variant-numeric: tabular-nums; font-size: 12px; margin-left: 8px; color: var(--muted); }
progress.bar {
  -webkit-appearance: none; appearance: none; width: 90px; height: 8px;
  border: 0; border-radius: 4px; background: var(--line); vertical-align: middle; overflow: hidden;
}
progress.bar::-webkit-progress-bar { background: var(--line); border-radius: 4px; }
progress.bar::-webkit-progress-value { background: var(--ok); border-radius: 4px; }
progress.bar::-moz-progress-bar { background: var(--ok); border-radius: 4px; }
progress.lvl-warn::-webkit-progress-value { background: var(--warn); }
progress.lvl-warn::-moz-progress-bar { background: var(--warn); }
progress.lvl-crit::-webkit-progress-value { background: var(--crit); }
progress.lvl-crit::-moz-progress-bar { background: var(--crit); }

/* Login */
.login {
  max-width: 360px; margin: 10vh auto 0; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 32px 28px; display: flex; flex-direction: column; gap: 14px; text-align: center;
}
.login img { margin: 0 auto; }
.login h1 { margin: 0; letter-spacing: .2em; font-size: 20px; }
.login p { margin: -8px 0 6px; }
.login label { display: flex; flex-direction: column; gap: 6px; text-align: left; font-size: 13px; color: var(--muted); }
.login input {
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 10px 12px; font-size: 15px;
}
.login input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(116,53,230,.25); }
.login button {
  margin-top: 6px; background: var(--brand); color: #fff; border: 0; border-radius: 8px;
  padding: 11px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.login button:hover { filter: brightness(1.1); }
.login-error { color: var(--crit); font-size: 13px; margin: 0 !important; }

@media (max-width: 600px) {
  .topbar { padding: 12px 16px; }
  .topbar-meta .muted { display: none; }
}

/* Detalle de equipo */
.link { border-bottom: 1px dashed var(--muted); }
.link:hover { color: #b892ff; border-bottom-color: var(--brand); }
.subtitle { margin: 6px 0 0; font-size: 14px; }
.note { margin-top: 20px; background: rgba(116,53,230,.12); border: 1px solid rgba(116,53,230,.45); border-radius: var(--radius); padding: 12px 16px; font-size: 14px; }
.note code { background: var(--bg); padding: 1px 6px; border-radius: 4px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.grid3 .panel { margin-top: 20px; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 14px; margin: 0 0 8px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.kv-bars { grid-template-columns: 150px 1fr; align-items: center; }
.kv-bars progress.bar { width: min(320px, 60%); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }
.summary { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.summary .chip { font-size: 12px; padding: 4px 10px; }
.sev-ok { background: rgba(43,182,115,.16); color: var(--ok); }
.state-warn { color: var(--warn); }
.panel table + table, .kv + table { margin-top: 12px; }
@media (max-width: 600px) { .kv, .kv-bars { grid-template-columns: 120px 1fr; } }

/* ===== v3: puntuación, directo y animaciones ===== */
.txt-warn { color: var(--warn); }
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.head-score { display: flex; align-items: center; gap: 12px; line-height: 1.3; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.grid2 .panel { margin-top: 20px; }

/* Aparición escalonada */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.fade { animation: rise .55s cubic-bezier(.2,.8,.2,1) both; }
.kpis .fade:nth-child(2), .cards .fade:nth-child(2), .grid3 .fade:nth-child(2), .grid2 .fade:nth-child(2) { animation-delay: .06s; }
.kpis .fade:nth-child(3), .cards .fade:nth-child(3), .grid3 .fade:nth-child(3) { animation-delay: .12s; }
.kpis .fade:nth-child(4), .cards .fade:nth-child(4) { animation-delay: .18s; }
.kpis .fade:nth-child(5), .cards .fade:nth-child(5) { animation-delay: .24s; }
.kpis .fade:nth-child(6), .cards .fade:nth-child(6) { animation-delay: .30s; }
.kpis .fade:nth-child(7), .cards .fade:nth-child(n+7) { animation-delay: .36s; }

/* Portada */
.hero { display: grid; grid-template-columns: minmax(280px, 1fr) 2.2fr; gap: 16px; margin-bottom: 24px; }
.hero .kpis { margin: 0; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.hero-score { display: flex; align-items: center; gap: 20px; margin: 0; }
.hero-score h2 { color: var(--text); text-transform: none; letter-spacing: 0; font-size: 17px; margin: 0 0 4px; }
@media (max-width: 860px) { .hero { grid-template-columns: 1fr; } }

/* Anillos de puntuación */
.ring { position: relative; flex: none; --c: var(--muted); }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 10; }
.ring-bg { stroke: var(--line); }
.ring-fg { stroke: var(--c); stroke-linecap: round; stroke-dasharray: 326.73; stroke-dashoffset: 326.73;
  transition: stroke-dashoffset 1.6s cubic-bezier(.2,.8,.2,1); filter: drop-shadow(0 0 6px color-mix(in srgb, var(--c) 55%, transparent)); }
.ring.lvl-ok { --c: var(--ok); } .ring.lvl-warn { --c: var(--warn); } .ring.lvl-crit { --c: var(--crit); }
.ring-label { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; }
.ring-num { font-weight: 800; font-variant-numeric: tabular-nums; color: var(--c); }
.ring-label small { color: var(--muted); font-size: 11px; margin-top: 4px; }
.ring-lg { width: 132px; height: 132px; } .ring-lg .ring-num { font-size: 38px; }
.ring-md { width: 78px; height: 78px; } .ring-md .ring-num { font-size: 22px; }
.ring-sm { width: 40px; height: 40px; margin-left: auto; } .ring-sm circle { stroke-width: 12; } .ring-sm .ring-num { font-size: 12px; }
.score-badge { display: inline-block; min-width: 36px; text-align: center; font-weight: 700; font-size: 12px; padding: 2px 8px; border-radius: 999px; }
.score-badge.lvl-ok { background: rgba(43,182,115,.16); color: var(--ok); }
.score-badge.lvl-warn { background: rgba(245,166,35,.16); color: var(--warn); }
.score-badge.lvl-crit { background: rgba(229,72,77,.18); color: var(--crit); }

/* Detalle de la puntuación */
.checks { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 8px 24px; font-size: 14px; }
.checks li { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.checks li .small { margin-left: auto; }
.check-icon { width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 12px; font-weight: 800; flex: none; }
.check-ok .check-icon { background: rgba(43,182,115,.18); color: var(--ok); }
.check-ko .check-icon { background: rgba(229,72,77,.2); color: var(--crit); }
.check-na { color: var(--muted); } .check-na .check-icon { background: var(--line); }

/* En directo */
.live-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.live-head h2 { display: flex; align-items: center; gap: 10px; margin: 0; }
.pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--crit); position: relative; }
.pulse::after { content: ""; position: absolute; inset: -5px; border-radius: 50%; border: 2px solid var(--crit); animation: ping 1.6s ease-out infinite; }
@keyframes ping { from { transform: scale(.4); opacity: .9; } to { transform: scale(1.6); opacity: 0; } }
.live.live-empty .pulse, .live.live-error .pulse { background: var(--muted); }
.live.live-empty .pulse::after, .live.live-error .pulse::after { display: none; }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.chart { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px 12px 6px; }
.chart-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.chart-top strong { color: var(--text); font-size: 18px; font-variant-numeric: tabular-nums; }
.duo { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.duo strong { font-size: 14px; margin-right: 6px; }
.sw { display: inline-block; width: 8px; height: 8px; border-radius: 2px; }
.sw-a { background: #38bdf8; } .sw-b { background: #a78bfa; } .sw-c { background: #f5a623; } .sw-d { background: #f472b6; }
.chart canvas { display: block; width: 100%; height: 130px; }
.live-note { display: none; margin: 10px 0 0; }
.live.live-empty .live-note { display: block; }

/* Minis de estabilidad */
.minis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin-bottom: 10px; }
.mini { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; }
.mini span { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.mini small { color: var(--muted); font-size: 12px; }
.mini-warn span { color: var(--warn); } .mini-crit span { color: var(--crit); }

/* Listas y desplegables */
.plain { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.plain li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.plain li:last-child { border-bottom: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
details summary { cursor: pointer; color: #b892ff; font-size: 14px; margin-bottom: 10px; }
details summary:hover { color: var(--text); }
.row-new td:first-child { box-shadow: inset 3px 0 0 var(--brand); }
.chip + .chip { margin-left: 2px; }

@media (prefers-reduced-motion: reduce) {
  .fade, .pulse::after { animation: none; }
  .ring-fg { transition: none; }
  .card { transition: none; }
}

/* Riesgo en las tarjetas de cliente */
.card-risk { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 14px 0 0; }
.risk { font-size: 13px; font-weight: 700; padding: 4px 12px; border-radius: 999px; display: inline-flex; align-items: center; gap: 8px; }
.risk::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 25%, transparent); }
.risk-verde { color: var(--ok); background: rgba(43,182,115,.12); }
.risk-ambar { color: var(--warn); background: rgba(245,166,35,.13); }
.risk-rojo { color: var(--crit); background: rgba(229,72,77,.14); }

/* Estado pendiente de los recolectores */
.spinner { display: inline-block; width: 12px; height: 12px; margin-right: 8px; vertical-align: -1px;
  border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
.empty.txt-crit { color: var(--crit); }

/* ===== Acciones, soluciones y puertos ===== */
.nowrap { white-space: nowrap; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 16px 0 0; }
.btn { border: 1px solid var(--line); background: var(--panel-2); color: var(--text); border-radius: 8px; padding: 8px 14px;
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; transition: border-color .15s, background .15s, transform .1s; }
.btn:hover:not(:disabled) { border-color: var(--brand); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.1); }
.btn-danger { background: rgba(229,72,77,.14); border-color: rgba(229,72,77,.5); color: #ff8b8e; }
.btn-danger:hover:not(:disabled) { background: rgba(229,72,77,.24); border-color: var(--crit); }
.btn-ghost { background: transparent; }
.btn.is-busy { position: relative; color: transparent !important; }
.btn.is-busy::after { content: ""; position: absolute; inset: 0; margin: auto; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.35); border-top-color: #fff; animation: spin 1s linear infinite; }

/* Listas desplegables (problemas y puertos) */
.issues { display: flex; flex-direction: column; gap: 8px; }
.issue { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
.issue[open] { border-color: #3a3a48; }
.issue > summary, .checks details > summary, .collapse > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; }
.issue > summary { padding: 10px 14px; color: var(--text); margin: 0; font-size: 14px; }
.issue > summary::-webkit-details-marker, .checks details > summary::-webkit-details-marker, .collapse > summary::-webkit-details-marker { display: none; }
.issue > summary::after, .checks details > summary::after, .collapse > summary::after {
  content: "›"; margin-left: auto; color: var(--muted); font-size: 18px; line-height: 1; transition: transform .2s; flex: none; }
.issue[open] > summary::after, .checks details[open] > summary::after, .collapse[open] > summary::after { transform: rotate(90deg); }
.issue-title { flex: 1; min-width: 0; }
.port-num { min-width: 52px; font-weight: 700; }
.advice { padding: 4px 16px 14px 16px; font-size: 14px; color: #d4d4de; border-top: 1px dashed var(--line); margin-top: 2px; }
.advice p { margin: 10px 0 6px; }
.advice ol { margin: 6px 0 0; padding-left: 20px; }
.advice li { margin: 4px 0; }
.advice-fix { margin-top: 12px; }
.chip.lvl-ok { background: rgba(43,182,115,.16); color: var(--ok); }
.chip.lvl-info { background: rgba(91,141,239,.16); color: var(--info); }
.chip.lvl-warn { background: rgba(245,166,35,.16); color: var(--warn); }
.chip.lvl-crit { background: rgba(229,72,77,.2); color: var(--crit); }

/* Comprobaciones con consejo */
.checks { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.checks li.check-ko { display: block; }
.checks li.check-ko details > summary { padding: 0; }
.checks li.check-ko details > summary .small { margin-left: auto; }
.checks li.check-ko .advice { border-top: 0; padding: 4px 0 6px 32px; }

/* Listas plegables */
.collapse > summary { color: #b892ff; font-size: 14px; padding: 4px 0; }
.collapse > summary::after { margin-left: 4px; }
.collapse[open] > summary { margin-bottom: 8px; }
.history .state { margin-right: 6px; }

/* Ventana de confirmación y avisos */
.modal { position: fixed; inset: 0; background: rgba(5,5,10,.7); backdrop-filter: blur(3px); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal[hidden] { display: none; }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 22px; max-width: 440px; width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,.5); animation: rise .2s ease-out both; }
.modal-box h3 { margin: 0 0 4px; font-size: 18px; }
.modal-box p { margin: 8px 0; }
.modal-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.toast { position: fixed; right: 20px; bottom: 20px; max-width: 420px; padding: 12px 16px; border-radius: 10px; font-size: 14px;
  z-index: 60; box-shadow: 0 10px 30px rgba(0,0,0,.45); animation: rise .25s ease-out both; }
.toast[hidden] { display: none; }
.toast-ok { background: #123524; border: 1px solid var(--ok); color: #c9f5dc; }
.toast-error { background: #3a1d20; border: 1px solid var(--crit); color: #ffd6d7; }
@media (prefers-reduced-motion: reduce) { .modal-box, .toast { animation: none; } .btn.is-busy::after { animation: none; } }

/* ===== Acceso (login en dos pasos) ===== */
.auth-bg { position: fixed; inset: 0; overflow: hidden; z-index: 0; pointer-events: none;
  background: radial-gradient(1200px 600px at 50% -10%, rgba(116,53,230,.18), transparent 60%); }
.auth-bg::after { content: ""; position: absolute; inset: 0; opacity: .35;
  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: 48px 48px; mask-image: radial-gradient(circle at 50% 40%, #000 0, transparent 70%); }
.auth-bg span { position: absolute; width: 520px; height: 520px; border-radius: 50%; filter: blur(90px); opacity: .28;
  background: var(--brand); animation: drift 18s ease-in-out infinite alternate; }
.auth-bg span:nth-child(1) { top: -160px; left: -120px; }
.auth-bg span:nth-child(2) { bottom: -220px; right: -140px; background: #22c1c3; opacity: .14; animation-duration: 22s; }
.auth-bg span:nth-child(3) { top: 40%; left: 55%; width: 300px; height: 300px; opacity: .14; animation-duration: 26s; }
@keyframes drift { to { transform: translate(60px, 40px) scale(1.15); } }

.auth { position: relative; z-index: 1; max-width: 380px; margin: 9vh auto 0; padding: 32px 28px 26px;
  background: rgba(21,21,28,.82); backdrop-filter: blur(14px); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: 0 30px 80px rgba(0,0,0,.45), 0 0 0 1px rgba(116,53,230,.06);
  animation: auth-in .8s cubic-bezier(.2,.8,.2,1) both; }
@keyframes auth-in { from { opacity: 0; transform: translateY(24px) scale(.97); filter: blur(6px); } to { opacity: 1; transform: none; filter: none; } }

.auth-brand { text-align: center; margin-bottom: 18px; }
.auth-brand h1 { margin: 16px 0 2px; letter-spacing: .24em; font-size: 20px; animation: rise .6s .35s both; }
.auth-brand p { margin: 0; font-size: 14px; animation: rise .6s .45s both; }
.auth-logo { position: relative; width: 64px; height: 64px; margin: 0 auto; }
.auth-logo > svg:first-child { width: 64px; height: 64px; overflow: visible; }
.auth-logo .bar-a { fill: #fff; transform-box: fill-box; transform-origin: bottom; animation: bar-up .55s .15s cubic-bezier(.2,.8,.2,1) both; }
.auth-logo .bar-b { fill: var(--brand); transform-box: fill-box; transform-origin: bottom; animation: bar-up .55s .27s cubic-bezier(.2,.8,.2,1) both; }
.auth-logo .dot { fill: var(--brand); transform-box: fill-box; transform-origin: center; animation: dot-pop .45s .5s cubic-bezier(.3,1.6,.5,1) both; }
@keyframes bar-up { from { transform: scaleY(0); opacity: 0; } to { transform: scaleY(1); opacity: 1; } }
@keyframes dot-pop { from { transform: scale(0); } to { transform: scale(1); } }
.auth-ring { position: absolute; inset: -10px; width: calc(100% + 20px); height: calc(100% + 20px); transform: rotate(-90deg); pointer-events: none; }
.auth-ring circle { fill: none; stroke: var(--ok); stroke-width: 3; stroke-linecap: round; stroke-dasharray: 352; stroke-dashoffset: 352; }

.auth-error { margin: 0 0 12px; padding: 9px 12px; border-radius: 10px; font-size: 13px; text-align: center;
  color: #ffb4b6; background: rgba(229,72,77,.12); border: 1px solid rgba(229,72,77,.35); animation: rise .3s both; }

.auth-stage { display: grid; grid-template-columns: minmax(0, 1fr); position: relative; transition: height .4s cubic-bezier(.2,.8,.2,1); }
.auth-pane { grid-area: 1 / 1; display: flex; flex-direction: column; gap: 14px;
  transition: transform .45s cubic-bezier(.2,.8,.2,1), opacity .35s ease, visibility 0s .45s; }
.auth-pane:not(.is-active) { opacity: 0; visibility: hidden; pointer-events: none; }
.pane-password:not(.is-active) { transform: translateX(-36px); }
.pane-code:not(.is-active) { transform: translateX(36px); }
.auth-pane.is-active { transition: transform .45s cubic-bezier(.2,.8,.2,1), opacity .35s .08s ease, visibility 0s; }
.auth-pane > label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.pane-password > label { animation: rise .5s .55s both; }
.pane-password > label + label { animation-delay: .62s; }
.pane-password .auth-btn { animation: rise .5s .7s both; }
.auth input { width: 100%; min-width: 0; background: var(--bg); border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 11px 12px; font-size: 15px;
  transition: border-color .15s, box-shadow .15s; }
.auth input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(116,53,230,.25); }
.auth input:disabled { opacity: .5; }

.pane-head { display: flex; gap: 12px; align-items: flex-start; }
.pane-head svg { width: 30px; height: 30px; flex: none; fill: none; stroke: var(--brand); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.pane-head strong { display: block; font-size: 15px; margin-bottom: 2px; }
.otp { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 26px !important; letter-spacing: .55em;
  text-align: center; padding: 12px 0 12px .55em !important; }
.otp::placeholder { color: var(--line); }

.auth-btn { position: relative; margin-top: 4px; background: var(--brand); color: #fff; border: 0; border-radius: 10px; padding: 12px;
  font-size: 15px; font-weight: 600; cursor: pointer; overflow: hidden; transition: filter .15s, transform .1s, background .3s; }
.auth-btn:hover { filter: brightness(1.12); }
.auth-btn:active { transform: scale(.98); }
.auth-btn:disabled { cursor: default; filter: saturate(.4) brightness(.8); }
.auth-btn.is-busy span { opacity: 0; }
.auth-btn.is-busy::after { content: ""; position: absolute; inset: 0; margin: auto; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.35); border-top-color: #fff; animation: spin .7s linear infinite; }
.auth-back { background: none; border: 0; color: var(--muted); font-size: 13px; cursor: pointer; padding: 4px; }
.auth-back:hover { color: var(--text); }
.auth-lock { text-align: center; margin: 14px 0 0; }
.auth-lock strong { color: var(--text); font-variant-numeric: tabular-nums; }

.auth.is-shaking { animation: shake .45s cubic-bezier(.36,.07,.19,.97) both; }
@keyframes shake { 10%, 90% { transform: translateX(-2px); } 20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); } 40%, 60% { transform: translateX(8px); } }

/* Éxito: el anillo se cierra alrededor del logo y la tarjeta se desvanece */
.auth.is-done .auth-ring circle { transition: stroke-dashoffset .7s cubic-bezier(.2,.8,.2,1); stroke-dashoffset: 0; }
.auth.is-done .auth-pane.is-active { opacity: 0; transform: scale(.96); transition: opacity .3s, transform .3s; }
.auth-ok { grid-area: 1 / 1; align-self: center; justify-self: center; text-align: center; opacity: 0; visibility: hidden; pointer-events: none; }
.auth-ok strong { display: block; font-size: 17px; color: var(--ok); margin-bottom: 4px; }
.auth.is-done .auth-ok { opacity: 1; visibility: visible; transform: none; animation: rise .45s .3s both; }
.auth.is-leaving { animation: auth-out .55s .1s cubic-bezier(.6,0,.4,1) both; }
@keyframes auth-out { to { opacity: 0; transform: scale(1.06); filter: blur(8px); } }

/* Bienvenida tras el login */
.welcome { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: var(--bg); pointer-events: none; animation: welcome-out .6s 1.3s cubic-bezier(.6,0,.4,1) forwards; }
.welcome img { animation: welcome-logo 1.2s cubic-bezier(.2,.8,.2,1) both; filter: drop-shadow(0 0 24px rgba(116,53,230,.6)); }
.welcome span { letter-spacing: .3em; text-transform: uppercase; font-size: 13px; color: var(--muted); animation: rise .6s .35s both; }
@keyframes welcome-logo { 0% { transform: scale(.6); opacity: 0; } 50% { transform: scale(1.08); opacity: 1; } 100% { transform: scale(1); } }
@keyframes welcome-out { to { opacity: 0; visibility: hidden; } }
.after-welcome .fade { animation-delay: 1.45s; }
.after-welcome .kpis .fade:nth-child(2), .after-welcome .cards .fade:nth-child(2) { animation-delay: 1.51s; }
.after-welcome .kpis .fade:nth-child(3), .after-welcome .cards .fade:nth-child(3) { animation-delay: 1.57s; }
.after-welcome .kpis .fade:nth-child(n+4), .after-welcome .cards .fade:nth-child(n+4) { animation-delay: 1.63s; }

@media (max-width: 480px) { .auth { margin: 4vh 12px 0; padding: 26px 20px 22px; } }
@media (prefers-reduced-motion: reduce) {
  .auth, .auth *, .auth-bg span, .welcome, .welcome * { animation: none !important; transition: none !important; }
  .welcome { display: none; }
}
