/* ===== RESPONSIVE.CSS - Mobile & Tablet Optimizations ===== */

/* ===== BASE RESPONSITIVE SETUP ===== */
* {
    box-sizing: border-box;
}

body {
    overflow-x: hidden;
}

/* ===== HAMBURGER MENU BUTTON ===== */
.hamburger-menu {
    display: none;
    flex-direction: column;
    justify-content: space-between;
    width: 24px;
    height: 18px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    z-index: 1001;
    transition: all 0.3s ease;
}

.hamburger-line {
    display: block;
    height: 2px;
    width: 100%;
    background-color: #4b5563;
    border-radius: 2px;
    transition: all 0.3s ease;
}

/* Hamburger Animation - X Shape */
.hamburger-menu.active .hamburger-line:nth-child(1) {
    transform: translateY(8px) rotate(45deg);
}

.hamburger-menu.active .hamburger-line:nth-child(2) {
    opacity: 0;
}

.hamburger-menu.active .hamburger-line:nth-child(3) {
    transform: translateY(-8px) rotate(-45deg);
}

/* ===== TABLET BREAKPOINT (768px - 1024px) ===== */
@media (max-width: 1024px) {
    /* Dashboard adjustments */
    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 1rem !important;
    }
    
    /* Form layouts */
    .form-row {
        grid-template-columns: 1fr !important;
    }
    
    /* Table improvements */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Modal sizing */
    .modal-content {
        width: 95% !important;
        max-width: 700px !important;
    }
}

