:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f1f0ee;
  --line: #cfccc6;
  --ink: #1c1b19;
  --ink-dim: #63605a;
  --accent: #16566f;
  --accent-soft: #dceaf0;
  --return: #9c4a0d;
  --return-soft: #f7e6d8;
  --empty: #f4f3f1;
  --hit: #f0c419;
  --radius: 6px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;

  /* Chart categories. The first two reuse the app's accent and return hues, so
     Amazon and eBay land on colours the rest of the UI already uses. --hit yellow
     is deliberately absent: it means "search match" everywhere else. Hues differ
     in lightness as well as hue, so they still separate for colour-blind viewers. */
  --cat-1: #16566f;  /* teal — amazon */
  --cat-2: #9c4a0d;  /* rust — ebay   */
  --cat-3: #3d7a53;  /* green  */
  --cat-4: #7b4b94;  /* purple */
  --cat-5: #2f6fb0;  /* blue   */
  --cat-6: #8a6d1f;  /* olive  */
  --cat-7: #a33a52;  /* crimson */
  --cat-8: #4a5560;  /* slate  */
  --cat-other: #a9a49c;
  --loss: #b3261e;
  --warn: #8a5a00;
  --warn-soft: #fbefd5;
}

/* Deliberately light-only. The shelf map is read against a white background in a
   workshop, and a dark theme would flip it depending on the desktop setting. */

* { box-sizing: border-box; }

/* The hidden attribute must always win. Without this, any class that sets display
   (.errors is display:flex) overrides the browser's own [hidden] rule, and every
   "hidden" error box shows up as an empty coloured strip. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

/* --- header ---------------------------------------------------------- */

header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 650;
  letter-spacing: 0.02em;
}

.stats {
  display: flex;
  gap: 20px;
  color: var(--ink-dim);
  font-size: 14.5px;
  flex: 1;
}

.stats b {
  color: var(--ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

#search {
  width: 250px;
  padding: 6px 10px;
  font: inherit;
  font-family: var(--mono);
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

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

/* --- shelf tabs ------------------------------------------------------ */

.shelfnav {
  display: flex;
  gap: 4px;
  padding: 10px 20px 0;
  flex-wrap: wrap;
}

.shelfnav button {
  padding: 8px 16px;
  font: inherit;
  font-size: 15px;
  background: transparent;
  color: var(--ink-dim);
  border: 1px solid transparent;
  border-radius: var(--radius) var(--radius) 0 0;
  cursor: pointer;
}

.shelfnav button:hover { color: var(--ink); }

.shelfnav button[aria-current="true"] {
  background: var(--surface);
  border-color: var(--line);
  border-bottom-color: var(--surface);
  color: var(--ink);
  font-weight: 600;
  margin-bottom: -1px;
}

.shelfnav .count {
  font-variant-numeric: tabular-nums;
  opacity: 0.6;
  margin-left: 6px;
  font-size: 13px;
}

/* --- board ----------------------------------------------------------- */

main {
  display: flex;
  align-items: flex-start;
  gap: 0;
}

.board {
  flex: 1;
  min-width: 0;
  padding: 0 20px 40px;
  overflow-x: auto;
}

.shelf-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 14px 2px 10px;
}

.shelf-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
.shelf-head .meta { color: var(--ink-dim); font-size: 14px; }

.shelf-row {
  display: flex;
  align-items: stretch;
  gap: 6px;
  margin-bottom: 6px;
}

.row-label {
  width: 62px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 4px;
  color: var(--ink-dim);
  font-size: 13px;
  font-weight: 600;
}

/* One column track per column on the widest row, so column N sits in the same
   place on every row — as it does on the physical shelf. Short rows simply
   stop early rather than stretching to fill. */
.row-cells {
  display: grid;
  grid-template-columns: repeat(var(--max-cols, 10), minmax(152px, 1fr));
  gap: 6px;
  flex: 1;
}

.cell {
  min-width: 152px;
  min-height: 88px;
  padding: 7px 9px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.cell:hover { border-color: var(--accent); }

.cell.empty {
  background: var(--empty);
  border-style: dashed;
  cursor: default;
}

.cell.empty:hover { border-color: var(--line); }

.cell.hit {
  border-color: var(--hit);
  box-shadow: inset 0 0 0 2px var(--hit);
}

.cell-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-dim);
  white-space: nowrap;     /* "Column 1" and "10 units" must not wrap onto each other */
  margin-bottom: 2px;
}

