/* Estilos del visor. Diseñado primero para teléfono; en PC se ve a dos columnas. */

:root {
  --barra: var(--principal);
  --sobre-barra: var(--sobre-principal);
  --fondo: #f3f4f6;
  --superficie: #ffffff;
  --superficie-2: #f0f2f5;
  --texto: #111b21;
  --texto-suave: #5f6f7a;
  --linea: #e3e6e9;
  --fondo-chat: #ece8e1;
  --burbuja-ajena: #ffffff;
  --burbuja-propia: #d9fdd3;
  --pildora: #ffffff;
  --marca-busqueda: #ffdf7e;
  --enlace: #0b6fb8;
  --peligro: #c62828;
  --sombra: 0 1px 1px rgba(11, 20, 26, .13);
  color-scheme: light dark;
}

/* Modo oscuro automático según el teléfono */
@media (prefers-color-scheme: dark) {
  :root {
    --barra: #1a2329;
    --sobre-barra: #e6ebee;
    --fondo: #101619;
    --superficie: #151d22;
    --superficie-2: #212c33;
    --texto: #e6ebee;
    --texto-suave: #92a2ad;
    --linea: #27333b;
    --fondo-chat: #0d1316;
    --burbuja-ajena: #202c33;
    --burbuja-propia: #115043;
    --pildora: #1f2a31;
    --marca-busqueda: #a97f10;
    --enlace: #6cc1ff;
    --peligro: #ff8a80;
    --sombra: 0 1px 1px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  height: 100dvh;
  overflow: hidden;
  background: var(--fondo);
  color: var(--texto);
  font: 16px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
svg { display: block; width: 24px; height: 24px; }
fieldset { border: 0; margin: 14px 0 0; padding: 0; min-width: 0; }
.oculto { position: absolute; width: 1px; height: 1px; opacity: 0; }

:focus-visible { outline: 2px solid var(--enlace); outline-offset: 2px; }

/* ----- Estructura ----- */

#app { height: 100%; display: flex; }

.vista {
  display: none;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  height: 100%;
  background: var(--superficie);
}

#app[data-vista="lista"] #vista-lista,
#app[data-vista="chat"] #vista-chat,
#app[data-vista="importar"] #vista-importar { display: flex; }

.panel-vacio { display: none; }

.desplazable {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

@media (min-width: 900px) {
  #vista-lista { display: flex; flex: 0 0 380px; border-right: 1px solid var(--linea); }
  #app[data-vista="lista"] .panel-vacio {
    display: flex;
    flex: 1;
    align-items: center;
    justify-content: center;
    background: var(--fondo-chat);
    color: var(--texto-suave);
  }
}

/* ----- Barras superiores ----- */

.barra {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: none;
  min-height: calc(56px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 6px 0;
  background: var(--barra);
  color: var(--sobre-barra);
}

.barra-titulo {
  flex: 1;
  min-width: 0;
  margin: 0 0 0 8px;
  font-size: 20px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.barra-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 4px 6px;
  border: 0;
  background: none;
  text-align: left;
}

.barra-nombre, .barra-detalle {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.barra-nombre { font-weight: 600; }
.barra-detalle { font-size: 12.5px; opacity: .85; }

.boton-icono {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: inherit;
}

.boton-icono:active { background: rgba(127, 127, 127, .25); }

#barra-busqueda input {
  flex: 1;
  min-width: 0;
  height: 38px;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, .92);
  color: #111b21;
}

.contador { flex: none; font-size: 13px; white-space: nowrap; padding: 0 2px; }

/* ----- Lista de chats ----- */

.caja-busqueda {
  position: relative;
  flex: none;
  padding: 8px 10px;
  background: var(--superficie);
  border-bottom: 1px solid var(--linea);
}

.caja-busqueda input {
  width: 100%;
  height: 40px;
  padding: 0 12px 0 40px;
  border: 0;
  border-radius: 10px;
  background: var(--superficie-2);
}

.lupa {
  position: absolute;
  left: 20px;
  top: 16px;
  color: var(--texto-suave);
  pointer-events: none;
}

.lupa svg { width: 22px; height: 22px; }

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 72px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--linea);
}

.chat-item:active, .chat-item.activo { background: var(--superficie-2); }

.avatar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  color: #fff;
  font-weight: 600;
  font-size: 18px;
}

.avatar-chico {
  width: 38px;
  height: 38px;
  font-size: 14px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .35);     /* Por si coincide con el color de la barra */
}

.chat-datos { flex: 1; min-width: 0; }