/* ===== MOBILE BREAKPOINT (max-width: 768px) ===== */
@media (max-width: 768px) {
    
    /* ===== NAVIGATION ===== */
    .hamburger-menu {
        display: flex;
        margin-left: auto;
        margin-right: 1rem;
    }

    .navbar {
        padding: 0 1rem;
        position: sticky;
        top: 0;
        z-index: 1000;
    }

    .nav-content {
        padding: 0.75rem 0;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .nav-brand {
        font-size: 1rem;
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }

    .nav-logo {
        height: 32px !important;
        width: auto;
    }

    /* Sidebar Navigation Menu */
    .nav-menu {
        position: fixed;
        top: 0;
        right: -280px;
        width: 280px;
        height: 100vh;
        background-color: white;
        box-shadow: -5px 0 15px rgba(0, 0, 0, 0.1);
        display: flex !important;
        flex-direction: column;
        justify-content: flex-start;
        align-items: stretch;
        padding: 0;
        gap: 0;
        z-index: 1000;
        overflow-y: auto;
        transition: right 0.3s ease;
        transform: translateX(0);
    }

    .nav-menu.active {
        right: 0;
    }
    
    /* Force hide non-active menu items container on desktop */
    .navbar .nav-menu:not(.active) {
        display: none !important;
    }
    
    /* Show menu when hamburger is clicked */
    .navbar .nav-menu.active {
        display: flex !important;
    }

    /* Side Overlay (darkens background) */
    .nav-side-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 999;
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }
    
    .nav-side-overlay.active {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    /* Navigation Items */
    .nav-menu > .nav-item {
        position: relative;
        background-color: white;
        padding: 1rem 1.5rem;
        border-bottom: 1px solid #f3f4f6;
        width: 100%;
        text-align: left;
        transition: all 0.2s ease;
        display: block;
        cursor: pointer;
    }

    .nav-menu > .nav-item:hover {
        background-color: #f9fafb;
    }

    .nav-menu > .nav-item.active {
        background-color: #eff6ff;
        color: #1e40af;
        border-left: 4px solid #3b82f6;
    }

    .nav-menu > .nav-item::after {
        display: none;
    }

    /* User Section in Mobile */
    .nav-user {
        margin-top: auto;
        border-top: 1px solid #e5e7eb;
        padding: 1rem;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .dropdown-menu {
        right: auto;
        left: 50%;
        transform: translateX(-50%);
    }

    /* ===== PAGE LAYOUT ===== */
    .app-container {
        padding: 0.5rem;
        margin-top: 0;
    }

    .main-content {
        padding: 1rem 0.5rem;
    }

    .page-header {
        margin-bottom: 1.5rem;
        padding: 0.9rem;
    }

    .page-header h1 {
        font-size: 1.5rem;
        margin-bottom: 0.5rem;
        line-height: 1.2;
        text-shadow: #e5e7eb;
    }

    .page-header p {
        font-size: 0.875rem;
        color: #000000;
        font-weight: 500;
        text-shadow: #f9fafb;
    }

    .page-content {
        padding: 0;
    }

    /* ===== DASHBOARD ===== */
    .dashboard-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
        padding: 0 0.5rem;
    }

    .dashboard-card {
        padding: 1.25rem 1rem !important;
    }

    .dashboard-card h3 {
        font-size: 1.75rem !important;
    }

    .dashboard-card p {
        font-size: 0.875rem;
    }

    /* ===== CARDS ===== */
    .card {
        margin-bottom: 1.5rem;
        border-radius: 0.5rem;
        overflow: hidden;
    }

    .card-header {
        padding: 1rem !important;
    }

    .card-header h3 {
        font-size: 1.125rem;
    }

    .card-body {
        padding: 1rem !important;
    }

    .card-header-content {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 1rem;
    }

    .card-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
        width: 100%;
    }

    .card-actions .btn-sm {
        flex: 1;
        min-width: 80px;
        font-size: 0.75rem;
        padding: 0.5rem 0.75rem;
    }

    .card-actions select.form-control,
    .card-actions input.form-control {
        width: 100% !important;
        margin-bottom: 0.5rem;
    }

    /* ===== PAGE ACTIONS ===== */
    .page-actions {
        flex-direction: column;
        align-items: stretch !important;
        gap: 1rem;
        margin-bottom: 1.5rem;
        padding: 0 0.5rem;
    }

    .action-buttons {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
        width: 100%;
    }

    .action-buttons .btn {
        flex: 1;
        min-width: 120px;
        font-size: 0.875rem;
    }

    /* ===== BUTTONS ===== */
    .btn {
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
        white-space: nowrap;
    }

    .btn-sm {
        padding: 0.5rem 0.75rem;
        font-size: 0.75rem;
    }

    .w-100 {
        width: 100% !important;
    }

    /* ===== FORMS ===== */
    .form-row {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }

    .form-group {
        margin-bottom: 1rem;
        width: 100%;
    }

    .form-group label {
        font-size: 0.875rem;
        margin-bottom: 0.5rem;
        display: block;
        font-weight: 500;
    }

    .form-control {
        padding: 0.75rem;
        font-size: 0.875rem;
        width: 100%;
    }

    .form-actions {
        flex-direction: column-reverse;
        gap: 0.75rem;
        padding-top: 1rem;
        margin-top: 1rem;
    }

    .form-actions .btn {
        width: 100%;
    }

/* ===== TABLES - FULLY SCROLLABLE ON ALL DEVICES ===== */

/* The container that acts as a viewport for the table */
.table-container {
    /* This is the key to making it work */
    overflow-x: auto; /* Enables horizontal scrolling when content is wider than the screen */
    overflow-y: auto; /* Enables vertical scrolling when content is taller than the container */
    -webkit-overflow-scrolling: touch; /* Improves scrolling experience on iOS devices */
    
    /* This creates the scrolling window */
    max-height: 60vh; /* Container will be at most 60% of the viewport height. Adjust as needed. */
    
    /* Aesthetics and positioning */
    margin: 1rem 0;
    border-radius: 0.5rem;
    width: 100%;
    position: relative; /* Needed for the scroll indicators */
    border: 1px solid var(--gray-200); /* Add a border to better define the container */
    box-shadow: var(--shadow); /* Add a shadow to make it stand out */
    background: var(--bg-primary); /* Ensure consistent background */
}

/* The table itself */
.table {
    font-size: 0.75rem;
    min-width: 600px; /* Forces the table to be wider than a typical mobile screen, triggering horizontal scroll */
    width: 100%;
    display: table;
    border-collapse: separate; /* Better for sticky headers */
    border-spacing: 0;
    background: var(--bg-primary); /* Ensure consistent background */
}

/* Table headers and cells */
.table th,
.table td {
    padding: 0.75rem 0.5rem;
    white-space: nowrap; /* Prevents text from wrapping, which is good for data tables */
    min-width: 80px;
    vertical-align: middle;
    background: var(--bg-primary); /* Ensure consistent background */
}

/* Make table headers sticky so they don't disappear when scrolling vertically */
.table th {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: sticky;
    top: 0;
    z-index: 10; /* Ensures it stays above other rows */
    background-color: var(--gray-50);
    border-bottom: 2px solid var(--gray-200);
}

/* Special case for the wider work orders table */
.table-workorders {
    min-width: 900px;
}

.table-workorders th,
.table-workorders td {
    padding: 0.75rem 0.5rem;
}

/* Table row groups for semantic HTML */
#productsTableBody,
#inventoryTableBody,
#ledgerTableBody,
#bomTableBody,
#planningTableBody,
#reportsWorkOrdersBody {
    display: table-row-group;
}

