/**
 * SalesMine Frontend Widget Style
 *
 * Version: 1.1.0 (Robust & Responsive)
 * This stylesheet provides a professional, resilient, and responsive
 * layout for the SalesMine chat widget.
 */

/* --- 0. Root Variables (From PHP) --- */
:root {
    --salesmine-primary-color: #4f46e5;
    --salesmine-primary-color-translucent: rgba(79, 70, 229, 0.1);
}

/* --- 1. Main Widget Container & Positioning --- */
#salesmine-widget-container {
    position: fixed;
    bottom: 20px;
    z-index: 99999999; /* Extremely high z-index to stay on top */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#salesmine-widget-container.bottom-right {
    right: 20px;
}

#salesmine-widget-container.bottom-left {
    left: 20px;
}

/* All direct children should use border-box for predictable sizing */
#salesmine-widget-container * {
    box-sizing: border-box;
}

/* --- 2. The Chat Window (Core Layout Fix) --- */
.salesmine-chat-window {
    width: 370px;
    max-width: calc(100vw - 40px);
    height: 70vh;
    max-height: 600px;
    background-color: #ffffff;
    border-radius: 16px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1), 0 5px 10px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    margin-bottom: 80px;

    /* CRITICAL: Use Flexbox for a robust header/messages/footer layout */
    display: flex;
    flex-direction: column;

    /* Animation for opening/closing */
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
    pointer-events: none; /* Not clickable when hidden */
}

.salesmine-chat-window.active {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

/* --- 3. Window Header (Agent Photo Fix) --- */
.salesmine-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid #e5e7eb;
    background-color: #f9fafb;
    flex-shrink: 0; /* Prevent header from shrinking */
}

.salesmine-agent-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* THE FIX for the oversized agent photo */
.salesmine-agent-photo {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover; /* Prevents image from stretching/squashing */
    flex-shrink: 0;
}

.salesmine-agent-details {
    display: flex;
    flex-direction: column;
}

.salesmine-agent-name {
    font-weight: 600;
    font-size: 16px;
    color: #111827;
}

.salesmine-agent-status {
    font-size: 13px;
    color: #4ade80; /* Green for "Online" */
    position: relative;
    padding-left: 12px;
}

.salesmine-agent-status::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 6px;
    height: 6px;
    background-color: #4ade80;
    border-radius: 50%;
}

/* Header Close Button Hover Fix */
.salesmine-header-close-wrapper {
    border-radius: 50%;
    transition: background-color 0.2s ease-in-out;
}

.salesmine-header-close-wrapper:hover {
    background-color: rgba(0, 0, 0, 0.08);
}

.salesmine-header .salesmine-close-button {
    background: transparent;
    border: none;
    padding: 8px;
    cursor: pointer;
    color: #6b7280;
    line-height: 1;
}

.salesmine-header .salesmine-close-button svg {
    display: block;
}

.salesmine-header .salesmine-close-button:hover {
    background-color: transparent !important;
}


/* --- 4. Messages Area (Scrolling Fix) --- */
.salesmine-messages-area {
    flex-grow: 1; /* CRITICAL: This makes the message area fill available space */
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.salesmine-message {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    max-width: 85%;
}

.salesmine-message-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.salesmine-message-agent {
    align-self: flex-start;
}

.salesmine-message-photo {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover; /* Also fix for message photos */
    flex-shrink: 0;
}

.salesmine-message-content {
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.5;
}

.salesmine-message-content p {
    margin: 0;
}

.salesmine-message-agent .salesmine-message-content {
    background-color: #f3f4f6;
    color: #1f2937;
    border-bottom-left-radius: 4px;
}

.salesmine-message-user .salesmine-message-content {
    background-color: var(--salesmine-primary-color);
    color: white;
    border-bottom-right-radius: 4px;
}

/* Typing Indicator */
.salesmine-typing-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px; /* Adjusted padding */
    margin: 0 16px 16px; /* Added margin */
    background-color: #f3f4f6; /* NEW: Subtle background color */
    border-radius: 18px; /* Match message bubble style */
    border-bottom-left-radius: 4px; /* Match message bubble style */
    align-self: flex-start; /* Ensure it doesn't stretch full width */
}

.typing-dots span {
    display: inline-block;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background-color: #d1d5db;
    animation: typing-bounce 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }
@keyframes typing-bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1.0); }
}

/*chat area links*/
/* --- 4a. Message Link Styling (Corrected) --- */
/* Style for links inside the agent's message (light background) */
.salesmine-message-agent .salesmine-message-content a {
    color: var(--salesmine-primary-color) !important; /* Use theme color and force it */
    text-decoration: underline;
    font-weight: 600;
}

/* Fix for hover color to ensure it stands out */
.salesmine-message-agent .salesmine-message-content a:hover {
    opacity: 0.8 !important; /* Slightly fade the primary color on hover */
}