.cell-head .units {
  font-variant-numeric: tabular-nums;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--surface-2);
  color: var(--ink);
}

.entry {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.4;
}

.entry .id { color: var(--ink); }
.entry .qty { color: var(--ink-dim); font-variant-numeric: tabular-nums; }

.entry.return .id::after {
  content: "R";
  font-size: 10px;
  vertical-align: super;
  color: var(--return);
  margin-left: 2px;
}

.entry.return .id { color: var(--return); }

.entry.hit .id {
  background: var(--hit);
  color: #1c1b19;
  border-radius: 2px;
  padding: 0 2px;
}

/* --- side panel ------------------------------------------------------ */

.panel {
  width: 370px;
  flex: none;
  align-self: stretch;
  background: var(--surface);
  border-left: 1px solid var(--line);
  padding: 16px 18px 40px;
  position: sticky;
  top: var(--header-h, 60px);
  max-height: calc(100vh - var(--header-h, 60px));
  overflow-y: auto;
}

/* Below this the board has no room left beside a docked panel, so float it. */
@media (max-width: 900px) {
  .panel {
    position: fixed;
    right: 0;
    top: var(--header-h, 60px);
    bottom: 0;
    max-height: none;
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.18);
    z-index: 25;
  }
}

.close {
  float: right;
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  color: var(--ink-dim);
  cursor: pointer;
  padding: 0 2px;
}

.panel h3 {
  margin: 0 0 3px;
  font-size: 16.5px;
}

.panel .sub {
  color: var(--ink-dim);
  font-size: 13.5px;
  margin-bottom: 14px;
}

.stack { list-style: none; margin: 0; padding: 0; }

/* position · item · quantity · Record button */
.stack li {
  display: grid;
  grid-template-columns: 26px 1fr auto auto;
  /* last track holds both buttons */
  gap: 8px;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

/* The item is text, not a control — every action is an explicit button, so
   nothing happens just because you clicked near a row. */
.stack .entry-id { font-family: var(--mono); }

.row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.stack .pos { color: var(--ink-dim); font-size: 12.5px; }
.stack .qty { font-variant-numeric: tabular-nums; }

.tag {
  font-size: 11.5px;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--accent-soft);
  color: var(--accent);
  margin-left: 5px;
  font-family: system-ui, sans-serif;
}

.tag.return { background: var(--return-soft); color: var(--return); }

.note {
  grid-column: 2 / -1;
  color: var(--ink-dim);
  font-size: 12.5px;
  font-family: system-ui, sans-serif;
}

.loc-list { list-style: none; margin: 8px 0 0; padding: 0; }