.chat-fila { display: flex; align-items: baseline; gap: 8px; }

.chat-nombre {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-fecha { flex: none; font-size: 12.5px; color: var(--texto-suave); }

.chat-previa {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
  color: var(--texto-suave);
  font-size: 14.5px;
  min-width: 0;
}

.chat-previa span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-previa svg { flex: none; width: 16px; height: 16px; }

.titulo-seccion {
  padding: 14px 14px 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--texto-suave);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.resultado {
  display: block;
  padding: 10px 14px;
  border-bottom: 1px solid var(--linea);
}

.resultado:active { background: var(--superficie-2); }

.resultado-texto {
  margin-top: 2px;
  font-size: 14.5px;
  color: var(--texto-suave);
  overflow-wrap: anywhere;
}

.estado-vacio { padding: 48px 24px; text-align: center; color: var(--texto-suave); }
.estado-vacio .boton { margin-top: 16px; }

.ver-mas { display: block; width: 100%; padding: 14px; border: 0; background: none; color: var(--enlace); }

mark { background: var(--marca-busqueda); color: inherit; border-radius: 2px; }

/* ----- Conversación ----- */

.zona-mensajes {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--fondo-chat);
}

#mensajes { padding: 8px 0 calc(12px + env(safe-area-inset-bottom)); }

.separador {
  position: sticky;
  top: 8px;
  z-index: 2;
  display: flex;
  justify-content: center;
  margin: 10px 0 6px;
  pointer-events: none;
}

.separador span, .aviso-sistema span {
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--pildora);
  box-shadow: var(--sombra);
  color: var(--texto-suave);
  font-size: 12.5px;
}

.aviso-sistema {
  display: flex;
  justify-content: center;
  margin: 8px 16px;
  text-align: center;
}

.fila { display: flex; margin-top: 8px; padding: 0 10px; }
.fila.sigue { margin-top: 2px; }
.fila.propio { justify-content: flex-end; }

.burbuja {
  max-width: min(84%, 560px);
  min-width: 72px;
  padding: 6px 8px 5px;
  border-radius: 10px;
  background: var(--burbuja-ajena);
  box-shadow: var(--sombra);
  overflow-wrap: anywhere;
}

.propio .burbuja { background: var(--burbuja-propia); }
.ajeno:not(.sigue) .burbuja { border-top-left-radius: 3px; }
.propio:not(.sigue) .burbuja { border-top-right-radius: 3px; }

.fila.resaltado .burbuja, .aviso-sistema.resaltado span { animation: destello 2s ease-out; }

@keyframes destello {
  0%, 40% { box-shadow: 0 0 0 3px var(--marca-busqueda); }
  100% { box-shadow: var(--sombra); }
}

@media (prefers-reduced-motion: reduce) {
  .fila.resaltado .burbuja { animation: none; outline: 3px solid var(--marca-busqueda); }
}

.autor { display: block; font-size: 13px; font-weight: 600; margin-bottom: 1px; }

.texto { white-space: pre-wrap; }
.texto::after { content: ""; display: block; clear: both; }
.texto a { color: var(--enlace); text-decoration: underline; }
.eliminado { font-style: italic; color: var(--texto-suave); }

.meta {
  float: right;
  margin: 5px 0 -1px 10px;
  font-size: 11px;
  color: var(--texto-suave);
  white-space: nowrap;
}

.meta-sola { float: none; display: block; text-align: right; margin: 3px 0 0; }

.foto {
  display: block;
  width: min(280px, 66vw);
  max-width: 100%;
  margin-bottom: 3px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  overflow: hidden;
  background: var(--superficie-2);
}

.foto img { display: block; width: 100%; height: 100%; object-fit: cover; }

.tarjeta-archivo {
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(270px, 64vw);
  max-width: 100%;
  margin-bottom: 3px;
  padding: 8px;
  border-radius: 7px;
  background: rgba(127, 127, 127, .13);
}

.tarjeta-archivo svg { flex: none; width: 30px; height: 30px; color: var(--texto-suave); }

.archivo-datos { flex: 1; min-width: 0; }

.archivo-nombre {
  display: block;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.archivo-detalle { display: block; font-size: 12px; color: var(--texto-suave); }

.boton-abrir {
  flex: none;
  padding: 7px 12px;
  border-radius: 8px;
  background: var(--principal);
  color: var(--sobre-principal);
  font-size: 14px;
  font-weight: 600;
}

.audio {
  display: flex;
  align-items: center;
  gap: 6px;
  width: min(270px, 64vw);
  max-width: 100%;
  margin-bottom: 3px;
}

.audio input { flex: 1; min-width: 0; accent-color: var(--principal); }

.audio-boton {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--principal);
  color: var(--sobre-principal);
}

