:root {
  --azul: #1345bb;
  --azul-oscuro: #0d3082;
  --azul-logo: #2e3192;
  --wa-verde: #008069;
  --wa-verde-claro: #00a884;
  --wa-fondo: #efeae2;
  --wa-saliente: #d9fdd3;
  --wa-entrante: #ffffff;
  --wa-texto: #111b21;
  --wa-gris: #667781;
  --wa-tilde: #53bdeb;
  --wa-barra: #f0f2f5;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--wa-texto);
  background: linear-gradient(135deg, var(--azul-oscuro) 0%, var(--azul) 55%, #4a78e0 100%);
  min-height: 100%;
}

.escenario {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 48px;
  padding: 24px;
}

/* ===== Panel lateral (escritorio) ===== */
.lateral {
  width: 340px;
  color: #fff;
}
.lateral-logo { width: 220px; background: #fff; border-radius: 10px; padding: 10px 14px; display: block; margin-bottom: 20px; }
.lateral h1 { font-size: 24px; font-weight: 600; margin: 0 0 10px; }
.lateral-intro { opacity: .92; margin: 0 0 18px; }
.lateral-estado { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0 0 18px; font-size: 14px; background: rgba(255,255,255,.1); border-radius: 10px; padding: 12px 14px; }
.lateral-estado dt { opacity: .8; }
.lateral-estado dd { margin: 0; font-weight: 500; }
.lateral-acciones { display: flex; gap: 10px; margin-bottom: 16px; }
.lateral button {
  background: #fff; color: var(--azul-oscuro); border: 0; border-radius: 8px; padding: 10px 14px; font: inherit; font-weight: 600; cursor: pointer;
}
.lateral button.secundario { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.6); }
.lateral-nota { font-size: 13px; opacity: .85; }
.lateral-nota em { font-style: normal; background: rgba(255,255,255,.14); padding: 1px 6px; border-radius: 4px; }

/* ===== Teléfono ===== */
.telefono {
  width: 390px;
  height: 780px;
  max-height: calc(100vh - 48px);
  background: #111;
  border-radius: 44px;
  padding: 12px;
  box-shadow: 0 30px 60px rgba(0,0,0,.45), inset 0 0 0 2px #333;
  flex: none;
}
.pantalla {
  height: 100%;
  border-radius: 34px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--wa-fondo);
  position: relative;
}

