/* ===== Chat interno ===== */
:root { --mine: #dff2f0; --tab-h: 0px; }

/* Contador de no leídos en el menú */
.side-nav a, .tabbar a { position: relative; }
.ch-num { margin-left: auto; background: var(--brand); color: #fff; font-size: 11.5px; font-weight: 700; min-width: 21px; height: 21px; border-radius: 99px;
  display: grid; place-items: center; padding: 0 6px; line-height: 1; }
.ch-num[hidden] { display: none; }
.tabbar .ch-num { position: absolute; top: 1px; left: calc(50% + 6px); margin: 0; min-width: 19px; height: 19px; font-size: 11px; box-shadow: 0 0 0 2px var(--dark); }

/* Pantalla del chat: ocupa todo el alto */
body.en-chat { overflow: hidden; }
.vista.vista-chat { position: fixed; top: var(--ch-top, 0px); left: var(--side); right: 0; padding: 0; max-width: none; margin: 0; }
.ch { display: grid; grid-template-columns: 340px minmax(0, 1fr); height: 100dvh; background: var(--bg); }

/* Avatares */
.cava { flex: none; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 15px; color: #fff; position: relative; }
.cava img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; }
.cava.sm { width: 32px; height: 32px; font-size: 12.5px; }
.cava.xl { width: 88px; height: 88px; font-size: 30px; }
.cava.canal { background: var(--brand-soft); color: var(--brand-ink); font-size: 21px; border-radius: 12px; }
.cava .en-linea { position: absolute; right: -1px; bottom: -1px; width: 13px; height: 13px; border-radius: 50%; background: #22b35e; border: 2px solid #fff; }
.cava.sm .en-linea { width: 11px; height: 11px; }

/* Lista de chats */
.ch-lista { background: var(--card); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.ch-lcab { padding: 18px 16px 10px; display: flex; flex-direction: column; gap: 12px; }
.ch-fila { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.ch-lcab h1 { margin: 0; font-size: 24px; }
.ch-ico { width: 42px; height: 42px; border-radius: 10px; border: 1px solid var(--line2); background: #fff; display: grid; place-items: center; color: var(--ink); flex: none; cursor: pointer; text-decoration: none; }
.ch-ico:hover { background: #faf8f5; }
.ch-ico svg { width: 20px; height: 20px; }
.ch-buscar { position: relative; display: block; }
.ch-buscar svg { position: absolute; left: 12px; top: 50%; translate: 0 -50%; width: 18px; color: var(--muted); pointer-events: none; }
.ch-buscar input { width: 100%; min-height: 44px; padding: 8px 12px 8px 38px; border: 1px solid var(--line2); border-radius: 10px; background: var(--bg); font-size: 16px; }
.ch-buscar input:focus { outline: none; border-color: var(--brand); background: #fff; box-shadow: 0 0 0 3px var(--brand-soft); }
.ch-chats { overflow-y: auto; flex: 1; padding: 0 8px 14px; overscroll-behavior: contain; }
.ch-chats h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 10px 6px; }
.ch-chat { width: 100%; display: flex; align-items: center; gap: 12px; padding: 10px; border: 0; background: none; border-radius: 12px; text-align: left; color: var(--ink); text-decoration: none; cursor: pointer; }
.ch-chat:hover { background: #f8f6f2; }
.ch-chat[aria-current] { background: var(--brand-soft); }
.ch-chat-txt { flex: 1; min-width: 0; display: block; }
.ch-chat-txt .l1, .ch-chat-txt .l2 { display: flex; align-items: center; gap: 8px; }
.ch-chat-txt b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.ch-chat-txt time { color: var(--muted); font-size: 12px; flex: none; }
.ch-chat-txt .res { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 13.5px; }
.ch-chat.sin-leer .res { color: var(--ink); font-weight: 700; }
.ch-chat.sin-leer time { color: var(--brand-ink); font-weight: 700; }
.ch-badge { flex: none; background: var(--brand); color: #fff; font-size: 12px; font-weight: 700; min-width: 21px; height: 21px; border-radius: 99px; display: grid; place-items: center; padding: 0 6px; }
.ch-nada { color: var(--muted); text-align: center; padding: 22px 12px; margin: 0; font-size: 14px; }

/* Aviso de notificaciones */
.ch-aviso { display: flex; gap: 12px; align-items: flex-start; background: var(--accent-soft); border: 1px solid #f3dcae; border-radius: 12px; padding: 12px; }
.ch-aviso > svg { width: 22px; height: 22px; flex: none; color: #9a5b00; margin-top: 1px; }
.ch-aviso b { font-size: 14px; } .ch-aviso p { margin: 2px 0 8px; font-size: 13px; color: #6b5233; line-height: 1.4; }
.ch-aviso p:last-child { margin-bottom: 0; }
.ch-aviso.gris { background: #f1ede8; border-color: var(--line2); } .ch-aviso.gris > svg { color: var(--muted); } .ch-aviso.gris p { color: var(--muted); }

/* Conversación */
.ch-conv { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--bg); }
.ch-ccab { background: var(--card); border-bottom: 1px solid var(--line); padding: 10px 18px; display: flex; align-items: center; gap: 12px; min-height: 66px; }
.ch-volver { display: none !important; border: 0; }
.ch-tit { flex: 1; min-width: 0; border: 0; background: none; padding: 0; text-align: left; cursor: pointer; color: var(--ink); }
.ch-tit b { display: block; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-tit small { color: var(--muted); font-size: 13px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-msgs { flex: 1; overflow-y: auto; padding: 14px clamp(12px, 3vw, 32px) 8px; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 2px; }
.ch-ini { align-self: center; text-align: center; display: grid; justify-items: center; gap: 6px; margin: 18px 0 8px; max-width: 360px; }
.ch-ini b { font-size: 17px; } .ch-ini p { margin: 0; color: var(--muted); font-size: 13.5px; }
.ch-mas { align-self: center; color: var(--muted); font-size: 12.5px; margin: 6px 0; }
.ch-dia { align-self: center; margin: 14px 0 8px; position: sticky; top: 0; z-index: 1; }
.ch-dia span { display: block; background: #ebe6df; color: var(--muted); font-size: 12px; font-weight: 700; padding: 3px 12px; border-radius: 99px; }
.ch-msg { display: flex; gap: 8px; align-items: flex-end; max-width: min(620px, 86%); margin-top: 8px; position: relative; }
.ch-msg.seguido { margin-top: 2px; }
.ch-msg.seguido > .cava { visibility: hidden; height: 0; }
.ch-msg.mio { align-self: flex-end; flex-direction: row-reverse; }
.ch-burb { background: var(--card); border-radius: 16px 16px 16px 4px; padding: 7px 12px 5px; box-shadow: 0 1px 1px rgba(35,31,32,.07); min-width: 0; }
.ch-msg.mio .ch-burb { background: var(--mine); border-radius: 16px 16px 4px 16px; }
.ch-msg.seguido .ch-burb { border-radius: 16px; }
.ch-autor { font-size: 13px; font-weight: 700; margin-bottom: 1px; display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.ch-autor small { font-weight: 400; color: var(--muted); font-size: 12px; }
.ch-burb p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.42; }
.ch-burb p a { color: var(--brand-ink); }
.ch-borrado { color: var(--muted); font-style: italic; display: flex; align-items: center; gap: 6px; }
.ch-borrado svg { width: 15px; height: 15px; }
.ch-meta { display: flex; justify-content: flex-end; align-items: center; gap: 3px; font-size: 11.5px; color: var(--muted); margin-top: 2px; white-space: nowrap; }
.ch-est { display: inline-grid; } .ch-est svg { width: 16px; height: 16px; }
.ch-est.visto { color: var(--brand); }
.ch-vn { color: var(--brand-ink); font-weight: 700; }
.ch-reint { border: 0; background: none; color: var(--danger); font-weight: 700; font-size: 12px; padding: 2px 0 2px 4px; cursor: pointer; text-decoration: underline; }
.ch-del { align-self: center; flex: none; width: 34px; height: 34px; border-radius: 50%; border: 0; background: transparent; color: var(--muted); display: grid; place-items: center; cursor: pointer; opacity: 0; transition: opacity .15s; }
.ch-del svg { width: 17px; height: 17px; }
.ch-msg:hover .ch-del, .ch-del:focus-visible { opacity: 1; }
.ch-del:hover { background: var(--danger-soft); color: var(--danger); }
@media (hover: none) { .ch-del { opacity: .55; width: 30px; height: 30px; } }

.ch-foto { display: block; border: 0; padding: 0; background: #e9e4dd; border-radius: 12px; overflow: hidden; margin: 3px 0 4px; width: min(300px, 62vw); cursor: zoom-in; }
.ch-foto img { width: 100%; height: auto; max-height: 360px; object-fit: cover; display: block; min-height: 120px; }
.ch-voz { display: flex; align-items: center; gap: 10px; width: min(280px, 60vw); padding: 4px 0; }
.ch-voz .play { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--brand); color: #fff; display: grid; place-items: center; flex: none; cursor: pointer; }
.ch-voz .play svg { width: 18px; height: 18px; }
.ondas { flex: 1; height: 30px; display: flex; align-items: center; gap: 2px; }
.ondas i { flex: 1; background: #c4bcb1; border-radius: 2px; min-width: 2px; }
.ondas i.on { background: var(--brand); }
.ch-voz time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 34px; text-align: right; }
.ch-fact { border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 12px; margin: 3px 0 4px; width: min(300px, 62vw); display: grid; gap: 4px; }
.ch-fact .top { display: flex; align-items: center; gap: 10px; }
.ch-fact .top img { width: 34px; height: 34px; border-radius: 8px; object-fit: contain; border: 1px solid var(--line); padding: 2px; }
.ch-fact .top b { font-size: 14px; } .ch-fact .top small { display: block; color: var(--muted); font-size: 12px; }
.ch-fact dl { margin: 6px 0 2px; display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: 13.5px; }
.ch-fact dt { color: var(--muted); } .ch-fact dd { margin: 0; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.ch-fact-ver { margin-top: 4px; min-height: 38px; border-radius: 9px; border: 1px solid var(--line2); background: #fff; font-weight: 700; font-size: 13.5px; display: grid; place-items: center; color: var(--ink); text-decoration: none; }
.ch-fact-ver:hover { background: #faf8f5; }
.ch-fact.anulada { opacity: .75; }
.ch-anul { justify-self: start; background: var(--danger-soft); color: var(--danger); font-size: 12px; font-weight: 700; border-radius: 99px; padding: 1px 9px; }

.ch-escr { padding: 0 clamp(12px, 3vw, 32px); color: var(--muted); font-size: 13px; min-height: 24px; display: flex; align-items: center; gap: 8px; }
.puntos { display: inline-flex; gap: 3px; }
.puntos i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: ch-pt 1.2s infinite; }
.puntos i:nth-child(2) { animation-delay: .15s; } .puntos i:nth-child(3) { animation-delay: .3s; }
@keyframes ch-pt { 0%, 60%, 100% { opacity: .25; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }

/* Escribir */
.ch-red { background: var(--card); border-top: 1px solid var(--line); padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); display: flex; align-items: flex-end; gap: 6px; position: relative; }
.ch-red textarea { flex: 1; min-width: 0; resize: none; min-height: 44px; max-height: 140px; padding: 10px 14px; border: 1px solid var(--line2); border-radius: 22px; background: var(--bg); font-size: 16px; line-height: 1.4; }
.ch-red textarea:focus { outline: none; border-color: var(--brand); background: #fff; box-shadow: 0 0 0 3px var(--brand-soft); }
.ch-r { width: 44px; height: 44px; border-radius: 50%; border: 0; background: transparent; color: var(--muted); display: grid; place-items: center; flex: none; cursor: pointer; }
.ch-r:hover { background: #f1ede8; color: var(--ink); }
.ch-r svg { width: 22px; height: 22px; }
.ch-r.enviar { background: var(--brand); color: #fff; }
.ch-r.enviar:hover { background: var(--brand-ink); color: #fff; }
.ch-red.grabando-on > :not(.ch-grab):not(input) { visibility: hidden; }
.ch-grab { position: absolute; inset: 10px 14px calc(10px + env(safe-area-inset-bottom)); display: flex; align-items: center; gap: 6px; }
.ch-grabando { flex: 1; display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 14px; border-radius: 22px; background: #fdecea; color: var(--danger); font-weight: 700; }
.ch-grabando .rec { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: ch-rec 1s infinite; }
@keyframes ch-rec { 50% { opacity: .2; } }
.ch-grabando time { font-variant-numeric: tabular-nums; }
.ch-grabando small { color: #9b4a40; font-weight: 400; margin-left: auto; white-space: nowrap; }

/* Sin chat abierto (PC) */
.ch-vacio { flex: 1; display: grid; place-content: center; justify-items: center; gap: 8px; text-align: center; color: var(--muted); padding: 24px; }
.ch-vacio svg { width: 54px; height: 54px; color: #c9c1b7; }
.ch-vacio b { color: var(--ink); font-size: 17px; } .ch-vacio p { margin: 0; max-width: 340px; font-size: 14px; }

/* Modales del chat */
.modal-card.ch-modal { max-width: 480px; }
.ch-modal .ch-buscar { margin: 4px 0 10px; }
.cf-lista { display: grid; gap: 2px; max-height: min(52vh, 420px); overflow-y: auto; margin: 0 -6px 14px; padding: 0 6px; }
.cf-fila { display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 8px; border: 0; background: none; border-radius: 10px; text-align: left; cursor: pointer; color: var(--ink); }
.cf-fila:hover:not(:disabled) { background: #f6f3ef; }
.cf-fila:disabled { opacity: .5; cursor: default; }
.cf-fila > b { flex: none; font-size: 13px; color: var(--brand-ink); min-width: 52px; }
.cf-fila > span:not(.cava) { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.cf-fila .cava, .ch-noti .cava { flex: none; display: grid; }
.cf-fila strong { font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cf-fila small { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cf-fila em { font-style: normal; font-weight: 700; font-size: 13.5px; flex: none; font-variant-numeric: tabular-nums; }
div.cf-fila { cursor: default; }
div.cf-fila:hover { background: none; }
.ch-checkp input { width: 20px; height: 20px; accent-color: var(--brand); flex: none; }
.ch-crear { width: 100%; margin-bottom: 10px; }
.ch-adm { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.ch-nota { font-size: 13.5px; }
.ch-per { display: grid; justify-items: center; text-align: center; gap: 6px; margin-bottom: 10px; }
.ch-per p { margin: 0 !important; }
.ch-form { display: grid; gap: 12px; }
.ch-form .ch-fila b { font-size: 14px; }
.ch-check { display: flex; gap: 12px; align-items: flex-start; padding: 12px; border: 1px solid var(--line2); border-radius: 12px; cursor: pointer; }
.ch-check input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--brand); flex: none; }
.ch-check span { display: flex; flex-direction: column; } .ch-check small { color: var(--muted); font-size: 13px; }
.ch-form .cf-lista { margin-bottom: 0; max-height: 34vh; }
.ch-form .modal-acc { margin-top: 2px; }

/* Visor de fotos y aviso de mensaje nuevo */
.ch-visor { position: fixed; inset: 0; background: rgba(20,18,17,.9); display: grid; place-items: center; z-index: 60; padding: 20px; }
.ch-visor img { max-width: 100%; max-height: 90dvh; border-radius: 12px; }
.ch-visor button { position: absolute; top: calc(16px + env(safe-area-inset-top)); right: 16px; width: 46px; height: 46px; border-radius: 50%; border: 0; background: rgba(255,255,255,.16); color: #fff; display: grid; place-items: center; cursor: pointer; }
.ch-visor button svg { width: 22px; height: 22px; }
.ch-noti { position: fixed; top: calc(14px + env(safe-area-inset-top)); right: 16px; width: min(360px, calc(100vw - 32px)); background: rgba(255,255,255,.98); border: 1px solid var(--line);
  border-radius: 16px; box-shadow: 0 12px 40px rgba(0,0,0,.18); padding: 12px 14px; display: flex; gap: 12px; align-items: flex-start; z-index: 55; cursor: pointer; text-align: left; color: var(--ink);
  transform: translateY(-16px); opacity: 0; visibility: hidden; transition: transform .35s cubic-bezier(.2,.9,.3,1.1), opacity .2s, visibility .2s; }
.ch-noti.ver { transform: none; opacity: 1; visibility: visible; }
.ch-noti span { min-width: 0; }
.ch-noti small { color: var(--muted); font-size: 12px; display: block; }
.ch-noti b { font-size: 14px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-noti p { margin: 2px 0 0; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (prefers-reduced-motion: reduce) { .puntos i, .ch-grabando .rec { animation: none; } .ch-noti { transition: none; } }

/* Tableta: sin menú lateral, con barra de abajo */
@media (max-width: 1023px) {
  .vista.vista-chat { left: 0; }
  .ch { height: calc(var(--ch-alto, 100dvh) - var(--tab-h)); grid-template-columns: 300px minmax(0, 1fr); }
}
/* Celular: una pantalla a la vez; con el chat abierto se esconde la barra de abajo */
@media (max-width: 760px) {
  .ch { grid-template-columns: minmax(0, 1fr); }
  .ch .ch-conv { display: none; }
  .ch.abierto .ch-lista { display: none; }
  .ch.abierto .ch-conv { display: flex; }
  body.ch-abierta .tabbar { display: none; }
  body.ch-abierta .ch { height: var(--ch-alto, 100dvh); }
  .ch-lcab { padding: 14px 12px 8px; }
  .ch-chats { padding: 0 4px 12px; }
  .ch-ccab { padding: 8px 8px; gap: 8px; min-height: 60px; }
  .ch-volver { display: grid !important; }
  .ch-msg { max-width: 92%; }
  .ch-red { padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); gap: 2px; }
  .ch-r { width: 42px; height: 42px; }
  .ch-grab { inset: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
  .ch-grabando small { display: none; }
  .ch-noti { right: 12px; left: 12px; width: auto; }
}
@media (max-width: 380px) {
  .ch-r { width: 38px; height: 38px; }
  .ch-r svg { width: 20px; height: 20px; }
}

/* Fotos pegadas o arrastradas */
.ch-previa { display: grid; place-items: center; background: #f3efe9; border-radius: 12px; padding: 8px; margin-bottom: 12px; max-height: 46vh; overflow: auto; }
.ch-previa img { max-width: 100%; max-height: 42vh; border-radius: 8px; display: block; }
.ch-previa.varias { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; place-items: stretch; }
.ch-previa.varias img { width: 100%; aspect-ratio: 1; object-fit: cover; max-height: none; }
.ch-conv.soltar { outline: 3px dashed var(--brand); outline-offset: -10px; background: var(--brand-soft); }
#cp-f .modal-acc { margin-top: 14px; }

/* Cámara en vivo */
.ch-cam { position: fixed; inset: 0; z-index: 70; background: #000; display: grid; place-items: center; overflow: hidden; }
.ch-cam video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.ch-cam.espejo video { transform: scaleX(-1); }
.ch-cam-msg { position: absolute; color: #fff; font-size: 15px; margin: 0; }
.ch-cam-x { position: absolute; top: calc(16px + env(safe-area-inset-top)); right: 16px; width: 46px; height: 46px; border-radius: 50%; border: 0; background: rgba(255,255,255,.18); color: #fff; display: grid; place-items: center; cursor: pointer; }
.ch-cam-x svg, .ch-cam-girar svg { width: 24px; height: 24px; }
.ch-cam-barra { position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 24px calc(22px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; background: linear-gradient(transparent, rgba(0,0,0,.55)); }
.ch-cam-disp { width: 74px; height: 74px; border-radius: 50%; border: 5px solid #fff; background: rgba(255,255,255,.25); cursor: pointer; padding: 0; transition: transform .12s, background .12s; }
.ch-cam-disp:active { transform: scale(.92); background: #fff; }
.ch-cam-disp:disabled { opacity: .45; cursor: default; }
.ch-cam-girar { justify-self: end; width: 52px; height: 52px; border-radius: 50%; border: 0; background: rgba(255,255,255,.18); color: #fff; display: grid; place-items: center; cursor: pointer; }
.ch-cam.flash::after { content: ''; position: absolute; inset: 0; background: #fff; animation: chFlash .25s ease-out forwards; pointer-events: none; }
@keyframes chFlash { from { opacity: .9; } to { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .ch-cam.flash::after { animation: none; opacity: 0; } }
