/**
 * Daraxa Chat Basic — widget.css
 * Dark theme — identidad corporativa Daraxa AI.
 *
 * Todas las clases tienen prefijo `dx-chat-` para evitar conflictos
 * con temas de WordPress u otros estilos externos.
 *
 * Las CSS custom properties están en #dx-chat-root, no en :root,
 * para no contaminar el namespace global de la página.
 */

/* ============================================================
   TOKENS / VARIABLES
   ============================================================ */
#dx-chat-root {
  /* Colores principales Daraxa */
  --dx-primary:        #d6b15f;
  --dx-primary-dark:   #b88a2e;
  --dx-primary-light:  rgba(214, 177, 95, 0.12);
  --dx-primary-glow:   rgba(214, 177, 95, 0.25);
  --dx-accent:         #6c8cef;
  --dx-green:          #22c55e;
  --dx-red:            #f76c6c;
  --dx-mint:           #6cefc8;

  /* Fondos oscuros */
  --dx-bg-deep:        #050505;
  --dx-bg-card:        #0b0b0f;
  --dx-bg-elevated:    #0b0b0f;
  --dx-surface:        #0b0b0f;
  --dx-surface-2:      #050505;
  --dx-surface-3:      rgba(255, 255, 255, 0.05);

  /* Bordes */
  --dx-border:         rgba(255, 255, 255, 0.10);
  --dx-border-strong:  rgba(255, 255, 255, 0.18);
  --dx-border-gold:    rgba(214, 177, 95, 0.25);

  /* Texto */
  --dx-text:           #ffffff;
  --dx-text-muted:     #a3a3a3;
  --dx-text-subtle:    rgba(255, 255, 255, 0.35);
  --dx-text-inverse:   #ffffff;

  /* Sombras */
  --dx-shadow-sm:      0 1px 4px rgba(0, 0, 0, 0.6);
  --dx-shadow-md:      0 4px 12px rgba(0, 0, 0, 0.6);
  --dx-shadow-lg:      0 8px 28px rgba(0, 0, 0, 0.7);
  --dx-shadow-xl:      0 24px 64px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(255, 255, 255, 0.07);
  --dx-shadow-gold:    0 4px 20px rgba(214, 177, 95, 0.35);

  /* Radios */
  --dx-radius-sm:      6px;
  --dx-radius-md:      12px;
  --dx-radius-lg:      18px;
  --dx-radius-xl:      22px;
  --dx-radius-full:    9999px;

  /* Tipografía */
  --dx-font:           -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --dx-font-size:      14px;
  --dx-line-height:    1.55;
  --dx-transition:     0.2s ease;

  /* Layout */
  --dx-z-base:         99999;
  --dx-window-w:       380px;
  --dx-window-h:       620px;

  /* Alias legacy (referenciados por JS) */
  --dx-secondary:      #050505;
}

/* ============================================================
   ROOT WRAPPER
   ============================================================ */
.dx-chat-root {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--dx-z-base);
  font-family: var(--dx-font);
  font-size: var(--dx-font-size);
  line-height: var(--dx-line-height);
  color: var(--dx-text);
  box-sizing: border-box;
}

.dx-chat-root *,
.dx-chat-root *::before,
.dx-chat-root *::after {
  box-sizing: inherit;
  margin: 0;
  padding: 0;
}

/* ============================================================
   BURBUJA DE NOTIFICACIÓN
   ============================================================ */
