/* Coastal Brew Baits: inventory dashboard
   Quiet bay-water palette; the stock gauge is the one bold element. */

:root {
  --laguna:   #12323d;   /* ink, header */
  --channel:  #0d6e78;   /* primary action, gauge fill */
  --shallows: #d6e9e7;   /* selected / hover tint */
  --flat:     #f2f6f5;   /* page */
  --sand:     #ffffff;   /* surfaces */
  --line:     #d3dedc;
  --muted:    #5a6f74;

  --low:      #9a5b00;
  --low-bg:   #fdf0d8;
  --low-fill: #e0a133;
  --out:      #a42a22;
  --out-bg:   #fbe6e3;

  --font: "Barlow", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-head: "Barlow Semi Condensed", var(--font);

  --radius-sm: 4px;
  --radius: 8px;
  --focus: 0 0 0 3px rgba(13, 110, 120, .35);
}

* { box-sizing: border-box; }

/* Components below set display:flex/grid; without this, [hidden] would be ignored. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--flat);
  color: var(--laguna);
  font: 400 15px/1.45 var(--font);
  font-variant-numeric: tabular-nums;
}

button, input, select { font: inherit; color: inherit; }

:focus-visible { outline: none; box-shadow: var(--focus); }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 24px;
  background: var(--laguna);
  color: #e7f1f0;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-logo { width: 40px; height: 40px; flex: none; display: block; }
.brand-name { font: 700 20px/1 var(--font-head); letter-spacing: .01em; }
.brand-area { font-size: 15px; color: #9fc3c1; }
.topbar-notes { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px 20px; }
.sync-note { margin: 0; font-size: 13px; color: #9fc3c1; }

.page { max-width: 1320px; margin: 0 auto; padding: 20px 24px 48px; }

/* ---------- Summary tallies ---------- */
.summary {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px; background: var(--line);
  border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; margin-bottom: 16px;
}
.tally {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 12px 16px; border: 0; background: var(--sand);
  text-align: left; cursor: pointer;
}
.tally:hover { background: #f7fbfa; }
.tally[aria-pressed="true"] { background: var(--shallows); box-shadow: inset 0 -3px 0 var(--channel); }
.tally-static { cursor: default; }
.tally-static:hover { background: var(--sand); }
.tally-num { font: 700 28px/1.1 var(--font-head); }
.tally-label { font-size: 13px; color: var(--muted); }
.tally-low .tally-num { color: var(--low); }
.tally-out .tally-num { color: var(--out); }
.tally-low[aria-pressed="true"] { background: var(--low-bg); box-shadow: inset 0 -3px 0 var(--low-fill); }
.tally-out[aria-pressed="true"] { background: var(--out-bg); box-shadow: inset 0 -3px 0 var(--out); }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 12px; }

.search { position: relative; flex: 1 1 320px; max-width: 480px; }
.search input {
  width: 100%; height: 42px; padding: 0 40px 0 38px;
  background: var(--sand); border: 1px solid var(--line); border-radius: var(--radius);
}
.search input:focus { border-color: var(--channel); }
.search-icon {
  position: absolute; left: 12px; top: 11px; width: 20px; height: 20px;
  fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round;
}
.search-hint {
  position: absolute; right: 10px; top: 10px;
  padding: 1px 7px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  font: 500 12px/18px var(--font); color: var(--muted); background: var(--flat);
}
.search input:focus ~ .search-hint { display: none; }

