/* ---------- tokens ---------- */
:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --surface-2: #f0efeb;
  --ink: #1b1b1f;
  --muted: #6f6f78;
  --faint: #a3a3ad;
  --line: #e3e2dd;
  --line-strong: #d2d1cb;
  --accent: #e5484d;          /* balloon coral */
  --accent-ink: #ffffff;
  --accent-soft: #fdecec;
  --amber: #b45309;
  --amber-bg: #fef3c7;
  --green: #15803d;
  --green-bg: #dcfce7;
  --focus: #2563eb;
  --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 4px 14px rgb(0 0 0 / .06);
  --shadow-lg: 0 8px 40px rgb(0 0 0 / .22);
  --img-bg: #ffffff;          /* photos are white-background JPEGs — keep white in both themes */
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131316;
    --surface: #1d1d21;
    --surface-2: #26262b;
    --ink: #ececf0;
    --muted: #9c9ca6;
    --faint: #6b6b74;
    --line: #2c2c32;
    --line-strong: #3a3a41;
    --accent: #f2555a;
    --accent-soft: #3a2224;
    --amber: #fbbf24;
    --amber-bg: #3a2f14;
    --green: #4ade80;
    --green-bg: #14331e;
    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 4px 14px rgb(0 0 0 / .35);
    --shadow-lg: 0 8px 40px rgb(0 0 0 / .6);
  }
}

* { box-sizing: border-box; margin: 0; }
html { scrollbar-gutter: stable; overflow-anchor: none; /* placeholder swaps during image loads were re-anchoring scroll */ }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }
kbd {
  font: 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--surface-2); border: 1px solid var(--line-strong);
  border-bottom-width: 2px; border-radius: 4px; padding: 2px 5px;
}

/* ---------- header ---------- */
#topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  padding: 10px 18px 0;
}
.bar-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
#topbar h1 { font-size: 15px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }
.searchwrap { flex: 0 1 280px; min-width: 180px; }
#q {
  width: 100%; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: 8px;
  padding: 7px 11px; font-size: 13px; outline: none;
}
#q:focus { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 18%, transparent); }
#sort {
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: 8px;
  padding: 7px 8px; font-size: 13px; outline: none;
}
.count { color: var(--muted); font-size: 12.5px; margin-left: auto; white-space: nowrap; font-variant-numeric: tabular-nums; }

.picks-btn {
  display: flex; align-items: center; gap: 7px;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 8px; padding: 7px 12px; font-size: 13px; font-weight: 600;
  box-shadow: 0 1px 2px rgb(0 0 0 / .04);
}
.picks-btn:hover { border-color: var(--accent); }
.picks-btn .badge {
  background: var(--accent); color: var(--accent-ink);
  border-radius: 99px; font-size: 11.5px; font-weight: 700;
  min-width: 20px; padding: 1.5px 6px; text-align: center;
  font-variant-numeric: tabular-nums;
}
.picks-btn .badge[data-zero] { background: var(--surface-2); color: var(--muted); }

/* ---------- filter bar ---------- */
.filterbar { padding: 8px 0 10px; gap: 8px; row-gap: 7px; font-size: 12.5px; }
.f-sep { width: 1px; align-self: stretch; background: var(--line-strong); flex: none; margin: 3px 2px; }

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

