/* ==========================================================================
   MOBIX v30.138.90 - Chat de Viaje Premium
   Estilos de Chat de Viaje Híbrido, Vidrio Esmerilado & Mobile-Safe
   ========================================================================== */

/* --- Botones Flotantes de Chat (Estilo Espejo) --- */
.btn-ride-chat {
  /* No declaramos posición absoluta aquí; se hereda o gestiona por selector específico */
  width: 48px !important;
  height: 48px !important;
  border-radius: 50% !important;
  
  /* Glassmorphism Oscuro Premium */
  background: rgba(18, 18, 22, 0.85) !important;
  backdrop-filter: blur(12px) !important;
  -webkit-backdrop-filter: blur(12px) !important;
  
  /* Trazado Gris Fino de 0.5px (Idéntico a recenter-btn y lupa) y Sombra Suave */
  border: 0.5px solid rgba(220, 220, 225, 0.6) !important;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.35) !important;
  
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 0 !important;
  margin: 0 !important;
  cursor: pointer !important;
  z-index: 1012 !important;
  
  /* Feedback Físico Táctil */
  transition: transform 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94), box-shadow 0.2s ease !important;
  touch-action: manipulation;
}

/* Blindaje de Ocultamiento contra display: flex !important */
.btn-ride-chat.hidden {
  display: none !important;
}

.btn-ride-chat:active {
  transform: scale(0.92) !important;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2) !important;
}

.btn-ride-chat svg {
  width: 22px;
  height: 22px;
  filter: drop-shadow(0px 2px 4px rgba(0, 0, 0, 0.4));
}

/* --- Posicionamiento Específico Cliente (Lugar de la Lupa) --- */
#btn-client-ride-chat {
  position: fixed !important;
  left: max(24px, env(safe-area-inset-left)) !important;
  right: auto !important;
  z-index: 1020 !important; /* Superior al .hud-backdrop (1005) para interacción táctil y click */
  /* Hereda el bottom exacto de los controles flotantes del mapa del cliente */
}

/* --- Posicionamiento Específico Conductor (20px sobre cancelar) --- */
.floating-action-bar #btn-driver-ride-chat {
  position: absolute !important;
  left: 15px !important;
  bottom: 68px !important; /* 48px de alto del botón Cancelar + 20px de separación */
  z-index: 1011 !important;
}

/* --- Overlay del Chat Expandido (Mobile Bottom Drawer) --- */
.mox-chat-overlay {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  background: rgba(0, 0, 0, 0.6) !important;
  backdrop-filter: blur(15px) !important;
  -webkit-backdrop-filter: blur(15px) !important;
  z-index: 20005 !important;
  
  display: flex !important;
  flex-direction: column !important;
  justify-content: flex-end !important; /* Estilo Drawer desde abajo */
  
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.mox-chat-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* Tarjeta del Chat */
.mox-chat-card {
  width: 100% !important;
  height: 85dvh !important; /* Se expande en la gran mayoría de la pantalla usando dvh */
  max-height: calc(100dvh - env(safe-area-inset-top) - 10px) !important;
  background: rgba(10, 10, 12, 0.96) !important;
  
  border-top-left-radius: 28px !important;
  border-top-right-radius: 28px !important;
  border: 1px solid rgba(255, 255, 255, 0.08) !important;
  border-bottom: none !important;
  
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.65) !important;
  
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
  
  /* Anti-Selección de Texto en Android para prevenir vibraciones hápticas de sistema */
  user-select: none !important;
  -webkit-user-select: none !important;
  
  /* Animación de entrada estilo iOS Bottom Sheet */
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.19, 1, 0.22, 1);
}

.mox-chat-overlay.active .mox-chat-card {
  transform: translateY(0);
}

/* --- MODO ARRASTRE: Optimización GPU 60fps (v30.138.105) ---
   Durante el gesto de arrastre, se desactivan TODOS los efectos costosos:
   - backdrop-filter: blur() → Re-renderiza el fondo completo cada frame (~40ms)
   - box-shadow: 40px spread → Recalcula bordes difusos cada transform (~8ms)
   - border semi-transparente → Fuerza composición alpha por frame
   - transition → Elimina el easing que compite con el touch directo
   
   Se promueve la tarjeta a GPU compositor layer con will-change y translate3d.
   El overlay usa opacity pura (compositor-only, cero repaint).
   
   Resultado: Solo propiedades "compositor-only" (transform + opacity) mutan
   durante el arrastre, logrando 60fps en iOS Safari y Android WebView. */
.mox-chat-overlay.mox-chat-dragging {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  transition: none !important;
}

.mox-chat-dragging .mox-chat-card {
  will-change: transform !important;
  box-shadow: none !important;
  border-color: transparent !important;
  transition: none !important;
}

/* --- Header del Chat --- */
.mox-chat-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: rgba(18, 18, 22, 0.8);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.25);
  z-index: 10;
}

.chat-user-profile {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-avatar-circle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 215, 0, 0.1);
  border: 1px solid rgba(255, 215, 0, 0.35);
  font-size: 1.1rem;
}

.chat-user-details h4 {
  color: #ffffff;
  font-size: 0.95rem;
  font-weight: 700;
  margin: 0 0 2px 0;
  font-family: "Montserrat", sans-serif;
  letter-spacing: 0.3px;
}

.chat-status-sub {
  color: #2ecc71;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-status-sub::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  background: #2ecc71;
  border-radius: 50%;
  box-shadow: 0 0 6px #2ecc71;
}

