:root {
  --brand: #185FA5;        /* ThaiKee Hub theme colour (deep blue) */
  --brand-dark: #0C447C;   /* pressed / active state */
  --teal: var(--brand);      /* legacy names kept as aliases so all */
  --teal-dark: var(--brand-dark); /* existing var(--teal) refs recolour */
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --err: #dc2626;
  --ok: #15803d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  background: var(--teal);
  color: #fff;
  padding: 10px 16px;
  text-align: center;
  position: sticky;          /* keep the whole blue bar (menu + settings) pinned on scroll */
  top: 0;
  z-index: 50;               /* above page content & sticky table headers; below drawer(60)/settings(70) */
  box-shadow: 0 2px 6px rgba(15, 23, 42, .18);
}
header h1 { margin: 0; font-size: 18px; display: inline-flex; align-items: center; gap: 8px; }
/* white line icon in the page header (matches the blue-on-white menu icons, inverted) */
.hdr-ic { width: 22px; height: 22px; color: #fff; flex: 0 0 auto; }
/* small line icon inside a button, inherits the button's text colour. margin-right
   spaces it in inline buttons (pending Open/Delete); flex buttons zero it and use gap. */
.btn-ic { width: 16px; height: 16px; vertical-align: -3px; margin-right: 5px; }
.details-btn .btn-ic, .report-btn .btn-ic { margin-right: 0; }

/* ---------- Hamburger + drawer ---------- */
.menu-btn {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: #fff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
}
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  z-index: 60;
}
.drawer-overlay.hidden { display: none; }
.drawer {
  width: 300px;
  max-width: 88%;
  height: 100%;
  background: #fff;
  box-shadow: 2px 0 16px rgba(0,0,0,.25);
  display: flex;
  flex-direction: column;
  overflow-y: auto;                    /* scroll when items exceed the screen */
  -webkit-overflow-scrolling: touch;   /* smooth momentum scroll on iOS */
}
/* keep the title bar visible while the list scrolls */
.drawer-head { position: sticky; top: 0; z-index: 1; }
.drawer-head {
  background: var(--teal);
  color: #fff;
  padding: 16px;
}
.drawer-title { font-size: 16px; font-weight: 700; display: block; }
.drawer-user { font-size: 12px; opacity: .9; }
.drawer a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid #f1f5f9;
  font-size: 15px;
}
.drawer a:active { background: #f1f5f9; }
.drawer a { position: relative; }
/* minimalist brand-blue line icon at the start of each drawer link */
.nav-ic {
  width: 21px; height: 21px; flex: 0 0 auto; color: var(--brand);
  stroke: currentColor;
}
.nav-label { flex: 1 1 auto; min-width: 0; }
/* red-dot reminder next to a drawer link */
.link-dot {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  width: 9px; height: 9px; border-radius: 50%; background: #ef4444;
}
/* red-dot reminder on the ☰ button (aggregate) — ringed so it reads on the blue header */
.menu-dot {
  position: absolute; top: 6px; right: 4px;
  width: 9px; height: 9px; border-radius: 50%; background: #ef4444;
  border: 1.5px solid var(--teal); box-sizing: content-box;
}
.drawer-foot {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-right: 16px;
}
.drawer-foot .drawer-logout { border-bottom: none; }
.drawer-logout { color: var(--err) !important; }
.drawer-sign { font-size: 10px; color: var(--muted); white-space: nowrap; }
.drawer-sec {
  padding: 10px 16px 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}
/* collapsible drawer group (Inventory, Invoices / orders) */
.drawer-dd {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 16px;
  background: none;
  border: none;
  border-bottom: 1px solid #f1f5f9;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}
.drawer-dd:active { background: #f1f5f9; }
.dd-caret {
  width: 18px; height: 18px; flex: 0 0 auto; color: var(--muted);
  margin-left: auto; transition: transform .15s ease;
}
.drawer-dd[aria-expanded="true"] .dd-caret { transform: rotate(90deg); }
.drawer-dd-body.hidden { display: none; }
.drawer-dd-body > a { padding-left: 40px; background: #fbfcfe; }
.sub { color: var(--muted); font-size: 12px; }

/* ---------- Settings gear + dropdown ---------- */
.gear-btn {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: #fff;
  line-height: 0;
  cursor: pointer;
  padding: 4px 8px;
}
.gear-btn svg { display: block; }
.settings-overlay { position: fixed; inset: 0; z-index: 70; }
.settings-overlay.hidden { display: none; }
.settings-panel {
  position: absolute;
  top: 48px;
  right: 8px;
  width: 244px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .25);
  overflow: hidden;
  padding: 4px 0;
}
.settings-head {
  padding: 10px 14px 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}
.settings-panel a, .settings-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  color: var(--text);
  text-decoration: none;
  font-size: 15px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: inherit;
}
.settings-panel a:active, .settings-item:active { background: #f1f5f9; }
.settings-item .set-sub { color: var(--muted); font-size: 12px; margin-left: auto; }
.settings-item.alert-on .set-sub { color: var(--teal); }
.qty-input, .cost-input {
  width: 64px;
  padding: 6px 8px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 15px;
  text-align: right;
}
.cost-input { width: 78px; }
.nav-link {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: #fff;
  text-decoration: none;
  font-size: 14px;
  opacity: .9;
}
.nav-link:hover { opacity: 1; text-decoration: underline; }
.nav-links {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  gap: 14px;
}
.nav-links a { color: #fff; text-decoration: none; font-size: 13px; opacity: .9; }
.nav-links a:hover { opacity: 1; text-decoration: underline; }
.nav-user { color: #fff; font-size: 12px; opacity: .85; }

/* ---------- Login page ---------- */
.login-card { max-width: 360px; margin: 24px auto; padding: 20px; }
.lfield {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 14px;
}
.lfield input {
  padding: 12px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  font-size: 16px;
  color: var(--text);
}
.login-card .btn.primary { width: 100%; }

main {
  max-width: 480px;
  margin: 0 auto;
  padding: 10px 12px;
}

#reader,
#nmReader,
#taskReader {
  width: 100%;
  height: 200px;            /* compact camera band so content fits in one screen */
  border-radius: 12px;
  overflow: hidden;
  background: #000;
}
/* Force the injected video/canvas to fill the compact band (cropped, not stretched) */
#reader video,
#reader canvas,
#nmReader video,
#nmReader canvas,
#taskReader video,
#taskReader canvas {
  width: 100% !important;
  height: 200px !important;
  object-fit: cover;
}

.controls {
  display: flex;
  gap: 10px;
  margin: 8px 0;
}

.btn {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #cbd5e1;
  background: #fff;
  border-radius: 10px;
  font-size: 16px;
  cursor: pointer;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary {
  background: var(--teal);
  color: #fff;
  border-color: var(--teal);
}
.btn.primary:active { background: var(--teal-dark); }

.manual {
  display: flex;
  gap: 10px;
  margin-bottom: 6px;
}
.manual input {
  flex: 1;
  padding: 12px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  font-size: 16px;
}

.status {
  min-height: 16px;
  font-size: 13px;
  color: var(--muted);
  margin: 4px 2px;
}
.status.ok { color: var(--ok); }
.status.warn { color: var(--warn); }
.status.err { color: var(--err); }

.card {
  background: var(--card);
  border-radius: 14px;
  box-shadow: 0 4px 16px rgba(0,0,0,.08);
  overflow: hidden;
  margin-top: 14px;
}
.card.hidden, .hidden { display: none; }

.card-img {
  height: 160px;
  background-size: cover;
  background-position: center;
  background-color: #e2e8f0;
}
.card-img.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 56px;
}

.card-body { padding: 16px; }
.card-body h2 { margin: 0 0 4px; font-size: 20px; }
.brand { margin: 0 0 8px; color: var(--muted); font-size: 14px; }
.price { margin: 0 0 8px; color: var(--teal); font-size: 22px; font-weight: 700; }
.desc { margin: 0 0 12px; color: #334155; font-size: 15px; }

.meta { display: flex; gap: 8px; flex-wrap: wrap; }
.tag {
  background: #f1f5f9;
  color: var(--muted);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 13px;
}

.card.warn {
  background: var(--warn-bg);
  padding: 16px;
  color: var(--warn);
}
.card.warn p { margin: 0 0 12px; }

/* ---------- Camera helpers (zoom / torch) ---------- */
.cam-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 10px 0 4px;
}
.zoom {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 13px;
  color: var(--muted);
}
.zoom span { display: flex; justify-content: space-between; }
.zoom input[type="range"] { width: 100%; accent-color: var(--teal); height: 28px; }
#torchBtn.active { background: var(--teal); color: #fff; border-color: var(--teal); }
.tip {
  font-size: 12px;
  color: var(--muted);
  background: #f1f5f9;
  border-radius: 8px;
  padding: 6px 8px;
  margin: 4px 0 0;
  line-height: 1.4;
}

/* Fallback OCR button — read the printed digits when a barcode won't scan. */
.ocr-btn {
  display: block;
  width: 100%;
  margin: 8px 0 2px;
  border: 1px dashed var(--brand);
  color: var(--brand);
  background: #f8fafc;
}
.ocr-btn.armed {
  border-style: solid;
  color: #fff;
  background: var(--brand);
}
.ocr-btn:disabled { opacity: .6; }

/* OCR aim box overlaid on the camera preview (fractions match OCR_BOX in app.js). */
.reader-wrap { position: relative; overflow: hidden; }
#ocrGuide {
  position: absolute;
  left: 7%; top: 42%; width: 86%; height: 16%;
  border: 2px solid var(--brand);
  border-radius: 6px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .38); /* dim everything outside the box */
  pointer-events: none;
  z-index: 5;
}
.ocr-guide-tag {
  position: absolute;
  left: 0; top: -20px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: var(--brand);
  padding: 1px 6px;
  border-radius: 4px;
  white-space: nowrap;
}

/* ---------- Scanner result cards ---------- */
#results { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.card.product { margin-top: 0; }
.card.product.current { box-shadow: 0 0 0 2px var(--teal), 0 4px 16px rgba(0,0,0,.08); }
.current-badge {
  background: var(--teal);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 7px 12px;
  text-align: center;
}
.card.product .card-body { padding: 12px; }
.card.product h2 { margin: 0 0 4px; font-size: 17px; line-height: 1.25; }
.sell {
  font-size: 24px;
  font-weight: 700;
  color: var(--teal);
  margin-bottom: 6px;
}
.sell-type {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: #f1f5f9;
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: 6px;
  vertical-align: middle;
}
table.kv { width: 100%; border-collapse: collapse; font-size: 14px; }
table.kv td { padding: 3px 0; border-top: 1px solid #f1f5f9; }
table.kv td:first-child { color: var(--muted); width: 110px; }
table.kv .sub { color: var(--muted); font-size: 13px; }

.card.clickable { cursor: pointer; transition: box-shadow .12s; }
.card.clickable:active { box-shadow: 0 0 0 2px var(--teal) inset; }
.tap-hint {
  margin-top: 8px;
  text-align: right;
  font-size: 12px;
  color: var(--teal);
  font-weight: 600;
}
.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
}
.card-foot .tap-hint { margin-top: 0; }
.details-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--teal);
  background: #ecfdf5;
  color: var(--teal);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.details-btn:active { background: #d1fae5; }

/* ---------- Action menu (bottom sheet) ---------- */
.menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  display: flex;
  align-items: flex-end;
  z-index: 50;
}
.menu-overlay.hidden { display: none; }
.menu-sheet {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  background: #fff;
  border-radius: 16px 16px 0 0;
  padding: 12px;
  box-shadow: 0 -6px 24px rgba(0,0,0,.2);
}
.menu-head { padding: 8px 8px 12px; border-bottom: 1px solid #f1f5f9; margin-bottom: 8px; }
.menu-title { font-size: 16px; font-weight: 700; }
.menu-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  padding: 14px 12px;
  border: none;
  background: #f8fafc;
  border-radius: 10px;
  font-size: 16px;
  margin-bottom: 8px;
  cursor: pointer;
}
.menu-item:active { background: #e2e8f0; }
.menu-cancel {
  width: 100%;
  padding: 12px;
  border: 1px solid #cbd5e1;
  background: #fff;
  border-radius: 10px;
  font-size: 15px;
  color: var(--muted);
  cursor: pointer;
}

#specialForm .field,
#orderForm .field,
#updateForm .field,
#reportOverlay .field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 14px;
  padding: 0 4px;
}
#specialForm .field input,
#orderForm .field input,
#updateForm .field input,
#reportOverlay .field input,
#reportOverlay .field textarea {
  padding: 12px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  font-size: 16px;
  color: var(--text);
}
#specialForm .btn.primary,
#orderForm .btn.primary,
#updateForm .btn.primary { margin-bottom: 8px; }
#orderFormTitle, #updateFormTitle { margin: 0 4px 10px; }

