:root {
  --bg: #f4f6f8; --card: #fff; --text: #1b1f24; --muted: #5b6570; --line: #d8dde3;
  --primary: #1f4e79; --ok: #1e7b3a; --warn: #b26a00; --bad: #b42318;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14181c; --card: #1d2329; --text: #e8ecef; --muted: #9aa5b0; --line: #2f3841; --primary: #6aa7e0; --ok: #4cc06d; --warn: #e6a23c; --bad: #f0645a; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 16px/1.4 system-ui, sans-serif; background: var(--bg); color: var(--text); }
header { display: flex; gap: 12px; align-items: center; padding: 10px 16px; background: var(--primary); color: #fff; flex-wrap: wrap; }
header #quien { flex: 1; opacity: .9; }
main { max-width: 1100px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }
section { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
h2 { margin: 0 0 12px; font-size: 1.1rem; }
input, select, button { font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--text); }
input { width: 100%; }
button { cursor: pointer; background: var(--primary); color: #fff; border: none; }
button.sec { background: transparent; color: var(--primary); border: 1px solid var(--primary); }
button.bad { background: var(--bad); }
button:disabled { opacity: .5; cursor: default; }
.fila { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.fila > input { flex: 1; min-width: 180px; }
.lista { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.lista li { display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; flex-wrap: wrap; }
.lista li.click { cursor: pointer; }
.lista li.click:hover { border-color: var(--primary); }
.muted { color: var(--muted); font-size: .9rem; }
.estado { font-size: .8rem; padding: 2px 8px; border-radius: 99px; background: var(--line); color: var(--text); white-space: nowrap; }
.estado.ok { background: var(--ok); color: #fff; } .estado.warn { background: var(--warn); color: #fff; } .estado.bad, .estado.off { background: var(--bad); color: #fff; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.chip { background: var(--primary); color: #fff; border-radius: 99px; padding: 4px 10px; display: inline-flex; gap: 6px; align-items: center; }
.chip button { padding: 0 4px; background: none; }
.aulas { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 6px; }
.aula { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: .9rem; display: flex; gap: 6px; align-items: center; }
.punto { width: 10px; height: 10px; border-radius: 50%; background: var(--bad); flex: none; }
.punto.on { background: var(--ok); }
.grande li { padding: 14px; font-size: 1.1rem; }
.error { color: var(--bad); min-height: 1.2em; margin: 6px 0 0; }
.codigo { font: 700 1.6rem ui-monospace, monospace; letter-spacing: 3px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs button.activa { background: var(--primary); color: #fff; }
.tabla-cont { overflow-x: auto; margin-top: 10px; }
.tabla { width: 100%; border-collapse: collapse; font-size: .95rem; }
.tabla th, .tabla td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tabla th { color: var(--muted); font-weight: 600; white-space: nowrap; }
.tabla tr.click { cursor: pointer; }
.tabla tr.click:hover td { background: color-mix(in srgb, var(--primary) 8%, transparent); }
.tabla tr.baja td { color: var(--muted); text-decoration: line-through; }
.tabla tr.incompleto td:first-child { border-left: 3px solid var(--warn); }
.dialogo { border: 1px solid var(--line); border-radius: 12px; padding: 20px; width: min(560px, calc(100vw - 32px)); background: var(--card); color: var(--text); }
.dialogo::backdrop { background: rgba(0, 0, 0, .45); }
.campo { display: grid; gap: 4px; margin-bottom: 10px; }
.campo > span { font-size: .85rem; color: var(--muted); }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; max-height: 180px; overflow-y: auto; }
.checks input, label > input[type=checkbox] { width: auto; }
.acciones { margin-top: 12px; }
.bloque { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 10px; display: grid; gap: 8px; }
.mapeo { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0 12px; }
details { margin: 8px 0; }
summary { cursor: pointer; font-weight: 600; }
select { max-width: 100%; }

.mudanza { background: #fff4d6; color: #1b1f24; border-color: #e6a23c; }
.boton-rojo { background: #c00; color: #fff; font-weight: 800; letter-spacing: 1px; padding: 10px 18px; border: 2px solid #800; }
button.blanco { background: #fff; color: #a00; border: none; font-weight: 700; }
button.sec.blanco { background: transparent; color: #fff; border: 1px solid #fff; }
.lista li.panico { background: #c00; color: #fff; border-color: #800; font-size: 1.1rem; }
.lista li.panico .muted { color: #fdd; }
.emergencia { position: fixed; inset: 0; z-index: 1000; background: #c00; color: #fff; display: grid; place-items: center; padding: 16px; animation: latido 1s infinite; }
.emergencia[hidden] { display: none; }
.emergencia-caja { max-width: 720px; text-align: center; display: grid; gap: 12px; }
.emergencia-titulo { font-size: clamp(2.2rem, 9vw, 5rem); font-weight: 900; line-height: 1.05; }
.emergencia-sub { font-size: 1.6rem; font-weight: 800; letter-spacing: 4px; }
.emergencia-mensaje { font-size: 1.5rem; font-weight: 700; }
@keyframes latido { 50% { background: #900; } }
.dialogo-emergencia { border: 4px solid #fff; border-radius: 14px; padding: 22px; width: min(620px, calc(100vw - 32px)); background: #c00; color: #fff; display: grid; gap: 12px; }
.dialogo-emergencia[open] { display: grid; }
.dialogo-emergencia::backdrop { background: rgba(80, 0, 0, .75); }
.dialogo-emergencia .error { color: #fff; font-weight: 700; }
.motivos { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.motivo { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.motivo input { width: auto; }
.activar { background: #fff; color: #c00; font-weight: 900; font-size: 1.15rem; padding: 14px; width: 100%; }

/* ---------- Tablero ---------- */
.plano { container-type: inline-size; display: grid; grid-template-columns: repeat(48, 1fr); grid-template-rows: repeat(27, 1fr);
  gap: .35cqw; width: 100%; aspect-ratio: 48 / 27; background: #fafafa; border-radius: 12px; padding: .4cqw; user-select: none; }
.plano .b { position: relative; border-radius: 1.2cqw; display: flex; flex-direction: column; justify-content: center; align-items: center;
  text-align: center; overflow: hidden; padding: .3cqw; font-weight: 700; line-height: 1.1; }
.plano .b-grande { font-size: 2.2cqw; }
.plano .b-medio { font-size: 1.3cqw; }
.plano .b-chico { font-size: .9cqw; opacity: .75; font-weight: 600; }
.plano .b-zona { font-size: 1.1cqw; text-transform: uppercase; }
.plano .b-insignia { position: absolute; left: 0; right: 0; bottom: 0; font-size: 1.05cqw; padding: .2cqw; background: rgba(0,0,0,.72); color: #fff; }
.plano .b.retiro { box-shadow: inset 0 0 0 .45cqw #e6a23c; }
.plano .b.asistencia { box-shadow: inset 0 0 0 .55cqw #ff7a00; animation: pulso 1.2s infinite; }
.plano .b.panico { background: #c00 !important; color: #fff !important; animation: latido 0.8s infinite; }
@keyframes pulso { 50% { box-shadow: inset 0 0 0 .15cqw #ff7a00; } }
.plano .b.con-mensajes { justify-content: flex-start; align-items: stretch; }
.plano .mensajes { width: 100%; height: 100%; display: flex; flex-direction: column; gap: .4cqw; padding: .4cqw .8cqw; text-align: left; color: #1b1f24; }
.plano .m-reloj { font-size: 2cqw; font-weight: 800; }
.plano .m-reloj span { font-size: 1.1cqw; font-weight: 600; opacity: .7; }
.plano .mensajes ul { list-style: none; margin: 0; padding: 0; display: grid; gap: .35cqw; }
.plano .mensajes li { font-size: 1.15cqw; font-weight: 700; background: #fff; border-radius: .7cqw; padding: .35cqw .6cqw; display: flex; justify-content: space-between; gap: .6cqw; }
.plano .mensajes li.m-panico { background: #c00; color: #fff; animation: latido 0.8s infinite; }
.plano .mensajes li.m-asistencia { background: #ffe1c2; }
.plano .mensajes li.m-retiro { background: #fff4d6; }
.plano .m-estado { white-space: nowrap; opacity: .85; }
.plano .m-vacio { font-size: 1.6cqw; opacity: .55; margin: auto; }
body.modo-tablero header { display: none; }
body.modo-tablero main { max-width: none; padding: 0; }
.tablero { width: min(100vw, calc(100vh * 48 / 27)); margin: 0 auto; }
.tablero .plano { border-radius: 0; }
.tablero-vacio { text-align: center; font-size: 1.4rem; }
.tablero-sonido { position: fixed; right: 12px; bottom: 12px; z-index: 50; }
.plano.editando .b { cursor: grab; touch-action: none; }
.plano.editando .b.seleccionado { outline: .3cqw solid #1f4e79; outline-offset: .1cqw; z-index: 2; }
.plano .b-manija { position: absolute; right: 0; bottom: 0; width: 1.4cqw; height: 1.4cqw; cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 50%, rgba(0,0,0,.55) 50%); }
.plano-editor { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 14px; align-items: start; margin-top: 10px; }
@media (max-width: 900px) { .plano-editor { grid-template-columns: 1fr; } }
.plano-lateral { display: grid; gap: 4px; }

.lista li.personal { background: #1f4e79; color: #fff; border-color: #163a5a; }
.lista li.personal .muted { color: #cfe0f0; }
.lista li.personal button { background: #fff; color: #1f4e79; }
