/* ==========================================================================
   Bevande Perino Chatbot — Styles
   Allineato al brand: bordeaux, crema texturizzata, verde oliva, oro accento
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Archivo+Black&family=Inter:wght@400;500;600;700&family=Lora:ital,wght@1,500&display=swap');

#bpc-chatbot-container {
    /* Palette esatta del sito */
    --bpc-burgundy: #7a1f2b;
    --bpc-burgundy-dark: #5e1620;
    --bpc-burgundy-light: #9a2a3a;
    --bpc-cream: #f5ecdc;
    --bpc-cream-light: #faf3e6;
    --bpc-cream-dark: #ebe0cc;
    --bpc-olive: #3d4a2a;
    --bpc-olive-light: #556638;
    --bpc-gold: #e8a838;
    --bpc-gold-soft: #f0c060;
    --bpc-text: #2b1a18;
    --bpc-text-muted: #8a7866;
    --bpc-bot-bg: #faf3e6;
    --bpc-shadow: 0 18px 50px -12px rgba(94, 22, 32, 0.4);
    --bpc-shadow-soft: 0 4px 14px rgba(94, 22, 32, 0.15);

    --bpc-paper-texture:
        radial-gradient(circle at 15% 25%, rgba(122, 31, 43, 0.025) 0%, transparent 35%),
        radial-gradient(circle at 85% 75%, rgba(61, 74, 42, 0.03) 0%, transparent 40%),
        radial-gradient(circle at 50% 50%, rgba(232, 168, 56, 0.02) 0%, transparent 60%);

    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999999;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ============ TOGGLE BUTTON ============ */
#bpc-toggle-btn {
    width: 66px;
    height: 66px;
    border-radius: 50%;
    background: var(--bpc-burgundy);
    border: 3px solid var(--bpc-cream);
    color: var(--bpc-cream);
    cursor: pointer;
    box-shadow: var(--bpc-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
    position: relative;
}

#bpc-toggle-btn:hover {
    transform: scale(1.08) translateY(-2px);
    box-shadow: 0 22px 60px -12px rgba(94, 22, 32, 0.55);
}

#bpc-toggle-btn:active { transform: scale(0.95); }

#bpc-toggle-btn svg { width: 28px; height: 28px; transition: transform 0.3s ease; }
#bpc-toggle-btn .bpc-icon-close { display: none; }
#bpc-chatbot-container.bpc-open #bpc-toggle-btn .bpc-icon-chat { display: none; }
#bpc-chatbot-container.bpc-open #bpc-toggle-btn .bpc-icon-close { display: flex; }

#bpc-toggle-btn::after {
    content: '';
    position: absolute;
    top: 4px;
    right: 4px;
    width: 14px;
    height: 14px;
    background: var(--bpc-gold);
    border: 2px solid var(--bpc-cream);
    border-radius: 50%;
    animation: bpc-pulse 2s infinite;
}

#bpc-chatbot-container.bpc-open #bpc-toggle-btn::after,
#bpc-chatbot-container.bpc-interacted #bpc-toggle-btn::after { display: none; }

@keyframes bpc-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.25); opacity: 0.75; }
}

/* ============ CHAT WINDOW ============ */
#bpc-chat-window {
    position: absolute;
    bottom: 84px;
    right: 0;
    width: 390px;
    max-width: calc(100vw - 32px);
    height: 600px;
    max-height: calc(100vh - 120px);
    background: var(--bpc-cream);
    background-image: var(--bpc-paper-texture);
    border-radius: 22px;
    box-shadow: var(--bpc-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    border: 1px solid rgba(122, 31, 43, 0.08);
}

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

/* ============ HEADER ============ */
.bpc-header {
    background: var(--bpc-burgundy);
    color: var(--bpc-cream);
    padding: 16px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
}

.bpc-header::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 3px;
    background: var(--bpc-gold);
    border-radius: 2px;
}

.bpc-header-info { display: flex; align-items: center; gap: 12px; }

/* Avatar: cerchio crema con monogramma "AP" stile mascotte del sito */
.bpc-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--bpc-cream);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--bpc-burgundy);
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    font-family: 'Archivo Black', sans-serif;
    font-size: 16px;
    letter-spacing: -0.5px;
}

.bpc-avatar svg { width: 26px; height: 26px; }

