:root {
  --bg: #14161a;
  --surface: #1d2026;
  --surface-2: #262a32;
  --line: #333844;
  --text: #f2f3f5;
  --muted: #9aa1ad;
  --red: #e5322d;
  --red-deep: #a81d19;
  --red-soft: rgba(229, 50, 45, .14);
  --amber: #f2a93b;
  --green: #35b26b;
  --green-soft: rgba(53, 178, 107, .14);
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  padding-bottom: calc(72px + var(--safe-b));
}
a { color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

/* Barra superior */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: rgba(20, 22, 26, .92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .01em; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--red); box-shadow: 0 0 0 4px var(--red-soft); }
.top-actions { display: flex; align-items: center; gap: 10px; }
.reload {
  display: grid; place-items: center; width: 44px; height: 44px; padding: 0; cursor: pointer;
  color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: 50%;
}
.reload svg { width: 24px; height: 24px; fill: currentColor; }
.reload.spinning svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.call911 {
  text-decoration: none; font-weight: 800; letter-spacing: .04em;
  padding: 6px 14px; border-radius: 999px; border: 2px solid var(--red); color: #fff;
}

main { padding: 16px; max-width: 560px; margin: 0 auto; }

/* Navegación inferior */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 6px 8px calc(6px + var(--safe-b));
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabs a {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0; font-size: .75rem; text-decoration: none; color: var(--muted);
}
.tabs a.active { color: var(--text); }
.tabs svg { width: 24px; height: 24px; fill: currentColor; }
.badge {
  position: absolute; top: 2px; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--red); color: #fff; font-size: .7rem; font-weight: 700; line-height: 18px; text-align: center;
}

/* Tarjetas y formularios */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.card.warn { border-color: var(--amber); background: rgba(242, 169, 59, .08); }
.card.danger { border-color: var(--red); background: var(--red-soft); }
.card.ok { border-color: var(--green); background: var(--green-soft); }
label { display: block; font-size: .875rem; color: var(--muted); margin: 12px 0 4px; }
input, textarea, select {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px;
}
input:focus, textarea:focus { outline: 2px solid var(--red); outline-offset: 1px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 48px; padding: 10px 16px; margin-top: 12px;
  font: inherit; font-weight: 650; color: var(--text); text-decoration: none;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; cursor: pointer;
}
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.green { background: var(--green); border-color: var(--green); color: #fff; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 12px; margin-bottom: 12px; }
.seg button { font: inherit; padding: 10px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); font-weight: 650; }

