* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

:root { --app-h: 100dvh; }

html { height: 100%; }
body {
  height: 100vh;            /* fallback */
  height: var(--app-h);     /* altura real del viewport (se ajusta con el teclado) */
  background: #d1d7db;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.oculto { display: none !important; }

/* ---------- LOGIN ---------- */
.login {
  width: 100%;
  height: 100%;
  min-height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  background: linear-gradient(135deg, #075e54 0%, #128c7e 55%, #25d366 140%);
  position: relative;
  overflow: hidden;
}
.login::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 15% 20%, rgba(255,255,255,0.10) 0, transparent 32%),
    radial-gradient(circle at 85% 75%, rgba(255,255,255,0.08) 0, transparent 30%);
  pointer-events: none;
}
.login-box {
  position: relative;
  background: #fff;
  padding: 34px 30px 30px;
  border-radius: 22px;
  text-align: center;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  animation: aparecer 0.4s ease;
}
@keyframes aparecer { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.brand { margin-bottom: 22px; }
.login-logo {
  width: 76px; height: 76px; margin: 0 auto 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 40px; border-radius: 50%;
  background: linear-gradient(135deg, #25d366, #128c7e);
  box-shadow: 0 8px 20px rgba(18, 140, 126, 0.45);
}
.login-box h1 { color: #075e54; margin: 0 0 4px; font-size: 21px; }
.subtitulo { color: #8696a0; font-size: 14px; margin: 0; }

/* Pestañas login/registro (estilo pill) */
.tabs {
  display: flex; gap: 4px; margin-bottom: 20px;
  background: #eef1f2; padding: 4px; border-radius: 12px;
}
.tab {
  flex: 1; padding: 10px; border: none; cursor: pointer;
  background: transparent; color: #667781; border-radius: 9px;
  font-size: 14px; font-weight: 600; transition: all 0.2s;
}
.tab.activa {
  background: #fff; color: #075e54;
  box-shadow: 0 2px 6px rgba(0,0,0,0.10);
}

.form { display: flex; flex-direction: column; gap: 13px; }

/* Campo con icono */
.campo {
  display: flex; align-items: center; gap: 8px;
  border: 1.5px solid #e4e8ea; background: #f8fafb;
  border-radius: 12px; padding: 0 14px; transition: all 0.2s;
}
.campo:focus-within {
  border-color: #25d366; background: #fff;
  box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.15);
}
.campo .ico { font-size: 16px; opacity: 0.75; width: 20px; text-align: center; }
.campo input {
  flex: 1; border: none; background: transparent; outline: none;
  padding: 13px 0; font-size: 15px; color: #111b21;
}
.form button {
  margin-top: 6px; padding: 13px; border: none; border-radius: 12px;
  background: linear-gradient(135deg, #25d366, #128c7e); color: #fff;
  font-size: 15.5px; font-weight: 700; cursor: pointer; transition: all 0.2s;
  box-shadow: 0 6px 16px rgba(18, 140, 126, 0.35);
}
.form button:hover { transform: translateY(-1px); box-shadow: 0 9px 20px rgba(18, 140, 126, 0.45); }
.form button:active { transform: translateY(0); }

.auth-error { color: #d32f2f; font-size: 13px; margin: 14px 0 0; min-height: 16px; }
.pie { position: relative; color: rgba(255,255,255,0.85); font-size: 12.5px; }

/* Selector de foto */
.foto-picker {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  cursor: pointer; margin-bottom: 4px;
}
.foto-circulo {
  width: 84px; height: 84px; border-radius: 50%; position: relative;
  background: #f0f2f5; border: 2px dashed #cfd8dc;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; transition: all 0.2s;
}
.foto-picker:hover .foto-circulo { border-color: #25d366; }
.foto-ico { font-size: 26px; opacity: 0.6; }
.foto-prev {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; display: none;
}
.foto-label { color: #8696a0; font-size: 12.5px; }

/* Avatar con foto */
.avatar.con-foto { background-size: cover; background-position: center; }
.mini { font-size: 11px; opacity: 0.75; }
.c-info { flex: 1; min-width: 0; }
.c-info .estado-mini { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-icono {
  background: none; border: none; color: #54656f; font-size: 18px; cursor: pointer;
}
.btn-nuevo {
  margin: 10px 12px 0; padding: 10px; border: none; border-radius: 8px;
  background: #25d366; color: #fff; font-weight: 600; cursor: pointer; font-size: 14px;
}
.btn-nuevo:hover { background: #1da851; }

/* ---------- APP (2 columnas) ---------- */
.app {
  width: 100%;
  max-width: 1000px;
  height: 100vh;            /* fallback */
  height: var(--app-h);
  display: flex;
  background: #fff;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.15);
  overflow: hidden;
}

/* ----- Sidebar / contactos ----- */
.sidebar {
  width: 33%;
  min-width: 260px;
  border-right: 1px solid #e9edef;
  display: flex;
  flex-direction: column;
  background: #fff;
}
.sidebar-header {
  background: #f0f2f5;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
}
.sidebar-header .header-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.sidebar-header .header-info span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-titulo {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #667781;
  padding: 12px 16px 6px;
}
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #128c7e;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.contactos { list-style: none; overflow-y: auto; flex: 1; }
.contacto {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid #f2f2f2;
}
.contacto:hover { background: #f5f6f6; }
.contacto.activo { background: #e9edef; }
.contacto .nombre { font-size: 15px; color: #111b21; }
.contacto .estado-mini { font-size: 12px; color: #8696a0; }
.contacto .punto-online {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #25d366;
}
.contacto .badge {
  background: #25d366;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
}
.sin-contactos {
  color: #8696a0;
  font-size: 13px;
  text-align: center;
  padding: 30px 16px;
}

/* ----- Panel de chat ----- */
.panel { flex: 1; display: flex; flex-direction: column; }

.bienvenida {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #f0f2f5;
  color: #667781;
  text-align: center;
  padding: 20px;
}
.bienvenida-logo { font-size: 70px; margin-bottom: 10px; }

.conversacion { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.chat-header {
  background: #075e54;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
}
.btn-volver {
  display: none;
  background: none;
  border: none;
  color: #fff;
  font-size: 26px;
  cursor: pointer;
  line-height: 1;
}
.header-info { display: flex; flex-direction: column; }
.header-titulo { font-weight: 600; font-size: 16px; }
.header-estado { font-size: 12px; opacity: 0.85; }

.mensajes {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background-color: #efeae2;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 40 40'%3E%3Cg fill='%23d9d0c4' fill-opacity='0.35'%3E%3Ccircle cx='8' cy='8' r='1.5'/%3E%3Ccircle cx='28' cy='20' r='1.5'/%3E%3Ccircle cx='16' cy='32' r='1.5'/%3E%3C/g%3E%3C/svg%3E");
}

.burbuja {
  max-width: 75%;
  padding: 7px 10px 5px;
  border-radius: 8px;
  font-size: 14.5px;
  line-height: 1.35;
  word-wrap: break-word;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
}
.burbuja .hora {
  font-size: 10.5px;
  color: #667781;
  float: right;
  margin: 4px 0 0 8px;
}
.burbuja .hora .check { color: #8696a0; letter-spacing: -2px; font-weight: 700; }
.burbuja .hora .check.leido { color: #53bdeb; }

.recibido { background: #fff; align-self: flex-start; border-top-left-radius: 0; }
.enviado { background: #d9fdd3; align-self: flex-end; border-top-right-radius: 0; }

.escribiendo {
  align-self: flex-start;
  font-size: 12px;
  color: #667781;
  font-style: italic;
  padding: 2px 6px;
}

.chat-footer {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  /* respeta el área segura del teléfono (esquinas redondeadas / barra de gestos) */
  padding-right: calc(10px + env(safe-area-inset-right));
  padding-left: calc(10px + env(safe-area-inset-left));
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  background: #f0f2f5;
  width: 100%;
  flex-wrap: nowrap;
}
.chat-footer input {
  flex: 1 1 auto;
  min-width: 0;              /* clave: permite que el input se encoja y no empuje el botón */
  padding: 11px 14px;
  border: none;
  border-radius: 20px;
  font-size: 16px;          /* 16px evita el zoom automático de iOS al enfocar */
  outline: none;
}
.chat-footer #btnEnviar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: #009688;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}
.chat-footer #btnEnviar:hover { background: #00796b; }

/* Botones de emoji / adjuntar */
.btn-adjunto {
  width: 38px; height: 38px; flex: 0 0 auto;
  border: none; background: transparent; cursor: pointer;
  font-size: 21px; border-radius: 50%; line-height: 1;
  padding: 0; display: flex; align-items: center; justify-content: center;
}
.btn-adjunto:hover { background: rgba(0, 0, 0, 0.06); }
.chat-footer #btnEnviar { flex: 0 0 auto; }

/* En pantallas muy angostas, apretamos un poco todo */
@media (max-width: 380px) {
  .chat-footer { gap: 3px; padding: 6px 6px; }
  .btn-adjunto { width: 34px; height: 34px; font-size: 19px; }
  .chat-footer #btnEnviar { width: 42px; height: 42px; }
  .chat-footer input { padding: 10px 12px; }
}

/* Panel de emojis */
.emoji-panel {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  padding: 8px 10px;
  background: #f0f2f5;
  border-top: 1px solid #e2e5e7;
  max-height: 210px;
  overflow-y: auto;
}
.emoji-panel .emoji {
  border: none; background: transparent; cursor: pointer;
  font-size: 24px; padding: 6px 0; border-radius: 8px;
}
.emoji-panel .emoji:hover { background: rgba(0, 0, 0, 0.08); }

/* Imágenes dentro de las burbujas */
.burbuja.burbuja-img { padding: 4px; }
.msg-img {
  display: block;
  max-width: 240px;
  max-height: 300px;
  width: auto;
  border-radius: 6px;
  cursor: pointer;
}
.burbuja-img .hora {
  position: relative;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  padding: 1px 6px;
  border-radius: 8px;
  margin: -22px 4px 4px 0;
}

/* ---------- MÓVIL: una columna a la vez ---------- */
@media (max-width: 640px) {
  .app { max-width: 100%; }
  .sidebar { width: 100%; min-width: 0; }
  /* En móvil, cuando hay chat abierto, ocultamos la lista */
  .app.viendo-chat .sidebar { display: none; }
  .app:not(.viendo-chat) .panel { display: none; }
  .btn-volver { display: block; }
}