.loc-list li {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.loc-list a { color: var(--accent); text-decoration: none; }
.loc-list a:hover { text-decoration: underline; }

.totals {
  display: flex;
  gap: 14px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: var(--radius);
  margin-bottom: 6px;
}

.totals div { font-size: 13px; color: var(--ink-dim); }
.totals b {
  display: block;
  font-size: 20px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* --- buttons and forms ----------------------------------------------- */

button.primary, button.ghost {
  padding: 8px 17px;
  font: inherit;
  font-size: 15px;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid var(--line);
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 550;
}

button.primary:hover { filter: brightness(1.08); }
button.primary:disabled { opacity: 0.55; cursor: default; }

button.ghost {
  background: transparent;
  color: var(--ink-dim);
}

button.ghost:hover { color: var(--ink); border-color: var(--ink-dim); }

.wide { width: 100%; }

.form { display: flex; flex-direction: column; gap: 11px; margin-top: 4px; }

.field { display: flex; flex-direction: column; gap: 3px; }

.field-label {
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-dim);
}

.form input, .form select {
  padding: 8px 10px;
  font: inherit;
  font-size: 15px;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.form input:focus, .form select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.form input:disabled, .form select:disabled {
  opacity: 0.6;
  cursor: default;
}

.form .mono { font-family: var(--mono); }

.blurb {
  font-size: 13.5px;
  color: var(--ink-dim);
  padding: 7px 9px;
  background: var(--surface-2);
  border-radius: var(--radius);
}

.hint { font-size: 12.5px; color: var(--ink-dim); }

.errors {
  padding: 8px 10px;
  background: var(--return-soft);
  border: 1px solid var(--return);
  border-radius: var(--radius);
  color: var(--return);
  font-size: 13.5px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.loc-list li.txn {
  font-family: system-ui, sans-serif;
  font-size: 13.5px;
  align-items: flex-start;
  gap: 10px;
}

.loc-list li.txn b { font-family: var(--mono); font-size: 13px; }
.loc-list li.txn .note { display: block; margin-top: 2px; }

.txn-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  flex: none;
}

.txn-right .date { font-size: 12.5px; color: var(--ink-dim); }

button.ghost.small {
  padding: 4px 12px;
  font-size: 13px;
}

.banner {
  padding: 10px 12px;
  margin-bottom: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: var(--radius);
  font-size: 13.5px;
}

/* --- search results -------------------------------------------------- */

.results {
  position: fixed;
  top: calc(var(--header-h, 60px) - 4px);
  right: 20px;
  width: 300px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  z-index: 30;
  max-height: 60vh;
  overflow-y: auto;
}

.results button {
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--line);
  font: inherit;
  font-family: var(--mono);
  font-size: 14px;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.results button:hover { background: var(--surface-2); }
.results .none { padding: 11px 13px; color: var(--ink-dim); font-size: 14px; }
.results small { color: var(--ink-dim); }


.period {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--ink-dim);
}

.period select {
  padding: 6px 10px;
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

/* --- dashboard layout --------------------------------------------------- */

.dash {
  flex: 1;
  min-width: 0;
  padding: 18px 20px 48px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.kpis { flex-wrap: wrap; gap: 8px 28px; padding: 14px 16px; margin: 0; }
.kpis .loss b { color: var(--loss); }

.notice {
  padding: 10px 14px;
  background: var(--warn-soft);
  border: 1px solid #ecd49c;
  border-radius: var(--radius);
  color: var(--warn);
  font-size: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.card {
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 2px);
  background: var(--surface);
  padding: 14px 16px;
  min-width: 0;
}

.card-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.card-head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.card-head .meta { color: var(--ink-dim); font-size: 13.5px; }

/* --- charts -------------------------------------------------------------- */

.charts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 16px;
}

.chart-body {
  display: flex;
  align-items: center;
  gap: 22px;
  flex-wrap: wrap;
}

.pie { width: 180px; height: 180px; flex: none; }
.bars { width: 100%; max-width: 360px; height: auto; flex: none; }

.pie path, .pie circle { stroke: var(--surface); stroke-width: 1.5; }

/* One class sets the colour; each element type decides what to paint with it. */
.cat-1 { --c: var(--cat-1); }   .cat-2 { --c: var(--cat-2); }
.cat-3 { --c: var(--cat-3); }   .cat-4 { --c: var(--cat-4); }
.cat-5 { --c: var(--cat-5); }   .cat-6 { --c: var(--cat-6); }
.cat-7 { --c: var(--cat-7); }   .cat-8 { --c: var(--cat-8); }
.cat-other { --c: var(--cat-other); }

.pie path, .pie circle, .bars rect { fill: var(--c); }
.bars rect.loss { fill: var(--loss); }
.bars .zero { stroke: var(--ink-dim); stroke-width: 1; }
.bars .bar-label { font-size: 13px; fill: var(--ink); font-family: system-ui, sans-serif; }

.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 170px;
  flex: 1;
}

.legend li {
  display: grid;
  grid-template-columns: 12px 1fr auto 42px;
  gap: 8px;
  align-items: center;
  font-size: 14px;
}

.swatch { width: 12px; height: 12px; border-radius: 3px; background: var(--c); }
.legend-label { font-family: var(--mono); font-size: 13px; }
.legend-value { font-variant-numeric: tabular-nums; }
.legend-pct { color: var(--ink-dim); text-align: right; font-variant-numeric: tabular-nums; }

.chart-empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--ink-dim);
  font-size: 14px;
  background: var(--empty);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.chart-note { margin: 10px 0 0; font-size: 13px; color: var(--ink-dim); }

