:root {
  --border: #d8dee5;
  --ink: #1f2933;
  --muted: #64748b;
  --accent: #1d5fa8;
  --bg-alt: #f6f8fa;
  font-size: 15px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: #fff;
}

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

/* ---- nav ---- */
#nav-slot { border-bottom: 1px solid var(--border); background: var(--bg-alt); }
.nav-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 20px;
}
.brand { margin-right: auto; font-weight: 700; font-size: 1.2rem; color: var(--ink); } /* pushes the rest of the nav to the right */
.add-item-link { white-space: nowrap; font-size: 0.85rem; color: var(--muted); }
.refresh-btn { white-space: nowrap; font-size: 0.85rem; color: var(--muted); background: none; border: 1px solid var(--border); border-radius: 4px; padding: 4px 8px; cursor: pointer; }
.refresh-btn:hover:not(:disabled) { color: inherit; border-color: currentColor; }
.refresh-btn:disabled { cursor: progress; }
.family-toggle { display: flex; align-items: center; gap: 5px; white-space: nowrap; font-size: 0.85rem; color: var(--muted); cursor: pointer; }
.family-toggle input { cursor: pointer; }
.cart-link { white-space: nowrap; font: inherit; font-weight: 600; color: var(--accent); background: none; border: none; padding: 0; cursor: pointer; }
.cart-link:hover { text-decoration: underline; }
.cart-count {
  display: inline-block;
  min-width: 1.4em;
  padding: 1px 5px;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  font-size: 0.75rem;
  text-align: center;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}


/* ---- homepage / category grids ---- */
.category-section { margin-bottom: 40px; }
.category-heading { display: flex; align-items: baseline; justify-content: space-between; border-bottom: 2px solid var(--ink); padding-bottom: 6px; margin-bottom: 14px; }

.filter-bar { display: flex; align-items: flex-start; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.filter-mode-label { font-size: 0.85rem; color: var(--muted); padding-top: 6px; }
#filter-mode { padding: 5px 8px; border: 1px solid var(--border); border-radius: 4px; background: #fff; align-self: flex-start; }
.filter-tags { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; }
.tag-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.82rem;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  background: #fff;
  user-select: none;
}
.tag-toggle:has(input:checked) { background: var(--accent); color: #fff; border-color: var(--accent); }
.tag-toggle input { margin: 0; }
.category-heading h2 { margin: 0; font-size: 1.3rem; }
.category-heading h2 a { color: var(--ink); }
.category-heading h3 { margin: 0; font-size: 1.05rem; }
.category-heading h3 a { color: var(--ink); }
.view-all { font-size: 0.85rem; white-space: nowrap; }
.subsection-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  margin: 18px 0 10px;
}

/* Subcategory blocks size to their own content (not a fixed column width),
   so several short ones can sit side by side instead of each claiming a full row. */
.subcategory-row {
  display: flex;
  flex-wrap: wrap;
  gap: 28px;
  margin-top: 4px;
}
.subcategory-block {
  flex: 0 1 auto;
  min-width: 0;
}
.subcategory-block h3 { margin: 0 0 10px; font-size: 1rem; }
.subcategory-block h3 a { color: var(--ink); }
.subcategory-block h3 .empty { font-weight: 400; }

.thumb-flex { display: flex; flex-wrap: wrap; gap: 16px; }
.thumb-flex .thumb-card { flex: 0 0 150px; }

