@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* Mobile-first Floating Chat (modern, animated) */

:root {
    --accent-1: #6366f1;
    --accent-2: #4f46e5;
    --bg: #ffffff;
    --muted: #9ca3af;
    --text: #0f172a;
    --border: #e5e7eb;
}

/* FAB */
#mwai-fab {
    position: fixed;
    bottom: 16px;
    right: 16px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
    cursor: pointer;
    z-index: 99999;
    box-shadow: 0 8px 30px rgba(79, 70, 229, 0.18);
    transition: transform 0.18s ease, box-shadow 0.18s ease, opacity 0.22s ease, visibility 0.22s ease;
}
#mwai-fab:hover { 
    transform: translateY(-3px); 
    box-shadow: 0 12px 40px rgba(79, 70, 229, 0.22); 
}
#mwai-fab.hidden-fab {
    opacity: 0;
    visibility: hidden;
    transform: scale(0);
    pointer-events: none;
}
#mwai-fab img { 
    width: 28px; 
    height: 28px; 
    filter: drop-shadow(0 1px 0 rgba(0,0,0,0.05)); 
}

/* Chat window */
#mwai-chat-window {
    position: fixed;
    bottom: 88px;
    right: 16px;
    width: 92%; /* Keep 92% for smaller screens */
    max-width: 100%; /* Allow full width on larger screens */
    max-height: 76vh;
    background: var(--bg);
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    overflow-x: hidden; /* Disable horizontal scrolling */
    overflow-y: hidden; /* Ensure main window doesn't scroll vertically, body handles it */
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.15);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    transition: transform 0.22s cubic-bezier(.2,.9,.2,1), opacity 0.18s ease;
    z-index: 99998;
}
#mwai-chat-window.hidden {
    opacity: 0;
    visibility: hidden;
    transform: scale(0.5) translate(50%, 50%); /* Start from bottom-right, scaled down */
    pointer-events: none; /* Disable interactions when hidden */
}

#mwai-chat-window.open {
    opacity: 1;
    visibility: visible;
    transform: scale(1) translate(0, 0); /* End at proper position */
    pointer-events: auto; /* Enable interactions when open */
}

/* Header */
#mwai-chat-header {
    background: linear-gradient(135deg, var(--accent-2), #4338ca);
    color: #fff;
    padding: 12px 14px;
    font-weight: 600;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
#mwai-chat-header img { 
    width: 20px; 
    height: 20px; 
    cursor: pointer; 
    filter: invert(100%); 
}

/* Body */
#mwai-chat-body {
    flex: 1;
    padding: 16px;
    overflow-y: auto; /* Enable vertical scrolling */
    overflow-x: hidden; /* Disable horizontal scrolling */
    background: #f8fafc;
}

/* Footer */
#mwai-chat-footer {
    display: flex;
    gap: 8px;
    padding: 10px;
    align-items: center;
    border-top: 1px solid var(--border);
    background: #fff;
}
#mwai-user-input {
    flex: 1;
    padding: 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    outline: none;
    font-size: 14px;
    background: #fbfdff;
}
#mwai-user-input:focus { 
    box-shadow: 0 6px 18px rgba(79,70,229,0.06); 
    border-color: rgba(79,70,229,0.12); 
}
#mwai-send-btn {
    padding: 8px 10px;
    background: transparent;
    border: none;
    cursor: pointer;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}
#mwai-send-btn img { 
    width: 24px; 
    height: 24px; 
}

/* Messages */
.mwai-msg { 
    margin-bottom: 16px; 
    display: block; 
    max-width: 100%; /* AI response takes full width */
    word-wrap: break-word; 
}
.mwai-msg p { 
    margin: 0; 
    display: inline-block; 
    padding: 12px 16px; 
    border-radius: 18px; 
    font-size: 14px; 
    line-height: 1.5; 
    animation: fadeInUp .25s ease; 
    white-space: pre-wrap; /* Preserve formatting */
    word-break: break-word; /* Ensure long words break to prevent overflow */
}
.mwai-msg.user { 
    margin-left: auto; 
    text-align: right; 
}
.mwai-msg.user p { 
    background: linear-gradient(135deg, var(--accent-1), var(--accent-2)); 
    color: #fff; 
    border-bottom-right-radius: 6px; 
    box-shadow: 0 6px 16px rgba(79,70,229,0.12); 
}
.mwai-msg.ai p { 
    background: transparent; /* Remove background to eliminate bubble effect */
    color: var(--text); 
    border: none; /* Remove border */
    border-radius: 0; /* Remove border-radius */
    box-shadow: none; /* Remove box-shadow */
    padding: 0; /* Remove padding to make it flush with the edge */
    font-size: 15px; /* Adjusted font size */
    text-transform: none; /* Ensure normal capitalization */
}

/* Typing indicator */
.mwai-msg.typing { 
    display: inline-flex; 
    gap: 8px; 
    align-items: center; 
}
.mwai-msg.typing span { 
    display: block; 
    width: 6px; 
    height: 6px; 
    background: var(--muted); 
    border-radius: 50%; 
    animation: blink 1.2s infinite both; 
}
.mwai-msg.typing span:nth-child(2) { 
    animation-delay: .15s; 
}
.mwai-msg.typing span:nth-child(3) { 
    animation-delay: .3s; 
}

/* Quick buttons */
.mwai-quick-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-start;
    margin-bottom: 16px;
}
.mwai-quick-buttons button {
    padding: 8px 16px;
    border-radius: 20px;
    background: #eef2ff;
    color: var(--accent-2);
    border: none;
    cursor: pointer;
    font-weight: 500;
    font-size: 13px;
    transition: background 0.2s ease;
}
.mwai-quick-buttons button:hover {
    background: #e0e7ff;
}

/* Product grid / unified card */
.mwai-products { 
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); /* fluid two-column layout */
    gap: 6px; 
    margin-top: 24px; 
    margin-bottom: 16px; 
    padding: 6px; 
    background: #f8fafc; 
    border-radius: 12px;
    width: 100%; /* Ensure it takes full width of its parent */
}

.mwai-product-card {
    display: flex;
    flex-direction: column; /* vertical layout */
    align-items: center;
    text-decoration: none;
    color: inherit;
    border-radius: 12px;
    border: 1px solid var(--border);
    padding: 6px;
    background: #fff;
    transition: transform .18s ease, box-shadow .18s ease;
    text-align: center;
    position: relative; /* for badge */
}

.mwai-product-card:hover { 
    transform: translateY(-4px); 
    box-shadow: 0 10px 24px rgba(15,23,42,0.08); 
}

/* Product image - square, responsive */
.mwai-product-card img { 
    width: 100%;       
    max-width: 100%;  
    height: auto; 
    aspect-ratio: 1/1; 
    border-radius: 6px; 
    object-fit: cover; 
    margin-bottom: 8px;
}

/* Product meta */
.mwai-product-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 100%;
}

.mwai-product-meta h4 { 
    margin: 0; 
    font-size: 10px; 
    font-weight: 600; 
    line-height: 1.3;
    color: #111827;
    text-transform: none; /* normal case */
    display: -webkit-box;
    -webkit-line-clamp: 2; 
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mwai-product-price { 
    font-size: 10px; 
    color: var(--accent-2); 
    font-weight: 700; 
}

/* CTA button */
.mwai-product-cta {
    margin-top: 6px;
    padding: 4px 8px;
    background-color: var(--accent-1);
    color: #fff;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 600;
    text-decoration: none;
    display: inline-block;
}

/* Badge on top-right */
.mwai-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 2px 6px;
    border-radius: 6px;
    font-size: 9px;
    font-weight: 600;
    text-transform: none; /* normal case */
    line-height: 1.2;
    z-index: 1; /* Ensure badge is above other elements if needed */
}

/* Product checkbox */
.mwai-product-checkbox {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2; /* Ensure checkbox is above badge */
    width: 18px;
    height: 18px;
    cursor: pointer;
    appearance: none; /* Hide default checkbox */
    background-color: rgba(255, 255, 255, 0.8);
    border: 1px solid var(--border);
    border-radius: 4px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mwai-product-checkbox:checked {
    background-color: var(--accent-1);
    border-color: var(--accent-1);
}

.mwai-product-checkbox:checked::after {
    content: '✔';
    color: #fff;
    font-size: 12px;
    line-height: 1;
}

.mwai-product-checkbox:hover {
    border-color: var(--accent-1);
}

.mwai-badge.local {
    background: #eef2ff;
    color: var(--accent-2);
}

.mwai-badge.global {
    background: #fff7ed;
    color: #d97706;
}

/* Tablet (768px–1023px) adjustments */
@media (max-width: 1023px) and (min-width: 768px) {
    .mwai-product-card img {
        max-width: 100%; /* Images take full width of card */
    }
    .mwai-product-meta h4,
    .mwai-product-price,
    .mwai-product-cta {
        font-size: 9px;
    }
    .mwai-badge {
        font-size: 8px;
        padding: 2px 4px;
    }
}

/* Mobile (<768px) adjustments */
@media (max-width: 767px) {
    .mwai-products {
        grid-template-columns: repeat(2, 1fr); /* always 2 columns on mobile */
        gap: 8px;
    }
    .mwai-product-card img {
        max-width: 100%; /* Images take full width of card */
    }
    .mwai-product-meta h4,
    .mwai-product-price,
    .mwai-product-cta {
        font-size: 10px; /* Increased from 8px for better readability */
    }
    .mwai-badge {
        font-size: 9px; /* Increased from 7px for better readability */
        padding: 1px 3px;
    }
}



/* Small animations */
@keyframes blink { 
    0%, 80%, 100% { opacity: .25 } 
    40% { opacity: 1 } 
}
@keyframes fadeInUp { 
    from { opacity: 0; transform: translateY(8px) } 
    to { opacity: 1; transform: translateY(0) } 
}

/* Desktop tweaks */
@media(min-width: 768px) {
    #mwai-chat-window { 
        width: 90%; /* Allow chat window to take more width on desktop */
        max-width: 600px; /* Example: increased max-width for desktop */
        max-height: 520px; 
        right: 24px; 
        bottom: 96px; 
    }
}
