/**
 * AI Chatbot — Widget Frontend Styles
 *
 * @package AIChatbot
 * @since   1.0.0
 */

/* ──────────────────────────────────────────
   VARIABILI
   ────────────────────────────────────────── */
:root {
    --chatbot-widget-primary: #0073aa;
    --chatbot-widget-font: 'Inter', sans-serif;
    --chatbot-widget-radius: 14px;
    --chatbot-widget-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
    --chatbot-widget-z: 999999;
    --chatbot-mobile-width: 95;
    --chatbot-mobile-height: 85;
}

/* ──────────────────────────────────────────
   RESET SCOPING
   ────────────────────────────────────────── */
#ai-chatbot-widget,
#ai-chatbot-widget * {
    box-sizing: border-box;
    font-family: var(--chatbot-widget-font);
    line-height: 1.5;
}

/* ──────────────────────────────────────────
   PULSANTE FLOATING
   ────────────────────────────────────────── */
.chatbot-floating-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--chatbot-widget-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    z-index: var(--chatbot-widget-z);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.chatbot-floating-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}

.chatbot-floating-btn:active {
    transform: scale(0.95);
}

/* ──────────────────────────────────────────
   CTA TOOLTIP
   ────────────────────────────────────────── */
.chatbot-cta-tooltip {
    position: fixed;
    bottom: 32px;
    right: 94px;
    background: #fff;
    color: #1d1d1f;
    padding: 10px 16px;
    border-radius: 20px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    z-index: calc(var(--chatbot-widget-z) - 1);
    font-family: var(--chatbot-widget-font);
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 12px;
    animation: chatbotTooltipSlide 0.4s ease;
    max-width: 300px;
    cursor: pointer;
}

.chatbot-cta-tooltip.hidden {
    display: none !important;
}

.chatbot-cta-tooltip::after {
    content: '';
    position: absolute;
    right: -8px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 8px solid #fff;
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
}

.chatbot-cta-tooltip-text {
    color: var(--chatbot-widget-primary);
    font-weight: 600;
}

.chatbot-cta-tooltip-close {
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    padding: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
    flex-shrink: 0;
}

.chatbot-cta-tooltip-close:hover {
    background: #f0f0f0;
    color: #333;
}

@keyframes chatbotTooltipSlide {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ──────────────────────────────────────────
   FINESTRA CHAT
   ────────────────────────────────────────── */
.chatbot-window {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 380px;
    max-height: 560px;
    height: calc(100vh - 140px);
    background: #fff;
    border-radius: var(--chatbot-widget-radius);
    box-shadow: var(--chatbot-widget-shadow);
    z-index: var(--chatbot-widget-z);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: chatbotSlideIn 0.3s ease;
}

.chatbot-window.open {
    display: flex;
}

@keyframes chatbotSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ──────────────────────────────────────────
   HEADER
   ────────────────────────────────────────── */
.chatbot-header {
    background: var(--chatbot-widget-primary);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.chatbot-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chatbot-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
}

.chatbot-avatar-default {
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
}

.chatbot-header-name {
    display: block;
    font-weight: 600;
    font-size: 15px;
}

.chatbot-header-status {
    display: block;
    font-size: 12px;
    opacity: 0.8;
}

.chatbot-close-btn {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.chatbot-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ──────────────────────────────────────────
   AREA MESSAGGI
   ────────────────────────────────────────── */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

.chatbot-messages::-webkit-scrollbar {
    width: 4px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 2px;
}

/* ──────────────────────────────────────────
   BOLLE MESSAGGIO
   ────────────────────────────────────────── */
.chatbot-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    word-wrap: break-word;
    animation: chatbotMsgFade 0.3s ease;
}

@keyframes chatbotMsgFade {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.chatbot-msg-bot {
    background: #f0f2f5;
    color: #1d1d1f;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
}

.chatbot-msg-user {
    background: var(--chatbot-widget-primary);
    color: #fff;
    border-bottom-right-radius: 4px;
    align-self: flex-end;
}

.chatbot-msg-time {
    font-size: 11px;
    opacity: 0.6;
    margin-top: 4px;
    display: block;
}

.chatbot-msg-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
    font-size: 13px;
    text-align: center;
    align-self: center;
}

/* ──────────────────────────────────────────
   TYPING INDICATOR
   ────────────────────────────────────────── */
.chatbot-typing {
    padding: 0 16px 8px;
    flex-shrink: 0;
}

.chatbot-typing-dots {
    display: inline-flex;
    gap: 4px;
    padding: 8px 14px;
    background: #f0f2f5;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
}

.chatbot-typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #999;
    animation: chatbotTypingDot 1.4s infinite both;
}