.btn-close-chat {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.7);
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}

.btn-close-chat:active {
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
}

/* --- Área de Mensajes --- */
.mox-chat-messages-container {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  scrollbar-width: none; /* Firefox */
}

.mox-chat-messages-container::-webkit-scrollbar {
  display: none; /* Safari/Chrome */
}

/* Burbujas de Mensaje */
.mox-chat-bubble {
  max-width: 75% !important;
  width: fit-content !important;
  display: flex !important;
  flex-direction: column !important;
  padding: 10px 14px !important;
  margin-bottom: 12px !important;
  line-height: 1.35 !important;
  font-size: 0.92rem !important;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15) !important;
  word-wrap: break-word !important;
  white-space: pre-wrap !important;
  box-sizing: border-box !important;
  
  /* Anti-Selección de Texto en Android para prevenir vibraciones hápticas de sistema */
  user-select: none !important;
  -webkit-user-select: none !important;
}

/* Estilo Cliente (Azul/Gris Esmerilado) */
.mox-chat-bubble.client-bubble {
  align-self: flex-start !important;
  align-items: flex-start !important;
  background: rgba(30, 41, 59, 0.8) !important;
  color: #f1f5f9 !important;
  border: 1px solid rgba(255, 255, 255, 0.05) !important;
  border-radius: 18px 18px 18px 4px !important;
}

/* Estilo Conductor (Dorado Corporativo) */
.mox-chat-bubble.driver-bubble {
  align-self: flex-end !important;
  align-items: flex-end !important;
  background: linear-gradient(135deg, #ffd700, #ffb900) !important;
  color: #121212 !important;
  font-weight: 600 !important;
  border-radius: 18px 18px 4px 18px !important;
  box-shadow: 0 4px 15px rgba(255, 215, 0, 0.18) !important;
}

.bubble-meta {
  font-size: 0.65rem !important;
  margin-top: 6px !important;
  opacity: 0.6 !important;
  align-self: flex-end !important;
  width: 100% !important;
  text-align: right !important;
}

.client-bubble .bubble-meta {
  color: #94a3b8 !important;
}

.driver-bubble .bubble-meta {
  color: rgba(18, 18, 18, 0.7) !important;
}

/* --- Zona de Arrastre Superior (Cupertino Pill) --- */
.mox-chat-drag-zone {
  width: 100% !important;
  height: 24px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  background: rgba(18, 18, 22, 0.8) !important;
  cursor: grab !important;
  flex-shrink: 0 !important;
  touch-action: none !important; /* Previene el bounce o scroll nativo de la página */
  z-index: 12 !important;
  border-top-left-radius: 28px !important;
  border-top-right-radius: 28px !important;
}

.mox-chat-drag-zone:active {
  cursor: grabbing !important;
}

.mox-chat-drag-handle {
  width: 44px !important;
  height: 5px !important;
  border-radius: 3px !important;
  background: rgba(255, 255, 255, 0.25) !important;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4) !important;
  transition: background 0.2s, transform 0.2s !important;
}

.mox-chat-drag-zone:hover .mox-chat-drag-handle {
  background: rgba(255, 255, 255, 0.45) !important;
  transform: scaleX(1.05) !important;
}

/* --- Caja de Entrada de Chat (Mobile Anchor) --- */
.mox-chat-input-area {
  flex-shrink: 0;
  background: #0f0f12;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom)) 16px !important; /* Acolchado inferior inteligente para notch */
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  z-index: 10;
  box-sizing: border-box;
}

.mox-chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.mox-chat-input-area textarea {
  flex: 1;
  min-width: 0;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 22px;
  padding: 10px 16px;
  color: #ffffff;
  font-family: inherit;
  font-size: 0.95rem;
  resize: none;
  outline: none;
  min-height: 22px;
  max-height: 90px;
  overflow-y: auto;
  line-height: 1.3;
  margin: 0;
  box-sizing: border-box;
  transition: border-color 0.2s;
}

.mox-chat-input-area textarea:focus {
  border-color: rgba(255, 215, 0, 0.5);
}

.btn-send-chat {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border-radius: 50%;
  border: none;
  background: #ffd700;
  color: #121212;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(255, 215, 0, 0.3);
  margin: 0;
}

.btn-send-chat:active {
  transform: scale(0.92);
}

.btn-send-chat svg {
  transform: translateX(1px);
}

/* Indicador de Mensajes No Leídos (Notificación Flotante) */
.chat-unread-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ff3b30;
  border: 2px solid rgba(18, 18, 22, 1);
  color: #ffffff;
  font-size: 0.65rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(255, 59, 48, 0.4);
  animation: pop-bounce 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes pop-bounce {
  0% { transform: scale(0); }
  70% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

/* ==========================================================================
   COREOGRAFÍA TÁCTIL DEL MAPA (Deslizamiento de Lupa en el Cliente)
   ========================================================================== */
body.user-is-interacting #btn-client-ride-chat {
  --mox-tx: -100px;
  opacity: 0 !important;
  pointer-events: none !important;
  transform: translate(var(--mox-tx), var(--mox-ty, 0px)) !important;
  transition:
    transform 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94) 0s,
    opacity 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94) 0s !important;
}

#btn-client-ride-chat {
  transition:
    transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94) 0.08s,
    opacity 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94) 0.08s,
    bottom 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94) !important;
}