/* Style for links inside the user's message (dark background) */
.salesmine-message-user .salesmine-message-content a {
    color: #ffffff;
    text-decoration: underline;
    font-weight: 700;
}

/* --- 5. Input Area & Footer --- */
.salesmine-input-area {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    border-top: 1px solid #e5e7eb;
    gap: 10px;
}

.salesmine-input-area textarea {
    flex-grow: 1;
    border: none;
    background: transparent;
    padding: 10px 0;
    resize: none;
    font-size: 15px;
    max-height: 100px;
    line-height: 1.5;
}

.salesmine-input-area textarea:focus {
    outline: none;
}

.salesmine-input-area button {
    background-color: transparent;
    border: none;
    padding: 6px;
    cursor: pointer;
    color: var(--salesmine-primary-color);
    border-radius: 50%;
}

.salesmine-input-area button:hover {
    background-color: var(--salesmine-primary-color-translucent);
}

.salesmine-footer {
    text-align: center;
    font-size: 12px;
    padding: 8px;
    background-color: #f9fafb;
    color: #9ca3af;
}

/* --- 6. Bubble, Text & Proactive Popup (UI Improvements) --- */
.salesmine-bubble-container {
    display: flex;
    align-items: center;
    gap: 12px;
    position: fixed; /* Position relative to viewport */
    bottom: 20px;
}

#salesmine-widget-container.bottom-right .salesmine-bubble-container { right: 20px; }
#salesmine-widget-container.bottom-left .salesmine-bubble-container { left: 20px; }

/* --- THE FIX for the Egg-Shaped Bubble --- */
#salesmine-widget-container .salesmine-chat-bubble {
    width: 60px !important;       /* Force the width */
    height: 60px !important;      /* Force the height */
    padding: 0 !important;        /* Reset any theme padding */
    margin: 0 !important;         /* Reset any theme margin */
    border-radius: 50% !important;/* Force the circle shape */
    background-color: var(--salesmine-primary-color);
    border: none;
    color: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    position: relative;
    transition: transform 0.2s ease;
    display: block !important;    /* Ensure it's a block element */
}
#salesmine-widget-container .salesmine-chat-bubble:hover {
    transform: scale(1.1);
}
#salesmine-widget-container .salesmine-chat-bubble svg {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: opacity 0.2s ease, transform 0.2s ease;
}
#salesmine-widget-container .salesmine-chat-bubble .salesmine-icon-close { opacity: 0; }
#salesmine-widget-container .salesmine-chat-bubble.active .salesmine-icon-chat { opacity: 0; }
#salesmine-widget-container .salesmine-chat-bubble.active .salesmine-icon-close { opacity: 1; }

#salesmine-widget-container .salesmine-bubble-text {
    background-color: #ffffff;
    padding: 8px 16px;
    border-radius: 8px;
    color: #1f2937;
    font-size: 15px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    white-space: nowrap;
    opacity: 0;
    transform: translateY(10px);
    animation: fadeInBubbleText 0.5s 0.5s ease forwards;
}
@keyframes fadeInBubbleText {
    to { opacity: 1; transform: translateY(0); }
}
#salesmine-widget-container.bottom-left .salesmine-bubble-container { flex-direction: row-reverse; }

/* Proactive Message with Arrow */
.salesmine-proactive-message {
    position: absolute;
    bottom: 75px; /* Position above the bubble */
    width: 280px;
    background: #ffffff;
    padding: 16px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    cursor: pointer;

    opacity: 0;
    transform: translateY(15px);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: none;
}
.salesmine-proactive-message.active {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}
.salesmine-proactive-message p { margin: 0; font-size: 14px; color: #374151; }

#salesmine-widget-container.bottom-right .salesmine-proactive-message { right: 0; }
#salesmine-widget-container.bottom-left .salesmine-proactive-message { left: 0; }

.salesmine-proactive-arrow {
    width: 14px;
    height: 14px;
    background-color: #ffffff;
    position: absolute;
    bottom: -7px;
    transform: rotate(45deg);
}
#salesmine-widget-container.bottom-right .salesmine-proactive-arrow { right: 24px; }
#salesmine-widget-container.bottom-left .salesmine-proactive-arrow { left: 24px; }

/*================================================================
--- THIS IS THE FIX FOR MOBILE PROACTIVE POPUP ---
 ================================================================*/
@media (max-width: 768px) {
    #salesmine-widget-container .salesmine-proactive-message {
        position: fixed; /* THIS IS THE KEY: Locks it to the screen */
        bottom: 95px; /* Pulled up: 20px from bottom + 60px bubble height + 15px gap */
        right: 20px;  /* Default to bottom-right alignment */
        left: auto;   /* Unset any left positioning */
    }

    /* Override for bottom-left alignment on mobile */
    #salesmine-widget-container.bottom-left .salesmine-proactive-message {
        left: 20px;
        right: auto;
    }
}

/*
========================================================================
--- 7. LEAD CAPTURE FORM (DESIGNED FOR WIDGET-SCRIPT.JS V1.1.0) ---
========================================================================
*/

