/* app/static/css/mobile.css - Mobile Responsive Styles */

/* ============================================
   Prevent Horizontal Overflow
   ============================================ */
html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

/* ============================================
   CSS Variables for Mobile
   ============================================ */
:root {
    --mobile-spacing-xs: 0.25rem;
    --mobile-spacing-sm: 0.5rem;
    --mobile-spacing-md: 1rem;
    --mobile-spacing-lg: 1.5rem;
    --mobile-touch-target: 44px;
    --mobile-card-gap: 8px;
    --swiper-theme-color: #F15A29;
    --swiper-navigation-size: 24px;
}

/* ============================================
   Swiper Carousel Styles
   ============================================ */
.swiper {
    width: 100%;
    padding: 10px 0 30px 0;
}

.swiper-slide {
    width: auto;
    height: auto;
}

/* Navigation buttons */
.swiper-button-next,
.swiper-button-prev {
    color: var(--swiper-theme-color);
    background: rgba(255, 255, 255, 0.9);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    transition: all 0.2s ease;
}

.swiper-button-next:after,
.swiper-button-prev:after {
    font-size: 14px;
    font-weight: bold;
}

.swiper-button-next:hover,
.swiper-button-prev:hover {
    background: var(--swiper-theme-color);
    color: white;
    transform: scale(1.1);
}

.swiper-button-disabled {
    opacity: 0.3 !important;
}

/* Pagination dots */
.swiper-pagination-bullet {
    width: 8px;
    height: 8px;
    background: #ccc;
    opacity: 1;
}

.swiper-pagination-bullet-active {
    background: var(--swiper-theme-color);
    width: 24px;
    border-radius: 4px;
}

/* Scrollbar */
.swiper-scrollbar {
    background: rgba(0, 0, 0, 0.1);
    height: 4px;
}

.swiper-scrollbar-drag {
    background: var(--swiper-theme-color);
    border-radius: 4px;
}

/* Hide navigation on mobile, show scrollbar/pagination */
@media (max-width: 768px) {
    .swiper-button-next,
    .swiper-button-prev {
        display: none !important;
    }

    .swiper {
        padding-bottom: 25px;
    }

    .swiper-pagination {
        bottom: 5px !important;
    }
}

/* ============================================
   Listings Carousel - Swiper Integration
   ============================================ */
.listings-swiper-container {
    position: relative;
    margin: 0 -15px;
    padding: 0 15px;
}

.listings-swiper {
    overflow: visible;
}

.listings-swiper .swiper-slide {
    width: 200px;
}

@media (max-width: 768px) {
    .listings-swiper .swiper-slide {
        width: 160px;
    }
}

@media (max-width: 480px) {
    .listings-swiper .swiper-slide {
        width: 140px;
    }
}

/* ============================================
   Premium Spotlight Swiper
   ============================================ */
.spotlight-swiper {
    border-radius: 12px;
    overflow: hidden;
}

.spotlight-swiper .swiper-slide {
    width: 100%;
}

.spotlight-swiper .swiper-pagination {
    bottom: 20px !important;
}

.spotlight-swiper .swiper-pagination-bullet {
    width: 12px;
    height: 12px;
    background: rgba(255, 255, 255, 0.5);
}

.spotlight-swiper .swiper-pagination-bullet-active {
    background: white;
    width: 30px;
}

/* ============================================
   Mobile Touch Optimizations
   ============================================ */
/* Ensure all interactive elements have proper touch targets */
@media (max-width: 768px) {
    button,
    .btn,
    a.btn,
    .nav-link,
    .dropdown-item,
    .page-link,
    input[type="submit"],
    input[type="button"] {
        min-height: var(--mobile-touch-target);
        padding: 0.5rem 1rem;
    }

    /* Form inputs */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    input[type="number"],
    select,
    textarea {
        font-size: 16px !important; /* Prevent iOS zoom */
        min-height: var(--mobile-touch-target);
        padding: 0.75rem;
    }

    /* Dropdown items */
    .dropdown-item {
        padding: 0.75rem 1rem;
    }
}

/* ============================================
   Mobile Navigation
   ============================================ */
