/* ===================================
   IMPROVED PRODUCTS MODAL - MOBILE OPTIMIZED
   =================================== */

/* Modal Overlay */
.ai-products-modal {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 100000;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

/* Animation */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from {
        transform: translateY(30px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Modal Content */
.ai-products-modal .modal-content {
    background: white;
    border-radius: 12px;
    max-width: 90%;
    max-height: 90vh;
    width: 1000px; /* Reduced from 1200px for better sizing */
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    animation: slideUp 0.3s ease;
    overflow: hidden;
}

/* Header - gradient with white text (consistent across all devices) */
.ai-products-modal-header,
.ai-products-modal .modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: none;
    background: linear-gradient(135deg, var(--convertybot-primary, #007cba) 0%, #005a8a 100%);
    color: white;
    border-radius: 12px 12px 0 0;
}

.ai-products-modal-header h3,
.ai-products-modal .modal-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: white;
}

/* Close Button - white to match gradient header */
.ai-products-modal-close,
.ai-products-modal .modal-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    font-size: 24px;
    color: white;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.ai-products-modal-close:hover,
.ai-products-modal .modal-close:hover {
    background: rgba(255, 255, 255, 0.4);
    color: white;
}

/* Body */
.ai-products-modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

/* Products Grid */
.ai-products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

/* Product Card */
.ai-product-card-modal {
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
    transition: all 0.3s ease;
    background: white;
    display: flex;
    flex-direction: column;
}

.ai-product-card-modal:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
}

.ai-product-card-modal img {
    width: 100%;
    height: 180px;
    object-fit: cover;
    border-bottom: 1px solid #e0e0e0;
}

/* Product Info */
.ai-product-info {
    padding: 12px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.ai-product-info h4 {
    margin: 0 0 8px 0;
    font-size: 14px;
    line-height: 1.3;
    color: #333;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    min-height: 36px;
}

/* Rating */
.ai-product-rating {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 8px;
    font-size: 12px;
}

.ai-product-rating .stars {
    color: #ffc107;
    letter-spacing: 1px;
    font-size: 14px;
}

.ai-product-rating span:last-child {
    color: #666;
    font-size: 11px;
}

/* Description */
.ai-product-description {
    margin: 0 0 10px 0;
    font-size: 12px;
    color: #666;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    flex: 1;
}

/* Price */
.ai-product-price {
    font-size: 16px;
    font-weight: bold;
    color: #e74c3c;
    margin-bottom: 10px;
}

/* View Product Button */
.ai-product-btn {
    display: block;
    padding: 8px 12px;
    background: #3498db;
    color: white;
    text-decoration: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    text-align: center;
    transition: background 0.3s ease;
}

.ai-product-btn:hover {
    background: #2980b9;
    color: white;
}

/* Show More Button */
.ai-show-more-btn {
    display: block;
    width: 100%;
    max-width: 300px;
    margin: 20px auto 0;
    padding: 12px 24px;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(52, 152, 219, 0.3);
}

.ai-show-more-btn:hover {
    background: #2980b9;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.4);
}

.ai-show-more-btn:active {
    transform: translateY(0);
}

/* Hidden products */
.ai-product-card-modal.hidden {
    display: none;
}

/* ===================================
   MOBILE RESPONSIVE
   =================================== */

@media (max-width: 768px) {
    /* Modal overlay - centered with padding */
    .ai-products-modal {
        padding: 20px !important;
        align-items: center !important;
        justify-content: center !important;
    }

    /* Modal content - NOT full screen, centered with margins */
    .ai-products-modal .modal-content {
        max-width: 320px !important;
        width: calc(100% - 40px) !important;
        max-height: 70vh !important;
        height: auto !important;
        border-radius: 12px !important;
        margin: auto !important;
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3) !important;
    }

    /* Header - proper styling with gradient and WHITE text */
    .ai-products-modal .modal-header,
    .ai-products-modal-header {
        padding: 10px 12px !important;
        background: linear-gradient(135deg, var(--convertybot-primary, #007cba) 0%, #005a8a 100%) !important;
        color: white !important;
        border-radius: 12px 12px 0 0 !important;
    }

    .ai-products-modal .modal-header h3,
    .ai-products-modal-header h3 {
        font-size: 12px !important;
        color: white !important;
        margin: 0 !important;
        font-weight: 600 !important;
    }

    .ai-products-modal .modal-close,
    .ai-products-modal-close {
        font-size: 18px !important;
        width: 24px !important;
        height: 24px !important;
        color: white !important;
        background: rgba(255, 255, 255, 0.2) !important;
        border-radius: 50% !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    /* Body - compact */
    .ai-products-modal .modal-body,
    .ai-products-modal-body {
        padding: 8px !important;
        max-height: 50vh !important;
        overflow-y: auto !important;
        background: #f8f9fa !important;
    }

    /* Single column on mobile */
    .ai-products-grid,
    .products-grid {
        grid-template-columns: 1fr !important;
        gap: 6px !important;
    }

    /* Compact product cards - horizontal layout */
    .ai-product-card-modal,
    .modal-product-card {
        display: flex !important;
        flex-direction: row !important;
        min-height: 60px !important;
        padding: 0 !important;
        background: white !important;
        border-radius: 6px !important;
        overflow: hidden !important;
    }

    .ai-product-card-modal img,
    .modal-product-card img {
        width: 55px !important;
        height: 55px !important;
        flex-shrink: 0 !important;
        border-bottom: none !important;
        border-right: 1px solid #e0e0e0 !important;
        border-radius: 0 !important;
        object-fit: cover !important;
    }

    .ai-product-info,
    .modal-product-card .product-info {
        padding: 5px 6px !important;
        flex: 1 !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: center !important;
        gap: 2px !important;
    }

    .ai-product-info h4,
    .modal-product-card .product-info h5 {
        font-size: 10px !important;
        -webkit-line-clamp: 1 !important;
        min-height: auto !important;
        margin: 0 0 2px 0 !important;
        line-height: 1.2 !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
    }

    /* Show rating on mobile with smaller size */
    .ai-product-rating,
    .modal-product-card .product-rating {
        display: flex !important;
        font-size: 8px !important;
        gap: 2px !important;
        margin-bottom: 3px !important;
    }

    .ai-product-rating .stars,
    .modal-product-card .product-rating .stars {
        font-size: 9px !important;
        letter-spacing: 0 !important;
    }

    .ai-product-rating span:last-child,
    .modal-product-card .product-rating .reviews {
        font-size: 7px !important;
    }

    /* Show description on mobile with smaller size */
    .ai-product-description,
    .modal-product-card .product-description {
        display: -webkit-box !important;
        font-size: 8px !important;
        line-height: 1.2 !important;
        -webkit-line-clamp: 2 !important;
        -webkit-box-orient: vertical !important;
        overflow: hidden !important;
        margin-bottom: 4px !important;
    }

    .ai-product-price,
    .modal-product-card .price {
        font-size: 10px !important;
        margin: 0 !important;
        color: #e74c3c !important;
        font-weight: bold !important;
    }

    .ai-product-btn,
    .btn-view-product-modal {
        padding: 3px 6px !important;
        font-size: 8px !important;
        border-radius: 3px !important;
        margin-top: 2px !important;
        display: inline-block !important;
        width: auto !important;
    }

    /* Show More Button */
    .ai-show-more-btn,
    .modal-show-more {
        font-size: 10px !important;
        padding: 6px 12px !important;
        margin-top: 8px !important;
    }
}

/* Small phones */
@media (max-width: 380px) {
    .ai-products-modal .modal-content {
        max-width: 280px !important;
        max-height: 65vh !important;
    }

    .ai-product-card-modal img,
    .modal-product-card img {
        width: 45px !important;
        height: 45px !important;
    }

    .ai-product-info h4,
    .modal-product-card .product-info h5 {
        font-size: 9px !important;
    }

    .ai-product-price,
    .modal-product-card .price {
        font-size: 9px !important;
    }

    .ai-product-btn,
    .btn-view-product-modal {
        font-size: 7px !important;
        padding: 2px 4px !important;
    }
}

/* Tablets */
@media (min-width: 769px) and (max-width: 1024px) {
    .ai-products-modal .modal-content {
        width: 90%;
        max-width: 800px;
    }

    .ai-products-grid {
        grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
        gap: 14px;
    }
}
