/* Contenedor principal del chat */
#ldai-chat-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Burbuja del chat */
#ldai-chat-bubble {
    width: 60px;
    height: 60px;
    border-radius: 50%;
   background: var(--ldai-accent);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

#ldai-chat-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(0, 0, 0, 0.2);
}

#ldai-chat-bubble.chat-open {
    background: #ff6b6b;
    transform: rotate(45deg);
}

#ldai-chat-bubble span {
    position: absolute;
    top: -35px;
    right: 0;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 8px 12px;
    border-radius: 20px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

#ldai-chat-bubble:hover span {
    opacity: 1;
}

#ldai-chat-icon {
    font-size: 24px;
    transition: transform 0.3s ease;
}

#ldai-chat-bubble.chat-open #ldai-chat-icon {
    transform: rotate(-45deg);
}

/* Ventana del chat - CORREGIDO */
/* Ventana del chat - CORREGIDO */
#ldai-chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 500px;
    max-height: calc(100vh - 120px);
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: none !important; /* FORZAR OCULTO INICIALMENTE */
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
}

/* Estado visible del chat */
#ldai-chat-window.chat-visible {
    display: flex !important;
    opacity: 1;
    transform: translateY(0);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Header del chat */
#ldai-chat-header {
    background: var(--ldai-accent);
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    flex-shrink: 0; /* No se encoge */
}

#ldai-chat-close {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s ease;
}

#ldai-chat-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Área de mensajes - CORREGIDO */
#ldai-chat-messages {
    flex: 1; /* Ocupa el espacio disponible */
    padding: 15px;
    overflow-y: auto; /* Scroll vertical */
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0; /* Permite que flex funcione correctamente */
}

#ldai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

#ldai-chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

#ldai-chat-messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

#ldai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Mensajes */
.message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    word-wrap: break-word;
    animation: messageSlideIn 0.3s ease;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.user-message {
    align-self: flex-end;
    align-items: flex-end;
}

.ai-message {
    align-self: flex-start;
    align-items: flex-start;
}

.message-content {
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.4;
    position: relative;
    word-break: break-word;
}

.user-message .message-content {
   background: var(--ldai-accent);
    color: white;
    border-bottom-right-radius: 4px;
}

.ai-message .message-content {
    background: white;
    color: #333;
    border: 1px solid #e1e5e9;
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 11px;
    color: #999;
    margin-top: 4px;
    padding: 0 16px;
}

/* Indicador de pensamiento */
.thinking-message .message-content {
    display: flex;
    align-items: center;
    gap: 10px;
    font-style: italic;
    color: #666;
}

.thinking-dots {
    display: flex;
    gap: 4px;
}

.thinking-dots span {
    width: 6px;
    height: 6px;
    background: #667eea;
    border-radius: 50%;
    animation: thinking 1.4s infinite ease-in-out;
}

.thinking-dots span:nth-child(1) { animation-delay: -0.32s; }
.thinking-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes thinking {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Área de input - CORREGIDO */
#ldai-chat-input {
    padding: 15px 20px;
    background: white;
    border-top: 1px solid #e1e5e9;
    display: flex;
    gap: 10px;
    align-items: center;
    flex-shrink: 0; /* No se encoge NUNCA */
    position: relative; /* Asegurar posicionamiento */
    z-index: 10; /* Por encima de mensajes */
}

#ldai-message-input {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 25px;
    padding: 12px 16px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.3s ease;
    resize: none; /* Prevenir resize */
}

#ldai-message-input:focus {
    border-color: #667eea;
}

#ldai-send-button {
   background: var(--ldai-accent);
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
    flex-shrink: 0; /* No se encoge */
}

#ldai-send-button:hover {
    transform: scale(1.1);
}

#ldai-send-button:active {
    transform: scale(0.95);
}

#ldai-send-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Botones de acción */
.ldai-action-button {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.3s ease;
    margin-top: 8px;
}

.ldai-action-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(79, 172, 254, 0.3);
}