.bpc-header-text h3 {
    font-family: 'Archivo Black', 'Inter', sans-serif;
    font-size: 17px;
    font-weight: 900;
    margin: 0;
    color: var(--bpc-cream);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.bpc-status {
    font-size: 11.5px;
    color: var(--bpc-cream);
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 3px;
    font-weight: 500;
}

.bpc-status-dot {
    width: 8px;
    height: 8px;
    background: var(--bpc-gold);
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(232, 168, 56, 0.3);
    animation: bpc-pulse-dot 2s infinite;
}

@keyframes bpc-pulse-dot {
    0%, 100% { box-shadow: 0 0 0 2px rgba(232, 168, 56, 0.3); }
    50% { box-shadow: 0 0 0 5px rgba(232, 168, 56, 0); }
}

#bpc-close-btn {
    background: transparent;
    border: none;
    color: var(--bpc-cream);
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    display: flex;
    transition: background 0.2s ease;
}

#bpc-close-btn:hover { background: rgba(255, 255, 255, 0.12); }
#bpc-close-btn svg { width: 20px; height: 20px; }

/* ============ MESSAGES ============ */
#bpc-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

#bpc-messages::-webkit-scrollbar { width: 6px; }
#bpc-messages::-webkit-scrollbar-track { background: transparent; }
#bpc-messages::-webkit-scrollbar-thumb { background: rgba(122, 31, 43, 0.25); border-radius: 3px; }
#bpc-messages::-webkit-scrollbar-thumb:hover { background: rgba(122, 31, 43, 0.5); }

.bpc-message {
    max-width: 85%;
    padding: 11px 15px;
    font-size: 14.5px;
    line-height: 1.5;
    word-wrap: break-word;
    animation: bpc-fade-in 0.3s ease;
    color: var(--bpc-text);
    font-weight: 400;
}

@keyframes bpc-fade-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.bpc-message.bpc-bot {
    align-self: flex-start;
    background: var(--bpc-bot-bg);
    border: 1px solid rgba(122, 31, 43, 0.12);
    border-radius: 16px 16px 16px 4px;
}

.bpc-message.bpc-user {
    align-self: flex-end;
    background: var(--bpc-burgundy);
    color: var(--bpc-cream-light);
    border-radius: 16px 16px 4px 16px;
    box-shadow: 0 2px 6px rgba(94, 22, 32, 0.15);
}

.bpc-message a { text-decoration: underline; font-weight: 600; }
.bpc-message.bpc-bot a { color: var(--bpc-burgundy); }
.bpc-message.bpc-user a { color: var(--bpc-gold-soft); }
.bpc-message strong { font-weight: 700; }

/* Typing indicator */
.bpc-typing { display: flex; gap: 4px; padding: 6px 4px; align-items: center; }

.bpc-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--bpc-burgundy);
    opacity: 0.4;
    animation: bpc-typing 1.4s infinite;
}

.bpc-typing span:nth-child(2) { animation-delay: 0.2s; }
.bpc-typing span:nth-child(3) { animation-delay: 0.4s; }

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

/* ============ QUICK ACTIONS ============ */
.bpc-quick-actions {
    padding: 0 16px 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    transition: opacity 0.3s ease, max-height 0.3s ease;
    max-height: 80px;
    overflow: hidden;
}

.bpc-quick-actions.bpc-hidden {
    opacity: 0;
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    pointer-events: none;
}

.bpc-quick-btn {
    background: var(--bpc-cream-light);
    border: 1.5px solid var(--bpc-burgundy);
    color: var(--bpc-burgundy);
    padding: 7px 13px;
    border-radius: 24px;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    white-space: nowrap;
}

.bpc-quick-btn:hover {
    background: var(--bpc-burgundy);
    color: var(--bpc-cream);
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(94, 22, 32, 0.2);
}

/* ============ INPUT AREA con onda verde ============ */
.bpc-wave {
    display: block;
    width: 100%;
    height: 24px;
    margin-bottom: -1px;
    line-height: 0;
}

.bpc-wave svg {
    display: block;
    width: 100%;
    height: 100%;
}

#bpc-input-form {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: var(--bpc-olive);
}

