/* ========================================
   SHOPTDANG MOBILE OPTIMIZATIONS v3.0
   Phase 5: Mobile & Performance
   ======================================== */

/* =====================
   1. BASE MOBILE RESET
   ===================== */

/* Touch Optimization */
* {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* Prevent text size adjustment */
html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
}

/* Better scrollbar for mobile */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--color-primary-500);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-primary-600);
}

/* =====================
   2. RESPONSIVE TYPOGRAPHY
   ===================== */

html {
    font-size: 16px;
}

@media (max-width: 768px) {
    html {
        font-size: 15px;
    }
}

@media (max-width: 480px) {
    html {
        font-size: 14px;
    }
}

/* Fluid Typography */
h1 {
    font-size: clamp(1.75rem, 5vw, 3rem);
}

h2 {
    font-size: clamp(1.5rem, 4vw, 2.25rem);
}

h3 {
    font-size: clamp(1.25rem, 3vw, 1.75rem);
}

/* =====================
   3. MOBILE HEADER
   ===================== */

@media (max-width: 1024px) {
    .header-container {
        padding: 0 var(--space-3);
        gap: var(--space-3);
    }
    
    .search-container {
        display: none;
    }
    
    .logo img {
        height: 38px;
    }
    
    .btn-text {
        display: none;
    }
    
    .header-btn {
        padding: var(--space-2);
        min-width: 40px;
        justify-content: center;
    }
    
    .user-info {
        display: none;
    }
    
    .user-profile {
        padding: var(--space-2);
    }
    
    .user-avatar {
        width: 34px;
        height: 34px;
    }
}

/* Mobile Search (Full Width) */
@media (max-width: 1024px) {
    .mobile-search {
        display: block;
        position: fixed;
        top: 70px;
        left: 0;
        right: 0;
        background: var(--bg-secondary);
        padding: var(--space-3);
        border-bottom: 1px solid var(--border-primary);
        transform: translateY(-100%);
        opacity: 0;
        transition: all var(--duration-300) var(--ease-out);
        z-index: var(--z-sticky);
    }
    
    .mobile-search.active {
        transform: translateY(0);
        opacity: 1;
    }
    
    .mobile-search-toggle {
        display: flex;
    }
}

@media (min-width: 1025px) {
    .mobile-search,
    .mobile-search-toggle {
        display: none !important;
    }
}

/* =====================
   4. MOBILE NAVIGATION
   ===================== */

/* Bottom Navigation Bar */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-top: 1px solid var(--border-primary);
    padding: var(--space-2) 0;
    padding-bottom: calc(var(--space-2) + env(safe-area-inset-bottom, 0));
    z-index: var(--z-fixed);
    backdrop-filter: blur(10px);
}

@media (max-width: 768px) {
    .mobile-bottom-nav {
        display: flex;
        justify-content: space-around;
        align-items: center;
    }
    
    /* Add padding to body for bottom nav */
    body {
        padding-bottom: calc(70px + env(safe-area-inset-bottom, 0));
    }
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-2) var(--space-3);
    color: var(--text-muted);
    text-decoration: none;
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    transition: all var(--duration-200) var(--ease-out);
    border-radius: var(--radius-lg);
    min-width: 60px;
}

.mobile-nav-item i {
    font-size: 1.5rem;
    transition: transform var(--duration-200) var(--ease-bounce);
}

.mobile-nav-item.active,
.mobile-nav-item:active {
    color: var(--color-primary-500);
    background: rgba(99, 102, 241, 0.1);
}

.mobile-nav-item.active i {
    transform: scale(1.1);
}

/* Badge on nav item */
.mobile-nav-item .nav-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: var(--color-danger-500);
    color: white;
    font-size: 10px;
    min-width: 16px;
    height: 16px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* =====================
   5. MOBILE PRODUCT GRID
   ===================== */

@media (max-width: 1280px) {
    .products-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: var(--space-4);
    }
}

@media (max-width: 1024px) {
    .products-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: var(--space-3);
    }
}

@media (max-width: 768px) {
    .products-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-3);
    }
    
    .product-card {
        border-radius: var(--radius-xl);
    }
    
    .product-info {
        padding: var(--space-3);
    }
    
    .product-title {
        font-size: var(--font-size-sm);
        -webkit-line-clamp: 1;
        line-clamp: 1;
    }
    
    .product-price {
        font-size: var(--font-size-base);
    }
}

@media (max-width: 480px) {
    .products-grid {
        gap: var(--space-2);
    }
    
    .product-badge {
        font-size: 0.65rem;
        padding: var(--space-1) var(--space-2);
    }
}

/* =====================
   6. MOBILE HERO/BANNER
   ===================== */

@media (max-width: 1024px) {
    .hero-grid {
        grid-template-columns: 1fr;
        gap: var(--space-4);
    }
    
    .hero-banner {
        height: 250px;
        border-radius: var(--radius-xl);
    }
    
    .hero-sidebar {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-3);
    }
}

@media (max-width: 640px) {
    .hero-banner {
        height: 180px;
        border-radius: var(--radius-lg);
    }
    
    .hero-sidebar {
        grid-template-columns: 1fr;
    }
}

/* =====================
   7. MOBILE MODALS
   ===================== */

@media (max-width: 640px) {
    .modal-container {
        max-width: 100%;
        margin: 0;
        border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
        max-height: 90vh;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
    }
    
    .modal-overlay {
        align-items: flex-end;
    }
    
    /* Swipe indicator for bottom sheet */
    .modal-container::before {
        content: '';
        position: absolute;
        top: var(--space-3);
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        background: var(--border-primary);
        border-radius: var(--radius-full);
    }
    
    .modal-header {
        padding-top: var(--space-6);
    }
}

