/* 
 * NF Chatbot Widget - v2.1.0
 * Stili completamente isolati dal tema del sito
 */

/* ============================================
   RESET - Isola dal tema del sito
   ============================================ */
#nf-chatbot-widget,
#nf-chatbot-widget *,
#nf-chatbot-widget *::before,
#nf-chatbot-widget *::after {
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    background: none !important;
    font: inherit !important;
    color: inherit !important;
    text-decoration: none !important;
    list-style: none !important;
    box-sizing: border-box !important;
    -webkit-tap-highlight-color: transparent !important;
}

/* Ripristina display per SVG */
#nf-chatbot-widget svg {
    display: inline-block !important;
    vertical-align: middle !important;
    overflow: visible !important;
}

#nf-chatbot-widget {
    /* Variabili CSS - sovrascritte dal JS */
    --nfc-primary: #171717;
    --nfc-primary-hover: #333333;
    
    /* Colori tema chiaro (default) */
    --nfc-bg: #ffffff;
    --nfc-bg-secondary: #f9f9f9;
    --nfc-bg-input: #f5f5f5;
    --nfc-text: #171717;
    --nfc-text-muted: #666666;
    --nfc-border: #e0e0e0;
    --nfc-bot-bg: #ffffff;
    --nfc-bot-text: #171717;
    
    display: block !important;
    position: fixed !important;
    bottom: 24px !important;
    z-index: 2147483647 !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
    font-size: 14px !important;
    line-height: 1.5 !important;
    color: var(--nfc-text) !important;
    -webkit-font-smoothing: antialiased !important;
    -moz-osx-font-smoothing: grayscale !important;
}

/* Tema scuro */
#nf-chatbot-widget.nfc-theme-dark {
    --nfc-bg: #1a1a1a;
    --nfc-bg-secondary: #111111;
    --nfc-bg-input: #2a2a2a;
    --nfc-text: #f0f0f0;
    --nfc-text-muted: #999999;
    --nfc-border: #333333;
    --nfc-bot-bg: #2a2a2a;
    --nfc-bot-text: #f0f0f0;
}

#nf-chatbot-widget.nf-chatbot-right { right: 24px !important; }
#nf-chatbot-widget.nf-chatbot-left { left: 24px !important; }

/* ============================================
   BUBBLE - Pulsante flottante
   ============================================ */
#nf-chatbot-widget .nf-chatbot-bubble {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 56px !important;
    height: 56px !important;
    border-radius: 50% !important;
    background-color: var(--nfc-primary) !important;
    border: none !important;
    cursor: pointer !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease !important;
}

#nf-chatbot-widget .nf-chatbot-bubble:hover {
    transform: scale(1.05) !important;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2) !important;
    background-color: var(--nfc-primary-hover) !important;
}

#nf-chatbot-widget .nf-chatbot-bubble:active {
    transform: scale(0.95) !important;
}

/* Icona chat (visibile quando chiuso) */
#nf-chatbot-widget .nf-chatbot-bubble .nf-chatbot-icon-chat {
    display: block !important;
    width: 24px !important;
    height: 24px !important;
}

#nf-chatbot-widget .nf-chatbot-bubble .nf-chatbot-icon-chat path,
#nf-chatbot-widget .nf-chatbot-bubble .nf-chatbot-icon-chat line {
    stroke: #ffffff !important;
    stroke-width: 2 !important;
    fill: none !important;
}

/* Icona X (nascosta di default) */
#nf-chatbot-widget .nf-chatbot-bubble .nf-chatbot-icon-close {
    display: none !important;
    width: 24px !important;
    height: 24px !important;
}

#nf-chatbot-widget .nf-chatbot-bubble .nf-chatbot-icon-close path,
#nf-chatbot-widget .nf-chatbot-bubble .nf-chatbot-icon-close line {
    stroke: #ffffff !important;
    stroke-width: 2 !important;
    fill: none !important;
}

/* Quando aperto: nascondi icona chat, mostra X */
#nf-chatbot-widget.nf-chatbot-widget-open .nf-chatbot-bubble .nf-chatbot-icon-chat {
    display: none !important;
}

#nf-chatbot-widget.nf-chatbot-widget-open .nf-chatbot-bubble .nf-chatbot-icon-close {
    display: block !important;
}

/* ============================================
   WINDOW - Finestra chat
   ============================================ */
#nf-chatbot-widget .nf-chatbot-window {
    display: none !important;
    flex-direction: column !important;
    position: absolute !important;
    bottom: 72px !important;
    width: 380px !important;
    height: 520px !important;
    max-height: calc(100vh - 100px) !important;
    background-color: var(--nfc-bg) !important;
    border-radius: 16px !important;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15) !important;
    overflow: hidden !important;
}

