/**
 * PC Store - Mobile Cyberpunk Optimizations
 * Optimizado para iPhone 16 Pro Max (430x932px) y Samsung similares
 * Breakpoints: Mobile (<768px), Tablet (768-992px), Desktop (>992px)
 */

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

@media (max-width: 991px) {
    /* Typography - Tamaños optimizados para móvil */
    body {
        font-size: 15px;
        line-height: 1.6;
    }

    h1, .h1 { font-size: 1.75rem; }
    h2, .h2 { font-size: 1.5rem; }
    h3, .h3 { font-size: 1.25rem; }
    h4, .h4 { font-size: 1.125rem; }
    h5, .h5 { font-size: 1rem; }
    h6, .h6 { font-size: 0.9rem; }

    /* Container - Reducir padding en móvil */
    .container {
        padding-left: 15px;
        padding-right: 15px;
    }

    /* Botones - Tamaño táctil mínimo 44x44px */
    .btn {
        min-height: 44px;
        padding: 0.75rem 1.25rem;
        font-size: 15px;
    }

    .btn-sm {
        min-height: 38px;
        padding: 0.5rem 1rem;
        font-size: 14px;
    }

    .btn-lg {
        min-height: 52px;
        padding: 1rem 1.5rem;
        font-size: 16px;
    }

    /* Forms - Inputs más grandes para touch */
    .form-control,
    .form-select {
        min-height: 44px;
        font-size: 16px; /* Previene zoom en iOS */
        padding: 0.75rem 1rem;
    }

    .form-label {
        font-size: 14px;
        margin-bottom: 0.5rem;
    }

    /* Cards - Spacing optimizado */
    .card {
        margin-bottom: 1rem;
    }

    .card-body {
        padding: 1rem;
    }

    /* Product Cards - Grid responsive */
    .product-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }

    /* Iconos - Tamaño táctil */
    .btn-icon,
    .nav-link {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Links - Área táctil adecuada */
    a {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }

    /* Tablas - Scroll horizontal */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Modales - Fullscreen en móvil */
    .modal-dialog {
        margin: 0;
        max-width: 100%;
    }

    .modal-content {
        min-height: 100vh;
        border-radius: 0;
    }

    /* Offcanvas - Transiciones suaves */
    .offcanvas {
        transition: transform 0.3s ease-in-out;
    }
}

/* ===========================================
   SAFE AREAS (iPhone notch)
   =========================================== */

@supports (padding: max(0px)) {
    .navbar,
    .header-main {
        padding-left: max(1rem, env(safe-area-inset-left));
        padding-right: max(1rem, env(safe-area-inset-right));
    }

    .footer {
        padding-bottom: max(2rem, env(safe-area-inset-bottom));
    }

    /* Mobile search bar */
    .mobile-search-bar {
        padding-top: max(1rem, env(safe-area-inset-top));
    }
}

/* ===========================================
   TABLET OPTIMIZATIONS (768px - 992px)
   =========================================== */

@media (min-width: 768px) and (max-width: 991px) {
    /* Grids - 3 columnas en tablet */
    .product-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 1.5rem;
    }

    /* Typography - Ligeramente más grande */
    body {
        font-size: 16px;
    }

    h1, .h1 { font-size: 2rem; }
    h2, .h2 { font-size: 1.75rem; }
}

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

@media (hover: none) and (pointer: coarse) {
    /* Eliminar hover en dispositivos touch */
    .card:hover {
        transform: none;
    }

    /* Tap highlights */
    * {
        -webkit-tap-highlight-color: rgba(166, 246, 28, 0.2);
    }

    /* Scrollbar oculto en móvil */
    ::-webkit-scrollbar {
        width: 0;
        height: 0;
    }
}

/* ===========================================
   MOBILE NAVIGATION
   =========================================== */

@media (max-width: 991px) {
    /* Header sticky con sombra */
    .header-main {
        position: sticky;
        top: 0;
        z-index: 1000;
        box-shadow: var(--shadow-md);
    }

    /* Navbar collapse - Animación suave */
    .navbar-collapse {
        transition: height 0.3s ease;
    }

    .navbar-collapse.collapsing {
        transition: height 0.2s ease;
    }

    /* Mobile menu - Full width */
    #mobileMenu {
        width: 100%;
    }

    /* Botones de navegación - Áreas grandes */
    .mobile-nav-menu .nav-link {
        padding: 1rem 1.25rem;
        min-height: 52px;
    }
}

/* ===========================================
   MOBILE SEARCH BAR
   =========================================== */

@media (max-width: 991px) {
    .mobile-search-bar {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        z-index: 1050;
        backdrop-filter: blur(10px);
    }

    .mobile-search-bar .form-control {
        font-size: 16px;
        border-radius: 8px;
    }

    .mobile-search-bar .btn {
        min-width: 52px;
        min-height: 52px;
    }
}

/* ===========================================
   MOBILE PRODUCT CARDS
   =========================================== */

@media (max-width: 767px) {
    .product-card {
        border-radius: 8px;
        overflow: hidden;
    }

    .product-card-image {
        height: 200px;
    }

    .product-card-body {
        padding: 1rem;
    }

    .product-title {
        font-size: 0.9rem;
        line-height: 1.4;
        min-height: 2.8rem;
    }

    .product-price {
        font-size: 1.25rem;
        margin: 0.75rem 0;
    }

    /* Add to cart button - Full width */
    .product-card .btn {
        width: 100%;
        font-size: 14px;
        padding: 0.75rem;
    }
}

/* ===========================================
   MOBILE FILTERS & SIDEBAR
   =========================================== */

