:root {
  --bg: #f4f6f9; --card: #fff; --ink: #1b2430; --muted: #5f6b7a; --line: #dde3ea;
  --brand: #1f3a5f; --accent: #f2b134; --ok: #1e7b4a; --warn: #a15c00; --bad: #b42318; --new: #175cd3;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
a { color: var(--new); }
h1 { font-size: 1.35rem; margin: .2rem 0 .8rem; }
h2 { font-size: 1.1rem; margin: 1.2rem 0 .5rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .center { text-align: center; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
main { max-width: 1100px; margin: 0 auto; padding: 12px; }
[hidden] { display: none !important; }

.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; background: var(--brand); color: #fff; padding: 10px 16px; }
.brand { color: #fff; font-weight: 700; text-decoration: none; font-size: 1.1rem; white-space: nowrap; }
.nav { display: none; gap: 4px; margin-left: auto; }
.nav a { color: #dbe6f3; text-decoration: none; padding: 6px 10px; border-radius: 6px; }
.nav a.active, .nav a:hover { background: rgba(255,255,255,.15); color: #fff; }
.pill { display: inline-block; min-width: 1.4em; padding: 0 .4em; border-radius: 99px; background: var(--accent); color: #1b2430; font-size: .75rem; font-weight: 700; text-align: center; }
.bottomnav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr); background: #fff; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.bottomnav a { display: flex; flex-direction: column; align-items: center; padding: 6px 0 8px; color: var(--muted); text-decoration: none; font-size: .72rem; position: relative; }
.bottomnav a span { font-size: 1.25rem; line-height: 1.3; }
.bottomnav a.active { color: var(--brand); font-weight: 700; }
.bottomnav .pill { position: absolute; top: 2px; left: 56%; }
@media (min-width: 800px) {
  .nav { display: flex; } .bottomnav { display: none !important; } body { padding-bottom: 0; } main { padding: 20px; }
}

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1 1 auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (max-width: 520px) { .grid2.stack { grid-template-columns: 1fr; } .grid4 { grid-template-columns: 1fr 1fr; } }

label { display: block; font-size: .85rem; font-weight: 600; color: #344054; margin-bottom: 8px; }
label > input, label > select, label > textarea { margin-top: 4px; }
input, select, textarea, button { font: inherit; }
input[type=text], input[type=number], input[type=password], input[type=search], input[type=tel], input:not([type]), select, textarea {
  width: 100%; padding: 10px 11px; border: 1px solid #c8d0da; border-radius: 8px; background: #fff; color: var(--ink); min-height: 44px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9ec5fe; border-color: #5b9bd5; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { width: 20px; height: 20px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 14px; border-radius: 8px; border: 1px solid #c8d0da; background: #fff; color: var(--ink); text-decoration: none; cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn:hover { background: #f2f4f7; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #18304f; }
.btn.accent { background: var(--accent); border-color: #d99a1f; color: #1b2430; }
.btn.danger { color: var(--bad); border-color: #f1b5ae; }
.btn.small { min-height: 34px; padding: 4px 10px; font-size: .88rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btnbar { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: .75rem; font-weight: 700; border: 1px solid; }
.badge.New { color: var(--new); border-color: #b2ccff; background: #eff4ff; }
.badge.Used { color: #5c4400; border-color: #f4d58d; background: #fff8e6; }
.badge.sample { color: #6b21a8; border-color: #d8b4fe; background: #faf5ff; }
.badge.pending { color: var(--warn); border-color: #fbd38d; background: #fffaeb; }
.badge.sold { color: var(--ok); border-color: #a6e2c0; background: #ecfdf3; }
.badge.cancelled { color: var(--muted); border-color: var(--line); background: #f2f4f7; }
.badge.out { color: var(--bad); border-color: #f1b5ae; background: #fef3f2; }
.badge.ebay { color: #0b5394; border-color: #9fc5e8; background: #eef6fd; }

.loc { display: inline-flex; align-items: center; gap: 6px; background: #102a43; color: #fff; font-weight: 700; padding: 4px 10px; border-radius: 6px; font-size: .92rem; }
.loc::before { content: "📍"; }
.loc.none { background: #98a2b3; }

.searchbar { position: sticky; top: 0; z-index: 10; background: var(--bg); padding: 4px 0 8px; }
@media (min-width: 800px) { .searchbar { top: 52px; } }
.searchbar input[type=search] { font-size: 1.05rem; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin-top: 8px; }
.filters select, .filters input { min-height: 40px; padding: 7px 9px; }

.results { display: grid; gap: 10px; }
@media (min-width: 800px) { .results { grid-template-columns: 1fr 1fr; } }
.part { display: grid; grid-template-columns: 84px 1fr; gap: 12px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; box-shadow: var(--shadow); position: relative; }
.part .thumb { width: 84px; height: 84px; border-radius: 8px; object-fit: cover; background: #e9edf2; display: flex; align-items: center; justify-content: center; color: #98a2b3; font-size: 1.8rem; }
.part h3 { margin: 0 0 2px; font-size: 1rem; }
.part h3 a { color: inherit; text-decoration: none; }
.part .meta { font-size: .84rem; color: var(--muted); margin: 2px 0; }
.part .price { font-weight: 800; font-size: 1.05rem; }
.part .bottom { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.part .sel { position: absolute; top: 8px; right: 8px; width: 22px; height: 22px; }

.gallery { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; }
.gallery img { height: 220px; max-width: 90%; border-radius: 8px; scroll-snap-align: start; object-fit: cover; background: #e9edf2; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; }
.kv dt { color: var(--muted); font-size: .88rem; } .kv dd { margin: 0; font-weight: 500; }
.photos-edit { display: flex; gap: 8px; flex-wrap: wrap; }
.photos-edit figure { margin: 0; position: relative; }
.photos-edit img { width: 92px; height: 92px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.photos-edit button { position: absolute; top: 2px; right: 2px; border: 0; background: rgba(0,0,0,.65); color: #fff; border-radius: 50%; width: 26px; height: 26px; cursor: pointer; }
.fitrow { display: grid; grid-template-columns: 76px 76px 1fr 1fr 40px; gap: 6px; margin-bottom: 6px; }
@media (max-width: 520px) { .fitrow { grid-template-columns: 1fr 1fr 40px; } .fitrow .mk, .fitrow .md { grid-column: span 1; } }
.fitrow button { min-height: 44px; }
details > summary { cursor: pointer; font-weight: 700; padding: 6px 0; }
.counter { font-size: .8rem; color: var(--muted); text-align: right; }
.counter.over { color: var(--bad); font-weight: 700; }

table.list { width: 100%; border-collapse: collapse; background: #fff; }
table.list th, table.list td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.tablewrap { overflow-x: auto; }
.warn { background: #fffaeb; border: 1px solid #fbd38d; color: #7a4a00; border-radius: 8px; padding: 8px 12px; margin: 8px 0; }
.warn ul { margin: 4px 0 0 18px; padding: 0; }
.error { background: #fef3f2; border: 1px solid #f1b5ae; color: var(--bad); border-radius: 8px; padding: 8px 12px; margin: 8px 0; }
.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: #1b2430; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 100; box-shadow: var(--shadow); max-width: 90vw; }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 200; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: #fff; padding: 16px; }
.overlay video { width: 100%; max-width: 520px; border-radius: 10px; }
.login { max-width: 380px; margin: 8vh auto; }
.sample-note { background: #faf5ff; border: 1px solid #d8b4fe; color: #6b21a8; padding: 8px 12px; border-radius: 8px; margin-bottom: 10px; font-size: .9rem; }
iframe.desc { width: 100%; min-height: 260px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }

/* ---------- printable pages ---------- */
.printpage { background: #fff; color: #000; max-width: 8.5in; margin: 0 auto; padding: .4in; font-size: 11pt; }
.ticket h1 { font-size: 18pt; margin: 0; }
.ticket .head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid #000; padding-bottom: 8px; margin-bottom: 10px; }
.ticket .head .right { text-align: right; }
.ticket .ordno { font-size: 16pt; font-weight: 800; }
.ticket table { width: 100%; border-collapse: collapse; }
.ticket th, .ticket td { border-bottom: 1px solid #999; padding: 6px 4px; text-align: left; vertical-align: middle; font-size: 10pt; }
.ticket th { border-bottom: 2px solid #000; font-size: 8.5pt; text-transform: uppercase; }
.ticket td.locc { font-weight: 800; font-size: 10.5pt; white-space: nowrap; }
.ticket td.num, .ticket th.num { text-align: right; white-space: nowrap; }
.ticket td.qr svg { width: 46px; height: 46px; display: block; }
.ticket .pick { width: 18px; height: 18px; border: 1.5px solid #000; display: inline-block; }
.ticket .totals { margin-top: 10px; display: flex; justify-content: flex-end; }
.ticket .totals table { width: auto; } .ticket .totals td { border: 0; font-size: 12pt; padding: 3px 8px; }
.ticket .sub { font-weight: 800; font-size: 13pt; }
.ticket .cust { margin-top: 26px; display: grid; grid-template-columns: 1fr 1fr; gap: 26px 30px; }
.ticket .cust div { border-bottom: 1px solid #000; padding-top: 18px; font-size: 9pt; }
.ticket .foot { margin-top: 20px; font-size: 8.5pt; color: #444; }
.label { width: 4in; height: 2in; border: 1px dashed #999; padding: .12in; display: grid; grid-template-columns: 1.3in 1fr; gap: .12in; margin: 0 auto .2in; page-break-inside: avoid; break-inside: avoid; color: #000; background: #fff; }
.label .qr svg { width: 1.3in; height: 1.3in; display: block; }
.label .sku { font: 800 13pt ui-monospace, monospace; margin-top: 2px; text-align: center; }
.label .nm { font-weight: 800; font-size: 11.5pt; line-height: 1.15; max-height: 2.4em; overflow: hidden; }
.label .fit { font-size: 8.5pt; margin-top: 2px; max-height: 2.3em; overflow: hidden; }
.label .pr { font-size: 20pt; font-weight: 900; margin-top: 3px; }
.label .lc { font-size: 10pt; font-weight: 800; border-top: 1.5px solid #000; margin-top: 4px; padding-top: 3px; }
.labels-sheet { display: grid; grid-template-columns: repeat(2, 4in); gap: 0.1in; justify-content: center; }

@media print {
  @page { size: letter; margin: 0.4in; }
  body { background: #fff; padding: 0; }
  .no-print, .topbar, .bottomnav, .toast { display: none !important; }
  main { max-width: none; padding: 0; }
  .printpage { padding: 0; max-width: none; }
  .label { border: 1px dotted #bbb; }
  .ticket tr { break-inside: avoid; }
}
.savebar { position: sticky; bottom: calc(64px + env(safe-area-inset-bottom)); background: var(--bg); padding: 8px 0; z-index: 5; }
@media (min-width: 800px) { .savebar { bottom: 0; } }
.badge.mp { color: #1b4fa0; border-color: #b6c8ef; background: #eef2fc; }