.audio-tiempo { flex: none; min-width: 34px; font-size: 12px; color: var(--texto-suave); }

.pildora-cargando {
  position: absolute;
  top: 10px;
  left: 50%;
  z-index: 3;
  transform: translateX(-50%);
  padding: 4px 12px;
  border-radius: 14px;
  background: var(--pildora);
  box-shadow: var(--sombra);
  font-size: 13px;
}

.boton-flotante {
  position: absolute;
  right: 14px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--pildora);
  color: var(--texto-suave);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .3);
}

/* ----- Visor de imagen ----- */

.visor {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: #000;
  color: #fff;
}

.visor-barra {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
  padding: env(safe-area-inset-top) 6px 0;
  min-height: calc(56px + env(safe-area-inset-top));
}

.visor-nombre {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.visor img {
  flex: 1;
  min-height: 0;
  width: 100%;
  object-fit: contain;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ----- Importar y formularios ----- */

.importar { padding: 16px; background: var(--fondo); }
.importar > * { max-width: 560px; margin-inline: auto; }

.zona-archivo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 36px 20px;
  border: 2px dashed var(--linea);
  border-radius: 14px;
  background: var(--superficie);
  color: var(--texto-suave);
  text-align: center;
  cursor: pointer;
}

.zona-archivo.encima { border-color: var(--principal); }
.zona-archivo strong { color: var(--texto); font-size: 17px; }
.zona-icono svg { width: 40px; height: 40px; }

.progreso { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
progress { width: 100%; height: 10px; accent-color: var(--principal); }

.resumen {
  margin: 0 0 12px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--superficie);
  white-space: pre-line;
}

.aviso-importar {
  margin: 0 0 12px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--marca-busqueda);
}

.campo { display: block; margin: 14px 0 6px; font-weight: 600; font-size: 14.5px; padding: 0; }

.entrada {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--linea);
  border-radius: 10px;
  background: var(--superficie);
}

.opcion-participante {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  margin-bottom: 6px;
  padding: 10px 12px;
  border: 1px solid var(--linea);
  border-radius: 10px;
  background: var(--superficie);
  cursor: pointer;
}

.opcion-participante input { flex: none; width: 20px; height: 20px; margin: 0; accent-color: var(--principal); }
.opcion-participante span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.opcion-participante small { flex: none; color: var(--texto-suave); }

.acciones { display: flex; gap: 10px; margin-top: 18px; }
.acciones .boton { flex: 1; }

.boton {
  display: inline-block;
  min-height: 46px;
  padding: 11px 18px;
  border: 0;
  border-radius: 10px;
  background: var(--principal);
  color: var(--sobre-principal);
  font-weight: 600;
  text-align: center;
}

.boton-secundario { background: var(--superficie-2); color: var(--texto); }
.boton-ancho { width: 100%; margin-top: 16px; }

.boton-peligro {
  width: 100%;
  min-height: 44px;
  margin-top: 14px;
  border: 0;
  background: none;
  color: var(--peligro);
}

.dialogo {
  width: min(420px, calc(100vw - 32px));
  border: 0;
  border-radius: 14px;
  background: var(--superficie);
  color: var(--texto);
}

.dialogo::backdrop { background: rgba(0, 0, 0, .5); }
.dialogo h2 { margin: 0 0 4px; font-size: 18px; }

.aviso-flotante {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 60;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: #111b21;
  color: #fff;
  font-size: 14.5px;
}

/* ----- Páginas sueltas: acceso y sin conexión ----- */

.pagina-centrada {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.tarjeta {
  width: 100%;
  max-width: 360px;
  padding: 28px 22px;
  border-radius: 16px;
  background: var(--superficie);
  box-shadow: var(--sombra);
  text-align: center;
}

.tarjeta h1 { margin: 12px 0 8px; font-size: 22px; }
.tarjeta form { text-align: left; }
.logo { border-radius: 18px; }
.error { margin: 10px 0 0; color: var(--peligro); font-size: 14.5px; }

.pin-inicial {
  margin: 12px 0 4px;
  padding: 12px;
  border-radius: 10px;
  background: var(--superficie-2);
  font-size: 14.5px;
}

.pin-inicial strong {
  display: block;
  margin: 4px 0;
  font-size: 30px;
  letter-spacing: .12em;
}
