/**
 * Mobile Responsiveness Enhancement - Complete Overhaul
 * Comprehensive mobile-first design for all pages with robust adaptability
 * Fixes header behavior, prevents horizontal scroll, ensures fluid layouts
 */

/* ==========================================
   GLOBAL MOBILE-FIRST BASE STYLES
   ========================================== */

/* Prevent horizontal overflow on all pages */
html {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
}

body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
    min-height: 100vh;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

/* Ensure all containers respect viewport width */
* {
    box-sizing: border-box;
}

*:before,
*:after {
    box-sizing: border-box;
}

/* Prevent images from causing overflow */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Fluid containers */
.container,
.container-fluid,
.container-wide,
.content-wrapper,
.main-content,
.page-wrapper {
    max-width: 100%;
    width: 100%;
    padding-left: 15px;
    padding-right: 15px;
    margin-left: auto;
    margin-right: auto;
    overflow-x: hidden;
}

/* Prevent table overflow */
table {
    max-width: 100%;
    table-layout: auto;
}

/* ==========================================
   HEADER & NAVIGATION - ADAPTIVE & STABLE
   ========================================== */

/* Desktop and large tablets (1025px+) */
@media (min-width: 1025px) {
    .ebay-top-header-content,
    .ebay-main-header-content,
    .fezamarket-header-content {
        max-width: 1280px;
        padding: 0 24px;
    }
}

/* Tablets and iPads (768px - 1024px) */
@media (max-width: 1024px) and (min-width: 769px) {
    .ebay-top-header-content,
    .ebay-main-header-content,
    .fezamarket-header-content {
        max-width: 100%;
        padding: 0 20px;
    }
    
    .ebay-top-left,
    .ebay-top-right,
    .top-nav-left,
    .top-nav-right {
        gap: 12px;
    }
    
    .ebay-top-header a,
    .top-nav-link {
        font-size: 12px;
    }
    
    /* Adjust search bar */
    .ebay-search-container {
        flex: 1;
        min-width: 0;
    }
}

