:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5d6b7d;
  --faint: #b3bcc7;
  --border: #dde2e8;
  /* Barkman logo blue is #5E8AB4; the accent is a darker shade for text contrast. */
  --accent: #3f6e9c;
  --on-accent: #ffffff;
  --header-bg: #ffffff;
  --header-text: #1c2430;
  --row-alt: #f9fafb;
  --row-hover: #eef4fb;
  --note-bg: #fff8e1;
  --note-border: #f0dca0;
  --note-bar: #e0a800;
  --note-text: #7a4f00;
  --note-muted: #8a6418;
  --note-badge: #f2b705;
  --note-badge-icon: #4a3000;
  --note-card: #fffdf3;
  --error: #b42318;
  --radius: 8px;
  color-scheme: light;
}

/* Dark tokens apply when the device prefers dark (unless the user picked
   Light) or when the user picked Dark. Keep the two blocks identical. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161c;
    --surface: #1a2029;
    --text: #e6eaf0;
    --muted: #9aa6b5;
    --faint: #4a5566;
    --border: #2c3542;
    --accent: #8db3d9;
    --on-accent: #0b1a2b;
    --header-bg: #0b0e12;
    --header-text: #e6eaf0;
    --row-alt: #1d242e;
    --row-hover: #233041;
    --note-bg: #2a2413;
    --note-border: #4a3d1c;
    --note-bar: #e0b030;
    --note-text: #f5d47a;
    --note-muted: #d8c493;
    --note-badge: #e8b52e;
    --note-badge-icon: #2a2413;
    --note-card: #332c18;
    --error: #f2877d;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #12161c;
  --surface: #1a2029;
  --text: #e6eaf0;
  --muted: #9aa6b5;
  --faint: #4a5566;
  --border: #2c3542;
  --accent: #8db3d9;
  --on-accent: #0b1a2b;
  --header-bg: #0b0e12;
  --header-text: #e6eaf0;
  --row-alt: #1d242e;
  --row-hover: #233041;
  --note-bg: #2a2413;
  --note-border: #4a3d1c;
  --note-bar: #e0b030;
  --note-text: #f5d47a;
  --note-muted: #d8c493;
  --note-badge: #e8b52e;
  --note-badge-icon: #2a2413;
  --note-card: #332c18;
  --error: #f2877d;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
}

.topbar {
  background: var(--header-bg);
  color: var(--header-text);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 16px;
  padding-top: 12px;
  padding-bottom: 12px;
}

.logo {
  display: block;
  width: 150px;
  height: auto;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.topbar-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.asof {
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

.theme-toggle:hover { color: var(--text); }.theme-toggle svg { width: 16px; height: 16px; }
.theme-toggle svg[hidden] { display: none; }
.theme-toggle[hidden] { display: none; }
a.theme-toggle { text-decoration: none; }

/* Sign-in */

.login {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 360px;
  margin: 48px auto;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.login[hidden] { display: none; }
.login h2 { margin: 0; font-size: 1.25rem; }
.login-hint { margin: 0 0 10px; color: var(--muted); font-size: 0.875rem; }
.login label { font-size: 0.85rem; font-weight: 600; }

.login input {
  height: 40px;
  margin-bottom: 8px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.login-error { margin: 0 0 8px; color: var(--error); font-size: 0.875rem; }

.login button {
  height: 40px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: var(--surface);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.login button:disabled { opacity: 0.6; cursor: wait; }

@media (max-width: 400px) {
  .logo { width: 120px; }
}

main.wrap { padding-top: 6px; padding-bottom: 32px; }

/* Search + locations stay pinned while scrolling. Negative margins extend
   the background across the page gutter so rows don't show beside it. */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 3;
  margin: 0 -16px;
  padding: 10px 16px;
  background: var(--bg);
}

.toolbar.stuck {
  border-bottom: 1px solid var(--border);
  box-shadow: 0 6px 12px -10px rgba(0, 0, 0, 0.35);
}

.to-top {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 4;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  cursor: pointer;
  opacity: 0;
  visibility: hidden; /* also removes it from the tab order */
  transform: translateY(8px);
  transition: opacity 0.15s, transform 0.15s, visibility 0.15s;
}

.to-top.visible {
  opacity: 1;
  visibility: visible;
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  .to-top { transition: none; }
}

/* Availability note: always shown, in gold so it stands apart from the blue UI.
   The lead lines (the disclaimers, each with an info icon) stay visible; the
   points below them collapse. It opens on every load (no remembered state). */
.notice {
  margin-bottom: 12px;
  background: var(--note-bg);
  border: 1px solid var(--note-border);
  border-left: 4px solid var(--note-bar);
  border-radius: var(--radius);
  color: var(--note-text);
  font-size: 0.875rem;
}

.notice[hidden] { display: none; }

/* Grid: icon | text | chevron. The chevron sits on the first line only;
   later lines leave its column empty. */
.notice-lead {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: 6px 8px;
  padding: 12px 16px;
  font-weight: 600;
  list-style: none;
  cursor: pointer;
}

.notice-lead::-webkit-details-marker { display: none; }
.notice-lead > svg:not(.notice-chevron) { grid-column: 1; }
.notice-lead > span { grid-column: 2; }
.notice-chevron { grid-column: 3; grid-row: 1; }

.notice svg {
  flex: none;
  width: 16px;
  height: 16px;
  margin-top: 2px;
}

.notice-chevron { transition: transform 0.15s; }
.notice[open] .notice-chevron { transform: rotate(180deg); }

/* Three cards side by side; one column on phones. */
.notice-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
  padding: 0 16px 14px;
  color: var(--note-muted);
  list-style: none;
}

.notice-cards li {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 12px 14px;
  background: var(--note-card);
  border: 1px solid var(--note-border);
  border-radius: var(--radius);
}

/* Gold icon badges; they pop slightly when the row is hovered. */
.notice-badge {
  display: grid;
  flex: none;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--note-badge);
  color: var(--note-badge-icon);
  box-shadow: 0 2px 6px -2px rgba(122, 79, 0, 0.45);
  transition: transform 0.15s;
}