.dx-chat-notification {
  position: absolute;
  bottom: 76px;
  right: 0;
  background: var(--dx-bg-card);
  border: 1px solid var(--dx-border-strong);
  color: var(--dx-text);
  padding: 11px 38px 11px 15px;
  border-radius: var(--dx-radius-lg) var(--dx-radius-lg) var(--dx-radius-sm) var(--dx-radius-lg);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: var(--dx-shadow-lg);
  opacity: 0;
  transform: translateY(8px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.dx-chat-notification--visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.dx-chat-notification-close {
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--dx-text-subtle);
  font-size: 12px;
  cursor: pointer;
  padding: 3px;
  line-height: 1;
  transition: color var(--dx-transition);
  font-family: var(--dx-font);
}

.dx-chat-notification-close:hover {
  color: var(--dx-text);
}

/* ============================================================
   BOTÓN LANZADOR (BURBUJA FLOTANTE)
   ============================================================ */
.dx-chat-launcher {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: var(--dx-radius-full);
  background: var(--dx-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--dx-shadow-gold), var(--dx-shadow-md);
  transition: background var(--dx-transition), transform var(--dx-transition), box-shadow var(--dx-transition);
  outline: none;
}

.dx-chat-launcher:hover {
  background: var(--dx-primary-dark);
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(214, 177, 95, 0.50), var(--dx-shadow-md);
}

.dx-chat-launcher:focus-visible {
  outline: 3px solid var(--dx-primary);
  outline-offset: 3px;
}

.dx-chat-launcher:active {
  transform: scale(0.96);
}

.dx-chat-launcher--open {
  background: var(--dx-bg-card);
  border: 1px solid var(--dx-border-strong);
  box-shadow: var(--dx-shadow-md);
}

.dx-chat-launcher--open:hover {
  background: var(--dx-bg-elevated);
  box-shadow: var(--dx-shadow-lg);
}

.dx-chat-launcher-icon {
  width: 24px;
  height: 24px;
  color: var(--dx-text-inverse);
  flex-shrink: 0;
}

/* ============================================================
   VENTANA DEL CHAT
   ============================================================ */
.dx-chat-window {
  position: absolute;
  bottom: 72px;
  right: 0;
  width: var(--dx-window-w);
  height: var(--dx-window-h);
  background: var(--dx-bg-card);
  border-radius: var(--dx-radius-xl);
  box-shadow: var(--dx-shadow-xl);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--dx-border);
  opacity: 0;
  transform: translateY(16px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.28s cubic-bezier(.22,.68,0,1.2),
              transform 0.28s cubic-bezier(.22,.68,0,1.2);
  will-change: transform, opacity;
}

.dx-chat-window--open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ============================================================
   CABECERA
   ============================================================ */
.dx-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--dx-bg-deep) 0%, var(--dx-bg-card) 100%);
  border-bottom: 1px solid var(--dx-border-gold);
  flex-shrink: 0;
}

.dx-chat-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dx-chat-header-avatar {
  width: 38px;
  height: 38px;
  border-radius: var(--dx-radius-full);
  background: var(--dx-primary-light);
  border: 1px solid var(--dx-border-gold);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--dx-primary);
}

.dx-chat-header-avatar svg {
  width: 22px;
  height: 22px;
}

.dx-chat-header-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dx-chat-header-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--dx-text-inverse);
  letter-spacing: -0.01em;
}

.dx-chat-header-status {
  font-size: 11px;
  color: var(--dx-text-muted);
  display: flex;
  align-items: center;
  gap: 5px;
}

.dx-chat-status-dot {
  width: 7px;
  height: 7px;
  border-radius: var(--dx-radius-full);
  background: var(--dx-primary);
  box-shadow: 0 0 0 2px var(--dx-primary-glow);
  animation: dx-chat-pulse 2.4s ease-in-out infinite;
}

@keyframes dx-chat-pulse {
  0%, 100% { box-shadow: 0 0 0 2px var(--dx-primary-glow); }
  50%       { box-shadow: 0 0 0 5px rgba(214, 177, 95, 0.10); }
}

.dx-chat-header-close {
  width: 32px;
  height: 32px;
  border-radius: var(--dx-radius-full);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--dx-border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--dx-text-muted);
  transition: background var(--dx-transition), color var(--dx-transition), border-color var(--dx-transition);
  flex-shrink: 0;
  font-family: var(--dx-font);
}

.dx-chat-header-close:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--dx-text);
  border-color: var(--dx-border-strong);
}

.dx-chat-header-close:focus-visible {
  outline: 2px solid var(--dx-primary);
  outline-offset: 2px;
}

