/**
 * Enhanced Chatbot Styles with CSS Variables for Dynamic Customization
 */

/* Store all customizable variables in :root for dynamic updates */
:root {
    /* Color Variables */
    --afc-primary-color: #0073aa;
    --afc-primary-color-hover: #005d87;
    --afc-background-color: #fff;
    --afc-conversation-bg-color: #f9f9f9;
    --afc-user-message-bg-color: #dcf8c6;
    --afc-bot-message-bg-color: #e5e5ea;
    --afc-rating-prompt-bg-color: #f0f0f0;
    --afc-text-color: #333;
    --afc-header-text-color: #fff;
    --afc-border-color: #ddd;
    --afc-shadow-color: rgba(0, 0, 0, 0.2);
    --afc-error-color: #e74c3c;
    --afc-button-color: #0073aa; /* New: Default button color */
    --afc-button-color-hover: #005d87; /* New: Default button hover color */
    
    /* Size Variables */
    --afc-chatbot-width: 350px;
    --afc-chatbot-height: 400px; /* Height of the chat body when open */
    --afc-minimized-circle-size: 60px; /* Size of the circle button */
    --afc-minimized-rectangle-height: 48px; /* Approx height of header */
    --afc-border-radius: 10px;
    --afc-font-size: 14px;
    --afc-padding: 15px;
        
    /* Font Variables */
    --afc-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    
    /* Animation Speed */
    --afc-transition-speed: 0.25s; /* Slightly faster transitions */
}

/* Styles for the Shadow Host - controls overall size and visibility */
/* JS will add classes like afc-state-open, afc-state-minimized-circle, afc-state-minimized-rectangle */
#afc-chatbot-shadow-host {
    /* Base positioning is handled by JS (applyChatbotPosition) */
    /* Transition for size changes */
    transition: width var(--afc-transition-speed) ease, height var(--afc-transition-speed) ease, opacity var(--afc-transition-speed) ease, transform var(--afc-transition-speed) ease;
}

#afc-chatbot-shadow-host.afc-state-open {
    width: var(--afc-chatbot-width);
    height: auto; /* Height will be determined by its content (header + body) */
    opacity: 1;
    transform: scale(1);
}

#afc-chatbot-shadow-host.afc-state-minimized-rectangle {
    width: var(--afc-chatbot-width); /* Can be adjusted if a smaller rectangle is desired */
    height: var(--afc-minimized-rectangle-height); /* Height of the header */
    opacity: 1;
    transform: scale(1);
}

#afc-chatbot-shadow-host.afc-state-minimized-circle {
    width: var(--afc-minimized-circle-size) !important; /* Force size */
    height: var(--afc-minimized-circle-size) !important; /* Force size */
    opacity: 1;
    transform: scale(1);
}


/* Styles for the main container within the Shadow DOM */
#afc-chatbot-container {
    width: 100%; /* Fill the host */
    height: 100%; /* Fill the host */
    background-color: var(--afc-background-color);
    font-family: var(--afc-font-family);
    font-size: var(--afc-font-size);
    color: var(--afc-text-color);
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Crucial for border-radius and transitions */
    transition: border-radius var(--afc-transition-speed) ease, box-shadow var(--afc-transition-speed) ease;
    box-shadow: 0 5px 25px var(--afc-shadow-color);
    border-radius: var(--afc-border-radius); /* Default for open and rectangle */
}

#afc-chatbot-container.afc-style-circle-minimized {
    border-radius: 50%; /* Make it a circle */
}

.afc-chatbot-header {
    background-color: var(--afc-primary-color);
    color: var(--afc-header-text-color);
    padding: var(--afc-padding);
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: background-color var(--afc-transition-speed) ease, padding var(--afc-transition-speed) ease;
    /* border-radius applied by parent container's overflow:hidden */
}
#afc-chatbot-container.afc-style-circle-minimized .afc-chatbot-header {
    padding: 0; /* Remove padding for circle */
    width: 100%;
    height: 100%;
    justify-content: center; /* Center the button icon */
}


