:root {
  --bg: #111418;
  --panel: #1b2027;
  --line: #2a313b;
  --text: #e9edf2;
  --muted: #8b95a3;
  --accent: #3b8bff;
  --talk: #e5484d;
  --rx: #30a46c;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { overscroll-behavior: none; }
.hidden { display: none !important; }
.screen { min-height: 100%; max-width: 480px; margin: 0 auto; padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 20px; }
.muted, .hint { color: var(--muted); }
.hint { font-size: 13px; margin: 0; }
.opt { color: #5c6673; font-size: 12px; }
.error { margin: 0; padding: 12px 14px; border-radius: 12px; background: #3b1517; border: 1px solid var(--talk); color: #ffb3b5; font-size: 14px; }
.ok-msg { margin: 0; padding: 12px 14px; border-radius: 12px; background: #11291c; border: 1px solid var(--rx); color: #9de0bd; font-size: 14px; }
.admin-link { color: var(--muted); font-size: 13px; text-align: center; margin-top: auto; padding-top: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.card h2 { margin: 0; font-size: 16px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > input { flex: 1; min-width: 0; }
.secondary { background: #2a313b; color: var(--text); border: 0; border-radius: 10px; padding: 12px 14px; font-weight: 600; }
.danger { background: none; border: 1px solid var(--talk); color: #ff8f93; border-radius: 8px; padding: 4px 10px; font-size: 13px; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; word-break: break-all; }
.chan { border-top: 1px solid var(--line); padding-top: 10px; }
.chan ul { list-style: none; padding: 0; margin: 6px 0 0; display: flex; flex-direction: column; gap: 6px; }
.chan li { display: flex; justify-content: space-between; align-items: center; }
.label { font-size: 11px; letter-spacing: .12em; color: var(--muted); font-weight: 600; }

/* Login */
.brand { text-align: center; margin-top: 8vh; }
.brand img { border-radius: 50%; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.brand h1 { margin: 12px 0 4px; font-size: 32px; letter-spacing: .02em; }
.brand p { margin: 0; }
form { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
input, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px; outline: none; }
input:focus, textarea:focus { border-color: var(--accent); }
button { font: inherit; cursor: pointer; }
.primary { background: var(--accent); color: #fff; border: 0; border-radius: 12px; padding: 15px; font-weight: 700; font-size: 17px; }
.ghost { background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 10px; padding: 8px 12px; }

/* Radio */
.topbar { display: flex; align-items: center; gap: 12px; }
.topbar > div:first-child { flex: 1; min-width: 0; }
.channel { font-size: 22px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conn { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #c99a2e; }
.dot.on { background: var(--rx); }
.dot.off { background: var(--talk); }

.display { background: #0b0e11; border: 1px solid var(--line); border-radius: 16px; padding: 18px; text-align: center;
  font-family: ui-monospace, "SF Mono", Menlo, monospace; transition: border-color .15s; }
.status-main { font-size: 24px; font-weight: 700; letter-spacing: .04em; }
.status-sub { color: var(--muted); font-size: 13px; margin-top: 4px; min-height: 1.4em; }
.display.tx { border-color: var(--talk); } .display.tx .status-main { color: var(--talk); }
.display.rx { border-color: var(--rx); } .display.rx .status-main { color: var(--rx); }
.display.busy .status-main { color: var(--accent); }

.ptt { align-self: center; width: min(64vw, 260px); aspect-ratio: 1; border-radius: 50%;
  border: 6px solid #2f3742; background: radial-gradient(circle at 50% 35%, #3a4350, #232a33);
  color: var(--text); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  font-weight: 700; font-size: 13px; letter-spacing: .08em; user-select: none; -webkit-user-select: none;
  touch-action: none; box-shadow: 0 10px 30px rgba(0,0,0,.45); transition: transform .08s, background .15s, border-color .15s; }
.ptt.active { transform: scale(.96); border-color: var(--talk); background: radial-gradient(circle at 50% 35%, #ff5c61, #b3262b); }
.ptt.waiting { border-color: var(--accent); }
.ptt.rx { border-color: var(--rx); }
.ptt:disabled { opacity: .45; }

.users ul { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.users li { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: 14px; }
.users li.me { border-color: var(--accent); }
.users li.speaking { border-color: var(--rx); color: var(--rx); }
.toggle { flex-direction: row; align-items: center; gap: 8px; font-size: 13px; margin-top: auto; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }
textarea { resize: vertical; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: -4px; }
.chips:empty { display: none; }
.chip { background: var(--panel); border: 1px solid var(--line); color: var(--text); border-radius: 999px; padding: 7px 12px; font-size: 14px; }
.chip.recent { border-style: dashed; color: var(--muted); }
.chip small { color: var(--muted); margin-left: 4px; }
.chip.sel { border-color: var(--accent); color: var(--accent); }

/* Panel: empresas */
.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: #2a313b; color: var(--text); white-space: nowrap; }
.pill.ok { background: #11291c; color: #9de0bd; }
.pill.warn { background: #3a2a10; color: #ffcf8a; }
.pill.bad { background: #3b1517; color: #ffb3b5; }
.tenant { border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.tenant.current { border-left: 3px solid var(--accent); padding-left: 10px; border-radius: 0; }
.tenant-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.tenant-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.tenant-actions button { padding: 7px 10px; font-size: 13px; border-radius: 8px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
select { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.stack { display: flex; flex-direction: column; gap: 14px; }

.legal-links { text-align: center; font-size: 13px; opacity: .7; margin-top: 8px; }
.legal-links a { color: inherit; }

/* ---------- Ondara: invitados, responsable, ubicación y SOS ---------- */
.invite-note.bad { background: rgba(229,72,77,.14); border-color: rgba(229,72,77,.5); }
.invite-note { background: rgba(255,138,31,.12); border: 1px solid rgba(255,138,31,.4); color: var(--text); border-radius: 12px; padding: 10px 12px; margin: 0; font-size: 14px; }
.lead-box { border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; }
.lead-box summary { cursor: pointer; color: var(--muted); font-size: 14px; }
.lead-box[open] summary { margin-bottom: 8px; }
.users li { display: inline-flex; align-items: center; gap: 6px; }
.users li .badge { font-size: 11px; background: var(--accent); color: #fff; border-radius: 999px; padding: 1px 7px; font-weight: 700; }
.users li .dist { color: var(--rx); font-size: 12px; font-weight: 600; }
.users li .dist.off { color: var(--muted); font-weight: 400; }
.users li.sos { border-color: #e5484d; background: rgba(229,72,77,.18); color: #ffb3b5; animation: sosPulse 1s infinite; }
@keyframes sosPulse { 50% { box-shadow: 0 0 0 4px rgba(229,72,77,.35); } }
.gps-box { border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; display: grid; gap: 6px; }
.gps-info { font-size: 14px; }
.ghost.small { padding: 6px 10px; font-size: 13px; justify-self: start; }
.sos-overlay { position: fixed; inset: 0; background: rgba(120,0,0,.88); display: grid; place-items: center; z-index: 50; padding: 20px; }
.sos-overlay.hidden { display: none; }
.sos-card { background: #1a0606; border: 2px solid #e5484d; border-radius: 18px; padding: 22px; width: min(420px, 100%); display: grid; gap: 12px; text-align: center; box-shadow: 0 0 40px rgba(229,72,77,.6); }
.sos-title { font-size: 34px; font-weight: 900; color: #ff4d52; letter-spacing: .06em; animation: sosBlink .8s infinite; }
@keyframes sosBlink { 50% { opacity: .45; } }
.sos-who { font-size: 20px; font-weight: 700; color: #fff; }
.sos-where { color: #ffcfd0; font-size: 15px; }
.sos-btn { display: block; background: #e5484d; color: #fff; text-decoration: none; font-weight: 800; padding: 16px; border-radius: 12px; font-size: 16px; }
.sos-btn.hidden { display: none; }
.app-banner { display: grid; gap: 6px; background: rgba(48,164,108,.12); border: 1px solid rgba(48,164,108,.5); border-radius: 12px; padding: 12px; font-size: 14px; }
.app-banner.hidden { display: none; }
.app-banner span { color: var(--muted); font-size: 13px; }
.app-btn { display: block; text-align: center; text-decoration: none; padding: 12px; border-radius: 10px; margin-top: 4px; }
.sos-web { display: grid; gap: 8px; border-top: 1px solid var(--line); padding-top: 10px; margin-top: 4px; }
.sos-web input[type=tel] { background: var(--panel); border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 10px 12px; font-size: 15px; }
.sos-alt { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sos-alt.hidden, #sosWa.hidden { display: none; }
.sos-btn2 { display: block; text-align: center; text-decoration: none; color: #fff; border: 1px solid #e5484d; border-radius: 12px; padding: 12px; font-weight: 700; }
#sosOwnCancel { color: #fff; border-color: #fff; padding: 14px; font-weight: 700; }

/* Invitado que ya tiene la app: botón grande arriba del todo; «Solicitar la app» queda en segundo plano */
.app-have { display: block; text-align: center; text-decoration: none; background: var(--accent); color: #fff; font-weight: 800; font-size: 18px; line-height: 1.3; padding: 16px 12px; border-radius: 12px; margin-bottom: 6px; box-shadow: 0 4px 18px rgba(59,139,255,.35); }
.app-have.hidden { display: none; }
.app-banner.has-app #appOpen { background: transparent; border: 1px solid var(--line); color: var(--muted); font-weight: 600; }
.voice-box .toggle { margin-top: 8px; }
.voice-box #repeatBtn { margin-top: 6px; }

/* Botón grande de SOS (cuando el SOS por voz está desactivado) */
.sos-big { display: grid; gap: 4px; width: 100%; margin: 14px 0 4px; padding: 20px 16px; border: 3px solid #ff8a8d; border-radius: 18px; background: linear-gradient(180deg, #e5484d, #b3161b); color: #fff; text-align: center; cursor: pointer; box-shadow: 0 6px 24px rgba(229,72,77,.45); animation: sosGlow 2s infinite; }
.sos-big.hidden { display: none; }
.sos-big:active { transform: scale(.98); }
.sos-big-t { font-size: 26px; font-weight: 900; letter-spacing: .05em; }
.sos-big-s { font-size: 13px; opacity: .9; }
@keyframes sosGlow { 50% { box-shadow: 0 6px 34px rgba(229,72,77,.8); } }

/* Panel: total de conectados en todos los grupos */
.grand-total { margin: 8px 0 12px; padding: 10px 14px; border-radius: 12px; background: rgba(46,204,113,.12); border: 1px solid rgba(46,204,113,.4); font-weight: 700; }

/* Panel: consumo por canal */
table.stats { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 14px; }
table.stats th, table.stats td { padding: 6px 4px; white-space: nowrap; border-bottom: 1px solid rgba(127,127,127,.25); text-align: right; }
table.stats th:first-child, table.stats td:first-child { text-align: left; }
table.stats tr.tot td { font-weight: 800; }