.notice .notice-badge svg { margin: 0; }
.notice-cards li:hover .notice-badge { transform: scale(1.1) rotate(-6deg); }

/* Phones: stacked cards, badge beside the text to keep them short. */
@media (max-width: 760px) {
  .notice-cards { grid-template-columns: 1fr; gap: 8px; }
  .notice-cards li { flex-direction: row; gap: 10px; padding: 10px 12px; }
  .notice-cards li > span:last-child { padding-top: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  .notice-chevron,
  .notice-badge { transition: none; }
}

/* Controls */

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
}

.controls select {
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

/* Search: looks like one input holding the term chips, the text box and the
   "/" shortcut badge. The menu (recent searches + tip) drops below it. */
.search-box {
  position: relative;
  display: flex;
  flex: 1 1 260px;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
  min-width: 0;
  min-height: 38px;
  padding: 3px 8px 3px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: text;
}

.search-box:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.search-icon { flex: none; width: 16px; height: 16px; color: var(--muted); }

.search-terms {
  display: contents;
  margin: 0;
  padding: 0;
  list-style: none;
}

.term {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 2px;
  max-width: 100%;
  height: 26px;
  padding: 0 2px 0 10px;
  border-radius: 999px;
  background: var(--row-hover);
  color: var(--text);
  font-size: 0.85rem;
  white-space: nowrap;
}

.term-text { overflow: hidden; text-overflow: ellipsis; }

.term button {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.term button:hover { background: var(--border); color: var(--text); }

.search-box input[type="search"] {
  flex: 1 1 120px;
  min-width: 80px;
  height: 30px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
}

.search-box input[type="search"]:focus-visible { outline: none; } /* the box shows focus */

.search-kbd {
  flex: none;
  display: grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: var(--muted);
  font: 600 0.75rem/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Only useful with a keyboard; hidden once the box is in use. */
.search-box:focus-within .search-kbd,
.search-kbd[hidden] { display: none; }
@media (hover: none) { .search-kbd { display: none; } }

.search-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 5;
  width: 100%;
  min-width: min(320px, calc(100vw - 32px));
  padding: 6px 0 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 10px 24px -8px rgba(0, 0, 0, 0.3);
  cursor: default;
}

.search-menu[hidden],
#search-recent[hidden] { display: none; }

.search-menu-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 12px 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.search-menu-clear {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  letter-spacing: 0;
  text-transform: none;
  cursor: pointer;
}

#search-recent-list { margin: 0; padding: 0; list-style: none; }

.search-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
}

.search-option svg { flex: none; width: 14px; height: 14px; color: var(--muted); }
.search-option:hover,
.search-option[aria-selected="true"] { background: var(--row-hover); }

.search-tip {
  margin: 6px 0 0;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.8rem;
}

#search-recent[hidden] + .search-tip { margin-top: -6px; border-top: 0; } /* no recent searches above it */
.search-tip strong { color: var(--text); }
.search-tip kbd {
  padding: 0 4px;
  border: 1px solid var(--border);
  border-radius: 3px;
  font: 600 0.75rem ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* "Did you mean …?" on the no-results row. */
.suggest { margin-top: 10px; color: var(--text); }
.suggest button {
  margin-left: 6px;
  padding: 4px 12px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
}
.filters { display: contents; }
.controls select { flex: 0 1 200px; min-width: 0; }

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  font-size: 0.9rem;
  white-space: nowrap;
  cursor: pointer;
}

.toggle input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

input:focus-visible,
select:focus-visible,
button:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.reset {
  height: 38px;
  padding: 0 4px;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
}

/* Class, then Locations, on one row. */
.chip-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin-top: 10px;
}