.afc-chatbot-header span { /* Title text */
    transition: opacity var(--afc-transition-speed) ease;
}
#afc-chatbot-container.afc-style-circle-minimized .afc-chatbot-header span {
    display: none; /* Hide title in circle mode */
}


#afc-toggle-chatbot { /* The actual button element */
    background: none;
    border: none;
    color: var(--afc-header-text-color);
    font-size: 20px; /* For text like + or - */
    cursor: pointer;
    padding: 0 5px;
    line-height: 1;
    transition: color var(--afc-transition-speed) ease, transform var(--afc-transition-speed) ease, width var(--afc-transition-speed) ease, height var(--afc-transition-speed) ease;
    display: flex; /* For centering SVG */
    align-items: center;
    justify-content: center;
    flex-shrink: 0; /* Prevent button from shrinking */
}
#afc-chatbot-container.afc-style-circle-minimized #afc-toggle-chatbot {
    width: 100%; /* Fill the circular header */
    height: 100%;
    padding: 0;
    font-size: inherit; /* Reset font size if using SVG */
}
#afc-chatbot-container.afc-style-circle-minimized #afc-toggle-chatbot svg {
    width: calc(var(--afc-minimized-circle-size) * 0.5); /* Icon size relative to button */
    height: calc(var(--afc-minimized-circle-size) * 0.5);
    fill: var(--afc-header-text-color);
}


.afc-chatbot-header button:hover {
    transform: scale(1.1); /* Subtle hover for the button content */
}
#afc-chatbot-container.afc-style-circle-minimized .afc-chatbot-header:hover {
    background-color: var(--afc-primary-color-hover); /* Hover on whole circle */
}


.afc-chatbot-body {
    /* display is controlled by JS (flex or none) */
    height: var(--afc-chatbot-height); 
    flex-direction: column;
    transition: height var(--afc-transition-speed) ease, opacity var(--afc-transition-speed) ease, transform var(--afc-transition-speed) ease;
    /* Initially hidden by JS if minimized, or animated in */
}
#afc-chatbot-container.afc-style-circle-minimized .afc-chatbot-body,
#afc-chatbot-container.afc-style-rectangle-minimized .afc-chatbot-body {
    display: none !important;
}


#afc-conversation {
    flex: 1;
    padding: var(--afc-padding);
    overflow-y: auto;
    background-color: var(--afc-conversation-bg-color);
    transition: background-color var(--afc-transition-speed) ease;
    scroll-behavior: smooth;
}

.afc-input-area {
    display: flex;
    padding: 10px;
    border-top: 1px solid var(--afc-border-color);
    background-color: var(--afc-background-color);
    transition: background-color var(--afc-transition-speed) ease;
}

#afc-user-input {
    flex: 1;
    padding: 12px;
    border: 1px solid var(--afc-border-color);
    border-radius: calc(var(--afc-border-radius) / 2);
    outline: none;
    font-family: var(--afc-font-family);
    font-size: var(--afc-font-size);
    color: var(--afc-text-color);
    transition: border-color var(--afc-transition-speed) ease, box-shadow var(--afc-transition-speed) ease;
}

#afc-user-input:focus {
    border-color: var(--afc-primary-color);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--afc-primary-color) 20%, transparent);
}

#afc-send-button {
    margin-left: 10px;
    padding: 10px 15px;
    background-color: var(--afc-primary-color);
    color: var(--afc-header-text-color);
    border: none;
    border-radius: calc(var(--afc-border-radius) / 2);
    cursor: pointer;
    font-family: var(--afc-font-family);
    transition: background-color var(--afc-transition-speed) ease, transform var(--afc-transition-speed) ease;
}

#afc-send-button:hover {
    background-color: var(--afc-primary-color-hover);
    transform: translateY(-1px); /* Subtle lift */
}