/* Formulario de reset de contraseña */
.reset-form {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    margin-top: 10px;
}

.reset-form label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: #333;
    font-size: 13px;
}

.reset-form input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-bottom: 10px;
    font-size: 13px;
    box-sizing: border-box;
}

.reset-form button {
    background: #28a745;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    width: 100%;
}

.reset-form button:hover {
    background: #218838;
}

/* Responsividad - MEJORADO */
@media (max-width: 480px) {
    #ldai-chat-window {
        width: calc(100vw - 40px);
        height: calc(100vh - 120px);
        bottom: 80px;
        right: 20px;
        left: 20px;
        max-height: calc(100vh - 120px);
    }
    
    #ldai-chat-container {
        right: 20px;
        bottom: 20px;
    }
    
    #ldai-chat-messages {
        padding: 12px;
    }
    
    #ldai-chat-input {
        padding: 12px 15px;
    }
    
    .message {
        max-width: 90%;
    }
}

@media (max-width: 380px) {
    #ldai-chat-messages {
        padding: 10px;
        gap: 10px;
    }
    
    #ldai-chat-input {
        padding: 10px 12px;
        gap: 8px;
    }
    
    .message {
        max-width: 95%;
    }
    
    .message-content {
        padding: 10px 12px;
        font-size: 13px;
    }
}

/* Estados adicionales */
.message.error .message-content {
    background: #ff6b6b;
    color: white;
}

.message.success .message-content {
    background: #51cf66;
    color: white;
}

.message.warning .message-content {
    background: #ffd43b;
    color: #333;
}

/* Efectos hover mejorados */
.message-content:hover {
    transform: translateY(-1px);
    transition: transform 0.2s ease;
}

/* Auto-scroll helper */
.ldai-scroll-to-bottom {
    scroll-behavior: smooth;
}

/* Estados de carga */
.ldai-chat-loading {
    opacity: 0.7;
    pointer-events: none;
}

.ldai-chat-loading #ldai-send-button {
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

/* Mejoras visuales adicionales */
#ldai-chat-window.focused {
    box-shadow: 0 15px 50px rgba(0, 0, 0, 0.2);
}

/* Badge de notificación */
#ldai-chat-bubble::after {
    content: '';
    position: absolute;
    top: -2px;
    right: -2px;
    width: 12px;
    height: 12px;
    background: #ff4757;
    border-radius: 50%;
    border: 2px solid white;
    opacity: 0;
    transform: scale(0);
    transition: all 0.3s ease;
}

#ldai-chat-bubble.has-notification::after {
    opacity: 1;
    transform: scale(1);
}

/* CORRECCIÓN ESPECÍFICA PARA EL PROBLEMA DE SCROLL */

#ldai-chat-messages {
    flex: 1 1 auto !important; /* Flex grow y shrink */
    padding: 15px;
    overflow-y: scroll !important; /* Forzar scroll */
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 12px;
    height: 0; /* Importante para flex */
    max-height: 350px; /* Altura máxima específica */
}

#ldai-chat-input {
    flex: 0 0 auto !important; /* No crece ni se encoge */
    padding: 15px 20px;
    background: white;
    border-top: 1px solid #e1e5e9;
    display: flex;
    gap: 10px;
    align-items: center;
    height: 70px; /* Altura fija */
    box-sizing: border-box;
}

/* Forzar scroll visible */
#ldai-chat-messages::-webkit-scrollbar {
    width: 8px !important;
    display: block !important;
}

#ldai-chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1 !important;
    border-radius: 4px;
}

#ldai-chat-messages::-webkit-scrollbar-thumb {
    background: #888 !important;
    border-radius: 4px;
}

#ldai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #555 !important;
}

/* Header con avatar */
#ldai-chat-header .ldai-agent {
    display: flex;
    align-items: center;
    gap: 10px;
}
#ldai-chat-header .ldai-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255,255,255,.35);
}
#ldai-chat-header .ldai-agent-name {
    font-weight: 700;
    line-height: 1.1;
}
#ldai-chat-header .ldai-agent-status {
    font-size: 12px;
    opacity: .85;
}

