:root {
  --verde: #008069;
  --verde-boton: #00a884;
  --fondo: #efeae2;
  --saliente: #d9fdd3;
  --entrante: #ffffff;
  --texto: #111b21;
  --gris: #667781;
  --azul-tilde: #53bdeb;
  --sombra: 0 1px 0.5px rgba(11, 20, 26, .13);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #d1d7db; color: var(--texto); }
button { font: inherit; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

.app {
  display: flex; flex-direction: column;
  height: 100dvh; max-width: 520px; margin: 0 auto;
  background-color: var(--fondo);
  /* trama sutil tipo WhatsApp, sin imágenes */
  background-image: radial-gradient(rgba(0,0,0,.035) 1.2px, transparent 1.3px);
  background-size: 18px 18px;
  box-shadow: 0 0 24px rgba(0,0,0,.12);
}

.cabecera {
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 8px 10px 14px;
  background: var(--verde); color: #fff;
}
.avatar { border-radius: 50%; flex: none; object-fit: cover; background: #fff; }
.cabecera__texto { flex: 1; min-width: 0; }
.cabecera h1 { margin: 0; font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cabecera p { margin: 1px 0 0; font-size: 13px; min-height: 1.2em; }
.icono {
  display: grid; place-items: center; width: 44px; height: 44px; flex: none;
  border: 0; border-radius: 50%; background: transparent; color: inherit; cursor: pointer;
  transition: background-color .15s ease, transform .1s ease;
}
.icono:active { transform: scale(.94); background: rgba(255,255,255,.15); }
.icono--gris { color: var(--gris); }
@media (hover: hover) { .icono:hover { background: rgba(255,255,255,.12); } .icono--gris:hover { background: rgba(0,0,0,.06); } }

.mensajes {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  padding: 12px 4% 8px; display: flex; flex-direction: column; gap: 2px;
}
.fecha { align-self: center; margin: 4px 0 8px; }
.fecha span, .aviso-cifrado, .aviso {
  display: inline-block; background: #fff; color: var(--gris); font-size: 12.5px;
  padding: 5px 12px; border-radius: 8px; box-shadow: var(--sombra);
}
.aviso-cifrado { align-self: center; text-align: center; background: #ffeecd; color: #54656f; max-width: 88%; margin-bottom: 10px; }
.aviso { align-self: center; text-align: center; background: #e7f3ff; margin: 8px 0; max-width: 88%; }

.burbuja {
  position: relative; max-width: 82%; padding: 6px 8px 8px 9px; margin-top: 6px;
  border-radius: 8px; box-shadow: var(--sombra);
  font-size: 15px; line-height: 1.38; white-space: pre-wrap; overflow-wrap: anywhere;
  animation: entrar .18s ease-out;
}
.burbuja + .burbuja.mismo { margin-top: 2px; }
.burbuja.sale { align-self: flex-end; background: var(--saliente); border-top-right-radius: 0; }
.burbuja.entra { align-self: flex-start; background: var(--entrante); border-top-left-radius: 0; }
.burbuja.sale.mismo { border-top-right-radius: 8px; }
.burbuja.entra.mismo { border-top-left-radius: 8px; }
/* espacio para la hora al final de la última línea */
.burbuja .cuerpo::after { content: ""; display: inline-block; width: 64px; }
.burbuja.entra .cuerpo::after { width: 42px; }
.meta {
  position: absolute; right: 7px; bottom: 3px;
  display: flex; align-items: center; gap: 3px; font-size: 11px; color: var(--gris);
}
.tilde { width: 16px; height: 11px; color: var(--gris); transition: color .3s ease; }
.tilde.leido { color: var(--azul-tilde); }
@keyframes entrar { from { opacity: 0; transform: translateY(4px) scale(.98); } }

.audio { display: flex; align-items: center; gap: 8px; min-width: 210px; padding-bottom: 14px; }
.audio button {
  width: 34px; height: 34px; border: 0; border-radius: 50%; background: transparent; color: var(--gris); cursor: pointer;
  display: grid; place-items: center; flex: none;
}
.onda { flex: 1; height: 4px; border-radius: 2px; background: #b6c2bc; position: relative; overflow: hidden; }
.onda i { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--verde-boton); }
.audio .dur { font-size: 11px; color: var(--gris); position: absolute; left: 52px; bottom: 4px; }
.transcripcion { font-size: 13px; color: #54656f; font-style: italic; border-top: 1px solid rgba(0,0,0,.06); padding-top: 4px; margin-top: 2px; white-space: pre-wrap; }
.autor { display: block; font-size: 12.5px; font-weight: 600; color: #027eb5; margin-bottom: 2px; }

.escribiendo { align-self: flex-start; display: flex; gap: 4px; padding: 12px 14px; }
.escribiendo span { width: 7px; height: 7px; border-radius: 50%; background: #9aa5ab; animation: punto 1.2s infinite ease-in-out; }
.escribiendo span:nth-child(2) { animation-delay: .15s; }
.escribiendo span:nth-child(3) { animation-delay: .3s; }
@keyframes punto { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }

.barra {
  display: flex; align-items: flex-end; gap: 6px;
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
}
.campo, .grabando {
  flex: 1; min-height: 48px; display: flex; align-items: center;
  background: #fff; border-radius: 24px; box-shadow: var(--sombra); padding: 0 14px;
}
.campo textarea {
  width: 100%; border: 0; outline: 0; resize: none; background: transparent;
  font: inherit; font-size: 16px; /* 16px: evita el zoom de iOS al enfocar */
  line-height: 1.35; max-height: 120px; padding: 12px 0; color: var(--texto);
}
.grabando { gap: 8px; padding-left: 4px; color: var(--texto); font-variant-numeric: tabular-nums; }
.grabando[hidden], .campo[hidden] { display: none; }
.grabando__txt { color: var(--gris); font-size: 14px; }
.punto { width: 10px; height: 10px; border-radius: 50%; background: #f15c6d; animation: latido 1s infinite; }
@keyframes latido { 50% { opacity: .3; } }
.enviar {
  width: 48px; height: 48px; flex: none; border: 0; border-radius: 50%;
  background: var(--verde-boton); color: #fff; cursor: pointer; display: grid; place-items: center;
  box-shadow: var(--sombra); transition: transform .1s ease, background-color .15s ease;
  -webkit-user-select: none; user-select: none;
}
.enviar:active { transform: scale(.94); }
.enviar:disabled { background: #8fd3c3; cursor: default; }
.enviar svg { grid-area: 1 / 1; transition: opacity .15s ease, transform .15s ease; }
.enviar .ico-enviar, .enviar.con-texto .ico-mic { opacity: 0; transform: scale(.6); }
.enviar.con-texto .ico-enviar { opacity: 1; transform: none; }
:focus-visible { outline: 2px solid var(--verde-boton); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
