@media (max-width: 768px) {

    /* Body and Container Adjustments */
    body {
        font-size: 14px;
        overflow-x: hidden;
    }

    .container,
    .container-fluid {
        padding-left: 15px;
        padding-right: 15px;
    }

    /* Typography */
    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;
    }

    /* Cards */
    .card {
        margin-bottom: 15px;
        border-radius: 8px;
    }

    .card-body {
        padding: 15px;
    }

    .card-header {
        padding: 12px 15px;
        font-size: 1rem;
    }

    /* Tables - Make them scrollable */
    .table-responsive {
        border: 0;
        margin-bottom: 15px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        min-width: 100%;
        font-size: 0.875rem;
    }

    table th,
    table td {
        padding: 8px 6px;
        white-space: nowrap;
    }

    /* Forms */
    .form-control,
    .form-select {
        font-size: 16px;
        /* Prevents zoom on iOS */
        padding: 10px 12px;
        min-height: 44px;
        /* Better touch targets */
    }

    .form-label {
        font-size: 14px;
        margin-bottom: 6px;
    }

    input[type="date"],
    input[type="time"],
    input[type="datetime-local"] {
        min-height: 44px;
        font-size: 16px;
    }

    textarea.form-control {
        min-height: 100px;
    }

    /* Buttons */
    .btn {
        padding: 10px 16px;
        font-size: 14px;
        min-height: 44px;
        width: 100%;
        margin-bottom: 8px;
    }

    .btn-group .btn {
        width: auto;
    }

    .btn-sm {
        padding: 6px 12px;
        font-size: 12px;
        min-height: 36px;
    }

    /* Modal Improvements */
    .modal-dialog {
        margin: 10px;
        max-width: calc(100% - 20px);
    }

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

    /* Fix for date/time inputs in modals on mobile */
    .modal-body input[type="date"],
    .modal-body input[type="time"],
    .modal-body input[type="datetime-local"],
    .modal-body select {
        position: relative;
        z-index: 1050;
        -webkit-appearance: none;
        appearance: none;
        background-color: #fff;
        cursor: pointer;
        touch-action: manipulation;
    }

    /* Re-add native appearance for better mobile experience */
    .modal-body input[type="date"]::-webkit-calendar-picker-indicator,
    .modal-body input[type="time"]::-webkit-calendar-picker-indicator,
    .modal-body input[type="datetime-local"]::-webkit-calendar-picker-indicator {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: auto;
        height: auto;
        color: transparent;
        background: transparent;
        cursor: pointer;
    }

    .modal-header {
        padding: 12px 15px;
    }

    .modal-footer {
        padding: 10px 15px;
        flex-wrap: wrap;
    }

    .modal-footer .btn {
        width: 100%;
        margin: 5px 0;
    }

    /* Navigation */
    .navbar {
        padding: 8px 15px;
    }

    .navbar-brand {
        font-size: 1.1rem;
    }

    .nav-link {
        padding: 10px 15px;
        font-size: 14px;
    }

    /* Sidebar */
    .sidebar {
        width: 100%;
        position: fixed;
        left: -100%;
        transition: left 0.3s ease;
        z-index: 1050;
    }

    .sidebar.active {
        left: 0;
    }

    /* Dashboard Adjustments */
    .dashboard-wrapper {
        padding: 10px;
    }

    .main-content {
        margin-left: 0;
        padding: 15px;
    }

    /* Stats Cards */
    .stats-card {
        margin-bottom: 15px;
        padding: 15px;
    }

    .stats-card h5 {
        font-size: 0.95rem;
    }

    .stats-card .fs-4 {
        font-size: 1.25rem !important;
    }

    /* Badges and Pills */
    .badge {
        font-size: 0.75rem;
        padding: 4px 8px;
    }

    /* Alerts */
    .alert {
        padding: 10px 12px;
        font-size: 0.875rem;
        margin-bottom: 12px;
    }

    /* Breadcrumbs */
    .breadcrumb {
        font-size: 0.875rem;
        padding: 8px 12px;
        flex-wrap: wrap;
    }

    /* Pagination */
    .pagination {
        font-size: 0.875rem;
        flex-wrap: wrap;
        justify-content: center;
    }

    .page-link {
        padding: 6px 12px;
    }

    /* Dropdowns */
    .dropdown-menu {
        font-size: 14px;
        max-width: calc(100vw - 30px);
    }

    .dropdown-item {
        padding: 10px 15px;
    }

    /* Images */
    img {
        max-width: 100%;
        height: auto;
    }

    /* Grid System Adjustments */
    .row {
        margin-left: -10px;
        margin-right: -10px;
    }

    .row>* {
        padding-left: 10px;
        padding-right: 10px;
    }

    /* Spacing Utilities - Reduce on mobile */
    .mb-4,
    .my-4 {
        margin-bottom: 1rem !important;
    }

    .mt-4,
    .my-4 {
        margin-top: 1rem !important;
    }

    .mb-5,
    .my-5 {
        margin-bottom: 1.5rem !important;
    }

    .mt-5,
    .my-5 {
        margin-top: 1.5rem !important;
    }

    /* Text Alignment */
    .text-md-start,
    .text-md-end,
    .text-md-center {
        text-align: center !important;
    }

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

    /* Stack elements vertically on mobile */
    .d-md-flex {
        display: block !important;
    }

    .flex-md-row {
        flex-direction: column !important;
    }

    /* Action buttons in tables */
    .btn-group {
        display: flex;
        flex-wrap: wrap;
        gap: 5px;
    }

    .btn-group .btn {
        flex: 1;
        min-width: auto;
    }

    /* Progress bars */
    .progress {
        height: 1.5rem;
        font-size: 0.75rem;
    }

    /* List groups */
    .list-group-item {
        padding: 10px 12px;
        font-size: 0.875rem;
        flex-wrap: wrap;
    }

    /* Toasts and notifications */
    .toast {
        font-size: 0.875rem;
        max-width: calc(100vw - 30px);
    }

    .toast-container-custom {
        right: 10px !important;
        bottom: 10px !important;
        left: 10px !important;
    }

    /* Charts */
    canvas {
        max-width: 100%;
        height: auto !important;
    }

    /* Input groups */
    .input-group {
        flex-wrap: wrap;
    }

    .input-group>* {
        min-width: 100%;
        margin-bottom: 5px;
    }

    .input-group-text {
        padding: 10px 12px;
    }

    /* Tabs */
    .nav-tabs .nav-link {
        font-size: 0.875rem;
        padding: 8px 12px;
    }

    /* Accordion */
    .accordion-button {
        font-size: 0.875rem;
        padding: 12px 15px;
    }

    .accordion-body {
        padding: 12px 15px;
    }
}

