* { box-sizing: border-box; margin: 0; padding: 0; }
/* el atributo HTML hidden debe ganarle a cualquier display (flex/block) */
[hidden] { display: none !important; }
:root {
  --wa-bg: #efeae2;
  --wa-green: #075e54;
  --wa-teal: #128c7e;
  --wa-light-green: #25d366;
  --out-bubble: #d9fdd3;
  --in-bubble: #ffffff;
  --header: #075e54;
}
html, body { height: 100%; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #d2dbe0;
  display: flex; justify-content: center; align-items: center;
  min-height: 100vh; min-height: 100dvh; padding: 16px;
  overflow-x: hidden;
}
.phone {
  width: 100%; max-width: 460px; height: min(92vh, 860px);
  background: var(--wa-bg);
  border-radius: 14px; overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: 0 12px 40px rgba(0,0,0,.3);
  position: relative;
}
/* === MÓVIL: pantalla completa, sin marco === */
@media (max-width: 600px) {
  body { padding: 0; background: var(--wa-bg); }
  .phone {
    max-width: none; width: 100%;
    height: 100vh; height: 100dvh;   /* dvh: maneja la barra del navegador móvil */
    border-radius: 0; box-shadow: none;
  }
  /* respeta notch / safe areas (iPhone) */
  .chat-header { padding-top: calc(12px + env(safe-area-inset-top)); }
  .composer { padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  .recording-bar { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  /* burbujas un poco más anchas y toques cómodos en móvil */
  .msg { max-width: 85%; font-size: 15px; }
  .attach-sheet button { padding: 15px 22px; font-size: 16px; }
}
/* pantallas muy angostas (<=360px) */
@media (max-width: 360px) {
  .header-icons span:nth-child(-n+2) { display: none; }  /* oculta cámara/llamada, deja menú */
  .chat { padding: 10px 6px; }
}
/* header */
.chat-header {
  background: var(--header); color: #fff;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; flex-shrink: 0;
}
.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: #25d366; color: #06402b; font-weight: 700;
  display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.avatar { flex-shrink: 0; }
.peer { flex: 1; min-width: 0; }   /* min-width:0 permite truncar el nombre */
.peer-name { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.peer-status { font-size: 12px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-icons { flex-shrink: 0; white-space: nowrap; }
.header-icons span { margin-left: 14px; cursor: pointer; font-size: 18px; }
/* chat area */
.chat {
  flex: 1; overflow-y: auto; padding: 14px 10px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Cpath d='M0 0h40v40H0z' fill='%23efeae2'/%3E%3Ccircle cx='20' cy='20' r='1.2' fill='%23d9d2c9'/%3E%3C/svg%3E");
  display: flex; flex-direction: column; gap: 6px;
}
.day-sep { text-align: center; margin: 6px 0 10px; }
.day-sep span {
  background: #d6e8d4; color: #5b6b5a; font-size: 12px;
  padding: 5px 12px; border-radius: 8px; display: inline-block;
}
.msg {
  max-width: 80%; padding: 7px 10px 18px; border-radius: 8px;
  position: relative; font-size: 14.5px; line-height: 1.4;
  word-wrap: break-word; white-space: pre-wrap;
  box-shadow: 0 1px .5px rgba(0,0,0,.13);
}
.msg.out { background: var(--out-bubble); align-self: flex-end; border-top-right-radius: 2px; }
.msg.in  { background: var(--in-bubble);  align-self: flex-start; border-top-left-radius: 2px; }
.msg .time {
  position: absolute; right: 9px; bottom: 4px;
  font-size: 11px; color: #667781;
}
.msg.out .time .tick { color: #53bdeb; margin-left: 2px; }
.msg img.media { max-width: 100%; border-radius: 6px; display: block; margin-bottom: 4px; }
.msg video.media { max-width: 100%; border-radius: 6px; display: block; margin-bottom: 4px; }
.msg audio.media { width: 100%; max-width: 240px; margin-bottom: 4px; }
.msg .doc-card {
  display: flex; align-items: center; gap: 8px;
  background: rgba(0,0,0,.05); padding: 8px; border-radius: 6px; margin-bottom: 4px;
  text-decoration: none; color: inherit;
}
.msg .doc-card .doc-ico { font-size: 26px; }
.msg .meta-note { font-size: 12px; color: #667781; font-style: italic; margin-top: 2px; }
/* typing */
.typing { align-self: flex-start; background: #fff; padding: 12px 14px; border-radius: 8px; box-shadow: 0 1px .5px rgba(0,0,0,.13); }
.typing span { display: inline-block; width: 7px; height: 7px; margin: 0 1px; background: #9aa6ac; border-radius: 50%; animation: blink 1.2s infinite both; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100% { opacity: .3; } 40% { opacity: 1; } }
/* composer */
.composer {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 10px; background: #f0f0f0; flex-shrink: 0;
}
.composer #textInput {
  flex: 1; border: none; border-radius: 22px; padding: 11px 16px;
  font-size: 16px; outline: none; background: #fff;   /* 16px evita el zoom automático en iOS */
  min-width: 0;
}
.icon-btn, .send-btn {
  border: none; cursor: pointer; font-size: 20px;
  width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: transparent; color: #54656f;
}
.send-btn { background: var(--wa-teal); color: #fff; }
.icon-btn:active { background: #e2e2e2; }
/* recording bar */
.recording-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; background: #f0f0f0; flex-shrink: 0;
}
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: #f00; animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }
.rec-label { flex: 1; color: #54656f; font-size: 14px; }
.rec-cancel, .rec-stop { border: none; cursor: pointer; font-size: 18px; width: 42px; height: 42px; border-radius: 50%; }
.rec-cancel { background: transparent; color: #d33; }
.rec-stop { background: var(--wa-teal); color: #fff; }
/* attach sheet */
.attach-sheet {
  position: absolute; bottom: 70px; left: 14px; z-index: 20;
  background: #fff; border-radius: 12px; overflow: hidden;
  box-shadow: 0 6px 24px rgba(0,0,0,.25); display: flex; flex-direction: column;
}
.attach-sheet button {
  border: none; background: #fff; text-align: left;
  padding: 13px 20px; font-size: 15px; cursor: pointer; white-space: nowrap;
}
.attach-sheet button:hover { background: #f2f2f2; }
.error-bubble { align-self: center; background: #fde2e1; color: #a33; font-size: 13px; padding: 8px 12px; border-radius: 8px; }
