@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    --primary-ring: rgba(37, 99, 235, 0.2);
    
    --secondary: #64748b;
    --secondary-hover: #475569;
    
    --success: #10b981;
    --success-light: #ecfdf5;
    --warning: #f59e0b;
    --warning-light: #fffbeb;
    --danger: #ef4444;
    --danger-light: #fef2f2;
    --info: #06b6d4;
    --info-light: #ecfeff;
    --purple: #8b5cf6;
    --purple-light: #f5f3ff;

    --sidebar-bg: #0f172a;
    --sidebar-surface: #1e293b;
    --sidebar-border: #334155;
    --sidebar-text: #94a3b8;
    --sidebar-text-active: #ffffff;
    --sidebar-active-bg: rgba(37, 99, 235, 0.15);
    --sidebar-active-border: #3b82f6;

    --bg-main: #f8fafc;
    --surface: #ffffff;
    --surface-border: #e2e8f0;
    --surface-border-subtle: #f1f5f9;

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;

    --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-sm: 0 1px 3px 0 rgba(15, 23, 42, 0.08), 0 1px 2px -1px rgba(15, 23, 42, 0.08);
    --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.04);
    --shadow-xl: 0 20px 25px -5px rgba(15, 23, 42, 0.1), 0 8px 10px -6px rgba(15, 23, 42, 0.05);

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden !important;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}

/* Remove all scrollbars across browsers */
::-webkit-scrollbar {
    width: 0px !important;
    height: 0px !important;
    display: none !important;
}

::-webkit-scrollbar-horizontal,
::-webkit-scrollbar-vertical {
    display: none !important;
    width: 0px !important;
    height: 0px !important;
}

body {
    font-family: 'Plus Jakarta Sans', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden !important;
}

/* Layout Structure */
.erp-container {
    display: flex;
    min-height: 100vh;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

.erp-sidebar {
    width: 250px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1000;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.12);
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.erp-sidebar::-webkit-scrollbar {
    display: none;
    width: 0;
}

.erp-main-wrapper {
    margin-left: 250px;
    width: calc(100% - 250px);
    max-width: calc(100% - 250px);
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background-color: var(--bg-main);
    overflow-x: hidden;
    transition: margin-left 0.3s ease, width 0.3s ease, max-width 0.3s ease;
}

/* Sidebar Branding */
.sidebar-brand {
    padding: 16px 14px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    border-bottom: 1px solid var(--sidebar-border);
    background: linear-gradient(180deg, rgba(30, 41, 59, 0.5) 0%, rgba(15, 23, 42, 0.2) 100%);
}

.sidebar-brand img {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: contain;
    background: #fff;
    padding: 2px;
    box-shadow: 0 0 12px rgba(59, 130, 246, 0.4);
}

.sidebar-brand .brand-title {
    color: #fff;
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.sidebar-brand .brand-sub {
    font-size: 0.72rem;
    color: var(--sidebar-text);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* Sidebar Navigation */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 16px 12px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.sidebar-nav::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

.nav-section-title {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #64748b;
    padding: 14px 12px 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 14px;
    border-radius: var(--radius-md);
    color: #94a3b8;
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 500;
    transition: all 0.15s ease;
    margin-bottom: 2px;
}

.nav-item:hover {
    color: #f1f5f9;
    background: rgba(255, 255, 255, 0.05);
}

.nav-item.active {
    color: #ffffff;
    background: var(--sidebar-active-bg);
    border-left: 3px solid var(--sidebar-active-border);
    font-weight: 600;
}

.nav-item i {
    font-size: 1.05rem;
    width: 20px;
    text-align: center;
    color: #64748b;
}

.nav-item.active i, .nav-item:hover i {
    color: #60a5fa;
}

/* Header Navbar */
.erp-header {
    min-height: 64px;
    height: auto;
    background: var(--surface);
    border-bottom: 1px solid var(--surface-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 20px;
    padding-top: max(10px, env(safe-area-inset-top));
    position: sticky;
    top: 0;
    z-index: 900;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
    max-width: 520px;
}

.header-search {
    position: relative;
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
}

.header-cam-btn {
    position: absolute;
    right: 8px;
    background: transparent;
    border: none;
    color: var(--primary);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    min-height: 40px;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.header-user-link {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: inherit;
}

.header-user-meta {
    display: flex;
    flex-direction: column;
}

.header-user-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.2;
}

.header-user-email {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.sidebar-close-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #e2e8f0;
    font-size: 1.15rem;
    cursor: pointer;
    flex-shrink: 0;
}

.sidebar-close-btn:hover {
    background: rgba(255, 255, 255, 0.16);
}

/* Workshop layout helpers */
.erp-ops-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.erp-dashboard-split {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
}

.erp-action-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.erp-action-tiles > a {
    min-height: 96px;
    touch-action: manipulation;
}

.header-search input {
    width: 100%;
    padding: 10px 44px 10px 38px;
    border: 1px solid var(--surface-border);
    border-radius: 999px;
    background: #f8fafc;
    font-size: 0.9rem;
    min-height: 44px;
    outline: none;
    transition: all 0.2s ease;
}

.header-search input:focus {
    background: #fff;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-ring);
}

.header-search i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.9rem;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 16px;
}

.user-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    background: var(--primary-light);
    color: var(--primary);
    letter-spacing: 0.04em;
}

.user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2563eb, #3b82f6);
    color: white;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.3);
}