.dx-chat-header-close svg {
  width: 18px;
  height: 18px;
}

/* ============================================================
   ÁREA DE MENSAJES
   ============================================================ */
.dx-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  background: var(--dx-bg-deep);
}

.dx-chat-messages::-webkit-scrollbar {
  width: 4px;
}
.dx-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}
.dx-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: var(--dx-radius-full);
}
.dx-chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.28);
}

/* ============================================================
   BURBUJAS DE MENSAJES
   ============================================================ */
.dx-chat-msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  max-width: 100%;
}

.dx-chat-msg--in {
  opacity: 1;
  transform: translateY(0);
}

/* Bot — alineado a la izquierda */
.dx-chat-msg--bot {
  align-self: flex-start;
  flex-direction: row;
  max-width: 88%;
}

.dx-chat-msg--bot .dx-chat-msg-bubble {
  background: rgba(255, 255, 255, 0.06);
  color: var(--dx-text);
  border: 1px solid var(--dx-border);
  border-radius: var(--dx-radius-md) var(--dx-radius-md) var(--dx-radius-md) var(--dx-radius-sm);
  box-shadow: var(--dx-shadow-sm);
}

/* Usuario — alineado a la derecha */
.dx-chat-msg--user {
  align-self: flex-end;
  flex-direction: row-reverse;
  max-width: 88%;
}

.dx-chat-msg--user .dx-chat-msg-bubble {
  width: max-content;
  max-width: 100%;
  background: linear-gradient(135deg, var(--dx-primary) 0%, var(--dx-primary-dark) 100%);
  color: #ffffff;
  border-radius: var(--dx-radius-md) var(--dx-radius-md) var(--dx-radius-sm) var(--dx-radius-md);
  box-shadow: 0 2px 10px rgba(214, 177, 95, 0.30);
}

.dx-chat-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--dx-radius-full);
  background: var(--dx-primary-light);
  border: 1px solid var(--dx-border-gold);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--dx-primary);
}

.dx-chat-msg-avatar svg {
  width: 16px;
  height: 16px;
}

.dx-chat-msg-bubble {
  padding: 10px 13px;
  font-size: 13.5px;
  line-height: 1.55;
  word-break: break-word;
}

.dx-chat-msg-bubble strong {
  font-weight: 700;
}

.dx-chat-msg-bubble small {
  font-size: 11px;
  display: block;
  margin-top: 4px;
  opacity: 0.7;
}

/* ============================================================
   INDICADOR DE ESCRITURA
   ============================================================ */
.dx-chat-typing {
  opacity: 1;
  transform: none;
}

.dx-chat-typing .dx-chat-msg-bubble {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 52px;
}

.dx-chat-typing-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: var(--dx-radius-full);
  background: rgba(255, 255, 255, 0.35);
  animation: dx-chat-bounce 1.3s ease-in-out infinite;
}

.dx-chat-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.dx-chat-typing-dot:nth-child(3) { animation-delay: 0.30s; }

@keyframes dx-chat-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%            { transform: translateY(-5px); }
}

/* ============================================================
   BADGE DE MODO DEMO
   ============================================================ */
.dx-chat-demo-badge {
  display: inline-block;
  background: rgba(108, 239, 200, 0.10);
  color: var(--dx-mint);
  border: 1px solid rgba(108, 239, 200, 0.25);
  border-radius: var(--dx-radius-full);
  font-size: 11px;
  padding: 2px 9px;
  margin-top: 5px;
  font-weight: 600;
}

/* ============================================================
   ÁREA DE ACCIONES (opciones, formularios, botones)
   ============================================================ */
.dx-chat-actions {
  padding: 8px 14px 10px;
  background: var(--dx-bg-card);
  border-top: 1px solid var(--dx-border);
  flex-shrink: 0;
}

/* ============================================================
   BOTONES DE OPCIÓN (bienvenida + pasos de pregunta)
   ============================================================ */