@media (max-width: 991px) {
    /* Full-height mobile menu */
    .navbar-collapse {
        max-height: calc(100vh - 56px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Better dropdown spacing on mobile */
    .navbar-nav .dropdown-menu {
        border: none;
        background: transparent;
        padding-left: 1rem;
    }

    .navbar-nav .dropdown-item {
        color: rgba(255, 255, 255, 0.85);
        border-radius: 4px;
        margin: 2px 0;
    }

    .navbar-nav .dropdown-item:hover,
    .navbar-nav .dropdown-item:focus {
        background: rgba(255, 255, 255, 0.1);
        color: white;
    }

    /* Submenu styling */
    .navbar-nav .dropdown-submenu {
        position: static !important;
        background: rgba(255, 255, 255, 0.05) !important;
        border-radius: 4px;
        margin: 4px 0;
        padding: 4px 0;
    }

    .navbar-nav .dropdown-submenu .dropdown-item {
        font-size: 0.9rem;
        padding-left: 1.5rem;
    }
}

/* ============================================
   Mobile Card Layouts
   ============================================ */
@media (max-width: 576px) {
    /* Two-column grid for product cards */
    .row.g-3 > [class*="col-"] {
        flex: 0 0 50%;
        max-width: 50%;
        padding: var(--mobile-card-gap);
    }

    /* Compact card styling */
    .listing-card-compact,
    .listing-card-small,
    .infinite-scroll-card {
        border-radius: 8px;
    }

    .listing-card-compact .card-body,
    .listing-card-small .card-body {
        padding: 0.5rem;
    }

    .listing-card-compact .card-title,
    .listing-card-small .card-title {
        font-size: 0.8rem;
        line-height: 1.2;
        margin-bottom: 0.25rem;
        -webkit-line-clamp: 2;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .listing-card-compact .card-text,
    .listing-card-small .card-text {
        font-size: 0.7rem;
        margin-bottom: 0.25rem;
    }

    /* Price emphasis */
    .listing-card-compact .text-primary.fw-bold,
    .listing-card-small .text-primary.fw-bold {
        font-size: 0.85rem;
    }
}

/* ============================================
   Infinite Scroll Mobile
   ============================================ */
.infinite-scroll-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--mobile-card-gap);
}

@media (min-width: 576px) {
    .infinite-scroll-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 768px) {
    .infinite-scroll-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (min-width: 992px) {
    .infinite-scroll-grid {
        grid-template-columns: repeat(5, 1fr);
    }
}

@media (min-width: 1200px) {
    .infinite-scroll-grid {
        grid-template-columns: repeat(6, 1fr);
    }
}

/* Loading indicator */
.infinite-scroll-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    gap: 0.5rem;
}

.infinite-scroll-loading .spinner {
    width: 24px;
    height: 24px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--swiper-theme-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* End of listings message */
.infinite-scroll-end {
    text-align: center;
    padding: 2rem;
    color: #6c757d;
}

/* ============================================
   Category Cards Mobile
   ============================================ */
@media (max-width: 576px) {
    .category-hero .row {
        margin: 0 -5px;
    }

    .category-hero [class*="col-"] {
        padding: 5px;
        min-width: 100px !important;
        max-width: 120px !important;
    }

    .category-card {
        min-height: 100px !important;
        aspect-ratio: 1;
    }

    .category-card .card-body {
        padding: 0.5rem !important;
    }

    .category-card .category-icon i {
        font-size: 1.5rem !important;
    }

    .category-card h6 {
        font-size: 0.7rem !important;
        margin-bottom: 0.15rem !important;
    }

    .category-card small {
        font-size: 0.6rem !important;
    }
}

/* ============================================
   Search Page Mobile
   ============================================ */
@media (max-width: 768px) {
    /* Stack search and controls */
    .search-controls-row {
        flex-direction: column;
        gap: 1rem;
    }

    /* Full-width search input */
    .search-input-group {
        width: 100%;
    }

    /* Horizontal scroll for filter badges */
    .active-filters {
        display: flex;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 0.5rem;
        padding-bottom: 0.5rem;
        scrollbar-width: none;
    }

    .active-filters::-webkit-scrollbar {
        display: none;
    }

    .active-filters .badge {
        flex-shrink: 0;
        white-space: nowrap;
    }

    /* Sort and view toggle row */
    .sort-view-controls {
        display: flex;
        justify-content: space-between;
        width: 100%;
        gap: 0.5rem;
    }

    .sort-view-controls .dropdown {
        flex: 1;
    }

    .sort-view-controls .btn-group {
        flex-shrink: 0;
    }
}

/* ============================================
   Smart Search Mobile
   ============================================ */
@media (max-width: 768px) {
    .compact-smart-search {
        padding: 1rem 0.5rem;
    }

    .compact-search-wrapper {
        margin: 0;
    }

    .compact-search-input {
        padding: 0.75rem 0.5rem !important;
        font-size: 16px !important;
        min-width: 0;
        flex: 1;
    }

    .search-options-dropdown {
        flex-shrink: 0;
        margin-right: 8px;
    }

    .search-options-dropdown .search-mode-btn {
        width: 40px;
        height: 40px;
        padding: 0;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .compact-search-btn {
        width: 40px;
        height: 40px;
        min-width: 40px;
        padding: 0;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        margin-left: 8px;
    }

}

/* ============================================
   Bottom Navigation Bar (Mobile)
   ============================================ */
@media (max-width: 768px) {
    /* Add padding at bottom for mobile nav if needed */
    body {
        padding-bottom: env(safe-area-inset-bottom);
    }

    /* Ensure content doesn't get hidden behind floating elements */
    main.container {
        padding-bottom: 80px;
    }
}

/* ============================================
   Mobile Listing View Page
   ============================================ */
@media (max-width: 768px) {
    /* Full-width image carousel */
    .listing-image-carousel {
        margin: 0 -15px;
        border-radius: 0;
    }

    .listing-image-carousel .swiper-slide img {
        width: 100%;
        height: auto;
        max-height: 50vh;
        object-fit: contain;
    }

    /* Sticky price/action bar */
    .listing-action-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        padding: 0.75rem 1rem;
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
        z-index: 1000;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .listing-action-bar .price {
        font-size: 1.25rem;
        font-weight: bold;
        color: var(--swiper-theme-color);
    }

    .listing-action-bar .btn {
        padding: 0.75rem 1.5rem;
    }

    /* Ensure content isn't hidden behind action bar */
    .listing-content {
        padding-bottom: 100px;
    }
}

/* ============================================
   Floating Action Button (FAB)
   ============================================ */
.fab-container {
    position: fixed;
    bottom: 80px;
    right: 20px;
    z-index: 900;
}

.fab-main {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #F15A29, #ff7e5f);
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(241, 90, 41, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    transition: all 0.3s ease;
    text-decoration: none !important;
}

.fab-main:hover,
.fab-main:focus,
.fab-main:visited {
    color: white;
    text-decoration: none !important;
}

.fab-main:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(241, 90, 41, 0.6);
}

.fab-main:active {
    transform: scale(0.95);
}

@media (min-width: 769px) {
    .fab-container {
        display: none;
    }
}

/* ============================================
   Gesture Hints
   ============================================ */
.swipe-hint {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 1rem 2rem;
    border-radius: 8px;
    font-size: 0.9rem;
    pointer-events: none;
    z-index: 100;
    animation: fadeOut 2s forwards;
    animation-delay: 1s;
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; visibility: hidden; }
}

@media (max-width: 768px) {
    .swipe-hint.show-once {
        display: block;
    }
}

/* ============================================
   Safe Area Support (iPhone X+)
   ============================================ */
@supports (padding: env(safe-area-inset-bottom)) {
    .fixed-bottom,
    .listing-action-bar,
    .cookie-consent-banner {
        padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    }

    body {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
}

/* ============================================
   Smooth Scrolling & Performance
   ============================================ */
html {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* Optimize animations for mobile */
@media (max-width: 768px) {
    * {
        -webkit-tap-highlight-color: transparent;
    }

    /* Reduce motion for accessibility */
    @media (prefers-reduced-motion: reduce) {
        *,
        *::before,
        *::after {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
        }
    }
}

/* ============================================
   Skeleton Loading States
   ============================================ */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-card {
    height: 200px;
}

.skeleton-text {
    height: 1em;
    margin-bottom: 0.5rem;
}

.skeleton-text.short {
    width: 60%;
}

/* ============================================
   Mobile Typography
   ============================================ */
@media (max-width: 576px) {
    h1 { font-size: 1.5rem; }
    h2, .section-title { font-size: 1.25rem; }
    h3 { font-size: 1.1rem; }
    h4 { font-size: 1rem; }
    h5 { font-size: 0.9rem; }
    h6 { font-size: 0.85rem; }

    .lead {
        font-size: 1rem;
    }

    p, .text-muted {
        font-size: 0.9rem;
    }
}

/* ============================================
   Price Range Cards Mobile
   ============================================ */
@media (max-width: 576px) {
    .quick-browse .row {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 0.5rem;
        padding: 0.5rem 0;
        scrollbar-width: none;
    }

    .quick-browse .row::-webkit-scrollbar {
        display: none;
    }

    .quick-browse [class*="col-"] {
        flex: 0 0 auto;
        width: auto;
        min-width: 120px;
        padding: 0 0.25rem;
    }

    .price-range-card {
        min-height: 80px;
    }
}

/* ============================================
   Header Controls Mobile
   ============================================ */
@media (max-width: 768px) {
    .carousel-header-controls {
        display: none;
    }

    .section-title {
        font-size: 1.1rem;
    }

    .d-flex.justify-content-between.align-items-center.mb-4 {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .d-flex.justify-content-between.align-items-center.mb-4 .btn {
        padding: 0.375rem 0.75rem;
        font-size: 0.85rem;
    }
}

/* ============================================
   Improved Touch Feedback
   ============================================ */
@media (max-width: 768px) {
    .card,
    .btn,
    .list-group-item,
    .nav-link {
        transition: transform 0.1s ease, box-shadow 0.1s ease;
    }

    .card:active,
    .listing-card-clickable:active {
        transform: scale(0.98);
    }

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

/* ============================================
   Modal/Overlay Mobile
   ============================================ */
@media (max-width: 768px) {
    .modal-dialog {
        margin: 0;
        max-width: 100%;
        height: 100%;
    }

    .modal-content {
        height: 100%;
        border: none;
        border-radius: 0;
    }

    .modal-body {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ============================================
   Giveaway Button Mobile Fix
   ============================================ */
@media (max-width: 768px) {
    .giveaway-float-btn {
        bottom: 20px !important;
        right: 15px !important;
        padding: 8px 14px !important;
        font-size: 0.8rem !important;
    }

    .giveaway-float-btn span {
        display: none;
    }

    .giveaway-float-btn .icon-wrapper {
        margin-right: 0;
    }
}

/* ============================================
   AI Chat Widget Mobile
   ============================================ */
@media (max-width: 768px) {
    .ai-chat-container {
        bottom: 20px;
        left: 15px;
    }

    .ai-chat-widget {
        width: calc(100vw - 30px);
        max-width: 350px;
        height: calc(100vh - 150px);
        max-height: 500px;
    }

    .ai-chat-toggle {
        padding: 8px 14px;
        font-size: 0.85rem;
    }
}

/* ============================================
   Feed Section Mobile
   ============================================ */
@media (max-width: 576px) {
    .feed-section .listing-card-small {
        min-width: 150px;
    }

    .feed-section .position-absolute.w-100 {
        font-size: 0.6rem !important;
        padding: 0.2rem 0.4rem !important;
    }
}

/* ============================================
   Additional Touch Optimizations
   ============================================ */
/* Ensure links in cards are fully tappable */
.listing-card-small a,
.listing-card-compact a,
.infinite-scroll-card a,
.category-card a {
    display: block;
    text-decoration: none;
    color: inherit;
}

/* Touch-friendly filter badges */
@media (max-width: 768px) {
    .badge {
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
    }
}

/* ============================================
   Search Page Mobile Improvements
   ============================================ */
@media (max-width: 768px) {
    /* Full-width filter collapse */
    #advancedFilters .card {
        border-radius: 0;
        margin: 0 -12px;
    }

    /* Better filter form on mobile */
    #advancedFilters .row.g-3 > div {
        margin-bottom: 0.5rem;
    }

    /* Horizontal scroll for active filters */
    .active-filters-container {
        display: flex;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 0.5rem;
        padding: 0.5rem 0;
        margin: 0 -15px;
        padding-left: 15px;
        padding-right: 15px;
    }

    .active-filters-container::-webkit-scrollbar {
        display: none;
    }

    .active-filters-container .badge {
        flex-shrink: 0;
    }

    /* Pagination mobile */
    .pagination {
        flex-wrap: nowrap;
        overflow-x: auto;
        justify-content: flex-start !important;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 0.5rem;
    }

    .pagination::-webkit-scrollbar {
        display: none;
    }

    .pagination .page-item {
        flex-shrink: 0;
    }

    .pagination .page-link {
        padding: 0.5rem 0.75rem;
        min-width: 44px;
        text-align: center;
    }
}

/* ============================================
   Listing Detail Page Mobile
   ============================================ */
@media (max-width: 768px) {
    /* Full-width images */
    .listing-image {
        max-height: 300px;
        border-radius: 0;
    }

    /* Better thumbnail gallery on mobile */
    .thumbnail-nav {
        width: 60px;
        height: 60px;
        margin: 2px;
    }

    /* Price and action sticky bar */
    .listing-info-header {
        position: sticky;
        top: 56px;
        background: white;
        z-index: 100;
        padding: 0.75rem 0;
        margin: 0 -15px;
        padding-left: 15px;
        padding-right: 15px;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    }

    /* Better button layout */
    .listing-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .listing-actions .btn {
        flex: 1 1 auto;
        min-width: 100px;
    }
}

/* ============================================
   Form Elements Mobile
   ============================================ */
@media (max-width: 768px) {
    /* Better select dropdowns */
    select.form-select {
        background-size: 16px 12px;
        padding-right: 2.5rem;
    }

    /* Radio and checkbox groups */
    .form-check {
        padding: 0.75rem 0;
        padding-left: 2rem;
    }

    .form-check-input {
        width: 1.25em;
        height: 1.25em;
    }

    /* Better file input */
    input[type="file"].form-control {
        padding: 0.75rem;
    }
}

/* ============================================
   Alert/Flash Messages Mobile
   ============================================ */
@media (max-width: 768px) {
    .alert {
        border-radius: 0;
        margin-left: -15px;
        margin-right: -15px;
        padding: 1rem;
    }

    .alert-dismissible .btn-close {
        padding: 1rem;
    }
}

/* ============================================
   Hero Sections Mobile
   ============================================ */
@media (max-width: 768px) {
    .hero-headline {
        padding: 1rem 0;
    }

    .hero-headline .lead {
        font-size: 0.95rem;
    }

    .category-hero {
        padding: 1.5rem 0;
    }

    .category-hero h2 {
        font-size: 1.25rem;
        margin-bottom: 1rem;
    }
}

/* ============================================
   Footer Mobile
   ============================================ */
@media (max-width: 768px) {
    footer.footer {
        padding: 1.5rem 0;
    }

    footer .col-md-3 {
        margin-bottom: 1.5rem;
        text-align: center;
    }

    footer h5 {
        font-size: 1rem;
        margin-bottom: 0.75rem;
    }

    footer .app-store-badges {
        margin-top: 1rem;
    }

    footer .app-store-badge {
        height: 36px;
    }

    footer .social-icons {
        justify-content: center;
    }
}

/* ============================================
   Hide Desktop-Only Elements on Mobile
   ============================================ */
@media (max-width: 768px) {
    .d-desktop-only {
        display: none !important;
    }
}

@media (min-width: 769px) {
    .d-mobile-only {
        display: none !important;
    }
}

/* ============================================
   Performance: Reduce animations on low-end
   ============================================ */
@media (max-width: 768px) and (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }
}

/* Optimize for slow connections */
@media (max-width: 768px) {
    /* Use system fonts as fallback */
    body {
        font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    }
}

/* ============================================
   Landscape Orientation Mobile
   ============================================ */
@media (max-width: 768px) and (orientation: landscape) {
    .navbar {
        padding: 0.25rem 0;
    }

    body {
        padding-top: 48px;
    }

    .premium-spotlight .spotlight-image {
        height: 200px !important;
    }

    .category-hero {
        padding: 1rem 0;
    }
}
