/* ============================================
   AI Chatbot Widget Styles
   ============================================ */

/* CSS Variables - Will be overridden by inline styles from database */
:root {
    --chatbot-primary-color: #667eea;
    --chatbot-accent-color: #764ba2;
    --chatbot-primary-rgb: 102, 126, 234;
}

/* Chatbot Container - Not needed anymore since we only have a link */

/* Chat Toggle Button - Now a link to chat page */
.chat-toggle-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 10000; /* Higher than bottom nav (9999) */
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--chatbot-primary-color) 0%, var(--chatbot-accent-color) 100%);
    border: none;
    box-shadow: 0 4px 15px rgba(var(--chatbot-primary-rgb, 102, 126, 234), 0.4);
    cursor: pointer;
    display: flex !important; /* Force display */
    align-items: center;
    justify-content: center;
    color: white !important;
    font-size: 28px;
    transition: all 0.3s ease;
    text-decoration: none;
    visibility: visible !important; /* Force visibility */
    opacity: 1 !important; /* Force opacity */
}

.chat-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(var(--chatbot-primary-rgb, 102, 126, 234), 0.6);
}

.chat-toggle-btn:active {
    transform: scale(0.95);
}

/* Notification Badge */
.chat-notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4757;
    color: white;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    border: 2px solid white;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

/* Chat Window */
.chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 550px;
    max-height: calc(100vh - 120px);
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-window.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* Chat Header */
.chat-header {
    background: linear-gradient(135deg, var(--chatbot-primary-color) 0%, var(--chatbot-accent-color) 100%);
    color: white;
    padding: 20px;
    border-radius: 16px 16px 0 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.chat-avatar {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: #000000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: white;
}

.chat-header-text h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.chat-header-text p {
    margin: 0;
    font-size: 12px;
    opacity: 0.9;
}

.chat-close-btn {
    background: transparent;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 5px;
    line-height: 1;
    transition: transform 0.2s;
}

.chat-close-btn:hover {
    transform: rotate(90deg);
}

/* Chat Messages Container */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Custom Scrollbar */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

/* Message Bubble */
.chat-message {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    animation: messageSlideIn 0.3s ease;
}

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

.chat-message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #000000;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.message-avatar.bot-avatar {
    background: #000000;
}

.message-avatar.user-avatar {
    background: #000000;
}

.message-content {
    max-width: 75%;
}

.message-bubble {
    background: white;
    padding: 12px 16px;
    border-radius: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    word-wrap: break-word;
    line-height: 1.5;
    font-size: 14px;
}

.chat-message.user .message-bubble {
    background: linear-gradient(135deg, var(--chatbot-primary-color) 0%, var(--chatbot-accent-color) 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message.bot .message-bubble {
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 11px;
    color: #a0aec0;
    margin-top: 4px;
    padding: 0 8px;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: white;
    border-radius: 16px;
    width: fit-content;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #cbd5e0;
    animation: typingAnimation 1.4s infinite;
}

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

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

@keyframes typingAnimation {
    0%, 60%, 100% {
        transform: translateY(0);
        background: #cbd5e0;
    }
    30% {
        transform: translateY(-10px);
        background: var(--chatbot-primary-color);
    }
}

/* Quick Replies */
.quick-replies {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    padding: 0 20px 10px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e0 transparent;
    position: relative;
}

/* Fade effect at edges to indicate scrollability */
.quick-replies::before,
.quick-replies::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 8px;
    width: 20px;
    pointer-events: none;
    z-index: 1;
}

.quick-replies::before {
    left: 0;
    background: linear-gradient(to right, rgba(248, 249, 250, 1) 0%, rgba(248, 249, 250, 0) 100%);
}

.quick-replies::after {
    right: 0;
    background: linear-gradient(to left, rgba(248, 249, 250, 1) 0%, rgba(248, 249, 250, 0) 100%);
}

/* Webkit scrollbar styling for quick replies */
.quick-replies::-webkit-scrollbar {
    height: 4px;
}

.quick-replies::-webkit-scrollbar-track {
    background: transparent;
    margin: 0 20px;
}

.quick-replies::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 10px;
}

.quick-replies::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

.quick-reply-btn {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 13px;
    color: #4a5568;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}

.quick-reply-btn:hover {
    background: var(--chatbot-primary-color);
    color: white;
    border-color: var(--chatbot-primary-color);
    transform: translateY(-2px);
}

/* Chat Input */
.chat-input {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid #e2e8f0;
    border-radius: 0 0 16px 16px;
    position: relative;
    z-index: 1;
}

.chat-input-form {
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
    z-index: 1;
}

.chat-input-field {
    flex: 1;
    border: 1px solid #e2e8f0;
    border-radius: 24px;
    padding: 12px 18px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s, color 0.2s;
    position: relative;
    z-index: 1;
    background: white;
    pointer-events: auto !important;
    color: #718096;
}

.chat-input-field:focus {
    border-color: var(--chatbot-primary-color);
    color: #000000;
}

.chat-input-field::placeholder {
    color: #a0aec0;
}

.chat-input-field:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background: #f1f5f9;
}

