:root {
  --fondo: #0b141a; --panel: #111b21; --barra: #202c33; --borde: #222d34; --texto: #e9edef; --suave: #8696a0;
  --mio: #005c4b; --otro: #202c33; --verde: #00a884; --azul: #53bdeb; --rojo: #f15c6d;
  --seguro-arriba: env(safe-area-inset-top); --seguro-abajo: env(safe-area-inset-bottom);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--fondo); color: var(--texto);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
#app { height: 100dvh; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
a { color: var(--azul); }

/* Acceso */
.acceso { max-width: 360px; margin: 0 auto; padding: calc(60px + var(--seguro-arriba)) 24px 24px; text-align: center; }
.acceso .logo img { width: 84px; height: 84px; border-radius: 20px; }
.acceso h1 { margin: 12px 0 4px; font-size: 24px; }
.acceso .sub { color: var(--suave); margin: 0 0 22px; }
.acceso input { width: 100%; padding: 13px 14px; margin-bottom: 10px; border-radius: 10px; border: 1px solid var(--borde);
  background: var(--panel); color: var(--texto); font-size: 16px; }
.acceso button { width: 100%; padding: 13px; border-radius: 10px; background: var(--verde); color: #fff; font-weight: 600; font-size: 16px; }
.error { color: var(--rojo); min-height: 1.2em; }

/* Marco */
.marco { display: grid; grid-template-columns: minmax(300px, 400px) 1fr; height: 100dvh; }
.lista { display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--borde); min-height: 0; }
.barra { display: flex; align-items: center; gap: 10px; padding: calc(10px + var(--seguro-arriba)) 12px 10px; background: var(--barra); min-height: 56px; }
.barra h2 { margin: 0; font-size: 18px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icono { font-size: 22px; width: 40px; height: 40px; display: inline-grid; place-items: center; border-radius: 50%; flex: none; }
.punto { width: 10px; height: 10px; border-radius: 50%; background: var(--suave); }
.punto.ok { background: var(--verde); } .punto.mal { background: var(--rojo); } .punto.espera { background: #e5b33a; }
.buscar { padding: 8px 12px; }
.buscar input { width: 100%; padding: 9px 12px; border-radius: 8px; border: 0; background: var(--barra); color: var(--texto); font-size: 16px; }
.chats { overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; padding-bottom: var(--seguro-abajo); }
.chat { display: flex; gap: 12px; padding: 10px 12px; color: inherit; text-decoration: none; cursor: pointer; }
.chat:active, .chat.activo { background: var(--barra); }
.avatar { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; color: #fff; flex: none; font-size: 16px; }
.avatar.chico { width: 36px; height: 36px; font-size: 13px; }
.info { flex: 1; min-width: 0; border-bottom: 1px solid var(--borde); padding-bottom: 10px; }
.fila { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.fila b { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fila small { color: var(--suave); font-size: 12px; flex: none; } .fila small.verde { color: var(--verde); }
.ultimo { color: var(--suave); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.burbuja-num { background: var(--verde); color: #111; border-radius: 12px; min-width: 20px; padding: 1px 6px; font-size: 12px; text-align: center; font-weight: 600; }
.nada { text-align: center; color: var(--suave); }
.titulo-arch { display: flex; justify-content: space-between; padding: 8px 14px; color: var(--suave); }
.titulo-arch button { color: var(--verde); }

/* Avisos y QR */
.avisos:empty { display: none; }
.estado-linea { padding: 8px 14px; background: #182229; color: var(--suave); font-size: 13px; }
.estado-linea.tip button { color: var(--verde); font-weight: 600; padding: 0; }
.qr { padding: 16px; text-align: center; background: #fff; color: #111; margin: 10px; border-radius: 12px; }
.qr h3 { margin: 0 0 8px; } .qr img { width: 240px; max-width: 100%; image-rendering: pixelated; }
.qr ol { text-align: left; padding-left: 20px; } .qr .nota { color: #555; font-size: 12px; }

/* Conversación */
.conversacion { display: flex; flex-direction: column; min-height: 0; background: var(--fondo); position: relative; }
.vacio { flex: 1; display: grid; place-items: center; color: var(--suave); }
.mensajes { flex: 1; overflow-y: auto; padding: 10px 4% 6px; -webkit-overflow-scrolling: touch;
  background-image: radial-gradient(rgba(255,255,255,.025) 1px, transparent 1px); background-size: 18px 18px; }
.cargando-mas { text-align: center; color: var(--suave); font-size: 12px; padding: 6px; }
.dia { text-align: center; margin: 10px 0; } .dia span { background: #182229; color: var(--suave); font-size: 12px; padding: 5px 10px; border-radius: 8px; }
.msg { display: flex; align-items: center; gap: 4px; margin: 3px 0; }
.msg.mio { flex-direction: row-reverse; }
.burbuja { max-width: min(78%, 520px); background: var(--otro); padding: 6px 8px 4px; border-radius: 8px; position: relative; overflow-wrap: anywhere; }
.mio .burbuja { background: var(--mio); }
.burbuja.sin-fondo { background: none; }
.texto { white-space: pre-wrap; }
.meta { float: right; margin: 6px 0 -2px 10px; font-size: 11px; color: rgba(233,237,239,.6); display: inline-flex; gap: 3px; align-items: center; }
.ticks.leido { color: var(--azul); }
.autor { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.cita { border-left: 4px solid var(--verde); background: rgba(0,0,0,.2); padding: 4px 8px; border-radius: 4px; margin-bottom: 4px; font-size: 13px; color: var(--suave);
  max-height: 60px; overflow: hidden; cursor: pointer; }
.media { display: block; max-width: 100%; width: 300px; max-height: 360px; object-fit: cover; border-radius: 6px; background: #000; cursor: zoom-in; }
video.media { cursor: auto; }
.sticker { width: 140px; height: 140px; object-fit: contain; }
audio { width: 250px; max-width: 100%; height: 40px; }
.doc { display: block; padding: 10px; background: rgba(0,0,0,.2); border-radius: 6px; text-decoration: none; color: var(--texto); }
.borrado { color: var(--suave); }
.responder { opacity: 0; font-size: 16px; color: var(--suave); padding: 4px; }
.msg:hover .responder, .msg:active .responder { opacity: 1; }
@media (hover: none) { .responder { opacity: .5; } }

.cita-activa { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 0 8px; padding: 8px 10px;
  background: var(--barra); border-left: 4px solid var(--verde); border-radius: 8px 8px 0 0; color: var(--suave); font-size: 14px; }
.cita-activa span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.redactar { display: flex; align-items: flex-end; gap: 6px; padding: 6px 8px calc(6px + var(--seguro-abajo)); background: var(--panel); flex-wrap: wrap; }
.redactar textarea { flex: 1; resize: none; border: 0; border-radius: 20px; padding: 10px 14px; background: var(--barra); color: var(--texto);
  font: inherit; font-size: 16px; max-height: 140px; min-height: 40px; }
.redactar .enviar, .redactar .grabar { background: var(--verde); color: #fff; font-size: 18px; }
.adjuntar { cursor: pointer; }
.redactar.grabando textarea, .redactar.grabando .adjuntar { display: none; }
.barra-grabacion { flex: 1; display: flex; align-items: center; gap: 14px; padding: 8px 6px; }
.barra-grabacion button { font-size: 20px; } .rojo { color: var(--rojo); }

/* Menú, visor y avisos */
.menu { position: fixed; top: calc(52px + var(--seguro-arriba)); left: 12px; z-index: 20; background: var(--barra); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5); display: flex; flex-direction: column; min-width: 240px; overflow: hidden; }
.menu button { text-align: left; padding: 13px 16px; border-bottom: 1px solid var(--borde); }
.menu .peligro { color: var(--rojo); }
.visor { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 30; display: grid; place-items: center; padding: 20px; }
.visor[hidden] { display: none; }
.visor img { max-width: 100%; max-height: 85vh; }
.visor .descargar { position: absolute; bottom: calc(24px + var(--seguro-abajo)); color: #fff; background: var(--verde); padding: 10px 18px; border-radius: 20px; text-decoration: none; }
.toast { position: fixed; left: 50%; bottom: calc(90px + var(--seguro-abajo)); transform: translateX(-50%); background: #2a3942; color: #fff;
  padding: 10px 16px; border-radius: 20px; z-index: 40; box-shadow: 0 4px 14px rgba(0,0,0,.4); max-width: 90vw; text-align: center; }
.error-total { padding: 30px; text-align: center; }

/* Celular: una columna */
@media (max-width: 760px) {
  .marco { grid-template-columns: 1fr; }
  .conversacion { display: none; }
  body.en-chat .lista { display: none; }
  body.en-chat .conversacion { display: flex; height: 100dvh; }
  .menu { left: auto; right: 12px; }
}
@media (min-width: 761px) { [data-atras] { display: none; } }
