/*
 * WooPredict AI Public Styles
 * Version: 1.0.0
 * Author: علی جهانی
 */

/* Base Font for Public Facing */
body, #woopredict-ai-chatbot-toggle, #woopredict-ai-chatbot-container, #woopredict-ai-chat-input,
.woopredict-ai-tooltip {
    font-family: 'Vazir Matn', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif !important;
}
/* Ensure Font Awesome icons use their specific font-family */
#woopredict-ai-chatbot-toggle i,
#woopredict-ai-chatbot-container i,
.woopredict-ai-chat-message-icon i {
    font-family: "Font Awesome 6 Free" !important;
    font-weight: 900 !important; /* For solid icons */
}

/* Chatbot Toggle Button (positioned within product summary, so it scrolls) */
#woopredict-ai-chatbot-toggle {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: linear-gradient(135deg, #0073aa 0%, #005684 100%); /* Blue gradient */
    color: white;
    padding: 12px 20px;
    border-radius: 30px; /* Rounded pill shape */
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    z-index: 10; /* Lower z-index as it's not fixed, but still above content */
    font-size: 15px;
    font-weight: 600;
    transition: all 0.3s ease;
    border: none;
    outline: none;
    position: relative; /* For tooltip positioning */
    box-sizing: border-box;
    margin-top: 20px; /* Space below add to cart button */
    /* Ensure it's not hidden by other elements */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#woopredict-ai-chatbot-toggle:hover {
    background: linear-gradient(135deg, #005684 0%, #003e5e 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

#woopredict-ai-chatbot-toggle i {
    font-size: 20px;
    line-height: 1;
    color: #fff;
    vertical-align: middle;
}

/* Tooltip for Chatbot Toggle */
#woopredict-ai-chatbot-toggle .woopredict-ai-tooltip {
    visibility: hidden;
    background-color: #333;
    color: #fff;
    text-align: center;
    border-radius: 8px;
    padding: 8px 12px;
    position: absolute;
    z-index: 10000;
    bottom: calc(100% + 12px); /* Position above the button */
    left: 50%;
    transform: translateX(-50%); /* Center the tooltip */
    opacity: 0;
    transition: opacity 0.3s ease, visibility 0.3s ease, bottom 0.3s ease;
    font-size: 12px;
    white-space: nowrap;
    pointer-events: none; /* Make tooltip unclickable */
    min-width: 150px;
    font-weight: normal;
}

#woopredict-ai-chatbot-toggle:hover .woopredict-ai-tooltip {
    visibility: visible;
    opacity: 1;
    bottom: calc(100% + 8px); /* Move slightly above the button */
}

#woopredict-ai-chatbot-toggle .woopredict-ai-tooltip::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -6px;
    border-width: 6px;
    border-style: solid;
    border-color: #333 transparent transparent transparent;
}


/* Chatbot Container (Fixed Position) */
#woopredict-ai-chatbot-container {
    position: fixed;
    bottom: 120px; /* Higher position, clearly above the footer */
    left: 30px; /* Default for LTR */
    width: 360px; /* Slightly narrower */
    height: 550px; /* Slightly shorter */
    background-color: #fff;
    border-radius: 18px;
    box-shadow: 0 12px 50px rgba(0, 0, 0, 0.35);
    z-index: 10000;
    display: none; /* Hidden by default */
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.9); /* Start slightly smaller for animation */
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.3s ease-out;
    transform-origin: bottom left; /* For LTR */
}

#woopredict-ai-chatbot-container.open {
    display: flex;
    transform: scale(1);
    opacity: 1;
}

#woopredict-ai-chatbot-header {
    background: linear-gradient(90deg, #0073aa, #005684);
    color: white;
    padding: 16px 20px;
    font-size: 18px;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top-left-radius: 18px;
    border-top-right-radius: 18px;
}
#woopredict-ai-chatbot-header .header-title {
    display: flex;
    align-items: center;
    gap: 8px;
}
#woopredict-ai-chatbot-header .header-title i {
    font-size: 22px;
    line-height: 1;
}

#woopredict-ai-chatbot-header .close-button {
    background: none;
    border: none;
    color: white;
    font-size: 26px;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    margin: 0;
    opacity: 0.9;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

#woopredict-ai-chatbot-header .close-button:hover {
    opacity: 1;
    transform: rotate(90deg);
}
#woopredict-ai-chatbot-header .close-button i {
    font-size: 22px;
    line-height: 1;
}


