/**
 * Mobile-First Responsive Styles
 * 
 * This file contains comprehensive mobile optimizations for the entire site.
 * Include this file in all pages after the main CSS files.
 * 
 * @version 1.0
 * @date 2026-02-08
 */

/* ==========================================
   BASE MOBILE OPTIMIZATIONS
   ========================================== */

/* Prevent horizontal scrolling on mobile */
html, body {
    overflow-x: hidden;
    max-width: 100%;
}

/* Ensure all images are responsive */
img {
    max-width: 100%;
    height: auto;
}

/* Mobile-friendly text */
@media (max-width: 767.98px) {
    body {
        font-size: 14px;
        line-height: 1.5;
    }
    
    h1 {
        font-size: 1.75rem;
    }
    
    h2 {
        font-size: 1.5rem;
    }
    
    h3 {
        font-size: 1.25rem;
    }
    
    h4 {
        font-size: 1.1rem;
    }
    
    h5 {
        font-size: 1rem;
    }
    
    h6 {
        font-size: 0.9rem;
    }
}

/* ==========================================
   HEADER & NAVIGATION (Mobile)
   ========================================== */

@media (max-width: 991.98px) {
    /* Make header sticky with reduced height */
    .header {
        position: sticky;
        top: 0;
        z-index: 1030;
    }
    
    /* Top bar optimizations */
    .top-bar {
        font-size: 0.8rem;
        padding: 5px 0;
    }
    
    /* Navbar */
    .navbar {
        padding: 0.5rem 0;
    }
    
    .navbar-brand {
        font-size: 1.3rem;
    }
    
    /* Mobile menu */
    .navbar-collapse {
        background-color: white;
        padding: 1rem;
        border-radius: 0.5rem;
        margin-top: 0.5rem;
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    }
    
    .navbar-nav {
        margin-bottom: 1rem;
    }
    
    .nav-link {
        padding: 0.75rem 1rem;
        border-bottom: 1px solid #f0f0f0;
    }
    
    .nav-link:last-child {
        border-bottom: none;
    }
    
    /* Dropdown menus */
    .dropdown-menu {
        border: none;
        box-shadow: none;
        padding-left: 1rem;
    }
    
    /* Search box in mobile menu */
    .search-wrapper {
        margin: 1rem 0;
        max-width: 100%;
    }
    
    /* Cart and user buttons */
    .header .d-flex {
        flex-wrap: wrap;
        gap: 0.5rem;
        margin-top: 1rem;
        padding-top: 1rem;
        border-top: 1px solid #f0f0f0;
    }
    
    .header .btn {
        flex: 1;
        min-width: 45%;
    }
}

/* ==========================================
   TABLES (Mobile)
   ========================================== */

@media (max-width: 767.98px) {
    /* Make tables scrollable */
    .table-responsive {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Better table styling on mobile */
    table {
        font-size: 0.85rem;
    }
    
    table thead {
        display: none;
    }
    
    table tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid #dee2e6;
        border-radius: 0.5rem;
        padding: 1rem;
    }
    
    table td {
        display: block;
        text-align: right;
        padding: 0.5rem !important;
        border: none;
    }
    
    table td::before {
        content: attr(data-label);
        float: left;
        font-weight: 600;
        color: #333;
    }
}

/* ==========================================
   FORMS (Mobile)
   ========================================== */