@media (max-width: 991px) {
    .filters-sidebar {
        position: fixed;
        top: 0;
        left: -100%;
        width: 85%;
        max-width: 400px;
        height: 100vh;
        background: var(--color-bg-card);
        transition: left 0.3s ease;
        z-index: 1040;
        overflow-y: auto;
        box-shadow: var(--shadow-lg);
        border-right: 1px solid var(--color-border);
    }

    .filters-sidebar.show {
        left: 0;
    }

    .filters-close {
        position: absolute;
        top: 1rem;
        right: 1rem;
        z-index: 1;
        min-width: 44px;
        min-height: 44px;
    }

    /* Filter toggle button */
    .filter-toggle {
        position: fixed;
        bottom: 2rem;
        right: 1rem;
        z-index: 1030;
        min-width: 56px;
        min-height: 56px;
        border-radius: 50%;
        box-shadow: var(--shadow-lg), var(--glow-green);
        background: var(--color-neon-green);
        color: var(--color-bg-primary);
    }

    .filter-toggle:hover {
        background: var(--color-neon-purple);
        box-shadow: var(--shadow-lg), var(--glow-purple);
    }
}

/* ===========================================
   MOBILE CART
   =========================================== */

@media (max-width: 767px) {
    .cart-item {
        display: flex;
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }

    .cart-item-image {
        width: 100%;
        max-width: 150px;
        margin: 0 auto;
    }

    .cart-item-info {
        text-align: center;
    }

    .quantity-control {
        justify-content: center;
        margin: 1rem 0;
    }

    .cart-item-actions {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
    }
}

/* ===========================================
   MOBILE PRODUCT DETAIL
   =========================================== */

@media (max-width: 767px) {
    .product-gallery {
        margin-bottom: 1.5rem;
    }

    .product-main-image {
        width: 100%;
        height: auto;
        border-radius: 8px;
    }

    .product-thumbnails {
        display: flex;
        gap: 0.5rem;
        overflow-x: auto;
        padding: 1rem 0;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
    }

    .product-thumbnail {
        flex-shrink: 0;
        width: 80px;
        height: 80px;
        border-radius: 8px;
        scroll-snap-align: start;
    }

    .product-info {
        padding: 1rem;
    }

    .product-actions {
        position: sticky;
        bottom: 0;
        background: var(--color-bg-card);
        padding: 1rem;
        border-top: 1px solid var(--color-border);
        box-shadow: var(--shadow-lg);
    }

    .product-actions .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
}

/* ===========================================
   MOBILE CHECKOUT
   =========================================== */

@media (max-width: 767px) {
    .checkout-steps {
        display: flex;
        overflow-x: auto;
        gap: 0.5rem;
        margin-bottom: 1.5rem;
        padding-bottom: 1rem;
        -webkit-overflow-scrolling: touch;
    }

    .checkout-step {
        flex-shrink: 0;
        min-width: 120px;
        padding: 0.75rem 1rem;
        text-align: center;
        border-radius: 8px;
        background: var(--color-bg-secondary);
        border: 1px solid var(--color-border);
    }

    .checkout-step.active {
        background: rgba(166, 246, 28, 0.1);
        border-color: var(--color-neon-green);
        color: var(--color-neon-green);
    }
}

/* ===========================================
   MOBILE ADMIN PANEL
   =========================================== */

@media (max-width: 991px) {
    .admin-sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        height: 100vh;
        width: 280px;
        z-index: 1040;
        transition: left 0.3s ease;
    }

    .admin-sidebar.show {
        left: 0;
    }

    .admin-main {
        width: 100%;
        margin-left: 0;
    }

    #sidebarToggle {
        display: block !important;
    }

    /* Admin tables - Scroll horizontal */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table {
        min-width: 600px;
    }
}

/* ===========================================
   VIEWPORT HEIGHT FIX (iOS)
   =========================================== */

.vh-100 {
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
}

/* ===========================================
   LOADING STATES
   =========================================== */

@media (max-width: 767px) {
    .spinner-border {
        width: 2rem;
        height: 2rem;
        border-width: 0.25rem;
    }

    .skeleton-loader {
        background: linear-gradient(
            90deg,
            var(--color-bg-secondary) 25%,
            var(--color-bg-card) 50%,
            var(--color-bg-secondary) 75%
        );
        background-size: 200% 100%;
        animation: skeleton-loading 1.5s ease-in-out infinite;
    }

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

/* ===========================================
   MOBILE ANIMATIONS
   =========================================== */

@media (prefers-reduced-motion: no-preference) {
    .fade-in {
        animation: fadeIn 0.3s ease-in;
    }

    @keyframes fadeIn {
        from { opacity: 0; }
        to { opacity: 1; }
    }

    .slide-up {
        animation: slideUp 0.3s ease-out;
    }

    @keyframes slideUp {
        from {
            transform: translateY(20px);
            opacity: 0;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }
}

/* ===========================================
   ACCESSIBILITY - HIGH CONTRAST
   =========================================== */

@media (prefers-contrast: high) {
    .btn-outline-primary,
    .btn-outline-secondary {
        border-width: 2px;
    }

    .nav-center-link,
    .mobile-nav-menu .nav-link {
        border: 1px solid var(--color-border);
    }
}

/* ===========================================
   PERFORMANCE OPTIMIZATIONS
   =========================================== */

/* GPU Acceleration */
.card,
.product-card,
.btn,
.dropdown-menu {
    transform: translateZ(0);
    will-change: transform;
}

/* Reduce animations on low-end devices */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