/* Ensure parent tables have proper width */
table {
    table-layout: auto;
}

/* ===== SCROLL INDICATORS (Visual Cues for Users) ===== */

/* Horizontal scroll indicator (appears on the right) */
.table-container::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 10px;
    background: linear-gradient(to left, rgba(0,0,0,0.1), transparent);
    pointer-events: none; /* Allows clicking through it */
    opacity: 0;
    transition: opacity 0.3s;
}

/* Vertical scroll indicator (appears at the bottom) */
.table-container::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 10px;
    background: linear-gradient(to top, rgba(0,0,0,0.1), transparent);
    pointer-events: none; /* Allows clicking through it */
    opacity: 0;
    transition: opacity 0.3s;
}

/* Show horizontal indicator when scrolled horizontally */
.table-container.scrolled-x::after {
    opacity: 1;
}

/* Show vertical indicator when scrolled vertically */
.table-container.scrolled-y::before {
    opacity: 1;
}

/* ===== COMPONENT STYLES WITHIN SCROLLABLE TABLES ===== */

/* Table Action Buttons */
.table-action-btn {
    padding: 0.375rem 0.5rem;
    font-size: 0.7rem;
    margin-right: 0.25rem;
    margin-bottom: 0.25rem;
    display: inline-block;
}

/* Work Order Cells */
.wo-cell-title {
    font-size: 0.75rem;
}

.wo-cell-subtitle {
    font-size: 0.65rem;
}

