/**
 * Mobile & Tablet Responsive Enhancements
 * Comprehensive mobile-first responsive design
 * Import this file after main CSS files for optimal mobile experience
 */

/* ============================================
   MOBILE BREAKPOINTS
   ============================================
   - Mobile: 320px - 767px
   - Tablet: 768px - 1024px
   - Desktop: 1025px+
   ============================================ */

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

/* Ensure all interactive elements are at least 44x44px (Apple guidelines) */
@media (max-width: 1024px) {
    .btn,
    .modern-btn,
    button,
    a.btn,
    a.modern-btn,
    input[type="submit"],
    input[type="button"] {
        min-height: 44px;
        min-width: 44px;
        padding: 0.75rem 1.25rem;
        font-size: 1rem;
    }

    .btn-sm,
    .modern-btn-sm {
        min-height: 40px;
        padding: 0.625rem 1rem;
        font-size: 0.9375rem;
    }

    /* Icon buttons */
    .btn-icon,
    .icon-button,
    button.icon-only {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Form inputs */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="url"],
    input[type="search"],
    select,
    textarea,
    .form-control,
    .modern-form-input,
    .modern-form-select {
        min-height: 48px;
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 0.875rem 1rem;
    }

    /* Checkboxes and radios */
    input[type="checkbox"],
    input[type="radio"] {
        min-width: 24px;
        min-height: 24px;
        margin-right: 0.5rem;
    }
}

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