#afc-send-button:active {
    transform: translateY(0);
}

.afc-message {
    margin-bottom: 15px;
    padding: 12px 14px;
    border-radius: 14px;
    max-width: 80%;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08); /* Softer shadow */
    line-height: 1.45; /* Improved line height */
    transition: all 0.3s ease;
}

.afc-message > *:first-child {
    margin-top: 0;
}

.afc-message > *:last-child {
    margin-bottom: 0;
}

.afc-message-appear {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
}

.afc-message-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.afc-user-message {
    background-color: var(--afc-user-message-bg-color);
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.afc-bot-message {
    background-color: var(--afc-bot-message-bg-color);
    margin-right: auto;
    border-bottom-left-radius: 4px;
}

.afc-bot-message a {
    color: var(--afc-primary-color);
    text-decoration: none;
    border-bottom: 1px dotted;
}

.afc-bot-message a:hover {
    color: var(--afc-primary-color-hover);
    border-bottom: 1px solid;
}

.afc-code-block {
    background: #f1f1f1;
    border-radius: 6px;
    margin: 8px 0;
    overflow: auto;
}

.afc-code-block pre {
    padding: 10px;
    margin: 0;
    font-family: monospace; /* Ensure monospace for code */
    font-size: 0.9em; /* Slightly smaller for code blocks */
}

.afc-typing-indicator {
    /* Make the container a flex row to align status and dots */
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px; /* Space between status text and dots */
}

.afc-status-text {
    font-size: 0.9em;
    color: #666; /* A neutral, slightly muted color */
    font-style: italic;
    animation: afc-fade-in 0.5s ease;
}

@keyframes afc-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Ensure the typing bubble container still looks good */
.afc-typing-bubble-container {
    display: flex;
    align-items: center;
    gap: 4px;
}

.afc-typing-bubble {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--afc-text-color);
    opacity: 0.6;
    animation: afc-bubble-animation 1.4s infinite ease-in-out both;
}

.afc-typing-bubble:nth-child(1) { animation-delay: -0.32s; }
.afc-typing-bubble:nth-child(2) { animation-delay: -0.16s; }

@keyframes afc-bubble-animation {
    0%, 80%, 100% { transform: scale(0.7); }
    40% { transform: scale(1); opacity: 1; }
}

.afc-rating-prompt {
    background-color: var(--afc-rating-prompt-bg-color);
    border: 1px solid var(--afc-border-color);
    border-radius: 12px;
    padding: var(--afc-padding);
    margin: 15px 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    transition: all 0.3s ease;
}

.afc-rating-appear { opacity: 0; transform: translateY(10px); }
.afc-rating-visible { opacity: 1; transform: translateY(0); }

.afc-rating-title-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.afc-rating-title-container p { margin: 0; font-weight: bold; color: var(--afc-text-color); }

.afc-rating-minimize {
    background: none; border: none; color: var(--afc-primary-color);
    font-size: 20px; cursor: pointer; padding: 0; line-height: 1;
    transition: transform 0.2s ease;
}
.afc-rating-minimize:hover { transform: scale(1.2); }

.afc-rating-content {
    transition: max-height var(--afc-transition-speed) ease-out, opacity var(--afc-transition-speed) ease-out,
                visibility var(--afc-transition-speed) ease-out, padding var(--afc-transition-speed) ease-out, margin var(--afc-transition-speed) ease-out;
    max-height: 500px; opacity: 1; visibility: visible; overflow: hidden;
}
.afc-rating-content.afc-minimized {
    max-height: 0; opacity: 0; visibility: hidden;
    padding-top: 0 !important; padding-bottom: 0 !important;
    margin-top: 0 !important; margin-bottom: 0 !important;
    border-top: none; /* Prevent border showing when minimized */
}

