/* Legacy M-ERP v4.0 design system — extracted verbatim from legacy/M-ERP_MINFINITY888_Live.html */
:root {
  --midnight: #12192B;
  --navy: #1B2C45;
  --tide: #2E7B8C;
  --mist: #7EA8B4;
  --gold: #C8A87A;
  --sunset: #A8522A;
  --fog: #EDEBE5;
  --cream: #F8F5EF;
  --white: #FFFFFF;
  --body: #18202C;
  --dim: #5A6577;
  --green: #2E8C5A;
  --green-bg: #E6F4EC;
  --amber: #B86E14;
  --amber-bg: #FEF3E2;
  --red: #C24B3D;
  --red-bg: #FDECE9;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
body {
  background: var(--cream);
  color: var(--body);
  font-family: 'Lato', 'Noto Sans Thai', -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* TOP COMMAND HEADER */
.top-hdr {
  background: var(--midnight);
  color: var(--white);
  border-bottom: 3px solid var(--gold);
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 90;
  box-shadow: 0 4px 20px rgba(0,0,0,0.22);
}
.brand-wrap { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 40px; height: 40px;
  background: var(--navy);
  border: 1.5px solid var(--gold);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Josefin Sans', sans-serif;
  font-weight: 600; font-size: 15px; letter-spacing: 1px; color: var(--gold);
  border-radius: 4px;
}
.brand-title {
  font-family: 'Josefin Sans', sans-serif;
  font-weight: 300;
  font-size: clamp(1.1rem, 0.9rem + 1vw, 1.5rem);
  letter-spacing: 5px;
  color: var(--white);
  line-height: 1.1;
}
.brand-sub {
  font-family: 'DM Mono', monospace;
  font-size: 9.5px;
  letter-spacing: 2px;
  color: var(--gold);
  text-transform: uppercase;
  margin-top: 3px;
}

.hdr-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hdr-btn {
  padding: 7px 12px;
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  border: 1px solid rgba(255,255,255,0.22);
  background: rgba(255,255,255,0.06);
  color: var(--white);
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.15s;
}
.hdr-btn:hover { background: rgba(255,255,255,0.15); border-color: var(--gold); }
.hdr-btn.gold { background: var(--gold); color: var(--midnight); border-color: var(--gold); font-weight: 700; }
.hdr-btn.green { background: var(--green); color: #fff; border-color: var(--green); font-weight: 700; }
.save-pill {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  color: #86efac;
  background: rgba(46,140,90,0.2);
  border: 1px solid rgba(46,140,90,0.5);
  padding: 5px 10px;
  border-radius: 20px;
}

/* THAI COMPANION GUIDE (Rule 2: Toggleable & Hidden on Print) */
.th-guide {
  display: none;
  background: #1B2C45;
  color: #F8F5EF;
  border-bottom: 2px solid var(--gold);
  padding: 12px 24px;
  font-family: 'Noto Sans Thai', sans-serif;
  font-size: 13px;
  line-height: 1.65;
}
.th-guide.show { display: block; }
.th-guide strong { color: var(--gold); }

/* KPI SIGNAL STRIP */
.kpi-bar {
  background: var(--navy);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
}
.kpi-item {
  padding: 12px 20px;
  border-right: 1px solid rgba(255,255,255,0.08);
}
.kpi-item:last-child { border-right: none; }
.kpi-lbl {
  font-family: 'DM Mono', monospace;
  font-size: 9px;
  letter-spacing: 1.8px;
  text-transform: uppercase;
  color: var(--mist);
}
.kpi-val {
  font-family: 'Josefin Sans', sans-serif;
  font-size: clamp(1.25rem, 1rem + 0.8vw, 1.65rem);
  font-weight: 400;
  color: var(--white);
  margin-top: 4px;
}
.kpi-note {
  font-family: 'DM Mono', monospace;
  font-size: 9.5px;
  margin-top: 2px;
  color: #cbd5e1;
}

/* NAVIGATION TABS */
.nav-tabs {
  background: var(--midnight);
  padding: 0 24px;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.nav-tab {
  padding: 12px 18px;
  font-family: 'DM Mono', monospace;
  font-size: 10.5px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: rgba(255,255,255,0.65);
  background: rgba(255,255,255,0.04);
  border: none;
  border-top: 3px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.nav-tab:hover { color: var(--white); background: rgba(255,255,255,0.1); }
.nav-tab.active {
  background: var(--cream);
  color: var(--midnight);
  border-top-color: var(--gold);
  font-weight: 700;
}

/* MAIN CONTAINER */
.main-wrap {
  max-width: 1240px;
  width: 100%;
  margin: 0 auto;
  padding: 22px 24px 60px;
  flex: 1;
  container-type: inline-size;
}
.tab-page { display: none; }
.tab-page.show { display: block; }

/* QUICK FIELD ACTION BAR (For On-Site Tomorrow!) */
.field-quick-bar {
  background: linear-gradient(135deg, #12192B 0%, #1B2C45 100%);
  border: 1px solid var(--gold);
  border-left: 6px solid var(--gold);
  border-radius: 6px;
  padding: 16px 20px;
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  color: var(--white);
  box-shadow: 0 6px 20px rgba(18,25,43,0.12);
}
.fq-title { font-size: 15px; font-weight: 700; color: var(--gold); letter-spacing: 0.5px; }
.fq-sub { font-size: 12.5px; color: #cbd5e1; margin-top: 2px; }
.fq-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.fq-btn {
  padding: 10px 15px;
  border-radius: 5px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.fq-btn:hover { background: var(--gold); color: var(--midnight); border-color: var(--gold); }
.fq-btn.primary { background: var(--gold); color: var(--midnight); border-color: var(--gold); font-weight: 700; }
.fq-btn.danger { background: var(--red); color: #fff; border-color: var(--red); }

/* CARDS & TABLES */
.card {
  background: var(--white);
  border: 1px solid #DCD7CC;
  border-radius: 5px;
  padding: 18px 20px;
  margin-bottom: 18px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.03);
  container-type: inline-size;
}
.card-hdr {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding-bottom: 12px;
  margin-bottom: 14px;
  border-bottom: 2px solid var(--fog);
}
.card-title {
  font-family: 'Josefin Sans', sans-serif;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--midnight);
}

.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inp-search, .sel-filter {
  padding: 7px 11px;
  border: 1px solid #CBD5E1;
  border-radius: 4px;
  font-size: 12.5px;
  background: var(--white);
  color: var(--midnight);
}

table.erp-tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
table.erp-tbl th {
  background: var(--midnight);
  color: var(--white);
  font-family: 'DM Mono', monospace;
  font-size: 9.5px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  padding: 9px 10px;
  text-align: left;
  position: sticky;
  top: 0;
}
table.erp-tbl th.r, table.erp-tbl td.r {
  text-align: right;
  font-family: 'DM Mono', monospace;
}
table.erp-tbl td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--fog);
  vertical-align: middle;
}
table.erp-tbl tbody tr:hover td { background: #F8FAFC; }
table.erp-tbl tfoot tr td {
  background: var(--midnight);
  color: var(--white);
  font-family: 'DM Mono', monospace;
  font-weight: 700;
  padding: 10px;
}

/* Responsive Container Query for Tables on Mobile Field View */
@container (width < 640px) {
  table.erp-tbl, table.erp-tbl thead, table.erp-tbl tbody, table.erp-tbl tr, table.erp-tbl th, table.erp-tbl td {
    display: block;
  }
  table.erp-tbl thead { display: none; }
  table.erp-tbl tr {
    margin-block-end: 1rem;
    border: 1px solid #CBD5E1;
    border-radius: 6px;
    padding: 8px;
    background: #fff;
  }
  table.erp-tbl td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #F1F5F9;
    padding: 6px 4px;
  }
  table.erp-tbl td::before {
    content: attr(data-label);
    font-family: 'DM Mono', monospace;
    font-size: 10px;
    text-transform: uppercase;
    color: var(--dim);
    font-weight: 600;
  }
}

/* STATUS PILLS */
.pill {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 3px;
  font-family: 'DM Mono', monospace;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  white-space: nowrap;
}
.p-pour { background: var(--amber-bg); color: var(--amber); border: 1px solid #F5D096; }
.p-prep { background: #E0F2FE; color: #0369A1; }
.p-sched { background: var(--fog); color: var(--navy); }
.p-done { background: var(--green-bg); color: var(--green); }
.p-inv { background: #EDE9FE; color: #6D28D9; }
.p-paid { background: #DCFCE7; color: #15803D; }
.p-overdue { background: var(--red-bg); color: var(--red); border: 1px solid #F5B7B1; }

/* BUTTONS */
.btn {
  padding: 6px 11px;
  font-family: 'DM Mono', monospace;
  font-size: 9.5px;
  letter-spacing: 1px;
  text-transform: uppercase;
  border: 1px solid #CBD5E1;
  background: var(--white);
  color: var(--midnight);
  border-radius: 3px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.btn:hover { background: var(--fog); border-color: var(--midnight); }
.btn-primary { background: var(--tide); color: #fff; border-color: var(--tide); }
.btn-primary:hover { background: #236473; color: #fff; }
.btn-gold { background: var(--gold); color: var(--midnight); border-color: var(--gold); font-weight: 700; }
.btn-danger { color: var(--red); border-color: #F5B7B1; }
.btn-danger:hover { background: var(--red-bg); }
.row-btns { display: flex; gap: 4px; flex-wrap: wrap; }

/* MODAL */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(18,25,43,0.68);
  z-index: 200;
  padding: 24px 14px;
  overflow-y: auto;
}
.modal-backdrop.show { display: block; }
.modal-card {
  background: var(--cream);
  max-width: 920px;
  margin: 0 auto;
  border-radius: 6px;
  border-top: 4px solid var(--gold);
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  overflow: hidden;
}
.modal-hdr {
  background: var(--midnight);
  color: var(--white);
  padding: 15px 22px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-ttl {
  font-family: 'Josefin Sans', sans-serif;
  font-size: 16px;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--gold);
}
.modal-close {
  background: none; border: none; color: #fff; font-size: 22px; cursor: pointer;
}
.modal-body { padding: 20px 22px; }
.modal-ftr {
  background: var(--white);
  padding: 14px 22px;
  border-top: 1px solid var(--fog);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.frm-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.frm-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.frm-f { display: flex; flex-direction: column; min-width: 0; max-width: 100%; }
.frm-f.full { grid-column: 1 / -1; }
.frm-lbl {
  font-family: 'DM Mono', monospace;
  font-size: 9.5px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--navy);
  margin-bottom: 4px;
  font-weight: 600;
}
.frm-in, .frm-sel, .frm-ta {
  padding: 8px 10px;
  border: 1px solid #CBD5E1;
  border-radius: 4px;
  font-size: 13px;
  background: var(--white);
  color: var(--midnight);
  font-family: inherit;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}
.frm-ta { min-height: 64px; resize: vertical; }
.sec-div {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--tide);
  border-bottom: 1.5px solid var(--gold);
  padding-bottom: 5px;
  margin: 18px 0 10px;
  font-weight: 700;
}

/* PRINT AREA (Official Australian Standard Tax Invoice / Quote / ITP / Site Notice) */
#print-area { display: none; }
.print-doc {
  max-width: 210mm;
  margin: 0 auto;
  background: #fff;
  color: #12192B;
  padding: 14mm 16mm;
  font-family: 'Lato', sans-serif;
}
.pd-hdr {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 2.5px solid #12192B;
  padding-bottom: 12px;
  margin-bottom: 16px;
}
.pd-brand { font-family: 'Josefin Sans', sans-serif; font-size: 26px; font-weight: 300; letter-spacing: 6px; }
.pd-sub { font-family: 'DM Mono', monospace; font-size: 9px; letter-spacing: 2px; color: #2E7B8C; text-transform: uppercase; margin-top: 3px; }
.pd-box { width: 255px; border: 1.5px solid #12192B; }
.pd-box-top { background: #12192B; color: #fff; padding: 8px 12px; font-size: 15px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; }
.pd-box-no { background: #1B2C45; color: #fff; padding: 8px 12px; display: flex; justify-content: space-between; align-items: center; font-family: 'DM Mono', monospace; font-size: 10.5px; }
.pd-box-no strong { color: #C8A87A; font-size: 14px; }
.pd-box-row { background: #64748b; color: #fff; padding: 5px 12px; display: flex; justify-content: space-between; font-family: 'DM Mono', monospace; font-size: 9.5px; border-top: 1px solid #94a3b8; }

@media (max-width: 820px) {
  .kpi-bar { grid-template-columns: repeat(2, 1fr); }
  .frm-grid, .frm-grid.three { grid-template-columns: minmax(0, 1fr); }
}

@media print {
  @page { size: A4; margin: 0; }
  body { background: #fff; }
  body.printing > *:not(#print-area) { display: none !important; }
  body.printing #print-area { display: block !important; }
  .th-guide, .no-print { display: none !important; }
}


/* =========================================================================
   M-ERP LIVE v5.0 — MULTI-DEVICE SYNC, AUTH, ROLES, QR, RESPONSIVE & PRINT
   ========================================================================= */

html, body {
  overflow-x: clip;
  max-width: 100%;
}

/* TH Companion Helper: controlled globally via body.th-on so module ctx.th() elements follow toggle */
body.th-on .th-guide { display: block; }
body:not(.th-on) .th-guide { display: none !important; }
.th-guide:not(#th-guide) {
  border-bottom: none;
  border-left: 3px solid var(--gold);
  border-radius: 4px;
  padding: 9px 14px;
  margin: 8px 0 12px;
  font-size: 12.5px;
}

/* Sync Status Pill & Role Pill */
.save-pill {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  user-select: none;
  transition: all 0.2s ease;
}
.save-pill.is-synced {
  color: #86efac;
  background: rgba(46,140,90,0.22);
  border-color: rgba(46,140,90,0.55);
}
.save-pill.is-syncing {
  color: #7dd3fc;
  background: rgba(46,123,140,0.28);
  border-color: rgba(125,211,252,0.55);
}
.save-pill.is-offline {
  color: #fde68a;
  background: rgba(184,110,20,0.28);
  border-color: rgba(245,208,150,0.65);
}
.save-pill.is-queued {
  color: #fef08a;
  background: rgba(194,75,61,0.32);
  border-color: var(--gold);
  font-weight: 700;
}

.role-pill {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  padding: 5px 10px;
  border-radius: 20px;
  border: 1px solid rgba(200,168,122,0.5);
  background: rgba(27,44,69,0.9);
  color: var(--gold);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}
.role-pill:hover { border-color: var(--gold); background: var(--navy); }

/* Role-based visibility */
body[data-role="Supervisor"] [data-perm="pl"],
body[data-role="Viewer"] [data-perm="pl"] {
  display: none !important;
}
body[data-role="Supervisor"] [data-perm="admin"],
body[data-role="Viewer"] [data-perm="admin"] {
  display: none !important;
}
body[data-role="Viewer"] [data-perm="write"] {
  display: none !important;
}

/* HOLD POINT Alert Banner in Job Sheet */
.hold-alert-banner {
  background: var(--red-bg);
  color: var(--red);
  border: 1.5px solid #F5B7B1;
  border-left: 5px solid var(--red);
  border-radius: 5px;
  padding: 10px 14px;
  margin: 10px 0;
  font-size: 12.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
tr.is-hold-stage td {
  background: #FFFBEB;
}
tr.is-hold-stage.is-hold-passed td {
  background: #F0FDF4;
}

/* Toast Notifications */
.merp-toast-wrap {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(420px, calc(100vw - 28px));
  pointer-events: none;
}
.merp-toast {
  pointer-events: auto;
  background: var(--midnight);
  color: var(--white);
  border-left: 4px solid var(--gold);
  border-radius: 5px;
  padding: 11px 15px;
  font-size: 12.5px;
  line-height: 1.45;
  box-shadow: 0 10px 28px rgba(0,0,0,0.32);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.merp-toast.is-ok { border-left-color: var(--green); }
.merp-toast.is-warn { border-left-color: var(--amber); }
.merp-toast.is-err { border-left-color: var(--red); background: #2B1215; }
.merp-toast-close {
  min-width: 44px;
  min-height: 44px;
  width: 44px;
  height: 44px;
  margin: -6px -6px -6px 0;
  padding: 0;
  background: none;
  border: none;
  color: #cbd5e1;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 4px;
  touch-action: manipulation;
}
.merp-toast-close:hover {
  color: var(--white);
  background: rgba(255,255,255,0.1);
}

/* PIN Login Overlay */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 400;
  background: radial-gradient(circle at 50% 20%, #1B2C45 0%, #12192B 72%);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  overflow-y: auto;
}
.login-overlay.show { display: flex; }
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--cream);
  border-radius: 8px;
  border-top: 4px solid var(--gold);
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
  overflow: hidden;
}
.login-hdr {
  background: var(--midnight);
  color: var(--white);
  padding: 20px 22px 16px;
  text-align: center;
  border-bottom: 1px solid rgba(200,168,122,0.3);
}
.login-hdr .brand-mark {
  margin: 0 auto 10px;
  width: 46px;
  height: 46px;
  font-size: 16px;
}
.login-hdr h1 {
  font-family: 'Josefin Sans', sans-serif;
  font-weight: 300;
  font-size: 20px;
  letter-spacing: 4px;
  color: var(--white);
}
.login-hdr p {
  font-family: 'DM Mono', monospace;
  font-size: 9.5px;
  letter-spacing: 1.6px;
  color: var(--gold);
  text-transform: uppercase;
  margin-top: 4px;
}
.login-body {
  padding: 20px 22px 22px;
}
.pin-dots {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}
.pin-input {
  width: 100%;
  text-align: center;
  font-family: 'DM Mono', monospace;
  font-size: 24px;
  letter-spacing: 10px;
  padding: 10px 14px;
  min-height: 48px;
  border: 1.5px solid #CBD5E1;
  border-radius: 6px;
  background: var(--white);
  color: var(--midnight);
}
.pin-input:focus { outline: none; border-color: var(--tide); }
.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}
.pin-key {
  min-height: 50px;
  border: 1px solid #CBD5E1;
  border-radius: 6px;
  background: var(--white);
  color: var(--midnight);
  font-family: 'DM Mono', monospace;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.pin-key:hover, .pin-key:active { background: var(--fog); border-color: var(--gold); }
.pin-key.is-submit {
  background: var(--gold);
  color: var(--midnight);
  border-color: var(--gold);
  font-size: 12px;
  letter-spacing: 1px;
  font-weight: 700;
}
.login-err {
  min-height: 20px;
  text-align: center;
  color: var(--red);
  font-size: 12px;
  font-weight: 700;
  margin-top: 8px;
}
.login-roles-note {
  margin-top: 12px;
  padding: 9px 11px;
  background: var(--fog);
  border-radius: 4px;
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  color: var(--dim);
  line-height: 1.6;
}

/* Open on Another Device / QR Grid */
.qr-split {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.qr-split > * {
  min-width: 0;
}
.qr-box {
  background: #fff;
  border: 1.5px solid var(--gold);
  border-radius: 6px;
  padding: 12px;
  text-align: center;
}
.qr-box svg {
  width: 100%;
  height: auto;
  max-width: 180px;
  display: block;
  margin: 0 auto;
}

/* Evidence & 3D Snapshots Grid in Tab 04 */
.hub-uploads-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
  margin-top: 10px;
}
.hub-up-card {
  border: 1px solid #DCD7CC;
  border-radius: 6px;
  background: var(--cream);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.hub-up-thumb {
  height: 132px;
  background: var(--midnight);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}
.hub-up-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.hub-up-kind {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(18,25,43,0.85);
  color: var(--gold);
  font-family: 'DM Mono', monospace;
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 3px;
  text-transform: uppercase;
}
.hub-up-meta {
  padding: 9px 11px;
  font-size: 11.5px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

/* Inline log photo thumbs */
.log-thumb-strip {
  display: inline-flex;
  gap: 4px;
  flex-wrap: wrap;
  vertical-align: middle;
}
.log-thumb-strip a {
  display: inline-block;
  width: 34px;
  height: 34px;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid #CBD5E1;
}
.log-thumb-strip img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Touch Targets >= 44px & Responsive Layouts (1280x720, 1024x1366, 1366x1024, 390x844) */
.nav-tabs {
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}
.nav-tab {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}
.hdr-btn, .fq-btn, .inp-search, .sel-filter, .frm-in, .frm-sel, .save-pill, .role-pill {
  min-height: 44px;
}
.btn {
  min-height: 44px;
  padding: 8px 12px;
}
.modal-close {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.stage-tick-lbl {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  cursor: pointer;
}
.stage-tick-lbl input[type="checkbox"] {
  width: 20px;
  height: 20px;
  cursor: pointer;
}

/* Job Sheet Modal — Touch Targets >= 44px & Zero Clipping Across All Viewports */
@media screen {
  .modal-body {
    container-type: inline-size;
    overflow-x: hidden;
  }
}
.js-tbl-in {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 44px;
  height: 44px;
  padding: 8px 10px;
  box-sizing: border-box;
}
.js-num-in {
  text-align: right;
  font-family: 'DM Mono', monospace;
}
.js-done-td {
  text-align: center;
}
input.stage-cb {
  -webkit-appearance: none;
  appearance: none;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  display: inline-grid;
  place-content: center;
  vertical-align: middle;
  touch-action: manipulation;
}
input.stage-cb::before {
  content: "";
  width: 24px;
  height: 24px;
  border: 2px solid var(--navy);
  border-radius: 5px;
  background: var(--white);
  display: grid;
  place-content: center;
  font-family: 'DM Mono', monospace;
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
  color: var(--white);
  transition: background 0.12s ease, border-color 0.12s ease;
}
input.stage-cb:checked::before {
  content: "✓";
  background: var(--green);
  border-color: var(--green);
}
input.stage-cb:focus-visible::before {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}
input.stage-cb:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

@media screen and (min-width: 721px) {
  table.js-modal-tbl {
    table-layout: fixed;
    width: 100%;
  }
  table.js-stages-tbl th:nth-child(1), table.js-stages-tbl td:nth-child(1) { width: 25%; word-break: break-word; }
  table.js-stages-tbl th:nth-child(2), table.js-stages-tbl td:nth-child(2) { width: 20%; }
  table.js-stages-tbl th:nth-child(3), table.js-stages-tbl td:nth-child(3) { width: 20%; }
  table.js-stages-tbl th:nth-child(4), table.js-stages-tbl td:nth-child(4) { width: 24%; word-break: break-word; }
  table.js-stages-tbl th:nth-child(5), table.js-stages-tbl td:nth-child(5) { width: 11%; text-align: center; }
  table.js-stages-tbl .itp-js-cell { min-width: 0; }
  table.js-costs-tbl th:nth-child(1), table.js-costs-tbl td:nth-child(1) { width: 34%; }
  table.js-costs-tbl th:nth-child(2), table.js-costs-tbl td:nth-child(2) { width: 28%; }
  table.js-costs-tbl th:nth-child(3), table.js-costs-tbl td:nth-child(3) { width: 19%; }
  table.js-costs-tbl th:nth-child(4), table.js-costs-tbl td:nth-child(4) { width: 19%; }
}

@media screen and (max-width: 720px) {
  .modal-body table.erp-tbl,
  .modal-body table.erp-tbl thead,
  .modal-body table.erp-tbl tbody,
  .modal-body table.erp-tbl tr,
  .modal-body table.erp-tbl th,
  .modal-body table.erp-tbl td {
    display: block;
    width: 100%;
    box-sizing: border-box;
  }
  .modal-body table.erp-tbl thead { display: none; }
  .modal-body table.erp-tbl tr {
    margin-block-end: 10px;
    border: 1px solid #CBD5E1;
    border-radius: 6px;
    padding: 8px 10px;
    background: #fff;
  }
  .modal-body table.erp-tbl td {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 6px 10px;
    border-bottom: 1px solid #F1F5F9;
    padding: 6px 2px;
    min-width: 0;
  }
  .modal-body table.erp-tbl td:last-child { border-bottom: none; }
  .modal-body table.erp-tbl td::before {
    content: attr(data-label);
    font-family: 'DM Mono', monospace;
    font-size: 10px;
    text-transform: uppercase;
    color: var(--dim);
    font-weight: 600;
    flex-shrink: 0;
  }
  .modal-body table.js-modal-tbl td .js-tbl-in {
    flex: 1 1 190px;
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }
  .modal-body table.js-modal-tbl td.stage-ext {
    align-items: flex-start;
  }
  .modal-body table.js-modal-tbl td.stage-ext .itp-js-cell {
    flex: 1 1 100%;
    min-width: 0;
    max-width: 100%;
  }
  .modal-body table.js-modal-tbl td.js-done-td {
    justify-content: space-between;
    align-items: center;
  }
}

@media (pointer: coarse), (max-width: 1024px) {
  .btn {
    min-height: 44px;
    padding: 8px 12px;
  }
}

/* Tablet Portrait (1024x1366) & Medium Screens */
@media (max-width: 1140px) {
  .main-wrap { padding: 16px 16px 48px; }
  .top-hdr { padding: 12px 16px; }
  .nav-tabs { padding: 0 12px; }
  .kpi-bar { grid-template-columns: repeat(3, 1fr); }
  .kpi-item { padding: 10px 14px; border-bottom: 1px solid rgba(255,255,255,0.08); }
  .card { padding: 14px 15px; overflow-x: auto; }
  table.erp-tbl th, table.erp-tbl td { padding: 8px 7px; font-size: 12px; }
}

@media (max-width: 820px) {
  .kpi-bar { grid-template-columns: repeat(2, 1fr); }
  .qr-split { grid-template-columns: minmax(0, 1fr); }
}

/* Mobile Field View (390x844) */
@container (width < 640px) {
  table.erp-tbl td {
    gap: 10px;
    flex-wrap: wrap;
    word-break: break-word;
    align-items: flex-start;
  }
  table.erp-tbl td.js-done-td {
    align-items: center;
  }
  table.erp-tbl td .js-tbl-in {
    flex: 1 1 190px;
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }
  table.erp-tbl td.stage-ext .itp-js-cell {
    flex: 1 1 100%;
    min-width: 0;
    max-width: 100%;
  }
  table.erp-tbl td.r {
    text-align: right;
  }
  table.erp-tbl tfoot tr {
    background: var(--midnight);
    color: var(--white);
    border-color: var(--gold);
  }
  table.erp-tbl tfoot tr td {
    border-bottom: 1px solid rgba(255,255,255,0.12);
    color: var(--white);
  }
  table.erp-tbl tfoot tr td:empty {
    display: none;
  }
}

@media (max-width: 560px) {
  .top-hdr { padding: 10px 12px; gap: 10px; }
  .brand-title { letter-spacing: 2px; font-size: 1.05rem; }
  .brand-sub { font-size: 8.5px; letter-spacing: 1px; }
  .hdr-actions { width: 100%; gap: 6px; }
  .hdr-btn { padding: 6px 9px; font-size: 9.5px; }
  .kpi-bar { grid-template-columns: repeat(2, 1fr); }
  .kpi-item { padding: 9px 11px; }
  .kpi-item:last-child { grid-column: 1 / -1; }
  .main-wrap { padding: 12px 10px 44px; }
  .field-quick-bar { padding: 12px 14px; }
  .fq-btns { width: 100%; }
  .fq-btn { width: 100%; justify-content: center; }
  .filter-bar { width: 100%; }
  .filter-bar .inp-search, .filter-bar .sel-filter, .filter-bar .btn { width: 100%; }
  .modal-backdrop { padding: 10px 8px; }
  .modal-hdr, .modal-body, .modal-ftr { padding: 12px 14px; }
}

/* Clean A4 Print Rules */
@media print {
  @page { size: A4; margin: 10mm; }
  html, body { background: #fff !important; overflow: visible !important; }
  .card, .modal-body { container-type: normal !important; }
  .th-guide,
  body.th-on .th-guide,
  .th-guide.show,
  .no-print,
  .merp-toast-wrap,
  #merp-login-overlay,
  .modal-backdrop { display: none !important; }

  body.printing > *:not(#print-area) { display: none !important; }
  body.printing #print-area { display: block !important; }
  body.printing .print-doc { padding: 4mm 6mm; max-width: 100%; }

  /* Master Schedule 1-Page Print (when window.print() runs without .printing / .dos-preview-open / .fleet-print-open) */
  body:not(.printing):not(.dos-preview-open):not(.fleet-print-open) .top-hdr .hdr-actions,
  body:not(.printing):not(.dos-preview-open):not(.fleet-print-open) .nav-tabs,
  body:not(.printing):not(.dos-preview-open):not(.fleet-print-open) .field-quick-bar,
  body:not(.printing):not(.dos-preview-open):not(.fleet-print-open) .filter-bar,
  body:not(.printing):not(.dos-preview-open):not(.fleet-print-open) .row-btns {
    display: none !important;
  }
}

/* =========================================================================
   M-ERP LIVE v6.0 — DIVISIONS, CREDIT HOLD WARNINGS, FLEET OVERHEAD & QBO
   ========================================================================= */

.div-pill {
  display: inline-block;
  font-family: 'DM Mono', monospace;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.6px;
  padding: 2px 6px;
  border-radius: 3px;
  text-transform: uppercase;
  vertical-align: middle;
  border: 1px solid transparent;
}
.div-pill.is-con { background: #EBF2F7; color: #1B2C45; border-color: #CBD5E1; }
.div-pill.is-pmp { background: #E0F2F1; color: #0F5257; border-color: #99D5CF; }
.div-pill.is-plt { background: #E8F5E9; color: #1E5631; border-color: #A7D7B8; }
.div-pill.is-var { background: #FEF3C7; color: #92400E; border-color: #FCD34D; }
.div-pill.is-internal { background: #F1F5F9; color: #475569; border-color: #CBD5E1; }

.credit-tag {
  display: inline-block;
  font-family: 'DM Mono', monospace;
  font-size: 9px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 3px;
  margin-left: 4px;
  vertical-align: middle;
}
.credit-tag.is-hold { background: var(--red-bg); color: var(--red); border: 1px solid #F5B7B1; }
.credit-tag.is-dispute { background: #FEF3C7; color: #92400E; border: 1px solid #FCD34D; }

.credit-warn-banner {
  border-radius: 5px;
  padding: 10px 14px;
  margin: 0 0 14px;
  font-size: 12.5px;
  line-height: 1.5;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.credit-warn-banner.is-hold {
  background: var(--red-bg);
  color: #8E251A;
  border: 1.5px solid #F5B7B1;
  border-left: 5px solid var(--red);
}
.credit-warn-banner.is-dispute {
  background: #FFF8E6;
  color: #7C3A06;
  border: 1.5px solid #F5D096;
  border-left: 5px solid var(--amber);
}
.credit-warn-banner.is-watch {
  background: #F0F9FF;
  color: #0C4A6E;
  border: 1.5px solid #BAE6FD;
  border-left: 5px solid var(--tide);
}

.pill.p-partpaid {
  background: #FEF3C7;
  color: #92400E;
  border: 1px solid #FCD34D;
}
.pill.p-disputed {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid #F5B7B1;
}

.qbo-pill {
  display: inline-block;
  font-family: 'DM Mono', monospace;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 3px;
  letter-spacing: 0.4px;
}
.qbo-pill.is-pending {
  background: #F1F5F9;
  color: #475569;
  border: 1px solid #CBD5E1;
}
.qbo-pill.is-exported {
  background: #DCFCE7;
  color: #166534;
  border: 1px solid #86EFAC;
}

tr.is-internal-row td {
  background: #F8FAFC;
}

.pl-split-bar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 14px;
}
.pl-split-item {
  background: var(--cream);
  border: 1px solid #DCD7CC;
  border-left: 3px solid var(--gold);
  border-radius: 5px;
  padding: 10px 12px;
  min-width: 0;
}
.pl-split-lbl {
  font-family: 'DM Mono', monospace;
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--dim);
}
.pl-split-val {
  font-family: 'DM Mono', monospace;
  font-size: 16px;
  font-weight: 700;
  color: var(--midnight);
  margin-top: 3px;
}
.pl-split-sub {
  font-size: 11px;
  font-weight: 500;
  color: var(--dim);
}

@media (max-width: 980px) {
  .pl-split-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .pl-split-bar { grid-template-columns: minmax(0, 1fr); }
}