.item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px;
}
.thumb-card {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  text-align: center;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: box-shadow .15s, border-color .15s;
}
.thumb-card[hidden] { display: none; } /* our own `display: flex` above would otherwise outrank the default [hidden] rule */
.thumb-card:hover { border-color: var(--accent); box-shadow: 0 2px 8px rgba(0,0,0,.08); text-decoration: none; }
.thumb-card img { width: 100%; aspect-ratio: 1; object-fit: contain; background: #fff; }
.thumb-card span { font-size: 0.85rem; line-height: 1.25; }
/* A card's corner button does one of two things: a family (multiple
   sizes/versions behind it) gets an ellipsis that opens the variant picker;
   a plain item gets a "+" that adds it straight to the cart. */
.card-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 20px;
  height: 20px;
  border: none;
  padding: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.85rem;
  font-family: inherit;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.card-badge:hover { filter: brightness(1.15); }
.add-badge { font-size: 1rem; font-weight: 700; }
/* The "N already in cart" counter next to any Add to Cart control — pinned to
   a card's opposite corner, or sitting inline in the family modal's list. */
.card-qty {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--ink);
  color: #fff;
  font-size: 0.7rem;
  line-height: 1;
}
.card-qty-corner { position: absolute; bottom: 6px; right: 6px; }
.card-qty[hidden], .in-cart[hidden] { display: none; } /* our own `display` would otherwise outrank the default [hidden] rule */
/* "3 in cart" on an item page: the same counter as .card-qty, with words. */
.in-cart { display: inline-block; font-size: 0.8rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: #e8f0fa; color: var(--accent); border: 1px solid #c5d8ee; white-space: nowrap; }
.in-cart-total { margin-top: 10px; }
.thumb-aka { font-size: 0.75rem; color: var(--muted); font-style: italic; }
.empty { color: var(--muted); font-size: 0.9rem; }

dialog#family-modal {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px 22px;
  max-width: 420px;
  width: 90%;
  box-shadow: 0 8px 24px rgba(0,0,0,.15);
}
dialog#family-modal::backdrop { background: rgba(0,0,0,.35); }
dialog#family-modal h3 { margin-top: 0; }
.family-modal-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow-y: auto; }
.family-modal-list li { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.family-modal-list li:last-child { border-bottom: none; }
.family-modal-label { flex: 1; }

/* ---- item detail ---- */
.item-layout { display: grid; grid-template-columns: 1fr 320px; gap: 32px; } /* text on the left, photos on the right (below the text on a narrow screen) */
.item-main { min-width: 0; } /* let wide content (e.g. .combo-table) scroll within the column instead of stretching it */
@media (max-width: 700px) { .item-layout { grid-template-columns: 1fr; } }
.item-gallery img { display: block; width: 100%; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
.item-gallery > * + * { margin-top: 10px; } /* spacing between the main photo, each extra, and the supplier box alike */
.item-photo-wrap { position: relative; }
.item-color-swatches { position: absolute; top: 8px; left: 8px; display: flex; gap: 4px; }
.color-swatch { width: 22px; height: 22px; border-radius: 4px; border: 1px solid rgba(0,0,0,.25); box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.item-tags { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 0; padding: 0; }
.item-tags li { font-size: 0.8rem; color: var(--muted); padding: 3px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--bg-alt); }
.item-title { font-size: 1.6rem; margin: 0 0 6px; }
/* A variant's family, above its own title: same size, lighter weight and color — and a link up to the family's page. */
.item-family { font-size: 1.6rem; font-weight: 400; margin: 0; }
.item-family a { color: var(--muted); }
.item-other-names { font-size: 0.85rem; color: var(--muted); font-style: italic; margin: 0 0 10px; }
.item-desc { margin: 14px 0; color: #333; }

.attr-table { border-collapse: collapse; width: 100%; margin: 10px 0 20px; font-size: 0.9rem; }
.attr-table th, .attr-table td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--border); }
.attr-table th { color: var(--muted); font-weight: 600; width: 40%; }

/* Comparison table (family items): many columns, so the 2-column key/value width doesn't apply. */
.combo-table { display: block; overflow-x: auto; }
.combo-table th { width: auto; white-space: nowrap; }
.combo-table td { white-space: nowrap; }
.combo-table input[type="number"] { width: 60px; padding: 4px; }
.combo-table button { padding: 6px 14px; background: var(--accent); color: #fff; border: none; border-radius: 4px; cursor: pointer; font-size: 0.85rem; }
.combo-table button:hover { opacity: .9; }

.add-to-cart { display: flex; align-items: center; gap: 8px; margin: 18px 0; flex-wrap: wrap; }
.add-to-cart input[type="number"] { width: 64px; padding: 6px; border: 1px solid var(--border); border-radius: 4px; }
.add-to-cart input[type="text"] { flex: 1; min-width: 160px; padding: 6px; border: 1px solid var(--border); border-radius: 4px; }
.add-to-cart button { padding: 7px 16px; background: var(--accent); color: #fff; border: none; border-radius: 4px; cursor: pointer; font-weight: 600; }
.add-to-cart button:hover { opacity: .9; }
/* An assembly offers two adds, kept visibly apart: the solid blue one (the default
   look) adds the item and its parts; the outlined teal one adds only the parts. */
.add-to-cart button.add-parts { background: #fff; color: #0d6e8c; border: 2px solid #0d6e8c; padding: 5px 14px; }

/* An assembly's parts, laid out like the cart. [label] is a reference tag. */
.parts-table { margin-bottom: 0; }
.parts-table .part-ref { width: 1%; white-space: nowrap; }
.parts-table .part-qty { width: 1%; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
/* A part whose id isn't in the catalog: its text left as written, just flagged. */
.part-missing { text-decoration: underline dashed #b3261e; text-decoration-thickness: 2px; text-underline-offset: 4px; }
.part-label { display: inline-block; min-width: 1.6em; text-align: center; font-size: 0.78rem; font-weight: 600; padding: 2px 9px; border: 1px solid var(--border); border-radius: 999px; background: var(--bg-alt); color: var(--muted); }
/* In the cart, beside a quantity raised by an assembly's parts — the cell stays on
   one line so the asterisk sits next to the box instead of wrapping under it. */
.cart-table td.cart-qty { white-space: nowrap; }
.part-bump { margin-left: 3px; font-weight: 700; color: #b45309; cursor: help; }

.related-block { margin-top: 30px; }
.related-block h3 { font-size: 1rem; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.link-list { list-style: none; padding: 0; margin: 0; }
.link-list li { padding: 4px 0; font-size: 0.9rem; }

.supplier-box { margin-top: 18px; padding: 10px 12px; background: var(--bg-alt); border: 1px solid var(--border); border-radius: 6px; font-size: 0.85rem; }

/* ---- cart ---- */
.cart-table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
.cart-table th, .cart-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.cart-table input[type="number"] { width: 60px; padding: 4px; }
.cart-table input[type="text"] { width: 100%; padding: 4px; border: 1px solid var(--border); border-radius: 4px; }
.cart-group-row td { padding-top: 16px; padding-bottom: 4px; border-bottom: none; font-weight: 600; }
/* `.cart-table td`'s own padding shorthand outranks a single class on
   specificity alone, regardless of source order — scope this to beat it. */
.cart-table td.cart-row-indent { padding-left: 36px; }
.cart-item-cell { display: flex; align-items: center; gap: 8px; }
.cart-thumb { width: 32px; height: 32px; object-fit: contain; background: #fff; border: 1px solid var(--border); border-radius: 4px; flex-shrink: 0; }
.variant-table td { white-space: nowrap; }
.variant-table td:first-child { white-space: normal; width: 100%; }
.variant-table button { padding: 6px 14px; background: var(--accent); color: #fff; border: none; border-radius: 4px; cursor: pointer; font-size: 0.85rem; }
.variant-table button:hover { opacity: .9; }
.cart-actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 16px 0; }
.cart-actions button, .cart-actions .btn { padding: 8px 14px; border: 1px solid var(--border); background: #fff; border-radius: 4px; cursor: pointer; font-size: 0.9rem; }
.cart-actions .btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.cart-actions .btn-primary.btn-update { background: #0d6e8c; border-color: #0d6e8c; } /* a different shade of blue, so "Update cart" reads as distinct from "Save cart" */
.remove-btn { color: #b3261e; background: none; border: none; cursor: pointer; font-size: 0.85rem; padding: 0; }
.saved-carts { margin-top: 30px; }
.saved-carts ul { list-style: none; padding: 0; }
.saved-carts li { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); }
.cart-name-btn {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  flex: 1;
}
.cart-name-btn:hover { color: var(--accent); text-decoration: underline; }

/* The cart slides over from the right edge. The UA stylesheet centers a modal
   dialog and caps its size, so all of that is undone here; .panel fills the
   dialog edge to edge so that a click on the backdrop is the only click whose
   target is the <dialog> itself (see cart-panel.js). */
dialog#cart-panel {
  margin: 0 0 0 auto;
  width: min(560px, 100vw);
  max-width: 100vw;
  height: 100vh;
  max-height: 100vh;
  padding: 0;
  border: none;
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 24px rgba(0,0,0,.15);
}
dialog#cart-panel::backdrop { background: rgba(0,0,0,.35); }
.panel { height: 100%; overflow-y: auto; padding: 18px 20px 30px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; border-bottom: 2px solid var(--ink); padding-bottom: 6px; margin-bottom: 14px; }
.panel-head h2 { margin: 0; font-size: 1.3rem; }
.panel-close { background: none; border: none; font-size: 1.6rem; line-height: 1; color: var(--muted); cursor: pointer; padding: 0 4px; }
.panel-close:hover { color: var(--ink); }

dialog#load-confirm, dialog#save-confirm {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px 22px;
  max-width: 380px;
  box-shadow: 0 8px 24px rgba(0,0,0,.15);
}
dialog#load-confirm::backdrop, dialog#save-confirm::backdrop { background: rgba(0,0,0,.35); }
dialog#load-confirm p, dialog#save-confirm p { margin-top: 0; }
dialog#load-confirm .cart-actions, dialog#save-confirm .cart-actions { margin: 16px 0 0; }


/* ---- homepage search ---- */
.item-search { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.item-search input[type="search"] { flex: 1; max-width: 480px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 4px; font-size: 1rem; }
.item-count { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
/* Grid | List, as one joined control pinned to the right of the search row. */
.view-toggle { display: flex; margin-left: auto; }
.view-toggle button { padding: 7px 14px; border: 1px solid var(--border); background: #fff; color: var(--ink); font: inherit; font-size: 0.9rem; cursor: pointer; }
.view-toggle button + button { border-left: none; }
.view-toggle button:first-child { border-radius: 4px 0 0 4px; }
.view-toggle button:last-child { border-radius: 0 4px 4px 0; }
.view-toggle button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.filter-clear { padding: 5px 10px; border: 1px solid var(--border); border-radius: 4px; background: #fff; color: var(--ink); font: inherit; font-size: 0.85rem; cursor: pointer; align-self: flex-start; }
.filter-clear:disabled { color: var(--muted); cursor: default; opacity: .6; }

/* List view: the cart's table, with a counter and an Add button per row. */
.item-list .list-qty { width: 1%; white-space: nowrap; text-align: right; }
.item-list .list-add { width: 1%; white-space: nowrap; }
.item-list .cart-item-cell .thumb-aka { margin-left: 4px; }
.list-add-btn { padding: 5px 12px; background: var(--accent); color: #fff; border: none; border-radius: 4px; cursor: pointer; font-size: 0.85rem; }
.list-add-btn:hover { opacity: .9; }

/* ---- add item form ---- */
.form-section { border: 1px solid var(--border); border-radius: 6px; padding: 16px 20px; margin-bottom: 20px; max-width: 640px; }
.form-section h2 { margin: 0 0 14px; font-size: 1.05rem; }
.form-section h2 .hint { display: inline; font-weight: 400; font-size: 0.8rem; margin: 0; }

.field { display: block; margin-bottom: 14px; }
.field > span:first-child { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 4px; }
.field input[type="text"], .field input[type="url"], .field textarea, .field select {
  width: 100%; padding: 7px 10px; border: 1px solid var(--border); border-radius: 4px; font: inherit;
}
fieldset.field { border: none; padding: 0; margin: 0 0 14px; }
fieldset.field legend { padding: 0; font-size: 0.85rem; font-weight: 600; margin-bottom: 4px; }
.required { color: #b3261e; }
.hint { font-size: 0.8rem; color: var(--muted); display: block; margin-top: 3px; }
.hint.error { color: #b3261e; }

.checkbox-list { max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: 4px; padding: 8px 12px; }
.checkbox-row { display: block; font-size: 0.9rem; padding: 3px 0; }
.checkbox-field { display: flex; align-items: center; gap: 8px; }
.checkbox-field input { width: auto; }

.attribute-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.attribute-row input { flex: 1; padding: 6px 8px; border: 1px solid var(--border); border-radius: 4px; }

.json-preview { margin-top: 24px; max-width: 640px; }
.json-preview summary { cursor: pointer; font-weight: 600; margin-bottom: 8px; }
.json-preview pre { background: var(--bg-alt); border: 1px solid var(--border); border-radius: 6px; padding: 12px; font-size: 0.8rem; overflow-x: auto; max-height: 400px; }

