/* Brand palette pulled from forwardfurniture.ca: near-black + white with a single amber
   accent, Roboto, small 4px radii, wide letter-spacing. --ink is new (used only in this
   file's own rules below); --accent is reused as-is everywhere it already appears inline
   in the HTML/JS (badges, risk-color chips), so those keep working unchanged. */
:root {
  --bg: #ffffff;
  --panel: #fafaf9;
  --panel-2: #f2f1ed;
  --border: #e3e1db;
  --text: #111111;
  --text-dim: #6b6b68;
  --accent: #c17f0a;
  --ink: #111111;
  --green: #1a7f4b;
  --yellow: #b8860b;
  --orange: #c1580a;
  --red: #c0392b;
  --purple: #7c5cbf;
  --topbar-h: 73px; /* fallback; measured live and overridden per-page where a sticky summary needs it */
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Roboto, -apple-system, Segoe UI, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  letter-spacing: 0.2px;
}

.app { max-width: none; width: 100%; margin: 0; padding: 24px; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 12px;
  /* Freeze the header/nav at the top while the page scrolls. --topbar-h is measured live by
     nav-reports-link.js so the sticky table column-headers (th, below) sit just under it. The
     negative top + matching padding-top pull the bar flush to the very top of the viewport,
     cancelling the .app 24px padding so nothing peeks above it. */
  position: sticky;
  top: -1px;
  z-index: 30;
  background: var(--bg);
  padding-top: 24px;
  margin-top: -24px;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 500; color: var(--text-dim); }
/* margin-left:auto keeps this pinned to the top-right corner even when .topbar wraps to a
   second row on narrow viewports - without it, a wrapped topbar-actions block falls back to
   the row's default left edge instead of staying at the right. */
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-left: auto; }

.brand {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 1.5px;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}
.brand span { font-size: 9px; font-weight: 400; letter-spacing: 3px; color: var(--text-dim); }

.btn {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  letter-spacing: 0.3px;
  transition: border-color 0.15s, background 0.15s;
}
.btn:hover { border-color: var(--ink); }
.btn-primary { background: var(--ink); border-color: var(--ink); color: white; font-weight: 700; }
.btn-primary:hover { background: #000000; }
.btn-ghost { background: transparent; }
.btn-danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: rgba(192,57,43,0.08); }

.msg-tab { border-radius: 0; border: none; border-bottom: 2px solid transparent; padding-bottom: 8px; }
.msg-tab.active { border-bottom-color: var(--accent); font-weight: 600; }

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}
/* Pins the summary tiles just under the (already-sticky) topbar so they stay visible while
   scrolling a long table below - --topbar-h is measured live per-page (see invoices-app.js)
   since the topbar's real height can vary (nav wrapping, etc.), not just the :root fallback. */
.summary.sticky-summary {
  position: sticky;
  top: var(--topbar-h);
  z-index: 20;
  background: var(--bg);
  /* Cancels .topbar's margin-bottom:20px (they'd otherwise collapse into a visible gap only
     at the very top of the page, before scrolling triggers the sticky top offset - once stuck,
     the gap already closes on its own, so this just makes the un-scrolled state match it). */
  margin-top: -20px;
  padding-top: 8px;
  padding-bottom: 4px;
}
/* Pins the small 3PL x product matrix right below the sticky summary tiles - --sticky-matrix-top
   is measured live (topbar height + summary height) since both vary. z-index below .summary's
   so the summary tiles' own shadow/border still reads as "in front" while both are stuck. */
.table-wrap.sticky-matrix {
  position: sticky;
  top: var(--sticky-matrix-top, var(--topbar-h));
  z-index: 15;
  /* Same margin-collapse cancellation as .sticky-summary, against .summary's margin-bottom:20px. */
  margin-top: -20px;
}
/* Pins the search/filter toolbar (incl. the Status dropdown) right below the sticky matrix -
   --sticky-toolbar-top is measured live (topbar + summary + matrix heights), same reasoning
   as the two rules above. Needs its own background since .toolbar has none by default. */
