/* Chat Widget - Production Ready CSS */
/* All styles are scoped to avoid conflicts with existing site styles */

/* Floating button */
.chat-widget-container .chat-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    border-radius: 30px;
    background-color: #7367F0;
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
    z-index: 1000;
}

.chat-widget-container .chat-button:hover {
    transform: scale(1.05);
}

.chat-widget-container .chat-button svg {
    width: 28px;
    height: 28px;
}

/* Chat window */
.chat-widget-container .chat-window {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 420px;
    height: 650px;
    background-color: white;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.12);
    display: none;
    flex-direction: column;
    z-index: 1000;
    overflow: hidden;
    border: 1px solid #e0e0e0;
}

.chat-widget-container .chat-window.rtl {
    direction: rtl;
}

.chat-widget-container .chat-window.show {
    display: flex;
}

/* Chat header */
.chat-widget-container .chat-header {
    padding: 20px;
    background-color: #7367F0;
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-widget-container .chat-window.rtl .chat-header {
    flex-direction: row-reverse;
}

.chat-widget-container .chat-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-widget-container .chat-title {
    font-weight: 600;
    font-size: 18px;
    color: white;
}

.chat-widget-container .sessions-left {
    font-size: 12px;
    color: rgba(255,255,255,0.8);
}

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

.chat-widget-container .lang-toggle {
    padding: 8px 16px;
    background-color: rgba(255,255,255,0.2);
    color: white;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 20px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
    backdrop-filter: blur(10px);
}

.chat-widget-container .lang-toggle:hover {
    background-color: rgba(255,255,255,0.3);
    transform: translateY(-1px);
}

.chat-widget-container .close-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: rgba(255,255,255,0.2);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.chat-widget-container .close-btn:hover {
    background-color: rgba(255,255,255,0.3);
    transform: scale(1.1);
}

/* Tabs */
.chat-widget-container .chat-tabs {
    display: flex;
    background-color: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
}

.chat-widget-container .tab-button {
    flex: 1;
    padding: 16px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: #666;
    transition: all 0.2s;
    position: relative;
}

.chat-widget-container .tab-button.active {
    color: #7367F0;
    background-color: white;
}

.chat-widget-container .tab-button.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background-color: #7367F0;
}

/* Tab content */
.chat-widget-container .tab-content {
    display: none;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.chat-widget-container .tab-content.active {
    display: flex;
    flex-direction: column;
}

/* History tab */
.chat-widget-container .history-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.chat-widget-container .new-conversation-btn {
    width: 100%;
    padding: 16px;
    background-color: #7367F0;
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 20px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.chat-widget-container .new-conversation-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(115, 103, 240, 0.3);
}

.chat-widget-container .conversation-item {
    padding: 16px;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: all 0.2s;
    background-color: white;
}

.chat-widget-container .conversation-item:hover {
    border-color: #7367F0;
    box-shadow: 0 4px 12px rgba(115, 103, 240, 0.1);
    transform: translateY(-1px);
}

.chat-widget-container .conversation-item.active {
    border-color: #7367F0;
    background-color: #f8f9ff;
}

.chat-widget-container .conversation-title {
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
    font-size: 14px;
}

.chat-widget-container .conversation-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: #666;
}

.chat-widget-container .conversation-preview {
    color: #888;
    font-size: 12px;
    margin-top: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Chat tab */
.chat-widget-container .chat-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-widget-container .chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
    min-height: 0;
    max-height: 100%;
}

.chat-widget-container .chat-area::-webkit-scrollbar {
    width: 6px;
}

.chat-widget-container .chat-area::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.chat-widget-container .chat-area::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.chat-widget-container .chat-area::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Ensure chat area is scrollable */
.chat-widget-container .chat-area {
    overflow-y: scroll;
    height: 100%;
    overflow-x: hidden;
}

.chat-widget-container .message {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
    position: relative;
    margin-bottom: 8px;
}