/* The main form container, which is appended to the messages area */
#salesmine-widget-container .salesmine-message-form {
    background-color: #f3f4f6; /* Matches agent message bubble background */
    border-radius: 18px;
    padding: 20px;
    margin: 10px 0;
    display: flex;
    flex-direction: column;
    gap: 15px; /* THE KEY: Creates the perfect gap between all form elements */
}

/* Style for the labels above each input field */
#salesmine-widget-container .salesmine-message-form label {
    font-size: 14px;
    font-weight: 600;
    color: var(--salesmine-primary-color);
    text-align: left; /* Ensures labels are aligned left */
}

/* General style for all input and textarea fields in the form */
#salesmine-widget-container .salesmine-message-form input,
#salesmine-widget-container .salesmine-message-form textarea {
    width: 100%;
    padding: 12px 14px;
    font-size: 15px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background-color: #ffffff;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    -webkit-appearance: none; /* Fix for iOS styling issues */
    font-family: inherit; /* Ensures it uses the same font */
}
#salesmine-widget-container .salesmine-message-form textarea {
    resize: vertical;
    min-height: 80px;
}

/* Highlight effect when a user clicks into a field */
#salesmine-widget-container .salesmine-message-form input:focus,
#salesmine-widget-container .salesmine-message-form textarea:focus {
    outline: none;
    border-color: var(--salesmine-primary-color);
    box-shadow: 0 0 0 3px var(--salesmine-primary-color-translucent);
}

/* The "Send Information" button */
#salesmine-widget-container .salesmine-form-submit-btn {
    width: 100%; /* Fills the width for a clean, centered look */
    padding: 12px 20px;
    font-size: 15px;
    font-weight: 600;
    color: #ffffff;
    background-color: var(--salesmine-primary-color);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    text-align: center; /* Ensures text is centered */
    transition: background-color 0.2s ease, opacity 0.2s ease;
    margin-top: 5px; /* Adds a little extra space above the button */
}

/* Style for the button when hovered or disabled */
#salesmine-widget-container .salesmine-form-submit-btn:hover {
    opacity: 0.9;
}
#salesmine-widget-container .salesmine-form-submit-btn:disabled {
    background-color: #9ca3af; /* Grey out when sending */
    cursor: wait;
}

/* Style for the final success message */
#salesmine-widget-container .salesmine-message-form-success {
    background-color: #d1fae5; /* Light green */
    color: #065f46; /* Dark green */
    border-radius: 18px;
    padding: 20px;
    margin: 10px 0;
    text-align: center;
    font-weight: 600;
}

/* Style for any error messages that appear */
#salesmine-widget-container .salesmine-form-error {
    color: #ef4444; /* Red */
    font-size: 14px;
    text-align: center;
    margin: -5px 0 5px 0; /* Position it nicely between field and button */
}

/* --- 7. End Styling Lead Capture Form --- */



/* --- 8. Responsive (Mobile) View --- */
@media (max-width: 768px) {
    #salesmine-widget-container,
    #salesmine-widget-container.bottom-right,
    #salesmine-widget-container.bottom-left {
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        position: fixed;
        /* FIX: No longer hidden, but not clickable either. This lets the bubble be seen. */
        pointer-events: none; 
    }
}
    /* When bubble is clicked, container shows up to display the full-screen window */
    #salesmine-widget-container.window-active-on-mobile {
        display: block;
    }

    /* --- 2. The Chat Window (Core Layout Fix) --- */
.salesmine-chat-window {
    width: 370px;
    max-width: calc(100vw - 40px);
    height: 70vh;
    max-height: 600px;
    background-color: #ffffff;
    border-radius: 16px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1), 0 5px 10px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    display: flex;
    flex-direction: column;

    /* --- NEW RULES START HERE --- */
    position: absolute; /* Change from default */
    bottom: 15px; /* Elevates it above the 60px bubble + 25px margin */
    border: 1px solid #e5e7eb; /* A default light border */
    border-left: 3px solid var(--salesmine-primary-color); /* Colored left border */
    border-right: 3px solid var(--salesmine-primary-color); /* Colored right border */
    /* --- NEW RULES END HERE --- */

    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
    pointer-events: none;
}
/* Adjust position based on widget alignment */
#salesmine-widget-container.bottom-right .salesmine-chat-window {
    right: 0;
}
#salesmine-widget-container.bottom-left .salesmine-chat-window {
    left: 0;
}

        /* Adjust bubble position on mobile */
    .salesmine-bubble-container {
        /* THE FIX: Give the bubble its own fixed position and make it clickable */
        position: fixed;
        bottom: 20px;
        right: 20px; /* Default to bottom-right on mobile */
        pointer-events: auto; /* This makes ONLY the bubble clickable */
        z-index: 10;
    }

    /* Adjust if the setting is bottom-left */
    #salesmine-widget-container.bottom-left .salesmine-bubble-container {
        left: 20px;
        right: auto;
    }