.toolbar.sticky-toolbar {
  position: sticky;
  top: var(--sticky-toolbar-top, var(--topbar-h));
  z-index: 14;
  background: var(--bg);
  /* Cancels #matrixWrap's inline margin-bottom:20px (same collapse pattern as the two rules above). */
  margin-top: -20px;
  padding-top: 6px;
  padding-bottom: 6px;
}
/* Cancels .sticky-toolbar's own margin-bottom:14px so the invoices table's now page-sticky
   header (#invoicesTable thead th, via --sticky-table-top) sits flush under it at rest too. */
#invoicesTableWrap { margin-top: -14px; }
.summary-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
}
.summary-card .num { font-size: 22px; font-weight: 700; color: var(--ink); }
.summary-card .label { font-size: 11px; color: var(--text-dim); margin-top: 2px; text-transform: uppercase; letter-spacing: 0.6px; }
.summary-card.clickable { cursor: pointer; transition: border-color 0.15s, box-shadow 0.15s; }
.summary-card.clickable:hover { border-color: var(--accent); box-shadow: 0 1px 4px rgba(0,0,0,0.08); }
.summary-card.overdue { border-color: var(--red); }
.summary-card.overdue .num { color: var(--red); }

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.toolbar input[type=text], .toolbar select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 4px;
  font-size: 13px;
}
#search { min-width: 240px; }
.overdue-toggle { font-size: 13px; color: var(--text-dim); display: flex; align-items: center; gap: 6px; }
.spacer { flex: 1; }

.table-wrap {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: auto;
  /* Cap the height so the table scrolls inside its own box, which keeps the
     column header frozen at the top (sticky) instead of scrolling off-page. */
  max-height: calc(100vh - 210px);
}
/* Opt out of the own-box scroll above: used when the table's header should instead stick to
   the page scroll (stacked under other sticky sections, e.g. invoices.html's toolbar) rather
   than to a capped-height inner scrollbox - the two don't compose (a sticky child only sticks
   within its nearest *scrolling* ancestor, so as long as .table-wrap itself scrolls, the outer
   page scrolling it out of view takes the header with it). */
