/* ============================================
   MOBILE-FRIENDLY GLOBAL STYLES
   Ghar Say Marketplace - Responsive Design
   ============================================ */

/* Ensure all pages have proper viewport handling */
html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

body {
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   MOBILE TYPOGRAPHY
   ============================================ */

/* Scale down large headings on mobile */
@media (max-width: 640px) {
    h1 {
        font-size: 1.875rem !important; /* 30px */
        line-height: 1.2;
    }

    h2 {
        font-size: 1.5rem !important; /* 24px */
        line-height: 1.3;
    }

    h3 {
        font-size: 1.25rem !important; /* 20px */
        line-height: 1.4;
    }

    .display-1,
    .display-2,
    .display-3 {
        font-size: 2.5rem !important; /* 40px */
    }

    .display-4,
    .display-5 {
        font-size: 2rem !important; /* 32px */
    }
}

/* ============================================
   MOBILE BUTTONS & INPUTS
   ============================================ */

@media (max-width: 640px) {
    /* Make buttons easier to tap */
    .btn,
    button,
    input[type="button"],
    input[type="submit"] {
        min-height: 44px; /* iOS minimum tap target */
        padding: 0.75rem 1.5rem;
        font-size: 1rem;
    }

    /* Full width buttons on mobile */
    .btn-block-mobile {
        width: 100%;
        display: block;
    }

    /* Input fields */
    input,
    textarea,
    select {
        font-size: 16px !important; /* Prevents iOS zoom on focus */
        min-height: 44px;
    }

    /* Dropdown selects */
    select {
        padding: 0.625rem 0.75rem;
    }
}

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

@media (max-width: 768px) {
    /* Navbar adjustments */
    .navbar-brand {
        font-size: 1.25rem !important;
    }

    .navbar-nav {
        padding: 1rem 0;
    }

    .navbar-nav .nav-link {
        padding: 0.75rem 1rem;
        font-size: 1rem;
    }

    /* Hamburger menu spacing */
    .navbar-toggler {
        padding: 0.5rem 0.75rem;
        font-size: 1.25rem;
    }
}

/* ============================================
   MOBILE TABLES
   ============================================ */

@media (max-width: 768px) {
    /* Make tables scrollable */
    .table-responsive {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Stack table rows on mobile */
    .table-mobile-stack {
        thead {
            display: none;
        }

        tr {
            display: block;
            margin-bottom: 1rem;
            border: 1px solid #dee2e6;
            border-radius: 0.375rem;
        }

        td {
            display: block;
            text-align: right;
            padding: 0.75rem;
            border: none;
            border-bottom: 1px solid #dee2e6;
        }

        td:last-child {
            border-bottom: none;
        }

        td::before {
            content: attr(data-label);
            float: left;
            font-weight: 600;
        }
    }
}

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

@media (max-width: 768px) {
    .card {
        margin-bottom: 1rem;
    }

    .card-body {
        padding: 1rem;
    }

    .card-title {
        font-size: 1.125rem;
    }

    /* Product cards */
    .product-card {
        min-height: auto;
    }

    .product-card img {
        max-height: 200px;
        object-fit: cover;
    }
}

/* ============================================
   MOBILE MODALS
   ============================================ */

@media (max-width: 640px) {
    .modal-dialog {
        margin: 0.5rem;
    }

    .modal-content {
        border-radius: 0.5rem;
    }

    .modal-header,
    .modal-footer {
        padding: 1rem;
    }

    .modal-body {
        padding: 1rem;
        max-height: calc(100vh - 200px);
        overflow-y: auto;
    }
}

/* ============================================
   MOBILE FORMS
   ============================================ */

@media (max-width: 640px) {
    /* Stack form groups */
    .form-row,
    .row {
        margin-left: 0;
        margin-right: 0;
    }

    .form-group {
        margin-bottom: 1rem;
    }

    /* File upload areas */
    .file-upload-area {
        min-height: 150px;
        padding: 1rem;
    }

    /* Checkbox and radio spacing */
    .form-check {
        padding: 0.75rem;
        margin-bottom: 0.5rem;
    }

    /* Help text */
    .form-text,
    .text-muted {
        font-size: 0.875rem;
    }
}

/* ============================================
   MOBILE SPACING
   ============================================ */

@media (max-width: 640px) {
    /* Reduce padding on containers */
    .container,
    .container-fluid {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    /* Section spacing */
    section {
        padding: 2rem 0;
    }

    /* Reduce margins */
    .my-5 {
        margin-top: 2rem !important;
        margin-bottom: 2rem !important;
    }

    .py-5 {
        padding-top: 2rem !important;
        padding-bottom: 2rem !important;
    }
}

/* ============================================
   MOBILE IMAGES
   ============================================ */

@media (max-width: 768px) {
    img {
        max-width: 100%;
        height: auto;
    }

    /* Product images */
    .product-image {
        max-height: 250px;
        object-fit: cover;
        width: 100%;
    }

    /* Avatar images */
    .avatar {
        width: 60px;
        height: 60px;
    }

    /* Hero images */
    .hero-image {
        max-height: 300px;
        object-fit: cover;
    }
}

/* ============================================
   MOBILE GRID ADJUSTMENTS
   ============================================ */

@media (max-width: 768px) {
    /* Force single column on mobile */
    .mobile-single-column {
        flex: 0 0 100%;
        max-width: 100%;
    }

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

@media (max-width: 480px) {
    .product-grid {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   MOBILE ALERTS & NOTIFICATIONS
   ============================================ */

@media (max-width: 640px) {
    .alert {
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
        border-radius: 0.375rem;
    }

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

    /* Toast notifications */
    .toast {
        max-width: calc(100vw - 2rem);
        font-size: 0.875rem;
    }
}

/* ============================================
   MOBILE HEADER FIXES
   ============================================ */

@media (max-width: 768px) {
    /* Fixed header adjustments */
    .fixed-top + * {
        padding-top: 60px;
    }

    /* Header actions */
    .header-actions {
        flex-direction: column;
        align-items: stretch !important;
    }

    .header-actions > * {
        margin-bottom: 0.5rem;
    }
}

/* ============================================
   MOBILE DASHBOARD
   ============================================ */

@media (max-width: 768px) {
    /* Dashboard widgets */
    .dashboard-widget {
        margin-bottom: 1rem;
    }

    .dashboard-stat {
        padding: 1rem;
    }

    .dashboard-stat-value {
        font-size: 1.5rem;
    }

    /* Sidebar */
    .sidebar {
        position: fixed;
        top: 0;
        left: -100%;
        width: 280px;
        height: 100vh;
        transition: left 0.3s ease;
        z-index: 1050;
    }

    .sidebar.show {
        left: 0;
    }

    /* Main content with sidebar */
    .main-content {
        margin-left: 0 !important;
    }
}

/* ============================================
   MOBILE FOOTER
   ============================================ */

@media (max-width: 768px) {
    footer {
        text-align: center;
        padding: 2rem 1rem;
    }

    footer .row > div {
        margin-bottom: 1.5rem;
    }

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

/* ============================================
   TOUCH-FRIENDLY INTERACTIONS
   ============================================ */

@media (hover: none) and (pointer: coarse) {
    /* Remove hover states on touch devices */
    a:hover,
    button:hover,
    .btn:hover {
        opacity: 1;
        transform: none;
    }

    /* Increase tap target size */
    a,
    button,
    .btn,
    input,
    select {
        min-height: 44px;
        min-width: 44px;
    }

    /* Add active states for touch feedback */
    a:active,
    button:active,
    .btn:active {
        opacity: 0.8;
    }
}

/* ============================================
   MOBILE ACCESSIBILITY
   ============================================ */

/* Ensure focus is visible on mobile */
@media (max-width: 768px) {
    *:focus {
        outline: 2px solid #667eea;
        outline-offset: 2px;
    }

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

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

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

/* Reduce animations on mobile for better performance */
@media (max-width: 768px) and (prefers-reduced-motion: no-preference) {
    * {
        animation-duration: 0.3s !important;
        transition-duration: 0.3s !important;
    }
}

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

/* ============================================
   MOBILE-SPECIFIC UTILITIES
   ============================================ */

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

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

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

    .show-mobile-inline {
        display: inline !important;
    }

    .show-mobile-flex {
        display: flex !important;
    }
}

/* Mobile text alignment */
@media (max-width: 768px) {
    .text-mobile-center {
        text-align: center !important;
    }

    .text-mobile-left {
        text-align: left !important;
    }
}

/* ============================================
   SPECIFIC COMPONENT FIXES
   ============================================ */

/* Product listing mobile */
@media (max-width: 768px) {
    .product-listing {
        padding: 0.75rem;
    }

    .product-listing-image {
        max-width: 100px;
        height: 100px;
        object-fit: cover;
        border-radius: 0.5rem;
    }

    .product-listing-title {
        font-size: 1rem;
        font-weight: 600;
    }

    .product-listing-price {
        font-size: 1.125rem;
        font-weight: 700;
        color: #667eea;
    }
}

/* Shopping cart mobile */
@media (max-width: 768px) {
    .cart-item {
        flex-direction: column;
        align-items: flex-start !important;
        padding: 1rem;
    }

    .cart-item-image {
        max-width: 100%;
        margin-bottom: 0.75rem;
    }

    .cart-item-actions {
        width: 100%;
        display: flex;
        justify-content: space-between;
        margin-top: 0.75rem;
    }
}

/* Order summary mobile */
@media (max-width: 768px) {
    .order-summary {
        position: static;
        margin-top: 1.5rem;
    }

    .order-summary-sticky {
        position: static !important;
    }
}

/* Profile page mobile */
@media (max-width: 768px) {
    .profile-header {
        flex-direction: column;
        text-align: center;
    }

    .profile-avatar {
        margin: 0 auto 1rem;
    }

    .profile-tabs {
        flex-direction: column;
    }

    .profile-tabs .nav-link {
        width: 100%;
        text-align: left;
    }
}

/* ============================================
   PRINT STYLES (Mobile-friendly printing)
   ============================================ */

@media print {
    /* Hide unnecessary elements */
    .navbar,
    .sidebar,
    .btn,
    footer,
    .ad-banner,
    .alert {
        display: none !important;
    }

    /* Optimize page breaks */
    .card,
    .product,
    .order-item {
        page-break-inside: avoid;
    }

    /* Ensure readable text */
    body {
        font-size: 12pt;
        color: #000;
        background: #fff;
    }

    a[href]:after {
        content: " (" attr(href) ")";
    }
}

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

@media (max-width: 768px) and (orientation: landscape) {
    /* Reduce hero section height in landscape */
    .hero-section {
        padding: 40px 0;
        min-height: auto;
    }

    /* Adjust modal height */
    .modal-body {
        max-height: calc(100vh - 150px);
    }
}

/* ============================================
   VERY SMALL DEVICES (< 375px)
   ============================================ */

@media (max-width: 374px) {
    body {
        font-size: 14px;
    }

    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.875rem;
    }

    .card-body {
        padding: 0.75rem;
    }

    .container {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
}