#woopredict-ai-chatbot-body {
    flex-grow: 1;
    padding: 15px 20px;
    overflow-y: auto;
    background-color: #f8fafd; /* Light background for chat area */
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth; /* Smooth scrolling */
}

.woopredict-ai-chat-message {
    margin-bottom: 15px;
    display: flex;
    align-items: flex-start;
}
.woopredict-ai-chat-message:last-of-type {
    margin-bottom: 0;
}

.woopredict-ai-chat-message.user {
    justify-content: flex-end;
}
.woopredict-ai-chat-message.ai {
    justify-content: flex-start;
}

.woopredict-ai-chat-message-icon {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: bold;
    color: white;
    flex-shrink: 0;
    margin: 0 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.woopredict-ai-chat-message.user .woopredict-ai-chat-message-icon {
    background-color: #0073aa;
    order: 2; /* User icon on the left in RTL, right in LTR */
}
.woopredict-ai-chat-message.user .woopredict-ai-chat-message-icon i {
    font-size: 16px;
}
.woopredict-ai-chat-message.ai .woopredict-ai-chat-message-icon {
    background-color: #5cb85c; /* Green for AI */
    order: 1; /* AI icon on the left in LTR, right in RTL */
}
.woopredict-ai-chat-message.ai .woopredict-ai-chat-message-icon i {
    font-size: 16px;
}


.woopredict-ai-chat-message-content {
    max-width: 80%;
    padding: 10px 15px;
    border-radius: 20px; /* More rounded */
    line-height: 1.6;
    word-wrap: break-word;
    font-size: 14px;
    position: relative;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    animation: messageFadeIn 0.3s ease-out forwards;
}

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

.woopredict-ai-chat-message.user .woopredict-ai-chat-message-content {
    background-color: #0073aa;
    color: white;
    border-bottom-right-radius: 6px; /* Slightly less rounded at the bottom-right corner */
}

.woopredict-ai-chat-message.ai .woopredict-ai-chat-message-content {
    background-color: #e0e6eb; /* Lighter gray for AI */
    color: #333;
    border-bottom-left-radius: 6px; /* Slightly less rounded at the bottom-left corner */
}
.woopredict-ai-chat-message.ai .woopredict-ai-chat-message-content p:last-child {
    margin-bottom: 0; /* Remove extra margin from last paragraph */
}

#woopredict-ai-chatbot-footer {
    padding: 12px 18px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    gap: 10px;
    background-color: #fff;
    border-bottom-left-radius: 18px;
    border-bottom-right-radius: 18px;
}

#woopredict-ai-chat-input {
    flex-grow: 1;
    padding: 10px 15px;
    border: 1px solid #ddd;
    border-radius: 22px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#woopredict-ai-chat-input:focus {
    border-color: #0073aa;
    box-shadow: 0 0 0 3px rgba(0, 115, 170, 0.15);
}

#woopredict-ai-chat-send {
    background-color: #0073aa;
    color: white;
    border: none;
    border-radius: 22px;
    padding: 10px 18px;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.2s ease;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

#woopredict-ai-chat-send:hover:not(:disabled) {
    background-color: #005177;
    transform: translateY(-1px);
}

#woopredict-ai-chat-send:disabled {
    background-color: #b0b0b0;
    cursor: not-allowed;
    transform: none;
    opacity: 0.8;
}
#woopredict-ai-chat-send i {
    font-size: 16px;
    line-height: 1;
}

