:root {
  --ground: #f2f5f2;
  --surface: #ffffff;
  --ink: #17211c;
  --muted: #5f6d66;
  --faint: #98a49e;
  --line: #d8e0db;
  --line-strong: #b9c5be;
  --accent: #0d6b4b;
  --accent-ink: #ffffff;
  --accent-soft: #e2f0e9;
  --available: #1f8a5a;
  --preorder: #b26a06;
  --backorder: #6b7a73;
  --danger: #b3261e;
  --row: 92px;
  --font: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.4 var(--font);
  color: var(--ink);
  background: var(--ground);
  display: flex;
  flex-direction: column;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3 { margin: 0; font-weight: 600; line-height: 1.2; }
h2 { font-size: 13px; color: var(--muted); }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
kbd { font: 12px/1 var(--font); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

.btn {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  border-radius: 6px;
  padding: 7px 12px;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  color: var(--ink);
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 500; }
.btn-primary:hover { background: #0a5a3f; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn-quiet:hover { color: var(--ink); border-color: var(--line-strong); }
.link { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Header */
.top {
  position: relative;
  display: grid;
  grid-template-columns: 200px 1fr auto;
  align-items: center;
  gap: 20px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; }
.brand-mark { width: 14px; height: 14px; background: var(--accent); border-radius: 3px; transform: rotate(45deg); }
.search { position: relative; display: block; }
.search input {
  width: 100%;
  padding: 11px 44px 11px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  font-size: 16px;
  background: var(--ground);
}
.search input:focus { background: var(--surface); border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.search kbd {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  padding: 3px 7px; border: 1px solid var(--line-strong); border-radius: 4px; color: var(--faint); background: var(--surface);
}
.feed { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.feed-text b { color: var(--ink); font-weight: 500; }
.cart-toggle { display: none; }
.progress {
  position: absolute; left: 0; right: 0; bottom: -1px; height: 3px; background: var(--line);
}
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .1s linear; }
.progress-text { position: absolute; right: 20px; bottom: 6px; font-size: 12px; color: var(--muted); background: var(--surface); padding: 2px 6px; border-radius: 4px; }

/* Three-column layout */
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 480px;
}
.filters, .cart { background: var(--surface); overflow-y: auto; }
.filters { border-right: 1px solid var(--line); padding: 16px; }
.cart { border-left: 1px solid var(--line); display: flex; flex-direction: column; }

.filter-block { margin-bottom: 20px; }
.filter-block h2 { margin-bottom: 8px; }
.check { display: flex; align-items: center; gap: 8px; padding: 4px 0; cursor: pointer; }
.check input { margin: 0; accent-color: var(--accent); }
.groups .check { justify-content: space-between; }
.groups .check span { display: flex; align-items: center; gap: 8px; }
.groups .count { color: var(--faint); font-size: 12px; }
.groups .check.zero { color: var(--faint); }
.filters input[type=text], .filters input:not([type]), .filters input[type=number] {
  width: 100%; padding: 6px 8px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface);
}
.price-range { display: flex; align-items: center; gap: 6px; }
.price-range span { color: var(--muted); }

/* Results */
.results-pane { display: flex; flex-direction: column; min-height: 0; }
.results-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 20px; color: var(--muted); font-size: 13px;
}
.sort select { margin-left: 6px; padding: 4px 6px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); }
.results { position: relative; flex: 1; overflow-y: auto; outline: none; }
.spacer { width: 1px; }
.rows { position: absolute; top: 0; left: 0; right: 0; }

.row {
  position: absolute; left: 12px; right: 12px; height: var(--row);
  display: grid;
  grid-template-columns: 80px minmax(0, 1fr) 150px 120px 132px;
  gap: 14px; align-items: center;
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.row:hover { background: #f8faf8; }
.row.selected { box-shadow: inset 3px 0 0 var(--accent); background: var(--accent-soft); }
.row.in-cart .name::before { content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-right: 6px; vertical-align: 2px; }
.thumb { width: 80px; height: 80px; object-fit: contain; background: var(--ground); border-radius: 6px; }
.thumb.missing { background: repeating-linear-gradient(45deg, var(--ground), var(--ground) 6px, #e6ebe7 6px, #e6ebe7 12px); }
.main { min-width: 0; }
.name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta .sku { color: var(--ink); }
.meta .discontinued { color: var(--danger); }
.meta .clearance { color: var(--preorder); font-weight: 500; }
.stock { font-size: 13px; line-height: 1.3; }
.stock .state { font-weight: 500; }
.stock .state.a0 { color: var(--available); }
.stock .state.a1 { color: var(--preorder); }
.stock .state.a2 { color: var(--backorder); }
.stock .sub { color: var(--muted); font-size: 12px; }
.price { text-align: right; line-height: 1.3; }
.price .ex { font-weight: 600; font-size: 15px; }
.price .rrp { color: var(--muted); font-size: 12px; }
.add { display: flex; justify-content: flex-end; align-items: center; gap: 4px; }
.qty {
  width: 46px; padding: 5px 4px; text-align: center;
  border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface);
}
.qty::-webkit-inner-spin-button { display: none; }
.add .btn { padding: 5px 10px; }
.add .btn-primary { min-width: 52px; }
.add .step { width: 28px; padding: 5px 0; text-align: center; }

.empty { display: flex; justify-content: center; padding: 60px 20px; }
.dropzone {
  max-width: 560px; padding: 32px; background: var(--surface);
  border: 2px dashed var(--line-strong); border-radius: 12px;
}
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone h1 { font-size: 22px; margin-bottom: 12px; letter-spacing: -0.01em; }
.dropzone p, .dropzone li { color: var(--muted); }
.dropzone ol { padding-left: 20px; margin: 16px 0 0; }
.dropzone li { margin: 6px 0; }
.dropzone em { font-style: normal; font-weight: 500; color: var(--ink); }
.no-results { padding: 40px; text-align: center; color: var(--muted); }

/* Cart */
.cart-head { display: flex; justify-content: space-between; align-items: baseline; padding: 16px 16px 8px; }
.cart-head h2 { font-size: 15px; color: var(--ink); }
.cart-summary { color: var(--muted); font-size: 12.5px; }
.cart-lines { flex: 1; overflow-y: auto; padding: 0 8px; }
.cart-empty { padding: 24px 8px; color: var(--muted); font-size: 13px; }
.line {
  display: grid; grid-template-columns: 104px minmax(0, 1fr) auto; gap: 4px 12px;
  padding: 12px 8px; border-bottom: 1px solid var(--line);
}
.line .lthumb {
  grid-row: 1 / 4; grid-column: 1; width: 104px; height: 104px; object-fit: contain;
  background: var(--ground); border-radius: 6px; cursor: pointer;
}
.line .lname {
  grid-column: 2; font-weight: 500; font-size: 13.5px; line-height: 1.3; cursor: pointer;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.line .lmeta { grid-column: 2; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.line .ltotal { grid-row: 1; grid-column: 3; text-align: right; font-weight: 600; font-size: 15px; }
.line .lctl { grid-row: 2 / 4; grid-column: 3; display: flex; align-items: center; gap: 2px; justify-content: flex-end; align-self: end; }
.line .lctl .qty { width: 48px; padding: 4px 2px; }
.line .lctl .step, .line .lctl .remove { border: 0; background: none; padding: 2px 6px; cursor: pointer; color: var(--muted); border-radius: 4px; font-size: 15px; }
.line .lctl .step:hover, .line .lctl .remove:hover { background: var(--ground); color: var(--ink); }
.line .warn { grid-column: 2; color: var(--preorder); font-size: 12px; }
.line .warn.bad { color: var(--danger); }
.cart-foot { border-top: 1px solid var(--line); padding: 12px 16px 16px; }
.totals { margin: 0 0 12px; }
.totals div { display: flex; justify-content: space-between; padding: 2px 0; color: var(--muted); }
.totals dd { margin: 0; }
.totals .grand { color: var(--ink); font-weight: 600; font-size: 16px; border-top: 1px solid var(--line); margin-top: 4px; padding-top: 6px; }
.cart-actions { display: flex; flex-direction: column; gap: 8px; }
.cart-actions-row { display: flex; justify-content: space-between; }
.quiet-link { font-size: 12.5px; color: var(--muted); text-align: center; }

/* Dialogs */
dialog { border: 0; border-radius: 12px; padding: 0; box-shadow: 0 20px 60px rgba(20, 40, 30, .25); color: var(--ink); }
dialog::backdrop { background: rgba(23, 33, 28, .45); }
.detail { width: min(1180px, 96vw); max-height: 92vh; }
.detail-body { display: grid; grid-template-columns: minmax(380px, 1fr) 1fr; gap: 28px; padding: 24px; }
.detail-gallery { position: sticky; top: 0; align-self: start; }
.detail-gallery > img { width: 100%; aspect-ratio: 1; object-fit: contain; background: var(--ground); border-radius: 8px; cursor: zoom-in; }
.detail-thumbs { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.detail-thumbs img { width: 104px; height: 104px; object-fit: contain; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; background: var(--ground); }
.detail-thumbs img.active { border-color: var(--accent); }
.detail h1 { font-size: 20px; letter-spacing: -0.01em; }
.detail .sub { color: var(--muted); margin: 4px 0 14px; }
.detail .buy { display: flex; align-items: center; gap: 12px; margin: 0 0 16px; padding: 12px; background: var(--ground); border-radius: 8px; }
.detail .buy .ex { font-size: 20px; font-weight: 600; }
.detail .buy .rrp { color: var(--muted); font-size: 13px; }
.detail .buy .add { margin-left: auto; }
.facts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px 16px; margin: 0 0 16px; font-size: 13px; }
.facts div { display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px solid var(--line); padding: 4px 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; text-align: right; }
.desc { white-space: pre-line; color: var(--ink); max-width: 60ch; line-height: 1.5; }
.desc.loading { color: var(--faint); }
.detail-close { position: absolute; top: 12px; right: 12px; }
.detail .links { margin-top: 16px; font-size: 13px; display: flex; gap: 16px; }

.import { width: min(560px, 94vw); }
.import form { padding: 24px; display: flex; flex-direction: column; gap: 12px; }
.import textarea { width: 100%; padding: 8px; border: 1px solid var(--line-strong); border-radius: 6px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.import p { margin: 0; color: var(--muted); }
.import-result { min-height: 1.4em; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
.toast.error { background: var(--danger); }

.hint {
  position: fixed; left: 12px; bottom: 12px; z-index: 4;
  display: flex; gap: 12px; align-items: center;
  padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--muted); font: 12px/1 var(--font);
  box-shadow: 0 4px 14px rgba(20, 40, 30, .08); cursor: pointer;
}
.hint:hover { border-color: var(--line-strong); color: var(--ink); }
.hint kbd, .keys kbd, .keys-note kbd {
  display: inline-block; padding: 2px 6px; border: 1px solid var(--line-strong); border-radius: 4px;
  background: var(--ground); color: var(--ink); font: 11px/1 var(--font);
}
.filters { padding-bottom: 56px; }

.shortcuts { width: min(460px, 94vw); }
.shortcuts form { padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.shortcuts h2 { font-size: 16px; color: var(--ink); }
.keys { margin: 0; display: grid; grid-template-columns: auto 1fr; row-gap: 10px; column-gap: 16px; }
.keys > div { display: contents; }
.keys dt { white-space: nowrap; text-align: right; }
.keys dd { margin: 0; }
.keys-note { margin: 0; color: var(--muted); font-size: 12.5px; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 200px minmax(0, 1fr); }
  .cart { position: fixed; right: 0; top: 0; bottom: 0; width: min(480px, 100vw); transform: translateX(100%); transition: transform .2s; z-index: 5; box-shadow: -8px 0 24px rgba(0,0,0,.1); }
  .cart.open { transform: none; }
  .cart-toggle { display: inline-block; }
  .row { grid-template-columns: 80px minmax(0, 1fr) 120px 100px 132px; }
}
@media (max-width: 760px) {
  .top { grid-template-columns: 1fr; gap: 8px; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .filters { display: none; }
  .hint { display: none; }
  .row { grid-template-columns: 64px minmax(0, 1fr) 90px; gap: 8px; }
  .row .stock { display: none; }
  .row .add { grid-column: 2 / -1; justify-content: flex-start; }
  .detail-body { grid-template-columns: 1fr; }
  .detail-gallery { position: static; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