/* Mobile and small tablets (768px and below) */
@media (max-width: 768px) {
    
    /* ======================
       TOP HEADER BAR
       ====================== */
    .ebay-top-header,
    .top-nav {
        height: auto;
        min-height: 36px;
    }
    
    .ebay-top-header-content,
    .top-nav-content {
        flex-direction: column;
        gap: 8px;
        padding: 8px 15px;
        align-items: stretch;
    }
    
    .ebay-top-left,
    .ebay-top-right,
    .top-nav-left,
    .top-nav-right {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
        gap: 8px;
        font-size: 12px;
    }
    
    /* Hide less important links on small screens */
    .ebay-top-header .hide-mobile,
    .top-nav .hide-mobile {
        display: none !important;
    }
    
    /* ======================
       MAIN HEADER
       ====================== */
    .ebay-main-header,
    .fezamarket-header {
        height: auto;
        min-height: 60px;
        position: sticky;
        top: 0;
        z-index: 1000;
        background: white;
    }
    
    .ebay-main-header-content,
    .main-header-content {
        flex-wrap: wrap;
        padding: 10px 15px;
        gap: 10px;
    }
    
    /* Logo - Scale appropriately */
    .ebay-logo,
    .fezamarket-logo {
        font-size: 28px;
        margin-right: 0;
    }
    
    /* ======================
       SEARCH BAR - FULL WIDTH ON MOBILE
       ====================== */
    .ebay-search-container,
    .search-bar-container {
        flex: 1 1 100%;
        order: 3;
        width: 100%;
        max-width: 100%;
    }
    
    .ebay-search-input,
    .search-input {
        width: 100%;
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 10px 12px;
    }
    
    .ebay-category-dropdown {
        display: none; /* Hide on mobile to save space */
    }
    
    /* ======================
       NAVIGATION LINKS
       ====================== */
    .ebay-nav-section,
    .main-nav-center {
        display: none; /* Hidden by default on mobile */
        flex-direction: column;
        width: 100%;
        order: 4;
        background: white;
        border-top: 1px solid #e5e7eb;
        padding: 10px 0;
    }
    
    .ebay-nav-section.mobile-open,
    .main-nav-center.mobile-open {
        display: flex !important;
    }
    
    .ebay-nav-section a,
    .main-nav-center .nav-link {
        display: block;
        padding: 12px 15px;
        border-bottom: 1px solid #f0f0f0;
        font-size: 15px;
        color: #333;
    }
    
    .ebay-nav-section a:hover,
    .main-nav-center .nav-link:hover {
        background: #f9fafb;
    }
    
    /* ======================
       HAMBURGER MENU BUTTON
       ====================== */
    .mobile-menu-toggle {
        display: flex !important;
        align-items: center;
        justify-content: center;
        background: none;
        border: none;
        font-size: 24px;
        cursor: pointer;
        padding: 8px;
        color: #333;
        order: 2;
        min-width: 44px; /* Touch target size */
        min-height: 44px;
    }
    
    .mobile-menu-toggle:hover {
        background: #f0f0f0;
        border-radius: 4px;
    }
    
    /* ======================
       HEADER ICONS - COMPACT
       ====================== */
    .ebay-header-icons,
    .header-icons {
        display: flex;
        gap: 8px;
        order: 1;
        margin-left: auto;
    }
    
    .notification-icon,
    .cart-icon-top,
    .watchlist-icon,
    .wishlist-icon {
        padding: 8px;
        font-size: 20px;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Badge positioning */
    .badge {
        top: 4px;
        right: 4px;
        min-width: 18px;
        height: 18px;
        font-size: 11px;
        padding: 2px 4px;
    }
    
    /* ======================
       ACCOUNT DASHBOARD
       ====================== */
    .account-dashboard {
        padding: 15px;
    }
    
    .dashboard-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }
    
    .stats-grid,
    .quick-actions-grid,
    .account-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    /* Navigation tabs - horizontal scroll */
    .nav-tabs,
    .account-tabs {
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
        flex-wrap: nowrap;
        scrollbar-width: none; /* Firefox */
        -ms-overflow-style: none; /* IE/Edge */
    }
    
    .nav-tabs::-webkit-scrollbar,
    .account-tabs::-webkit-scrollbar {
        display: none; /* Chrome/Safari */
    }
    
    .nav-tab {
        font-size: 14px;
        padding: 10px 15px;
        flex-shrink: 0;
    }
    
    /* ======================
       TABLES - RESPONSIVE
       ====================== */
    .orders-table-container,
    .data-table-wrapper,
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -15px;
        padding: 0 15px;
    }
    
    .orders-table,
    .data-table {
        min-width: 600px;
        font-size: 13px;
    }
    
    .orders-table th,
    .orders-table td,
    .data-table th,
    .data-table td {
        padding: 8px 6px;
        white-space: nowrap;
    }
    
    /* ======================
       FORMS - MOBILE FRIENDLY
       ====================== */
    .form-row {
        flex-direction: column;
        gap: 15px;
    }
    
    .form-group {
        width: 100% !important;
        margin-bottom: 15px;
    }
    
    .form-input,
    .form-control,
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="tel"],
    input[type="number"],
    textarea,
    select {
        font-size: 16px; /* Prevents iOS zoom */
        padding: 12px;
        width: 100%;
    }
    
    .form-actions {
        flex-direction: column;
        gap: 10px;
    }
    
    .form-actions button,
    .form-actions .btn {
        width: 100%;
        min-height: 44px;
    }
    
    /* ======================
       BUTTONS - TOUCH FRIENDLY
       ====================== */
    .btn,
    button,
    .button,
    a.btn {
        min-height: 44px;
        padding: 12px 20px;
        font-size: 15px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    
    .btn-group {
        flex-direction: column;
        gap: 10px;
    }
    
    .btn-group button,
    .btn-group .btn {
        width: 100%;
    }
    
    /* ======================
       MODALS - FULL SCREEN ON MOBILE
       ====================== */
    .modal {
        padding: 0;
    }
    
    .modal-content {
        width: 100%;
        height: 100vh;
        max-height: 100vh;
        margin: 0;
        border-radius: 0;
        overflow-y: auto;
    }
    
    .modal-header {
        position: sticky;
        top: 0;
        background: white;
        z-index: 1;
        border-bottom: 1px solid #e5e7eb;
    }
    
    /* ======================
       CARDS & GRIDS
       ====================== */
    .card-grid,
    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    /* Product grid - 2 columns on mobile */
    .products-grid,
    .product-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    
    .product-card {
        font-size: 13px;
    }
    
    .product-card-image {
        height: 150px;
    }
    
    .product-card-title {
        font-size: 14px;
        line-height: 1.4;
    }
    
    .product-card-price {
        font-size: 16px;
    }
    
    /* ======================
       CHECKOUT PAGE
       ====================== */
    .checkout-container {
        flex-direction: column;
        padding: 0 1rem;
    }
    
    .checkout-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
    
    .checkout-main,
    .checkout-sidebar {
        width: 100%;
    }
    
    .checkout-section {
        padding: 1.25rem;
        margin-bottom: 1rem;
    }
    
    /* Prevent horizontal scroll on small screens */
    .form-control,
    .form-row,
    .shipping-option,
    .order-summary {
        max-width: 100%;
        box-sizing: border-box;
    }
    
    /* Ensure inputs don't overflow */
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    select,
    textarea {
        max-width: 100%;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    /* ======================
       ADMIN DASHBOARD
       ====================== */
    .admin-dashboard {
        padding: 15px;
    }
    
    .admin-stats-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .admin-modules-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .module-features {
        grid-template-columns: 1fr;
    }
    
    /* Admin Products Page - Responsive Table */
    .data-table-card {
        overflow-x: auto;
    }
    
    .data-table {
        min-width: 800px;
    }
    
    .product-cell {
        min-width: 200px;
    }
    
    .product-info {
        display: flex;
        gap: 0.75rem;
        align-items: center;
    }
    
    .product-image {
        width: 50px;
        height: 50px;
        flex-shrink: 0;
    }
    
    /* Admin Tables - Mobile Card View */
    @media (max-width: 768px) {
        .data-table {
            min-width: 100%;
        }
        
        .data-table thead {
            display: none;
        }
        
        .data-table tbody tr {
            display: block;
            margin-bottom: 1rem;
            border: 1px solid #e5e7eb;
            border-radius: 8px;
            padding: 1rem;
            background: white;
        }
        
        .data-table tbody td {
            display: block;
            text-align: right;
            padding: 0.5rem 0;
            border: none;
        }
        
        .data-table tbody td::before {
            content: attr(data-label);
            float: left;
            font-weight: 600;
            color: #6b7280;
        }
        
        .product-cell::before {
            content: '';
        }
        
        .bulk-checkbox-cell {
            text-align: left !important;
        }
    }
}

/* ==========================================
   MOBILE PHONES (480px and below)
   ========================================== */

@media (max-width: 480px) {
    
    /* Typography scaling */
    h1 {
        font-size: 22px;
        line-height: 1.3;
    }
    
    h2 {
        font-size: 18px;
        line-height: 1.3;
    }
    
    h3 {
        font-size: 16px;
        line-height: 1.4;
    }
    
    p, body {
        font-size: 14px;
        line-height: 1.5;
    }
    
    /* Header - Extra Compact */
    .ebay-logo,
    .fezamarket-logo {
        font-size: 24px;
    }
    
    .ebay-top-header,
    .top-nav {
        font-size: 11px;
    }
    
    /* Search Bar */
    .ebay-search-input,
    .search-input {
        font-size: 16px;
        padding: 10px;
    }
    
    /* Product Grid - Single Column for very small screens */
    .products-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .product-card-image {
        height: 200px;
    }
    
    /* Stats Cards - Compact */
    .stat-card {
        padding: 12px;
    }
    
    .stat-value {
        font-size: 20px;
    }
    
    .stat-label {
        font-size: 12px;
    }
    
    /* Buttons - Slightly smaller padding */
    .btn,
    button {
        padding: 10px 16px;
        font-size: 14px;
    }
    
    /* Tables - Card View on Mobile */
    .data-table,
    .orders-table {
        font-size: 11px;
    }
    
    .data-table th,
    .data-table td,
    .orders-table th,
    .orders-table td {
        padding: 6px 4px;
    }
    
    /* Navigation tabs - smaller */
    .nav-tab {
        padding: 8px 12px;
        font-size: 13px;
    }
    
    /* Modals - Full screen */
    .modal-content {
        padding: 15px;
    }
    
    .modal-header h2,
    .modal-header h3 {
        font-size: 18px;
    }
}

/* ==========================================
   LANDSCAPE ORIENTATION FIXES
   ========================================== */

@media (max-height: 500px) and (orientation: landscape) {
    /* Adjust header for landscape */
    .ebay-main-header,
    .fezamarket-header {
        position: relative; /* Don't stick in landscape */
    }
    
    .modal-content {
        max-height: 100vh;
        overflow-y: auto;
    }
}

/* ==========================================
   HIGH DPI / RETINA DISPLAYS
   ========================================== */

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* Ensure images look sharp on retina */
    img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* ==========================================
   TOUCH DEVICE OPTIMIZATIONS
   ========================================== */

@media (hover: none) and (pointer: coarse) {
    /* Better touch targets */
    a, button, .btn, .clickable {
        min-height: 44px;
        min-width: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Remove hover effects on touch devices */
    a:hover, button:hover, .btn:hover {
        transform: none;
    }
    
    /* Add tap highlight */
    a, button, .btn {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    }
}

/* ==========================================
   PRINT STYLES - BONUS
   ========================================== */

@media print {
    .ebay-top-header,
    .top-nav,
    .main-nav-center,
    .header-icons,
    .mobile-menu-toggle,
    .sidebar,
    .footer,
    button,
    .btn {
        display: none !important;
    }
    
    .ebay-main-header,
    .fezamarket-header {
        position: relative;
        border-bottom: 2px solid #000;
    }
    
    body {
        font-size: 12pt;
        line-height: 1.5;
        color: #000;
        background: white;
    }
}

/* ==========================================
   UTILITY CLASSES
   ========================================== */

/* Hide on mobile */
@media (max-width: 768px) {
    .hide-mobile,
    .desktop-only {
        display: none !important;
    }
}

/* Show only on mobile */
@media (min-width: 769px) {
    .show-mobile,
    .mobile-only {
        display: none !important;
    }
}

/* Hide on desktop */
@media (min-width: 769px) {
    .hide-desktop {
        display: none !important;
    }
}

/* Responsive text alignment */
@media (max-width: 768px) {
    .text-center-mobile {
        text-align: center !important;
    }
    
    .text-left-mobile {
        text-align: left !important;
    }
}
    }
    
    h2 {
        font-size: 20px;
    }
    
    h3 {
        font-size: 18px;
    }
    
    /* Header */
    .logo {
        font-size: 18px;
    }
    
    .top-nav-content {
        font-size: 12px;
    }
    
    /* Search Bar */
    .search-input {
        font-size: 14px;
        padding: 8px 12px;
    }
    
    /* Product Grid - Single Column */
    .products-grid {
        grid-template-columns: 1fr;
    }
    
    /* Stats Cards */
    .stat-card {
        padding: 15px;
    }
    
    .stat-value {
        font-size: 24px;
    }
    
    /* Tables - Card View on Mobile */
    .data-table {
        font-size: 12px;
    }
    
    /* Alternative: Convert tables to cards on mobile */
    .table-mobile-card {
        display: none;
    }
    
    @supports (display: grid) {
        .data-table-wrapper.mobile-card-view .data-table {
            display: none;
        }
        
        .table-mobile-card {
            display: block;
            margin-bottom: 15px;
            background: white;
            border: 1px solid #e5e7eb;
            border-radius: 8px;
            padding: 15px;
        }
        
        .table-mobile-card .card-row {
            display: flex;
            justify-content: space-between;
            padding: 10px 0;
            border-bottom: 1px solid #f3f4f6;
        }
        
        .table-mobile-card .card-row:last-child {
            border-bottom: none;
        }
        
        .table-mobile-card .card-label {
            font-weight: 600;
            color: #6b7280;
        }
        
        .table-mobile-card .card-value {
            text-align: right;
        }
    }
    
    /* Buttons - Full Width and Touch Friendly */
    .btn,
    button {
        padding: 12px 20px;
        font-size: 16px;
        min-height: 44px; /* iOS touch target */
    }
    
    .btn-sm {
        padding: 10px 16px;
        font-size: 14px;
        min-height: 40px;
    }
    
    /* Forms - Larger inputs for mobile */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="url"],
    textarea,
    select {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 12px;
        min-height: 44px;
    }
    
    /* Modals - Full Screen on Small Mobile */
    .modal-content {
        width: 100%;
        height: 100vh;
        margin: 0;
        border-radius: 0;
        max-height: none;
    }
    
    /* Navigation Tabs - Scrollable */
    .nav-tabs {
        gap: 5px;
        padding: 0 10px;
    }
    
    .nav-tab {
        font-size: 13px;
        padding: 8px 12px;
        min-width: auto;
    }
    
    /* Footer */
    .footer {
        padding: 20px 15px;
    }
    
    .footer-grid {
        grid-template-columns: 1fr;
        gap: 30px;
    }
    
    /* Spacing */
    .section {
        padding: 30px 15px;
    }
    
    /* Cards */
    .card {
        padding: 15px;
    }
    
    .card-header {
        flex-direction: column;
        gap: 10px;
    }
    
    /* Developer Portal Tables */
    .logs-table-container {
        overflow-x: auto;
    }
    
    .logs-table {
        min-width: 700px;
    }
    
    /* Pagination */
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
        gap: 5px;
    }
    
    .pagination .page-link {
        padding: 8px 12px;
        font-size: 14px;
    }
}

