/* PWA Mobile Enhancements for BizMaster */

/* Mobile-first responsive design */
@media (max-width: 768px) {
    /* Enhanced touch targets */
    .btn, .nav-link, .dropdown-item, .form-control, .form-select {
        min-height: 44px;
        padding: 12px 16px;
    }
    
    /* Better mobile navigation */
    .navbar-nav .nav-link {
        padding: 16px 20px;
        font-size: 1.1rem;
        border-bottom: 1px solid rgba(0,0,0,0.1);
    }
    
    /* Mobile-optimized sidebar */
    .sidebar {
        position: fixed;
        top: 0;
        left: -280px;
        width: 280px;
        height: 100vh;
        z-index: 1050;
        transition: left 0.3s ease-in-out;
        background: #fff;
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .sidebar.show {
        left: 0;
    }
    
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0,0,0,0.5);
        z-index: 1040;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
    }
    
    .sidebar-overlay.show {
        opacity: 1;
        visibility: visible;
    }
    
    /* Mobile header with hamburger */
    .mobile-header {
        background: #0d6efd;
        color: white;
        padding: 12px 16px;
        position: sticky;
        top: 0;
        z-index: 1030;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
    
    .mobile-menu-toggle {
        background: none;
        border: none;
        color: white;
        font-size: 1.5rem;
        padding: 8px;
        cursor: pointer;
    }
    
    .mobile-brand {
        font-size: 1.25rem;
        font-weight: 600;
        margin: 0;
    }
    
    /* Touch-friendly cards */
    .card {
        margin-bottom: 16px;
        border-radius: 12px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    }
    
    .card-header {
        padding: 16px 20px;
        background: #f8f9fa;
        border-bottom: 1px solid #dee2e6;
    }
    
    .card-body {
        padding: 20px;
    }
    
    /* Mobile forms */
    .form-group {
        margin-bottom: 20px;
    }
    
    .form-label {
        font-weight: 600;
        margin-bottom: 8px;
        color: #495057;
    }
    
    .form-control, .form-select {
        border-radius: 8px;
        border: 2px solid #dee2e6;
        font-size: 16px; /* Prevents zoom on iOS */
        transition: border-color 0.3s ease;
    }
    
    .form-control:focus, .form-select:focus {
        border-color: #0d6efd;
        box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25);
    }
    
    /* Mobile tables */
    .table-responsive {
        border-radius: 8px;
        overflow: hidden;
    }
    
    .table {
        font-size: 0.9rem;
    }
    
    .table th,
    .table td {
        padding: 12px 8px;
        vertical-align: middle;
    }
    
    /* Stack table on very small screens */
    @media (max-width: 480px) {
        .table-mobile-stack {
            display: block;
        }
        
        .table-mobile-stack thead {
            display: none;
        }
        
        .table-mobile-stack tbody,
        .table-mobile-stack tr,
        .table-mobile-stack td {
            display: block;
            width: 100%;
        }
        
        .table-mobile-stack tr {
            background: white;
            border: 1px solid #dee2e6;
            border-radius: 8px;
            margin-bottom: 12px;
            padding: 12px;
        }
        
        .table-mobile-stack td {
            border: none;
            padding: 8px 0;
            position: relative;
            padding-left: 40%;
        }
        
        .table-mobile-stack td:before {
            content: attr(data-label) ": ";
            position: absolute;
            left: 0;
            width: 35%;
            font-weight: 600;
            color: #495057;
        }
        
        /* Better action buttons in mobile tables */
        .table-mobile-stack .btn {
            min-width: 44px;
            min-height: 44px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            margin: 2px;
        }
        
        /* Improved mobile form layouts */
        .row.g-3 {
            gap: 16px !important;
        }
        
        .col-md-4, .col-md-3, .col-md-6, .col-lg-4, .col-lg-6, .col-lg-8, .col-xl-3 {
            width: 100% !important;
            flex: none !important;
        }
        
        /* Better mobile cards */
        .card {
            margin-bottom: 16px;
            border-radius: 12px;
        }
        
        .card-header {
            border-radius: 12px 12px 0 0 !important;
            padding: 16px 20px;
        }
        
        .card-body {
            padding: 20px;
        }
        
        /* Mobile breadcrumbs */
        .breadcrumb {
            background: none;
            padding: 0;
            margin-bottom: 16px;
            font-size: 0.9rem;
            flex-wrap: wrap;
        }
        
        .breadcrumb-item + .breadcrumb-item::before {
            padding: 0 0.3rem;
        }
    }
    
    /* Mobile modals */
    .modal-dialog {
        margin: 10px;
        max-width: calc(100% - 20px);
    }
    
    .modal-content {
        border-radius: 12px;
        border: none;
        box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    }
    
    .modal-header {
        padding: 20px;
        border-bottom: 1px solid #dee2e6;
    }
    
    .modal-body {
        padding: 20px;
    }
    
    .modal-footer {
        padding: 20px;
        border-top: 1px solid #dee2e6;
    }
    
    /* Mobile buttons */
    .btn {
        border-radius: 8px;
        font-weight: 500;
        padding: 12px 20px;
        transition: all 0.3s ease;
    }
    
    .btn-primary {
        background: #0d6efd;
        border: none;
    }
    
    .btn-primary:hover {
        background: #0b5ed7;
        transform: translateY(-1px);
    }
    
    /* Mobile spacing utilities */
    .mb-mobile {
        margin-bottom: 20px !important;
    }
    
    .mt-mobile {
        margin-top: 20px !important;
    }
    
    .p-mobile {
        padding: 20px !important;
    }
    
    /* Mobile-specific components */
    .mobile-fab {
        position: fixed;
        bottom: 20px;
        right: 20px;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        background: #0d6efd;
        color: white;
        border: none;
        font-size: 1.5rem;
        box-shadow: 0 4px 12px rgba(13, 110, 253, 0.3);
        z-index: 1000;
        transition: all 0.3s ease;
    }
    
    .mobile-fab:hover {
        background: #0b5ed7;
        transform: scale(1.1);
    }
    
    .mobile-stats-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 12px;
        margin-bottom: 20px;
    }
    
    .mobile-stat-card {
        background: white;
        border: 1px solid #dee2e6;
        border-radius: 12px;
        padding: 16px;
        text-align: center;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
    
    .mobile-stat-value {
        font-size: 1.5rem;
        font-weight: 700;
        color: #0d6efd;
        margin-bottom: 4px;
    }
    
    .mobile-stat-label {
        font-size: 0.85rem;
        color: #6c757d;
    }
    
    /* PWA-specific mobile styles */
    .pwa-install-banner {
        background: linear-gradient(135deg, #0d6efd, #6610f2);
        color: white;
        padding: 16px;
        margin: -15px -15px 20px -15px;
        border-radius: 0 0 12px 12px;
        text-align: center;
        position: relative;
    }
    
    .pwa-install-banner .btn {
        background: rgba(255,255,255,0.2);
        border: 1px solid rgba(255,255,255,0.3);
        color: white;
        margin-top: 12px;
    }
    
    .pwa-install-banner .btn:hover {
        background: rgba(255,255,255,0.3);
    }
    
    /* Offline indicator */
    .offline-indicator {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        background: #ffc107;
        color: #000;
        padding: 8px;
        text-align: center;
        z-index: 1060;
        font-size: 0.9rem;
        transform: translateY(-100%);
        transition: transform 0.3s ease;
    }
    
    .offline-indicator.show {
        transform: translateY(0);
    }
    
    /* Loading states for mobile */
    .mobile-loading {
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 40px;
        color: #6c757d;
    }
    
    .mobile-loading-spinner {
        width: 24px;
        height: 24px;
        border: 2px solid #e9ecef;
        border-top: 2px solid #0d6efd;
        border-radius: 50%;
        animation: spin 1s linear infinite;
        margin-right: 12px;
    }
    
    @keyframes spin {
        0% { transform: rotate(0deg); }
        100% { transform: rotate(360deg); }
    }
    
    /* Safe area adjustments for PWA */
    .safe-area-top {
        padding-top: env(safe-area-inset-top);
    }
    
    .safe-area-bottom {
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    /* Swipe gestures indicators */
    .swipe-indicator {
        position: relative;
        overflow: hidden;
    }
    
    .swipe-indicator::after {
        content: "";
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        height: 3px;
        background: linear-gradient(90deg, #0d6efd, #6610f2);
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    
    .swipe-indicator.swiping::after {
        transform: translateX(0);
    }
}

/* Tablet optimizations */
@media (min-width: 769px) and (max-width: 1024px) {
    .main-content {
        padding: 20px;
    }
    
    .container-fluid {
        padding-left: 30px;
        padding-right: 30px;
    }
    
    .card {
        margin-bottom: 24px;
    }
    
    .btn {
        padding: 10px 16px;
    }
}

/* High DPI display optimizations */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .card {
        box-shadow: 0 1px 4px rgba(0,0,0,0.1);
    }
    
    .btn {
        box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    }
}

/* Dark mode support for PWA */
@media (prefers-color-scheme: dark) {
    .sidebar {
        background: #1a1a1a;
        color: #ffffff;
    }
    
    .mobile-header {
        background: #1a1a1a;
    }
    
    .card {
        background: #2d2d2d;
        border-color: #404040;
        color: #ffffff;
    }
    
    .form-control, .form-select {
        background: #2d2d2d;
        border-color: #404040;
        color: #ffffff;
    }
    
    .mobile-stat-card {
        background: #2d2d2d;
        border-color: #404040;
        color: #ffffff;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .sidebar,
    .sidebar-overlay,
    .btn,
    .card,
    .form-control,
    .form-select {
        transition: none;
    }
    
    .mobile-loading-spinner {
        animation: none;
    }
}
