@media (max-width: 991.98px) {
    .wrapper {
        min-height: 100vh;
    }

    #sidebar {
        min-width: 0;
        max-width: none;
        width: 100%;
        min-height: 0;
        position: relative;
        top: auto;
        border-right: 0;
        border-bottom: 1px solid var(--border-color, #dee2e6);
    }

    #sidebar .sidebar-header {
        padding: 1rem 1.25rem !important;
    }

    #sidebar .sidebar-profile {
        display: flex;
        align-items: center;
        gap: 0.85rem;
        padding: 0 1.25rem 1rem !important;
        margin-bottom: 0 !important;
        text-align: left !important;
    }

    #sidebar .sidebar-profile #userIcon {
        flex: 0 0 48px;
        width: 48px !important;
        height: 48px !important;
        margin: 0 !important;
        font-size: 1.15rem !important;
    }

    #sidebar .sidebar-profile > div:nth-child(2) {
        flex: 1;
        min-width: 0;
        margin-bottom: 0 !important;
    }

    #sidebar .sidebar-profile h6,
    #sidebar .sidebar-profile p {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    #sidebar .sidebar-profile .btn {
        width: auto !important;
        flex: 0 0 auto;
    }

    #sidebar .sidebar-menu {
        flex-direction: row !important;
        flex-wrap: nowrap;
        gap: 0.25rem;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 0.25rem 0.75rem 0.65rem !important;
        white-space: nowrap;
        scrollbar-width: thin;
        -webkit-overflow-scrolling: touch;
    }

    #sidebar .sidebar-menu > p,
    #sidebar .sidebar-menu > hr {
        display: none;
    }

    #sidebar .sidebar-menu .nav-link {
        flex: 0 0 auto;
        width: auto;
        padding: 0.65rem 0.85rem;
        border-radius: 0.65rem;
        text-align: center !important;
    }

    #sidebar .sidebar-menu .nav-link.active {
        border-bottom: 0;
    }

    #sidebar .sidebar-menu #adminSideMenu:not(.d-none) {
        display: flex !important;
        flex: 0 0 auto;
        gap: 0.25rem;
    }

    #sidebar .sidebar-menu #adminSideMenu > p,
    #sidebar .sidebar-menu #adminSideMenu > hr {
        display: none;
    }

    #sidebar > .px-4.pb-4 {
        position: absolute;
        top: 0.8rem;
        right: 0.75rem;
        padding: 0 !important;
    }

    #sidebar > .px-4.pb-4 .btn {
        width: auto !important;
        padding: 0.35rem 0.55rem !important;
    }

    #content {
        width: 100%;
        min-height: 0 !important;
        padding: 1.25rem !important;
    }

    #content > .tab-content {
        max-width: 100% !important;
    }

    .sidebar {
        position: relative !important;
        inset: auto !important;
        width: 100% !important;
        height: auto !important;
        min-height: 0;
        z-index: 10;
        border-right: 0 !important;
        border-bottom: 1px solid var(--border-color, #dee2e6);
    }

    .sidebar > .nav {
        flex-direction: row !important;
        flex-wrap: nowrap;
        gap: 0.25rem;
        overflow-x: auto;
        padding: 0.5rem 0.75rem 0.75rem;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }

    .sidebar > .nav .nav-link {
        flex: 0 0 auto;
        width: auto;
        padding: 0.65rem 0.85rem;
        border-left: 0 !important;
        border-radius: 0.65rem;
    }

    .sidebar > .nav > li {
        flex: 0 0 auto;
    }

    .main-content {
        width: 100%;
        margin-left: 0 !important;
        padding: 1.5rem !important;
    }

    .container {
        max-width: 100%;
    }
}

