:root {
  --pared: #5d6366;
  --metal: #d3d6d9;
  --metal-oscuro: #9da2a7;
  --grabado: #2a2e32;
  --luz: #f4b63f;
  --verde: #2f9d5c;
  --rojo: #c9432f;
  --noche: #1d2124;
  --texto-claro: #eef0f1;
  --fuente: "Barlow", "Helvetica Neue", Arial, sans-serif;
  --fuente-placa: "Barlow Condensed", "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  font-family: var(--fuente);
  font-size: 17px;
  line-height: 1.45;
  color: var(--grabado);
  background: radial-gradient(120% 70% at 50% 0%, #6f7579 0%, var(--pared) 60%, #4c5154 100%);
  min-height: 100vh;
  min-height: 100dvh; /* en iPhone, 100vh queda tapado por la barra de Safari */
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: max(20px, env(safe-area-inset-top)) 14px max(24px, env(safe-area-inset-bottom));
}

[hidden] { display: none !important; }

button, input, textarea { font: inherit; }

:focus-visible { outline: 3px solid var(--luz); outline-offset: 3px; }

/* ── La placa del portero ─────────────────────────────── */

.placa {
  position: relative;
  width: 100%;
  max-width: 400px;
  padding: 26px 22px 24px;
  border-radius: 14px;
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,.07) 0 1px, rgba(0,0,0,.035) 1px 3px),
    linear-gradient(180deg, #e2e5e7 0%, var(--metal) 45%, #c2c6ca 100%);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,.9),
    inset 0 -2px 0 rgba(0,0,0,.18),
    0 18px 40px rgba(0,0,0,.35),
    0 2px 4px rgba(0,0,0,.3);
}

/* tornillos */
.placa::before, .placa::after {
  content: "";
  position: absolute;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #f3f4f5, #8d9297 70%);
  box-shadow: 0 1px 0 rgba(255,255,255,.7), inset 0 0 0 1px rgba(0,0,0,.2);
  top: 10px; left: 10px;
}
.placa::after { left: auto; right: 10px; }

.parlante {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin-bottom: 18px;
}
.rejilla {
  width: 132px; height: 46px;
  border-radius: 8px;
  background-image: radial-gradient(circle, #3b4044 2.2px, transparent 2.6px);
  background-size: 11px 11px;
  background-position: center;
  box-shadow: inset 0 1px 2px rgba(0,0,0,.25), 0 1px 0 rgba(255,255,255,.7);
}
.lente {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 35%, #5a7186 0 2px, #14181b 4px, #24292d 9px, #6d7378 11px);
  box-shadow: 0 1px 0 rgba(255,255,255,.7);
}

.edificio {
  font-family: var(--fuente-placa);
  font-weight: 600;
  font-size: 30px;
  line-height: 1.05;
  letter-spacing: .01em;
  text-align: center;
  margin: 0;
  color: var(--grabado);
  text-shadow: 0 1px 0 rgba(255,255,255,.75);
}
.direccion {
  text-align: center;
  margin: 4px 0 18px;
  font-size: 15px;
  color: #4a5055;
  text-shadow: 0 1px 0 rgba(255,255,255,.6);
}

.campo-nombre {
  display: block;
  margin-bottom: 18px;
}
.campo-nombre span {
  display: block;
  font-size: 14px;
  margin-bottom: 5px;
  color: #3d4247;
}
.campo-nombre input, .mensaje textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid #8f959a;
  border-radius: 8px;
  background: #f4f5f6;
  color: var(--grabado);
  box-shadow: inset 0 2px 3px rgba(0,0,0,.12);
}

/* ── Botonera ─────────────────────────────── */

.botonera { display: flex; flex-direction: column; gap: 10px; }

.piso {
  display: grid;
  grid-template-columns: 42px 1fr;
  align-items: center;
  gap: 10px;
}
.piso-nombre {
  font-family: var(--fuente-placa);
  font-weight: 600;
  font-size: 20px;
  text-align: right;
  color: #3a3f44;
  text-shadow: 0 1px 0 rgba(255,255,255,.7);
}
.piso-botones {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(48px, 1fr));
  gap: 10px;
}