/* Main Content Area */
.erp-content {
    flex: 1;
    padding: 18px 22px;
    min-width: 0;
    max-width: 100%;
}

/* Page Header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 14px;
}

.page-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.page-subtitle {
    font-size: 0.84rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* Cards & Surfaces */
.erp-card {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 18px 20px;
    margin-bottom: 20px;
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.erp-card:hover {
    box-shadow: var(--shadow-md);
}

.card-header-custom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--surface-border-subtle);
}

.card-title-custom {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* KPI Cards Grid */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-lg);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
}

.kpi-card.blue::before { background: var(--primary); }
.kpi-card.amber::before { background: var(--warning); }
.kpi-card.emerald::before { background: var(--success); }
.kpi-card.purple::before { background: var(--purple); }
.kpi-card.cyan::before { background: var(--info); }
.kpi-card.rose::before { background: var(--danger); }

.kpi-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    flex-shrink: 0;
}

.kpi-icon.blue { background: var(--primary-light); color: var(--primary); }
.kpi-icon.amber { background: var(--warning-light); color: var(--warning); }
.kpi-icon.emerald { background: var(--success-light); color: var(--success); }
.kpi-icon.purple { background: var(--purple-light); color: var(--purple); }
.kpi-icon.cyan { background: var(--info-light); color: var(--info); }
.kpi-icon.rose { background: var(--danger-light); color: var(--danger); }

.kpi-value {
    font-size: 1.65rem;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1.1;
}

.kpi-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
    margin-top: 4px;
}