.chat-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--chatbot-primary-color) 0%, var(--chatbot-accent-color) 100%);
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    pointer-events: auto !important;
}

.chat-send-btn:hover:not(:disabled) {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(var(--chatbot-primary-rgb, 102, 126, 234), 0.4);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Welcome Message */
.welcome-message {
    background: linear-gradient(135deg, #f6f8fb 0%, #e9ecef 100%);
    padding: 20px;
    border-radius: 12px;
    text-align: center;
    margin-bottom: 16px;
}

.welcome-message h5 {
    margin: 0 0 8px;
    color: #2d3748;
    font-size: 16px;
}

.welcome-message p {
    margin: 0;
    color: #718096;
    font-size: 13px;
}

/* Product Cards in Chat */
.chat-products-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 12px;
    width: 100%;
}

.chat-product-card {
    display: flex;
    gap: 12px;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 12px;
    transition: all 0.2s ease;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
}

.chat-product-card:hover {
    border-color: var(--chatbot-primary-color);
    box-shadow: 0 4px 12px rgba(var(--chatbot-primary-rgb, 102, 126, 234), 0.15);
    transform: translateY(-2px);
}

.chat-product-image {
    width: 80px;
    height: 80px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
    background: #f8f9fa;
}

.chat-product-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.chat-product-name {
    font-weight: 600;
    font-size: 14px;
    color: #2d3748;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.3;
}

.chat-product-category {
    font-size: 11px;
    color: #718096;
    background: #f1f5f9;
    padding: 2px 8px;
    border-radius: 4px;
    display: inline-block;
    width: fit-content;
}

.chat-product-price {
    font-weight: 700;
    font-size: 15px;
    color: var(--chatbot-primary-color);
    margin-top: auto;
}

.chat-product-stock {
    font-size: 11px;
    color: #10b981;
    font-weight: 500;
}

.chat-product-stock.low-stock {
    color: #f59e0b;
}

.chat-product-stock.out-of-stock {
    color: #ef4444;
}

/* Product card in bot message */
.chat-message.bot .chat-products-container {
    max-width: 100%;
}

/* Responsive adjustments for product cards */
@media (max-width: 500px) {
    .chat-product-card {
        gap: 10px;
        padding: 10px;
    }

    .chat-product-image {
        width: 70px;
        height: 70px;
    }

    .chat-product-name {
        font-size: 13px;
    }

    .chat-product-price {
        font-size: 14px;
    }
}

/* Empty State */
.chat-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    color: #a0aec0;
}

.chat-empty-state i {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.3;
}

.chat-empty-state p {
    margin: 0;
    font-size: 14px;
}

/* Mobile Responsive - Updated breakpoint */
@media (max-width: 768px) {
    .chat-toggle-btn {
        bottom: 100px; /* Above bottom navigation */
        right: 16px;
        width: 56px;
        height: 56px;
        font-size: 24px;
    }

    .chat-window {
        width: calc(100vw - 20px);
        max-width: none;
        height: calc(100vh - 180px); /* Adjusted for bottom nav */
        max-height: none;
        bottom: 165px; /* Above toggle button and bottom nav (100px + 56px + 9px) */
        right: auto; /* Remove right positioning */
        left: 50%; /* Center horizontally */
        transform: translateX(-50%) translateY(20px) scale(0.95); /* Center + initial animation state */
        border-radius: 16px;
    }

    .chat-window.active {
        transform: translateX(-50%) translateY(0) scale(1); /* Maintain center on open */
        opacity: 1;
        pointer-events: all;
    }

    .chat-header {
        border-radius: 16px 16px 0 0;
    }

    .message-content {
        max-width: 80%;
    }
}

/* Modal Backdrop for Mobile */
.chat-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 9998;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: auto;
}

.chat-backdrop.active {
    display: block;
    opacity: 1;
}

