/* ==========================================================================
   SMTBOX AI Chatbot Stylesheet (BEM namespaced under #sre-chatbot-container)
   ========================================================================== */

/* --------------------------------------------------------------------------
   0. Global Body Scroll Lock (Whitelist Rule 1)
   -------------------------------------------------------------------------- */
html.sre-chat-scroll-locked,
body.sre-chat-scroll-locked {
    overflow: hidden !important;
}

/* --------------------------------------------------------------------------
   1. Root Chatbot Container (Whitelist Rule 2)
   -------------------------------------------------------------------------- */
#sre-chatbot-container * {
    box-sizing: border-box;
}

#sre-chatbot-container {
    position: fixed;
    bottom: 75px;
    right: 20px;
    z-index: 2147483647 !important;
    width: auto;
    height: auto;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* --------------------------------------------------------------------------
   2. Promo Banner Mode (Default closed state)
   -------------------------------------------------------------------------- */
#sre-chatbot-container #sre-chatbot-banner {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 280px;
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid rgba(0, 39, 128, 0.15);
    border-radius: 12px;
    box-shadow: 0 6px 20px rgba(0, 39, 128, 0.12);
    cursor: pointer;
    transition: transform 0.2s ease, opacity 0.2s ease;
    display: flex;
    padding: 12px 14px;
    align-items: center;
    box-sizing: border-box;
}

#sre-chatbot-container #sre-chatbot-banner:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 39, 128, 0.18);
}

#sre-chatbot-container #sre-chatbot-banner-close {
    position: absolute;
    top: 6px;
    right: 8px;
    background: none;
    border: none;
    color: #999999;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    padding: 2px;
    z-index: 10;
}

#sre-chatbot-container #sre-chatbot-banner-close:hover {
    color: #CF0921;
}

#sre-chatbot-container #sre-chatbot-banner-content {
    display: flex;
    align-items: center;
    width: 100%;
    pointer-events: none;
}

#sre-chatbot-container .sre-chatbot-banner-avatar {
    width: 36px;
    height: 36px;
    background: #002780;
    border: 2px solid #CF0921;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    flex-shrink: 0;
}

#sre-chatbot-container .sre-chatbot-banner-avatar svg {
    width: 18px;
    height: 18px;
    stroke-width: 2.5;
}

#sre-chatbot-container .sre-chatbot-banner-text {
    margin-left: 12px;
    overflow: hidden;
    text-align: left;
}

#sre-chatbot-container .sre-chatbot-banner-title {
    font-size: 13px;
    font-weight: 700;
    color: #002780;
    margin-bottom: 2px;
    line-height: 1.2;
}

#sre-chatbot-container .sre-chatbot-banner-desc {
    font-size: 10px;
    color: #666666;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --------------------------------------------------------------------------
   3. Compact Mode (Circular Floating Action Button)
   -------------------------------------------------------------------------- */
#sre-chatbot-container #sre-chatbot-toggle {
    display: none;
    width: 60px;
    height: 60px;
    background-color: #002780;
    border: 2px solid #CF0921;
    color: #ffffff;
    border-radius: 50%;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 39, 128, 0.4);
    transition: transform 0.2s ease;
}

#sre-chatbot-container #sre-chatbot-toggle:hover {
    transform: scale(1.05);
}

#sre-chatbot-container #sre-chatbot-toggle svg {
    width: 30px;
    height: 30px;
    max-width: 30px;
    max-height: 30px;
}

#sre-chatbot-container.sre-chatbot-compact #sre-chatbot-toggle {
    display: flex;
}

/* Container State Toggles */
#sre-chatbot-container.sre-chatbot-open #sre-chatbot-banner,
#sre-chatbot-container.sre-chatbot-open #sre-chatbot-toggle,
#sre-chatbot-container.sre-chatbot-compact #sre-chatbot-banner {
    display: none;
}

/* --------------------------------------------------------------------------
   4. Chat Window Frame (Whitelist Rule 3)
   -------------------------------------------------------------------------- */
#sre-chatbot-container #sre-chatbot-window {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 2147483647 !important;
    width: 640px;
    height: min(650px, calc(100dvh - 120px));
    max-width: calc(100vw - 40px);
    max-height: calc(100dvh - 40px);
    background: #ffffff;
    border-radius: 12px;
    border: 2px solid #002780;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

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