@media (max-width: 767.98px) {
    /* Better form inputs on mobile */
    .form-control,
    .form-select,
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    select,
    textarea {
        font-size: 16px !important; /* Prevents iOS auto-zoom */
        padding: 0.75rem;
    }
    
    .input-group-text {
        font-size: 16px !important;
    }
    
    /* Form labels */
    label {
        font-size: 0.9rem;
        margin-bottom: 0.5rem;
    }
    
    /* Buttons */
    .btn {
        padding: 0.75rem 1.25rem;
        font-size: 0.95rem;
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    .btn-sm {
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
    }
    
    .btn-lg {
        padding: 1rem 1.5rem;
        font-size: 1.1rem;
    }
    
    /* Button groups */
    .btn-group {
        display: flex;
        flex-direction: column;
    }
    
    .btn-group > .btn {
        border-radius: 0.375rem !important;
        margin-bottom: 0.5rem;
    }
    
    /* Form validation messages */
    .invalid-feedback,
    .valid-feedback {
        font-size: 0.85rem;
    }
}

/* ==========================================
   CARDS (Mobile)
   ========================================== */

@media (max-width: 767.98px) {
    .card {
        margin-bottom: 1rem;
    }
    
    .card-body {
        padding: 1rem;
    }
    
    .card-title {
        font-size: 1.1rem;
    }
    
    .card-text {
        font-size: 0.9rem;
    }
}

/* ==========================================
   MODALS (Mobile)
   ========================================== */

@media (max-width: 767.98px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    
    .modal-content {
        border-radius: 0.5rem;
    }
    
    .modal-header {
        padding: 1rem;
    }
    
    .modal-body {
        padding: 1rem;
    }
    
    .modal-footer {
        padding: 0.75rem;
        flex-direction: column;
    }
    
    .modal-footer .btn {
        width: 100%;
        margin: 0.25rem 0;
    }
}

/* ==========================================
   ALERTS & TOASTS (Mobile)
   ========================================== */

@media (max-width: 767.98px) {
    .alert {
        font-size: 0.9rem;
        padding: 0.75rem;
        margin-bottom: 1rem;
    }
    
    .toast {
        font-size: 0.9rem;
        max-width: calc(100% - 2rem);
    }
}

/* ==========================================
   BREADCRUMBS (Mobile)
   ========================================== */

@media (max-width: 767.98px) {
    .breadcrumb {
        font-size: 0.85rem;
        padding: 0.5rem 0;
        flex-wrap: wrap;
    }
    
    .breadcrumb-item + .breadcrumb-item::before {
        padding: 0 0.3rem;
    }
}

/* ==========================================
   PAGINATION (Mobile)
   ========================================== */

@media (max-width: 767.98px) {
    .pagination {
        font-size: 0.9rem;
    }
    
    .page-item {
        margin: 0 0.2rem;
    }
    
    .page-link {
        padding: 0.5rem 0.75rem;
    }
    
    /* Hide some pagination items on very small screens */
    .pagination .page-item:not(.active):not(.disabled):nth-child(n+6) {
        display: none;
    }
}

/* ==========================================
   CART PAGE (Mobile)
   ========================================== */

@media (max-width: 767.98px) {
    .cart-item {
        flex-direction: column;
        align-items: flex-start !important;
        padding: 1rem;
    }
    
    .cart-item-image {
        width: 100%;
        max-width: 150px;
        margin: 0 auto 1rem;
    }
    
    .cart-item-details {
        width: 100%;
        text-align: center;
    }
    
    .cart-item-quantity {
        width: 100%;
        justify-content: center;
        margin: 1rem 0;
    }
    
    .cart-item-price {
        width: 100%;
        text-align: center;
        font-size: 1.2rem;
        margin: 0.5rem 0;
    }
    
    .cart-summary {
        position: static;
        margin-top: 2rem;
    }
}

/* ==========================================
   CHECKOUT PAGE (Mobile)
   ========================================== */

@media (max-width: 767.98px) {
    .checkout-steps {
        flex-direction: column;
    }
    
    .checkout-step {
        width: 100%;
        margin-bottom: 1rem;
        text-align: center;
    }
    
    .order-summary {
        position: static;
        margin-top: 2rem;
    }
}

/* ==========================================
   PRODUCT PAGE (Mobile)
   ========================================== */

@media (max-width: 767.98px) {
    .product-gallery {
        margin-bottom: 1.5rem;
    }
    
    .product-main-image {
        height: 300px;
    }
    
    .product-thumbnails {
        margin-top: 1rem;
    }
    
    .product-thumbnail {
        width: 60px;
        height: 60px;
        margin-right: 0.5rem;
    }
    
    .product-info {
        padding: 1rem;
    }
    
    .product-price {
        font-size: 1.5rem;
        margin: 1rem 0;
    }
    
    .product-attributes {
        margin: 1rem 0;
    }
    
    .product-tabs {
        margin-top: 2rem;
    }
    
    .product-tabs .nav-tabs {
        flex-wrap: wrap;
    }
    
    .product-tabs .nav-link {
        font-size: 0.9rem;
        padding: 0.5rem 0.75rem;
    }
}

/* ==========================================
   UTILITY CLASSES (Mobile)
   ========================================== */

@media (max-width: 767.98px) {
    /* Spacing utilities */
    .mobile-mt-1 { margin-top: 0.25rem !important; }
    .mobile-mt-2 { margin-top: 0.5rem !important; }
    .mobile-mt-3 { margin-top: 1rem !important; }
    .mobile-mt-4 { margin-top: 1.5rem !important; }
    .mobile-mt-5 { margin-top: 3rem !important; }
    
    .mobile-mb-1 { margin-bottom: 0.25rem !important; }
    .mobile-mb-2 { margin-bottom: 0.5rem !important; }
    .mobile-mb-3 { margin-bottom: 1rem !important; }
    .mobile-mb-4 { margin-bottom: 1.5rem !important; }
    .mobile-mb-5 { margin-bottom: 3rem !important; }
    
    .mobile-p-1 { padding: 0.25rem !important; }
    .mobile-p-2 { padding: 0.5rem !important; }
    .mobile-p-3 { padding: 1rem !important; }
    .mobile-p-4 { padding: 1.5rem !important; }
    .mobile-p-5 { padding: 3rem !important; }
    
    /* Text alignment */
    .mobile-text-center { text-align: center !important; }
    .mobile-text-left { text-align: left !important; }
    .mobile-text-right { text-align: right !important; }
    
    /* Display utilities */
    .mobile-d-none { display: none !important; }
    .mobile-d-block { display: block !important; }
    .mobile-d-flex { display: flex !important; }
    
    /* Flex direction */
    .mobile-flex-column { flex-direction: column !important; }
    .mobile-flex-row { flex-direction: row !important; }
    
    /* Width utilities */
    .mobile-w-100 { width: 100% !important; }
    .mobile-w-auto { width: auto !important; }
}

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

/* Reduce animations on mobile for better performance */
@media (max-width: 767.98px) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    /* But keep essential transitions */
    .btn,
    .nav-link,
    .dropdown-item,
    a {
        transition-duration: 0.2s !important;
    }
}

/* ==========================================
   ACCESSIBILITY (Touch Targets)
   ========================================== */

/* Ensure all interactive elements are at least 44x44px on touch devices */
@media (hover: none) and (pointer: coarse) {
    button,
    a,
    input[type="button"],
    input[type="submit"],
    .btn,
    .nav-link {
        min-height: 44px;
        min-width: 44px;
    }
}

/* ==========================================
   FIX FOR iOS Safari
   ========================================== */

/* Prevent iOS from resizing text */
@supports (-webkit-touch-callout: none) {
    body {
        -webkit-text-size-adjust: 100%;
    }
}

/* Fix for iOS Safari bottom bar covering content */
@supports (-webkit-touch-callout: none) {
    .footer {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ==========================================
   LANDSCAPE MODE OPTIMIZATIONS
   ========================================== */

@media (max-height: 500px) and (orientation: landscape) {
    .header {
        position: relative;
    }
    
    .hero-section {
        display: none;
    }
    
    section.py-5 {
        padding-top: 1rem !important;
        padding-bottom: 1rem !important;
    }
}