#nf-chatbot-widget.nf-chatbot-right .nf-chatbot-window { right: 0 !important; }
#nf-chatbot-widget.nf-chatbot-left .nf-chatbot-window { left: 0 !important; }

#nf-chatbot-widget .nf-chatbot-window.nf-chatbot-open {
    display: flex !important;
    animation: nfcFadeIn 0.2s ease-out !important;
}

@keyframes nfcFadeIn {
    from { opacity: 0; transform: translateY(10px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ============================================
   HEADER
   ============================================ */
#nf-chatbot-widget .nf-chatbot-header {
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
    padding: 16px 20px !important;
    background-color: var(--nfc-primary) !important;
    flex-shrink: 0 !important;
}

#nf-chatbot-widget .nf-chatbot-avatar {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 40px !important;
    height: 40px !important;
    border-radius: 50% !important;
    overflow: hidden !important;
    background-color: rgba(255, 255, 255, 0.2) !important;
    flex-shrink: 0 !important;
}

#nf-chatbot-widget .nf-chatbot-avatar img {
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
}

#nf-chatbot-widget .nf-chatbot-header-info {
    display: block !important;
    flex: 1 !important;
    min-width: 0 !important;
}

#nf-chatbot-widget .nf-chatbot-title {
    display: block !important;
    font-size: 15px !important;
    font-weight: 600 !important;
    color: #ffffff !important;
    margin: 0 !important;
}

#nf-chatbot-widget .nf-chatbot-status {
    display: block !important;
    font-size: 12px !important;
    color: rgba(255, 255, 255, 0.7) !important;
    margin-top: 2px !important;
}

/* Close button */
#nf-chatbot-widget .nf-chatbot-close {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 32px !important;
    height: 32px !important;
    border-radius: 50% !important;
    background-color: rgba(255, 255, 255, 0.1) !important;
    border: none !important;
    cursor: pointer !important;
    transition: background-color 0.15s ease !important;
    flex-shrink: 0 !important;
}

#nf-chatbot-widget .nf-chatbot-close:hover {
    background-color: rgba(255, 255, 255, 0.2) !important;
}

#nf-chatbot-widget .nf-chatbot-close svg {
    display: block !important;
    width: 16px !important;
    height: 16px !important;
    stroke: #ffffff !important;
    fill: none !important;
}

/* ============================================
   MESSAGES AREA
   ============================================ */
#nf-chatbot-widget .nf-chatbot-messages {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
    flex: 1 !important;
    overflow-y: auto !important;
    padding: 20px !important;
    background-color: var(--nfc-bg-secondary) !important;
}

#nf-chatbot-widget .nf-chatbot-messages::-webkit-scrollbar {
    width: 4px !important;
}

#nf-chatbot-widget .nf-chatbot-messages::-webkit-scrollbar-thumb {
    background-color: #d0d0d0 !important;
    border-radius: 2px !important;
}

/* Message wrapper */
#nf-chatbot-widget .nf-chatbot-msg-wrapper {
    display: flex !important;
}

#nf-chatbot-widget .nf-chatbot-msg-wrapper.nf-chatbot-user-wrapper {
    justify-content: flex-end !important;
}

/* Messages */
#nf-chatbot-widget .nf-chatbot-msg {
    display: block !important;
    max-width: 85% !important;
    padding: 12px 16px !important;
    font-size: 14px !important;
    line-height: 1.5 !important;
    word-wrap: break-word !important;
}

#nf-chatbot-widget .nf-chatbot-msg.nf-chatbot-user {
    background-color: var(--nfc-primary) !important;
    color: #ffffff !important;
    border-radius: 18px 18px 4px 18px !important;
}

#nf-chatbot-widget .nf-chatbot-msg.nf-chatbot-bot {
    background-color: var(--nfc-bot-bg) !important;
    color: var(--nfc-bot-text) !important;
    border-radius: 18px 18px 18px 4px !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05) !important;
}

#nf-chatbot-widget .nf-chatbot-msg-time {
    display: block !important;
    font-size: 10px !important;
    margin-top: 6px !important;
    opacity: 0.5 !important;
}

#nf-chatbot-widget .nf-chatbot-user .nf-chatbot-msg-time {
    text-align: right !important;
    color: #ffffff !important;
}

#nf-chatbot-widget .nf-chatbot-bot .nf-chatbot-msg-time {
    color: #171717 !important;
}

/* Typing indicator */
#nf-chatbot-widget .nf-chatbot-typing {
    display: flex !important;
    align-items: center !important;
    gap: 5px !important;
    padding: 14px 16px !important;
}

#nf-chatbot-widget .nf-chatbot-typing-dot {
    display: block !important;
    width: 8px !important;
    height: 8px !important;
    background-color: #a0a0a0 !important;
    border-radius: 50% !important;
    animation: nfcTyping 1.2s ease-in-out infinite !important;
}