.chat-widget-container .user-message {
    align-self: flex-end;
    background-color: #7367F0;
    color: white;
    margin-left: auto;
    margin-right: 0;
}

.chat-widget-container .bot-message {
    align-self: flex-start;
    background-color: #f8f9fa;
    color: #333;
    margin-right: auto;
    margin-left: 0;
    border: 1px solid #e0e0e0;
}

/* Fix RTL alignment for messages */
.chat-widget-container .chat-window.rtl .user-message {
    align-self: flex-start;
    margin-left: 0;
    margin-right: auto;
}

.chat-widget-container .chat-window.rtl .bot-message {
    align-self: flex-end;
    margin-right: 0;
    margin-left: auto;
}

.chat-widget-container .message-time {
    font-size: 10px;
    color: rgba(255,255,255,0.7);
    margin-top: 4px;
    text-align: right;
}

.chat-widget-container .bot-message .message-time {
    color: #999;
    text-align: left;
}

.chat-widget-container .chat-window.rtl .bot-message .message-time {
    text-align: right;
}

/* Enhanced Product carousel */
.chat-widget-container .products-container {
    display: flex;
    gap: 16px;
    overflow-x: auto;
    padding: 20px 0;
    margin-top: 16px;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: #7367F0 transparent;
    max-width: 100%;
    scroll-snap-type: x mandatory;
    min-height: 200px;
    contain: layout style paint;
}

.chat-widget-container .products-container::-webkit-scrollbar {
    height: 6px;
}

.chat-widget-container .products-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.chat-widget-container .products-container::-webkit-scrollbar-thumb {
    background: #7367F0;
    border-radius: 3px;
}

.chat-widget-container .products-container::-webkit-scrollbar-thumb:hover {
    background: #5a4fdb;
}

/* Ensure smooth scrolling and proper spacing */
.chat-widget-container .products-container > * {
    scroll-snap-align: start;
}

/* Hide scrollbar on mobile for cleaner look */
@media (max-width: 768px) {
    .chat-widget-container .products-container::-webkit-scrollbar {
        display: none;
    }
    .chat-widget-container .products-container {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }
}

.chat-widget-container .product-card {
    min-width: calc(50% - 8px);
    max-width: calc(50% - 8px);
    width: calc(50% - 8px);
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    padding: 12px;
    text-align: center;
    background-color: white;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    flex-shrink: 0;
}

/* Single product takes full width */
.chat-widget-container .products-container:has(.product-card:only-child) .product-card,
.chat-widget-container .products-container .product-card:only-child {
    min-width: calc(100% - 16px);
    max-width: calc(100% - 16px);
    width: calc(100% - 16px);
}

.chat-widget-container .product-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.1);
    border-color: #7367F0;
}

.chat-widget-container .product-card img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: 12px;
    margin-bottom: 12px;
    transition: transform 0.3s ease;
    display: block;
    background-color: #f8f9fa;
}

.chat-widget-container .product-card:hover img {
    transform: scale(1.05);
}

.chat-widget-container .product-card h4 {
    font-size: 12px;
    color: #333;
    margin-bottom: 8px;
    font-weight: 600;
    line-height: 1.3;
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    word-wrap: break-word;
}

.chat-widget-container .view-product-btn {
    background: linear-gradient(135deg, #7367F0 0%, #5a4fdb 100%);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.chat-widget-container .view-product-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(115, 103, 240, 0.3);
}

/* Product navigation arrows */
.chat-widget-container .products-navigation {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 8px 0;
}

.chat-widget-container .nav-arrow {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #7367F0;
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    font-size: 16px;
    font-weight: bold;
}

.chat-widget-container .nav-arrow:hover {
    background: #5a4fdb;
    transform: scale(1.1);
}

.chat-widget-container .nav-arrow:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

/* Typing indicator */
.chat-widget-container .typing-indicator {
    display: none;
    align-self: flex-start;
    padding: 12px 16px;
    background-color: #f8f9fa;
    border-radius: 18px;
    border: 1px solid #e0e0e0;
    margin-right: auto;
    margin-left: 0;
}

.chat-widget-container .chat-window.rtl .typing-indicator {
    align-self: flex-end;
    margin-right: 0;
    margin-left: auto;
}

.chat-widget-container .typing-indicator.show {
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-widget-container .typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #999;
    animation: typing 1.4s infinite;
}

.chat-widget-container .typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.chat-widget-container .typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        opacity: 0.3;
    }
    30% {
        opacity: 1;
    }
}

