/* Customer chat widget — Atención al cliente Driver Solution
   Scope: clases con prefijo .dscb-
   Coexistencia con .btn-whatsapp-float: el widget se apila por encima.
*/

.dscb-launcher,
.dscb-panel,
.dscb-panel * {
  box-sizing: border-box;
  font-family: "Montserrat", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.dscb-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ─── Launcher (burbuja flotante) ─────────────────────────────────────── */

.dscb-launcher {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 9998;
  width: 64px;
  height: 64px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #006cff;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 108, 255, 0.32);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
  -webkit-tap-highlight-color: transparent;
}

.dscb-launcher:hover,
.dscb-launcher:focus-visible {
  background: #0057d4;
  box-shadow: 0 10px 30px rgba(0, 108, 255, 0.42);
  transform: translateY(-1px);
  outline: none;
}

.dscb-launcher svg {
  width: 28px;
  height: 28px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Variante con avatar (foto de Maite) */
.dscb-launcher--avatar {
  background: #eaf3ff;
  overflow: hidden;
  border: 2px solid #fff;
  box-shadow: 0 8px 24px rgba(6, 24, 51, 0.28);
  position: fixed; /* heredado de .dscb-launcher */
}

.dscb-launcher--avatar:hover,
.dscb-launcher--avatar:focus-visible {
  background: #eaf3ff;
  box-shadow: 0 12px 32px rgba(6, 24, 51, 0.36);
}

.dscb-launcher-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
  border-radius: 50%;
  pointer-events: none;
}

/* Apila encima del botón flotante de WhatsApp si está presente */
body:has(.btn-whatsapp-float) .dscb-launcher {
  bottom: 96px;
}

.dscb-launcher[hidden] {
  display: none !important;
}

/* ─── Panel ──────────────────────────────────────────────────────────── */

.dscb-panel {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 9999;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 540px;
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(15, 23, 42, 0.22);
  overflow: hidden;
  border: 1px solid rgba(15, 23, 42, 0.08);
}

.dscb-panel[hidden] {
  display: none !important;
}

/* Móvil (portrait): panel pegado abajo, anclado al borde, con espacio para teclado. */
@media (max-width: 480px) {
  .dscb-panel {
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: 85vh;
    height: 85dvh;
    max-height: 85vh;
    max-height: 85dvh;
    border-radius: 16px 16px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* Móvil landscape: pantallas cortas, panel a pantalla completa. */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .dscb-panel {
    right: 0;
    left: 0;
    top: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ─── Cabecera ───────────────────────────────────────────────────────── */

.dscb-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: #006cff;
  color: #fff;
  flex-shrink: 0;
}

.dscb-header-id {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.dscb-header-avatar {
  position: relative;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  overflow: hidden;
  background: #eaf3ff;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(6, 24, 51, 0.25);
}

.dscb-header-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}

.dscb-header-text {
  min-width: 0;
}

.dscb-header h2 {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.dscb-header-sub {
  display: block;
  font-size: 0.72rem;
  font-weight: 500;
  opacity: 0.85;
  margin-top: 2px;
}

.dscb-close {
  width: 32px;
  height: 32px;
  border: 0;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.dscb-close:hover,
.dscb-close:focus-visible {
  background: rgba(255, 255, 255, 0.28);
  outline: none;
}

.dscb-close svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ─── Mensajes ───────────────────────────────────────────────────────── */

.dscb-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f5f8fc;
  scroll-behavior: smooth;
}

.dscb-msg {
  max-width: 86%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 0.92rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

/* Fila bot: avatar + burbuja */
.dscb-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 100%;
}

.dscb-row-bot {
  align-self: flex-start;
  max-width: 92%;
}

.dscb-msg-avatar {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 50%;
  overflow: hidden;
  background: #eaf3ff;
  border: 1px solid rgba(15, 23, 42, 0.08);
  box-shadow: 0 1px 3px rgba(6, 24, 51, 0.12);
  align-self: flex-end;
}

.dscb-msg-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}

.dscb-row-bot .dscb-msg-bot {
  align-self: auto;
}

.dscb-msg-bot {
  align-self: flex-start;
  background: #fff;
  color: #0f172a;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-bottom-left-radius: 4px;
}

.dscb-msg-user {
  align-self: flex-end;
  background: #006cff;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.dscb-msg a {
  color: inherit;
  text-decoration: underline;
}

.dscb-msg-user a {
  color: #fff;
}

.dscb-status {
  font-size: 0.78rem;
  color: #64748b;
  text-align: center;
  padding: 4px 8px;
}

.dscb-status[hidden] {
  display: none;
}

.dscb-typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 4px;
  padding: 10px 14px;
  background: #fff;
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}

.dscb-typing[hidden] {
  display: none;
}

.dscb-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #94a3b8;
  animation: dscb-blink 1.2s infinite ease-in-out both;
}

.dscb-typing span:nth-child(2) {
  animation-delay: 0.18s;
}

.dscb-typing span:nth-child(3) {
  animation-delay: 0.36s;
}

@keyframes dscb-blink {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.9); }
  40% { opacity: 1; transform: scale(1); }
}

/* ─── Composer ───────────────────────────────────────────────────────── */

.dscb-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid rgba(15, 23, 42, 0.08);
  background: #fff;
  flex-shrink: 0;
}

.dscb-composer textarea {
  flex: 1;
  min-height: 40px;
  max-height: 120px;
  padding: 9px 12px;
  border: 1px solid rgba(15, 23, 42, 0.16);
  border-radius: 10px;
  resize: none;
  font: inherit;
  font-size: 16px; /* >=16px evita zoom automático en iOS al focar */
  line-height: 1.4;
  color: #0f172a;
  background: #f8fafc;
}

.dscb-composer textarea:focus {
  outline: 2px solid rgba(0, 108, 255, 0.35);
  outline-offset: 0;
  border-color: #006cff;
}

.dscb-send {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: #006cff;
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease;
}

.dscb-send:hover,
.dscb-send:focus-visible {
  background: #0057d4;
  outline: none;
}

.dscb-send:disabled {
  background: #cbd5e1;
  cursor: not-allowed;
}

.dscb-send svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ─── Footer mini-disclaimer ────────────────────────────────────────── */

.dscb-foot {
  font-size: 0.7rem;
  color: #94a3b8;
  text-align: center;
  padding: 4px 12px 8px;
  background: #fff;
  border-top: 0;
}

/* ─── Tap targets en móvil/táctil (>=44x44 recomendado por WCAG/Apple) ── */

@media (max-width: 768px), (hover: none) and (pointer: coarse) {
  .dscb-close {
    width: 44px;
    height: 44px;
  }
  .dscb-send {
    width: 44px;
    height: 44px;
  }
  .dscb-launcher {
    width: 64px;
    height: 64px;
  }
}

/* ─── Tablets/portátil bajo: panel un poco más ancho ─────────────────── */

@media (min-width: 481px) and (max-width: 768px) {
  .dscb-panel {
    width: 400px;
    height: min(580px, calc(100vh - 40px));
    height: min(580px, calc(100dvh - 40px));
  }
}

/* ─── Reducción de movimiento: respeta la preferencia del sistema ────── */

@media (prefers-reduced-motion: reduce) {
  .dscb-launcher,
  .dscb-close,
  .dscb-send,
  .dscb-messages {
    transition: none;
    scroll-behavior: auto;
  }
  .dscb-typing span {
    animation: none;
    opacity: 0.7;
  }
}
