@media (max-width: 768px) {
    #app-container {
        flex-direction: row;
    }

    #sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        width: 280px;
        height: 100vh;
        height: 100dvh;
        z-index: 1001;
        transition: left 0.3s ease;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    }

    #app-container:not(.sidebar-collapsed) #sidebar {
        left: 0;
        box-shadow: 4px 0 12px rgba(0, 0, 0, 0.3);
    }

    /* Backdrop overlay */
    #app-container:not(.sidebar-collapsed)::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1000;
        animation: fadeIn 0.3s;
    }

    @keyframes fadeIn {
        from { opacity: 0; }
        to { opacity: 1; }
    }

    #sidebar ul.components {
        display: block;
        padding: 0;
        border-bottom: none;
    }

    #sidebar ul li {
        flex: none;
        max-width: none;
        width: 100%;
    }

    #sidebar ul li a {
        padding: 16px 20px;
        font-size: 1em;
        text-align: left;
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 12px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    }

    #sidebar ul li a i {
        margin-right: 0;
        font-size: 1.2em;
        width: 24px;
        text-align: center;
    }

    .sidebar-header {
        padding: 20px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }

    .sidebar-header h3 {
        font-size: 1.3em;
    }

    #content {
        width: 100%;
        padding: 10px;
        height: 100vh;
        height: 100dvh;
    }

    #main-header {
        flex-wrap: nowrap;
        padding: 8px 10px;
        gap: 8px;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 999;
        background: var(--white);
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        transition: transform 0.3s ease;
    }

    #main-header.header-hidden {
        transform: translateY(-100%);
    }

    #main-header h2 {
        font-size: 1em;
        width: auto;
        flex: 1;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    #sidebar-toggle {
        font-size: 1.3rem;
        padding: 6px 10px;
        background: var(--primary-blue);
        color: white;
        border-radius: 6px;
        min-width: 40px;
        min-height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    #main-header > div {
        flex-wrap: wrap;
        gap: 8px;
    }

    #current-user-name {
        display: none;
    }

    #help-btn,
    #logout-btn {
        min-width: 40px;
        min-height: 40px;
        padding: 8px;
    }

    #help-btn span,
    #logout-btn span {
        display: none;
    }

    #logout-btn i {
        margin-right: 0;
    }

    #main-content {
        padding-top: 60px;
    }

    .card {
        padding: 15px;
        margin-bottom: 15px;
    }

    .card-title {
        font-size: 1.2rem;
    }

    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 16px;
    }

    .btn {
        padding: 12px 15px;
        font-size: 0.95em;
        min-height: 44px;
    }

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

    .item-list li {
        padding: 12px;
        flex-direction: column;
        align-items: flex-start;
    }

    .item-info {
        width: 100%;
        margin-bottom: 10px;
    }

    .item-actions {
        width: 100%;
        justify-content: stretch;
        flex-wrap: wrap;
        gap: 8px;
    }

    .item-actions button,
    .item-actions input,
    .item-actions select {
        flex: 1 1 auto;
        min-width: 120px;
    }

    #dashboard-summary {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .summary-card {
        padding: 15px;
    }

    .summary-card i {
        font-size: 2rem;
    }

    .summary-card-info h2 {
        font-size: 1.5rem;
    }

    .calendar-grid {
        gap: 2px;
    }

    .calendar-day, .empty {
        min-height: 80px;
        padding: 3px;
        font-size: 0.85em;
    }

    .day-number {
        width: 24px;
        height: 24px;
        font-size: 0.85em;
    }

    .calendar-event {
        font-size: 0.7em;
        padding: 2px 4px;
    }

    .calendar-header {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }

    .calendar-header button {
        width: 100%;
    }

    .sub-nav {
        flex-wrap: wrap;
        gap: 5px;
        padding-bottom: 5px;
    }

    .sub-nav-link {
        font-size: 0.85em;
        padding: 8px 12px;
        flex: 1 1 auto;
        text-align: center;
    }

    /* Generic Table Responsive Wrapper */
    table {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .payroll-table {
        font-size: 0.85em;
        white-space: nowrap;
        min-width: 100%;
    }

    .payroll-table th,
    .payroll-table td {
        padding: 6px;
    }

    .modal-backdrop {
        padding: 10px;
    }

    .modal-content {
        max-width: 100%;
        max-height: 95vh;
    }

    [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }

    #production-board,
    #work-orders-board {
        grid-template-columns: 1fr;
    }

    .bar-visualization {
        height: 30px;
    }

    .optimizer-results .cut-piece,
    .optimizer-results .remnant-piece {
        font-size: 0.7em;
    }

    .optimizer-results .cut-piece[style*="width: 0%"],
    .optimizer-results .cut-piece[style*="width: 1%"],
    .optimizer-results .cut-piece[style*="width: 2%"],
    .optimizer-results .cut-piece[style*="width: 3%"],
    .optimizer-results .cut-piece[style*="width: 4%"],
    .optimizer-results .cut-piece[style*="width: 5%"] {
        font-size: 0;
    }

    #chat-messages {
        max-height: 300px;
    }

    #chat-form {
        flex-wrap: wrap;
    }

    #chat-input {
        flex: 1 1 100%;
        min-width: 100%;
        margin-bottom: 10px;
    }

    .edit-hours-btn,
    .payment-amount {
        min-width: 100px;
    }

    /* Floating Calculator Mobile Styles */
    #floating-calc-toggle {
        width: 50px !important;
        height: 50px !important;
        bottom: 20px !important;
        right: 20px !important;
        font-size: 20px !important;
        box-shadow: 0 4px 10px rgba(0,0,0,0.4) !important;
    }

    #floating-calc-panel {
        width: calc(100vw - 30px) !important;
        max-width: 320px !important;
        bottom: 80px !important;
        right: 15px !important;
        left: auto !important;
        padding: 10px !important;
    }

    #floating-calc-display {
        font-size: 24px !important;
        padding: 15px !important;
        min-height: 60px !important;
        margin-bottom: 10px !important;
    }

    #floating-calc-buttons button {
        padding: 15px !important;
        font-size: 18px !important;
        min-height: 55px;
    }

    #floating-calc-buttons {
        gap: 8px !important;
    }
}

@media (max-width: 375px) {
    #sidebar ul li {
        flex: 0 0 50%;
        max-width: 50%;
    }

    .card {
        padding: 10px;
    }

    .card-title {
        font-size: 1.1rem;
    }

    .summary-card-info h2 {
        font-size: 1.3rem;
    }

    .btn {
        font-size: 0.9em;
        padding: 10px 12px;
    }

    .calendar-day, .empty {
        min-height: 60px;
        font-size: 0.75em;
    }

    .day-number {
        width: 20px;
        height: 20px;
        font-size: 0.75em;
    }

    .calendar-event {
        font-size: 0.65em;
        padding: 1px 3px;
    }
}