@media (max-width: 768px) {
    /* Hide desktop nav, show mobile menu toggle */
    .nav-menu:not(.mobile-nav-menu) {
        position: fixed;
        top: 60px;
        left: -100%;
        right: 0;
        bottom: 0;
        background: var(--color-bg-primary, #ffffff);
        flex-direction: column;
        padding: 1.5rem;
        transition: left 0.3s ease;
        overflow-y: auto;
        z-index: 999;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
        max-width: 280px;
    }

    .nav-menu.active {
        left: 0;
    }

    /* Mobile menu overlay */
    .mobile-menu-overlay {
        display: none;
        position: fixed;
        top: 60px;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 998;
    }

    .mobile-menu-overlay.active {
        display: block;
    }

    /* Mobile menu items */
    .nav-menu li {
        margin: 0;
        width: 100%;
    }

    .nav-link,
    .modern-nav-link {
        display: block;
        padding: 1rem;
        width: 100%;
        border-radius: 0.5rem;
        margin-bottom: 0.25rem;
    }

    /* Hamburger menu button */
    .mobile-menu-toggle {
        display: flex !important;
        align-items: center;
        justify-content: center;
        min-width: 44px;
        min-height: 44px;
        background: none;
        border: none;
        cursor: pointer;
        font-size: 1.5rem;
        color: var(--color-text-primary, #000);
    }
}

/* ============================================
   RESPONSIVE GRID SYSTEM
   ============================================ */

@media (max-width: 1024px) {
    .modern-grid-4,
    .modern-grid-3 {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }
}

@media (max-width: 768px) {
    /* All grids become single column on mobile */
    .modern-grid,
    .modern-grid-2,
    .modern-grid-3,
    .modern-grid-4,
    .listing-grid,
    .listings-grid,
    .category-grid,
    .stats-grid,
    .packages-container {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    /* Flexbox columns */
    .row {
        flex-direction: column;
    }

    [class*='col-'] {
        flex: 0 0 100%;
        max-width: 100%;
        margin-bottom: 1rem;
    }
}

/* ============================================
   RESPONSIVE TABLES
   ============================================ */

@media (max-width: 768px) {
    /* Card-style tables for mobile */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table {
        font-size: 0.875rem;
    }

    .table thead {
        display: none;
    }

    .table,
    .table tbody,
    .table tr,
    .table td {
        display: block;
        width: 100%;
    }

    .table tr {
        margin-bottom: 1rem;
        background: var(--color-bg-secondary, #f8f9fa);
        border: 1px solid var(--color-border, #e0e0e0);
        border-radius: 0.5rem;
        padding: 1rem;
    }

    .table td {
        text-align: right;
        padding: 0.5rem 0;
        border: none;
        position: relative;
        padding-left: 50%;
    }

    .table td::before {
        content: attr(data-label);
        position: absolute;
        left: 0;
        width: 45%;
        padding-right: 10px;
        text-align: left;
        font-weight: 600;
        color: var(--color-text-secondary, #666);
    }

    /* Alternative: Horizontal scroll for complex tables */
    .table-scroll-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -1rem;
        padding: 0 1rem;
    }

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

/* ============================================
   RESPONSIVE CARDS
   ============================================ */

@media (max-width: 768px) {
    .card,
    .modern-card,
    .listing-card,
    .stat-card,
    .stats-card {
        margin-bottom: 1rem;
    }

    .card-header,
    .modern-card-header {
        padding: 1rem;
    }

    .card-body,
    .modern-card-body,
    .listing-content {
        padding: 1rem;
    }

    .card-footer,
    .modern-card-footer {
        padding: 1rem;
        flex-direction: column;
        gap: 0.75rem;
    }

    .card-footer .btn,
    .modern-card-footer .modern-btn {
        width: 100%;
    }
}

/* ============================================
   RESPONSIVE MODALS
   ============================================ */

@media (max-width: 768px) {
    .modal-content {
        width: 95%;
        max-width: none;
        margin: 1rem;
        max-height: 90vh;
    }

    .modal-header {
        padding: 1rem;
    }

    .modal-title {
        font-size: 1.25rem;
    }

    .modal-body {
        padding: 1rem;
    }

    .modal-footer {
        padding: 1rem;
        flex-direction: column-reverse;
    }

    .modal-footer .btn,
    .modal-footer .modern-btn {
        width: 100%;
    }
}

/* ============================================
   RESPONSIVE FORMS
   ============================================ */

@media (max-width: 768px) {
    .form-group,
    .modern-form-group {
        margin-bottom: 1.25rem;
    }

    /* Stack form labels and inputs */
    .form-inline,
    .form-row {
        flex-direction: column;
    }

    .form-inline .form-group {
        width: 100%;
        margin-bottom: 1rem;
    }

    /* Full-width buttons in forms */
    form .btn,
    form .modern-btn {
        width: 100%;
        margin-top: 0.5rem;
    }

    form .btn-group {
        flex-direction: column;
        width: 100%;
    }

    form .btn-group .btn {
        width: 100%;
        border-radius: 0.5rem;
        margin-bottom: 0.5rem;
    }

    /* File upload areas */
    .file-upload-area {
        padding: 2rem 1rem;
    }
}

/* ============================================
   RESPONSIVE TYPOGRAPHY
   ============================================ */

@media (max-width: 768px) {
    html {
        font-size: 14px;
    }

    h1 {
        font-size: 1.75rem;
    }

    h2 {
        font-size: 1.5rem;
    }

    h3 {
        font-size: 1.25rem;
    }

    h4 {
        font-size: 1.125rem;
    }

    h5, h6 {
        font-size: 1rem;
    }

    .hero h1 {
        font-size: 2rem;
        line-height: 1.2;
    }

    .hero p {
        font-size: 1rem;
    }

    /* Smaller stat values on mobile */
    .stat-value,
    .stats-card-value {
        font-size: 1.75rem;
    }

    /* Package pricing */
    .package-price {
        font-size: 1.5rem;
    }

    .package-type {
        font-size: 1.125rem;
    }
}

/* ============================================
   RESPONSIVE SPACING
   ============================================ */

@media (max-width: 768px) {
    .container,
    .container-fluid {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .section {
        padding-top: 2rem;
        padding-bottom: 2rem;
    }

    /* Reduce padding in various components */
    .header {
        padding: 0.75rem 0;
    }

    .navbar {
        padding: 0.5rem 0;
    }

    /* Dashboard spacing */
    .dashboard-header {
        padding: 1rem 0;
        margin-bottom: 1.5rem;
    }

    .dashboard-section {
        margin-bottom: 2rem;
    }
}

/* ============================================
   DASHBOARD RESPONSIVE ENHANCEMENTS
   ============================================ */

@media (max-width: 768px) {
    /* Stats cards */
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .stat-card,
    .stats-card {
        padding: 1.25rem;
    }

    /* Charts */
    .chart-container {
        position: relative;
        height: 250px;
        width: 100%;
    }

    /* Seller dashboard improvements */
    .seller-dashboard-stats {
        flex-direction: column;
    }

    .seller-stat-card {
        width: 100%;
    }

    /* Performance metrics */
    .performance-grid {
        grid-template-columns: 1fr;
    }

    /* Quick actions */
    .quick-actions {
        flex-direction: column;
    }

    .quick-action-btn {
        width: 100%;
    }
}

/* ============================================
   LISTING PAGES RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
    /* Filters sidebar */
    .filters-sidebar {
        position: fixed;
        top: 0;
        left: -100%;
        bottom: 0;
        width: 85%;
        max-width: 320px;
        background: var(--color-bg-primary, #fff);
        z-index: 1000;
        transition: left 0.3s ease;
        overflow-y: auto;
        padding: 1.5rem;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    }

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

    .filters-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }

    .filters-overlay.active {
        display: block;
    }

    /* Mobile filter toggle button */
    .mobile-filters-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        width: 100%;
        margin-bottom: 1rem;
        padding: 0.875rem;
        background: var(--color-primary, #3b82f6);
        color: white;
        border: none;
        border-radius: 0.5rem;
        font-size: 1rem;
        font-weight: 600;
        cursor: pointer;
    }

    /* Listing cards */
    .listing-card {
        margin-bottom: 1rem;
    }

    .listing-image {
        height: 180px;
    }

    /* Package tabs - horizontal scroll */
    .package-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
        margin: 0 -1rem;
        padding: 0 1rem;
    }

    .package-tab {
        display: inline-block;
        margin-right: 0.5rem;
    }

    /* Seller profile on listing page */
    .seller-profile-sidebar {
        margin-top: 2rem;
    }

    .seller-stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }
}

/* ============================================
   ADMIN LAYOUT RESPONSIVE
   ============================================ */

@media (max-width: 1024px) {
    .admin-layout {
        flex-direction: column;
    }

    .admin-sidebar {
        position: relative;
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--color-border, #e0e0e0);
    }

    .admin-content {
        margin-left: 0;
        padding: 1.5rem;
    }

    /* Mobile admin sidebar - collapsible */
    .admin-sidebar-toggle {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 1rem;
        background: var(--color-bg-secondary, #f8f9fa);
        cursor: pointer;
        border-bottom: 1px solid var(--color-border, #e0e0e0);
    }

    .admin-sidebar-menu {
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
    }

    .admin-sidebar-menu.active {
        max-height: 1000px;
    }
}

/* ============================================
   IMAGE GALLERIES & MEDIA
   ============================================ */

@media (max-width: 768px) {
    /* Image gallery */
    .image-gallery {
        flex-direction: column;
    }

    .gallery-main {
        width: 100%;
        height: 250px;
    }

    .gallery-thumbnails {
        flex-direction: row;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-top: 1rem;
        gap: 0.5rem;
    }

    .gallery-thumbnail {
        flex-shrink: 0;
        width: 80px;
        height: 80px;
    }

    /* Video embeds */
    .video-container {
        position: relative;
        padding-bottom: 56.25%; /* 16:9 aspect ratio */
        height: 0;
        overflow: hidden;
    }

    .video-container iframe,
    .video-container video {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
    }
}

/* ============================================
   REVIEWS & RATINGS
   ============================================ */

@media (max-width: 768px) {
    .review-summary-main {
        flex-direction: column;
        gap: 1.5rem;
    }

    .review-overall {
        width: 100%;
        text-align: center;
    }

    .review-breakdown {
        width: 100%;
    }

    .review-card {
        padding: 1rem;
    }

    .review-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
}

/* ============================================
   CHAT & MESSAGING
   ============================================ */

@media (max-width: 768px) {
    .chat-box {
        height: calc(100vh - 200px);
    }

    .chat-messages {
        padding: 1rem;
    }

    .chat-message-content {
        max-width: 85%;
        font-size: 0.9375rem;
    }

    .chat-input-box {
        padding: 1rem;
        gap: 0.5rem;
    }

    .chat-input {
        font-size: 16px; /* Prevent zoom on iOS */
    }
}

/* ============================================
   ORDER PAGES
   ============================================ */

@media (max-width: 768px) {
    .order-timeline {
        padding-left: 1.5rem;
    }

    .order-details-grid {
        grid-template-columns: 1fr;
    }

    .order-summary {
        position: relative;
        margin-top: 2rem;
    }

    .order-actions {
        flex-direction: column;
    }

    .order-action-btn {
        width: 100%;
    }
}

/* ============================================
   BREADCRUMBS
   ============================================ */

@media (max-width: 768px) {
    .breadcrumb {
        font-size: 0.8125rem;
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    .breadcrumb-item {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 150px;
    }
}

/* ============================================
   PAGINATION
   ============================================ */

@media (max-width: 768px) {
    .pagination {
        flex-wrap: wrap;
        gap: 0.25rem;
        justify-content: center;
    }

    .pagination .page-link {
        min-width: 40px;
        min-height: 40px;
        padding: 0.5rem;
    }

    /* Hide some page numbers on mobile */
    .pagination .page-item:not(.active):not(:first-child):not(:last-child):nth-child(n+4):nth-last-child(n+4) {
        display: none;
    }
}

/* ============================================
   DROPDOWNS
   ============================================ */

@media (max-width: 768px) {
    .dropdown-menu {
        position: fixed;
        left: 1rem;
        right: 1rem;
        top: auto;
        bottom: 1rem;
        min-width: auto;
        max-height: 60vh;
        overflow-y: auto;
    }
}

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

@media (max-width: 768px) {
    /* Increase tap target size for accessibility */
    a,
    button,
    [role="button"],
    [tabindex]:not([tabindex="-1"]) {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }

    /* Focus states more visible on mobile */
    *:focus {
        outline: 2px solid var(--color-primary, #3b82f6);
        outline-offset: 2px;
    }

    /* Skip to content link for screen readers */
    .skip-to-content {
        position: absolute;
        top: -40px;
        left: 0;
        background: var(--color-primary, #3b82f6);
        color: white;
        padding: 0.5rem 1rem;
        text-decoration: none;
        z-index: 100;
    }

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

/* ============================================
   TABLET-SPECIFIC OPTIMIZATIONS (768px - 1024px)
   ============================================ */

@media (min-width: 769px) and (max-width: 1024px) {
    .modern-grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .packages-container {
        grid-template-columns: repeat(2, 1fr);
    }

    .listing-grid,
    .listings-grid {
        grid-template-columns: repeat(2, 1fr);
    }

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

/* ============================================
   LANDSCAPE MOBILE OPTIMIZATIONS
   ============================================ */

@media (max-width: 896px) and (orientation: landscape) {
    .modal-content {
        max-height: 85vh;
        overflow-y: auto;
    }

    .chat-box {
        height: 70vh;
    }

    .hero {
        padding: 1.5rem 0;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    .header,
    .footer,
    .navbar,
    .sidebar,
    .admin-sidebar,
    .mobile-menu-toggle,
    .filters-sidebar,
    .btn,
    .modern-btn,
    button {
        display: none !important;
    }

    body {
        font-size: 12pt;
        color: #000;
        background: #fff;
    }

    .container {
        max-width: 100%;
    }

    .admin-content {
        margin-left: 0;
    }
}

/* ============================================
   UTILITY CLASSES FOR RESPONSIVE
   ============================================ */

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

@media (min-width: 769px) {
    .hide-mobile {
        display: initial;
    }
}

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

@media (min-width: 769px) {
    .show-mobile {
        display: none;
    }
}

/* Hide on tablet */
@media (min-width: 769px) and (max-width: 1024px) {
    .hide-tablet {
        display: none;
    }
}

/* Show only on tablet */
@media (min-width: 769px) and (max-width: 1024px) {
    .show-tablet-only {
        display: initial;
    }
}

@media (max-width: 768px), (min-width: 1025px) {
    .show-tablet-only {
        display: none;
    }
}

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

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

/* Responsive flex direction */
@media (max-width: 768px) {
    .flex-column-mobile {
        flex-direction: column;
    }

    .flex-row-mobile {
        flex-direction: row;
    }
}

/* Full width on mobile */
@media (max-width: 768px) {
    .w-full-mobile {
        width: 100% !important;
    }
}
