/* Pagina de chats: lista e hilo 1:1 */
    /* ── CHATS (mensajes directos, blanco/morado + motion Apple) ── */
    .chat-page {
      position: fixed;
      inset: 0;
      z-index: 1550;
      background: white;
      display: none;
      flex-direction: column;
      font-family: 'Barlow', 'DM Sans', sans-serif
    }

    .chat-page.on {
      display: flex;
      animation: obFade .28s ease
    }

    .chat-head {
      display: flex;
      align-items: center;
      gap: 12px;
      padding: 11px 16px;
      padding-top: calc(11px + env(safe-area-inset-top, 0px));
      border-bottom: 1px solid rgba(124, 58, 237, .12);
      background: rgba(255, 255, 255, .92);
      -webkit-backdrop-filter: blur(16px);
      backdrop-filter: blur(16px);
      flex-shrink: 0
    }

    .chat-back {
      width: 38px;
      height: 38px;
      border-radius: 50%;
      background: rgba(124, 58, 237, .08);
      color: var(--p);
      border: none;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 1rem;
      flex-shrink: 0;
      transition: background .15s, transform .12s
    }

    .chat-back:hover {
      background: rgba(124, 58, 237, .15)
    }

    .chat-back:active {
      transform: scale(.92)
    }

    .chat-head-title {
      font-family: 'Barlow Condensed', sans-serif;
      font-weight: 900;
      font-size: 1.35rem;
      text-transform: uppercase;
      letter-spacing: .5px;
      color: var(--p);
      flex: 1
    }

    .chat-head-name {
      font-weight: 700;
      font-size: 1rem;
      color: var(--tx);
      flex: 1;
      min-width: 0;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis
    }

    /* Botón "Nuevo mensaje" en la cabecera de la lista */
    .chat-new {
      width: 38px;
      height: 38px;
      border-radius: 50%;
      background: var(--p);
      color: white;
      border: none;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: .92rem;
      flex-shrink: 0;
      transition: background .15s, transform .12s
    }

    .chat-new:hover {
      background: var(--pd)
    }

    .chat-new:active {
      transform: scale(.92)
    }

    /* Buscador del directorio de personas */
    .chat-search {
      display: flex;
      align-items: center;
      gap: 10px;
      margin: 12px 16px 4px;
      padding: 11px 15px;
      border: 1.5px solid rgba(124, 58, 237, .22);
      background: rgba(124, 58, 237, .05);
      border-radius: 50px;
      flex-shrink: 0;
      transition: border-color .2s, background .2s
    }

    .chat-search:focus-within {
      border-color: var(--p);
      background: white
    }

    .chat-search i {
      color: var(--pk-tx);
      font-size: .9rem;
      flex-shrink: 0
    }

    .chat-search input {
      flex: 1;
      min-width: 0;
      border: none;
      background: none;
      outline: none;
      font-family: 'Barlow', 'DM Sans', sans-serif;
      font-size: .95rem;
      color: var(--tx)
    }

    .chat-search input::-webkit-search-cancel-button {
      -webkit-appearance: none
    }

    .chat-dir-go {
      width: 34px;
      height: 34px;
      border-radius: 50%;
      background: rgba(124, 58, 237, .09);
      color: var(--p);
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: .82rem;
      flex-shrink: 0
    }

    .chat-item:hover .chat-dir-go {
      background: var(--p);
      color: white
    }

    .chat-list {
      flex: 1;
      overflow-y: auto;
      padding: 6px 0 30px;
      -webkit-overflow-scrolling: touch
    }

    .chat-item {
      display: flex;
      gap: 12px;
      align-items: center;
      padding: 12px 18px;
      cursor: pointer;
      border: none;
      background: none;
      width: 100%;
      text-align: left;
      font-family: 'Barlow', 'DM Sans', sans-serif;
      transition: background .15s
    }

    .chat-item:hover {
      background: rgba(124, 58, 237, .05)
    }

    .chat-item:active {
      background: rgba(124, 58, 237, .1)
    }

    .chat-ava {
      width: 48px;
      height: 48px;
      border-radius: 50%;
      flex-shrink: 0;
      background: linear-gradient(135deg, var(--p), var(--pdd));
      color: white;
      display: flex;
      align-items: center;
      justify-content: center;
      font-family: 'Barlow Condensed', sans-serif;
      font-weight: 900;
      font-size: 1.05rem;
      overflow: hidden;
      text-transform: uppercase
    }

    .chat-ava img {
      width: 100%;
      height: 100%;
      object-fit: cover
    }

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

    .chat-item-name {
      display: block;
      font-weight: 700;
      font-size: .95rem;
      color: var(--tx);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis
    }

    .chat-item-last {
      display: block;
      font-size: .84rem;
      color: var(--tx2);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      margin-top: 2px
    }

    .chat-item.unread .chat-item-name,
    .chat-item.unread .chat-item-last {
      color: var(--pd);
      font-weight: 700
    }

    .chat-item-meta {
      display: flex;
      flex-direction: column;
      align-items: flex-end;
      gap: 6px;
      flex-shrink: 0
    }

    .chat-item-time {
      font-size: .72rem;
      color: var(--tx2)
    }

    .chat-dot {
      width: 10px;
      height: 10px;
      border-radius: 50%;
      background: var(--p);
      opacity: 0;
      transition: opacity .2s
    }

    .chat-item.unread .chat-dot {
      opacity: 1
    }

    .chat-thread-msgs {
      flex: 1;
      overflow-y: auto;
      padding: 16px 16px 10px;
      display: flex;
      flex-direction: column;
      gap: 4px;
      -webkit-overflow-scrolling: touch
    }

    .msg {
      position: relative;
      max-width: 78%;
      padding: 9px 14px;
      border-radius: 18px;
      font-size: .93rem;
      line-height: 1.45;
      word-break: break-word;
      white-space: pre-wrap
    }

    /* Solo las burbujas NUEVAS se animan (las marca chats.js con .msg-enter).
       Antes .msg animaba siempre y, como el onSnapshot repinta toda la lista,
       en cada mensaje re-aparecían todas de golpe. */
    /* Entrada estilo iMessage: la burbuja brota desde su esquina de origen
       (la mía desde abajo-derecha, la suya desde abajo-izquierda) con un
       ligero rebote al final, en vez de un simple deslizamiento. */
    .msg-enter {
      animation: msgIn .34s cubic-bezier(.2, 1.28, .38, 1) both
    }

    .msg.mine.msg-enter { transform-origin: 100% 100%; }
    .msg.theirs.msg-enter { transform-origin: 0 100%; }

    @keyframes msgIn {
      from { opacity: 0; transform: translateY(14px) scale(.55) }
      60%  { opacity: 1 }
      to   { opacity: 1; transform: none }
    }

    @media (prefers-reduced-motion: reduce) {
      .msg-enter { animation: msgFade .18s ease both }
      @keyframes msgFade { from { opacity: 0 } to { opacity: 1 } }
    }

    /* ── Visto (palomitas, solo en lo mío) ── */
    .msg-check {
      margin-left: 5px;
      font-size: .62rem;
      opacity: .85;
      vertical-align: baseline
    }

    .msg-check.visto {
      color: #7dd3fc;
      opacity: 1
    }

    /* ── Mensaje eliminado: se queda el hueco con el aviso, como en IG ── */
    .msg.msg-borrado {
      background: rgba(124, 58, 237, .08) !important;
      color: var(--tx2) !important;
      font-style: italic;
      border: 1px dashed rgba(124, 58, 237, .28)
    }

    .msg.msg-borrado .msg-txt { font-size: .86rem }
    .msg.msg-borrado .msg-txt i { font-size: .74rem; margin-right: 4px; opacity: .7 }

    /* Realimentación al mantener pulsado */
    .msg-presionado {
      transform: scale(.94);
      transition: transform .18s cubic-bezier(.2, 1.2, .4, 1)
    }

    /* ── Hoja de acciones del mensaje ── */
    .msg-sheet {
      position: fixed;
      inset: 0;
      z-index: 1700;
      background: rgba(18, 8, 46, .45);
      -webkit-backdrop-filter: blur(3px);
      backdrop-filter: blur(3px);
      display: flex;
      align-items: flex-end;
      justify-content: center;
      padding: 16px;
      opacity: 0;
      transition: opacity .18s
    }

    .msg-sheet.on { opacity: 1 }

    .msg-sheet-box {
      width: 100%;
      max-width: 420px;
      display: flex;
      flex-direction: column;
      gap: 8px;
      transform: translateY(14px);
      transition: transform .22s cubic-bezier(.2, 1.1, .4, 1)
    }

    .msg-sheet.on .msg-sheet-box { transform: none }

    .msg-sheet-box button {
      width: 100%;
      border: none;
      border-radius: 14px;
      padding: 15px;
      font-family: 'DM Sans', sans-serif;
      font-size: .95rem;
      font-weight: 700;
      cursor: pointer;
      background: #fff
    }

    .msg-sheet-del { color: var(--danger) }
    .msg-sheet-cancel { color: var(--tx) }

    /* Fila de emojis para reaccionar, encima de las opciones de la hoja */
    .msg-reacc-row {
      display: flex;
      justify-content: space-between;
      gap: 4px;
      background: #fff;
      border-radius: 999px;
      padding: 8px 10px;
      margin-bottom: 2px
    }

    .msg-reacc-row .msg-reacc {
      width: auto;
      flex: 1;
      border: none;
      background: transparent;
      border-radius: 50%;
      padding: 6px 0;
      font-size: 1.5rem;
      cursor: pointer;
      transition: transform .12s
    }

    .msg-reacc-row .msg-reacc:hover { transform: scale(1.25) }
    .msg-reacc-row .msg-reacc.on { background: var(--lp) }

    /* Chips de reacción bajo la burbuja */
    .msg-reaccs {
      position: absolute;
      bottom: -11px;
      display: flex;
      gap: 3px
    }

    .msg.mine .msg-reaccs { right: 8px }
    .msg.theirs .msg-reaccs { left: 8px }

    .msg-reaccs .msg-reacc-chip {
      background: #fff;
      border: 1px solid rgba(124, 58, 237, .18);
      border-radius: 999px;
      padding: 1px 6px;
      font-size: .78rem;
      line-height: 1.3;
      box-shadow: 0 1px 4px rgba(18, 8, 46, .12);
      display: inline-flex;
      align-items: center;
      gap: 2px
    }

    .msg-reaccs .msg-reacc-chip b { font-size: .68rem; color: var(--pd); font-weight: 800 }

    /* Deja aire bajo la burbuja para que los chips no se encimen con la de abajo */
    .msg.con-reacc { margin-bottom: 14px }

    .msg.mine {
      align-self: flex-end;
      background: var(--p);
      color: white;
      border-bottom-right-radius: 6px
    }

    .msg.theirs {
      align-self: flex-start;
      background: rgba(124, 58, 237, .07);
      border: 1px solid rgba(124, 58, 237, .1);
      color: var(--tx);
      border-bottom-left-radius: 6px
    }

    .msg-time {
      font-size: .66rem;
      opacity: .7;
      margin-top: 3px;
      text-align: right
    }

    .msg.theirs .msg-time {
      color: var(--tx2);
      opacity: 1
    }

    /* Enviado pero aún sin confirmar por Firestore: se ve, pero se nota
       que va en camino. Lo sustituye el onSnapshot en cuanto llega. */
    .msg.pending {
      opacity: .62
    }

    /* El nombre de la cabecera abre el perfil */
    .chat-head-name.tappable {
      cursor: pointer
    }

    .chat-head-name.tappable:active {
      opacity: .6
    }

    .chat-day {
      align-self: center;
      font-size: .72rem;
      font-weight: 700;
      color: var(--pk-tx);
      background: rgba(124, 58, 237, .07);
      border-radius: 50px;
      padding: 4px 14px;
      margin: 10px 0 6px
    }

    .chat-inputbar {
      display: flex;
      gap: 8px;
      padding: 10px 14px;
      padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
      border-top: 1px solid rgba(124, 58, 237, .12);
      background: white;
      flex-shrink: 0
    }

    .chat-inputbar input {
      flex: 1;
      min-width: 0;
      border: 1.5px solid rgba(124, 58, 237, .22);
      background: rgba(124, 58, 237, .05);
      border-radius: 50px;
      padding: 11px 16px;
      font-family: 'Barlow', 'DM Sans', sans-serif;
      font-size: .95rem;
      color: var(--tx);
      outline: none;
      transition: border-color .2s, background .2s
    }

    .chat-inputbar input:focus {
      border-color: var(--p);
      background: white
    }

    .chat-send {
      width: 44px;
      height: 44px;
      border-radius: 50%;
      background: var(--p);
      color: white;
      border: none;
      cursor: pointer;
      font-size: 1rem;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;
      transition: background .15s, transform .1s ease-out
    }

    .chat-send:hover {
      background: var(--pd)
    }

    .chat-send:active {
      transform: scale(.9)
    }

    .chat-send:disabled {
      opacity: .45
    }

    /* Botón de adjuntar foto: mismo tamaño que enviar, pero discreto */
    .chat-attach {
      width: 44px;
      height: 44px;
      border-radius: 50%;
      background: rgba(124, 58, 237, .08);
      color: var(--p);
      border: none;
      cursor: pointer;
      font-size: 1.05rem;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;
      transition: background .15s, transform .1s ease-out
    }

    .chat-attach:active {
      transform: scale(.9);
      background: rgba(124, 58, 237, .16)
    }

    /* Vista previa de la foto elegida, sobre la barra de entrada */
    .chat-attach-preview {
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 10px 14px;
      border-top: 1px solid rgba(124, 58, 237, .1);
      background: rgba(124, 58, 237, .03)
    }

    .chat-attach-preview[hidden] {
      display: none
    }

    .cap-thumb {
      position: relative;
      width: 56px;
      height: 56px;
      border-radius: 12px;
      overflow: hidden;
      flex-shrink: 0;
      background: rgba(124, 58, 237, .1)
    }

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

    /* Barra de progreso de subida (crece de 0 a 100%) */
    .cap-bar {
      position: absolute;
      left: 0;
      bottom: 0;
      height: 4px;
      width: 0%;
      background: var(--p);
      transition: width .15s linear
    }

    .cap-x {
      width: 34px;
      height: 34px;
      border-radius: 50%;
      border: none;
      background: rgba(124, 58, 237, .1);
      color: var(--p);
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0
    }

    .cap-x:active {
      transform: scale(.9)
    }

    /* ── Burbujas con foto ────────────────────────────────────────── */
    /* Con imagen la burbuja no lleva relleno: la foto ocupa todo el ancho.
       SIN `overflow:hidden`: estaba ahí para redondear las esquinas de la foto,
       pero eso ya lo hace el `border-radius` de la propia foto — y de paso
       recortaba por la mitad los chips de reacción, que cuelgan 11 px por
       debajo del globo (`.msg-reaccs { bottom:-11px }`). En un mensaje con
       foto, un ❤️ se veía partido. */
    .msg.has-img {
      padding: 4px
    }

    /* La foto se ve ENTERA, encogida hasta caber en la burbuja.
       Antes iba `width:100%` + `max-height:320px` + `object-fit:cover`. Con el
       ancho fijado y un tope de alto, la foto queda sobre-restringida y CADA
       MOTOR lo resuelve a su manera: Chromium encoge la caja y respeta la
       proporción, pero con `cover` de por medio cualquier motor que prefiera
       mantener el ancho recorta la foto por arriba y por abajo — justo lo que
       le pasa a las verticales, que son casi todas las del teléfono.
       Con ancho y alto automáticos no hay nada que resolver: la foto se reduce
       proporcionalmente hasta caber por los dos lados, en cualquier navegador.
       `contain` deja de ser un recorte y pasa a ser un seguro.
       `min-width` evita que la burbuja se colapse mientras la foto carga. */
    .msg-img {
      display: block;
      width: auto;
      height: auto;
      /* Antes el tope era 240 px fijos: un pantallazo de teléfono acababa a
         190 px de ancho, ilegible sin abrirlo. */
      max-width: min(260px, 68vw);
      max-height: 360px;
      min-width: 120px;
      object-fit: contain;
      border-radius: 14px;
      background: rgba(0, 0, 0, .05);
      cursor: zoom-in
    }

    /* Foto que el navegador no pudo pintar */
    .msg-img-rota {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 14px 12px;
      border-radius: 14px;
      background: rgba(0, 0, 0, .06);
      font-size: .78rem;
      font-weight: 600;
      color: inherit;
      text-decoration: underline;
      opacity: .85
    }

    .msg-img-rota i { font-size: 1rem; opacity: .7 }

    /* Texto que acompaña a una foto: debajo de la imagen, con su propio margen */
    .msg.has-img .msg-txt {
      display: block;
      padding: 6px 10px 2px
    }

    .msg.has-img .msg-time {
      padding: 0 10px 4px
    }

