/* Mobile-First Critical Overrides - Load Last */

/* Ensure viewport scaling works properly */
html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

/* Mobile-first global styles */
@media (max-width: 768px) {
    
    /* Prevent horizontal scrolling */
    body {
        overflow-x: hidden !important;
        width: 100% !important;
    }
    
    /* Make all containers mobile-friendly */
    .container, 
    .container-fluid,
    .dashboard-container,
    .employee-container,
    .schedule-container,
    .inventory-container {
        padding-left: 8px !important;
        padding-right: 8px !important;
        margin-left: auto !important;
        margin-right: auto !important;
        max-width: 100% !important;
        width: 100% !important;
    }
    
    /* Fix common layout issues */
    .row {
        margin-left: -4px !important;
        margin-right: -4px !important;
    }
    
    .col, .col-md-6, .col-lg-6, .col-sm-6, .col-12 {
        padding-left: 4px !important;
        padding-right: 4px !important;
        margin-bottom: 16px !important;
    }
    
    /* Mobile-optimized cards */
    .card, .employee-card, .schedule-card, .franchise-card {
        margin-bottom: 16px !important;
        border-radius: 12px !important;
        border: 1px solid #e0e0e0 !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.08) !important;
    }
    
    .card-body, .card-header {
        padding: 16px !important;
    }
    
    /* Mobile form optimizations */
    .form-control, input, textarea, select {
        font-size: 16px !important; /* Prevents iOS zoom */
        padding: 12px 16px !important;
        border-radius: 8px !important;
        min-height: 48px !important;
        border: 2px solid #e0e0e0 !important;
        transition: border-color 0.2s ease !important;
    }
    
    .form-control:focus, input:focus, textarea:focus, select:focus {
        border-color: #007bff !important;
        box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1) !important;
        outline: none !important;
    }
    
    /* Touch-friendly buttons */
    .btn, button {
        min-height: 48px !important;
        padding: 12px 20px !important;
        font-size: 1em !important;
        border-radius: 8px !important;
        font-weight: 500 !important;
        transition: all 0.2s ease !important;
        border: none !important;
        cursor: pointer !important;
    }
    
    .btn-sm {
        min-height: 40px !important;
        padding: 8px 16px !important;
        font-size: 0.9em !important;
    }
    
    .btn-lg {
        min-height: 56px !important;
        padding: 16px 24px !important;
        font-size: 1.1em !important;
    }
    
    /* Better button spacing */
    .btn + .btn, .btn-group .btn {
        margin-left: 8px !important;
        margin-top: 8px !important;
    }
    
    /* Mobile-optimized modal */
    .modal-dialog {
        margin: 10px !important;
        max-width: calc(100vw - 20px) !important;
        width: calc(100vw - 20px) !important;
    }
    
    .modal-content {
        border-radius: 12px !important;
        border: none !important;
        box-shadow: 0 10px 30px rgba(0,0,0,0.2) !important;
    }
    
    .modal-header {
        padding: 20px 20px 10px 20px !important;
        border-bottom: 1px solid #e9ecef !important;
    }
    
    .modal-body {
        padding: 20px !important;
        max-height: 70vh !important;
        overflow-y: auto !important;
    }
    
    .modal-footer {
        padding: 10px 20px 20px 20px !important;
        border-top: 1px solid #e9ecef !important;
        flex-direction: column !important;
        gap: 8px !important;
    }
    
    .modal-footer .btn {
        width: 100% !important;
        margin: 0 !important;
    }
    
    /* Better text sizing */
    h1 { font-size: 1.8rem !important; line-height: 1.3 !important; }
    h2 { font-size: 1.5rem !important; line-height: 1.3 !important; }
    h3 { font-size: 1.3rem !important; line-height: 1.3 !important; }
    h4 { font-size: 1.2rem !important; line-height: 1.3 !important; }
    h5 { font-size: 1.1rem !important; line-height: 1.3 !important; }
    
    /* Better spacing */
    .mb-3, .my-3 { margin-bottom: 1.5rem !important; }
    .mt-3, .my-3 { margin-top: 1.5rem !important; }
    .mb-4, .my-4 { margin-bottom: 2rem !important; }
    .mt-4, .my-4 { margin-top: 2rem !important; }
    
    /* Hide desktop-only elements */
    .d-none-mobile { display: none !important; }
    
    /* Show mobile-only elements */
    .d-block-mobile { display: block !important; }
    .d-flex-mobile { display: flex !important; }
}

/* Extra small devices (phones) */
@media (max-width: 480px) {
    
    /* Even more compact for small phones */
    .container, 
    .dashboard-container,
    .employee-container,
    .schedule-container {
        padding-left: 4px !important;
        padding-right: 4px !important;
    }
    
    .card-body, .card-header {
        padding: 12px !important;
    }
    
    .btn {
        padding: 10px 16px !important;
        font-size: 0.95em !important;
    }
    
    .modal-dialog {
        margin: 5px !important;
        max-width: calc(100vw - 10px) !important;
        width: calc(100vw - 10px) !important;
    }
    
    .modal-body {
        padding: 16px !important;
    }
    
    h1 { font-size: 1.6rem !important; }
    h2 { font-size: 1.4rem !important; }
    h3 { font-size: 1.25rem !important; }
}

/* Landscape mobile improvements */
@media (max-width: 896px) and (orientation: landscape) {
    
    /* Better use of space in landscape */
    .navbar-brand .brand-text {
        display: none !important;
    }
    
    .modal-body {
        max-height: 60vh !important;
    }
    
    .dashboard-tabs {
        flex-direction: row !important;
        overflow-x: auto !important;
        white-space: nowrap !important;
    }
    
    .dashboard-tabs .tab-btn {
        min-width: auto !important;
        white-space: nowrap !important;
        padding: 12px 16px !important;
    }
}

/* High-DPI mobile displays */
@media only screen and (-webkit-min-device-pixel-ratio: 2) and (max-width: 768px) {
    
    /* Sharper borders and shadows for retina displays */
    .btn, .form-control, .card {
        border-width: 0.5px !important;
    }
    
    .card {
        box-shadow: 0 1px 4px rgba(0,0,0,0.1) !important;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    
    /* Remove hover effects that don't work on touch */
    .btn:hover, 
    .nav-link:hover,
    .dropdown-item:hover {
        transform: none !important;
    }
    
    /* Better touch feedback */
    .btn:active,
    .nav-link:active,
    .dropdown-item:active {
        transform: scale(0.95) !important;
        transition: transform 0.1s ease !important;
    }
    
    /* Larger touch targets */
    .btn, .nav-link, .dropdown-item, input, select, textarea {
        min-height: 48px !important;
        min-width: 48px !important;
    }
}