/* Status Badges */
.badge-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.badge-status::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.status-RECEIVED { background: #f1f5f9; color: #475569; }
.status-RECEIVED::before { background: #64748b; }

.status-INSPECTION, .status-DISMANTLING { background: #fef3c7; color: #b45309; }
.status-INSPECTION::before, .status-DISMANTLING::before { background: #f59e0b; }

.status-REWINDING, .status-VARNISHING_VPI { background: #eff6ff; color: #1d4ed8; }
.status-REWINDING::before, .status-VARNISHING_VPI::before { background: #3b82f6; }

.status-MECHANICAL_REPAIR, .status-MACHINING, .status-BALANCING { background: #f5f3ff; color: #6d28d9; }
.status-MECHANICAL_REPAIR::before, .status-MACHINING::before, .status-BALANCING::before { background: #8b5cf6; }

.status-TESTING { background: #ecfeff; color: #0e7490; }
.status-TESTING::before { background: #06b6d4; }

.status-REWORK { background: #fef2f2; color: #b91c1c; }
.status-REWORK::before { background: #ef4444; }

.status-FINISHED, .status-READY_FOR_DISPATCH { background: #ecfdf5; color: #047857; }
.status-FINISHED::before, .status-READY_FOR_DISPATCH::before { background: #10b981; }

.status-DISPATCHED { background: #e0e7ff; color: #4338ca; }
.status-DISPATCHED::before { background: #6366f1; }

.status-CANCELLED { background: #fee2e2; color: #991b1b; }
.status-CANCELLED::before { background: #dc2626; }

/* Buttons */
.btn-erp {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.15s ease;
    border: 1px solid transparent;
    text-decoration: none;
    line-height: 1.25;
}

.btn-erp:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-erp-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 1px 2px rgba(37, 99, 235, 0.2);
}

.btn-erp-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    box-shadow: 0 4px 8px rgba(37, 99, 235, 0.3);
}

.btn-erp-secondary {
    background: white;
    border-color: var(--surface-border);
    color: var(--text-primary);
}

.btn-erp-secondary:hover:not(:disabled) {
    background: #f8fafc;
    border-color: #cbd5e1;
}

.btn-erp-danger {
    background: var(--danger);
    color: white;
}

.btn-erp-danger:hover:not(:disabled) {
    background: #dc2626;
}

.btn-erp-sm {
    padding: 5px 8px;
    font-size: 0.78rem;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    line-height: 1;
}

/* Modern Data Tables */
.table-responsive {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
}

/* Slim scrollbar only if columns overflow on very small viewports */
.table-responsive::-webkit-scrollbar {
    height: 4px !important;
    display: block !important;
}
.table-responsive::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}
.table-responsive::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}
.table-responsive::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.erp-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.84rem;
}

.erp-table th {
    background: #f8fafc;
    color: var(--text-secondary);
    font-weight: 600;
    text-align: left;
    padding: 10px 10px;
    border-bottom: 1px solid var(--surface-border);
    white-space: nowrap;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.erp-table td {
    padding: 10px 10px;
    border-bottom: 1px solid var(--surface-border-subtle);
    color: var(--text-primary);
    vertical-align: middle;
    font-size: 0.84rem;
}

.erp-table th:last-child,
.erp-table td:last-child {
    text-align: right;
    padding-right: 12px;
    white-space: nowrap;
}

.erp-table tbody tr {
    transition: background-color 0.15s ease;
}

.erp-table tbody tr:hover {
    background-color: #f8fafc;
}

.erp-table td.mono {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    font-weight: 500;
}

/* Modals */
.erp-modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
}

.erp-modal-backdrop.active {
    display: flex;
}

.erp-modal {
    background: white;
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 600px;
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--surface-border);
    overflow: hidden;
    animation: modalSlide 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalSlide {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.erp-modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--surface-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.erp-modal-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
}

.erp-modal-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.erp-modal-close:hover {
    color: var(--text-primary);
    background: #f1f5f9;
}

.erp-modal-body {
    padding: 24px;
    max-height: calc(85vh - 140px);
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.erp-modal-body::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

.erp-modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--surface-border);
    background: #f8fafc;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* Forms */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.form-label.required::after {
    content: ' *';
    color: var(--danger);
}

.form-control-erp {
    width: 100%;
    padding: 9px 12px;
    font-size: 0.88rem;
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-md);
    background: #ffffff;
    color: var(--text-primary);
    outline: none;
    transition: all 0.15s ease;
    font-family: inherit;
}

.form-control-erp:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-ring);
}

.form-control-erp.is-invalid {
    border-color: var(--danger);
    background-color: #fffdfd;
}

.invalid-feedback {
    color: var(--danger);
    font-size: 0.75rem;
    margin-top: 4px;
    display: block;
}

.barcode-scanner-box {
    display: flex;
    gap: 8px;
    align-items: center;
    background: #f8fafc;
    padding: 8px 12px;
    border: 2px dashed #cbd5e1;
    border-radius: var(--radius-md);
}

.barcode-scanner-box input {
    border: none;
    background: transparent;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.95rem;
    font-weight: 600;
    width: 100%;
    outline: none;
}

/* Toast Notifications */
.erp-toast-container {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.erp-toast {
    background: white;
    border-radius: var(--radius-md);
    padding: 14px 18px;
    box-shadow: var(--shadow-lg);
    border-left: 4px solid var(--primary);
    min-width: 300px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.88rem;
    font-weight: 500;
    animation: toastIn 0.25s ease;
}

.erp-toast.success { border-left-color: var(--success); }
.erp-toast.error { border-left-color: var(--danger); }
.erp-toast.warning { border-left-color: var(--warning); }

@keyframes toastIn {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

/* Footer */
.erp-footer {
    background: var(--surface);
    border-top: 1px solid var(--surface-border);
    padding: 16px 28px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Responsive Viewport Optimizations (legacy alias: use .show) */
@media (max-width: 992px) {
    .erp-sidebar {
        transform: translateX(-100%);
    }
    .erp-sidebar.show {
        transform: translateX(0);
    }
    .erp-main-wrapper {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }
}

/* DataTables ERP Styling */
.dataTables_wrapper {
    width: 100% !important;
    font-family: inherit;
    font-size: 0.84rem;
}
.dataTables_wrapper::after {
    content: "";
    display: table;
    clear: both;
}
.dataTables_wrapper .dataTables_length {
    float: left;
    margin-bottom: 16px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}
.dataTables_wrapper .dataTables_length select {
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-sm);
    padding: 6px 12px;
    background: #ffffff;
    color: var(--text-main);
    outline: none;
    font-size: 0.82rem;
    margin: 0 4px;
}
.dataTables_wrapper .dataTables_filter {
    float: right;
    margin-bottom: 16px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
}
.dataTables_wrapper .dataTables_filter label {
    display: flex;
    align-items: center;
    gap: 8px;
}
.dataTables_wrapper .dataTables_filter input {
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-sm);
    padding: 7px 14px;
    background: #ffffff;
    color: var(--text-main);
    outline: none;
    font-size: 0.84rem;
    min-width: 240px;
    transition: all 0.2s;
}
.dataTables_wrapper .dataTables_filter input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.12);
}
.dataTables_wrapper .dataTables_info {
    float: left;
    padding-top: 14px;
    color: var(--text-muted);
    font-size: 0.82rem;
}
.dataTables_wrapper .dataTables_paginate {
    float: right;
    padding-top: 12px;
}
.dataTables_wrapper .dataTables_paginate .paginate_button {
    padding: 5px 10px !important;
    border-radius: var(--radius-sm) !important;
    border: 1px solid var(--surface-border) !important;
    background: #ffffff !important;
    color: var(--text-main) !important;
    margin: 0 2px !important;
    font-size: 0.8rem !important;
    transition: all 0.15s ease;
}
.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    background: #f1f5f9 !important;
    color: var(--primary) !important;
    border-color: #cbd5e1 !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
    background: var(--primary) !important;
    color: #ffffff !important;
    border-color: var(--primary) !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled,
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled:hover {
    opacity: 0.45;
    cursor: not-allowed;
    background: #f8fafc !important;
    color: var(--text-muted) !important;
    border-color: var(--surface-border) !important;
}
table.dataTable {
    width: 100% !important;
    clear: both;
    margin-top: 8px !important;
    margin-bottom: 8px !important;
    border-collapse: separate !important;
    border-spacing: 0;
}
table.dataTable.no-footer {
    border-bottom: 1px solid var(--surface-border) !important;
}
table.dataTable thead th, table.dataTable thead td {
    border-bottom: 1px solid var(--surface-border) !important;
    padding: 10px 10px !important;
}
table.dataTable tbody td {
    padding: 10px 10px !important;
}
table.dataTable tbody td.dataTables_empty {
    text-align: center !important;
    padding: 32px 16px !important;
    color: var(--text-muted) !important;
    font-size: 0.88rem !important;
    background: #fafbfc;
}

/* ==========================================================================
   Mobile & Tablet Responsiveness Enhancements
   ========================================================================== */

/* Hamburger Menu Toggle */
.mobile-menu-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: var(--surface);
    border: 1px solid var(--surface-border);
    color: var(--text-primary);
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}
.mobile-menu-toggle:hover {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
}

/* Sidebar Overlay Backdrop */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(2px);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
}
.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* Touch-friendly Table Scrolling */
.table-responsive,
.dataTables_wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Screen <= 1024px: Tablet & Mobile Off-Canvas Navigation */
@media (max-width: 1024px) {
    .mobile-menu-toggle {
        display: inline-flex;
        min-width: 44px;
        min-height: 44px;
    }

    .sidebar-close-btn {
        display: inline-flex !important;
    }

    .erp-sidebar {
        width: min(300px, 88vw);
        transform: translateX(-105%);
        box-shadow: none;
        z-index: 1050;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .erp-sidebar.show {
        transform: translateX(0);
        box-shadow: 8px 0 32px rgba(0, 0, 0, 0.35);
    }

    .erp-main-wrapper {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    .erp-content {
        padding: 14px 14px 24px;
        padding-bottom: max(24px, env(safe-area-inset-bottom));
    }

    .nav-item {
        min-height: 44px;
        padding: 12px 14px;
        font-size: 0.95rem;
    }

    .erp-ops-grid,
    .erp-dashboard-split {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }

    .kpi-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
    }

    .erp-action-tiles {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }

    .erp-action-tiles > a {
        min-height: 88px !important;
        font-size: 0.78rem !important;
        padding: 14px 10px !important;
    }

    .erp-modal {
        width: calc(100vw - 24px) !important;
        max-width: 640px !important;
        max-height: calc(100vh - 32px) !important;
        margin: 16px auto !important;
    }

    .form-control-erp,
    select.form-control-erp,
    textarea.form-control-erp {
        min-height: 44px;
        font-size: 16px !important; /* prevents iOS zoom on focus */
    }

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

    .btn-erp {
        min-height: 44px;
        padding: 10px 16px;
        font-size: 0.92rem;
    }

    .barcode-scanner-box {
        flex-wrap: wrap;
        padding: 10px;
        gap: 10px;
    }

    .barcode-scanner-box input {
        min-height: 44px;
        font-size: 1rem;
        flex: 1 1 160px;
    }
}

/* Screen <= 768px: Phones & small tablets */
@media (max-width: 768px) {
    .erp-header {
        padding: 10px 12px;
        padding-top: max(10px, env(safe-area-inset-top));
        flex-wrap: wrap;
        gap: 10px;
    }

    .header-left {
        width: 100%;
        max-width: none;
        order: 1;
    }

    .header-user {
        width: 100%;
        order: 2;
        justify-content: space-between;
        gap: 8px;
    }

    .header-role-badge,
    .header-user-email,
    .header-user-meta {
        display: none !important;
    }

    .header-actions .btn-label {
        display: none;
    }

    .header-actions .btn-erp {
        width: 44px;
        min-width: 44px;
        padding: 0;
        justify-content: center;
    }

    .page-header {
        flex-direction: column;
        align-items: stretch !important;
        gap: 12px;
        margin-bottom: 1rem;
    }

    .page-header > div:last-child {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }

    .page-header > div:last-child .btn-erp {
        flex: 1 1 auto;
        justify-content: center;
    }

    .page-title {
        font-size: 1.2rem !important;
    }

    .page-subtitle {
        font-size: 0.8rem !important;
    }

    .erp-card {
        padding: 14px 12px !important;
        border-radius: 10px !important;
        margin-bottom: 14px;
    }

    .card-header-custom {
        flex-wrap: wrap;
        gap: 10px;
        margin-bottom: 14px;
        padding-bottom: 10px;
    }

    /* Stack common inline grids (with/without spaces) */
    .erp-content div[style*="grid-template-columns: 1fr 1fr"],
    .erp-content div[style*="grid-template-columns:1fr 1fr"],
    .erp-content div[style*="grid-template-columns: 1fr 1fr 1fr"],
    .erp-content div[style*="grid-template-columns:1fr 1fr 1fr"],
    .erp-content div[style*="grid-template-columns: 1fr 1fr 1fr 1fr"],
    .erp-content div[style*="grid-template-columns:1fr 1fr 1fr 1fr"],
    .erp-content div[style*="grid-template-columns: 2fr 1fr"],
    .erp-content div[style*="grid-template-columns:2fr 1fr"],
    .erp-content div[style*="grid-template-columns: 1fr 1fr 1fr 120px"],
    .erp-modal-body div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }

    .kpi-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 10px !important;
    }

    .kpi-card {
        padding: 12px 10px !important;
        gap: 10px !important;
    }

    .kpi-value {
        font-size: 1.25rem !important;
    }

    .kpi-label {
        font-size: 0.72rem !important;
    }

    .erp-table th,
    .erp-table td,
    table.dataTable thead th,
    table.dataTable tbody td {
        padding: 10px 8px !important;
        font-size: 0.8rem !important;
        white-space: nowrap;
    }

    .table-responsive {
        margin: 0 -4px;
        padding-bottom: 4px;
    }

    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter,
    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        float: none !important;
        text-align: left !important;
        width: 100%;
        margin-bottom: 10px;
    }

    .dataTables_wrapper .dataTables_filter input {
        min-width: 0 !important;
        width: 100% !important;
        min-height: 44px;
        font-size: 16px !important;
    }

    .erp-modal-backdrop {
        align-items: flex-end;
        padding: 0;
    }

    .erp-modal {
        width: 100% !important;
        max-width: 100% !important;
        max-height: 92vh !important;
        border-radius: 16px 16px 0 0 !important;
        margin: 0 !important;
    }

    .erp-modal-footer {
        flex-wrap: wrap;
        gap: 8px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .erp-modal-footer .btn-erp {
        flex: 1 1 140px;
        justify-content: center;
    }

    .erp-footer {
        flex-direction: column;
        gap: 6px;
        text-align: center;
        padding: 12px 14px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .jc-tab-btn {
        padding: 10px 12px !important;
        font-size: 0.82rem !important;
        min-height: 42px;
    }

    .erp-toast,
    .erp-toast-container {
        left: 12px !important;
        right: 12px !important;
        min-width: 0 !important;
        max-width: calc(100vw - 24px);
    }

    /* Report filter chips wrap */
    .erp-content a.btn-erp {
        touch-action: manipulation;
    }
}

/* Screen <= 480px: Small phones */
@media (max-width: 480px) {
    .kpi-grid {
        grid-template-columns: 1fr !important;
    }

    .erp-action-tiles {
        grid-template-columns: 1fr 1fr !important;
    }

    .erp-action-tiles > a span {
        font-size: 0.72rem;
        text-align: center;
        line-height: 1.25;
    }

    .header-search input {
        font-size: 16px !important;
    }

    .page-header > div:last-child .btn-erp {
        width: 100%;
    }
}

/* Landscape phones / short viewports */
@media (max-height: 500px) and (orientation: landscape) {
    .erp-sidebar {
        width: min(260px, 70vw);
    }

    .erp-modal {
        max-height: 96vh !important;
    }
}


/* ==========================================================================
   PAGINATION STYLES
   ========================================================================== */
nav[role="navigation"],
nav .pagination,
ul.pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.pagination {
    display: inline-flex;
    align-items: center;
}

.page-item {
    display: inline-block;
}

.page-link,
.pagination li a,
.pagination li span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 12px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    background-color: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-sm);
    text-decoration: none;
    transition: all 0.15s ease-in-out;
    cursor: pointer;
}

.page-link:hover,
.pagination li a:hover {
    color: var(--primary);
    background-color: var(--primary-light);
    border-color: var(--primary);
}

.page-item.active .page-link,
.pagination li.active span,
.pagination li.active a {
    color: #ffffff !important;
    background-color: var(--primary) !important;
    border-color: var(--primary) !important;
    font-weight: 600;
}

.page-item.disabled .page-link,
.pagination li.disabled span,
.pagination li.disabled a {
    color: var(--text-muted);
    background-color: var(--bg-main);
    border-color: var(--surface-border);
    cursor: not-allowed;
    opacity: 0.7;
}

/* Fallback SVG size inside pagination links */
.pagination svg,
nav[role="navigation"] svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
    display: inline-block;
    vertical-align: middle;
}


/* ==========================================================================
   PRINT STYLES — Job Card & General Print Layout
   ========================================================================== */
@media print {
    /* ── Hide all UI chrome ── */
    .erp-sidebar,
    .sidebar-overlay,
    .erp-header,
    .erp-footer,
    .erp-modal-backdrop,
    .btn-erp,
    button,
    .dataTables_wrapper .dataTables_filter,
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate,
    .header-search,
    .swal2-container,
    #cancelModal,
    #addActivityModal,
    #camera-scanner-modal,
    .no-print {
        display: none !important;
    }

    /* ── Reset layout to full-width ── */
    html, body {
        margin: 0 !important;
        padding: 0 !important;
        background: #fff !important;
        font-size: 11pt !important;
        color: #000 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .erp-container {
        display: block !important;
    }

    .erp-main-wrapper {
        margin-left: 0 !important;
        padding: 0 !important;
        width: 100% !important;
    }

    .erp-content {
        padding: 0 !important;
        margin: 0 !important;
    }

    /* ── Print-only header (company branding) ── */
    .print-header {
        display: flex !important;
        align-items: center;
        justify-content: space-between;
        border-bottom: 3px solid #1e293b;
        padding-bottom: 12px;
        margin-bottom: 16px;
    }

    .print-header .print-company-name {
        font-size: 18pt;
        font-weight: 800;
        color: #0f172a;
        letter-spacing: -0.5px;
    }

    .print-header .print-company-sub {
        font-size: 9pt;
        color: #475569;
        margin-top: 2px;
    }

    .print-header .print-doc-title {
        text-align: right;
        font-size: 14pt;
        font-weight: 700;
        color: #1e293b;
    }

    .print-header .print-doc-date {
        text-align: right;
        font-size: 8pt;
        color: #64748b;
    }

/* ── Page header area (job card title) ── */
    .page-header {
        margin-bottom: 12px !important;
        flex-direction: column !important;
    }

    .page-header > div:last-child {
        /* hide action buttons row */
        display: none !important;
    }

    .page-title {
        font-size: 14pt !important;
        color: #000 !important;
    }

    .page-subtitle {
        font-size: 9pt !important;
        color: #333 !important;
    }

    /* ── Show ALL tab content at once ── */
    .jc-tab-content {
        display: block !important;
        page-break-inside: avoid;
        margin-bottom: 12px;
    }

    /* Hide tab navigation bar */
    .jc-tab-btn {
        display: none !important;
    }

    /* The tab bar container itself */
    .jc-tab-content + .jc-tab-content {
        border-top: 1px solid #ccc;
        padding-top: 10px;
    }

    /* ── Tab section headers for print ── */
    .print-section-title {
        display: block !important;
        font-size: 12pt;
        font-weight: 700;
        color: #1e293b;
        border-bottom: 2px solid #2563eb;
        padding-bottom: 4px;
        margin: 16px 0 10px 0;
    }

    /* ── Cards ── */
    .erp-card {
        box-shadow: none !important;
        border: 1px solid #d1d5db !important;
        border-radius: 4px !important;
        padding: 10px !important;
        margin-bottom: 12px !important;
        background: #fff !important;
        page-break-inside: avoid;
    }

    /* ── Tables ── */
    .erp-table,
    .erp-table th,
    .erp-table td,
    table, th, td {
        border: 1px solid #aaa !important;
        border-collapse: collapse !important;
        font-size: 9pt !important;
        color: #000 !important;
    }

    .erp-table th {
        background: #f3f4f6 !important;
        font-weight: 700 !important;
        padding: 6px 8px !important;
    }

    .erp-table td {
        padding: 5px 8px !important;
    }

    .table-responsive {
        overflow: visible !important;
    }

    /* ── Form fields → show as static text ── */
    textarea,
    input[type="text"],
    input[type="date"],
    input[type="datetime-local"],
    input[type="number"],
    select {
        border: none !important;
        background: transparent !important;
        box-shadow: none !important;
        padding: 2px 0 !important;
        font-size: 10pt !important;
        color: #000 !important;
        -webkit-appearance: none !important;
        appearance: none !important;
        resize: none !important;
    }

    textarea {
        overflow: visible !important;
        height: auto !important;
    }

    /* ── Badges / status pills ── */
    .badge,
    span[style*="border-radius: 9999px"],
    span[style*="text-transform: uppercase"] {
        border: 1px solid #666 !important;
        background: transparent !important;
        color: #000 !important;
        font-weight: 700 !important;
        padding: 2px 6px !important;
    }

    /* ── Links ── */
    a {
        color: #000 !important;
        text-decoration: none !important;
    }

    /* ── Hide flash message alerts ── */
    div[style*="border-left: 4px solid #10b981"],
    div[style*="border-left: 4px solid #f59e0b"] {
        display: none !important;
    }

    /* ── Page break controls ── */
    h1, h2, h3, h4 {
        page-break-after: avoid;
    }

    .erp-card, .table-responsive, table {
        page-break-inside: avoid;
    }

    /* ── Footer signature area (print-only) ── */
    .print-footer {
        display: block !important;
        margin-top: 30px;
        border-top: 1px solid #999;
        padding-top: 14px;
        page-break-inside: avoid;
    }

    .print-footer .signature-grid {
        display: grid;
        grid-template-columns: 1fr 1fr 1fr;
        gap: 30px;
        margin-top: 40px;
    }

    .print-footer .signature-box {
        border-top: 1px solid #333;
        padding-top: 6px;
        text-align: center;
        font-size: 9pt;
        color: #333;
    }

    /* ── Page margins ── */
    @page {
        size: A4 portrait;
        margin: 12mm 14mm;
    }
}

/* ── Elements hidden on screen, shown in print ── */
.print-header,
.print-footer,
.print-section-title {
    display: none;
}