/* --- sales table --------------------------------------------------------- */

.table-wrap { overflow-x: auto; }

table.sales {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

table.sales th {
  text-align: left;
  font-size: 12.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--ink-dim);
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

table.sales td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--surface-2);
  white-space: nowrap;
}

table.sales .num { text-align: right; font-variant-numeric: tabular-nums; }
table.sales .mono { font-family: var(--mono); font-size: 13px; }
table.sales .order { color: var(--ink-dim); }
table.sales .date { color: var(--ink-dim); font-variant-numeric: tabular-nums; white-space: nowrap; }
table.sales .shipped { display: block; font-size: 11.5px; color: var(--warn); }
table.sales .profit { font-weight: 600; }
table.sales .loss { color: var(--loss); }
table.sales .tags { white-space: normal; }
table.sales .tags .tag { margin: 0 4px 0 0; }

table.sales tbody tr { cursor: pointer; }
table.sales tbody tr:hover { background: var(--surface-2); }
table.sales tbody tr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* A left rule makes incomplete rows scannable without reading every tag. */
table.sales tr.incomplete td:first-child { box-shadow: inset 3px 0 0 #e2b04a; }

.chan {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chan::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c, var(--cat-other));
}

.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.muted { background: var(--surface-2); color: var(--ink-dim); }

/* --- profit preview in the edit form ------------------------------------- */

.preview {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: var(--radius);
  font-size: 14px;
}

.preview div { display: flex; justify-content: space-between; gap: 10px; }
.preview b { font-variant-numeric: tabular-nums; font-weight: 500; }
.preview .preview-total {
  border-top: 1px solid var(--line);
  margin-top: 4px;
  padding-top: 6px;
}
.preview .preview-total b { font-weight: 700; }
.preview .loss { color: var(--loss); }
.preview .meta { color: var(--ink-dim); }

/* --- optional money on the SALE form -------------------------------------- */

.money-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 12px;
}

.money-section summary {
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}

.money-section[open] summary { margin-bottom: 10px; }


/* --- app shell: left menu + page ------------------------------------------ */

:root { --nav-w: 208px; --nav-w-collapsed: 60px; }

body {
  display: grid;
  grid-template-columns: var(--nav-w) minmax(0, 1fr);
  min-height: 100vh;
}

body.nav-collapsed { grid-template-columns: var(--nav-w-collapsed) minmax(0, 1fr); }

.content { min-width: 0; display: flex; flex-direction: column; }

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 10px;
  background: #f7f6f4;
  border-right: 1px solid var(--line);
  overflow: hidden;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 6px 16px;
  white-space: nowrap;
}

.brand-mark {
  flex: none;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
}

.brand-name { font-weight: 650; font-size: 15px; letter-spacing: 0.01em; }