#nf-chatbot-widget .nf-chatbot-typing-dot:nth-child(2) { animation-delay: 0.15s !important; }
#nf-chatbot-widget .nf-chatbot-typing-dot:nth-child(3) { animation-delay: 0.3s !important; }

@keyframes nfcTyping {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* ============================================
   INPUT AREA
   ============================================ */
#nf-chatbot-widget .nf-chatbot-input-area {
    display: block !important;
    padding: 16px !important;
    background-color: var(--nfc-bg) !important;
    border-top: 1px solid var(--nfc-border) !important;
    flex-shrink: 0 !important;
}

#nf-chatbot-widget .nf-chatbot-input-wrapper {
    display: flex !important;
    align-items: center !important;
    gap: 10px !important;
    padding: 6px 6px 6px 18px !important;
    background-color: var(--nfc-bg-input) !important;
    border: 1px solid var(--nfc-border) !important;
    border-radius: 28px !important;
    transition: border-color 0.15s ease, box-shadow 0.15s ease !important;
}

#nf-chatbot-widget .nf-chatbot-input-wrapper:focus-within {
    border-color: var(--nfc-primary) !important;
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.1) !important;
}

#nf-chatbot-widget .nf-chatbot-input-wrapper input {
    display: block !important;
    flex: 1 !important;
    padding: 10px 0 !important;
    font-size: 14px !important;
    font-family: inherit !important;
    color: var(--nfc-text) !important;
    background: transparent !important;
    border: none !important;
    outline: none !important;
}

#nf-chatbot-widget .nf-chatbot-input-wrapper input::placeholder {
    color: var(--nfc-text-muted) !important;
}

/* Send button */
#nf-chatbot-widget .nf-chatbot-send {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 40px !important;
    height: 40px !important;
    border-radius: 50% !important;
    background-color: var(--nfc-primary) !important;
    border: none !important;
    cursor: pointer !important;
    transition: transform 0.15s ease, opacity 0.15s ease, background-color 0.15s ease !important;
    flex-shrink: 0 !important;
}

#nf-chatbot-widget .nf-chatbot-send:hover {
    transform: scale(1.05) !important;
    background-color: var(--nfc-primary-hover) !important;
}

#nf-chatbot-widget .nf-chatbot-send:active {
    transform: scale(0.95) !important;
}

#nf-chatbot-widget .nf-chatbot-send:disabled {
    background-color: var(--nfc-border) !important;
    cursor: not-allowed !important;
    transform: none !important;
}

#nf-chatbot-widget .nf-chatbot-send svg {
    display: block !important;
    width: 18px !important;
    height: 18px !important;
    stroke: #ffffff !important;
    fill: none !important;
}

#nf-chatbot-widget .nf-chatbot-send:disabled svg {
    stroke: #999999 !important;
}

/* ============================================
   POWERED BY
   ============================================ */
#nf-chatbot-widget .nf-chatbot-powered {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 6px !important;
    padding: 10px !important;
    font-size: 11px !important;
    color: var(--nfc-text-muted) !important;
    background-color: var(--nfc-bg) !important;
    border-top: 1px solid var(--nfc-border) !important;
    flex-shrink: 0 !important;
}

/* Inverti logo in tema scuro */
#nf-chatbot-widget.nfc-theme-dark .nf-chatbot-powered-logo {
    filter: invert(1) !important;
}

#nf-chatbot-widget .nf-chatbot-powered a {
    display: inline-flex !important;
    align-items: center !important;
    text-decoration: none !important;
}

#nf-chatbot-widget .nf-chatbot-powered-logo {
    display: block !important;
    height: 12px !important;
    width: auto !important;
    opacity: 0.5 !important;
    transition: opacity 0.15s ease !important;
}

#nf-chatbot-widget .nf-chatbot-powered a:hover .nf-chatbot-powered-logo {
    opacity: 0.8 !important;
}

/* ============================================
   MOBILE RESPONSIVE
   ============================================ */
@media screen and (max-width: 480px) {
    #nf-chatbot-widget {
        bottom: 16px !important;
        right: 16px !important;
        left: auto !important;
    }

    #nf-chatbot-widget.nf-chatbot-left {
        left: 16px !important;
        right: auto !important;
    }

    #nf-chatbot-widget .nf-chatbot-bubble {
        width: 52px !important;
        height: 52px !important;
    }

    #nf-chatbot-widget .nf-chatbot-window {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: 100% !important;
        max-height: 100% !important;
        border-radius: 0 !important;
    }

    #nf-chatbot-widget .nf-chatbot-header {
        padding: 14px 16px !important;
    }

    #nf-chatbot-widget .nf-chatbot-input-area {
        padding: 12px 16px !important;
        padding-bottom: calc(12px + env(safe-area-inset-bottom)) !important;
    }
}