#bpc-input {
    flex: 1;
    border: 1.5px solid transparent;
    border-radius: 24px;
    padding: 11px 16px;
    font-size: 14px;
    font-family: inherit;
    background: var(--bpc-cream-light);
    color: var(--bpc-text);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#bpc-input:focus {
    border-color: var(--bpc-gold);
    box-shadow: 0 0 0 3px rgba(232, 168, 56, 0.25);
}

#bpc-input::placeholder { color: var(--bpc-text-muted); }

#bpc-send-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--bpc-gold);
    border: none;
    color: var(--bpc-burgundy-dark);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    flex-shrink: 0;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15);
}

#bpc-send-btn:hover:not(:disabled) {
    transform: scale(1.08);
    background: var(--bpc-gold-soft);
    box-shadow: 0 5px 14px rgba(232, 168, 56, 0.4);
}

#bpc-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
#bpc-send-btn svg { width: 18px; height: 18px; }

/* ============ FOOTER ============ */
.bpc-footer {
    padding: 8px 16px 10px;
    text-align: center;
    font-size: 10.5px;
    color: rgba(245, 236, 220, 0.7);
    background: var(--bpc-olive);
    letter-spacing: 0.8px;
    text-transform: uppercase;
    font-weight: 500;
}

.bpc-footer strong { color: var(--bpc-gold); font-weight: 700; }

.bpc-footer a {
    color: inherit;
    text-decoration: none;
    transition: opacity 0.2s ease;
}

.bpc-footer a:hover {
    opacity: 0.8;
}

.bpc-footer a:hover strong {
    text-decoration: underline;
}

/* ============ MOBILE ============ */
@media (max-width: 600px) {
    #bpc-chatbot-container {
        bottom: 16px;
        right: 16px;
    }

    #bpc-toggle-btn {
        width: 58px;
        height: 58px;
    }

    /* Su mobile, quando la chat è aperta:
       - copre tutto lo schermo
       - usiamo flex column per avere header + messaggi (scrollabili) + input fissi */
    #bpc-chatbot-container.bpc-open #bpc-chat-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        height: 100vh;
        height: 100dvh; /* dynamic viewport height — risolve problemi iOS Safari */
        max-width: 100vw;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
        border: none;
        display: flex;
        flex-direction: column;
    }

    /* Nascondi toggle button quando chat è aperta */
    #bpc-chatbot-container.bpc-open #bpc-toggle-btn {
        display: none;
    }

    /* Header più compatto su mobile, con safe area per il notch */
    .bpc-header {
        padding: 12px 14px;
        padding-top: calc(12px + env(safe-area-inset-top));
        flex-shrink: 0;
    }

    .bpc-avatar {
        width: 38px;
        height: 38px;
        font-size: 14px;
    }

    .bpc-header-text h3 {
        font-size: 15px;
    }

    .bpc-status {
        font-size: 11px;
    }

    #bpc-close-btn {
        padding: 8px;
    }

    #bpc-close-btn svg {
        width: 22px;
        height: 22px;
    }

    /* Messages: occupano tutto lo spazio disponibile e scrollano */
    #bpc-messages {
        flex: 1 1 auto;
        min-height: 0; /* importante per flex scroll */
        padding: 14px 12px;
    }

    .bpc-message {
        font-size: 14px;
        padding: 10px 13px;
    }

    /* Quick actions */
    .bpc-quick-actions {
        flex-shrink: 0;
        padding: 0 12px 8px;
    }

    .bpc-quick-btn {
        font-size: 12px;
        padding: 6px 11px;
    }

    /* Wave non shrinka */
    .bpc-wave {
        flex-shrink: 0;
        height: 18px;
    }

    /* Input form fissato in basso */
    #bpc-input-form {
        flex-shrink: 0;
        padding: 10px 12px;
    }

    #bpc-input {
        font-size: 16px; /* 16px evita lo zoom automatico iOS quando si focalizza l'input */
        padding: 10px 14px;
    }

    #bpc-send-btn {
        width: 40px;
        height: 40px;
    }

    /* Footer con safe area per home indicator */
    .bpc-footer {
        flex-shrink: 0;
        padding: 6px 14px;
        padding-bottom: calc(8px + env(safe-area-inset-bottom));
        font-size: 9.5px;
    }
}

/* ============ BLOCCO SCROLL BODY quando chat aperta su mobile ============ */
@media (max-width: 600px) {
    body.bpc-chat-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
        height: 100%;
    }
}