/* Punto verde "En línea" */
#ldai-chat-header .ldai-agent-status { display:flex; align-items:center; gap:6px; font-size:12px; opacity:.9; }
#ldai-chat-header .ldai-status-dot { width:8px; height:8px; border-radius:50%; background:#2ecc71; box-shadow:0 0 0 2px rgba(0,0,0,.12); }

/* Splash de bienvenida centrado */
#ldai-welcome-splash {
  display: none; /* se muestra via JS si no hay mensajes */
  height: 220px;
  margin: 10px 16px 0;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(0,0,0,0.02), rgba(0,0,0,0.04));
  display: flex; /* se activa en JS */
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
}
.ldai-splash-avatar {
  width: 72px; height: 72px; border-radius: 50%;
  object-fit: cover;
  border: 3px solid rgba(0,0,0,.08);
}
.ldai-splash-title {
  font-weight: 700; font-size: 18px; line-height: 1.25;
}
.ldai-splash-subtitle {
  font-size: 13px; opacity:.8;
}


/* Botón enviar circular con icono */
#ldai-send-button{
  width:44px;height:44px;border-radius:9999px;
  display:flex;align-items:center;justify-content:center;
  padding:0;border:0;color:#fff;background:var(--ldai-accent);
  box-shadow:none;cursor:pointer;
}
#ldai-send-button svg{display:block;width:18px;height:18px}

/* FAB: centrado con icono SVG */
#ldai-chat-bubble{
  width:56px;height:56px;border-radius:9999px;
  background:var(--ldai-accent);
  display:flex;align-items:center;justify-content:center;
  box-shadow:none;cursor:pointer;
}
#ldai-chat-bubble .ldai-fab-svg{
  width:24px;height:24px;fill:#fff;display:block;pointer-events:none;
}
#ldai-chat-bubble:hover{ filter:brightness(1.06); }


#ldai-chat-container { display: none; }

/* Asegurar que el chat se muestre correctamente */
#ldai-chat-container.loaded {
    display: block !important;
}

body.ldai-chat-open #ldai-chat-bubble {
    background: #ff6b6b;
}

body.ldai-chat-open #ldai-chat-bubble .ldai-fab-svg {
    transform: rotate(45deg);
}

#ldai-chat-bubble.chat-open::before,
#ldai-chat-bubble.chat-open::after{
  display: none;
}

/* === ONDAS ANIMADAS PARA LA BURBUJA === */

/* Ondas de pulso alrededor del FAB */
#ldai-chat-bubble::before,
#ldai-chat-bubble::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: var(--ldai-accent);
    opacity: 0;
    z-index: -1;
    pointer-events: none;
    animation: ldai-ripple 2.5s ease-out infinite;
}

#ldai-chat-bubble::after {
    animation-delay: 1.25s; /* Segunda onda desfasada */
}

@keyframes ldai-ripple {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.6;
    }
    50% {
        opacity: 0.3;
    }
    100% {
        transform: translate(-50%, -50%) scale(2.2);
        opacity: 0;
    }
}

/* Onda adicional más sutil */
#ldai-chat-bubble {
    position: relative;
}

#ldai-chat-bubble::before {
    animation-duration: 2.5s;
}

#ldai-chat-bubble::after {
    animation-duration: 2.5s;
    animation-delay: 1.25s;
}

/* Pausar ondas al pasar el mouse */
#ldai-chat-bubble:hover::before,
#ldai-chat-bubble:hover::after {
    animation-play-state: paused;
    opacity: 0.4;
    transform: translate(-50%, -50%) scale(1.1);
    transition: all 0.3s ease;
}

/* Detener ondas cuando el chat está abierto */
body.ldai-chat-open #ldai-chat-bubble::before,
body.ldai-chat-open #ldai-chat-bubble::after {
    animation-play-state: paused;
    opacity: 0;
}

