/**
 * Listing Page Mobile-First Responsive Styles
 * Enhanced mobile experience with improved touch targets and spacing
 */

/* ============================================
   Base Mobile Styles (Mobile First)
   ============================================ */

/* Show view toggle on all screen sizes */
@media (max-width: 767px) {
    .item2-gl-nav .item2-gl-menu {
        display: flex !important;
        justify-content: center;
        margin-bottom: 10px;
    }
}

/* Ensure grid cards use full column width without overflow */
.item2-gl #tab-12 .row {
    margin-left: -0.5rem;
    margin-right: -0.5rem;
}

.item2-gl #tab-12 .row > [class*="col-"] {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
}

/* Make sure cards fill their columns */
.item2-gl #tab-12 .card {
    height: 100%;
}

/* Responsive grid columns - more ads visible on wider screens */
@media (min-width: 1400px) {
    /* 5 columns on XXL screens */
    .col-xxl-2-4 {
        flex: 0 0 20%;
        max-width: 20%;
    }
}

/* ============================================
   Mobile Navigation & Filters
   ============================================ */

/* Mobile filter toggle button */
.filter-toggle-btn {
    position: sticky;
    top: 10px;
    z-index: 100;
}

/* Mobile filter panel - slide up from bottom */
@media (max-width: 767px) {
    .filter-panel {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 1050;
        background: white;
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        max-height: 85vh;
    }

    .filter-panel.active {
        transform: translateY(0);
    }

    .filter-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 1rem 1.25rem;
        border-bottom: 1px solid #f0f0f0;
        background: white;
        border-radius: 20px 20px 0 0;
        position: sticky;
        top: 0;
        z-index: 10;
    }

    .filter-header h3 {
        margin: 0;
        font-size: 1.125rem;
        font-weight: 700;
    }

    .filter-header .btn-close {
        width: 32px;
        height: 32px;
        border-radius: 50%;
        background: #f0f0f0;
        border: none;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: background 0.2s;
    }

    .filter-header .btn-close:hover {
        background: #e0e0e0;
    }

    .filter-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1040;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s;
    }

    .filter-overlay.active {
        opacity: 1;
        visibility: visible;
    }
}

/* ============================================
   Mobile Card Improvements
   ============================================ */

@media (max-width: 767px) {
    /* Full width cards on mobile */
    .item2-gl #tab-12 .col-lg-6,
    .item2-gl #tab-12 .col-xl-3 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* Card styling */
    .item2-gl .card {
        margin-bottom: 1rem;
        border-radius: 12px;
    }

    /* Increase touch targets */
    .item-card9-icons1 {
        width: 44px;
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Price badge mobile styling */
    .price-badge {
        padding: 6px 12px;
        font-size: 0.875rem;
    }

    /* Card footer mobile */
    .item-card9-footer {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
}

/* Two columns on larger phones */
@media (min-width: 480px) and (max-width: 767px) {
    .item2-gl #tab-12 .col-lg-6,
    .item2-gl #tab-12 .col-xl-3 {
        flex: 0 0 50%;
        max-width: 50%;
    }
}

/* ============================================
   Touch-Friendly Improvements
   ============================================ */

/* Larger tap targets for buttons */
@media (max-width: 767px) {
    .listing-mode-btn {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Search form mobile improvements */
    .ads-search-background .form-control {
        height: 48px;
        font-size: 16px; /* Prevents zoom on iOS */
    }

    .ads-search-background .search-button {
        min-width: 48px;
        min-height: 48px;
    }

    /* Category filters */
    .categories-filter .category-filter {
        padding: 12px 10px;
        font-size: 0.9375rem;
    }

    /* Attribute filters */
    .attribute-filter {
        padding: 12px 1rem;
    }
}

/* ============================================
   Pull to Refresh Indicator
   ============================================ */

.pull-to-refresh-indicator {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%) translateY(-100%);
    z-index: 1100;
    background: white;
    padding: 0.75rem 1.5rem;
    border-radius: 0 0 20px 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: transform 0.3s;
}

.pull-to-refresh-indicator.visible {
    transform: translateX(-50%) translateY(0);
}

.pull-to-refresh-indicator .spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #f0f0f0;
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   Mobile Pagination
   ============================================ */

@media (max-width: 767px) {
    /* Hide traditional pagination on mobile, show load more */
    .pagination {
        display: none;
    }

    .load-more-container {
        display: block;
    }

    .btn-load-more {
        width: 100%;
        padding: 1rem;
        font-size: 1rem;
        border-radius: 12px;
    }
}

@media (min-width: 768px) {
    .load-more-container {
        display: none;
    }
}

/* ============================================
   Mobile Sorting
   ============================================ */

@media (max-width: 575px) {
    .item2-gl-nav {
        flex-direction: column;
        gap: 0.75rem;
    }

    .item2-gl-nav .showing-results {
        text-align: center;
        width: 100%;
    }

    .item2-gl-nav .select2-sm {
        width: 100%;
        justify-content: center;
    }

    .item2-gl-nav .item2-gl-menu {
        order: -1;
    }
}

/* ============================================
   Swipe Gestures Hint
   ============================================ */

@media (max-width: 767px) {
    .swipe-hint {
        position: absolute;
        bottom: 10px;
        left: 50%;
        transform: translateX(-50%);
        background: rgba(0, 0, 0, 0.6);
        color: white;
        padding: 4px 12px;
        border-radius: 20px;
        font-size: 0.75rem;
        opacity: 0;
        transition: opacity 0.3s;
        pointer-events: none;
    }

    .card:hover .swipe-hint {
        opacity: 1;
    }
}

/* ============================================
   Safe Area for Notched Phones
   ============================================ */

@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .filter-panel {
        padding-bottom: env(safe-area-inset-bottom);
    }

    .sticky-search-wrapper {
        padding-top: env(safe-area-inset-top);
    }
}

/* ============================================
   Skeleton Loading on Mobile
   ============================================ */

@media (max-width: 767px) {
    .skeleton-card {
        border-radius: 12px;
        margin-bottom: 1rem;
    }

    .skeleton-image {
        height: 180px;
    }
}

/* ============================================
   Landscape Mode Adjustments
   ============================================ */

@media (max-height: 500px) and (orientation: landscape) {
    .filter-panel {
        max-height: 80vh;
    }

    .ads-search-background {
        padding: 0.5rem;
    }
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
    .filter-toggle-btn,
    .filter-panel,
    .sticky-search-wrapper,
    .item2-gl-menu,
    .pagination,
    .load-more-container {
        display: none !important;
    }

    .card {
        break-inside: avoid;
        page-break-inside: avoid;
    }
}