.chip-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
}

.chip-group + .chip-group:not([hidden]) {
  padding-left: 16px;
  border-left: 1px solid var(--border);
}

.chip-bar[hidden],
.chip-group[hidden] { display: none; }

.chip-group-label {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
}

.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.count {
  margin: 12px 0 8px;
  color: var(--muted);
  font-size: 0.875rem;
}

.status {
  padding: 32px 0;
  color: var(--muted);
  text-align: center;
}

.status.error { color: var(--error); }

/* Table */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: clip; /* rounds corners without breaking the sticky header */
}

.table-wrap:has(> table[hidden]) { display: none; }

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 9px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  position: sticky;
  top: var(--toolbar-h, 0px); /* sits just below the pinned toolbar; set by app.js */
  background: var(--surface);
  z-index: 1;
  white-space: nowrap;
}

th button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  cursor: pointer;
}

th.num button { text-align: right; }
th[aria-sort="ascending"] button::after { content: " ▲"; }
th[aria-sort="descending"] button::after { content: " ▼"; }
th[aria-sort="ascending"] button,
th[aria-sort="descending"] button { color: var(--text); }

.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.role-title { font-weight: 600; white-space: nowrap; }
.divider { border-left: 1px solid var(--border); }

td.zero { color: var(--faint); }
td.code { color: var(--muted); font-size: 0.8rem; font-style: italic; }
td.neg { color: var(--error); }

/* Transfer column: pallets at the transfer site, with the site under it. */
td.transfer .value.zero { color: var(--faint); }

.transfer-site {
  display: block;
  margin-top: 1px;
  color: var(--muted);
  font-size: 0.75rem;
}

tbody tr:nth-child(even) { background: var(--row-alt); }
tbody tr:hover { background: var(--row-hover); }
tbody tr:last-child td { border-bottom: 0; }

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

/* Tablets: let the table scroll sideways instead of squeezing. */
@media (max-width: 960px) and (min-width: 641px) {
  .table-wrap { overflow-x: auto; }
}

/* Phones: each part becomes a card with a row of in-stock locations. */
@media (max-width: 640px) {
  /* Keep the pinned toolbar short: search + toggle on one row. Chips wrap
     (each group on its own row) so every option is visible, never cut off;
     they're a little smaller here to save height. */
  .search-box { flex-basis: 140px; }

  .chip-bar { flex-direction: column; align-items: stretch; gap: 6px; margin-top: 8px; }
  .chip-group + .chip-group:not([hidden]) { padding-left: 0; border-left: 0; }
  .chip-group { gap: 4px 8px; }
  .chip { height: 30px; padding: 0 10px; }

  .table-wrap { background: none; border: 0; overflow: visible; }
  thead { display: none; }
  table, tbody { display: block; }

  tbody tr,
  tbody tr:nth-child(even),
  tbody tr:hover {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
    padding: 10px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
  }

  td {
    flex-basis: 100%;
    padding: 0;
    border: 0;
  }

  td.role-title { font-size: 1rem; }
  td.role-subtitle { color: var(--muted); margin-bottom: 4px; }
  td.role-unit { display: none; }

  td.qty {
    flex-basis: auto;
    display: grid;
    grid-template-columns: auto auto;
    justify-content: start;
    align-items: baseline;
    column-gap: 4px;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    text-align: left;
  }

  td.qty::before {
    content: attr(data-label);
    grid-column: 1 / -1;
    color: var(--muted);
    font-size: 0.72rem;
  }

  td.qty[data-unit]::after {
    content: attr(data-unit);
    color: var(--muted);
    font-size: 0.75rem;
  }

  td.qty.zero { display: none; }

  /* Transfer pill: dashed, so it reads apart from on-hand stock.
     Order: label, value, unit, then the site on its own line. */
  td.qty.transfer:not(.zero) { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 4px; border-style: dashed; }
  td.qty.transfer::before { flex-basis: 100%; }
  td.qty.transfer::after { order: 1; }
  td.qty.transfer .transfer-site { order: 2; flex-basis: 100%; margin: 0; }

  tbody tr[data-empty]::after {
    content: "No stock on hand";
    color: var(--muted);
    font-size: 0.85rem;
  }

  td.empty {
    padding: 24px 0;
    text-align: center;
  }
}