.segmented {
  display: inline-flex; background: var(--sand);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 3px;
}
.segmented button {
  border: 0; background: none; padding: 6px 14px; border-radius: 5px;
  cursor: pointer; font-weight: 500; color: var(--muted);
}
.segmented button:hover { color: var(--laguna); }
.segmented button[aria-pressed="true"] { background: var(--laguna); color: #fff; }

.result-count { margin: 0 0 0 auto; font-size: 13px; color: var(--muted); }

/* ---------- Table ---------- */
.table-wrap {
  background: var(--sand); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: auto; max-height: calc(100vh - 250px); min-height: 240px;
}
.inv { width: 100%; border-collapse: separate; border-spacing: 0; }

.inv th {
  position: sticky; top: 0; z-index: 2;
  background: #e8f0ef; border-bottom: 1px solid var(--line);
  text-align: left; white-space: nowrap; padding: 0;
}
.inv th button {
  display: flex; align-items: center; gap: 4px; width: 100%;
  padding: 10px 12px; border: 0; background: none; cursor: pointer;
  font-weight: 600; font-size: 13px; color: var(--muted);
}
.inv th.num button { justify-content: flex-end; }
.inv th button:hover { color: var(--laguna); }
.inv th[aria-sort] button { color: var(--laguna); }
.inv th[aria-sort] button::after { content: "▲"; font-size: 9px; }
.inv th[aria-sort="descending"] button::after { content: "▼"; }

.inv td {
  padding: 9px 12px; border-bottom: 1px solid #e6eeec;
  white-space: nowrap; vertical-align: middle;
}
.inv tbody tr { cursor: pointer; }
.inv tbody tr:hover td { background: #f5faf9; }
.inv tbody tr:focus-visible { box-shadow: none; }
.inv tbody tr:focus-visible td { background: var(--shallows); }
.inv tbody tr:last-child td { border-bottom: 0; }

/* First column stays put when the table scrolls sideways on tablets. */
.inv .col-product, .inv td:first-child {
  position: sticky; left: 0; z-index: 1; background: inherit;
}
.inv th.col-product { z-index: 3; background: #e8f0ef; }
.inv td:first-child { background: var(--sand); box-shadow: 1px 0 0 #e6eeec; }

.num { text-align: right; }
.prod-name { font-weight: 600; }
.prod-label { display: block; font-size: 13px; color: var(--muted); }
.code { letter-spacing: .02em; }
.blank { color: #9aabae; }

/* Low and out rows (UI-3) carry a left edge mark as well as the gauge colour,
   so status never depends on colour alone. */
.inv tr.is-low td:first-child  { box-shadow: inset 4px 0 0 var(--low-fill), 1px 0 0 #e6eeec; }
.inv tr.is-out td:first-child  { box-shadow: inset 4px 0 0 var(--out), 1px 0 0 #e6eeec; }

/* ---------- Stock gauge: the bar fills toward 4x the alert level;
   the tick marks the alert level itself. ---------- */
.gauge { display: grid; grid-template-columns: 3.2ch 1fr auto; align-items: center; gap: 10px; min-width: 200px; }
.gauge-num { font: 700 17px/1 var(--font-head); text-align: right; }
.gauge-track {
  position: relative; height: 8px; border-radius: 4px; background: #e4ecea;
}
.gauge-fill {
  position: absolute; inset: 0 auto 0 0; border-radius: 4px; background: var(--channel);
}
.gauge-tick {
  position: absolute; top: -4px; bottom: -4px; width: 2px; margin-left: -1px;
  background: var(--laguna); opacity: .55;
}
.gauge-tag {
  font-size: 12px; font-weight: 600; padding: 1px 7px; border-radius: 10px;
  visibility: hidden;
}
.is-low .gauge-num { color: var(--low); }
.is-low .gauge-fill { background: var(--low-fill); }
.is-low .gauge-tag { visibility: visible; background: var(--low-bg); color: var(--low); }
.is-out .gauge-num { color: var(--out); }
.is-out .gauge-tag { visibility: visible; background: var(--out-bg); color: var(--out); }

/* ---------- Empty / error states ---------- */
.empty { padding: 48px 24px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--laguna); font-size: 16px; margin-bottom: 4px; }
.empty button {
  margin-top: 12px; padding: 7px 14px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--sand); cursor: pointer; font-weight: 500;
}
.skeleton td { color: transparent; }
.skeleton td::after {
  content: ""; display: block; height: 12px; border-radius: 3px; background: #e9f0ef;
}

/* ---------- History drawer ---------- */
.scrim { position: fixed; inset: 0; background: rgba(18, 50, 61, .35); z-index: 10; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 11;
  width: min(480px, 100vw); background: var(--sand);
  display: flex; flex-direction: column; overflow-y: auto;
  box-shadow: -8px 0 24px rgba(18, 50, 61, .18);
  animation: drawer-in .18s ease-out;
}
@keyframes drawer-in { from { transform: translateX(24px); opacity: 0; } }

.drawer-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: 20px 20px 12px; border-bottom: 1px solid var(--line);
}
.drawer-head h2 { margin: 0; font: 700 22px/1.2 var(--font-head); }
.drawer-sub { margin: 2px 0 0; color: var(--muted); }
.icon-btn {
  flex: none; width: 36px; height: 36px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--sand); cursor: pointer;
  display: grid; place-items: center;
}
.icon-btn svg { width: 18px; height: 18px; stroke: var(--laguna); stroke-width: 2; stroke-linecap: round; }

.facts {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 16px;
  margin: 0; padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.facts div { min-width: 0; }
.facts dt { font-size: 12px; color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }

.history { padding: 16px 20px 24px; }
.history h3 { margin: 0 0 10px; font: 700 17px/1.2 var(--font-head); }
.history-filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.history-filters label { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); }
.history-filters input, .history-filters select {
  height: 34px; padding: 0 8px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--sand); color: var(--laguna); font-size: 14px;
}

.moves { list-style: none; margin: 0; padding: 0; }
.move {
  display: grid; grid-template-columns: 56px 1fr auto; gap: 2px 12px;
  padding: 10px 0; border-bottom: 1px solid #e6eeec;
}
.move-change { grid-row: span 2; font: 700 18px/1.3 var(--font-head); text-align: right; }
.move-change.up { color: var(--channel); }
.move-change.down { color: var(--out); }
.move-reason { font-weight: 600; }
.move-after { color: var(--muted); font-size: 13px; text-align: right; }
.move-meta { grid-column: 2 / 4; font-size: 13px; color: var(--muted); }
.move-note { grid-column: 2 / 4; font-size: 13px; }
.moves-empty { color: var(--muted); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 20;
  max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: var(--radius);
  background: var(--laguna); color: #fff; box-shadow: 0 6px 20px rgba(18, 50, 61, .3);
}

/* ---------- Tablet and below (UI-6) ---------- */
@media (max-width: 900px) {
  .page { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .result-count { margin-left: 0; width: 100%; }
  .table-wrap { max-height: none; }
}
@media (max-width: 560px) {
  .topbar-notes { display: none; }
  /* The logo carries the name on phones; screen readers still hear it. */
  .brand-name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .search { max-width: none; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; padding: 6px 4px; }
  .facts { grid-template-columns: repeat(2, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .drawer { animation: none; }
}

/* ---------- Adjust stock (UI-2) ---------- */
.adjust { padding: 16px 20px; border-bottom: 1px solid var(--line); }
.adjust h3 { margin: 0 0 10px; font: 700 17px/1.2 var(--font-head); }
.adjust-mode { display: flex; width: 100%; margin-bottom: 12px; }
.adjust-mode button { flex: 1; padding: 6px 8px; }
.adjust-row { display: grid; grid-template-columns: 120px 1fr; gap: 10px; }
.adjust label { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--muted); }
.adjust .optional { color: #8a9a9d; }
.adjust input, .adjust select {
  height: 38px; padding: 0 10px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--sand); color: var(--laguna); font-size: 15px;
}
.adjust input:focus, .adjust select:focus { border-color: var(--channel); }
.adjust-note { margin-top: 10px; }
.adjust-preview { margin: 10px 0 0; min-height: 20px; font-size: 14px; }
.adjust-preview strong { font: 700 16px/1 var(--font-head); }
.adjust-error { margin: 8px 0 0; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--out-bg); color: var(--out); font-size: 14px; }
.btn-primary {
  margin-top: 12px; height: 40px; padding: 0 18px; border: 0; border-radius: var(--radius);
  background: var(--channel); color: #fff; font-weight: 600; cursor: pointer;
}
.btn-primary:hover { background: #0b5f68; }
.btn-primary:disabled { background: #9db9bb; cursor: default; }

/* Shopify status on a history entry (SYNC-7, SYNC-8) */
.move-sync { grid-column: 2 / 4; justify-self: start; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 10px; }
.move-sync.sent { background: var(--shallows); color: var(--channel); }
.move-sync.waiting { background: #eef2f1; color: var(--muted); }
.move-sync.failed { background: var(--out-bg); color: var(--out); }

/* Header warning + retry when changes didn't reach Shopify */
.sync-note.warn { color: #ffd9a0; }
.sync-retry {
  height: 26px; padding: 0 10px; border: 1px solid #9fc3c1; border-radius: var(--radius-sm);
  background: transparent; color: #e7f1f0; font-size: 13px; cursor: pointer;
}
.sync-retry:hover { background: rgba(255,255,255,.08); }
@media (max-width: 560px) { .adjust-row { grid-template-columns: 1fr; } }

/* ---------- Alert level (admins) ---------- */
.threshold-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.threshold-row label { width: 140px; }

/* ---------- Lure photos (from Shopify) ---------- */
.thumb {
  display: inline-flex; flex: none; align-items: center; justify-content: center; overflow: hidden;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.thumb.no-photo {
  background: var(--flat) center / 55% no-repeat
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239bb3b0' stroke-width='1.6' stroke-linecap='round'%3E%3Crect x='3' y='5' width='18' height='14' rx='2'/%3E%3Ccircle cx='9' cy='10' r='1.6'/%3E%3Cpath d='M21 16l-5-5-8 8'/%3E%3C/svg%3E");
}
.thumb-sm { width: 40px; height: 40px; }
.thumb-md { width: 56px; height: 56px; }
.thumb-lg { width: 120px; height: 120px; border-radius: var(--radius); }
.with-thumb { display: flex; align-items: center; gap: 10px; min-width: 0; }
.with-thumb > span:last-child, .with-thumb > div:last-child { min-width: 0; }
.drawer-id { align-items: flex-start; gap: 14px; }
#drawer-photo:empty { display: none; }

/* ---------- QuickBooks invoices on order details ---------- */
.qi-box { margin: 4px 0 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--flat); }
.qi-title { margin: 0 0 6px; font: 700 15px/1.2 var(--font-head); }
.qi-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 14px; }
.qi-note { font-size: 12px; margin-top: 2px; }
.qi-box .notice { margin: 8px 0 0; }

/* ---------- Left sidebar (every staff page) ---------- */
.app { display: grid; grid-template-columns: 220px minmax(0, 1fr); align-content: start; min-height: calc(100vh - 68px); }
.app > main { min-width: 0; width: 100%; } /* auto margins would size it to its content; wide content scrolls inside instead */

.sidenav {
  display: flex; flex-direction: column; gap: 2px;
  padding: 16px 10px; background: var(--sand); border-right: 1px solid var(--line);
  position: sticky; top: 0; align-self: start; height: calc(100vh - 68px); overflow-y: auto;
}
.sidenav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius);
  color: var(--laguna); text-decoration: none; font-weight: 500;
}
.sidenav-link svg {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.sidenav-link:hover { background: var(--flat); }
.sidenav-link[aria-current="page"] { background: var(--shallows); font-weight: 700; }
.sidenav-link[aria-current="page"] svg { stroke: var(--channel); }

@media (max-width: 900px) {
  /* Sidebar becomes a scrolling strip of page links under the top bar. */
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidenav {
    flex-direction: row; position: static; height: auto; overflow-x: auto;
    padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--line);
  }
  .sidenav-link { flex: none; padding: 7px 10px; }
  .has-sidenav .tabs { overflow-x: auto; }
}