@keyframes ldai-ripple {
    0% {
        transform: translate(-50%, -50%) scale(0.8);
        opacity: 0.8;
    }
    25% {
        opacity: 0.6;
    }
    50% {
        opacity: 0.4;
        transform: translate(-50%, -50%) scale(1.5);
    }
    75% {
        opacity: 0.2;
        transform: translate(-50%, -50%) scale(1.8);
    }
    100% {
        transform: translate(-50%, -50%) scale(2.5);
        opacity: 0;
    }
}

/* Efecto de "bounce" sutil en la burbuja */
#ldai-chat-bubble {
    animation: ldai-gentle-bounce 4s ease-in-out infinite;
}

@keyframes ldai-gentle-bounce {
    0%, 100% {
        transform: translateY(0px);
    }
    50% {
        transform: translateY(-3px);
    }
}

/* Pausar bounce al hover o cuando está abierto */
#ldai-chat-bubble:hover,
body.ldai-chat-open #ldai-chat-bubble {
    animation-play-state: paused;
}

/* Pausar ondas al pasar el mouse o cuando el chat está abierto */
#ldai-chat-bubble:hover::before,
#ldai-chat-bubble:hover::after{
  animation-play-state: paused;
  opacity:.4;
}
body.ldai-chat-open #ldai-chat-bubble::before,
body.ldai-chat-open #ldai-chat-bubble::after{
  display:none;
}

/* Verificación de estado inicial */
#ldai-chat-container:not(.initialized) #ldai-chat-window {
    display: none !important;
    visibility: hidden;
}

#ldai-chat-container.initialized #ldai-chat-window {
    visibility: visible;
}


/* Tercera onda para efecto más llamativo */
#ldai-chat-bubble {
    position: relative;
}

#ldai-chat-bubble .ldai-third-wave {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid var(--ldai-accent);
    background: transparent;
    opacity: 0;
    z-index: -1;
    pointer-events: none;
    animation: ldai-border-pulse 3s ease-in-out infinite;
    animation-delay: 0.5s;
}

@keyframes ldai-border-pulse {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.7;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.3);
        opacity: 0.3;
    }
    100% {
        transform: translate(-50%, -50%) scale(1.6);
        opacity: 0;
    }
}


/* Estados controlados por JavaScript */
#ldai-chat-bubble.waves-paused::before,
#ldai-chat-bubble.waves-paused::after,
#ldai-chat-bubble.waves-paused .ldai-third-wave {
    animation-play-state: paused !important;
    opacity: 0 !important;
}

#ldai-chat-bubble.waves-active::before,
#ldai-chat-bubble.waves-active::after,
#ldai-chat-bubble.waves-active .ldai-third-wave {
    animation-play-state: running !important;
}

/* Efecto especial de "llamada de atención" cada 10 segundos */
@keyframes ldai-attention-grab {
    0%, 90%, 100% {
        transform: translateY(0px) scale(1);
    }
    5% {
        transform: translateY(-5px) scale(1.05);
    }
    10% {
        transform: translateY(0px) scale(1);
    }
}

#ldai-chat-bubble {
    animation: 
        ldai-gentle-bounce 4s ease-in-out infinite,
        ldai-attention-grab 15s ease-in-out infinite;
}

/* Mejorar la presentación del indicador de pensamiento */
.thinking-message .message-content {
    display: flex;
    align-items: center;
    gap: 8px;
    font-style: italic;
    color: #666;
    padding: 12px 16px;
}

.thinking-dots {
    display: flex;
    gap: 3px;
    margin-left: 5px;
}

.thinking-dots span {
    width: 6px;
    height: 6px;
    background: #667eea;
    border-radius: 50%;
    animation: thinking 1.4s infinite ease-in-out;
}

.thinking-dots span:nth-child(1) { animation-delay: -0.32s; }
.thinking-dots span:nth-child(2) { animation-delay: -0.16s; }
.thinking-dots span:nth-child(3) { animation-delay: 0s; }

@keyframes thinking {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}