.table-wrap.flat-scroll { overflow: visible; max-height: none; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; cursor: pointer; user-select: none; position: sticky; top: 0; z-index: 3; background: var(--panel-2); border-bottom: 2px solid var(--accent); }
th:hover { color: var(--ink); }
tbody tr:hover { background: var(--panel); }
td.notes-cell { white-space: normal; width: 340px; max-width: 340px; color: var(--text-dim); vertical-align: top; }
.notes-clip {
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
  cursor: help;
}
td.editable-row { cursor: pointer; }
td.lineitem-cell { vertical-align: top; white-space: nowrap; line-height: 1.6; }
label.checkbox-row { flex-direction: row; align-items: center; gap: 8px; }
.group-row td {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--ink);
  font-weight: 700;
  color: #ffffff;
  border-top: 2px solid var(--accent);
  border-bottom: 1px solid var(--border);
  letter-spacing: .02em;
}
td.grp-idx { color: var(--text-dim); text-align: center; vertical-align: top; }
.group-row .grp-name { font-size: 14px; color: #ffffff; }
.group-row .grp-total { float: right; font-weight: 600; font-size: 12px; color: #ffffff; }
.group-row .subtle { color: rgba(255,255,255,0.82); font-weight: 400; }
/* Order Status: freeze each section header (Lightspeed Kelowna / Shopify / Kirby &
   Andreas) just under the frozen column header (38px) while scrolling that section;
   the next section's header takes over as you reach it. separate border-collapse is
   required for a sticky <td> to hold mid-table in Chromium. */
#ordersTable { border-collapse: separate; border-spacing: 0; }
#ordersTable .group-row td { position: sticky; top: 38px; z-index: 2; }
/* PO Tracker: freeze each supplier's group header just under the frozen column header
   (38px) while scrolling that supplier's POs; the next supplier's header takes over. */
#poTable { border-collapse: separate; border-spacing: 0; }
#poTable .group-row td { position: sticky; top: 38px; z-index: 2; }
/* 3PL Invoices: freeze ONLY the top column-header line (Invoice #, Date, ...).
   The 3PL highlighted bars scroll normally with the invoices. */
#invoicesTable thead th { position: sticky; top: var(--sticky-table-top, 0); z-index: 5; }
#invoicesTable .group-row td { position: static; background: var(--ink); }
/* Uniform font (same family + size) across the whole 3PL invoice table, so no
   cell stands out - normalizes the monospace invoice #, the 12px date/badge
   text, and the 14px 3PL bar to one consistent style. */
#invoicesTable th,
#invoicesTable td,
#invoicesTable .mono,
#invoicesTable .subtle,
#invoicesTable .grp-name,
#invoicesTable .grp-total,
#invoicesTable .badge,
#invoicesTable .days-badge,
#catalogTable td,
#catalogTable code,
#adjustmentsTable td,
#adjustmentsTable code {
  font-family: Roboto, -apple-system, Segoe UI, Helvetica, Arial, sans-serif;
  font-size: 13px;
}

/* 3PL Invoices: one table per 3PL, each with its own sticky <thead> so the
   highlighted 3PL bar + column header freeze while that 3PL's rows scroll. */
.invoice-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}
.invoice-table thead .group-row th {
  position: sticky;
  top: 0;
  z-index: 4;
  background: var(--ink);
  color: #ffffff;
  font-weight: 700;
  text-align: left;
  border-top: 2px solid var(--accent);
  border-bottom: 1px solid var(--border);
  letter-spacing: .02em;
  cursor: default;
}
.invoice-table thead .col-header th {
  /* frozen just below the 3PL bar so both stay pinned while the rows scroll */
  position: sticky;
  top: 41px;
  z-index: 3;
  background: var(--panel-2);
  color: var(--text);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-align: left;
  border-bottom: 2px solid var(--accent);
  cursor: default;
}
.invoice-table tbody td { overflow: hidden; text-overflow: ellipsis; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
}
.badge-clickable { cursor: pointer; text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 2px; }
.badge-clickable:hover { filter: brightness(0.92); }
.badge-Ordered { background: rgba(107,107,104,0.13); color: var(--text-dim); }
.badge-Confirmed { background: rgba(193,127,10,0.14); color: var(--accent); }
.badge-Shipped { background: rgba(124,92,191,0.14); color: var(--purple); }
.badge-In-Transit { background: rgba(184,134,11,0.14); color: var(--yellow); }
.badge-Customs { background: rgba(193,88,10,0.14); color: var(--orange); }
.badge-Delivered { background: rgba(26,127,75,0.14); color: var(--green); }
.badge-Received { background: rgba(26,127,75,0.22); color: var(--green); }
.badge-Delayed-Issue { background: rgba(192,57,43,0.14); color: var(--red); }

/* 3PL invoice status badges */
.badge-Paid { background: rgba(26,127,75,0.14); color: var(--green); }
.badge-Unpaid { background: rgba(184,134,11,0.14); color: var(--yellow); }
.badge-Disputed { background: rgba(192,57,43,0.16); color: var(--red); }

/* Customer order-status badges */
.badge-in_stock { background: rgba(26,127,75,0.14); color: var(--green); }
.badge-backorder_eta { background: rgba(184,134,11,0.14); color: var(--yellow); }
.badge-awaiting_eta { background: rgba(193,88,10,0.14); color: var(--orange); }
.badge-unlinked { background: rgba(192,57,43,0.16); color: var(--red); }
.badge-Processed { background: rgba(193,127,10,0.14); color: var(--accent); }
.badge-Exception { background: rgba(192,57,43,0.16); color: var(--red); }