/* Tipos de alerta: cuadrícula de 3 × 2, todos visibles sin desplazarse */
.types-title { font-size: 1rem; text-align: center; margin: 14px 0 8px; }
.types { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.type {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 76px; padding: 8px 4px; cursor: pointer;
  font: inherit; font-size: .82rem; line-height: 1.15; text-align: center; color: var(--text);
  background: var(--surface-2); border: 2px solid var(--line); border-radius: 12px;
}
.type .ico { font-size: 1.6rem; line-height: 1; }
.type:last-child:nth-child(3n+1) { grid-column: 1 / -1; min-height: 56px; flex-direction: row; gap: 8px; } /* si sobra uno (Otra), ocupa la fila entera */
.type.on { background: var(--red-soft); border-color: var(--red); font-weight: 700; box-shadow: 0 0 0 1px var(--red); }
.subtype { margin-top: 10px; }
.subtype[hidden] { display: none; }
.subtype label { margin: 0 0 4px; color: var(--text); font-weight: 650; }
.subtype select { border: 2px solid var(--red); appearance: auto; }
.where { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.where label { margin: 0; flex: none; }
.where input { padding: 9px 12px; }

/* Botón de pánico */
.panic-card { padding: 4px 0 8px; }
.panic-wrap { display: grid; place-items: center; padding: 18px 0 6px; }
.panic {
  position: relative; width: min(58vw, 220px); aspect-ratio: 1; border-radius: 50%;
  border: 0; padding: 0; cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none;
  background: radial-gradient(circle at 50% 35%, #ff5a52, var(--red) 55%, var(--red-deep));
  box-shadow: 0 0 0 10px var(--red-soft), 0 12px 40px rgba(229, 50, 45, .35);
  color: #fff; font: inherit;
}
.panic svg.ring { position: absolute; inset: -10px; width: calc(100% + 20px); height: calc(100% + 20px); transform: rotate(-90deg); pointer-events: none; }
.panic svg.ring circle { fill: none; stroke: #fff; stroke-width: 1.6; stroke-linecap: round; stroke-dasharray: 100; stroke-dashoffset: 100; opacity: 0; }
.panic.holding svg.ring circle { opacity: 1; }
.panic .label { display: flex; flex-direction: column; align-items: center; gap: 4px; pointer-events: none; }
.panic .big { font-size: 1.6rem; font-weight: 850; letter-spacing: .06em; }
.panic .hint { font-size: .8rem; opacity: .9; }
.panic.holding { transform: scale(.97); }
.panic.sent { background: radial-gradient(circle at 50% 35%, #5fd394, var(--green) 60%, #1f7a47); box-shadow: 0 0 0 10px var(--green-soft); }

/* Volver: en la barra superior fija, siempre visible al desplazarse */
.top-back {
  display: inline-flex; align-items: center; gap: 4px; min-height: 44px; padding: 8px 18px 8px 10px;
  font-size: 1.05rem; font-weight: 700; text-decoration: none; color: var(--bg);
  background: var(--text); border-radius: 999px;
}
.top-back svg { width: 24px; height: 24px; fill: currentColor; }
.top-back[hidden], .brand[hidden] { display: none; }

/* Aviso de no llamar a la víctima */
.no-call { margin: 12px 0 0; padding: 10px 12px; border-radius: 10px; background: rgba(242, 169, 59, .12); border: 1px solid var(--amber); font-size: .9rem; }

.sent-ok { margin: 10px 0 0; padding: 10px 12px; border-radius: 10px; font-weight: 650; color: #fff; background: var(--green); }
.sent-error { margin: 10px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--red-soft); border: 1px solid var(--red); }
.sent-error[hidden] { display: none; }

.evidence { margin: 10px 0 0; padding: 10px 12px; border-radius: 10px; font-size: .9rem; background: var(--surface-2); border: 1px solid var(--line); }

/* Alertas cerradas */
.closed-banner {
  display: flex; align-items: center; gap: 14px; padding: 16px; margin-bottom: 12px;
  border-radius: var(--radius); border: 2px solid;
}
.closed-banner b { font-size: 1.25rem; display: block; margin-bottom: 2px; }
.closed-banner .ico {
  flex: none; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%;
  font-size: 1.4rem; font-weight: 800; color: #fff;
}
.closed-banner.resolved { border-color: var(--green); background: var(--green-soft); }
.closed-banner.resolved .ico { background: var(--green); }
.closed-banner.false_alarm { border-color: var(--muted); background: var(--surface-2); }
.closed-banner.false_alarm .ico { background: var(--muted); color: var(--bg); }
.card.closed { opacity: .85; }
.alert-item.closed { border-left: 4px solid var(--muted); }
.alert-item.closed.resolved { border-left-color: var(--green); }

/* Alertas */
.alert-item { display: block; text-decoration: none; }
.alert-item .top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.pill { flex: none; align-self: flex-start; line-height: 1.5; font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.pill.active { background: var(--red); color: #fff; }
.pill.resolved { background: var(--green); color: #fff; }
.pill.false_alarm { background: var(--surface-2); color: var(--muted); }
.pill.pending { background: rgba(242, 169, 59, .15); color: var(--amber); }
.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px var(--red-soft); } }
.notes { list-style: none; padding: 0; margin: 4px 0 12px; border-left: 3px solid var(--amber); }
.notes li { display: flex; gap: 10px; padding: 4px 0 4px 10px; }
.notes li:last-child span { font-weight: 650; } /* el más reciente */
.notes time, .responses time { flex: none; color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.responses { list-style: none; padding: 0; margin: 8px 0 0; }
.responses li { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); font-size: .9rem; }
.resp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.resp-grid .btn { margin-top: 0; font-size: .9rem; }
.resp-grid .btn.on { outline: 2px solid var(--green); }
.counts { display: flex; gap: 16px; flex-wrap: wrap; margin: 8px 0; font-size: .9rem; }
.counts b { font-size: 1.2rem; }

.member { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.member:first-of-type { border-top: 0; }
.member .actions { display: flex; gap: 6px; }
.member .actions .btn { width: auto; min-height: 36px; margin: 0; padding: 6px 10px; font-size: .85rem; }

ol.steps { padding-left: 1.2em; margin: 0; }
ol.steps li { margin-bottom: 6px; }

#toast {
  position: fixed; left: 50%; bottom: calc(84px + var(--safe-b)); transform: translateX(-50%) translateY(20px);
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px;
  background: #000; color: #fff; border: 1px solid var(--line); opacity: 0; pointer-events: none; transition: .2s;
  z-index: 20; font-size: .9rem;
}
#toast.show { opacity: 1; transform: translateX(-50%); }

@media (prefers-reduced-motion: reduce) { .pulse, .reload.spinning svg { animation: none; } .reload.spinning { opacity: .6; } }
.tabs[hidden] { display: none; }
.member { flex-wrap: wrap; }
.member > div:first-child { flex: 1 1 180px; min-width: 0; }
.member .actions { flex-wrap: wrap; }
.member .actions .btn { white-space: nowrap; }

/* Códigos de ingreso */
.code-input { font-size: 1.6rem; text-align: center; letter-spacing: .2em; font-variant-numeric: tabular-nums; }
.code-big { margin: 8px 0; font-size: 2.6rem; font-weight: 850; text-align: center; letter-spacing: .15em; font-variant-numeric: tabular-nums; }
.sent-ok[hidden] { display: none; }