/* ---------- Admin / catalog page ---------- */
main.admin { max-width: 920px; }
/* wide layout for data-heavy pages (e.g. invoice review) */
main.admin.wide { max-width: min(1750px, 98vw); }
.hint { color: var(--muted); font-size: 13px; margin: 4px 2px 12px; }

/* ---------- Order groups (accordion) ---------- */
.card.group { margin-bottom: 10px; padding: 0; overflow: hidden; }
.group-head {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 14px 14px;
  background: #f8fafc;
  border: none;
  cursor: pointer;
  text-align: left;
  font-size: 15px;
}
.group-head.open { background: #ecfdf5; }
.group-name { font-weight: 700; }
.group-meta { color: var(--muted); font-size: 13px; white-space: nowrap; }
.group-meta .send-sup { margin: 0 6px; padding: 3px 12px; }
.order-total-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  margin: 10px 0;
  background: #ecfdf5;
  border-radius: 10px;
  font-size: 16px;
}
.order-total-bar b { font-size: 18px; color: var(--teal); }
.group-head .caret { display: inline-block; transition: transform .15s; }
.group-head.open .caret { transform: rotate(180deg); }
.group-body { overflow-x: auto; }
.group-body.hidden { display: none; }
table.orders-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.orders-table th {
  text-align: left; background: #fff; color: var(--muted); font-weight: 600;
  padding: 8px 10px; border-bottom: 1px solid #e2e8f0; white-space: nowrap;
}
table.orders-table td { padding: 8px 10px; border-bottom: 1px solid #f1f5f9; }
table.orders-table .num { text-align: right; white-space: nowrap; }
table.orders-table tfoot td { border-top: 2px solid #e2e8f0; background: #f8fafc; }
.grp-dl {
  border: 1px solid #cbd5e1;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  padding: 1px 6px;
  margin: 0 4px;
}
.grp-dl:active { background: #e2e8f0; }
.grp-close {
  border: 1px solid #fca5a5;
  background: #fff;
  color: #b91c1c;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  padding: 1px 6px;
  margin: 0 4px;
}
.grp-close:active { background: #fee2e2; }
.status-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 999px;
  margin-left: 6px;
  white-space: nowrap;
}
.status-badge.pending { background: #fef9c3; color: #854d0e; }
.status-badge.waiting { background: #fde68a; color: #92400e; }
.status-badge.finished { background: #dcfce7; color: #15803d; }
.grp-finish {
  border: 1px solid #86efac;
  background: #fff;
  color: #15803d;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  padding: 1px 6px;
  margin: 0 4px;
}
.grp-finish:active { background: #dcfce7; }
.group.closed .group-head { background: #fffbeb; }
.fin-by { font-size: 12px; font-weight: 400; color: #15803d; margin-left: 8px; white-space: nowrap; }

/* Orders list — 3-line header: (1) supplier + send date, (2) status, (3) count/total + buttons.
   Scoped to .orders-head so the shared .group-head on other pages is unaffected. */
.orders-head { flex-direction: column; align-items: stretch; gap: 8px; }
.orders-head .oh-row { display: flex; align-items: center; gap: 8px; }
.orders-head .oh-title { justify-content: space-between; }
.orders-head .group-name { font-weight: 700; font-size: 15px; }
.orders-head .oh-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.orders-head .oh-date { color: var(--muted); font-size: 13px; white-space: nowrap; }
.orders-head .oh-status { min-height: 20px; }
.orders-head .oh-actions { justify-content: space-between; flex-wrap: wrap; }
.orders-head .oh-count { color: var(--muted); font-size: 14px; white-space: nowrap; }
.orders-head .oh-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.orders-head .oh-btns > button { margin: 0; padding: 8px 12px; font-size: 13px; }

.upload-card { padding: 16px; margin-bottom: 14px; }
.upload-card h2 { margin: 0 0 6px; font-size: 18px; }
.upload-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.upload-row input[type="file"] { flex: 1; min-width: 200px; font-size: 14px; }
.upload-card .status { margin-top: 8px; }

.form-card { padding: 16px; }
.form-card h2 { margin: 0 0 12px; font-size: 18px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.form-grid label {
  display: flex;
  flex-direction: column;
  font-size: 13px;
  color: var(--muted);
  gap: 4px;
}
.form-grid label.full { grid-column: 1 / -1; }
.form-grid input {
  padding: 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 15px;
}
.form-grid input:disabled { background: #f1f5f9; color: var(--muted); }
.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}
.form-actions .btn { flex: 0 0 auto; }
.form-actions .status { margin: 0; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0 8px;
}
.toolbar input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 15px;
}
.count { color: var(--muted); font-size: 14px; white-space: nowrap; }

.table-card { padding: 0; overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
thead th {
  text-align: left;
  background: #f8fafc;
  color: var(--muted);
  font-weight: 600;
  padding: 10px 12px;
  border-bottom: 1px solid #e2e8f0;
  white-space: nowrap;
}
tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}
tbody tr:hover { background: #f8fafc; }
td.num, th.num { text-align: right; white-space: nowrap; }
td.mono { font-family: ui-monospace, "Consolas", monospace; }
.actions-col { white-space: nowrap; text-align: right; width: 1%; }

.btn.small { flex: 0 0 auto; padding: 6px 12px; font-size: 13px; }
.btn.danger { color: #fff; background: var(--err); border-color: var(--err); }
.btn.danger:active { background: #b91c1c; }

.empty { padding: 24px; text-align: center; color: var(--muted); }

.st-cell { text-align: center; white-space: nowrap; }
.st-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 6px;
}
.st-btn:hover { background: #f1f5f9; }
.st-btn:active { transform: scale(0.92); }
.st { font-size: 18px; }

@media (max-width: 560px) {
  .form-grid { grid-template-columns: 1fr; }

  /* Order / invoice group headers: on narrow phones the meta row (Lock / PDF / Finish /
     Delete buttons + caret) can't fit next to the supplier name, so the right-most button
     (e.g. Finish) gets clipped off-screen and is hard to tap. Stack the meta BELOW the name
     so the buttons get a full-width row, let them wrap, and enlarge them into proper tap
     targets. */
  .group-head { flex-direction: column; align-items: stretch; gap: 8px; }
  .group-meta {
    white-space: normal;
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  }
  .group-meta .caret { margin-left: auto; }   /* keep the expand caret at the far right */
  .grp-finish, .grp-close, .grp-dl, .group-meta .send-sup {
    margin: 0; padding: 8px 14px; font-size: 14px;   /* ~36px tall, easy to tap */
  }
}

/* ---------- New-item / can't-scan report ---------- */
.link-btn {
  display: block;
  width: 100%;
  margin: 4px 0 0;
  padding: 8px;
  background: transparent;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}
.link-btn:active { background: #f1f5f9; }
.report-card { padding: 16px; text-align: center; }
.report-lead { margin: 0 0 10px; color: var(--muted); font-size: 14px; }
.report-btn { width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px; }

/* report form (scanner page modal) */
#reportOverlay .field textarea {
  font-family: inherit;
  resize: vertical;
  width: 100%;
  box-sizing: border-box;
}
/* hide the native file picker (its button text follows the OS language) and
   drive it with our own English button instead */
.file-hidden {
  position: absolute;
  width: 1px; height: 1px;
  opacity: 0; pointer-events: none;
}
.file-btn {
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: 16px;
  text-align: center;
  background: #ecfdf5;
  border: 2px dashed var(--teal);
  border-radius: 12px;
  color: var(--teal);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.file-btn:active { background: #d1fae5; }
#reportOverlay .btn.primary { width: 100%; margin-bottom: 8px; }
#reportOverlay .menu-cancel { width: 100%; }
.menu-sheet .check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  margin: 6px 2px 12px;
  cursor: pointer;
}
.menu-sheet .check input { width: 18px; height: 18px; }
.report-previews {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 4px;
}
.report-thumb {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  cursor: pointer;
}

/* report viewer table */
.photo-cell { white-space: nowrap; }
.photo-cell .report-thumb { width: 44px; height: 44px; margin-right: 4px; vertical-align: middle; }
.urgent-badge {
  display: inline-block;
  background: #fee2e2;
  color: #b91c1c;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.row-urgent > td { background: #fff1f2; }

/* full-size photo lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}
.lightbox.hidden { display: none; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

/* ---------- Invoice upload / mapping / review ---------- */
.map-preview-wrap { margin-top: 12px; }
.grid-preview { overflow-x: auto; border: 1px solid #e2e8f0; border-radius: 8px; }
.grid-preview table { font-size: 12px; border-collapse: collapse; min-width: 100%; }
.grid-preview th, .grid-preview td {
  border: 1px solid #eef2f7; padding: 4px 8px; white-space: nowrap;
  max-width: 160px; overflow: hidden; text-overflow: ellipsis;
}
.grid-preview thead th { background: #f1f5f9; color: var(--muted); position: sticky; top: 0; }
.grid-preview .rownum { background: #f8fafc; color: var(--muted); text-align: center; }

/* keep the table from squishing — force a min width so all columns fit;
   .review-scroll (overflow:auto) gives horizontal + vertical scrollbars */
.review-scroll { max-height: 70vh; overflow: auto; }
.supplier-badge { color: var(--brand, #185FA5); font-weight: 600; font-size: 16px; }
#reviewTable { min-width: 1600px; }
#reviewTable td { vertical-align: top; }
/* sticky header + footer while the rows scroll vertically */
#reviewTable thead th {
  position: sticky; top: 0; z-index: 3;
  background: #f1f5f9; border-bottom: 1px solid #e2e8f0;
}
#reviewTable tfoot td { position: sticky; bottom: 0; z-index: 3; }
#reviewTable .rownum { width: 40px; color: var(--muted); text-align: center; }
#reviewTable td.mark-cell { min-width: 180px; }
#reviewTable .cell {
  width: 100%; box-sizing: border-box; padding: 6px 8px;
  border: 1px solid #cbd5e1; border-radius: 6px; font-size: 14px;
}
#reviewTable .num-in { text-align: right; }
#reviewTable .qty-manual { border-color: #f59e0b; background: #fffbeb; }
#reviewTable td.num, #reviewTable th.num { width: 92px; }
#reviewTable td.ctr, #reviewTable th { text-align: left; }
#reviewTable td.ctr { text-align: center; vertical-align: middle; }
.matched-name { font-weight: 600; color: #15803d; margin-bottom: 4px; font-size: 13px; }
.matched-none { color: #334155; margin-bottom: 4px; font-size: 13px; }
.nm-tag {
  display: inline-block; background: #fee2e2; color: #b91c1c;
  font-size: 10px; font-weight: 700; padding: 0 6px; border-radius: 999px;
  vertical-align: middle; white-space: nowrap;
}
.carton-note { color: #2563eb; font-size: 11px; margin-bottom: 4px; }
.carton-warn { color: #b45309; font-size: 11px; margin-bottom: 4px; }
.cmp-note { color: #b45309; font-size: 11px; white-space: nowrap; }
#reviewTable .diff-cell.diff-up {   /* invoice dearer than system */
  background: #fee2e2; color: #b91c1c; font-weight: 700; border-radius: 6px;
}
#reviewTable .diff-cell.diff-down { /* invoice cheaper than system */
  background: #dcfce7; color: #15803d; font-weight: 700; border-radius: 6px;
}
#reviewTable tfoot td { border-top: 2px solid #e2e8f0; background: #f8fafc; font-size: 15px; }

/* row marks (OK / FOLLOW THAIKEE / SPECIAL / DISCOUNT / GOING TO RETURN) */
#reviewTable tr.row-mark-ok > td { background: #dcfce7; }
#reviewTable tr.row-mark-follow > td { background: #fef9c3; }
#reviewTable tr.row-mark-special > td { background: #e0f2fe; }
#reviewTable tr.row-mark-discount > td { background: #f3e8ff; }
#reviewTable tr.row-mark-return > td { background: #fee2e2; }
#reviewTable tr.row-mark-cantfind > td { background: #fed7aa; }
#reviewTable tr.row-mark-notify > td { background: #dbeafe; }
.mark-cell { white-space: nowrap; }
/* custom mark menu trigger (replaces the old <select> so Notify buyer can host a submenu) */
.mark-cell .mark-btn {
  font-size: 12px; padding: 5px 8px; border: 1px solid #cbd5e1; border-radius: 6px;
  max-width: 140px; margin-right: 4px; background: #fff; color: #334155; cursor: pointer;
  text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mark-cell .mark-btn.has-mark { border-color: var(--brand); color: var(--brand); font-weight: 600; }
.mark-cell .mark-btn:hover { border-color: var(--brand); }

/* the floating mark menu (fixed-positioned, so table overflow never clips it) */
#markPop {
  position: fixed; z-index: 1000; min-width: 160px;
  background: #fff; border: 1px solid #cbd5e1; border-radius: 10px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .18); padding: 5px;
}
#markPop[hidden] { display: none; }
#markPop .mk, #markPop .bk {
  display: block; width: 100%; box-sizing: border-box; text-align: left;
  background: none; border: 0; border-radius: 6px; padding: 8px 10px;
  font-size: 13px; color: #334155; cursor: pointer; white-space: nowrap;
}
#markPop .mk:hover, #markPop .bk:hover { background: #eef2f7; }
#markPop .mk.sel, #markPop .bk.sel { background: #dbeafe; color: var(--brand); font-weight: 700; }
#markPop .mk-clear { color: #94a3b8; border-top: 1px solid #e2e8f0; margin-top: 4px; }
#markPop .mk-sub-wrap { position: relative; }
#markPop .mk-has-sub { font-weight: 600; }
#markPop .mk-sub {
  display: none; position: absolute; right: 100%; top: 0; margin-right: 4px;
  min-width: 130px; max-height: 260px; overflow-y: auto;
  background: #fff; border: 1px solid #cbd5e1; border-radius: 10px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .18); padding: 5px;
}
#markPop .mk-sub-wrap:hover .mk-sub,
#markPop .mk-sub-wrap.open .mk-sub { display: block; }
#markPop .mk-empty { padding: 8px 10px; font-size: 12px; color: #94a3b8; }

/* My task page (buyer's notified items) */
.task-desc { font-weight: 600; color: #334155; font-size: 13px; }
.task-bc { color: #64748b; font-size: 12px; }
.task-replied { color: #15803d; font-size: 11px; margin-top: 3px; }
#taskTable tr.task-done > td { background: #f0fdf4; }
#taskTable .resp {
  font-size: 13px; padding: 6px 8px; border: 1px solid #cbd5e1; border-radius: 6px;
  max-width: 160px;
}
#taskTable td.diff-up { color: #b91c1c; font-weight: 700; }
#taskTable td.diff-down { color: #15803d; font-weight: 700; }
/* not-matched task: barcode scanner field + "please scan" prompt */
#taskTable .bc-field {
  width: 100%; box-sizing: border-box; margin-top: 4px; padding: 6px 8px;
  border: 1px solid var(--brand); border-radius: 6px; font-size: 12px;
  font-family: ui-monospace, monospace; background: #f0f7ff; cursor: pointer;
}
#taskTable .nm-msg { text-align: center; color: #b45309; font-weight: 600; font-size: 12px; }
#taskTable .nm-msg.done { color: #15803d; }
#taskTable tr.task-nm.task-done > td { background: #f0fdf4; }

/* Phone portrait: fit all 6 columns on screen (no sideways scroll) via a fixed layout.
   Order: Response · Supplier · Product · Diff · Unit · System. */
@media (max-width: 560px) {
  #taskTable { table-layout: fixed; width: 100%; font-size: 11px; }
  #taskTable th, #taskTable td { padding: 6px 3px; overflow: hidden; word-break: break-word; }
  #taskTable th.num, #taskTable td.num { white-space: nowrap; }   /* keep +$0.20 on one line */
  #taskTable th:nth-child(1), #taskTable td:nth-child(1) { width: 18%; }  /* Response */
  #taskTable th:nth-child(2), #taskTable td:nth-child(2) { width: 15%; }  /* Supplier  */
  #taskTable th:nth-child(3), #taskTable td:nth-child(3) { width: 27%; }  /* Product   */
  #taskTable th:nth-child(4), #taskTable td:nth-child(4) { width: 14%; }  /* Diff      */
  #taskTable th:nth-child(5), #taskTable td:nth-child(5) { width: 13%; }  /* Unit      */
  #taskTable th:nth-child(6), #taskTable td:nth-child(6) { width: 13%; }  /* System    */
  #taskTable .resp { width: 100%; max-width: 100%; font-size: 11px; padding: 4px 2px; }
  #taskTable .task-desc { font-size: 11px; }
  #taskTable .task-bc { font-size: 10px; }
  #taskTable .task-replied { font-size: 10px; }
}

/* Sent tasks page (admin overview) */
.st-reply { font-weight: 700; color: var(--brand); }
.st-wait { color: #b45309; font-weight: 600; }
.st-when { color: #64748b; font-size: 11px; }
/* Buyer cell stacks name / reply / sent-time (mirrors My-task's first column) */
.st-buyer-cell .st-buyer { font-weight: 500; }
.st-buyer-cell .st-resp { margin-top: 2px; }
.st-buyer-cell .st-sent { margin-top: 1px; }
#sentTable tr.task-done > td { background: #f0fdf4; }

/* Phone portrait: same treatment as My-task — fixed layout so all columns fit the
   screen (no sideways scroll). Order: Buyer&reply · Supplier · Product · Diff · Unit · System · ✕ */
@media (max-width: 560px) {
  #sentTable { table-layout: fixed; width: 100%; font-size: 11px; }
  #sentTable th, #sentTable td { padding: 6px 3px; overflow: hidden; word-break: break-word; }
  #sentTable th.num, #sentTable td.num { white-space: nowrap; }
  #sentTable th:nth-child(1), #sentTable td:nth-child(1) { width: 22%; }  /* Buyer & reply */
  #sentTable th:nth-child(2), #sentTable td:nth-child(2) { width: 14%; }  /* Supplier      */
  #sentTable th:nth-child(3), #sentTable td:nth-child(3) { width: 25%; }  /* Product       */
  #sentTable th:nth-child(4), #sentTable td:nth-child(4) { width: 13%; }  /* Diff          */
  #sentTable th:nth-child(5), #sentTable td:nth-child(5) { width: 11%; }  /* Unit          */
  #sentTable th:nth-child(6), #sentTable td:nth-child(6) { width: 11%; }  /* System        */
  #sentTable th:nth-child(7), #sentTable td:nth-child(7) { width: 4%; }   /* delete ✕      */
  #sentTable .task-desc { font-size: 11px; }
  #sentTable .task-bc, #sentTable .st-when { font-size: 10px; }
  #sentTable .st-sent { display: none; }   /* drop the sent-time line on phones to save space */
  #sentTable .row-del { padding: 2px; font-size: 12px; border: none; background: none; color: #b91c1c; }
}

/* other-suppliers expandable panel */
#reviewTable tr.detail-row > td { background: #f8fafc; padding: 10px 14px; }
.supplier-detail .sd-title { font-weight: 600; margin-bottom: 6px; font-size: 13px; color: var(--muted); }
.sd-table { border-collapse: collapse; font-size: 13px; }
.sd-table th, .sd-table td { border: 1px solid #e2e8f0; padding: 5px 12px; text-align: left; }
.sd-table th { background: #eef2f7; color: var(--muted); font-weight: 600; }
.sd-table .num { text-align: right; }
.filter-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.filter-bar select {
  padding: 6px 10px; border: 1px solid #cbd5e1; border-radius: 8px; font-size: 14px;
}
.barcode { font-family: ui-monospace, monospace; }
.row-unmatched > td { background: #fff7ed; }
.row-del {
  border: 1px solid #fca5a5; background: #fff; color: #b91c1c;
  border-radius: 6px; cursor: pointer; padding: 4px 8px; font-size: 13px;
}
.row-del:active { background: #fee2e2; }

/* charts */
.chart-box { max-width: 760px; margin: 8px auto 18px; }
.chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 2px 4px 4px; }
.chart-head-title { font-size: 14px; font-weight: 600; color: #334155; }
.chart-balance { font-size: 13px; font-weight: 700; color: var(--brand); white-space: nowrap; }
.chart-balance.neg { color: #dc2626; }

/* Inventory (net-flow) — TESTING */
.testing-tag {
  display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase; color: #92400e; background: #fde68a;
  padding: 1px 6px; border-radius: 6px; vertical-align: middle; margin-left: 4px;
}
.inv-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.inv-bar input { flex: 1; min-width: 180px; }
.inv-row { cursor: pointer; }
.inv-row:hover { background: #f1f5f9; }
.inv-row .it-name { font-weight: 600; }
.num.neg { color: #dc2626; }
.num.pos { color: #16a34a; }

/* Phone portrait: fixed layout so all 5 columns fit the screen — the Item column is
   capped (name wraps) so Net (4 wk) is always visible without sideways scrolling. */
@media (max-width: 560px) {
  #invTable { table-layout: fixed; width: 100%; font-size: 12px; }
  #invTable th, #invTable td { padding: 7px 5px; overflow: hidden; }
  #invTable th:nth-child(1), #invTable td:nth-child(1) { width: 33%; }   /* Item          */
  #invTable th:nth-child(2), #invTable td:nth-child(2) { width: 15%; }   /* Avg / wk       */
  #invTable th:nth-child(3), #invTable td:nth-child(3) { width: 19%; }   /* Net (4 wk)     */
  #invTable th:nth-child(4), #invTable td:nth-child(4) { width: 18%; }   /* Relative level */
  #invTable th:nth-child(5), #invTable td:nth-child(5) { width: 15%; }   /* Last received  */
  #invTable .it-name { white-space: normal; word-break: break-word; line-height: 1.25; }
  #invTable .sub { font-size: 10px; word-break: break-word; }
  #invTable td:nth-child(4) svg { width: 100%; height: auto; display: block; }
}

/* chart popup */
.chart-modal {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(15, 23, 42, .5);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.chart-modal.hidden { display: none; }
.chart-modal-box {
  background: #fff; border-radius: 14px; padding: 16px;
  width: min(820px, 96vw); max-height: 92vh; overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .3);
}
.chart-modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.chart-modal-head h2 { margin: 0; font-size: 17px; flex: 1 1 auto; min-width: 0; }
/* 4/6/8-weeks range dropdown in the chart popups */
.range-sel {
  flex: 0 0 auto; padding: 5px 8px; font: inherit; font-size: 13px;
  border: 1px solid #d1d5db; border-radius: 8px; background: #fff; color: #111;
}
.chart-close {
  border: none; background: #f1f5f9; border-radius: 8px;
  width: 32px; height: 32px; cursor: pointer; font-size: 15px; flex: 0 0 auto;
}
.chart-close:active { background: #e2e8f0; }
.inv-del {
  border: 1px solid #fca5a5; background: #fff; color: #b91c1c;
  border-radius: 6px; cursor: pointer; font-size: 13px; padding: 1px 8px; margin: 0 6px;
}
.inv-del:active { background: #fee2e2; }
.review-date {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-weight: 600; margin: 4px 0 2px;
}
.review-date input[type="date"], .review-date input:not([type]) {
  padding: 6px 8px; border: 1px solid #cbd5e1; border-radius: 6px; font-size: 14px;
}
.review-date input:not([type]) { min-width: 260px; max-width: 100%; }
.review-date input[type="date"]:focus, .review-date input:not([type]):focus { outline: 2px solid var(--brand, #185FA5); outline-offset: 0; border-color: var(--brand, #185FA5); }
.review-date .sub { font-weight: 400; }
.inv-editdate {
  border: 1px solid #bcd0e6; background: #fff; color: var(--brand, #185FA5);
  border-radius: 6px; cursor: pointer; font-size: 13px; padding: 1px 8px;
}
.inv-editdate:active { background: #eef4fb; }
/* Inline invoice-date editor in the header */
.inv-date-edit { font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.inv-date-in { padding: 4px 6px; border: 1px solid #cbd5e1; border-radius: 6px; font-size: 14px; }
.inv-date-in:focus { outline: 2px solid var(--brand, #185FA5); outline-offset: 0; border-color: var(--brand, #185FA5); }
.inv-date-save {
  border: 1px solid #86c9a0; background: #fff; color: #157347;
  border-radius: 6px; cursor: pointer; font-size: 14px; padding: 2px 9px; margin-left: 6px;
}
.inv-date-save:active { background: #e7f4ec; }
.inv-date-cancel {
  border: 1px solid #cbd5e1; background: #fff; color: #475569;
  border-radius: 6px; cursor: pointer; font-size: 14px; padding: 2px 9px; margin-left: 4px;
}
.inv-date-cancel:active { background: #f1f5f9; }
.line-del {
  border: 1px solid #fca5a5; background: #fff; color: #b91c1c;
  border-radius: 6px; cursor: pointer; font-size: 12px; padding: 0 6px; line-height: 20px;
}
.line-del:active { background: #fee2e2; }
/* Inline line-edit controls (qty / unit / line total) */
.line-edit {
  border: 1px solid #bcd0e6; background: #fff; color: var(--brand, #185FA5);
  border-radius: 6px; cursor: pointer; font-size: 12px; padding: 0 6px; line-height: 20px; margin-right: 4px;
}
.line-edit:active { background: #eef4fb; }
.line-save {
  border: 1px solid #86c9a0; background: #fff; color: #157347;
  border-radius: 6px; cursor: pointer; font-size: 13px; padding: 0 7px; line-height: 20px; margin-right: 4px;
}
.line-cancel {
  border: 1px solid #cbd5e1; background: #fff; color: #475569;
  border-radius: 6px; cursor: pointer; font-size: 13px; padding: 0 7px; line-height: 20px;
}
.line-save:active { background: #e7f4ec; }
.line-cancel:active { background: #f1f5f9; }
.pe-in {
  width: 74px; padding: 4px 6px; border: 1px solid #cbd5e1; border-radius: 6px;
  font-size: 13px; text-align: right; font-variant-numeric: tabular-nums;
}
.pe-in:focus { outline: 2px solid var(--brand, #185FA5); outline-offset: 0; border-color: var(--brand, #185FA5); }
.inv-item-row.editing { cursor: default; background: #f8fbff; }
.inv-item-row.editing:hover > td { background: #f8fbff; }
.inv-item-row { cursor: pointer; }
.inv-item-row:hover > td { background: #ecfdf5; }

/* ---------- Safety stock page ---------- */
.ss-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.ss-bar input[type="search"] {
  flex: 1 1 240px; min-width: 180px; padding: 9px 12px;
  border: 1px solid #cbd5e1; border-radius: 10px; font-size: 14px;
}
.ss-bar input[type="search"]:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
.ss-table thead th { cursor: pointer; user-select: none; white-space: nowrap; }
.ss-table thead th.sorted { color: var(--brand); }
.ss-table thead th::after { content: attr(data-arrow); font-size: 10px; }
.ss-table td.num { font-variant-numeric: tabular-nums; }

/* Reports (Department sale / Slow movers / Safety stock / Relative inventory):
   scroll the rows inside the card and freeze the column headers, like the
   invoice review table. Keeps horizontal scroll working on phones. */
.report-scroll { max-height: 72vh; overflow: auto; }
.report-scroll table.orders-table th {
  position: sticky; top: 0; z-index: 2;
  background: #fff;
  box-shadow: inset 0 -1px 0 #e2e8f0;   /* border-collapse drops real borders when sticky */
}
/* Freeze the first column (Product/Item) too, so rows stay identifiable when
   scrolling sideways. The corner header sits above both sticky edges. */
.report-scroll table.orders-table td:first-child {
  position: sticky; left: 0; z-index: 1;
  background: #fff;
  box-shadow: 1px 0 0 #e2e8f0;          /* divider down its right edge */
}
.report-scroll table.orders-table th:first-child {
  left: 0; z-index: 3;                   /* position/top inherited from the header rule */
  box-shadow: inset 0 -1px 0 #e2e8f0, 1px 0 0 #e2e8f0;
}
.report-scroll table.orders-table tbody tr:hover td:first-child { background: #f8fafc; }
.chip-ok, .chip-er, .chip-low, .chip-so {
  display: inline-block; font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px; line-height: 1.6; white-space: nowrap;
}
.chip-ok { color: #15803d; background: #e7f4ec; }
.chip-er { color: #b4530a; background: #fbecdd; }
.chip-low { color: #475569; background: #eef2f7; }
.chip-so { color: #1d4ed8; background: #e5edff; }   /* stockout-adjusted (lost sales added back) */
.pending-card { padding: 14px; margin-bottom: 10px; }
/* Pending receiving cards are wider than the default admin column so a long supplier
   name doesn't shove the two action buttons onto the next line. */
main.admin.pending-page { max-width: 1150px; }
/* nowrap: the buttons stay on the row; a long supplier name wraps INSIDE the left
   column (min-width:0) instead of pushing them down. Phones fall back to wrapping. */
.pending-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: nowrap; }
.pending-row > div:first-child { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.pending-actions { display: flex; gap: 8px; flex-wrap: nowrap; flex: 0 0 auto; }
.pending-actions .btn { text-decoration: none; white-space: nowrap; }
@media (max-width: 560px) {
  .pending-row { flex-wrap: wrap; }   /* small phones: buttons drop below the text */
}
.pm-badge {
  display: inline-block; background: #dcfce7; color: #15803d;
  font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 999px;
  margin-left: 6px; white-space: nowrap;
}
.btn.btn-on { background: #dcfce7; border-color: #86efac; color: #15803d; }

/* ---------- Sale order / invoice (B2B) ---------- */
/* The details page reuses .form-grid, which only styled <input> — selects and the
   notes textareas need the same box so the two-column form stays even. */
.form-grid select, .form-grid textarea {
  padding: 10px; border: 1px solid #cbd5e1; border-radius: 8px;
  font-size: 15px; font-family: inherit; color: var(--text); resize: vertical;
}
.cust-info { margin-top: 12px; padding: 10px 12px; background: #f8fafc; border-radius: 10px; }
.cust-info table.kv td:first-child { width: 140px; }
#custPick { flex: 1 1 260px; min-width: 200px; padding: 10px; border: 1px solid #cbd5e1;
  border-radius: 8px; font-size: 15px; }
#custSearch { flex: 1 1 240px; min-width: 200px; padding: 10px 12px;
  border: 1px solid #cbd5e1; border-radius: 10px; font-size: 15px; }

/* Scanning tab: the order header sits above the camera so staff can see whose order
   they're building without switching back to the details tab. */
.so-head { padding: 12px 14px; }
.so-head-main { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.so-head-main b { font-size: 16px; }
.so-head table.kv { margin-top: 6px; }
.so-head table.kv td:first-child { width: 130px; }
/* Sale order working page: two columns on desktop (scanner left, order right),
   stacked on phones. */
main.sale-scan-page { max-width: min(1280px, 97vw); }
.sale-scan-grid { display: grid; gap: 16px; grid-template-columns: 1fr; align-items: start; }
/* Let the columns shrink below their content so the lines table scrolls inside its own
   box instead of pushing the whole page sideways. */
.ss-left, .ss-right { min-width: 0; }
@media (min-width: 900px) {
  .sale-scan-grid { grid-template-columns: minmax(320px, 400px) 1fr; }
  /* Keep the camera + controls in view while the lines list grows. */
  .ss-left { position: sticky; top: 72px; }
}
.ss-left .reader-wrap { margin-top: 0; }
.ss-right > .card:first-child { margin-top: 0; }

/* Item list: sticky header while the rows scroll (like the invoice review table). */
.so-lines-scroll { max-height: 58vh; overflow: auto; }
.so-lines { min-width: 640px; }
.so-lines thead th {
  position: sticky; top: 0; z-index: 2;
  background: #f1f5f9; border-bottom: 1px solid #e2e8f0;
}
.so-lines td { vertical-align: middle; }
.so-lines td.so-item { min-width: 160px; white-space: normal; }
.so-lines tbody tr:hover { background: #fafcff; }

/* Freeze the Item column too, so you can still tell which row is which when scrolling
   the table sideways on a phone. */
.so-lines th:first-child,
.so-lines td.so-item {
  position: sticky; left: 0;
  background: #fff;
  box-shadow: 1px 0 0 #e2e8f0;   /* thin divider down its right edge */
}
.so-lines td.so-item { z-index: 1; }               /* above the normal body cells */
.so-lines thead th:first-child {
  z-index: 3;                                       /* the corner: above both sticky edges */
  background: #f1f5f9;
}
.so-lines tbody tr:hover td.so-item { background: #fafcff; }

/* Inline-editable cells. */
.ln-in {
  width: 74px; max-width: 100%; padding: 6px 7px; text-align: right;
  border: 1px solid #cbd5e1; border-radius: 6px; font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.ln-in:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
.ln-qty { width: 58px; }
.ln-disc-wrap { display: inline-flex; align-items: stretch; gap: 4px; justify-content: flex-end; }
.ln-disc { width: 56px; }
.ln-dtype {
  flex: 0 0 auto; width: 30px; border: 1px solid #cbd5e1; border-radius: 6px;
  background: #fff; color: var(--brand); font-weight: 700; font-size: 14px; cursor: pointer;
}
.ln-dtype:hover { background: #eef4fb; }
.so-lines .ln-total b { font-variant-numeric: tabular-nums; }

/* Item entry popup: discount value + its %/$ mode switch on one row. */
#saleForm .field {
  display: flex; flex-direction: column; gap: 6px; font-size: 13px;
  color: var(--muted); margin-bottom: 14px; padding: 0 4px;
}
#saleForm .field input {
  padding: 12px; border: 1px solid #cbd5e1; border-radius: 10px;
  font-size: 16px; color: var(--text);
}
#saleForm .btn.primary { margin-bottom: 8px; }
.so-pop-kv { margin: 0 4px 12px; }
.disc-row { display: flex; gap: 8px; align-items: stretch; }
.disc-row input { flex: 1; }
.seg { display: flex; flex: 0 0 auto; border: 1px solid #cbd5e1; border-radius: 10px; overflow: hidden; }
.seg-btn {
  border: none; background: #fff; color: var(--muted);
  padding: 0 14px; font-size: 15px; cursor: pointer;
}
.seg-btn + .seg-btn { border-left: 1px solid #cbd5e1; }
.seg-btn.active { background: var(--brand); color: #fff; font-weight: 600; }
.so-calc {
  margin: 0 4px 14px; padding: 10px 12px; background: #f8fafc;
  border-radius: 10px; font-size: 14px;
}
.so-calc div { display: flex; justify-content: space-between; align-items: baseline; padding: 2px 0; }
.so-calc div:last-child b { font-size: 18px; color: var(--brand); }

/* Sale order header: the details fold open for editing (native <details>). */
#soDetails { margin-top: 8px; }
#soDetails > summary {
  cursor: pointer; font-size: 13px; color: var(--brand); font-weight: 600;
  padding: 6px 0; list-style: none;
}
#soDetails > summary::-webkit-details-marker { display: none; }
#soDetails > summary::before { content: "▸ "; display: inline-block; transition: transform .15s; }
#soDetails[open] > summary::before { content: "▾ "; }
#soDetails .form-grid { margin: 8px 0 4px; }
#soNumber { margin-left: 0; }

/* Standard discount + totals block at the bottom of an order. */
.so-totals { padding: 14px; }
.std-row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding-bottom: 12px; margin-bottom: 8px; border-bottom: 1px solid #f1f5f9;
  font-size: 14px;
}
.std-input { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.std-input input {
  width: 92px; padding: 10px; border: 1px solid #cbd5e1; border-radius: 8px;
  font-size: 16px; text-align: right;
}
.tot-row {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 5px 0; font-size: 14px;
}
.tot-row b { font-variant-numeric: tabular-nums; }
.tot-row.muted { color: var(--muted); }
.tot-row.grand {
  margin-top: 6px; padding-top: 10px; border-top: 2px solid #e2e8f0; font-size: 16px;
}
.tot-row.grand b { font-size: 20px; color: var(--brand); }

/* Sale order list */
.so-list tbody tr { cursor: pointer; }
.so-list tbody tr:hover { background: #f8fafc; }
.so-list tbody tr:active { background: #f1f5f9; }
