:root {
  --bg: #0b1220; --card: #121b2d; --card2: #18243a; --line: #23324d; --txt: #e8eef7; --mu: #8b9bb3;
  --azul: #009fe3; --azul2: #0086c0; --ok: #22c55e; --warn: #f59e0b; --bad: #ef4444; --bad2: #b91c1c;
  --radio: 16px;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bot: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--txt); background: var(--bg);
  font-size: 16px; line-height: 1.4; min-height: 100vh;
}
[hidden] { display: none !important; }
.mu { color: var(--mu); }
.chico { font-size: .85rem; }
.vista { max-width: 520px; margin: 0 auto; padding: calc(12px + var(--safe-top)) 16px calc(24px + var(--safe-bot)); }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 14px;
  padding: 15px 16px; font: inherit; font-weight: 700; color: #fff; background: var(--card2); cursor: pointer;
  transition: transform .1s, opacity .2s; min-height: 52px;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn.primario { background: var(--azul); }
.btn.verde { background: #15803d; }
.btn.rojo { background: var(--bad2); }
.btn.texto { background: none; color: var(--azul); min-height: 0; padding: 10px; }
.btn.chico { padding: 8px 14px; min-height: 0; font-size: .9rem; }
.icono { background: none; border: 0; color: var(--txt); font-size: 1.6rem; width: 44px; height: 44px; border-radius: 12px; cursor: pointer; }

/* ---------- Ingreso ---------- */
.login { display: flex; flex-direction: column; justify-content: center; min-height: 100vh; }
.login-logo { width: 220px; max-width: 70%; margin: 0 auto 10px; display: block; }
.login-sub { text-align: center; color: var(--mu); margin-bottom: 18px; }
.tarjeta { background: var(--card); border: 1px solid var(--line); border-radius: var(--radio); padding: 16px; margin-bottom: 14px; }
.tarjeta h2 { font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; color: var(--mu); margin-bottom: 8px; font-weight: 700; }
label { display: block; font-size: .9rem; color: var(--mu); margin: 12px 0 6px; }
label:first-child { margin-top: 0; }
input {
  width: 100%; padding: 14px; border-radius: 12px; border: 1px solid var(--line); background: #0a1322;
  color: var(--txt); font: inherit;
}
input:focus { outline: 2px solid var(--azul); border-color: transparent; }
#fLogin .btn { width: 100%; margin-top: 18px; }
.error { color: #fca5a5; margin-top: 10px; min-height: 1.2em; font-size: .92rem; }

/* ---------- Barra ---------- */
.barra { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; position: relative; }
.barra-logo { width: 38px; height: 38px; flex: none; }
.barra-cuenta { flex: 1; min-width: 0; background: none; border: 0; color: inherit; text-align: left; font: inherit; cursor: pointer; }
.barra-cuenta b { display: block; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.barra-cuenta span { font-size: .8rem; }
.pill { font-size: .75rem; font-weight: 700; padding: 4px 10px; border-radius: 99px; background: var(--card2); color: var(--mu); white-space: nowrap; }
.pill.ok { background: rgba(34,197,94,.15); color: #86efac; }
.pill.bad { background: rgba(239,68,68,.15); color: #fca5a5; }
.pill.warn { background: rgba(245,158,11,.15); color: #fcd34d; }

.menu {
  position: absolute; z-index: 20; right: 16px; left: 16px; max-width: 488px; margin: 0 auto; top: calc(64px + var(--safe-top));
  background: var(--card2); border: 1px solid var(--line); border-radius: var(--radio); padding: 6px;
  box-shadow: 0 20px 40px rgba(0,0,0,.5);
}
.menu button { display: flex; width: 100%; text-align: left; background: none; border: 0; color: var(--txt); font: inherit; padding: 13px 12px; border-radius: 10px; cursor: pointer; gap: 10px; align-items: center; }
.menu button:hover, .menu button:focus-visible { background: rgba(255,255,255,.06); }
.menu button.actual { color: var(--azul); font-weight: 700; }
.menu button.peligro { color: #fca5a5; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }

/* ---------- Estado ---------- */
.estado {
  text-align: center; padding: 26px 16px 22px; border-radius: 22px; margin-bottom: 14px;
  background: linear-gradient(160deg, #10301f, #0d1f17); border: 1px solid rgba(34,197,94,.35);
  transition: background .3s, border-color .3s;
}
.estado-anillo {
  width: 92px; height: 92px; border-radius: 50%; margin: 0 auto 12px; display: grid; place-items: center; font-size: 2.6rem;
  background: rgba(34,197,94,.14); box-shadow: 0 0 0 8px rgba(34,197,94,.06);
}
.estado h1 { font-size: 1.6rem; letter-spacing: .02em; }
.estado p { margin-top: 4px; min-height: 1.3em; }
.estado.armada { background: linear-gradient(160deg, #3b0f14, #220a0d); border-color: rgba(239,68,68,.45); }
.estado.armada .estado-anillo { background: rgba(239,68,68,.16); box-shadow: 0 0 0 8px rgba(239,68,68,.07); }
.estado.tiempo { background: linear-gradient(160deg, #3a2a07, #221905); border-color: rgba(245,158,11,.5); }
.estado.tiempo .estado-anillo { background: rgba(245,158,11,.16); box-shadow: 0 0 0 8px rgba(245,158,11,.07); }
.estado.disparo { background: var(--bad2); border-color: #fca5a5; animation: latido 1s infinite; }
.estado.disparo .estado-anillo { background: rgba(255,255,255,.18); }
.estado.disparo p { color: #fee2e2; }
.estado.offline { background: var(--card); border-color: var(--line); }
.estado.offline .estado-anillo { background: rgba(139,155,179,.12); box-shadow: none; }
@keyframes latido { 50% { filter: brightness(1.25); } }

/* ---------- Acciones ---------- */
.acciones { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.acciones .ancho { grid-column: 1 / -1; }

.aviso {
  display: flex; gap: 12px; align-items: center; justify-content: space-between; background: rgba(0,159,227,.12);
  border: 1px solid rgba(0,159,227,.4); border-radius: var(--radio); padding: 12px 14px; margin-bottom: 14px; font-size: .92rem;
}

/* ---------- Zonas ---------- */
.zonas { list-style: none; }
.zonas li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.zonas li:last-child { border-bottom: 0; }
.zonas .num { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--card2); font-weight: 700; font-size: .9rem; flex: none; }
.zonas .nom { flex: 1; min-width: 0; }
.zonas .nom small { display: block; color: var(--mu); font-size: .78rem; }

/* ---------- Panico ---------- */
.panico-caja { text-align: center; margin: 22px 0; }
.panico {
  position: relative; width: 150px; height: 150px; border-radius: 50%; border: 0; cursor: pointer; margin-bottom: 10px;
  background: radial-gradient(circle at 35% 30%, #f87171, #b91c1c 70%); color: #fff; font-weight: 800; font-size: 1.15rem;
  letter-spacing: .06em; box-shadow: 0 10px 30px rgba(185,28,28,.45), inset 0 -6px 0 rgba(0,0,0,.15);
  user-select: none; -webkit-user-select: none; touch-action: none; -webkit-touch-callout: none;
}
.panico span { position: relative; z-index: 1; }
.panico svg { position: absolute; inset: -8px; width: calc(100% + 16px); height: calc(100% + 16px); transform: rotate(-90deg); }
.panico .pista { fill: none; stroke: rgba(239,68,68,.18); stroke-width: 5; }
.panico .progreso { fill: none; stroke: #fff; stroke-width: 5; stroke-linecap: round; stroke-dasharray: 339.3; stroke-dashoffset: 339.3; }
.panico.apretando { transform: scale(.96); }
.panico-caja p { max-width: 280px; margin: 0 auto; }

/* ---------- Eventos ---------- */
.eventos { list-style: none; }
.eventos li { display: flex; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); align-items: flex-start; }
.eventos li:last-child { border-bottom: 0; }
.eventos .ic { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--card2); flex: none; font-size: 1rem; }
.eventos .ic.rojo { background: rgba(239,68,68,.18); }
.eventos .ic.verde { background: rgba(34,197,94,.15); }
.eventos .ic.azul { background: rgba(0,159,227,.15); }
.eventos .tx { flex: 1; min-width: 0; font-size: .93rem; }
.eventos .tx small { display: block; color: var(--mu); font-size: .78rem; margin-top: 2px; }
.eventos .vacio { color: var(--mu); justify-content: center; }

.info { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.info span { display: block; font-size: .75rem; }
.info b { font-size: .95rem; }
.pie { text-align: center; font-size: .78rem; margin-top: 10px; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + var(--safe-bot)); transform: translateX(-50%) translateY(20px); opacity: 0;
  background: #1c2a42; border: 1px solid var(--line); color: var(--txt); padding: 13px 18px; border-radius: 12px;
  max-width: calc(100% - 32px); width: max-content; transition: all .25s; pointer-events: none; z-index: 50; text-align: center;
}
.toast.ver { opacity: 1; transform: translateX(-50%); }
.toast.error { background: #4c1414; border-color: #7f1d1d; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