/* Input area */
.chat-widget-container .input-area {
    padding: 20px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    gap: 12px;
    align-items: center;
    background-color: #f8f9fa;
}

.chat-widget-container .chat-window.rtl .input-area {
    flex-direction: row-reverse;
}

.chat-widget-container .chat-input {
    flex: 1;
    padding: 12px 20px;
    border: 2px solid #e0e0e0;
    border-radius: 25px;
    font-size: 14px;
    outline: none;
    transition: all 0.2s;
    background-color: white;
}

.chat-widget-container .chat-input:focus {
    border-color: #7367F0;
    box-shadow: 0 0 0 3px rgba(115, 103, 240, 0.1);
}

.chat-widget-container .chat-window.rtl .chat-input {
    text-align: right;
}

.chat-widget-container .send-button {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background-color: #7367F0;
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    box-shadow: 0 4px 12px rgba(115, 103, 240, 0.3);
}

.chat-widget-container .send-button:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(115, 103, 240, 0.4);
}

.chat-widget-container .send-button svg {
    width: 20px;
    height: 20px;
}

/* Empty state */
.chat-widget-container .empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #666;
    text-align: center;
    padding: 20px;
}

.chat-widget-container .empty-state svg {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.chat-widget-container .empty-state h3 {
    margin-bottom: 8px;
    color: #333;
}

.chat-widget-container .empty-state p {
    font-size: 14px;
    line-height: 1.5;
}

/* Responsive */
@media (max-width: 480px) {
    .chat-widget-container .chat-window {
        width: calc(100vw - 20px);
        height: calc(100vh - 100px);
        right: 10px;
        bottom: 80px;
    }

    .chat-widget-container .chat-button {
        right: 10px;
        bottom: 10px;
    }

    .chat-widget-container .message {
        max-width: 85%;
    }

    .chat-widget-container .user-message {
        margin-left: auto;
        margin-right: 0;
    }

    .chat-widget-container .bot-message {
        margin-right: auto;
        margin-left: 0;
    }

    .chat-widget-container .typing-indicator {
        margin-right: auto;
        margin-left: 0;
    }

    .chat-widget-container .products-container {
        gap: 8px;
        padding: 12px 0;
    }

    .chat-widget-container .product-card {
        min-width: calc(50% - 8px);
        max-width: calc(50% - 8px);
        width: calc(50% - 8px);
        padding: 10px;
    }

    /* Single product takes full width */
    .chat-widget-container .products-container:has(.product-card:only-child) .product-card,
    .chat-widget-container .products-container .product-card:only-child {
        min-width: calc(100% - 16px);
        max-width: calc(100% - 16px);
        width: calc(100% - 16px);
    }

    .chat-widget-container .product-card img {
        height: 90px;
    }

    .chat-widget-container .product-card h4 {
        font-size: 11px;
        min-height: 28px;
    }

    .chat-widget-container .view-product-btn {
        padding: 6px 10px;
        font-size: 9px;
    }

    .chat-widget-container .nav-arrow {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }
}

/* Loading spinner */
.chat-widget-container .loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #7367F0;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Welcome message animation for first-time users */
@keyframes welcomePulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.chat-widget-container .welcome-message {
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%) !important;
    color: white !important;
    border: none !important;
    animation: welcomePulse 2s ease-in-out;
    box-shadow: 0 4px 20px rgba(72, 187, 120, 0.3);
}