/* Mobile Modal Style (≤500px) */
@media (max-width: 500px) {
    /* Chat window as full screen modal - Not needed since we use dedicated chat page */
    .chat-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100vh;
        max-width: none;
        max-height: none;
        border-radius: 0;
        transform: translateY(100%);
        transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 9999;
    }

    .chat-window.active {
        transform: translateY(0);
        opacity: 1;
        pointer-events: all;
    }

    /* Ensure input is above everything */
    .chat-input {
        position: relative;
        z-index: 10001;
    }

    .chat-input-field,
    .chat-send-btn {
        position: relative;
        z-index: 10001;
    }

    /* Header - Fixed at top */
    .chat-header {
        padding: 16px 20px;
        border-radius: 0;
        position: relative;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }

    .chat-avatar {
        width: 40px;
        height: 40px;
        font-size: 20px;
    }

    .chat-header-text h4 {
        font-size: 16px;
        font-weight: 600;
    }

    .chat-header-text p {
        font-size: 12px;
    }

    .chat-close-btn {
        font-size: 24px;
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        transition: background 0.2s;
    }

    .chat-close-btn:hover {
        background: rgba(255, 255, 255, 0.2);
    }

    /* Messages area - Scrollable */
    .chat-messages {
        flex: 1;
        padding: 16px;
        gap: 12px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .message-content {
        max-width: 75%;
    }

    .message-bubble {
        padding: 12px 16px;
        font-size: 14px;
        line-height: 1.5;
    }

    /* Welcome message */
    .welcome-message {
        padding: 16px;
        margin-bottom: 12px;
        border-radius: 12px;
    }

    .welcome-message h5 {
        font-size: 16px;
        margin-bottom: 8px;
        font-weight: 600;
    }

    .welcome-message p {
        font-size: 13px;
        line-height: 1.5;
    }

    /* Quick replies */
    .quick-replies {
        padding: 0 16px 12px;
        gap: 8px;
        /* Keep horizontal scroll on mobile */
        overflow-x: auto;
        flex-wrap: nowrap;
    }

    /* Hide scrollbar on mobile but keep functionality */
    .quick-replies::-webkit-scrollbar {
        height: 3px;
    }

    .quick-reply-btn {
        padding: 10px 16px;
        font-size: 13px;
        border-radius: 20px;
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* Input area - Fixed at bottom */
    .chat-input {
        padding: 16px;
        background: white;
        border-top: 1px solid #e2e8f0;
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
    }

    .chat-input-form {
        display: flex;
        align-items: center;
        gap: 12px;
    }

    .chat-input-field {
        flex: 1;
        padding: 12px 18px;
        font-size: 14px;
        border-radius: 24px;
        border: 1px solid #e2e8f0;
        background: #f8f9fa;
        color: #718096;
        transition: background 0.2s, border-color 0.2s, color 0.2s;
    }

    .chat-input-field:focus {
        background: white;
        border-color: var(--chatbot-primary-color);
        color: #000000;
    }

    .chat-input-field::placeholder {
        color: #a0aec0;
    }

    .chat-send-btn {
        width: 44px;
        height: 44px;
        font-size: 18px;
        flex-shrink: 0;
    }

    /* Adjust for safe area (iOS notch) */
    @supports (padding-top: env(safe-area-inset-top)) {
        .chat-header {
            padding-top: calc(16px + env(safe-area-inset-top));
        }

        .chat-input {
            padding-bottom: calc(16px + env(safe-area-inset-bottom));
        }
    }
}

/* Tablet Responsive */
@media (min-width: 481px) and (max-width: 768px) {
    .chat-toggle-btn {
        bottom: 20px;
        right: 20px;
    }
}

/* Small phones (up to 375px width) */
@media (max-width: 375px) {
    .chat-window {
        width: calc(100vw - 24px);
        height: calc(100vh - 190px);
        max-height: 580px;
    }

    .chat-header {
        padding: 14px;
    }

    .chat-messages {
        padding: 14px;
    }

    .message-content {
        max-width: 70%;
    }
}

/* Landscape Phone */
@media (max-height: 500px) and (orientation: landscape) {
    .chat-toggle-btn {
        bottom: 10px;
        right: 10px;
    }
}

/* Accessibility */
.chat-toggle-btn:focus,
.chat-send-btn:focus,
.quick-reply-btn:focus {
    outline: 2px solid var(--chatbot-primary-color);
    outline-offset: 2px;
}

/* Dark mode support (optional) */
@media (prefers-color-scheme: dark) {
    .chat-window {
        background: #1a202c;
    }

    .chat-messages {
        background: #2d3748;
    }

    .message-bubble {
        background: #4a5568;
        color: #e2e8f0;
    }

    .chat-input {
        background: #1a202c;
        border-top-color: #4a5568;
    }

    .chat-input-field {
        background: #2d3748;
        color: #e2e8f0;
        border-color: #4a5568;
    }

    .quick-reply-btn {
        background: #2d3748;
        color: #e2e8f0;
        border-color: #4a5568;
    }
}