.afc-rating-stars { display: flex; justify-content: center; margin: 12px 0; }
.afc-rating-star {
    font-size: 28px; color: #ccc; cursor: pointer; margin: 0 5px;
    transition: all 0.2s ease; transform-origin: center;
}
.afc-rating-star.active { color: #ffc107; }
.afc-rating-star.selected { transform: scale(1.1); }
.afc-rating-star:hover { transform: scale(1.2); color: #ffdb58; }

.afc-rating-feedback {
    width: calc(100% - 20px); box-sizing: border-box; margin: 10px auto;
    padding: 12px; border: 1px solid var(--afc-border-color);
    border-radius: calc(var(--afc-border-radius) / 2); resize: vertical; min-height: 80px;
    font-family: var(--afc-font-family); font-size: var(--afc-font-size); color: var(--afc-text-color);
    display: block; transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.afc-rating-feedback:focus {
    border-color: var(--afc-primary-color);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--afc-primary-color) 20%, transparent);
    outline: none;
}

.afc-rating-submit {
    background-color: var(--afc-primary-color); color: var(--afc-header-text-color);
    border: none; padding: 10px 20px; border-radius: 20px; cursor: pointer;
    font-weight: 500; display: flex; align-items: center; justify-content: center;
    margin: 10px auto 0; min-width: 120px; transition: all 0.2s ease; position: relative;
}
.afc-rating-submit:hover {
    background-color: var(--afc-primary-color-hover); transform: translateY(-2px);
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.afc-rating-submit:active { transform: translateY(0); box-shadow: none; }
.afc-rating-submit.afc-loading .afc-submit-text { visibility: hidden; }
.afc-rating-submit.afc-loading .afc-submit-loader {
    position: absolute; width: 20px; height: 20px; border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%; border-top-color: white; animation: afc-spin 0.8s linear infinite;
}
@keyframes afc-spin { to { transform: rotate(360deg); } }
.afc-rating-submit:disabled { background-color: #cccccc; cursor: not-allowed; transform: none; box-shadow: none; }

.afc-rating-alert {
    color: var(--afc-error-color); font-size: 0.95em; text-align: center; margin: 5px 0;
    padding: 5px; border-radius: 4px; background-color: color-mix(in srgb, var(--afc-error-color) 10%, transparent);
}
.afc-thank-you-message {
    text-align: center; padding: 15px 10px; color: var(--afc-primary-color);
    font-weight: bold; font-size: 1.1em;
}

.afc-loading-message, .afc-error-message { text-align: center; padding: 10px; color: #777; font-style: italic; }
.afc-input-error-message { color: var(--afc-error-color); font-size: 0.9em; padding: 5px 10px 0; text-align: center; }
.afc-input-shake { animation: afc-shake 0.5s; }
@keyframes afc-shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}
.afc-disabled { opacity: 0.6; cursor: not-allowed !important; pointer-events: none; }

@media (max-width: 480px) {
    #afc-chatbot-shadow-host.afc-state-open { /* Ensure open state respects smaller screens */
         width: 95vw; /* More responsive width */
         /* height: auto; Let content define height */
    }
    #afc-chatbot-container { /* Container inside host */
        --afc-chatbot-height: 60vh; /* Adjust height for smaller screens */
        --afc-font-size: 13px; 
        --afc-padding: 10px; 
    }
    .afc-chatbot-body { height: var(--afc-chatbot-height); }
    .afc-rating-star { font-size: 22px; }
    #afc-user-input, #afc-send-button { padding: 8px; font-size: 13px; }
    #afc-send-button { padding: 8px 12px; }
    .afc-message { padding: 8px; margin-bottom: 10px; }
}

/*--------------------------------------------------------------
# Product Card Container
--------------------------------------------------------------*/
.afc-bot-message .product-cards-container {
    display: flex;
    flex-direction: column;
    gap: 12px; /* This creates the space between multiple product cards */
    margin-top: 8px;
    margin-bottom: 8px;
}

/*--------------------------------------------------------------
# Product Card Styles
--------------------------------------------------------------*/
.afc-bot-message .product-card {
    background-color: var(--afc-background-color, #fff);
    border-radius: calc(var(--afc-border-radius) / 1.5);
    padding: 15px; /* Reverted padding to 15px */
    margin-top: 10px;
    border: 1px solid var(--afc-border-color, #ddd);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    font-family: var(--afc-font-family);
    color: var(--afc-text-color);
}

.product-card .product-header .product-title {
    font-size: 1.1em;
    font-weight: 600;
    margin: 0 0 5px 0;
}

.product-card .product-header .product-sku {
    font-size: 0.85em;
    color: #777;
    margin: 0 0 10px 0;
}

.product-card .product-summary p {
    margin: 0 0 12px 0;
    font-size: 0.95em;
    line-height: 1.5;
}

.product-card .product-details .product-specs {
    list-style: none;
    padding: 0;
    margin: 0 0 15px 0;
    font-size: 0.9em;
}

.product-card .product-details .product-specs li {
    margin-bottom: 5px;
    display: flex;
    justify-content: space-between;
}

.product-card .stock-status {
    font-weight: bold;
}

.product-card .stock-status.in-stock {
    color: #28a745;
}

.product-card .stock-status.out-of-stock {
    color: #dc3545;
}

.product-card .product-link-button {
    display: block;
    width: 100%;
    padding: 12px;
    background-color: var(--afc-button-color, #0073aa); /* Changed to new variable */
    color: var(--afc-header-text-color, #fff);
    text-align: center;
    text-decoration: none;
    border-radius: calc(var(--afc-border-radius) / 2);
    font-weight: 500;
    transition: background-color 0.2s ease;
    box-sizing: border-box; 
    border-bottom: none !important;
}

.product-card .product-link-button:hover {
    background-color: var(--afc-button-color-hover, #005d87); /* Changed to new variable */
    color: var(--afc-header-text-color, #fff); /* Added this line */
    border-bottom: none !important;
}

/* --- NEW STYLES FOR HEADER --- */
.afc-chatbot-header {
    /* This rule likely already exists, just ensure it has display: flex */
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.afc-header-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    margin-right: 10px; /* Add space between text and close button */
    overflow: hidden; /* Prevents long text from breaking layout */
}

.afc-header-title {
    /* font-weight: bold; is likely inherited */
    line-height: 1.2;
    transition: opacity var(--afc-transition-speed) ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.afc-session-id {
    font-size: 0.8em; /* Make it smaller */
    font-weight: 400; /* Make it normal weight */
    opacity: 0.9;
    line-height: 1.1;
    transition: opacity var(--afc-transition-speed) ease;
    display: none; /* JS will show it when chat is open */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --- UPDATE EXISTING RULE FOR CIRCLE MODE --- */
/* Find the rule for .afc-chatbot-header span in circle mode */
#afc-chatbot-container.afc-style-circle-minimized .afc-chatbot-header span {
    display: none; /* This rule is fine, it will hide the title */
}

/* ADD this rule to also hide the new container in circle mode */
#afc-chatbot-container.afc-style-circle-minimized .afc-header-content {
    display: none;
}

/* --- UPDATE EXISTING RULE FOR HEADER SPAN (TITLE) --- */
/* Change this existing rule: */
/*
.afc-chatbot-header span { 
    transition: opacity var(--afc-transition-speed) ease;
}
*/
/* To this (to be more specific): */
.afc-header-title { /* Title text */
    transition: opacity var(--afc-transition-speed) ease;
}

/* And change this rule: */
/*
#afc-chatbot-container.afc-style-circle-minimized .afc-chatbot-header span {
    display: none; 
}
*/
/* To this: */
#afc-chatbot-container.afc-style-circle-minimized .afc-header-title {
    display: none; /* Hide title in circle mode */
}