.summary-card.risk { border-color: var(--red); }
.summary-card.risk .num { color: var(--red); }
.summary-card.ready { border-color: var(--green); }
.summary-card.ready .num { color: var(--green); }
.summary-card.stock { border-color: var(--accent); }
.summary-card.stock .num { color: var(--accent); }
#stockMatrix .stock-total td, #backorderMatrix .stock-total td, #remainingMatrix .stock-total td { border-top: 2px solid var(--border); font-weight: 600; }
#backorderMatrix .bom-sep td, #remainingMatrix .bom-sep td { background: var(--panel-2); color: var(--text); font-weight: 600; font-size: 12px; padding: 6px 12px; border-top: 2px solid var(--accent); border-bottom: 1px solid var(--border); }
#backorderMatrix .bom-row td, #remainingMatrix .bom-row td { color: var(--text); }

.nav-links { display: flex; gap: 4px; align-items: center; }
.nav-link {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid transparent;
}
.nav-link:hover { color: var(--ink); border-color: var(--border); }
.nav-link.active { color: var(--ink); background: transparent; border-color: transparent; border-bottom: 2px solid var(--accent); border-radius: 0; font-weight: 600; }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.sku-map { color: var(--text-dim); }
.sku-map b { color: var(--text); }
td.eta-cell { font-weight: 600; }
.row-risk { background: rgba(192,57,43,0.05); }
.subtle { color: var(--text-dim); font-size: 12px; }
.days-badge { color: var(--text-dim); font-size: 12px; }
.days-badge.slow { color: var(--orange); font-weight: 600; }

.row-overdue td.eta-col { color: var(--red); font-weight: 600; }

.empty-state { padding: 60px 20px; text-align: center; color: var(--text-dim); }

/* Product Catalog: "Columns" show/hide panel (inventory-catalog-app.js). Preference is per
   column class (col-warehouse etc. on both the <th> and its matching <td>s); hiding just
   toggles a hide-col-X class on the table itself rather than re-rendering rows. */
.col-panel {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 30;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 14px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.col-panel label { display: flex; align-items: center; gap: 8px; font-size: 13px; white-space: nowrap; }
#catalogTable.hide-col-sku .col-sku,
#catalogTable.hide-col-name .col-name,
#catalogTable.hide-col-category .col-category,
#catalogTable.hide-col-warehouse .col-warehouse,
#catalogTable.hide-col-onhand .col-onhand,
#catalogTable.hide-col-available .col-available,
#catalogTable.hide-col-backorder .col-backorder,
#catalogTable.hide-col-cost .col-cost,
#catalogTable.hide-col-reorder .col-reorder,
#catalogTable.hide-col-supplier .col-supplier {
  display: none;
}

.row-actions { display: flex; gap: 6px; }
.row-actions button { background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 13px; }
.row-actions button:hover { color: var(--accent); }

.modal-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(17,17,17,0.55);
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 22px;
  width: 640px;
  max-width: 92vw;
  max-height: 88vh;
  overflow: auto;
  box-shadow: 0 12px 40px rgba(17,17,17,0.18);
}
.modal h2 { margin-top: 0; font-size: 17px; font-weight: 700; }
.modal .hint { font-size: 12px; color: var(--text-dim); line-height: 1.5; }
.modal .hint code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-dim); }
label.full { margin-bottom: 12px; }
input, select, textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
#pasteArea { width: 100%; margin-top: 10px; }
.modal-actions { display: flex; gap: 8px; margin-top: 10px; align-items: center; }

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--ink);
  border: 1px solid var(--ink);
  color: #ffffff;
  padding: 12px 16px;
  border-radius: 6px;
  font-size: 13px;
  max-width: 360px;
  box-shadow: 0 8px 24px rgba(17,17,17,0.25);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateY(0); }