/* =====================
   8. MOBILE FORMS
   ===================== */

@media (max-width: 768px) {
    input, 
    select, 
    textarea {
        font-size: 16px !important; /* Prevent zoom on iOS */
    }
    
    .form-group {
        margin-bottom: var(--space-4);
    }
    
    .form-group input,
    .form-group select {
        padding: var(--space-4);
    }
}

/* =====================
   9. MOBILE CARDS
   ===================== */

@media (max-width: 768px) {
    .glass-card {
        border-radius: var(--radius-xl);
        padding: var(--space-4);
    }
    
    .card-header {
        padding: var(--space-3) var(--space-4);
    }
    
    .card-body {
        padding: var(--space-4);
    }
}

/* =====================
   10. MOBILE TABLES (Responsive)
   ===================== */

@media (max-width: 768px) {
    .table-responsive {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Card-style tables for mobile */
    .table-cards {
        display: block;
    }
    
    .table-cards thead {
        display: none;
    }
    
    .table-cards tbody tr {
        display: block;
        background: var(--bg-card);
        border-radius: var(--radius-lg);
        padding: var(--space-3);
        margin-bottom: var(--space-3);
        border: 1px solid var(--border-primary);
    }
    
    .table-cards tbody td {
        display: flex;
        justify-content: space-between;
        padding: var(--space-2) 0;
        border-bottom: 1px solid var(--border-secondary);
    }
    
    .table-cards tbody td:last-child {
        border-bottom: none;
    }
    
    .table-cards tbody td::before {
        content: attr(data-label);
        font-weight: var(--font-weight-semibold);
        color: var(--text-muted);
    }
}

/* =====================
   11. TOUCH INTERACTIONS
   ===================== */

/* Better touch targets */
@media (hover: none) and (pointer: coarse) {
    button,
    a,
    .clickable {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Remove hover effects on touch devices */
    .product-card:hover {
        transform: none;
        box-shadow: none;
    }
    
    .product-card:active {
        transform: scale(0.98);
        transition: transform var(--duration-100) var(--ease-out);
    }
    
    /* Larger click areas */
    .product-card {
        cursor: pointer;
    }
}

/* =====================
   12. PULL TO REFRESH
   ===================== */

.pull-to-refresh {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translateY(-100%);
    transition: transform var(--duration-300) var(--ease-out);
    z-index: var(--z-fixed);
}

.pull-to-refresh.pulling {
    transform: translateY(0);
}

.pull-to-refresh .spinner {
    width: 30px;
    height: 30px;
}

/* =====================
   13. SAFE AREAS (Notch)
   ===================== */

/* Support for notched devices */
@supports (padding: env(safe-area-inset-top)) {
    .modern-header {
        padding-top: max(0.75rem, env(safe-area-inset-top));
    }
    
    .mobile-bottom-nav {
        padding-bottom: max(var(--space-2), env(safe-area-inset-bottom));
    }
    
    body {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
}

/* =====================
   14. LANDSCAPE MODE
   ===================== */

@media (max-height: 500px) and (orientation: landscape) {
    .modern-header {
        padding: var(--space-2) 0;
    }
    
    .logo img {
        height: 30px;
    }
    
    .hero-banner {
        height: 150px;
    }
    
    .mobile-bottom-nav {
        display: none;
    }
}

/* =====================
   15. PERFORMANCE OPTIMIZATIONS
   ===================== */

/* GPU Acceleration for animations */
.product-card,
.modal-container,
.mobile-bottom-nav,
[class*="animate-"] {
    will-change: transform;
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* Reduce paint on scroll */
.modern-header {
    contain: layout style;
}

/* Lazy load images placeholder */
img[loading="lazy"] {
    background: var(--bg-secondary);
}

/* Content visibility for long lists */
.product-card {
    content-visibility: auto;
    contain-intrinsic-size: 0 300px;
}

/* =====================
   16. PWA STYLES
   ===================== */

/* Standalone mode (installed PWA) */
@media (display-mode: standalone) {
    .install-prompt {
        display: none;
    }
    
    .modern-header {
        padding-top: env(safe-area-inset-top);
    }
}

/* Fullscreen mode */
@media (display-mode: fullscreen) {
    .modern-header {
        padding-top: var(--space-4);
    }
}

/* =====================
   17. SKELETON LOADING
   ===================== */

.skeleton {
    background: linear-gradient(
        90deg,
        var(--bg-secondary) 0%,
        var(--bg-hover) 50%,
        var(--bg-secondary) 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-md);
}

.skeleton-card {
    height: 300px;
    border-radius: var(--radius-xl);
}

.skeleton-text {
    height: 1em;
    margin-bottom: var(--space-2);
}

.skeleton-text.short {
    width: 60%;
}

.skeleton-avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
}

/* =====================
   18. DARK MODE ADJUSTMENTS
   ===================== */

@media (prefers-color-scheme: dark) {
    /* Auto dark mode for images */
    img {
        filter: brightness(0.95);
    }
    
    img:hover {
        filter: brightness(1);
    }
}

/* =====================
   19. PRINT MOBILE
   ===================== */

@media print {
    .mobile-bottom-nav,
    .modern-header,
    .mobile-search {
        display: none !important;
    }
    
    body {
        padding: 0 !important;
    }
}