/* ============================================
   SMALL MOBILE STYLES (max-width: 576px)
   ============================================ */

@media (max-width: 576px) {
    body {
        font-size: 13px;
    }

    h1 {
        font-size: 1.5rem;
    }

    h2 {
        font-size: 1.25rem;
    }

    h3 {
        font-size: 1.1rem;
    }

    h4 {
        font-size: 1rem;
    }

    h5 {
        font-size: 0.9rem;
    }

    .container,
    .container-fluid {
        padding-left: 10px;
        padding-right: 10px;
    }

    .card-body {
        padding: 12px;
    }

    .modal-dialog {
        margin: 5px;
        max-width: calc(100% - 10px);
    }

    .btn {
        font-size: 13px;
        padding: 8px 12px;
    }

    table th,
    table td {
        padding: 6px 4px;
        font-size: 0.8rem;
    }

    /* Stack all columns on very small screens */
    .col-sm-6,
    .col-md-6,
    .col-lg-6,
    .col-sm-4,
    .col-md-4,
    .col-lg-4,
    .col-sm-3,
    .col-md-3,
    .col-lg-3 {
        width: 100%;
        margin-bottom: 10px;
    }
}

/* ============================================
   LANDSCAPE MOBILE (max-height: 500px)
   ============================================ */

@media (max-height: 500px) and (orientation: landscape) {
    .modal-body {
        max-height: 300px;
        overflow-y: auto;
    }

    .navbar {
        padding: 5px 15px;
    }

    .card-body {
        padding: 10px;
    }
}

/* ============================================
   TOUCH DEVICE IMPROVEMENTS
   ============================================ */

@media (hover: none) and (pointer: coarse) {

    /* Better touch targets */
    a,
    button,
    .btn,
    .nav-link,
    .dropdown-item {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Larger clickable areas */
    .form-check-input {
        width: 1.5rem;
        height: 1.5rem;
    }

    .form-check-label {
        padding-left: 0.5rem;
    }

    /* Remove hover effects on touch devices */
    .btn:hover,
    .nav-link:hover,
    a:hover {
        opacity: 1;
    }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

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

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

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

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

/* Responsive text sizes */
.text-responsive {
    font-size: 16px;
}

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

@media (max-width: 576px) {
    .text-responsive {
        font-size: 13px;
    }
}

/* Responsive spacing */
.spacing-responsive {
    padding: 30px;
}

@media (max-width: 768px) {
    .spacing-responsive {
        padding: 15px;
    }
}

@media (max-width: 576px) {
    .spacing-responsive {
        padding: 10px;
    }
}

/* Full width on mobile */
.mobile-full-width {
    width: auto;
}

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

/* Prevent horizontal scroll */
.no-scroll-x {
    overflow-x: hidden;
    max-width: 100vw;
}