/* Mobile Responsive Styles */

@media (max-width: 768px) {

    /* Force 3 columns for product cards on mobile as requested */
    /* Force 3 columns for product cards on mobile as requested */
    .products-grid {
        display: grid !important;
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
        gap: 6px !important;
        width: 100% !important;
        padding: 0 !important;
        box-sizing: border-box !important;
    }

    /* Adjust card styling to fit 3 columns */
    .product-card {
        display: flex;
        flex-direction: column;
        height: 100%;
        min-height: 180px;
        /* Ensure consistent height */
        background: #ffffff;
        /* Ensure background is visible vs transparent */
        border-radius: 8px;
        /* Slightly smaller radius */
        overflow: hidden;
        border: 1px solid rgba(0, 0, 0, 0.08);
        /* Define border clearly */
    }

    .product-img {
        height: 80px !important;
        /* Smaller image height */
        min-height: 80px !important;
        padding: 5px;
    }

    .product-img img {
        width: 100%;
        height: 100%;
        object-fit: contain;
    }

    .product-info {
        padding: 6px !important;
        /* Compact padding */
    }

    .product-title {
        font-size: 0.7rem !important;
        /* Smaller font */
        line-height: 1.2 !important;
        height: 2.4em !important;
        /* Limit height */
        margin-bottom: 4px !important;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .product-price {
        font-size: 0.8rem !important;
    }

    .product-old-price {
        font-size: 0.6rem !important;
    }

    .product-discount-tag {
        font-size: 0.6rem !important;
        padding: 1px 3px !important;
    }

    .product-rating {
        display: none !important;
        /* Hide rating to save space if needed, or make very small */
    }

    .product-who-by {
        font-size: 0.6rem !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Topbar and Search Input on Mobile */
    .topbar {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
        height: auto !important;
        min-height: auto !important;
        padding: 10px 1rem !important;
        gap: 10px !important;
        align-items: center !important;
    }

    .topbar-brand {
        order: 1 !important;
        width: auto !important;
        flex: none !important;
    }

    .topbar-brand img {
        width: 50px !important;
    }

    .topbar-brand span {
        font-size: 1.1rem !important;
    }

    .right-controls {
        order: 2 !important;
        flex: 1 !important;
        justify-content: flex-end !important;
        display: flex !important;
    }

    .topbar-search-container {
        order: 3 !important;
        display: flex !important;
        width: 100% !important;
        flex: none !important;
        margin: 0 !important;
    }

    .search-input-wrapper {
        width: 100% !important;
        background: #f1f5f9 !important;
        border-radius: 14px !important;
        padding: 2px 10px !important;
        border: 1px solid rgba(0, 0, 0, 0.05) !important;
    }

    .topbar-search-input {
        font-size: 16px !important;
        /* Prevents zoom on iOS */
        min-height: 44px !important;
        padding: 8px 0 !important;
    }

    .search-plus-btn,
    .search-icon-btn {
        width: 32px !important;
        height: 32px !important;
    }

    /* Tabs adjustment on Mobile */
    .topbar-search-tabs-container {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        padding: 0 1rem !important;
        overflow-x: auto !important;
        justify-content: flex-start !important;
        background: #ffffff !important;
        border-bottom: 1px solid #e2e8f0 !important;
        -webkit-overflow-scrolling: touch !important;
        position: relative !important;
        /* Changed from sticky */
        top: auto !important;
        /* Changed from 0 */
        z-index: 999 !important;
        /* Lower than topbar */
        height: auto !important;
        min-height: 44px !important;
        scrollbar-width: none !important;
        /* Firefox */
        -ms-overflow-style: none !important;
        /* IE and Edge */
    }

    .topbar-search-tabs-container::-webkit-scrollbar {
        display: none !important;
        /* Chrome, Safari, Opera */
    }

    .topbar-search-tabs {
        display: flex !important;
        justify-content: flex-start !important;
        gap: 15px !important;
        width: max-content !important;
        align-items: center !important;
        padding-right: 2.5rem !important;
    }

    .search-tab {
        display: flex !important;
        align-items: center !important;
        padding: 12px 8px !important;
        font-size: 0.85rem !important;
        color: var(--text-muted) !important;
        flex-shrink: 0 !important;
        text-decoration: none !important;
    }

    .search-tab.active {
        color: var(--primary) !important;
        border-bottom: 2px solid var(--primary) !important;
    }

    .search-tab i {
        margin-right: 5px !important;
    }

    .content-area {
        padding: 10px 5px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    /* Prevent topbar from being too high or covering things */
    .topbar {
        position: sticky !important;
        /* Changed from relative */
        top: 0 !important;
        z-index: 1000 !important;
        background: #ffffff !important;
        /* Ensure opaque background */
    }
}

/* Alerts Page Mobile Styles */
@media (max-width: 768px) {
    .content-area:has(.alerts-page-container) {
        padding: 0 !important;
        height: calc(100vh - 120px) !important;
        /* Adjust based on topbar/tabs height */
    }

    .alerts-page-container {
        height: 100% !important;
        display: block !important;
        /* Use block to manage visibility manually or flex with one child */
        position: relative !important;
    }

    .alerts-sidebar {
        width: 100% !important;
        height: 100% !important;
        max-height: none !important;
        display: flex !important;
        border-right: none !important;
        border-bottom: none !important;
    }

    .alert-detail-view {
        width: 100% !important;
        height: 100% !important;
        display: none !important;
        /* Hidden by default */
        position: absolute !important;
        top: 0;
        left: 0;
        background: #ffffff !important;
        z-index: 20;
    }

    /* When detail is active */
    .alerts-page-container.mobile-detail-active .alerts-sidebar {
        display: none !important;
    }

    .alerts-page-container.mobile-detail-active .alert-detail-view {
        display: flex !important;
    }

    .mobile-back-btn {
        background: transparent;
        border: none;
        font-size: 1.1rem;
        color: var(--primary);
        font-weight: 600;
        display: flex !important;
        align-items: center;
        gap: 8px;
        cursor: pointer;
        padding: 0;
        font-family: 'Outfit', sans-serif;
    }

    /* Mobile Sticky Header in Alerts */
    .mobile-sticky-header {
        position: sticky !important;
        top: 0;
        z-index: 50;
        background: #ffffff;

        /* Compensate padding of alerts-detail-content-wrapper (1.25rem) */
        margin-top: -1.25rem;
        margin-left: -1.25rem;
        margin-right: -1.25rem;

        padding-top: 1.25rem;
        padding-left: 1.25rem;
        padding-right: 1.25rem;
        padding-bottom: 0.75rem;

        margin-bottom: 1rem;
        border-bottom: 1px solid rgba(0, 0, 0, 0.05);
        display: block !important;
    }

    .mobile-back-btn {
        display: flex !important;
        /* Remove negative margin or extra overrides if needed */
    }

    /* =====================================================
       DARK MODE — Mobile Overrides
       ===================================================== */
    body.dark-mode {
        background-color: #0f172a;
    }

    /* Topbar & Search Interface */
    body.dark-mode .topbar {
        background: #0f172a !important;
        border-bottom: 1px solid #1e293b !important;
    }

    body.dark-mode .search-input-wrapper {
        background: #1e293b !important;
        border-color: #334155 !important;
    }

    body.dark-mode .topbar-search-tabs-container {
        background: #0f172a !important;
        border-bottom: 1px solid #1e293b !important;
    }

    /* Product Cards */
    body.dark-mode .product-card {
        background: #1e293b !important;
        border-color: #334155 !important;
    }

    body.dark-mode .product-img {
        background: #0f172a !important;
    }

    body.dark-mode .product-info {
        background: #1e293b !important;
    }

    /* Mobile Popover & Navigation */
    body.dark-mode .mobile-actions-popover {
        background: #1e293b !important;
        border-color: #334155 !important;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6) !important;
    }

    body.dark-mode .popover-item {
        color: #f1f5f9 !important;
    }

    body.dark-mode .popover-item i {
        color: #94a3b8 !important;
    }

    body.dark-mode .popover-item:active {
        background: rgba(255, 255, 255, 0.05) !important;
    }

    /* Tags / Toggles */
    body.dark-mode .active-tag {
        background: rgba(148, 163, 184, 0.15) !important;
        border-color: rgba(148, 163, 184, 0.3) !important;
        color: #f1f5f9 !important;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4) !important;
    }

    body.dark-mode .active-tag i {
        color: #94a3b8 !important;
    }

    /* Plus Button Active State */
    body.dark-mode .mobile-plus-btn.active {
        background: #f1f5f9 !important;
        color: #0f172a !important;
    }

    /* Alerts Page Detail */
    body.dark-mode .mobile-sticky-header {
        background: #0f172a !important;
        border-bottom-color: #1e293b !important;
    }

    body.dark-mode .mobile-back-btn {
        color: #f1f5f9 !important;
    }

    body.dark-mode .alert-detail-view {
        background: #0f172a !important;
    }

    /* Search Buttons Visibility */
    body.dark-mode .search-plus-btn,
    body.dark-mode .search-icon-btn {
        color: #94a3b8 !important;
    }

    body.dark-mode .search-plus-btn:active,
    body.dark-mode .search-icon-btn:active {
        background: rgba(255, 255, 255, 0.1) !important;
    }

    /* Tag Refinements */
    body.dark-mode .active-tag i.fa-xmark {
        color: #f1f5f9 !important;
        opacity: 0.8;
    }
}