/* supplier / picked pill checkboxes */
.pill-check {
  position: relative;
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line-strong); background: var(--surface);
  border-radius: 99px; padding: 4px 11px 4px 9px; cursor: pointer;
  color: var(--muted); user-select: none; white-space: nowrap;
  transition: border-color .12s, color .12s, background .12s;
}
.pill-check:hover { border-color: var(--faint); color: var(--ink); }
.pill-check input { position: absolute; opacity: 0; pointer-events: none; }
.pill-check .dot { width: 8px; height: 8px; border-radius: 99px; background: var(--sc, var(--faint)); flex: none; opacity: .35; }
.pill-check .n { opacity: .6; font-size: 11px; font-variant-numeric: tabular-nums; }
.pill-check:has(input:checked) { color: var(--ink); border-color: color-mix(in srgb, var(--sc, var(--ink)) 55%, var(--line-strong)); background: color-mix(in srgb, var(--sc, var(--ink)) 7%, var(--surface)); }
.pill-check:has(input:checked) .dot { opacity: 1; }
.pill-check:has(input:focus-visible) { box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
.picked-pill:has(input:checked) { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* dropdown facets */
.dd { position: relative; }
.f-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line-strong); background: var(--surface);
  border-radius: 8px; padding: 4.5px 10px; color: var(--muted); white-space: nowrap;
}
.f-btn:hover { border-color: var(--faint); color: var(--ink); }
.f-btn .caret { font-size: 10px; opacity: .6; }
.f-btn .f-n {
  background: var(--ink); color: var(--bg); border-radius: 99px;
  font-size: 10.5px; font-weight: 700; min-width: 17px; padding: 1px 5px; text-align: center;
}
.dd.active .f-btn { color: var(--ink); border-color: var(--ink); }
.dd.open .f-btn { border-color: var(--focus); color: var(--ink); }
.dd-pop {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30;
  min-width: 250px; max-width: 330px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; overflow: hidden;
}
.dd-pop[hidden] { display: none; }
.dd-search {
  margin: 8px 8px 4px; padding: 6px 9px; font-size: 12.5px;
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 7px; outline: none;
}
.dd-search:focus { border-color: var(--focus); }
.dd-list { max-height: 290px; overflow-y: auto; padding: 5px 4px; }
.dd-item {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 8px; border-radius: 6px; cursor: pointer; user-select: none;
}
.dd-item:hover { background: var(--surface-2); }
.dd-item input { accent-color: var(--accent); margin: 0; flex: none; }
.dd-item .lbl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dd-item .cnt { color: var(--faint); font-size: 11px; font-variant-numeric: tabular-nums; }
.dd-item.zero { opacity: .45; }
.dd-empty { padding: 12px; color: var(--faint); text-align: center; }
.dd-foot { border-top: 1px solid var(--line); padding: 6px 10px; }
.linklike { border: none; background: none; color: var(--muted); font-size: 12px; padding: 2px 0; }
.linklike:hover { color: var(--accent); }

/* pages */
.pages-filter {
  display: flex; align-items: center; gap: 5px;
  color: var(--muted); white-space: nowrap;
}
.pages-filter input {
  width: 48px; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: 7px;
  padding: 4.5px 5px; font-size: 12.5px; text-align: center; outline: none;
  -moz-appearance: textfield; appearance: textfield;
}
.pages-filter input::-webkit-outer-spin-button,
.pages-filter input::-webkit-inner-spin-button { -webkit-appearance: none; }
.pages-filter input:focus { border-color: var(--focus); }
.pages-filter .dash { color: var(--faint); }

/* validation segmented control */
.seg {
  display: inline-flex; border: 1px solid var(--line-strong);
  border-radius: 8px; overflow: hidden; background: var(--surface);
}
.seg button {
  border: none; background: none; padding: 5px 10px; color: var(--muted);
  font-size: 12px; white-space: nowrap;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); font-weight: 600; }

.f-clear {
  border: none; background: none; color: var(--accent);
  font-size: 12px; font-weight: 600; padding: 4px 6px; border-radius: 6px;
  margin-left: auto;
}
.f-clear:hover { background: var(--accent-soft); }

/* ---------- grid ---------- */
main { padding: 16px 18px 60px; }
#grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
}
.page-divider {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: 10px;
  color: var(--faint); font-size: 11.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em;
  margin: 10px 0 -2px;
}
.page-divider .sdot { width: 7px; height: 7px; border-radius: 99px; background: var(--sc, var(--faint)); flex: none; }
.page-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.page-divider:first-child { margin-top: 0; }