/* --------------------------------------------------------------------------
   5. Window Header
   -------------------------------------------------------------------------- */
#sre-chatbot-container #sre-chatbot-header {
    background: #002780;
    color: #FFD93B;
    padding: 6px 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 2px solid #CF0921;
    height: 38px;
    flex-shrink: 0;
}

#sre-chatbot-container #sre-chatbot-header h3 {
    margin: 0;
    font-size: 13px;
    font-weight: 700;
    color: #FFD93B;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1.2;
}

#sre-chatbot-container #sre-chatbot-close {
    background: none;
    border: none;
    color: #FFD93B;
    font-size: 20px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    min-height: 0;
    min-width: 0;
    border-radius: 50%;
    margin-right: -4px;
    margin-bottom: 0;
    padding: 0;
    transition: all 0.2s ease-in-out;
}

#sre-chatbot-container #sre-chatbot-close:hover {
    color: #FFFFFF;
    background: rgba(255, 255, 255, 0.15);
}

/* --------------------------------------------------------------------------
   6. Navigation Tabs
   -------------------------------------------------------------------------- */
#sre-chatbot-container .sre-chatbot-tabs {
    display: flex;
    background: #ffffff;
    border-bottom: 1px solid #e2e8f0;
    height: 38px;
    flex-shrink: 0;
}

#sre-chatbot-container .sre-chatbot-tab-btn {
    flex: 1;
    background: none;
    border: none;
    color: #64748b;
    padding: 8px 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    outline: none;
    border-bottom: 3px solid transparent;
    transition: color 0.2s ease, border-color 0.2s ease;
}

#sre-chatbot-container .sre-chatbot-tab-btn:hover {
    color: #002780;
}

#sre-chatbot-container .sre-chatbot-tab-btn.active {
    color: #002780;
    background: none;
    border-bottom: 3px solid #CF0921;
}

/* --------------------------------------------------------------------------
   7. View Switching
   -------------------------------------------------------------------------- */
#sre-chatbot-container #sre-chatbot-chat-view {
    display: none;
}

#sre-chatbot-container #sre-chatbot-chat-view.active {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

#sre-chatbot-container #sre-chatbot-rfq-view {
    display: none;
    flex-direction: column;
    flex: 1;
    overflow-y: auto;
    background: #EFF2F7;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

#sre-chatbot-container #sre-chatbot-rfq-view.active {
    display: flex;
}

/* --------------------------------------------------------------------------
   8. Messages Scroll Area & Bubbles
   -------------------------------------------------------------------------- */
#sre-chatbot-container #sre-chatbot-messages {
    flex: 1 1 0%;
    min-height: 0;
    padding: 15px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    background: #f9f9f9;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
}

#sre-chatbot-container #sre-chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

#sre-chatbot-container #sre-chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

#sre-chatbot-container #sre-chatbot-messages::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.15);
    border-radius: 3px;
}

#sre-chatbot-container .chat-message {
    margin-bottom: 15px;
    line-height: 1.4;
    font-size: 14px;
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    word-wrap: break-word;
}

#sre-chatbot-container .bot-message {
    background: #f1f1f1;
    color: #333333;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

#sre-chatbot-container .user-message {
    background: #002780;
    color: #ffffff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

/* Embedded Product Cards */
#sre-chatbot-container .chat-products {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 15px;
    width: 100%;
}

#sre-chatbot-container .chat-product-card {
    display: flex;
    align-items: center;
    background: #ffffff;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    padding: 8px;
    text-decoration: none;
    color: #333333;
    transition: box-shadow 0.2s ease;
}

#sre-chatbot-container .chat-product-card:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

#sre-chatbot-container .chat-product-img {
    width: 50px;
    min-width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: 4px;
    margin: 0;
    padding: 0;
    display: block;
}

#sre-chatbot-container .chat-product-info {
    margin-left: 10px;
    flex: 1;
    overflow: hidden;
}

#sre-chatbot-container .chat-product-title {
    font-size: 13px;
    margin: 0 0 4px 0;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
    color: #333333;
}

#sre-chatbot-container .chat-product-sku {
    font-size: 11px;
    color: #777777;
    margin: 0;
    line-height: 1;
}

/* Typing Indicator Animation */
#sre-chatbot-container .typing-indicator {
    display: flex;
    gap: 4px;
    padding: 14px;
}

#sre-chatbot-container .typing-indicator span {
    width: 6px;
    height: 6px;
    background: #999999;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out both;
}

#sre-chatbot-container .typing-indicator span:nth-child(1) {
    animation-delay: -0.32s;
}

#sre-chatbot-container .typing-indicator span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typing {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* --------------------------------------------------------------------------
   9. Chat Input Area
   -------------------------------------------------------------------------- */
#sre-chatbot-container #sre-chatbot-input-area {
    padding: 10px;
    background: #ffffff;
    border-top: 1px solid #eeeeee;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

#sre-chatbot-container #sre-chatbot-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #dddddd;
    border-radius: 20px;
    outline: none;
    font-size: 14px;
    height: 40px;
    box-sizing: border-box;
}

#sre-chatbot-container #sre-chatbot-input:focus {
    border-color: #CF0921;
}

#sre-chatbot-container #sre-chatbot-send {
    background: #CF0921;
    color: #ffffff;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease;
    flex-shrink: 0;
}

#sre-chatbot-container #sre-chatbot-send:hover {
    background: #A8071B;
}

#sre-chatbot-container #sre-chatbot-send svg {
    width: 18px;
    height: 18px;
    max-width: 18px;
    max-height: 18px;
    flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   10. Brevo RFQ View Overrides
   -------------------------------------------------------------------------- */
#sre-chatbot-container #sre-chatbot-rfq-view .sib-form {
    padding: 0;
    background-color: transparent;
}

#sre-chatbot-container #sre-chatbot-rfq-view #sib-container {
    max-width: 100%;
    width: 100%;
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding: 15px;
    background-color: #ffffff;
}

#sre-chatbot-container #sre-chatbot-rfq-view .sib-input {
    padding: 4px 0;
}

#sre-chatbot-container #sre-chatbot-rfq-view .entry__label {
    font-size: 14px;
}

#sre-chatbot-container #sre-chatbot-rfq-view .entry__specification {
    font-size: 11px;
    margin-top: 2px;
}

#sre-chatbot-container #sre-chatbot-rfq-view button.sib-form-block__button {
    width: 100%;
    justify-content: center;
    text-align: center;
    padding: 10px;
    background-color: #002780;
}

#sre-chatbot-container #sre-chatbot-rfq-view button.sib-form-block__button:hover {
    background-color: #001f66;
}

#sre-chatbot-container #sre-chatbot-rfq-view #sib-form > div {
    padding: 4px 0;
}

#sre-chatbot-container #sre-chatbot-rfq-view #sib-container input.input,
#sre-chatbot-container #sre-chatbot-rfq-view #sib-container textarea.input {
    padding: 8px 12px;
    height: auto;
    font-size: 14px;
    border-radius: 4px;
}

#sre-chatbot-container #sre-chatbot-rfq-reset-btn:hover {
    background-color: #001f66;
}

/* --------------------------------------------------------------------------
   11. Mobile & Narrow Viewport Responsive Scaling (<768px)
   -------------------------------------------------------------------------- */
@media screen and (max-width: 767px) {
    #sre-chatbot-container {
        position: fixed;
        inset: 0;
        width: 100%;
        height: 100%;
        pointer-events: none;
    }

    #sre-chatbot-container.sre-chatbot-closed,
    #sre-chatbot-container.sre-chatbot-compact {
        top: auto;
        left: auto;
        width: auto;
        height: auto;
        right: 15px;
        bottom: 15px;
        pointer-events: none;
    }

    #sre-chatbot-container.sre-chatbot-closed #sre-chatbot-banner,
    #sre-chatbot-container.sre-chatbot-compact #sre-chatbot-toggle {
        pointer-events: auto;
    }

    #sre-chatbot-container.sre-chatbot-open {
        pointer-events: auto;
    }

    #sre-chatbot-container #sre-chatbot-window {
        position: fixed;
        inset: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100dvh;
        border-radius: 0;
        border: none;
        margin: 0;
        box-shadow: none;
    }

    #sre-chatbot-container #sre-chatbot-messages {
        padding: 12px;
    }

    #sre-chatbot-container #sre-chatbot-banner {
        width: calc(100vw - 30px);
        max-width: 360px;
    }

    /* Prevent iOS Safari auto-zoom on input focus */
    #sre-chatbot-container #sre-chatbot-input {
        font-size: 16px;
    }
}