.timbre {
  position: relative;
  height: 62px;
  border: 1px solid #7f858a;
  border-radius: 9px;
  background: linear-gradient(180deg, #eef0f1 0%, #c7cbcf 100%);
  box-shadow: 0 4px 0 #7b8186, 0 5px 8px rgba(0,0,0,.25), inset 0 1px 0 #fff;
  cursor: pointer;
  padding: 7px;
  transition: transform .06s, box-shadow .06s;
  -webkit-tap-highlight-color: transparent;
}
.timbre:active, .timbre.presionado {
  transform: translateY(4px);
  box-shadow: 0 0 0 #7b8186, 0 1px 3px rgba(0,0,0,.3), inset 0 1px 0 #fff;
}
.timbre .visor {
  display: flex;
  height: 100%;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  background: linear-gradient(180deg, #2b3035, #1c2023);
  color: #fdf3dc;
  font-family: var(--fuente-placa);
  font-weight: 600;
  font-size: 24px;
  box-shadow: inset 0 1px 3px rgba(0,0,0,.6);
  transition: background .2s, color .2s, box-shadow .2s;
}
.timbre.presionado .visor {
  background: var(--luz);
  color: #3a2706;
  box-shadow: 0 0 14px rgba(244,182,63,.85), inset 0 0 6px rgba(255,255,255,.5);
}
.timbre:disabled { cursor: not-allowed; opacity: .55; }

.ayuda {
  margin: 20px 0 0;
  text-align: center;
  font-size: 15px;
  color: #3d4247;
}

/* ── Pantallas del visitante ─────────────────────────── */

.estado {
  text-align: center;
}
.lampara {
  width: 18px; height: 18px;
  margin: 4px auto 14px;
  border-radius: 50%;
  background: #6f6650;
  box-shadow: inset 0 1px 2px rgba(0,0,0,.5);
}
.lampara.encendida {
  background: var(--luz);
  box-shadow: 0 0 16px 4px rgba(244,182,63,.7);
  animation: latido 1.2s ease-in-out infinite;
}
.lampara.conectada {
  background: #57d38a;
  box-shadow: 0 0 16px 4px rgba(87,211,138,.6);
}
@keyframes latido { 50% { opacity: .35; box-shadow: none; } }

.destino {
  font-family: var(--fuente-placa);
  font-weight: 600;
  font-size: 46px;
  line-height: 1;
  margin: 0;
  text-shadow: 0 1px 0 rgba(255,255,255,.75);
}
.estado p { margin: 8px 0 0; }
.cuenta { font-variant-numeric: tabular-nums; color: #4a5055; font-size: 15px; }

.vista-previa {
  display: block;
  width: 120px;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  margin: 16px auto 0;
  border-radius: 10px;
  background: #1c2023;
  transform: scaleX(-1);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.4), 0 2px 6px rgba(0,0,0,.25);
}

.log {
  list-style: none;
  padding: 0;
  margin: 16px 0 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.log li {
  align-self: flex-start;
  max-width: 90%;
  padding: 9px 13px;
  border-radius: 12px 12px 12px 3px;
  background: var(--noche);
  color: var(--texto-claro);
  text-align: left;
}

.acciones { display: flex; gap: 10px; margin-top: 20px; }
.btn {
  flex: 1;
  min-height: 50px;
  border: 0;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  padding: 10px 16px;
}
.btn-rojo { background: var(--rojo); color: #fff; }
.btn-verde { background: var(--verde); color: #fff; }
.btn-gris { background: #4a5055; color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-audio { width: 100%; margin-top: 16px; animation: latido 1.2s ease-in-out infinite; }

.mensaje { margin-top: 16px; text-align: left; }
.mensaje textarea { min-height: 96px; resize: vertical; }

.aviso-error {
  text-align: center;
  padding: 10px 0;
}
.aviso-error p { margin: 0; }

/* ── Pantalla del residente ─────────────────────────── */

body.residente {
  background: var(--noche);
  color: var(--texto-claro);
  padding: 0;
}
.llamada {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: max(22px, env(safe-area-inset-top)) 18px max(22px, env(safe-area-inset-bottom));
}
.llamada-cabecera { text-align: center; }
.llamada-cabecera .depto {
  font-family: var(--fuente-placa);
  font-weight: 600;
  font-size: 20px;
  color: var(--luz);
  margin: 0;
}
.llamada-cabecera h1 {
  font-size: 28px;
  line-height: 1.15;
  margin: 6px 0 4px;
  font-weight: 600;
}
.llamada-cabecera .estado-texto { margin: 0; color: #aab1b6; font-size: 15px; }
/* Llamada terminada: solo el mensaje, centrado */
body.terminada .video-visita,
body.terminada .respuestas,
body.terminada .escribir,
body.terminada .botones-llamada,
body.terminada .estado-texto:empty { display: none !important; }
body.terminada .llamada { justify-content: center; }
body.terminada .llamada-cabecera h1 { color: #aab1b6; }

.video-visita {
  position: relative;
  flex: 1;
  min-height: 260px;
  margin: 18px 0;
  border-radius: 16px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 40%, #2c3337 0%, #15181a 75%);
  display: flex;
  align-items: center;
  justify-content: center;
}
.video-visita video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
/* El video no se oculta con display:none porque en iPhone eso puede silenciar el audio */
.video-visita video.sin-imagen { opacity: 0; }
.video-visita .btn-audio {
  position: absolute;
  left: 50%; bottom: 16px;
  transform: translateX(-50%);
  width: auto;
  margin: 0;
  z-index: 1;
}
.video-visita .sin-video {
  color: #8a9298;
  text-align: center;
  padding: 20px;
  font-size: 15px;
}

.respuestas {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.respuestas button {
  border: 1px solid #485056;
  background: #262b2f;
  color: var(--texto-claro);
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 15px;
  cursor: pointer;
}
.respuestas button:active { background: #353c41; }

.escribir { display: flex; gap: 8px; margin-bottom: 18px; }
.escribir input {
  flex: 1;
  min-width: 0;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid #485056;
  background: #262b2f;
  color: var(--texto-claro);
}
.escribir button {
  border: 0;
  border-radius: 10px;
  padding: 0 16px;
  background: var(--luz);
  color: #3a2706;
  font-weight: 600;
  cursor: pointer;
}

.botones-llamada {
  display: flex;
  justify-content: center;
  gap: 34px;
}
.redondo {
  width: 72px; height: 72px;
  border-radius: 50%;
  border: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}
.redondo svg { width: 30px; height: 30px; }
.redondo.verde { background: var(--verde); }
.redondo.rojo { background: var(--rojo); }
.redondo.gris { background: #3b4246; }
.redondo.gris[aria-pressed="true"] { background: var(--texto-claro); color: var(--noche); }
.etiqueta-boton {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: #c4cacd;
}

/* ── Administración ─────────────────────────── */

.placa-admin { max-width: 560px; }
.admin-titulo {
  font-family: var(--fuente-placa);
  font-weight: 600;
  font-size: 22px;
  margin: 26px 0 8px;
  text-shadow: 0 1px 0 rgba(255,255,255,.7);
}
.admin-checks { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.admin-checks li {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(255,255,255,.4);
  box-shadow: inset 0 1px 2px rgba(0,0,0,.15);
  font-size: 15px;
  overflow-wrap: anywhere;
}
.admin-nota { font-size: 15px; color: #3d4247; margin: 10px 0; }
.admin-error { color: #8f2a1c; font-weight: 600; margin: 12px 0 0; text-align: center; }
.admin-alerta {
  margin: 0 0 8px; padding: 10px 12px; border-radius: 8px;
  background: #fbe3c0; color: #5a3a07; font-size: 15px; overflow-wrap: anywhere;
}
.admin-depto {
  padding: 12px;
  margin-bottom: 10px;
  border: 1px solid #9da2a7;
  border-radius: 10px;
  background: rgba(255,255,255,.35);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.8);
}
.admin-depto-cab { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.admin-depto-cab strong { font-family: var(--fuente-placa); font-size: 22px; }
.admin-etiqueta { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: #4a5055; color: #fff; }
.admin-conectados { margin: 4px 0 10px; font-size: 15px; color: #3d4247; overflow-wrap: anywhere; }
.admin-botones { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-chico {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 40px;
  padding: 6px 12px;
  border: 1px solid #7f858a;
  border-radius: 8px;
  background: linear-gradient(180deg, #eef0f1 0%, #c7cbcf 100%);
  box-shadow: 0 2px 0 #7b8186, inset 0 1px 0 #fff;
  color: var(--grabado);
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn-chico:active { transform: translateY(2px); box-shadow: inset 0 1px 0 #fff; }
.btn-chico.rojo { color: #8f2a1c; }
.btn-chico:disabled, .btn-chico.deshabilitado { opacity: .5; cursor: not-allowed; pointer-events: none; }

/* ── Cartel imprimible ─────────────────────────── */

body.cartel-body { align-items: center; }
.cartel {
  width: 100%;
  max-width: 480px;
  background: #fff;
  color: #1d2124;
  border-radius: 14px;
  padding: 34px 30px;
  text-align: center;
  box-shadow: 0 18px 40px rgba(0,0,0,.35);
}
.cartel h1 {
  font-family: var(--fuente-placa);
  font-weight: 600;
  font-size: 40px;
  line-height: 1.05;
  margin: 0;
}
.cartel .sub { margin: 6px 0 22px; color: #555c61; }
.cartel .qr { display: inline-block; padding: 14px; border: 3px solid #1d2124; border-radius: 14px; }
.cartel .qr img, .cartel .qr canvas { display: block; width: 260px; height: 260px; }
.cartel .instruccion {
  font-family: var(--fuente-placa);
  font-weight: 600;
  font-size: 28px;
  line-height: 1.1;
  margin: 22px 0 6px;
}
.cartel .detalle { margin: 0; color: #555c61; font-size: 16px; }
.cartel-form { display: flex; gap: 8px; margin-top: 8px; }
.cartel-form input {
  flex: 1; min-width: 0; padding: 11px 12px; border-radius: 8px; border: 1px solid #a3a9ad;
}
.cartel-error { color: var(--rojo); margin: 10px 0 0; }

@media print {
  body { background: #fff; padding: 0; }
  .cartel { box-shadow: none; max-width: none; }
  .no-imprimir { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  .lampara.encendida { animation: none; }
  .timbre { transition: none; }
}

.sr {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