.dx-chat-options-grid {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.dx-chat-option-btn {
  width: 100%;
  padding: 9px 14px;
  border: 1px solid var(--dx-border);
  border-radius: var(--dx-radius-md);
  background: rgba(255, 255, 255, 0.04);
  color: var(--dx-text);
  font-family: var(--dx-font);
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: border-color var(--dx-transition), background var(--dx-transition),
              color var(--dx-transition), transform var(--dx-transition), box-shadow var(--dx-transition);
  line-height: 1.4;
}

.dx-chat-option-btn:hover {
  border-color: var(--dx-primary);
  background: var(--dx-primary-light);
  color: var(--dx-primary);
  transform: translateX(2px);
  box-shadow: 0 0 0 1px var(--dx-primary-light);
}

.dx-chat-option-btn:focus-visible {
  outline: 2px solid var(--dx-primary);
  outline-offset: 2px;
}

.dx-chat-option-btn:active {
  transform: scale(0.98);
}

/* ============================================================
   INPUT DE TEXTO INLINE (paso de tipo input)
   ============================================================ */
.dx-chat-inline-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.dx-chat-inline-input {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid var(--dx-border);
  border-radius: var(--dx-radius-md);
  font-family: var(--dx-font);
  font-size: 13.5px;
  color: var(--dx-text);
  background: rgba(255, 255, 255, 0.06);
  outline: none;
  transition: border-color var(--dx-transition), box-shadow var(--dx-transition), background var(--dx-transition);
}

.dx-chat-inline-input::placeholder {
  color: var(--dx-text-subtle);
}

.dx-chat-inline-input:focus {
  border-color: var(--dx-primary);
  background: rgba(255, 255, 255, 0.09);
  box-shadow: 0 0 0 3px var(--dx-primary-glow);
}

.dx-chat-inline-input.dx-chat-input--error {
  border-color: var(--dx-red);
  box-shadow: 0 0 0 3px rgba(247, 108, 108, 0.20);
}

.dx-chat-inline-send {
  width: 38px;
  height: 38px;
  border-radius: var(--dx-radius-full);
  background: var(--dx-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  flex-shrink: 0;
  transition: background var(--dx-transition), transform var(--dx-transition), box-shadow var(--dx-transition);
  font-family: var(--dx-font);
}

.dx-chat-inline-send:hover {
  background: var(--dx-primary-dark);
  transform: scale(1.07);
  box-shadow: var(--dx-shadow-gold);
}

.dx-chat-inline-send:focus-visible {
  outline: 2px solid var(--dx-primary);
  outline-offset: 2px;
}

.dx-chat-inline-send svg {
  width: 18px;
  height: 18px;
}

/* ============================================================
   FORMULARIO DE LEAD
   ============================================================ */
.dx-chat-lead-form {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.dx-chat-field-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.dx-chat-field-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--dx-text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.dx-chat-field-optional {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  opacity: 0.7;
}

.dx-chat-field-input {
  width: 100%;
  padding: 7px 11px;
  border: 1px solid var(--dx-border);
  border-radius: var(--dx-radius-md);
  font-family: var(--dx-font);
  font-size: 13px;
  color: var(--dx-text);
  background: rgba(255, 255, 255, 0.06);
  outline: none;
  transition: border-color var(--dx-transition), box-shadow var(--dx-transition), background var(--dx-transition);
  resize: none;
  appearance: none;
  -webkit-appearance: none;
}

.dx-chat-field-input::placeholder {
  color: var(--dx-text-subtle);
}

.dx-chat-field-input:focus {
  border-color: var(--dx-primary);
  background: rgba(255, 255, 255, 0.09);
  box-shadow: 0 0 0 3px var(--dx-primary-glow);
}

.dx-chat-field-textarea {
  min-height: 48px;
  resize: none;
}

.dx-chat-privacy {
  font-size: 10.5px;
  color: var(--dx-text-subtle);
  line-height: 1.4;
  border-top: 1px solid var(--dx-border);
  padding-top: 6px;
}

.dx-chat-form-error {
  font-size: 12px;
  color: var(--dx-red);
  font-weight: 500;
  min-height: 0;
  transition: min-height var(--dx-transition);
}

.dx-chat-form-error:not(:empty) {
  min-height: 18px;
}

.dx-chat-submit-btn {
  width: 100%;
  padding: 9px 16px;
  background: var(--dx-primary);
  color: #ffffff;
  border: none;
  border-radius: var(--dx-radius-md);
  font-family: var(--dx-font);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--dx-transition), transform var(--dx-transition), box-shadow var(--dx-transition);
  letter-spacing: 0.01em;
}

.dx-chat-submit-btn:hover:not(:disabled) {
  background: var(--dx-primary-dark);
  box-shadow: var(--dx-shadow-gold);
  transform: translateY(-1px);
}

.dx-chat-submit-btn:active:not(:disabled) {
  transform: translateY(0);
}

.dx-chat-submit-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.dx-chat-submit-btn:focus-visible {
  outline: 2px solid var(--dx-primary);
  outline-offset: 3px;
}

/* ============================================================
   BOTÓN DE REINICIO
   ============================================================ */
.dx-chat-restart-btn {
  width: 100%;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--dx-text-muted);
  border: 1px solid var(--dx-border);
  border-radius: var(--dx-radius-md);
  font-family: var(--dx-font);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--dx-transition), color var(--dx-transition),
              border-color var(--dx-transition), box-shadow var(--dx-transition);
}