@media (max-width: 767.98px) {
    body {
        overflow-x: hidden;
    }

    .container {
        padding-right: 0.85rem;
        padding-left: 0.85rem;
    }

    .container.py-4 {
        padding-top: 1rem !important;
        padding-bottom: 1rem !important;
    }

    .container > .d-flex.justify-content-between.align-items-center.mb-4 {
        gap: 0.5rem;
        margin-bottom: 1rem !important;
    }

    .container > .d-flex.justify-content-between.align-items-center.mb-4 .logo-text {
        font-size: clamp(1.15rem, 5vw, 1.45rem);
        white-space: nowrap;
    }

    #userInfoArea {
        gap: 0.4rem !important;
    }

    #userInfoArea > div {
        padding-right: 0.55rem !important;
        padding-left: 0.7rem !important;
    }

    #userInfoArea .btn {
        padding-right: 0.65rem !important;
        padding-left: 0.65rem !important;
        white-space: nowrap;
    }

    .container.py-4 > .row.g-2.mb-3.text-center {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.55rem !important;
        margin-right: 0;
        margin-left: 0;
    }

    .container.py-4 > .row.g-2.mb-3.text-center > .col-3 {
        width: auto;
        padding: 0;
    }

    .container.py-4 > .row.g-2.mb-3.text-center > .col-3 > div {
        height: 100%;
        padding: 0.75rem 0.4rem !important;
        font-size: 0.9rem;
        overflow-wrap: anywhere;
    }

    .container.py-4 > .row.g-2.mb-3.text-center #totalDays,
    .container.py-4 > .row.g-2.mb-3.text-center #totalHours,
    .container.py-4 > .row.g-2.mb-3.text-center #unpaidSalary,
    .container.py-4 > .row.g-2.mb-3.text-center #paidSalary {
        font-size: clamp(1rem, 4.8vw, 1.35rem);
    }

    .widget-card .card-body {
        padding: 0.9rem !important;
    }

    #calcTaxRate {
        min-width: 0;
    }

    .filter-bar {
        align-items: center;
    }

    #workplaceFilter {
        width: 100% !important;
        min-width: 0;
    }

    .calendar-container,
    #calendar {
        min-width: 0;
    }

    .container > .bg-white.rounded-4.shadow-sm.p-3 {
        padding: 0.6rem !important;
        overflow: hidden;
    }

    .fc .fc-toolbar {
        display: grid;
        grid-template-columns: 1fr auto;
        gap: 0.5rem;
        align-items: center;
        margin-bottom: 0.75rem !important;
    }

    .fc .fc-toolbar-chunk {
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        gap: 0.2rem;
    }

    .fc .fc-toolbar-chunk:nth-child(2) {
        grid-column: 1 / -1;
        grid-row: 1;
        justify-content: center;
    }

    .fc .fc-toolbar-chunk:first-child {
        grid-column: 1;
        grid-row: 2;
    }

    .fc .fc-toolbar-chunk:last-child {
        grid-column: 2;
        grid-row: 2;
        justify-content: flex-end;
    }

    .fc .fc-toolbar-title {
        margin: 0 !important;
        font-size: clamp(1rem, 4.6vw, 1.25rem) !important;
    }

    .fc .fc-button {
        min-height: 36px;
        padding: 0.35rem 0.5rem !important;
        font-size: 0.78rem !important;
    }

    .fc .fc-daygrid-day-frame {
        min-height: clamp(3.5rem, 12vw, 5rem);
    }

    .fc .fc-daygrid-day-number {
        padding: 0.2rem !important;
        font-size: 0.72rem;
    }

    .fc .fc-col-header-cell-cushion {
        padding: 0.35rem 0.1rem;
        font-size: 0.72rem;
    }

    .fc .fc-daygrid-event {
        margin: 1px !important;
    }

    .fc .fc-daygrid-event .fc-event-title {
        font-size: 0.68rem;
    }

    .fc-event-custom > div:first-child {
        display: none;
    }

    .modal-dialog {
        margin: 0.65rem;
    }

    .modal-dialog-centered {
        min-height: calc(100% - 1.3rem);
    }

    .modal-body {
        padding: 1.1rem !important;
    }

    .theme-toggle {
        right: 0.7rem;
        bottom: max(0.7rem, env(safe-area-inset-bottom));
    }

    .pay-stub {
        margin-bottom: 1.5rem !important;
    }

    .pay-stub .row {
        row-gap: 1rem;
    }

    .border-start-md {
        border-left: 0 !important;
    }

    .table-responsive {
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 575.98px) {
    .container > .d-flex.justify-content-between.align-items-center.mb-4 {
        flex-wrap: wrap;
    }

    #userInfoArea {
        width: 100%;
        justify-content: flex-end;
    }

    #sidebar .sidebar-header {
        padding: 0.75rem 1rem !important;
    }

    #sidebar .sidebar-profile {
        padding-right: 1rem !important;
        padding-left: 1rem !important;
    }

    #sidebar .sidebar-profile .btn {
        font-size: 0.75rem;
    }

    #content {
        padding: 0.85rem !important;
    }

    .main-content {
        padding: 1rem 0.85rem !important;
    }

    .fc .fc-daygrid-day-frame {
        min-height: 3.25rem;
    }

    .fc .fc-daygrid-day-events {
        margin: 0 1px;
    }

    .fc .fc-daygrid-event {
        padding: 0;
    }

    .fc-event-custom {
        padding: 2px 1px !important;
        border-radius: 4px !important;
    }

    .fc-event-custom > div:last-child {
        font-size: 0.62rem !important;
    }

    .fc .fc-daygrid-more-link {
        font-size: 0.65rem;
    }

    .pay-stub {
        padding: 1rem !important;
    }

    .pay-stub h3 {
        font-size: 1.25rem;
    }

    .pay-stub .fs-2 {
        font-size: 1.5rem !important;
    }

    .pay-stub .p-4 {
        padding: 1rem !important;
    }

    .modal-footer {
        gap: 0.5rem;
    }

    .modal-footer > .btn {
        flex: 1 1 auto;
    }

    .theme-toggle {
        min-height: 42px;
    }
}

@media (max-width: 991.98px) and (prefers-reduced-motion: reduce) {
    .fc-event,
    #sidebar,
    .theme-toggle {
        transition: none !important;
    }
}