/* Badges */
.priority-badge,
.status-badge {
    font-size: 0.65rem;
    padding: 0.25rem 0.5rem;
}
        /* ===== MODALS ===== */
        .modal {
            padding: 1rem;
            overflow-y: auto;
        }

        .modal-content {
            width: 95% !important;
            max-width: 100% !important;
            max-height: 90vh;
            margin: auto;
            display: flex;
            flex-direction: column;
        }

        .large-modal .modal-content {
            max-width: 100% !important;
        }

        .modal-header {
            padding: 1rem !important;
            flex-shrink: 0;
        }

        .modal-header h2 {
            font-size: 1.25rem;
        }

        .modal-body {
            padding: 1rem !important;
            max-height: calc(90vh - 150px);
            overflow-y: auto;
            overflow-x: hidden;
            flex: 1;
        }

        /* Tables inside modals must scroll */
        .modal-body .table-container {
            overflow-x: auto;
            -webkit-overflow-scrolling: touch;
            margin: 0.5rem 0;
        }

        .modal-body .table-responsive {
            overflow-x: auto;
            -webkit-overflow-scrolling: touch;
            width: 100%;
        }

        .modal-body table {
            min-width: 600px;
            width: 100%;
        }

        .modal-footer {
            padding: 1rem !important;
            flex-direction: column-reverse;
            gap: 0.5rem;
            flex-shrink: 0;
        }

        .modal-footer .btn {
            width: 100%;
        }

        .close {
            font-size: 1.5rem;
            padding: 0.5rem;
        }

        /* ===== BATCH MANAGEMENT ===== */
        .batch-summary-card {
            grid-template-columns: 1fr !important;
            gap: 0.75rem;
        }

        .batch-summary-item {
            padding: 0.75rem;
        }

        .batch-summary-item .label {
            font-size: 0.75rem;
        }

        .batch-summary-item .value {
            font-size: 0.875rem;
        }

        .batch-actions {
            flex-direction: column;
            gap: 0.75rem;
        }

        .batch-actions .btn {
            width: 100%;
        }

        .batch-calculation-card {
            padding: 1rem;
        }

        .batch-calculation-card h4 {
            font-size: 1rem;
        }

        .batches-list {
            margin-top: 1rem;
            overflow-x: auto;
            -webkit-overflow-scrolling: touch;
        }

        .batch-item {
            flex-direction: column;
            align-items: flex-start;
            gap: 0.5rem;
            padding: 1rem;
        }

        /* Batch table - ensure scrollability */
        #batchesTable {
            min-width: 800px;
            width: 100%;
        }

        #batchesTableBody tr {
            display: table-row;
        }

        #batchesTableBody td {
            padding: 0.75rem 0.5rem;
            white-space: nowrap;
        }

        /* Make sure table wrapper scrolls */
        .batches-list .table-responsive,
        .table-responsive {
            overflow-x: auto !important;
            -webkit-overflow-scrolling: touch;
            width: 100%;
            display: block;
        }

        /* ===== SEARCH BOX ===== */
        .search-box {
            margin-bottom: 1rem;
            padding: 0 0.5rem;
        }

        .search-box input {
            padding: 0.75rem;
            font-size: 0.875rem;
        }

        /* ===== INVENTORY PAGE ===== */
        #stockFilterInfo,
        #ledgerFilterInfo {
            font-size: 0.75rem;
            padding: 0.5rem;
        }

        /* ===== MATERIAL PLANNING ===== */
        #planningTableBody td {
            font-size: 0.75rem;
        }

        /* ===== REPORTS PAGE ===== */
        #paginationContainer {
            display: flex;
            flex-wrap: wrap;
            gap: 0.5rem;
            justify-content: center;
            padding: 1rem 0.5rem;
        }

        /* ===== BOM ITEMS ===== */
        .bom-items {
            margin-top: 1rem;
        }

        .bom-items h4 {
            font-size: 1rem;
            margin-bottom: 1rem;
        }

        #bomItemsList {
            display: flex;
            flex-direction: column;
            gap: 1rem;
        }

        /* ===== CONFIRMATION DIALOG ===== */
        .confirm-content {
            width: 90% !important;
            max-width: 350px;
            padding: 1.5rem !important;
        }

        .confirm-message {
            font-size: 0.875rem;
            margin-bottom: 1.5rem;
        }

        .confirm-buttons {
            flex-direction: column-reverse;
            gap: 0.5rem;
        }

        .confirm-buttons .btn {
            width: 100%;
        }

        /* ===== LOADING OVERLAY ===== */
        .loading-overlay {
            padding: 1rem;
        }

        .spinner {
            width: 35px;
            height: 35px;
        }

        .loading-overlay p {
            font-size: 0.875rem;
        }

        /* ===== UTILITY CLASSES ===== */
        .text-muted {
            font-size: 0.875rem;
        }

        .small {
            font-size: 0.75rem;
        }

        /* Hide desktop-only elements */
        .desktop-only {
            display: none !important;
        }

        /* Show mobile-only elements */
        .mobile-only {
            display: block !important;
        }
    }

    /* ===== SMALL MOBILE BREAKPOINT (max-width: 480px) ===== */
    @media (max-width: 480px) {
        /* Full-width sidebar */
        .nav-menu {
            width: 100%;
            right: -100%;
        }

        .nav-brand {
            font-size: 0.875rem;
        }

        .nav-logo {
            height: 28px !important;
        }

        /* Smaller text */
        .page-header h1 {
            font-size: 1.25rem;
        }

        .dashboard-card h3 {
            font-size: 1.5rem !important;
        }

        /* Compact tables */
        .table {
            font-size: 0.7rem;
        }

        .table th,
        .table td {
            padding: 0.5rem 0.375rem;
        }

        /* Compact buttons */
        .btn {
            padding: 0.625rem 0.875rem;
            font-size: 0.8125rem;
        }

        .btn-sm {
            padding: 0.375rem 0.625rem;
            font-size: 0.7rem;
        }

        /* Modal adjustments */
        .modal {
            padding: 0.5rem;
        }

        .modal-content {
            width: 100% !important;
            border-radius: 0.5rem;
        }

        .modal-header h2 {
            font-size: 1.125rem;
        }

        /* Form controls */
        .form-control {
            padding: 0.625rem;
            font-size: 0.8125rem;
        }

        /* Card actions - stack vertically */
        .card-actions {
            flex-direction: column;
        }

        .card-actions .btn-sm,
        .card-actions select,
        .card-actions input {
            width: 100% !important;
        }
    }

    /* ===== LANDSCAPE MOBILE (max-height: 500px) ===== */
    @media (max-height: 500px) and (orientation: landscape) {
        .modal-body {
            max-height: 60vh;
        }

        .nav-menu {
            overflow-y: scroll;
        }
    }

    /* ===== PRINT STYLES ===== */
    @media print {
        .navbar,
        .hamburger-menu,
        .page-actions,
        .card-actions,
        .btn,
        .modal,
        .loading-overlay,
        .nav-side-overlay {
            display: none !important;
        }

        .table-container {
            overflow: visible;
        }

        .table {
            font-size: 10pt;
        }

        body {
            print-color-adjust: exact;
            -webkit-print-color-adjust: exact;
        }
    }