.nav-links { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.nav-link, .nav-toggle {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 10px;
  border-radius: var(--radius);
  color: var(--ink-dim);
  text-decoration: none;
  font: inherit;
  font-size: 15px;
  white-space: nowrap;
  border: none;
  background: none;
  cursor: pointer;
  text-align: left;
}

.nav-link:hover, .nav-toggle:hover { background: var(--surface-2); color: var(--ink); }

.nav-link[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.nav-link:focus-visible, .nav-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.nav-icon { flex: none; width: 20px; height: 20px; display: grid; place-items: center; }
.nav-icon svg { width: 20px; height: 20px; }

.nav-toggle { font-size: 13.5px; }
.nav-toggle .nav-icon svg { transition: transform 0.15s; }

/* Collapsed: icons only. Labels are hidden, not removed, so the title tooltip and
   screen readers still name each item. */
body.nav-collapsed .nav-label { display: none; }
body.nav-collapsed .nav-link, body.nav-collapsed .nav-toggle { justify-content: center; padding: 8px 0; }
body.nav-collapsed .brand { justify-content: center; padding-left: 0; padding-right: 0; }
body.nav-collapsed .nav-toggle .nav-icon svg { transform: rotate(180deg); }

/* The page title replaces the brand in the header. */
.page-title { font-size: 18px; font-weight: 650; white-space: nowrap; }

/* Narrow windows: always icons only, whatever was saved. */
@media (max-width: 900px) {
  body, body.nav-collapsed { grid-template-columns: var(--nav-w-collapsed) minmax(0, 1fr); }
  .nav-label { display: none; }
  .nav-link, .nav-toggle { justify-content: center; padding: 8px 0; }
  .brand { justify-content: center; padding-left: 0; padding-right: 0; }
  .nav-toggle { display: none; }
}

/* The header wraps when the window is narrow rather than clipping its buttons.
   Its real height is measured into --header-h (common.js), so the side panel and
   search results sit below it however many lines it takes. */
header { flex-wrap: wrap; row-gap: 10px; }
header .stats { min-width: 260px; }

/* --- product library ------------------------------------------------------ */

#lib-search {
  flex: 1 1 280px;
  min-width: 220px;
  padding: 7px 11px;
  font: inherit;
  font-family: var(--mono);
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

#lib-search:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.library-wrap { flex: 1; min-width: 0; padding: 18px 20px 48px; }

/* One bar holds every way of narrowing the library. */
.lib-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  margin-bottom: 14px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: calc(var(--radius) + 2px);
}

.filter { display: flex; align-items: center; gap: 7px; font-size: 14px; color: var(--ink-dim); }
.filter select {
  padding: 7px 9px;
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  max-width: 230px;
}
.filter select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* What made a tile match */
.tile-match { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.match-label { font-size: 12px; font-weight: 600; color: var(--warn); }
.oem-chip.hit { background: var(--warn-soft); border-color: #e2b04a; color: var(--warn); font-size: 12px; padding: 1px 6px; }
.make.hit { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.hit-text { background: var(--warn-soft); border-radius: 3px; padding: 0 3px; margin: 0 -3px; }

/* Brands on the card are buttons that filter the library. */
.make.link { border: none; font: inherit; font-size: 12px; cursor: pointer; }
.make.link:hover { background: var(--accent-soft); color: var(--accent); }


.library {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
}

.lib-empty { grid-column: 1 / -1; }

.tile {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 12px 14px;
  min-height: 168px;
  text-align: left;
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 2px);
  cursor: pointer;
  transition: border-color 0.12s, box-shadow 0.12s;
}

.tile:hover { border-color: var(--accent); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06); }
.tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tile.no-info { background: var(--empty); border-style: dashed; }

.tile-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tile-pn { font-family: var(--mono); font-size: 17px; font-weight: 700; }
.tile-oem { font-family: var(--mono); font-size: 13.5px; color: var(--ink); }
.tile-oem .label, .card-sub .label { font-family: system-ui, sans-serif; color: var(--ink-dim); font-size: 12.5px; }

.tile-title {
  font-size: 13.5px;
  color: var(--ink-dim);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tile-makes { display: flex; flex-wrap: wrap; gap: 4px; }
.make {
  font-size: 12px;
  padding: 1px 7px;
  border-radius: 20px;
  background: var(--surface-2);
  color: var(--ink);
}

.tile-foot {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.stock { font-weight: 600; font-variant-numeric: tabular-nums; }
.stock.none { color: var(--ink-dim); font-weight: 400; }

.badges { display: flex; gap: 4px; flex: none; }

.ch-badge {
  font-size: 11.5px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 4px;
  color: #fff;
  white-space: nowrap;
}
.ch-badge.amazon { background: var(--cat-1); }
.ch-badge.ebay { background: var(--cat-2); }
.ch-badge.absent { background: transparent; color: var(--ink-dim); border: 1px dashed var(--line); opacity: 0.7; }

/* --- product card --------------------------------------------------------- */

.product-card {
  width: min(1040px, calc(100vw - 40px));
  max-height: calc(100vh - 40px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}

.product-card::backdrop { background: rgba(28, 27, 25, 0.45); }

#card-body {
  max-height: calc(100vh - 42px);
  overflow-y: auto;
  padding: 20px 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.card-pn { margin: 0; font-family: var(--mono); font-size: 26px; font-weight: 700; }
.card-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 6px; font-size: 15px; }
.card-sub b { font-family: var(--mono); }
.card-makes { margin-top: 10px; }
.card-top .close { float: none; font-size: 28px; padding: 0 4px; }

#card-body .totals { margin: 0; flex-wrap: wrap; }

.diff-list { margin: 4px 0 0 18px; padding: 0; }

.card-section { border-top: 1px solid var(--line); padding-top: 14px; }
.card-section-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.card-section-head h3 { margin: 0; font-size: 16px; }
.card-section-head .meta { font-size: 13px; color: var(--ink-dim); }

.compare {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 12px;
}

.compare-col {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  border-top-width: 3px;
  min-width: 0;
}
.compare-col.amazon { border-top-color: var(--cat-1); }
.compare-col.ebay { border-top-color: var(--cat-2); }
.compare-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.compare-head .meta { font-size: 12.5px; color: var(--ink-dim); }

/* Compatible vehicles: Brand -> Model -> year ranges. */
.fit, .fit ul { list-style: none; margin: 0; padding: 0; }
.fit { font-size: 14px; display: flex; flex-direction: column; gap: 8px; }
.fit-brand { font-weight: 600; cursor: pointer; }
.fit-count { font-weight: 400; font-size: 12.5px; margin-left: 8px !important; }
.fit-models { margin: 4px 0 0 14px !important; border-left: 2px solid var(--surface-2); padding-left: 10px !important; }
.fit-model { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; padding: 2px 0; }
.fit-model-name { min-width: 7em; overflow-wrap: anywhere; }
.fit-ranges { display: flex; flex-wrap: wrap; gap: 4px; }
.fit-range {
  display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: 0 6px;
  background: var(--surface-2); border-radius: 4px; padding: 1px 7px; font-size: 13px;
}
.fit-years { font-family: var(--mono); font-size: 12.5px; }
.fit-engine { color: var(--accent); }
.fit-note { color: var(--ink-dim); font-style: italic; }

.listing-text { margin: 8px 0; }
.listing-text-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.listing-text p {
  margin: 4px 0 0; font-size: 13px; line-height: 1.45; color: var(--ink-dim);
  background: var(--surface-2); border-radius: 4px; padding: 6px 8px;
  max-height: 7.5em; overflow-y: auto; overflow-wrap: anywhere; user-select: all;
}

/* Editor for the same list. */
.fe { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.fe-brands { display: flex; flex-direction: column; gap: 8px; align-self: stretch; }
.fe-brand { border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 8px; }
.fe-brand-head, .fe-model-head { display: flex; align-items: center; gap: 6px; }
.fe-brand-body { margin: 6px 0 2px 10px; padding-left: 10px; border-left: 2px solid var(--surface-2);
                 display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.fe-models { display: flex; flex-direction: column; gap: 8px; align-self: stretch; }
.fe-model { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.fe-model-head { align-self: stretch; }
.fe-ranges { display: flex; flex-direction: column; gap: 4px; align-self: stretch; padding-left: 12px; }
.fe-range { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.fe input {
  font: inherit; font-size: 13px; padding: 4px 6px; min-width: 0;
  border: 1px solid var(--line); border-radius: 4px; background: var(--bg); color: var(--ink);
}
.fe input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.fe input:disabled { background: var(--surface-2); }
.fe-brand-name { font-weight: 600 !important; flex: 1 1 10em; }
.fe-model-name { flex: 1 1 10em; }
.fe-year { width: 4.6em; }
.fe-dash { color: var(--ink-dim); }
.fe-engine { flex: 1 1 7em; }
.fe-note { flex: 2 1 9em; }
.fe-count { font-size: 12px; white-space: nowrap; }
.fe-remove {
  border: none; background: none; color: var(--ink-dim); font-size: 17px; line-height: 1;
  width: 24px; height: 24px; border-radius: 4px; cursor: pointer; flex: none;
}
.fe-remove:hover:not(:disabled) { background: var(--return-soft); color: var(--loss); }
.fe-add { font-size: 12px; }

.oem-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.oem-chip {
  font-family: var(--mono);
  font-size: 13px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--surface-2);
  border: 1px solid transparent;
}
.oem-chip.only-here { background: var(--warn-soft); border-color: #e2b04a; color: var(--warn); }
.oem-brand {
  font-family: system-ui, sans-serif;
  font-size: 11.5px;
  color: var(--ink-dim);
  margin-right: 5px;
}
.oem-group-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-dim);
  margin: 12px 0 6px;
}

.listing-title { font-weight: 600; font-size: 14.5px; line-height: 1.4; }
.facts { margin: 8px 0 0; display: grid; grid-template-columns: max-content 1fr; gap: 3px 12px; font-size: 13.5px; }
.facts dt { color: var(--ink-dim); }
.facts dd { margin: 0; font-family: var(--mono); overflow-wrap: anywhere; }
.notes, .refs { margin: 0; padding-left: 18px; font-size: 13.5px; line-height: 1.5; }
.refs a { color: var(--accent); overflow-wrap: anywhere; }
.product-card .meta { color: var(--ink-dim); font-size: 13.5px; margin: 0; }
.product-card code { font-family: var(--mono); font-size: 13px; }

/* --- product card: editing ------------------------------------------------ */

.card-actions { display: flex; align-items: center; gap: 10px; flex: none; }

.product-card textarea, .product-card input.wide {
  padding: 7px 9px;
  font: inherit;
  font-size: 14px;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  resize: vertical;
  line-height: 1.45;
}
.product-card textarea.mono, .product-card input.mono { font-family: var(--mono); font-size: 13px; }
.product-card textarea:focus, .product-card input.wide:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.part-form { max-width: 360px; }
.move-warn { color: var(--warn); font-weight: 600; }

/* Save and Cancel stay reachable however long the form is. */
.edit-bar {
  position: sticky;
  bottom: -28px;
  margin: 0 -24px -28px;
  padding: 12px 24px 16px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.edit-buttons { display: flex; justify-content: flex-end; gap: 10px; }

/* --- adding and removing products and listings ---------------------------- */

.add-product { margin-left: auto; }

button.ghost.danger { color: var(--loss); border-color: #e3b7b3; }
button.ghost.danger:hover { background: #fbeae8; color: var(--loss); border-color: var(--loss); }
button.ghost.danger:disabled { opacity: 0.45; cursor: default; background: none; }

.compare-head .spacer { flex: 1; }

/* A listing marked for removal stays visible, so it can be kept again before saving. */
.compare-col.removing { opacity: 0.5; background: repeating-linear-gradient(-45deg, transparent 0 8px, var(--surface-2) 8px 16px); }
.compare-col.removing .compare-head { opacity: 1; }

.add-listing-buttons { display: flex; gap: 8px; margin-top: 10px; }

.pn-status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-height: 18px; }

.flash { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.flash > span { flex: 1; }
.flash .close { float: none; font-size: 20px; }
