:root {
            --primary: #2563eb;
            --bg-light: #f3f4f6;
            --text-dark: #1f2937;
            --white: #ffffff;
            --danger: #ef4444;
            --success: #10b981;
            --warning: #f59e0b;
            --muted: #64748b;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            -webkit-tap-highlight-color: transparent;
        }

        body {
            display: flex;
            height: 100vh;
            background-color: var(--bg-light);
            color: var(--text-dark);
            overflow: hidden;
        }

        .sidebar {
            width: 230px;
            background: #1e293b;
            color: var(--white);
            padding: 15px;
            display: flex;
            flex-direction: column;
            transition: transform 0.3s;
            z-index: 100;
        }

        .brand {
            font-size: 1.3rem;
            font-weight: bold;
            margin-bottom: 30px;
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .nav-item {
            padding: 12px;
            cursor: pointer;
            border-radius: 6px;
            margin-bottom: 4px;
            display: flex;
            align-items: center;
            gap: 10px;
            transition: 0.3s;
            font-size: 0.9rem;
        }

        .nav-item:hover, .nav-item.active {
            background: var(--primary);
        }

        .bottom-nav {
            display: none;
        }

        .main-content {
            flex: 1;
            padding: 20px;
            overflow-y: auto;
            position: relative;
        }

        .sync-badge {
            position: relative;
            width: 100%;
            margin-top: 10px;
            background: rgba(255,255,255,0.10);
            padding: 8px 10px;
            border-radius: 10px;
            box-shadow: none;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            font-size: 0.75rem;
            font-weight: 700;
            color: #e2e8f0;
            z-index: 50;
            transition: all 0.3s;
            white-space: nowrap;
            border: 1px solid rgba(255,255,255,0.14);
        }

        .sync-badge.syncing { color: #93c5fd; border-color: rgba(147,197,253,.35); background: rgba(37,99,235,.16); }
        .sync-badge.success { color: #86efac; border-color: rgba(134,239,172,.35); background: rgba(16,185,129,.14); }
        .sync-badge.cached  { color: #fcd34d; border-color: rgba(252,211,77,.38); background: rgba(245,158,11,.14); }
        .sync-badge.error   { color: #fca5a5; border-color: rgba(252,165,165,.38); background: rgba(239,68,68,.14); }

        #toast-container {
            position: fixed;
            top: 20px;
            right: 20px;
            z-index: 2000;
            display: flex;
            flex-direction: column;
            gap: 10px;
            pointer-events: none;
        }

        .toast {
            background: white;
            padding: 12px 20px;
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0,0,0,0.15);
            display: flex;
            align-items: center;
            gap: 12px;
            min-width: 250px;
            transform: translateX(100%);
            animation: slideIn 0.3s forwards;
            pointer-events: auto;
            border-left: 5px solid #ccc;
        }

        .toast.success { border-left-color: var(--success); }
        .toast.error { border-left-color: var(--danger); }
        .toast i { font-size: 1.2rem; }
        .toast.success i { color: var(--success); }
        .toast.error i { color: var(--danger); }
        .toast-msg { font-size: 0.9rem; font-weight: 600; color: #374151; }

        @keyframes slideIn { to { transform: translateX(0); } }

        #system-error-modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.8);
            z-index: 9999;
            justify-content: center;
            align-items: center;
        }

        .error-box {
            background: white;
            width: 90%;
            max-width: 400px;
            padding: 30px;
            border-radius: 12px;
            text-align: center;
            box-shadow: 0 10px 25px rgba(0,0,0,0.5);
        }

        .error-icon { font-size: 3rem; color: var(--danger); margin-bottom: 15px; }
        .error-title { font-size: 1.2rem; font-weight: bold; color: #1f2937; margin-bottom: 10px; }
        .error-desc {
            font-size: 0.9rem;
            color: #4b5563;
            margin-bottom: 20px;
            line-height: 1.5;
            background: #fef2f2;
            padding: 10px;
            border-radius: 6px;
            border: 1px solid #fee2e2;
            word-break: break-word;
        }

        .btn-reload {
            background: var(--text-dark);
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 6px;
            cursor: pointer;
            font-weight: 600;
            width: 100%;
        }

        .btn-reload:hover { background: black; }

        .header {
            margin-bottom: 15px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            gap: 10px;
            flex-wrap: nowrap; /* Prevent title and actions from splitting */
        }

        .header h2 { font-size: 1.5rem; flex-shrink: 0; }
        
        .header-actions {
            display: flex;
            align-items: center;
            justify-content: flex-end;
            gap: 8px;
            flex-wrap: nowrap; /* Horizontal alignment fix */
        }

        .search-box { position: relative; }
        .search-box input {
            padding: 8px 15px 8px 30px;
            border: 1px solid #d1d5db;
            border-radius: 6px;
            width: 250px;
            outline: none;
            transition: 0.2s;
            font-size: 0.9rem;
        }

        .search-box input:focus {
            border-color: var(--primary);
            box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
        }

        .search-box i {
            position: absolute;
            left: 10px;
            top: 50%;
            transform: translateY(-50%);
            color: #9ca3af;
            font-size: 0.8rem;
        }

        .data-table-container {
            background: var(--white);
            padding: 15px;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.05);
            overflow-x: auto;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 5px;
            table-layout: auto;
        }

        th, td {
            text-align: left;
            padding: 8px 10px;
            border-bottom: 1px solid #e5e7eb;
            vertical-align: middle;
            font-size: 0.85rem;
        }

        th {
            color: #6b7280;
            font-size: 0.75rem;
            text-transform: uppercase;
            letter-spacing: 0.05em;
            font-weight: 700;
            background: #f9fafb;
        }

        /* Ensure the actions column has enough width */
        th:last-child, td:last-child {
            min-width: 150px;
            white-space: nowrap;
        }

        td:first-child {
            font-weight: 600;
            color: #f59e0b;
        }

        .status-select {
            padding: 2px 8px;
            height: 24px;
            border-radius: 12px;
            border: none;
            font-size: 0.75rem;
            font-weight: 600;
            cursor: pointer;
            appearance: none;
            text-align: center;
            outline: none;
            width: 100px;
        }

        .status-select.Open { background: #dbeafe; color: #1e40af; }
        .status-select.Accepted { background: #e0f2fe; color: #0369a1; }
        .status-select.InProgress { background: #fef3c7; color: #b45309; }
        .status-select.OnHold { background: #f3f4f6; color: #4b5563; }
        .status-select.Completed { background: #dcfce7; color: #15803d; }

        .priority {
            font-weight: 600;
            padding: 3px 10px;
            border-radius: 12px;
            font-size: 0.75rem;
            display: inline-block;
            text-align: center;
        }

        .priority.Low { background: #dbeafe; color: #1e40af; }
        .priority.Medium { background: #fef3c7; color: #b45309; }
        .priority.Critical { background: #fee2e2; color: #991b1b; }

        .desc-cell { max-width: 240px; }
        .desc-preview {
            cursor: pointer;
            display: inline-block;
            line-height: 1.4;
            color: #374151;
            word-break: break-word;
        }
        .desc-preview:hover {
            color: var(--primary);
            text-decoration: underline;
        }

        .btn {
            padding: 8px 16px;
            background: var(--primary);
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: 0.2s;
            font-size: 0.9rem;
            white-space: nowrap;
        }

        .btn:hover { background: #1e40af; }
        .btn-success { background: var(--success); }
        .btn-danger { background: var(--danger); padding: 6px 10px; border-radius: 4px; }
        .btn-critical {
            background: #ef4444;
            color: white;
            padding: 8px 16px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 0.9rem;
        }

        /* Fixed: Action buttons aligned horizontally without wrapping */
        .action-btn-group {
            display: flex;
            flex-direction: row;
            flex-wrap: nowrap; 
            gap: 6px;
            align-items: center;
            justify-content: flex-start;
            white-space: nowrap;
        }

        .btn-icon {
            width: 28px;
            height: 28px;
            flex-shrink: 0; /* Prevent buttons from squishing */
            border-radius: 4px;
            border: none;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            transition: 0.2s;
            font-size: 0.85rem;
        }

        .btn-view { background-color: #64748b; }
        .btn-view:hover { background-color: #475569; }
        .btn-edit { background-color: var(--warning); }
        .btn-edit:hover { background-color: #d97706; }
        .btn-del { background-color: var(--danger); }
        .btn-del:hover { background-color: #dc2626; }
        .btn-pdf { background-color: #e11d48; }
        .btn-pdf:hover { background-color: #be123c; }

        .calendar-container {
            background: white;
            padding: 15px;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.05);
        }

        .calendar-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 15px;
        }

        .calendar-title { font-size: 1.1rem; font-weight: bold; }
        .calendar-nav-btn {
            background: #f3f4f6;
            border: none;
            width: 30px;
            height: 30px;
            border-radius: 50%;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .calendar-nav-btn:hover { background: #e5e7eb; }

        .calendar-grid {
            display: grid;
            grid-template-columns: repeat(7, 1fr);
            gap: 5px;
            text-align: center;
        }

        .cal-day-name {
            font-size: 0.75rem;
            font-weight: bold;
            color: #6b7280;
            padding-bottom: 5px;
        }

        .cal-day {
            height: 50px;
            border: 1px solid #e5e7eb;
            border-radius: 4px;
            position: relative;
            cursor: pointer;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            font-size: 0.9rem;
        }

        .cal-day:hover { background: #f9fafb; border-color: var(--primary); }
        .cal-day.today { background: #eff6ff; border-color: #bfdbfe; font-weight: bold; color: var(--primary); }
        .cal-day.selected { background: var(--primary); color: white; border-color: var(--primary); }
        .cal-day.empty { border: none; background: transparent; cursor: default; }

        .job-dots {
            display: flex;
            gap: 2px;
            position: absolute;
            bottom: 4px;
        }

        .job-dot {
            width: 6px;
            height: 6px;
            border-radius: 50%;
            background: #ccc;
        }

        .job-dot.has-job { background: var(--primary); }
        .job-dot.has-critical { background: var(--danger); }

        .cal-day.selected .job-dot { background: white; }

        #calendar-details {
            margin-top: 20px;
            border-top: 1px solid #e5e7eb;
            padding-top: 15px;
        }

        .modal {
            display: none;
            position: fixed;
            inset: 0;
            width: 100%;
            height: 100%;
            background: rgba(15, 23, 42, 0.62);
            backdrop-filter: blur(5px);
            justify-content: center;
            align-items: center;
            z-index: 1000;
            padding: 24px;
        }

        .modal-content {
            background: #ffffff;
            padding: 28px;
            border-radius: 18px;
            width: min(560px, 96vw);
            position: relative;
            max-height: 88vh;
            overflow-y: auto;
            box-shadow: 0 28px 80px rgba(15, 23, 42, 0.32);
            border: 1px solid rgba(148, 163, 184, 0.22);
            animation: modalPop 0.18s ease-out;
        }

        .modal-content > span[onclick*="closeModal"] {
            position: absolute;
            top: 14px;
            right: 16px;
            width: 32px;
            height: 32px;
            border-radius: 999px;
            background: #f1f5f9;
            color: #334155;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1.35rem;
            line-height: 1;
            transition: 0.2s;
        }

        .modal-content > span[onclick*="closeModal"]:hover {
            background: #e2e8f0;
            color: #0f172a;
        }

        .modal-content h3 {
            font-size: 1.2rem;
            font-weight: 800;
            color: #0f172a;
            margin-bottom: 18px;
            padding-right: 38px;
        }

        @keyframes modalPop {
            from { opacity: 0; transform: translateY(10px) scale(.98); }
            to { opacity: 1; transform: translateY(0) scale(1); }
        }

        .form-group { margin-bottom: 15px; }
        .form-group label {
            display: block;
            margin-bottom: 5px;
            font-weight: 500;
            font-size: 0.9rem;
        }

        .form-group input,
        .form-group select,
        .form-group textarea {
            width: 100%;
            padding: 8px;
            border: 1px solid #d1d5db;
            border-radius: 6px;
            font-size: 0.9rem;
        }

        .form-group textarea {
            resize: vertical;
            min-height: 100px;
            font-family: inherit;
        }

        .char-count {
            text-align: right;
            font-size: 0.75rem;
            color: #6b7280;
            margin-top: 2px;
        }

        .detail-row {
            display: flex;
            justify-content: space-between;
            padding: 8px 0;
            border-bottom: 1px solid #f3f4f6;
            font-size: 0.9rem;
            gap: 10px;
        }

        .detail-label { font-weight: 600; color: #64748b; }
        .section { display: none; }
        .section.active { display: block; }

        .settings-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 15px;
        }

        .settings-card {
            background: white;
            padding: 15px;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.05);
            display: flex;
            flex-direction: column;
            max-height: 500px;
        }

        .settings-card h3 {
            margin-bottom: 10px;
            color: #374151;
            border-bottom: 2px solid #f3f4f6;
            padding-bottom: 8px;
            display: flex;
            align-items: center;
            gap: 10px;
            font-size: 1.1rem;
        }

        .settings-list {
            list-style: none;
            overflow-y: auto;
            flex: 1;
            border: 1px solid #e5e7eb;
            border-radius: 6px;
            margin-bottom: 10px;
            background: #fafafa;
        }

        .settings-item {
            padding: 8px;
            border-bottom: 1px solid #f3f4f6;
            display: flex;
            justify-content: space-between;
            align-items: center;
            background: #fff;
            transition: 0.2s;
        }

        .settings-item:hover { background: #f9fafb; }
        .settings-item:last-child { border-bottom: none; }

        .item-info { display: flex; flex-direction: column; }
        .item-main { font-weight: 600; font-size: 0.85rem; color: #1f2937; }
        .item-sub { font-size: 0.7rem; color: #6b7280; }

        .item-actions { display: flex; gap: 5px; }
        .btn-mini {
            padding: 2px 6px;
            border-radius: 4px;
            border: none;
            cursor: pointer;
            color: white;
            font-size: 0.7rem;
        }

        .add-row {
            display: flex;
            gap: 10px;
            margin-top: auto;
        }

        #img-preview-container { margin-top: 10px; text-align: center; }
        #edit-img-preview {
            max-height: 100px;
            border-radius: 5px;
            border: 1px solid #ddd;
            display: none;
        }

        #remove-img-btn {
            background: #ef4444;
            color: white;
            border: none;
            padding: 4px 8px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 0.8rem;
            margin-top: 5px;
            display: none;
        }

        .parts-box {
            background:#f9fafb;
            border:1px solid #e5e7eb;
            border-radius:6px;
            padding:10px;
        }

        .part-row {
            display:flex;
            justify-content:space-between;
            align-items:center;
            gap:8px;
            padding:6px 0;
            border-bottom:1px solid #e5e7eb;
        }

        .part-row:last-child { border-bottom:none; }

        .inventory-low {
            color: #dc2626;
            font-weight: 700;
        }

        .dashboard-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
            gap: 12px;
            margin-bottom: 15px;
        }

        .summary-card {
            background: white;
            border-radius: 10px;
            padding: 14px;
            box-shadow: 0 2px 6px rgba(0,0,0,0.06);
            border: 1px solid #e5e7eb;
        }

        .summary-card-label {
            color: #64748b;
            font-size: 0.75rem;
            text-transform: uppercase;
            letter-spacing: 0.05em;
            margin-bottom: 6px;
            font-weight: 700;
        }

        .summary-card-value {
            font-size: 1.7rem;
            font-weight: 800;
            color: #0f172a;
        }

        .summary-card-note {
            margin-top: 4px;
            font-size: 0.78rem;
            color: #64748b;
        }

        .today-jobs-card {
            background: white;
            border-radius: 10px;
            padding: 14px;
            box-shadow: 0 2px 6px rgba(0,0,0,0.06);
            border: 1px solid #e5e7eb;
            margin-bottom: 15px;
        }
        .today-jobs-card h3 { display: flex; align-items: center; gap: 8px; font-size: 1rem; color: #0f172a; margin-bottom: 10px; }
        .today-jobs-list { display: grid; gap: 8px; }
        .today-job-item {
            border: 1px solid #e5e7eb;
            border-radius: 8px;
            padding: 10px;
            background: #f8fafc;
            display: grid;
            grid-template-columns: 1fr auto;
            gap: 6px 10px;
            align-items: center;
        }
        .today-job-title { font-weight: 800; color: #0f172a; font-size: 0.9rem; }
        .today-job-meta { color: #64748b; font-size: 0.78rem; line-height: 1.4; }

        .alert-box {
            background: #fff7ed;
            border: 1px solid #fdba74;
            color: #9a3412;
            border-radius: 10px;
            padding: 12px 14px;
            margin-bottom: 15px;
        }

        .alert-box strong {
            display: block;
            margin-bottom: 4px;
        }

        .alert-box.hidden {
            display: none;
        }

        .overdue-row {
            background: #fff7f7;
        }

        .overdue-badge {
            display: inline-block;
            margin-left: 6px;
            padding: 2px 8px;
            border-radius: 999px;
            background: #fee2e2;
            color: #b91c1c;
            font-size: 0.7rem;
            font-weight: 700;
            vertical-align: middle;
        }

        .parts-list-view {
            margin-top: 12px;
            background: #f8fafc;
            border: 1px solid #e5e7eb;
            border-radius: 8px;
            padding: 10px;
        }

        .backup-actions {
            display: flex;
            gap: 10px;
            flex-wrap: wrap;
            margin-bottom: 15px;
        }

        
        .auth-overlay {
            position: fixed; inset: 0; background: rgba(15,23,42,.68);
            display: none; align-items: center; justify-content: center; z-index: 5000;
            padding: 20px;
        }
        .auth-card {
            width: 100%; max-width: 420px; background: white; border-radius: 16px; padding: 24px;
            box-shadow: 0 24px 64px rgba(0,0,0,.22);
        }
        .auth-card h2 { margin-bottom: 8px; }
        .auth-card p { color: #64748b; margin-bottom: 18px; }
        .auth-row { margin-bottom: 12px; }
        .auth-row input, .auth-row select { width: 100%; padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 8px; }
        .auth-error { color: #b91c1c; font-size: 0.85rem; min-height: 1.2rem; margin: 8px 0 0; }
        .sidebar-account { margin-top:auto; padding-top:12px; border-top:1px solid rgba(255,255,255,0.12); display:flex; flex-direction:column; gap:8px; }
        .user-pill { display:block; background:rgba(255,255,255,0.12); border:1px solid rgba(255,255,255,0.18); border-radius:10px; padding:8px 10px; font-size:.8rem; font-weight:600; color:#fff; text-align:center; }
        .sidebar-auth-btn { width:100%; padding:8px 10px; font-size:0.85rem; }
        .hidden-auth { display:none !important; }


        .empty-state {
            text-align: center;
            color: #64748b;
            padding: 28px 16px;
        }
        .empty-state i {
            font-size: 1.8rem;
            margin-bottom: 10px;
            color: #94a3b8;
            display: block;
        }
        .activity-log-list {
            list-style: none;
            overflow-y: auto;
            flex: 1;
            border: 1px solid #e5e7eb;
            border-radius: 6px;
            background: #fafafa;
        }
        .activity-log-item {
            padding: 10px 12px;
            border-bottom: 1px solid #e5e7eb;
            background: #fff;
        }
        .activity-log-item:last-child { border-bottom: none; }
        .activity-log-top {
            display:flex;
            align-items:center;
            justify-content:space-between;
            gap:10px;
            margin-bottom:4px;
        }
        .activity-log-title { font-weight:700; font-size:0.82rem; color:#0f172a; }
        .activity-log-meta { font-size:0.72rem; color:#64748b; }
        .activity-log-details { font-size:0.78rem; color:#475569; line-height:1.4; }
        .action-modal-card {
            width: min(460px, 96vw);
            background: #ffffff;
            border-radius: 18px;
            padding: 24px;
            box-shadow: 0 28px 80px rgba(15, 23, 42, 0.34);
            border: 1px solid rgba(148, 163, 184, 0.22);
            animation: modalPop 0.18s ease-out;
        }
        .action-modal-title { font-size: 1.18rem; font-weight: 850; margin-bottom: 8px; color:#0f172a; }
        .action-modal-message { color:#64748b; line-height:1.55; margin-bottom: 16px; }
        .action-modal-actions { display:flex; justify-content:flex-end; gap:10px; margin-top: 18px; }
        .btn-secondary { background:#e5e7eb; color:#111827; }
        .btn-secondary:hover { background:#d1d5db; }
        .loading-inline { opacity: .7; pointer-events: none; }
        [data-role-guard="manager"] { display: none; }
        [data-role-guard="admin"] { display: none; }


        .master-list-card {
            margin-top: 22px;
            background: #fff;
            border: 1px solid #e5e7eb;
            border-radius: 10px;
            padding: 15px;
            box-shadow: 0 2px 6px rgba(0,0,0,0.06);
        }
        .master-list-card .data-table-container { box-shadow: none; padding: 0; }
        .master-list-header { align-items: flex-start; margin-bottom: 12px; }
        .master-list-tab-active { background: var(--primary) !important; color: #fff !important; }


        /* Windows-style centered popup upgrade */
        .modal {
            background: rgba(15, 23, 42, 0.58) !important;
            backdrop-filter: blur(4px);
            align-items: center !important;
            justify-content: center !important;
        }

        .modal-content,
        .action-modal-card {
            border-radius: 10px !important;
            border: 1px solid #cbd5e1 !important;
            box-shadow: 0 24px 80px rgba(15, 23, 42, 0.38), 0 2px 8px rgba(15, 23, 42, 0.18) !important;
            animation: windowsPop 0.16s ease-out !important;
        }

        .modal-content h3,
        .action-modal-title {
            background: linear-gradient(180deg, #f8fafc, #e2e8f0);
            margin: -28px -28px 18px -28px !important;
            padding: 14px 48px 14px 18px !important;
            border-bottom: 1px solid #cbd5e1;
            border-radius: 10px 10px 0 0;
            font-weight: 800;
            color: #0f172a;
        }

        .modal-content > span[onclick*="closeModal"] {
            top: 9px !important;
            right: 10px !important;
            width: 30px !important;
            height: 30px !important;
            background: transparent !important;
            border-radius: 6px !important;
            color: #475569 !important;
            font-weight: 700 !important;
        }

        .modal-content > span[onclick*="closeModal"]:hover {
            background: #ef4444 !important;
            color: #ffffff !important;
        }

        .form-group {
            margin-bottom: 11px !important;
        }

        .form-group label {
            font-size: 0.82rem !important;
            font-weight: 700 !important;
            color: #334155 !important;
        }

        .form-group input,
        .form-group select,
        .form-group textarea {
            padding: 7px 9px !important;
            border-radius: 6px !important;
        }

        .modal-content .btn,
        .action-modal-card .btn {
            border-radius: 6px !important;
        }

        @keyframes windowsPop {
            from { opacity: 0; transform: translateY(8px) scale(0.985); }
            to { opacity: 1; transform: translateY(0) scale(1); }
        }

        @media (max-width: 768px) {
            .sidebar { display: none; }
            .bottom-nav {
                display: flex;
                position: fixed;
                bottom: 0;
                left: 0;
                width: 100%;
                background: #1e293b;
                color: white;
                justify-content: space-around;
                padding: 12px 0;
                z-index: 900;
                box-shadow: 0 -4px 12px rgba(0,0,0,0.1);
                overflow-x: auto;
            }

            .nav-btn {
                background: none;
                border: none;
                color: #94a3b8;
                cursor: pointer;
                display: flex;
                flex-direction: column;
                align-items: center;
                gap: 4px;
                font-size: 0.65rem;
                font-weight: 500;
                min-width: 65px;
            }

            .nav-btn.active { color: var(--primary); }
            .main-content { padding: 15px; padding-bottom: 90px; }
            .header { flex-direction: column; align-items: flex-start; gap: 12px; }
            .header h2 { font-size: 1.3rem; }
            
            .header-actions {
                width: 100%;
                justify-content: space-between;
                flex-wrap: wrap; 
                gap: 10px;
            }
            .search-box { flex: 1; width: 100%; }
            .search-box input { width: 100%; }
            .btn { white-space: nowrap; font-size: 0.85rem; padding: 8px 12px; }
            .data-table-container { padding: 0; box-shadow: none; background: transparent; }
            table { min-width: 760px; background: white; border-radius: 8px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
            .modal { padding: 14px; }
            .modal-content { width: 100%; max-height: 88vh; padding: 22px; border-radius: 16px; }
            .settings-grid { grid-template-columns: 1fr; }
            #toast-container { right: 10px; left: 10px; width: auto; }
        }

        /* =========================================================
           MOBILE JOB-ONLY PATCH V2 - keeps original backend + JS
           This patch does not remove original modals/functions.
           It only changes the phone layout and bottom menu.
        ========================================================= */
        @media (max-width: 768px) {
            html, body { height: auto; min-height: 100vh; overflow-x: hidden; overflow-y: auto; background: #eef2f7; }
            body { display: block; padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
            .sidebar { display: none !important; }
            .main-content { width: 100%; padding: 12px 12px calc(104px + env(safe-area-inset-bottom)); overflow: visible; }
            #schedule, #assets, #locations, #engineers, #inventory, #settings { display: none !important; }
            .section.active { display: block; }
            .dashboard-grid, #dashboard-today-jobs, #dashboard-low-stock { display: none !important; }
            .header { position: sticky; top: 0; z-index: 20; margin: -12px -12px 14px; padding: 14px 14px 12px; background: linear-gradient(135deg, #0f172a, #1e3a8a); color: #fff; border-radius: 0 0 18px 18px; box-shadow: 0 8px 24px rgba(15,23,42,.22); flex-direction: column; align-items: stretch; gap: 10px; }
            .header h2 { color: #fff; font-size: 1.25rem; line-height: 1.2; margin: 0; }
            .header .item-sub { color: rgba(255,255,255,.78); }
            .header-actions { width: 100%; display: flex; gap: 8px; flex-wrap: wrap; }
            .header-actions .btn, .header-actions .btn-danger, .header-actions .btn-critical, .header-actions select, .search-box { flex: 1 1 100%; width: 100%; }
            .search-box input, #history-asset-filter { width: 100% !important; height: 46px; border-radius: 14px !important; border: 1px solid rgba(255,255,255,.25) !important; background: rgba(255,255,255,.94) !important; font-size: 16px !important; }
            .btn, .btn-critical, .btn-danger, .btn-secondary { min-height: 46px; border-radius: 14px !important; font-size: .96rem !important; font-weight: 800; box-shadow: 0 4px 12px rgba(15,23,42,.12); }
            .data-table-container { background: transparent !important; padding: 0 !important; box-shadow: none !important; overflow: visible !important; }
            #wo-table, #master-table, #history-table { min-width: 0 !important; width: 100% !important; display: block; background: transparent !important; box-shadow: none !important; border-radius: 0 !important; }
            #wo-table thead, #master-table thead, #history-table thead { display: none !important; }
            #wo-table tbody, #master-table tbody, #history-table tbody { display: block; width: 100%; }
            #wo-table tr, #master-table tr, #history-table tr { display: block; width: 100%; margin: 0 0 12px; padding: 13px; background: #fff; border: 1px solid #e2e8f0; border-radius: 18px; box-shadow: 0 6px 18px rgba(15,23,42,.08); }
            #wo-table td, #master-table td, #history-table td { display: block; width: 100% !important; min-width: 0 !important; border: 0 !important; padding: 4px 0 !important; white-space: normal !important; font-size: .94rem; color: #334155; }
            #wo-table td:first-child, #master-table td:first-child, #history-table td:nth-child(2) { color: #0f172a; font-size: 1rem; font-weight: 900; margin-bottom: 3px; }
            #history-table td:first-child { display: none !important; }
            #wo-table td:nth-child(2)::before, #master-table td:nth-child(2)::before, #history-table td:nth-child(4)::before { content: 'Asset: '; font-weight: 800; color: #64748b; }
            #wo-table td:nth-child(3)::before, #master-table td:nth-child(3)::before, #history-table td:nth-child(5)::before { content: 'Location: '; font-weight: 800; color: #64748b; }
            #wo-table td:nth-child(4)::before, #master-table td:nth-child(4)::before, #history-table td:nth-child(6)::before { content: 'Requested: '; font-weight: 800; color: #64748b; }
            #history-table td:nth-child(3)::before { content: 'Scheduled: '; font-weight: 800; color: #64748b; }
            .desc-cell { max-width: none !important; background: #f8fafc; padding: 9px 10px !important; border-radius: 12px; margin: 7px 0; }
            .priority { padding: 7px 12px; border-radius: 999px; font-size: .82rem; }
            .status-select { width: 100% !important; height: 48px !important; border-radius: 14px !important; margin-top: 8px; font-size: 16px !important; border: 1px solid #cbd5e1 !important; text-align: left; padding: 0 12px !important; appearance: auto !important; }
            .action-btn-group { display: grid !important; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px !important; margin-top: 10px; width: 100%; white-space: normal !important; }
            .btn-icon { width: 100% !important; height: 46px !important; border-radius: 14px !important; font-size: 1rem !important; }
            .modal { padding: 10px !important; align-items: flex-end !important; }
            .modal-content, .action-modal-card { width: 100% !important; max-width: 100% !important; max-height: 92vh !important; border-radius: 20px 20px 0 0 !important; padding: 22px !important; }
            .modal-content h3, .action-modal-title { margin: -22px -22px 16px -22px !important; padding: 16px 52px 16px 18px !important; font-size: 1.12rem !important; }
            .form-group input, .form-group select, .form-group textarea { min-height: 46px; font-size: 16px !important; border-radius: 13px !important; padding: 10px 12px !important; }
            .form-group textarea { min-height: 118px; }
            #toast-container { top: 10px; left: 10px; right: 10px; width: auto; }
            .toast { min-width: 0; width: 100%; transform: none; animation: none; border-radius: 14px; }
            .bottom-nav { display: grid !important; grid-template-columns: repeat(5, minmax(0, 1fr)); position: fixed; left: 0; right: 0; bottom: 0; width: 100%; padding: 7px 4px calc(7px + env(safe-area-inset-bottom)); background: rgba(15,23,42,.98); color: white; z-index: 900; box-shadow: 0 -8px 26px rgba(15,23,42,.28); overflow: visible; }
            .nav-btn { min-width: 0 !important; border: none; background: transparent; color: #94a3b8; padding: 7px 2px; border-radius: 14px; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: .66rem; font-weight: 800; }
            .nav-btn i { font-size: 1.05rem; }
            .nav-btn.active { color: #fff; background: rgba(37,99,235,.30); }
        }

        @media (max-width: 768px) {
            .modal { backdrop-filter: none !important; }
            #wo-table tr, #master-table tr, #history-table tr { box-shadow: 0 3px 10px rgba(15,23,42,.06) !important; }
            .header { box-shadow: 0 4px 14px rgba(15,23,42,.16) !important; }
            .bottom-nav { box-shadow: 0 -4px 14px rgba(0,0,0,.16) !important; }
        }


        /* =========================================================
           MOBILE CENTERED POPUP PATCH V4
           Keeps original modal functions, but makes phone popups
           open as centered cards instead of bottom sheets.
        ========================================================= */
        @media (max-width: 768px) {
            .modal {
                padding: 14px !important;
                align-items: center !important;
                justify-content: center !important;
                background: rgba(15, 23, 42, 0.68) !important;
                backdrop-filter: blur(3px) !important;
            }

            .modal-content,
            .action-modal-card,
            .error-box,
            .auth-card {
                width: min(94vw, 430px) !important;
                max-width: 430px !important;
                max-height: 86vh !important;
                overflow-y: auto !important;
                border-radius: 22px !important;
                padding: 22px !important;
                box-shadow: 0 24px 70px rgba(15, 23, 42, 0.42) !important;
                border: 1px solid rgba(226, 232, 240, 0.95) !important;
                animation: mobileCenteredPop 0.18s ease-out !important;
            }

            .modal-content h3,
            .action-modal-title {
                margin: -22px -22px 18px -22px !important;
                padding: 17px 56px 17px 18px !important;
                border-radius: 22px 22px 0 0 !important;
                background: linear-gradient(180deg, #ffffff, #eef2f7) !important;
                border-bottom: 1px solid #dbe4ef !important;
                color: #0f172a !important;
                font-size: 1.08rem !important;
                line-height: 1.25 !important;
            }

            .modal-content > span[onclick*="closeModal"] {
                top: 10px !important;
                right: 10px !important;
                width: 38px !important;
                height: 38px !important;
                border-radius: 999px !important;
                background: #e2e8f0 !important;
                color: #0f172a !important;
                font-size: 1.45rem !important;
                font-weight: 900 !important;
                display: flex !important;
                align-items: center !important;
                justify-content: center !important;
                z-index: 3 !important;
            }

            .modal-content > span[onclick*="closeModal"]:hover,
            .modal-content > span[onclick*="closeModal"]:active {
                background: #ef4444 !important;
                color: #ffffff !important;
            }

            .modal-content .form-group {
                margin-bottom: 13px !important;
            }

            .modal-content .btn,
            .action-modal-card .btn,
            .action-modal-card .btn-danger,
            .action-modal-card .btn-secondary {
                min-height: 48px !important;
                border-radius: 15px !important;
                font-size: 1rem !important;
            }

            .action-modal-actions {
                display: grid !important;
                grid-template-columns: 1fr 1fr !important;
                gap: 10px !important;
            }

            #imgModal .modal-content {
                background: transparent !important;
                border: none !important;
                box-shadow: none !important;
                padding: 0 !important;
                width: 94vw !important;
                max-width: 94vw !important;
            }

            #full-image {
                max-width: 94vw !important;
                max-height: 82vh !important;
                border-radius: 18px !important;
                box-shadow: 0 18px 50px rgba(0,0,0,.45) !important;
            }
        }

        @keyframes mobileCenteredPop {
            from { opacity: 0; transform: translateY(10px) scale(0.96); }
            to { opacity: 1; transform: translateY(0) scale(1); }
        }

    

        /* Mobile action loading overlay */
        #ifix-loading-overlay {
            display: none;
            position: fixed;
            inset: 0;
            z-index: 12000;
            background: rgba(15, 23, 42, 0.62);
            backdrop-filter: blur(4px);
            align-items: center;
            justify-content: center;
            padding: 18px;
        }
        #ifix-loading-overlay.active { display: flex; }
        .ifix-loading-card {
            width: min(320px, 88vw);
            background: #ffffff;
            border-radius: 18px;
            padding: 24px 20px;
            text-align: center;
            box-shadow: 0 24px 80px rgba(15, 23, 42, 0.34);
            border: 1px solid rgba(226, 232, 240, 0.9);
        }
        .ifix-loading-spinner {
            width: 42px;
            height: 42px;
            border: 4px solid #dbeafe;
            border-top-color: var(--primary);
            border-radius: 999px;
            margin: 0 auto 14px;
            animation: ifixSpin 0.8s linear infinite;
        }
        .ifix-loading-title { font-weight: 850; color: #0f172a; font-size: 1.05rem; margin-bottom: 4px; }
        .ifix-loading-subtitle { color: #64748b; font-size: 0.86rem; line-height: 1.45; }
        @keyframes ifixSpin { to { transform: rotate(360deg); } }