.dx-chat-restart-btn:hover {
  background: var(--dx-primary-light);
  color: var(--dx-primary);
  border-color: var(--dx-primary);
  box-shadow: 0 0 0 1px var(--dx-primary-light);
}

.dx-chat-restart-btn:focus-visible {
  outline: 2px solid var(--dx-primary);
  outline-offset: 2px;
}

/* ============================================================
   PIE DEL WIDGET
   ============================================================ */
.dx-chat-footer {
  padding: 7px 14px;
  font-size: 11px;
  color: var(--dx-text-subtle);
  text-align: center;
  background: var(--dx-bg-deep);
  border-top: 1px solid var(--dx-border);
  flex-shrink: 0;
}

.dx-chat-footer-link {
  color: var(--dx-primary);
  text-decoration: none;
  font-weight: 600;
  transition: color var(--dx-transition);
}

.dx-chat-footer-link:hover {
  color: var(--dx-primary-dark);
}

/* ============================================================
   RESPONSIVE — MÓVIL
   ============================================================ */
@media (max-width: 480px) {
  .dx-chat-root {
    bottom: 16px;
    right: 12px;
    left: 12px;
  }

  .dx-chat-window {
    right: 0;
    left: 0;
    bottom: 72px;
    /* Fallback para navegadores sin soporte svh (Safari ≤15.3, Chrome ≤107) */
    height: calc(100vh - 110px);
    height: calc(100svh - 110px);
    min-height: 420px;
    max-height: 600px;
    border-radius: var(--dx-radius-lg);
  }

  .dx-chat-notification {
    right: 0;
    left: 0;
    white-space: normal;
    width: 100%;
    bottom: 72px;
  }

  .dx-chat-launcher {
    position: absolute;
    right: 0;
    bottom: 0;
  }

  .dx-chat-msg--bot,
  .dx-chat-msg--user {
    max-width: 92%;
  }
}

@media (max-width: 360px) {
  .dx-chat-window {
    height: calc(100vh - 100px);
    height: calc(100svh - 100px);
  }
}

/* ============================================================
   MOVIMIENTO REDUCIDO — accesibilidad del sistema operativo
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .dx-chat-window,
  .dx-chat-notification,
  .dx-chat-msg {
    transition: none !important;
  }

  .dx-chat-launcher {
    transition: background var(--dx-transition), box-shadow var(--dx-transition);
  }

  .dx-chat-typing-dot {
    animation: none !important;
    opacity: 0.4;
  }

  .dx-chat-status-dot {
    animation: none !important;
  }
}