.card {
  position: relative;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; overflow: hidden;
  display: flex; flex-direction: column;
  transition: box-shadow .15s, border-color .15s;
  outline: none;
}
.card:hover { box-shadow: var(--shadow); border-color: var(--line-strong); }
.card:focus-visible { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
.card.picked { border-color: var(--accent); box-shadow: 0 0 0 1.5px var(--accent); }

.thumb {
  aspect-ratio: 6 / 7; background: var(--img-bg);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; cursor: zoom-in;
}
.thumb img {
  width: 100%; height: 100%; object-fit: contain; display: block;
  transition: transform .18s ease;
}
.card:hover .thumb img { transform: scale(1.035); }
.noimg {
  width: 100%; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  color: #b9b9c0; font-size: 11px; background: var(--surface-2);
}
.noimg .b { font-size: 26px; filter: grayscale(1); opacity: .45; }

.meta {
  padding: 7px 9px 8px;
  display: flex; align-items: center; justify-content: space-between; gap: 7px;
  border-top: 1px solid var(--line);
}
.meta .left { display: flex; align-items: center; gap: 6px; min-width: 0; }
.sbadge {
  flex: none; font-size: 9px; font-weight: 800; letter-spacing: .04em;
  color: var(--sc); background: color-mix(in srgb, var(--sc) 13%, var(--surface));
  border-radius: 4px; padding: 2px 4px; line-height: 1;
}
.meta .sku {
  font-size: 12px; font-weight: 600; letter-spacing: -.01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.meta .size { color: var(--muted); font-size: 11.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* pick control on card */
.pick {
  position: absolute; top: 8px; right: 8px; z-index: 2;
  width: 28px; height: 28px; border-radius: 99px;
  border: 1.5px solid var(--line-strong);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  color: var(--muted); font-size: 14px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity .12s, background .12s, transform .1s;
  backdrop-filter: blur(3px);
}
.card:hover .pick, .card:focus-visible .pick, .card:focus-within .pick { opacity: 1; }
.pick:hover { transform: scale(1.1); border-color: var(--accent); color: var(--accent); }
.card.picked .pick {
  opacity: 1; background: var(--accent); border-color: var(--accent); color: var(--accent-ink);
}
@media (hover: none) { .pick { opacity: .85; } }

/* status / skeleton */
.status { text-align: center; color: var(--muted); padding: 28px 0; font-size: 13px; }
.status .btn { margin-top: 10px; }
#sentinel { height: 1px; }
.skel {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  aspect-ratio: 6 / 8.1; position: relative; overflow: hidden;
}
.skel::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 30%, color-mix(in srgb, var(--ink) 4%, transparent) 50%, transparent 70%);
  animation: shimmer 1.3s infinite;
}
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

.empty {
  grid-column: 1 / -1; text-align: center; padding: 70px 0; color: var(--muted);
}
.empty .big { font-size: 34px; margin-bottom: 10px; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--line-strong); background: var(--surface);
  border-radius: 8px; padding: 8px 14px; font-size: 13px; font-weight: 600;
  transition: background .12s, border-color .12s;
}
.btn:hover { border-color: var(--faint); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--accent); border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: default; }
.icon-btn {
  border: none; background: transparent; color: var(--muted);
  width: 30px; height: 30px; border-radius: 7px; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

/* ---------- drawer ---------- */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 40;
  width: min(360px, 92vw);
  background: var(--surface); border-left: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .22s ease;
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.drawer-head h2 { font-size: 15px; }
.drawer-head h2 span { color: var(--muted); font-weight: 500; font-size: 13px; }
.drawer-list { flex: 1; overflow-y: auto; padding: 6px 0; }
.drawer-group {
  display: flex; align-items: center; gap: 6px;
  padding: 9px 16px 3px; color: var(--faint);
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
}
.drawer-group .sdot { width: 7px; height: 7px; border-radius: 99px; background: var(--sc, var(--faint)); }
.pick-row {
  display: flex; align-items: center; gap: 11px;
  padding: 7px 16px;
}
.pick-row:hover { background: var(--surface-2); }
.pick-row .pr-thumb {
  width: 44px; height: 50px; flex: none; border-radius: 6px;
  background: var(--img-bg); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  cursor: zoom-in;
}
.pick-row .pr-thumb img { width: 100%; height: 100%; object-fit: contain; }
.pick-row .pr-meta { flex: 1; min-width: 0; }
.pick-row .pr-sku { font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-row .pr-sub { font-size: 11.5px; color: var(--muted); }
.pick-row .pr-x { flex: none; }
.drawer-empty { flex: 1; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: var(--muted); padding: 0 30px; text-align: center; }
.drawer-empty .hint { font-size: 12px; color: var(--faint); }
.drawer.is-empty .drawer-list { display: none; }
.drawer.is-empty .drawer-empty { display: flex; }
.drawer-foot {
  display: flex; gap: 9px; padding: 13px 16px;
  border-top: 1px solid var(--line);
}
.drawer-foot .primary { flex: 1; }

/* ---------- lightbox / detail ---------- */
.lightbox { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; gap: 6px; }
.lightbox[hidden] { display: none; }
.lb-backdrop { position: absolute; inset: 0; background: rgb(0 0 0 / .55); backdrop-filter: blur(2px); }
.lb-card {
  position: relative; z-index: 1;
  display: flex; background: var(--surface);
  border-radius: 14px; overflow: hidden; box-shadow: var(--shadow-lg);
  max-width: min(940px, calc(100vw - 120px)); max-height: min(680px, 90vh);
}
.lb-imgwrap {
  background: var(--img-bg); flex: 1.3; min-width: 0;
  display: flex; align-items: center; justify-content: center;
}
.lb-imgwrap img { max-width: 100%; max-height: min(680px, 90vh); object-fit: contain; display: block; }
.lb-imgwrap .noimg { aspect-ratio: 6/7; width: 100%; }
.lb-meta {
  flex: 1; min-width: 270px; max-width: 340px;
  padding: 20px 20px 16px; display: flex; flex-direction: column; gap: 8px;
  border-left: 1px solid var(--line); overflow-y: auto;
}
.lb-badges { display: flex; gap: 6px; flex-wrap: wrap; }
.lb-badge {
  font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  border-radius: 5px; padding: 3px 7px; line-height: 1;
}
.lb-badge.supplier { color: var(--sc); background: color-mix(in srgb, var(--sc) 13%, var(--surface)); }
.lb-badge.ok { color: var(--green); background: var(--green-bg); }
.lb-badge.warn { color: var(--amber); background: var(--amber-bg); }
.lb-badge.info { color: var(--muted); background: var(--surface-2); }
.lb-sku { font-size: 16.5px; font-weight: 700; letter-spacing: -.01em; line-height: 1.25; }
.lb-rawname { font-size: 13px; color: var(--muted); }
.lb-rawname:empty { display: none; }
.lb-fields {
  display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px;
  font-size: 12px; margin: 6px 0 2px;
}
.lb-fields dt { color: var(--faint); white-space: nowrap; }
.lb-fields dd { color: var(--ink); min-width: 0; overflow-wrap: anywhere; }
.lb-fields dd .sub { color: var(--faint); }
.lb-fields dd.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }
.lb-fields .syn-flag { color: var(--amber); font-weight: 600; }
.lb-raw { font-size: 12px; }
.lb-raw summary { color: var(--muted); cursor: pointer; user-select: none; padding: 2px 0; }
.lb-raw summary:hover { color: var(--ink); }
.lb-raw pre {
  margin-top: 6px; padding: 9px 10px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 10.5px; line-height: 1.5; overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.lb-meta .pick-toggle { margin-top: 8px; align-self: flex-start; padding: 9px 18px; }
.lb-meta .pick-toggle.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.lb-hint { margin-top: 8px; font-size: 11px; color: var(--faint); }
.lb-close { position: absolute; top: 10px; right: 10px; background: var(--surface); }
.lb-nav {
  position: relative; z-index: 1; border: none; background: transparent;
  color: #fff; font-size: 44px; line-height: 1; padding: 20px 14px;
  opacity: .7; transition: opacity .12s; user-select: none;
}
.lb-nav:hover { opacity: 1; }
.lb-nav:disabled { opacity: .15; cursor: default; }
@media (max-width: 700px) {
  .lb-card { flex-direction: column; max-width: calc(100vw - 70px); overflow-y: auto; }
  .lb-imgwrap img { max-height: 42vh; }
  .lb-meta { max-width: none; border-left: none; border-top: 1px solid var(--line); padding: 16px 18px; }
}

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  z-index: 60; background: var(--ink); color: var(--bg);
  padding: 10px 18px; border-radius: 99px; font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow-lg);
  animation: toast-in .18s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }
