/**
 * Shimio Floating AI Assistant Styling
 * Premium Glassmorphism, Responsive layout, Light/Dark configurations, Bouncing animations.
 */

:root {
    --chat-primary: #1E4638;       /* Forest Green */
    --chat-primary-hover: #133025;
    --chat-primary-light: #E8EFEA;
    --chat-accent: #D4AF37;        /* Gold */
    --chat-border-radius: 12px;
    --chat-shadow: 0 12px 32px rgba(30, 70, 56, 0.15);
    
    /* Light Mode Default Variables */
    --chat-bg: rgba(255, 255, 255, 0.85);
    --chat-text-main: #333333;
    --chat-text-dark: #111111;
    --chat-text-muted: #777777;
    --chat-border: rgba(30, 70, 56, 0.1);
    --chat-bubble-ai-bg: rgba(232, 239, 234, 0.9);
    --chat-bubble-ai-text: #111111;
    --chat-bubble-user-bg: #1E4638;
    --chat-bubble-user-text: #FFFFFF;
    --chat-input-bg: #FFFFFF;
    --chat-input-border: #EDEDED;
}

/* Dark Mode Variables Override */
.shimio-chat-dark {
    --chat-bg: rgba(20, 26, 23, 0.92);
    --chat-text-main: #E2E8F0;
    --chat-text-dark: #FFFFFF;
    --chat-text-muted: #94A3B8;
    --chat-border: rgba(255, 255, 255, 0.08);
    --chat-bubble-ai-bg: rgba(30, 45, 38, 0.9);
    --chat-bubble-ai-text: #E2E8F0;
    --chat-bubble-user-bg: #1e4638;
    --chat-bubble-user-text: #FFFFFF;
    --chat-input-bg: #121714;
    --chat-input-border: rgba(255, 255, 255, 0.1);
}

/* 1. Floating Container */
.shimio-chat-container {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 99999;
    font-family: 'Outfit', 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* 2. Floating Action Button */
.shimio-chat-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: var(--chat-primary);
    color: #FFFFFF;
    border: none;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(30, 70, 56, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    position: relative;
}

.shimio-chat-toggle-btn:hover {
    background-color: var(--chat-primary-hover);
    transform: scale(1.08) translateY(-2px);
    box-shadow: 0 12px 28px rgba(30, 70, 56, 0.4);
}

.shimio-chat-toggle-btn svg {
    transition: transform 0.3s ease;
}

/* 3. Chat Window Layout */
.shimio-chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 580px;
    background: var(--chat-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--chat-border);
    border-radius: var(--chat-border-radius);
    box-shadow: var(--chat-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.4s cubic-bezier(0.25, 1, 0.5, 1);
    transform-origin: bottom right;
    animation: chatOpenAnim 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes chatOpenAnim {
    0% { opacity: 0; transform: scale(0.8) translateY(20px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

/* 4. Chat Header */
.chat-header {
    background-color: var(--chat-primary);
    color: #FFFFFF;
    padding: 15px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-top-left-radius: inherit;
    border-top-right-radius: inherit;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background-color: #FFFFFF;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    box-sizing: border-box;
    overflow: hidden; /* Clips square corners and prevents overflow */
    border: 2.5px solid #FFFFFF; /* High-quality circular ring outline */
}

.chat-avatar img {
    width: 100%;
    height: 100%; /* Forces exact circular height containment */
    object-fit: cover; /* Crops center of image rather than squishing */
    border-radius: 50%;
}

.chat-avatar-status {
    width: 10px;
    height: 10px;
    background-color: #10B981; /* Green status dot */
    border: 2px solid var(--chat-primary);
    border-radius: 50%;
    position: absolute;
    bottom: -1px;
    right: -1px;
}

.chat-title {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.2;
    color: #FFFFFF;
}

.chat-status {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.85);
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-header-action-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    padding: 5px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.chat-header-action-btn:hover {
    color: #FFFFFF;
    background-color: rgba(255, 255, 255, 0.1);
}

/* 5. Chat Scroll Body */
.chat-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Custom Scrollbar */
.chat-body::-webkit-scrollbar {
    width: 6px;
}
.chat-body::-webkit-scrollbar-track {
    background: transparent;
}
.chat-body::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 10px;
}
.shimio-chat-dark .chat-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
}

/* 6. Chat Bubbles */
.chat-message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: messageFadeIn 0.3s ease-out forwards;
}

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

.chat-message.assistant {
    align-self: flex-start;
}

.chat-message.user {
    align-self: flex-end;
}

.chat-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.5;
    word-break: break-word;
}

.chat-message.assistant .chat-bubble {
    background-color: var(--chat-bubble-ai-bg);
    color: var(--chat-bubble-ai-text);
    border-top-left-radius: 2px;
    border: 1px solid var(--chat-border);
}

.chat-message.user .chat-bubble {
    background-color: var(--chat-bubble-user-bg);
    color: var(--chat-bubble-user-text);
    border-top-right-radius: 2px;
}

/* 7. Markdown content within bubbles */
.chat-bubble p {
    margin: 0 0 8px 0;
}
.chat-bubble p:last-child {
    margin-bottom: 0;
}
.chat-bubble strong {
    font-weight: 700;
    color: var(--chat-text-dark);
}
.chat-message.user .chat-bubble strong {
    color: #FFFFFF;
}
.chat-bubble ul, .chat-bubble ol {
    margin: 5px 0;
    padding-left: 18px;
}
.chat-bubble li {
    margin-bottom: 4px;
}
.chat-bubble a {
    color: var(--chat-accent);
    text-decoration: underline;
    font-weight: 600;
}
.chat-message.user .chat-bubble a {
    color: #FFF;
}

/* 8. Bouncing Typing Loader */
.chat-typing-indicator {
    align-self: flex-start;
    background-color: var(--chat-bubble-ai-bg);
    border: 1px solid var(--chat-border);
    padding: 12px 16px;
    border-radius: 14px;
    border-top-left-radius: 2px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-typing-indicator span {
    width: 6px;
    height: 6px;
    background-color: var(--chat-text-muted);
    border-radius: 50%;
    display: inline-block;
    animation: bounceTyping 1.4s infinite ease-in-out both;
}

.chat-typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.chat-typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

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

/* 9. Suggested Query Chips */
.chat-suggestions-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 5px;
}

.chat-suggestion-chip {
    background-color: var(--chat-input-bg);
    color: var(--chat-primary);
    border: 1px solid var(--chat-border);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    font-weight: 600;
}

.chat-suggestion-chip:hover {
    background-color: var(--chat-primary-light);
    border-color: var(--chat-primary);
}

.shimio-chat-dark .chat-suggestion-chip {
    color: var(--chat-accent);
}
.shimio-chat-dark .chat-suggestion-chip:hover {
    background-color: rgba(212, 175, 55, 0.1);
    border-color: var(--chat-accent);
}

/* 10. Product Card Recommendations */
.chat-products-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 8px 0;
}

.chat-product-card {
    background: var(--chat-input-bg);
    border: 1px solid var(--chat-border);
    border-radius: 8px;
    padding: 10px;
    display: flex;
    gap: 10px;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.03);
    transition: transform 0.2s ease;
}

.chat-product-card:hover {
    transform: translateY(-2px);
}

.chat-product-img {
    width: 60px;
    height: 60px;
    border-radius: 4px;
    object-fit: cover;
    background-color: var(--chat-primary-light);
}

.chat-product-info {
    flex: 1;
    min-width: 0;
}

.chat-product-name {
    font-size: 13px;
    font-weight: 700;
    margin: 0 0 2px 0;
    color: var(--chat-text-dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-product-market {
    font-size: 10px;
    color: var(--chat-text-muted);
    font-weight: 600;
}

.chat-product-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 4px;
}

.chat-product-price {
    font-size: 12.5px;
    font-weight: 700;
    color: var(--chat-primary);
}
.shimio-chat-dark .chat-product-price {
    color: var(--chat-accent);
}

.chat-product-btn {
    background-color: var(--chat-primary);
    color: #FFFFFF;
    border: none;
    font-size: 10.5px;
    padding: 4px 10px;
    border-radius: 4px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s ease;
}

.chat-product-btn:hover {
    background-color: var(--chat-primary-hover);
}

/* 11. Human Escalation panel */
.chat-escalation-card {
    background: rgba(212, 175, 55, 0.08);
    border: 1.5px dashed var(--chat-accent);
    border-radius: 8px;
    padding: 15px;
    margin: 5px 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-escalation-title {
    font-size: 13.5px;
    font-weight: 700;
    color: var(--chat-text-dark);
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-escalation-details {
    font-size: 12px;
    color: var(--chat-text-main);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-escalation-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-escalation-item svg {
    color: var(--chat-primary);
    flex-shrink: 0;
}
.shimio-chat-dark .chat-escalation-item svg {
    color: var(--chat-accent);
}

.chat-whatsapp-btn {
    background-color: #25D366; /* WhatsApp brand color */
    color: #FFFFFF !important;
    text-decoration: none !important;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap; /* Prevents text from wrapping or cutting off */
    transition: background 0.2s ease;
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.2);
}

.chat-whatsapp-btn:hover {
    background-color: #128C7E;
}

/* 12. Input Form Footer */
.chat-input-form {
    padding: 15px;
    background-color: var(--chat-bg);
    border-top: 1px solid var(--chat-border);
    display: flex;
    gap: 8px;
}

.chat-input {
    flex: 1;
    background-color: var(--chat-input-bg);
    border: 1px solid var(--chat-input-border);
    color: var(--chat-text-dark);
    padding: 10px 14px;
    border-radius: 20px;
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s ease;
}

.chat-input:focus {
    border-color: var(--chat-primary);
}

.chat-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: var(--chat-primary);
    color: #FFFFFF;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chat-send-btn:hover {
    background-color: var(--chat-primary-hover);
    transform: scale(1.05);
}

/* 13. Mobile Responsiveness */
@media (max-width: 480px) {
    .shimio-chat-container {
        bottom: 15px;
        right: 15px;
    }
    
    .shimio-chat-window {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        right: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
        border: none;
        z-index: 100000;
    }
}
