/* AI Widget Styles */
.ai-fab-container {
    position: fixed;
    bottom: 120px;
    right: 2rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 1rem;
}

.ai-fab-btn {
    width: 65px;
    height: 65px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ff6b00, #ff944d);
    border: none;
    box-shadow: 0 10px 25px rgba(255, 107, 0, 0.5);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    border: 3px solid white;
}

.ai-fab-btn:hover {
    transform: scale(1.1);
}

.ai-fab-btn svg {
    width: 30px;
    height: 30px;
    fill: white;
}

.ai-fab-label {
    background: #1e293b;
    color: white;
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    white-space: nowrap;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    opacity: 1;
    /* ✅ Visible por defecto */
    transform: translateX(0);
    /* ✅ Sin desplazamiento inicial */
    transition: all 0.3s ease;
    pointer-events: none;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.ai-fab-container:hover .ai-fab-label {
    transform: scale(1.05);
    /* ✨ Pequeño efecto al hover en lugar de aparecer */
}

/* Animación de pulso para el botón */
@keyframes ai-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 107, 0, 0.4);
    }

    70% {
        box-shadow: 0 0 0 15px rgba(255, 107, 0, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(255, 107, 0, 0);
    }
}

.ai-fab-btn {
    animation: ai-pulse 2s infinite;
}

.ai-chat-window {
    position: fixed;
    bottom: 200px;
    right: 2rem;
    width: 380px;
    height: 550px;
    background: white;
    border-radius: 1.5rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 10000;
    transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
    border: 1px solid rgba(226, 232, 240, 0.8);
    backdrop-filter: blur(10px);
}

.ai-chat-window.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px) scale(0.95);
}

/* Modo Caja Integrada (Admin) */
.ai-chat-window.admin-box {
    position: relative;
    bottom: auto;
    right: auto;
    width: 100%;
    height: 100%;
    max-width: none;
    box-shadow: none;
    border-radius: 0.5rem;
}

.ai-header {
    background: linear-gradient(135deg, #1e293b, #0f172a);
    padding: 1rem;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ai-header h4 {
    margin: 0;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.ai-status-dot {
    width: 8px;
    height: 8px;
    background: #22c55e;
    border-radius: 50%;
    display: inline-block;
    box-shadow: 0 0 5px #22c55e;
}

.ai-header-logo {
    width: 24px !important;
    height: 24px !important;
    border-radius: 50% !important;
    object-fit: cover !important;
    margin-right: 8px !important;
    display: inline-block !important;
    vertical-align: middle !important;
}

.ai-close-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
}

.ai-close-btn:hover {
    color: white;
}

.ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.ai-msg {
    max-width: 80%;
    padding: 0.875rem 1.125rem;
    border-radius: 1.125rem;
    font-size: 0.95rem;
    line-height: 1.5;
    position: relative;
    word-wrap: break-word;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
}

.ai-msg-assistant {
    background: #f1f5f9;
    color: #0f172a;
    align-self: flex-start;
    border-bottom-left-radius: 0.25rem;
    border: 1px solid #e2e8f0;
}

.ai-msg-user {
    background: linear-gradient(135deg, #ff6b00, #ff8533);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 0.25rem;
    box-shadow: 0 4px 12px rgba(255, 107, 0, 0.2);
}

.ai-input-area {
    padding: 1rem;
    border-top: 1px solid #e2e8f0;
    display: flex;
    gap: 0.5rem;
    background: white;
}

.ai-input {
    flex: 1;
    padding: 0.5rem 1rem;
    border: 1px solid #e2e8f0;
    border-radius: 1.5rem;
    outline: none;
    font-size: 0.9rem;
    transition: border-color 0.2s;
}

.ai-input:focus {
    border-color: #ff6b00;
}

.ai-send-btn {
    background: #1e293b;
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.ai-send-btn:hover {
    background: #ff6b00;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 12px;
    background: white;
    border-radius: 1rem;
    width: fit-content;
    border: 1px solid #e2e8f0;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: #94a3b8;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* Markdown Styles inside messages */
.ai-msg p {
    margin: 0 0 0.5rem 0;
}

.ai-msg p:last-child {
    margin: 0;
}

.ai-msg ul {
    padding-left: 1.2rem;
    margin: 0.5rem 0;
}

.ai-msg code {
    background: rgba(0, 0, 0, 0.1);
    padding: 0.1rem 0.3rem;
    border-radius: 0.25rem;
    font-family: monospace;
}

/* Lead Capture & Habeas Data */
.ai-lead-capture {
    background: #f1f5f9;
    padding: 0.75rem 1rem;
    border-top: 1px solid #e2e8f0;
    font-size: 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    transition: all 0.3s ease;
}

.ai-lead-capture.hidden {
    display: none;
}

.ai-legal-banner {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    color: #64748b;
    line-height: 1.2;
}

.ai-legal-banner input {
    margin-top: 2px;
}

.ai-legal-banner a {
    color: #ff6b00;
    text-decoration: underline;
}

.ai-submit-lead-btn {
    background: #ff6b00;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
    font-size: 0.85rem;
}

.ai-submit-lead-btn:hover:not(:disabled) {
    background: #e55a00;
    transform: translateY(-1px);
}

.ai-submit-lead-btn:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
    opacity: 0.7;
}

.ai-date-divider {
    text-align: center;
    font-size: 0.7rem;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 1rem 0;
    position: relative;
}

.ai-date-divider::before,
.ai-date-divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 30%;
    height: 1px;
    background: #e2e8f0;
}

.ai-date-divider::before {
    left: 0;
}

.ai-date-divider::after {
    right: 0;
}

/* 📱 Optmización para Celulares */
@media (max-width: 600px) {
    .ai-fab-container {
        bottom: 1rem;
        right: 1.5rem;
        gap: 0.5rem;
    }

    .ai-fab-btn {
        width: 55px;
        height: 55px;
    }

    .ai-chat-window {
        width: 100%;
        height: 85vh;
        /* Estilo Bottom Sheet */
        max-height: 85vh;
        bottom: 0;
        right: 0;
        left: 0;
        border-radius: 20px 20px 0 0;
        z-index: 10001;
        box-shadow: 0 -5px 20px rgba(0, 0, 0, 0.15);
        border-top: 1px solid rgba(255, 255, 255, 0.5);
    }

    .ai-chat-window:not(.hidden) {
        display: flex;
        animation: slideUpMobile 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
    }

    @keyframes slideUpMobile {
        from {
            transform: translateY(100%);
        }

        to {
            transform: translateY(0);
        }
    }

    .ai-header {
        padding: 1.2rem 1rem;
    }

    .ai-messages {
        padding: 0.8rem;
    }

    .ai-msg {
        max-width: 90%;
        font-size: 0.9rem;
    }

    .ai-input-area {
        padding: 0.8rem;
        padding-bottom: env(safe-area-inset-bottom, 0.8rem);
    }
}