.chatbot-typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.chatbot-typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes chatbotTypingDot {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ──────────────────────────────────────────
   QUICK REPLY BUTTONS
   ────────────────────────────────────────── */
.chatbot-quick-replies {
    padding: 8px 16px 0;
    flex-shrink: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-height: 100px;
    overflow-y: auto;
}

.chatbot-quick-replies.hidden {
    display: none;
}

.chatbot-quick-reply-btn {
    background: var(--chatbot-qr-bg, #fff);
    color: var(--chatbot-qr-text, var(--chatbot-widget-primary));
    border: var(--chatbot-qr-border-width, 1px) solid var(--chatbot-qr-border-color, var(--chatbot-widget-primary));
    border-radius: var(--chatbot-qr-border-radius, 16px);
    padding: 6px 14px;
    font-size: 13px;
    font-family: var(--chatbot-qr-font, var(--chatbot-widget-font));
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    flex-shrink: 0;
}

.chatbot-quick-reply-btn:hover {
    background: var(--chatbot-widget-primary);
    color: #fff;
    transform: translateY(-1px);
}

.chatbot-quick-reply-btn:active {
    transform: translateY(0);
}

/* ──────────────────────────────────────────
   INPUT AREA
   ────────────────────────────────────────── */
.chatbot-input-area {
    padding: 12px 16px;
    border-top: 1px solid #eee;
    flex-shrink: 0;
    background: #fff;
}

.chatbot-input-area form {
    display: flex;
    gap: 8px;
    align-items: center;
}

#chatbot-input {
    flex: 1;
    border: 1px solid #e0e0e0;
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: var(--chatbot-widget-font);
    outline: none;
    transition: border-color 0.2s;
    -webkit-appearance: none;
}

#chatbot-input:focus {
    border-color: var(--chatbot-widget-primary);
}

#chatbot-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--chatbot-widget-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.2s, opacity 0.2s;
}

#chatbot-send-btn:hover {
    transform: scale(1.08);
}

#chatbot-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ──────────────────────────────────────────
   MOBILE RESPONSIVE
   ────────────────────────────────────────── */
@media (max-width: 480px) {
    .chatbot-window {
        width: calc(var(--chatbot-mobile-width) * 1vw);
        height: calc(var(--chatbot-mobile-height) * 1vh);
        max-height: none;
        bottom: 80px;
        right: 8px;
        left: auto;
        border-radius: 12px;
    }

    .chatbot-floating-btn {
        width: 54px;
        height: 54px;
        bottom: 16px;
        right: 16px;
    }

    /* CTA tooltip su mobile */
    .chatbot-cta-tooltip {
        right: 80px;
        bottom: 24px;
        max-width: calc(100vw - 120px);
        font-size: 13px;
    }

    /* Quick replies su mobile */
    .chatbot-quick-reply-btn {
        font-size: 12px;
        padding: 5px 12px;
    }

    /* Previene zoom automatico su iOS/Android quando si tocca l'input */
    #chatbot-input {
        font-size: 16px;
    }
}

@media (max-width: 380px) {
    .chatbot-msg {
        max-width: 90%;
        font-size: 13px;
    }

    #chatbot-input {
        font-size: 16px; /* Previene zoom su iOS */
    }
}

/* ──────────────────────────────────────────
   SIDEBAR WIDGET
   ────────────────────────────────────────── */
.chatbot-sidebar-open-btn {
    display: inline-block;
    background: var(--chatbot-widget-primary, #0073aa);
    color: #fff;
    border: none;
    padding: 8px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    margin-top: 8px;
}

.chatbot-sidebar-open-btn:hover {
    opacity: 0.9;
}