/* Very Small Phones (360px and below) */
@media (max-width: 360px) {
    .container {
        padding: 0 10px;
    }
    
    h1 {
        font-size: 20px;
    }
    
    h2 {
        font-size: 18px;
    }
    
    .products-grid {
        gap: 10px;
    }
    
    .stat-card {
        padding: 12px;
    }
    
    .stat-value {
        font-size: 20px;
    }
}

/* ==========================================
   UTILITY CLASSES
   ========================================== */

/* Hide on mobile */
.hide-mobile {
    display: block;
}

@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
}

/* Show only on mobile */
.show-mobile {
    display: none;
}

@media (max-width: 768px) {
    .show-mobile {
        display: block !important;
    }
}

/* Hide on desktop */
.hide-desktop {
    display: none;
}

@media (min-width: 769px) {
    .hide-desktop {
        display: block !important;
    }
}

/* Touch-friendly spacing */
.touch-target {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Prevent text selection on buttons/controls */
.no-select {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Enable momentum scrolling on iOS */
.momentum-scroll {
    -webkit-overflow-scrolling: touch;
}

/* ==========================================
   HAMBURGER MENU STYLES
   ========================================== */

.mobile-menu-toggle {
    display: none;
    position: relative;
    width: 30px;
    height: 30px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
}

.hamburger-icon {
    display: block;
    position: relative;
    width: 100%;
    height: 2px;
    background: #333;
    transition: all 0.3s ease;
}

.hamburger-icon::before,
.hamburger-icon::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 2px;
    background: #333;
    transition: all 0.3s ease;
}

.hamburger-icon::before {
    top: -8px;
}

.hamburger-icon::after {
    bottom: -8px;
}

.mobile-menu-toggle.active .hamburger-icon {
    background: transparent;
}

.mobile-menu-toggle.active .hamburger-icon::before {
    top: 0;
    transform: rotate(45deg);
}

.mobile-menu-toggle.active .hamburger-icon::after {
    bottom: 0;
    transform: rotate(-45deg);
}

@media (max-width: 768px) {
    .mobile-menu-toggle {
        display: block;
    }
}

/* ==========================================
   ACCESSIBILITY IMPROVEMENTS
   ========================================== */

/* Focus styles for keyboard navigation */
*:focus-visible {
    outline: 2px solid #0654ba;
    outline-offset: 2px;
}

/* Skip to main content link */
.skip-to-main {
    position: absolute;
    top: -40px;
    left: 0;
    background: #0654ba;
    color: white;
    padding: 8px;
    text-decoration: none;
    z-index: 100;
}

.skip-to-main:focus {
    top: 0;
}