/* Responsive Adjustments for Chatbot */
@media (max-width: 600px) {
    #woopredict-ai-chatbot-toggle {
        /* This button is now within the product summary, so its positioning is relative to that */
        margin-left: auto; /* Center or align as needed within its parent */
        margin-right: auto;
        display: flex; /* Make it a flex container to center */
        justify-content: center;
        width: 100%; /* Take full width if desired */
        max-width: 300px; /* Or limit width */
        padding: 10px 18px;
        font-size: 14px;
        gap: 8px;
        border-radius: 25px;
        /* No fixed position for the toggle button on mobile either */
    }
    #woopredict-ai-chatbot-toggle i {
        font-size: 18px;
    }
    #woopredict-ai-chatbot-toggle .button-text {
        /* display: none; */ /* Keep text visible if space allows, or hide based on further testing */
    }

    #woopredict-ai-chatbot-container {
        width: calc(100% - 40px); /* Full width minus margins */
        height: calc(100% - 40px); /* Full height minus margins */
        bottom: 20px;
        left: 20px; /* Default for LTR */
        border-radius: 12px;
        max-width: none; /* Remove max-width on mobile */
        max-height: none; /* Remove max-height on mobile */
        transform-origin: bottom left;
    }
    #woopredict-ai-chatbot-header {
        padding: 14px 16px;
        font-size: 16px;
        border-top-left-radius: 12px;
        border-top-right-radius: 12px;
    }
    #woopredict-ai-chatbot-header .close-button {
        font-size: 24px;
    }
    #woopredict-ai-chatbot-body {
        padding: 12px 15px;
    }
    .woopredict-ai-chat-message-content {
        max-width: 90%;
        padding: 8px 12px;
        font-size: 13px;
    }
    .woopredict-ai-chat-message-icon {
        width: 26px;
        height: 26px;
        font-size: 14px;
        margin: 0 6px;
    }
    .woopredict-ai-chat-message-icon i {
        font-size: 14px;
    }
    #woopredict-ai-chatbot-footer {
        padding: 10px 12px;
        gap: 8px;
        border-bottom-left-radius: 12px;
        border-bottom-right-radius: 12px;
    }
    #woopredict-ai-chat-input {
        padding: 8px 12px;
        font-size: 13px;
    }
    #woopredict-ai-chat-send {
        padding: 8px 15px;
        font-size: 13px;
    }

    /* Adjust tooltip for mobile if needed, or hide */
    #woopredict-ai-chatbot-toggle .woopredict-ai-tooltip {
        display: none; /* Hide tooltip on mobile for simplicity */
    }
}


/* RTL Adjustments for Chatbot */
html[dir="rtl"] #woopredict-ai-chatbot-toggle {
    left: auto;
    right: 0; /* Position on right for RTL, within its parent container */
    flex-direction: row-reverse; /* Icon to the left of text */
}
html[dir="rtl"] #woopredict-ai-chatbot-toggle .woopredict-ai-tooltip {
    left: auto;
    right: 50%;
    transform: translateX(50%); /* Center for RTL */
}
html[dir="rtl"] #woopredict-ai-chatbot-toggle .woopredict-ai-tooltip::after {
    left: auto;
    right: 50%;
    margin-left: 0;
    margin-right: -6px;
}

html[dir="rtl"] #woopredict-ai-chatbot-container {
    left: auto;
    right: 30px; /* Position on right for RTL */
    transform-origin: bottom right; /* For RTL */
}
html[dir="rtl"] #woopredict-ai-chatbot-header {
    flex-direction: row-reverse; /* Swap title and close button */
}
html[dir="rtl"] #woopredict-ai-chatbot-header .header-title i {
    margin-left: 8px; /* Space after icon */
    margin-right: 0;
}
html[dir="rtl"] .woopredict-ai-chat-message.user {
    justify-content: flex-start; /* User messages start from right in RTL */
}
html[dir="rtl"] .woopredict-ai-chat-message.ai {
    justify-content: flex-end; /* AI messages start from left in RTL */
}
html[dir="rtl"] .woopredict-ai-chat-message.user .woopredict-ai-chat-message-content {
    border-bottom-left-radius: 6px;
    border-bottom-right-radius: 20px; /* Reset */
}
html[dir="rtl"] .woopredict-ai-chat-message.ai .woopredict-ai-chat-message-content {
    border-bottom-right-radius: 6px;
    border-bottom-left-radius: 20px; /* Reset */
}
html[dir="rtl"] .woopredict-ai-chat-message.user .woopredict-ai-chat-message-icon {
    order: 1; /* User icon on the right in RTL */
}
html[dir="rtl"] .woopredict-ai-chat-message.ai .woopredict-ai-chat-message-icon {
    order: 2; /* AI icon on the left in RTL */
}
html[dir="rtl"] .woopredict-ai-chat-message-icon {
    margin: 0 8px; /* Reset margin */
}

html[dir="rtl"] #woopredict-ai-chatbot-footer {
    flex-direction: row-reverse; /* Input on right, button on left */
}

@media (max-width: 600px) {
    html[dir="rtl"] #woopredict-ai-chatbot-toggle {
        right: 0; /* Align to the right edge of its parent */
    }
    html[dir="rtl"] #woopredict-ai-chatbot-container {
        right: 20px;
    }
    html[dir="rtl"] #woopredict-ai-chatbot-toggle .button-text {
        /* display: none; */
    }
}