/* ============================================================================
   Chat de usuarios (#6) + notas de voz (#8) — estilo moderno tipo Messenger.
   El dock de ventanas se ancla abajo-derecha PERO por encima del botón flotante
   "Reportar incidencia" (.inc-fab, bottom:20 height:50) para no solaparse.
   ============================================================================ */
:root {
  --chat-accent: #003a68;
  --chat-accent-2: #2563eb;
  --chat-bg: #ffffff;
  --chat-line: #e6ebf1;
  --chat-mut: #64748b;
  --chat-in: #f1f5f9;
  --chat-out: #003a68;
}
/* La app funciona SIEMPRE en tema claro: el chat no debe seguir el modo oscuro del
   sistema operativo (si no, quedaba texto oscuro sobre paneles oscuros = ilegible). */

/* --- Paneles desplegables bajo los iconos de la barra superior --- */
.chat-pop {
  position: absolute; top: 46px; right: 0; width: 320px; max-width: 92vw;
  background: var(--chat-bg); border: 1px solid var(--chat-line); border-radius: 14px;
  box-shadow: 0 24px 60px -12px rgba(2, 20, 45, .35); overflow: hidden; z-index: 12500;
  animation: chatPop .14s ease-out;
}
@keyframes chatPop { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.chat-pop[hidden] { display: none; }
.chat-pop-head {
  display: flex; align-items: center; gap: 8px; padding: 12px 14px; font-weight: 800;
  color: #fff; background: linear-gradient(120deg, var(--chat-accent), var(--chat-accent-2)); font-size: .95rem;
}
.chat-pop-head .chat-count { margin-left: auto; font-size: .72rem; font-weight: 700; opacity: .9; }
.chat-pop-list { max-height: 60vh; overflow-y: auto; }
.chat-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 13px; cursor: pointer;
  border-bottom: 1px solid var(--chat-line); transition: background .12s;
}
.chat-row:hover { background: var(--chat-in); }
.chat-av { position: relative; width: 40px; height: 40px; flex: 0 0 40px; }
.chat-av img, .chat-av .chat-av-ph {
  width: 40px; height: 40px; border-radius: 50%; object-fit: cover; display: block;
  border: 1px solid var(--chat-line); background: #dbe4ee;
}
.chat-dot {
  position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px; border-radius: 50%;
  background: #cbd5e1; border: 2px solid var(--chat-bg);
}
.chat-dot.on { background: #16a34a; box-shadow: 0 0 0 2px rgba(22,163,74,.18); }
.chat-meta { min-width: 0; flex: 1; }
.chat-name { font-weight: 700; font-size: .9rem; color: var(--text-primary, #0f172a); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-sub { font-size: .74rem; color: var(--chat-mut); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-badge-n {
  margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: #e11d48; color: #fff; font-size: .72rem; font-weight: 800; display: inline-flex;
  align-items: center; justify-content: center;
}
.chat-empty { padding: 22px 14px; text-align: center; color: var(--chat-mut); font-size: .85rem; }

/* --- Dock de ventanas de conversación (abajo-derecha, sobre el FAB) --- */
#chat-dock {
  position: fixed; right: 20px; bottom: 84px; z-index: 12060;
  display: flex; align-items: flex-end; gap: 14px; pointer-events: none;
}
@media (max-width: 760px) { #chat-dock { bottom: 138px; right: 10px; left: 10px; justify-content: flex-end; } }

.chat-win {
  pointer-events: auto; width: 330px; max-width: 92vw; height: 440px; max-height: 70vh;
  background: var(--chat-bg); border: 1px solid var(--chat-line); border-radius: 14px 14px 12px 12px;
  box-shadow: 0 26px 64px -14px rgba(2, 20, 45, .5); display: flex; flex-direction: column;
  overflow: hidden; animation: chatWin .16s ease-out;
}
@keyframes chatWin { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
.chat-win.min { height: 46px; }
.chat-win.min .chat-win-body, .chat-win.min .chat-win-foot { display: none; }
.chat-win-head {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px; cursor: pointer;
  color: #fff; background: linear-gradient(120deg, var(--chat-accent), var(--chat-accent-2));
}
.chat-win-head .chat-av img, .chat-win-head .chat-av .chat-av-ph { width: 30px; height: 30px; }
.chat-win-head .chat-av { width: 30px; height: 30px; flex: 0 0 30px; }
.chat-win-title { min-width: 0; flex: 1; }
.chat-win-title .n { font-weight: 800; font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-win-title .s { font-size: .7rem; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-win-btns { display: flex; gap: 2px; }
.chat-win-btns button { background: transparent; border: 0; color: #fff; width: 28px; height: 28px; border-radius: 7px; cursor: pointer; font-size: .95rem; opacity: .9; }
.chat-win-btns button:hover { background: rgba(255,255,255,.18); opacity: 1; }
.chat-win-body { flex: 1; overflow-y: auto; padding: 12px 12px 4px; background: var(--chat-bg); display: flex; flex-direction: column; gap: 3px; }
.chat-day { text-align: center; font-size: .68rem; color: var(--chat-mut); margin: 8px 0 4px; }
.chat-b { max-width: 82%; padding: 8px 11px; border-radius: 15px; font-size: .87rem; line-height: 1.35; word-wrap: break-word; position: relative; }
.chat-b.me { align-self: flex-end; background: var(--chat-out); color: #fff; border-bottom-right-radius: 5px; }
.chat-b.them { align-self: flex-start; background: var(--chat-in); color: var(--text-primary, #0f172a); border-bottom-left-radius: 5px; }
.chat-b .who { font-size: .68rem; font-weight: 800; opacity: .85; margin-bottom: 2px; }
.chat-b .t { display: block; font-size: .62rem; opacity: .7; margin-top: 3px; text-align: right; }
.chat-b audio { display: block; width: 200px; max-width: 100%; margin-top: 3px; height: 34px; }
.chat-b .trans { font-size: .78rem; opacity: .92; margin-top: 4px; font-style: italic; border-top: 1px dashed rgba(148,163,184,.4); padding-top: 4px; }
.chat-win-foot { border-top: 1px solid var(--chat-line); padding: 8px; display: flex; align-items: flex-end; gap: 6px; background: var(--chat-bg); }
.chat-win-foot textarea {
  flex: 1; resize: none; border: 1px solid var(--chat-line); border-radius: 18px; padding: 8px 12px;
  font-size: .87rem; font-family: inherit; max-height: 90px; min-height: 20px; background: var(--chat-in); color: var(--text-primary, #0f172a);
}
.chat-win-foot button {
  flex: 0 0 auto; width: 38px; height: 38px; border-radius: 50%; border: 0; cursor: pointer;
  color: #fff; font-size: 1rem; display: inline-flex; align-items: center; justify-content: center;
}
.chat-send { background: var(--chat-accent); }
.chat-send:hover { background: var(--chat-accent-2); }
.chat-mic { background: #64748b; }
.chat-mic:hover { background: #475569; }
.chat-mic.rec { background: #e11d48; animation: chatPulse 1s infinite; }
@keyframes chatPulse { 0%,100% { box-shadow: 0 0 0 0 rgba(225,29,72,.5); } 50% { box-shadow: 0 0 0 7px rgba(225,29,72,0); } }
.chat-recbar { flex: 1; display: flex; align-items: center; gap: 8px; font-size: .8rem; color: #e11d48; font-weight: 700; }
.chat-recbar .live { flex: 1; color: var(--chat-mut); font-weight: 500; font-style: italic; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Nota de voz en composición (previsualización antes de enviar) */
.chat-voz-prev { flex: 1; display: flex; align-items: center; gap: 6px; font-size: .78rem; color: var(--chat-mut); }
.chat-voz-prev audio { height: 32px; flex: 1; min-width: 0; }

/* --- Zumbido (nudge tipo MSN Messenger) --- */
.chat-zumbido { background: #f59e0b; }
.chat-zumbido:hover { background: #d97706; }
.chat-zumbido:disabled { opacity: .5; cursor: default; }
.chat-zumbido-msg {
  align-self: center; margin: 6px 0; padding: 5px 12px; border-radius: 12px;
  background: rgba(245, 158, 11, .15); color: #b45309; font-size: .78rem; font-weight: 700;
  display: inline-flex; align-items: center; gap: 6px;
}
/* La sacudida clásica del zumbido */
.chat-buzz { animation: chatBuzz .8s cubic-bezier(.36,.07,.19,.97) both; }
@keyframes chatBuzz {
  10%, 90% { transform: translate(-2px, 1px); }
  20%, 80% { transform: translate(4px, -2px); }
  30%, 50%, 70% { transform: translate(-8px, 3px); }
  40%, 60% { transform: translate(8px, -3px); }
  0%, 100% { transform: translate(0, 0); }
}
/* Buscador en los paneles de chat (GASCA) */
.chat-pop-q { padding: 8px 10px; border-bottom: 1px solid var(--chat-line); background: #f8fafc; }
.chat-pop-q input { width: 100%; height: 32px; border: 1px solid var(--chat-line); border-radius: 8px; padding: 0 10px; font: inherit; font-size: .84rem; background: #fff; color: #0f172a; outline: none; }
.chat-pop-q input:focus { border-color: var(--chat-accent-2); }
/* Ventana minimizada con mensajes nuevos (INC-00014) */
.chat-win.min.chat-win-nuevo .chat-win-head { animation: chatNuevo 1.2s ease-in-out infinite; }
@keyframes chatNuevo { 0%, 100% { filter: none; } 50% { filter: brightness(1.35) saturate(1.3); } }

/* INC-00019: adjuntos y capturas */
.chat-clip { background: transparent; border: 0; color: var(--chat-mut, #64748b); cursor: pointer; width: 30px; flex: none; font-size: .95rem; }
.chat-clip:hover { color: #0B3C73; }
.chat-win.chat-drop { box-shadow: 0 0 0 3px #3b82f6 inset; }
.chat-adj-prev { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-top: 1px solid rgba(148,163,184,.3); font-size: .76rem; color: var(--chat-mut, #64748b); }
.chat-adj-prev img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; border: 1px solid #e2e8f0; }
.chat-adj-prev span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-adj-prev button { background: transparent; border: 0; color: #e11d48; cursor: pointer; }
.chat-b .chat-img { display: block; max-width: 220px; max-height: 180px; border-radius: 10px; margin: 2px 0 4px; cursor: zoom-in; border: 1px solid rgba(0,0,0,.08); }
.chat-b .chat-file { display: inline-flex; align-items: center; gap: 6px; padding: 6px 9px; border-radius: 9px; background: rgba(255,255,255,.65); color: #0B3C73; text-decoration: none; margin: 2px 0 4px; max-width: 100%; }
.chat-b .chat-file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }
.chat-b .chat-file small { opacity: .7; }
.chat-lightbox { position: fixed; inset: 0; z-index: 100000; background: rgba(15,23,42,.88); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 20px; }
.chat-lightbox img { max-width: 95vw; max-height: 85vh; border-radius: 8px; box-shadow: 0 20px 60px rgba(0,0,0,.5); background: #fff; }
.chat-lb-bar { display: flex; gap: 10px; }
.chat-lb-bar a, .chat-lb-bar button { background: #fff; color: #0f172a; border: 0; border-radius: 8px; padding: 8px 14px; font: inherit; font-size: .85rem; cursor: pointer; text-decoration: none; }
/* INC-00037: separador «Desconectados» en el panel de usuarios en línea */
.chat-sep { padding: 8px 14px 4px; font-size: .68rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: #94a3b8; border-top: 1px solid #f1f5f9; margin-top: 4px; }