/* ===== Cabecera ===== */
.cabecera {
  background: var(--wa-verde);
  color: #fff;
  padding: 44px 8px 10px 4px;
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
  flex: none;
}
.cabecera-volver { background: none; border: 0; color: #fff; font-size: 30px; line-height: 1; padding: 0 6px; cursor: pointer; }
.cabecera-avatar { width: 40px; height: 40px; border-radius: 50%; background: #fff; object-fit: cover; object-position: 2% center; padding: 3px; flex: none; }
.cabecera-texto { flex: 1; min-width: 0; }
.cabecera-nombre { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cabecera-estado { font-size: 12.5px; opacity: .9; }
.cabecera-menu { background: none; border: 0; color: #fff; font-size: 24px; padding: 0 8px; cursor: pointer; }
.menu {
  position: absolute; right: 10px; top: 86px; background: #fff; color: var(--wa-texto);
  border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.25); z-index: 20; min-width: 190px; padding: 6px 0;
}
.menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 12px 18px; font: inherit; cursor: pointer; }
.menu button:hover { background: #f5f6f6; }

/* ===== Chat ===== */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 10px 10px 6px;
  background-color: var(--wa-fondo);
  background-image:
    radial-gradient(circle at 20% 30%, rgba(0,0,0,.025) 0 2px, transparent 3px),
    radial-gradient(circle at 70% 60%, rgba(0,0,0,.02) 0 3px, transparent 4px),
    radial-gradient(circle at 45% 85%, rgba(0,0,0,.02) 0 2px, transparent 3px);
  background-size: 90px 90px, 130px 130px, 70px 70px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.aviso-cifrado {
  align-self: center; background: #ffeecd; color: #54656f; font-size: 12.5px; border-radius: 8px;
  padding: 6px 12px; margin: 6px 0 10px; text-align: center; max-width: 92%;
}
.fecha {
  align-self: center; background: #fff; color: var(--wa-gris); font-size: 12.5px; border-radius: 8px; padding: 5px 12px; margin: 8px 0; box-shadow: 0 1px .5px rgba(0,0,0,.13);
}
.burbuja {
  max-width: 80%;
  padding: 6px 8px 8px 9px;
  border-radius: 8px;
  box-shadow: 0 1px .5px rgba(0,0,0,.13);
  position: relative;
  font-size: 14.5px;
  line-height: 1.35;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: aparecer .18s ease-out;
}
@keyframes aparecer { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.burbuja.entrante { align-self: flex-start; background: var(--wa-entrante); border-top-left-radius: 0; }
.burbuja.saliente { align-self: flex-end; background: var(--wa-saliente); border-top-right-radius: 0; }
.burbuja.entrante::before, .burbuja.saliente::before {
  content: ""; position: absolute; top: 0; width: 0; height: 0; border-style: solid;
}
.burbuja.entrante::before { left: -8px; border-width: 0 8px 10px 0; border-color: transparent var(--wa-entrante) transparent transparent; }
.burbuja.saliente::before { right: -8px; border-width: 0 0 10px 8px; border-color: transparent transparent transparent var(--wa-saliente); }
.burbuja .hora {
  float: right; margin: 6px -2px -4px 10px; font-size: 11px; color: var(--wa-gris); white-space: nowrap;
}
.burbuja .tildes { color: var(--wa-gris); margin-left: 3px; font-size: 12px; letter-spacing: -3px; }
.burbuja .tildes.leido { color: var(--wa-tilde); }
.burbuja.imagen { padding: 4px; }
.burbuja.imagen img { display: block; max-width: 100%; border-radius: 6px; image-rendering: pixelated; min-width: 180px; background: #fff; }
.burbuja.imagen .hora { position: absolute; right: 8px; bottom: 6px; margin: 0; color: #fff; text-shadow: 0 0 3px rgba(0,0,0,.7); }
.burbuja b { font-weight: 600; }
.burbuja code { font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.burbuja .seguida { }

.escribiendo {
  align-self: flex-start; background: var(--wa-entrante); border-radius: 8px; border-top-left-radius: 0;
  padding: 10px 14px; box-shadow: 0 1px .5px rgba(0,0,0,.13); display: inline-flex; gap: 4px;
}
.escribiendo i { width: 7px; height: 7px; border-radius: 50%; background: #9aa5ad; animation: puntos 1.2s infinite; }
.escribiendo i:nth-child(2) { animation-delay: .2s; }
.escribiendo i:nth-child(3) { animation-delay: .4s; }
@keyframes puntos { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }

/* ===== Entrada ===== */
.entrada { background: var(--wa-barra); padding: 6px 8px 22px; flex: none; }
.entrada form { display: flex; gap: 8px; align-items: center; }
.entrada input {
  flex: 1; border: 0; border-radius: 22px; padding: 11px 16px; font: inherit; font-size: 15px; background: #fff; outline: none; min-width: 0;
}
.entrada button {
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--wa-verde-claro); color: #fff; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.entrada button:disabled { opacity: .6; cursor: default; }

/* ===== Modal de inicio ===== */
.modal {
  position: fixed; inset: 0; background: rgba(13,48,130,.55); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 100;
}
.modal[hidden] { display: none; }
.modal-caja { background: #fff; border-radius: 14px; padding: 26px 24px; width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.modal-logo { width: 200px; display: block; margin: 0 auto 14px; }
.modal-caja h2 { margin: 0 0 8px; font-size: 20px; color: var(--azul-oscuro); }
.modal-caja p { margin: 0 0 14px; color: #444; font-size: 14px; }
.modal-caja label { display: block; font-size: 13px; color: #333; margin-bottom: 12px; }
.modal-caja input { display: block; width: 100%; margin-top: 4px; padding: 10px 12px; font: inherit; border: 1px solid #c9d0dc; border-radius: 8px; }
.modal-caja button { width: 100%; background: var(--azul); color: #fff; border: 0; border-radius: 8px; padding: 12px; font: inherit; font-weight: 600; cursor: pointer; }
.modal-error { color: #b3261e; font-size: 13px; }

/* ===== Móvil: el teléfono ocupa todo ===== */
@media (max-width: 820px) {
  body { background: var(--wa-fondo); }
  .escenario { padding: 0; gap: 0; min-height: 100dvh; }
  .lateral { display: none; }
  .telefono { width: 100%; height: 100dvh; max-height: none; border-radius: 0; padding: 0; box-shadow: none; background: transparent; }
  .pantalla { border-radius: 0; }
  .cabecera { padding-top: calc(10px + env(safe-area-inset-top)); }
  .menu { top: calc(60px + env(safe-area-inset-top)); }
  .entrada { padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
}
