:root {
  --bg: #f7f8fa;
  --card-bg: #ffffff;
  --text: #000;
  --muted: #aaa;
  --accent: #dc2626;
  --border: #dfdfdf;
  --shadow: 0 4px 12px rgba(2, 8, 23, 0.05);
  --radius: 8px;
  --pill-radius: 6px;
  --maxw: 1200px;
  --control-h: 46px;
  --pill-h: 26px;
  --pill-gap: 0.25em;
  --side-pad: 20px;
  --searchbar-h: 0px;
  --subtle-white: rgba(255, 255, 255, 0.7); 
  --recipe-font: 'Roboto', sans-serif;
  --recipe-size: 16px;
  --recipe-spacing: 1.5;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
}

html {
  scrollbar-gutter: stable;
}

body {
  margin: 0;
  font-family: 'Roboto Mono', monospace;
  color: var(--text);
  background: #fff;
  padding-top: calc(env(safe-area-inset-top, 0px) + var(--searchbar-h));
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

* {
  scrollbar-width: thin;
  scrollbar-color: #c1c1c1 #f1f1f1;
}

body.full-width .container {
  max-width: none;
  padding: 0 20px 48px;
}

@media (max-width: 640px) {
  body.full-width .grid {
    width: 100%;
    margin-left: 0;
    margin-right: 0;
  }
}

body.full-width .search-wrap {
  padding-top: 12px;
  padding-bottom: 10px;
}

.container {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 var(--side-pad) 48px;
}

/* Toolbar */
.toolbar {
  position: relative;
  z-index: 10;
  margin: 0;
  padding: 0;
}

.toolbar .search-wrap {
  position: fixed;
  top: env(safe-area-inset-top, 0px);
  left: 0;
  right: 0;
  z-index: 2000;
  background: #fff;
  padding: 12px 0 10px;
  box-shadow: 0 1px 12px rgba(0, 0, 0, 0.1);
}

.search-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 var(--side-pad);
  display: grid;
  grid-template-columns: 1fr auto auto auto auto;
  align-items: center;
  gap: 15px;
}

body.full-width .search-inner {
  max-width: none;
}

@media (min-width: 641px) and (max-width: 1200px) {
  .search-inner {
    grid-template-columns: 1fr auto auto auto;
  }
  .search-inner #fullWidthBtn {
    display: none !important;
  }
}

@media (max-width: 640px) {
  .search-inner {
    grid-template-columns: 1fr auto;
  }
  .search-inner .sort-select,
  .search-inner .custom-sort,
  .search-inner .view-toggle,
  .search-inner #fullWidthBtn {
    display: none !important;
  }
}

.search {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  box-shadow: none;
  min-width: 0;
  min-height: var(--control-h);
}

.search input {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  font-size: 16px;
  color: var(--text);
  flex: 1 1 auto;
  min-width: 0;
  font-family: 'Roboto Condensed', sans-serif;
}

.search input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.search .icon {
  width: 20px;
  height: 20px;
  color: var(--muted);
  flex: 0 0 auto;
}

.search-scope {
  /* Pill Styling */
  background: #eee;
  color: #0f172a;
  border: 1px solid #d1d1d1;
  /* Layout & Typography */
  border-radius: var(--pill-radius); /* USING VARIABLE */
  padding: 4px 8px;
  font-family: 'Roboto Condensed', sans-serif;
  font-size: 12px;
  font-weight: 400;
  line-height: 1;
  white-space: nowrap;
  margin-left: -4px;
  display: none;
  align-items: center;
  justify-content: center;
  user-select: none;
  cursor: pointer;
  position: relative;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.1s ease;
}

/* ON HOVER: Hide text, slightly darker grey background */
.search-scope:hover {
  border-color: #bbb;
  color: transparent;
}

.search-scope.active {
  display: inline-flex;
}

/* Create the X using CSS */
.search-scope::after {
  content: "✕";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  color: #555;
  font-size: 10px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
}

/* Show the X on hover */
.search-scope:hover::after {
  opacity: 1;
}

.clear-x {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  width: 20px;
  height: 20px;
  padding: 0;
  margin: 0;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: 0 0 auto;
}

.clear-x svg {
  width: 100%;
  height: 100%;
  display: block;
}

.search .icon-search {
  display: inline-block;
}

.search .clear-x {
  display: none;
}

.search.has-value .icon-search {
  display: none;
}

.search.has-value .clear-x {
  display: inline-flex;
}

.search .count {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  flex: 0 0 auto;
}

.sort-select {
  font-family: 'Roboto Condensed', sans-serif;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 24px 0 12px;
  padding: 0 12px;
  height: var(--control-h);
  background: #fff;
  color: #aaa;
  box-shadow: none;
  font-size: 16px;
  appearance: none;
  background-image: none;
  text-align: center;
  text-align-last: center;
}

.sort-select:focus {
  outline: none;
}

.sort-select option {
  text-align: center;
  text-align-last: center;
}

.view-toggle {
  display: inline-flex;
  gap: 6px;
  justify-self: end;
}

.view-btn {
  font-family: 'Roboto Condensed', sans-serif;
  appearance: none;
  border: 1px solid var(--border);
  background: #fff;
  color: #0f172a;
  height: var(--control-h);
  padding: 0 12px;
  border-radius: 6px;
  box-shadow: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.view-btn[aria-pressed="true"] {
  background: #fee2e2;
  color: #b91c1c;
  border-color: #fecaca;
  box-shadow: none;
}

.view-btn svg {
  width: 18px;
  height: 18px;
}

.settings-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  height: var(--control-h);
  border-radius: 6px;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  padding: 0;
}

body.full-width #fullWidthBtn {
  background: #fee2e2;
  color: #b91c1c;
  border-color: #fecaca;
  box-shadow: none;
}

.settings-btn svg {
  width: 18px;
  height: 18px;
}

.catbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 16px 0 16px 0;
}

.cat-chip {
  font-family: 'Roboto Condensed', sans-serif;
  appearance: none;
  border: 1px solid #d1d1d1;
  background: #eee;
  color: #0f172a;
  font-size: 13px;
  line-height: 1;
  border-radius: var(--pill-radius); /* USING VARIABLE */
  padding: 6px 10px;
  cursor: pointer;
  user-select: none;
  transition: background .15s, color .15s, border-color .15s, box-shadow .15s;
}

.cat-chip.active {
  background: #fee2e2;
  color: #b91c1c;
  border-color: #fecaca;
  box-shadow: none;
}

@media (max-width: 1024px) {
  .catbar {
    gap: 4px;
  }
  .cat-chip {
    font-size: 12px;
    padding: 4px 8px;
  }
}

@media (max-width: 640px) {
  .catbar {
    gap: 4px;
  }
  .cat-chip {
    font-size: 11px;
    padding: 4px 8px;
    white-space: nowrap;
  }
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
  margin-top: 0;
}

.card {
  background: var(--card-bg);
  border: 1px solid #bbb;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: clip;
  display: flex;
  flex-direction: column;
  transition: box-shadow .18s ease, border-color .18s ease;
}

.card:hover {
  box-shadow: var(--shadow);
}

.media {
  width: 100%;
  aspect-ratio: 3 / 2;
  background: #f0f0f0;
  overflow: hidden;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.media-emoji {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 70px;
  line-height: 1;
  background: #f0f0f0;
  user-select: none;
  cursor: default;
}

.sku-stack {
  position: absolute;
  top: 10px;
  left: 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  z-index: 3;
}

.weight-stack {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  z-index: 3;
}

.price-stack {
  position: absolute;
  left: 10px;
  bottom: 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  z-index: 3;
  cursor: pointer;
}

.sku-stack.expanded,
.weight-stack.expanded,
.price-stack.expanded {
  z-index: 10;
}

.price-pill {
  height: var(--pill-h);
  padding: 0 8px;
  border-radius: var(--pill-radius); /* USING VARIABLE */
  color: #fff;
  font-weight: 400;
  font-size: 12px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  box-shadow: var(--shadow);
  backdrop-filter: blur(2px);
  white-space: nowrap;
  font-family: 'Roboto Mono', monospace;
  width: fit-content;
}

.price-pill.retail {
  background: #dc2626;
}

.price-pill.trade {
  background: #059669;
}

.price-pill.wholesale {
  background: #0284c7;
}

.price-pill.cost {
  background: #666666;
}

.sku-pill {
  font-size: 12px;
  color: #000000;
  background: #fff;
  border: 0px solid #ccc;
  border-radius: var(--pill-radius); /* USING VARIABLE */
  padding: 2px 8px;
  width: fit-content;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sku-pill svg {
  height: 1em;
  width: auto;
  vertical-align: middle;
  margin-right: 0.125em;
}

.sku-prefix {
  opacity: 0.6;
}

.sku-pill.barcode-pill {
  background: #ddd;
}

.sku-stack.expanded .sku-pill {
  background: #fff;
  border: 1px solid #ccc;
  font-size: 12px;
}

.sku-stack.expanded .sku-pill.barcode-pill {
  background: #ddd;
  border: 1px solid #bbb;
  font-size: 12px;
}

.weight-pill {
  font-size: 12px;
  color: #000000;
  background: #fff; /* Standard background (white) for KG/M3 */
  border: 0px solid #ccc;
  border-radius: var(--pill-radius); /* USING VARIABLE */
  padding: 2px 8px;
  width: fit-content;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
}

.weight-stack.expanded .weight-pill {
  background: #fff;
  border: 1px solid #ccc;
  font-size: 12px;
}

/* NEW: Specific styles for L, W, H pills (dim-pill class) */
.weight-pill.dim-pill {
  background: #ddd;
}

.weight-stack.expanded .weight-pill.dim-pill {
  background: #ddd;
  border: 1px solid #bbb;
}

.main-sku-pill,
.main-weight-pill {
  cursor: pointer;
}

.sku-stack.expanded .main-sku-pill {
  display: none;
}

.weight-stack.expanded .main-weight-pill {
  display: none;
}

.tier-label {
  font-family: 'Roboto Mono', monospace;
  display: inline-block;
  width: 1.2ch;
  text-align: right;
  margin-right: var(--pill-gap);
  /* UPDATED: Subtle white color */
  color: var(--subtle-white);
}

.price-stack:not(.expanded) .tier-label,
.price-stack:not(.expanded) .postfix {
  display: none;
}

.price-pill .postfix {
  margin-left: var(--pill-gap);
  /* UPDATED: Subtle white color */
  color: var(--subtle-white);
}

.price-pill .postfix .sep {
  display: inline-block;
  width: var(--pill-gap);
}

.upper-prices {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.price-stack.expanded .upper-prices,
.sku-stack.expanded .upper-prices {
  max-height: 200px;
  opacity: 1;
}

.upper-weights {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-end;
}

.weight-stack.expanded .upper-weights {
  max-height: 120px;
  opacity: 1;
  max-height: 200px;
}

.img-ctas {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: inline-flex;
  gap: 8px;
  z-index: 1;
}

.img-cta {
  appearance: none;
  height: var(--pill-h);
  padding: 0 8px;
  border-radius: var(--pill-radius); /* USING VARIABLE */
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  border: none;
  background: rgba(255, 255, 255, 0.88);
  color: #000000;
  text-decoration: none;
  cursor: pointer;
  transition: transform .15s ease, background .15s ease;
  box-shadow: var(--shadow);
  backdrop-filter: blur(2px);
}

.view-btn-overlay {
  position: absolute;
  bottom: 10px;
  right: 10px;
  background: #dc2626;
  color: white;
  border: none;
  padding: 6px 16px;
  border-radius: 4px;
  font-weight: 600;
  cursor: pointer;
  z-index: 2;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.content {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px;
}

.title-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
}

.title-row .name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.name {
  font-family: 'Roboto Condensed', sans-serif;
  font-weight: 700;
  font-size: 16px;
  line-height: 1.25;
}

.code {
  font-family: 'Roboto Mono', monospace;
  color: #000000;
  background: #eee;
  border: 1px solid #d1d1d1;
  padding: 3px 5px;
  width: fit-content;
  border-radius: var(--pill-radius); /* USING VARIABLE */
  font-size: 10px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.models {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
}

.model-tag {
  font-size: 10px;
  color: #b91c1c;
  background: #fee2e2;
  border: 1px solid #fecaca;
  border-radius: var(--pill-radius); /* USING VARIABLE */
  padding: 3px 5px;
  width: fit-content;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.type-badge {
  background: #fee2e2;
  color: #b91c1c;
  border-color: #fecaca;
  font-weight: 400;
  text-transform: uppercase;
}

.tag-pill {
  background: #f3f4f6;
  color: #4b5563;
}

.attrs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
  margin-bottom: 2px;
}

.attr-pill {
  font-size: 10px;
  color: #000000;
  background: #eee;
  border: 1px solid #d1d1d1;
  border-radius: var(--pill-radius); /* USING VARIABLE */
  padding: 3px 5px;
  width: fit-content;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  text-transform: uppercase;
}

.attr-pill .pill-icon {
  width: 12px;
  height: 12px;
  margin-right: 4px;
  display: block;
}

.desc {
  font-family: 'Roboto Condensed', sans-serif;
  color: #333;
  font-size: 14px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.empty {
  display: none;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  margin: 24px 0;
}

.empty.active {
  display: block;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background: rgba(5, 5, 5, 0.6);
  padding: 12px;
  opacity: 0;
  visibility: hidden;
  transition: opacity .18s ease, visibility .18s ease;
}

.modal.open {
  opacity: 1;
  visibility: visible;
}

.modal .panel {
  box-sizing: border-box;
  width: min(960px, calc(100vw - 24px));
  height: min(92vh, calc(100vh - 24px));
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

.modal .panel iframe {
  width: 100%;
  height: auto;
  flex: 1;
  border: 0;
  display: block;
}

.modal-content-scroll {
  padding: 20px;
  overflow-y: auto;
  height: auto;
  flex: 1;
  background: transparent;
  display: none;
}

.recipe-body {
  max-width: 800px;
  margin: 0 auto;
  font-family: var(--recipe-font);
  line-height: var(--recipe-spacing);
  font-size: var(--recipe-size);
  color: var(--text);
}

/* Remove top margin from the very first element */
.recipe-body > :first-child {
  margin-top: 0 !important;
}

.recipe-body h1, .recipe-body h2, .recipe-body h3 { 
  margin-top: 1.2em; 
  margin-bottom: 0.5em; 
  color: var(--text); 
  font-weight: 700;
  line-height: 1.3;
}
.recipe-body h1 { font-size: 2.2em; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
.recipe-body h2 { font-size: 1.8em; }
.recipe-body h3 { font-size: 1.4em; }

.recipe-body p { margin-bottom: 0.8em; }

.recipe-body ul, .recipe-body ol { margin-bottom: 1em; padding-left: 2em; }
.recipe-body li { margin-bottom: 0; }
.recipe-body li p { margin-bottom: 0; }

.recipe-body img { max-width: 100%; height: auto; border-radius: 8px; margin: 1.5em 0; display: block; }
.recipe-body hr { border: 0; height: 1px; background: var(--border); margin: 2em 0; }
.recipe-body strong { font-weight: 700; }
.recipe-body em { font-style: italic; }

.recipe-body code { background: #f4f4f4; padding: 2px 5px; border-radius: 3px; font-family: 'Roboto Mono', monospace; font-size: 0.9em; color: #333; }
.recipe-body pre { background: #f4f4f4; padding: 15px; border-radius: 5px; overflow-x: auto; margin-bottom: 1em; }
.recipe-body blockquote { border-left: 4px solid #ddd; padding-left: 15px; color: #666; margin: 1em 0; }

/* Table Styling */
.recipe-body table {
  border-collapse: collapse;
  width: 100%;
  margin-bottom: 1em;
}
.recipe-body th, .recipe-body td {
  border: 1px solid #ddd;
  padding: 8px 12px;
  text-align: left;
}
.recipe-body th {
  background-color: #f8f9fa;
  font-weight: bold;
  color: #333;
}
.recipe-body tr:nth-child(even) {
  background-color: #f9f9f9;
}

.modal-header {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-family: 'Roboto Condensed', sans-serif;
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.close-btn {
  position: absolute;
  right: 16px;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  padding: 0 8px;
  color: var(--text);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-header-bar {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 20;
  display: flex;
  justify-content: flex-end;
  padding: 8px 12px;
  pointer-events: none;
}

.modal-close-x {
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s ease;
  pointer-events: auto;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  backdrop-filter: blur(4px);
}

.mobile-close-btn {
  display: none;
}

@media (max-width: 640px) {
  .mobile-close-btn {
    display: block;
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #fff;
    color: #000;
    border: 1px solid #ddd;
    padding: 12px 32px;
    border-radius: 30px;
    font-family: 'Roboto Condensed', sans-serif;
    font-weight: 700;
    font-size: 16px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    z-index: 100;
    cursor: pointer;
    transition: transform 0.1s;
  }
  .mobile-close-btn:active {
    transform: translateX(-50%) scale(0.96);
  }
  .modal-content-scroll {
    padding-bottom: 80px;
  }
}

.modal-body {
  flex: 1;
  overflow: auto;
  padding: 16px;
}

@media (max-width: 640px) {
  .modal {
    padding: 10px;
  }
  .modal .panel {
    width: calc(100vw - 20px);
    height: calc(100vh - 20px);
    border-radius: 10px;
  }
}

body.modal-open {
  overflow: hidden;
}

body[data-view="list"] .grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

body[data-view="list"] .card {
  flex-direction: row;
  align-items: stretch;
  min-width: 400px;
}

body[data-view="list"] .media {
  flex: 0 0 220px;
  width: 220px;
  aspect-ratio: 3 / 2;
  border-right: 1px solid var(--border);
  transform: translate3d(0, 0, 0);
  will-change: transform;
}

body[data-view="list"] .slide,
body[data-view="list"] .media img:not(.slide) {
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  image-rendering: auto;
}

body[data-view="list"] .content {
  padding: 12px 14px;
  gap: 6px;
  justify-content: center;
}

body[data-view="list"] .desc {
  display: block;
}

body[data-view="list"] .title-row {
  display: none;
} /* Overridden below */

/* --- FIXED LIST VIEW LAYOUT --- */
/* In list view, turn the title-row into a flex row (Name + Code side-by-side) */
body[data-view="list"] .title-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  grid-template-columns: none;
}

/* Let the name flow normally in list view, not constrained by grid */
body[data-view="list"] .title-row .name {
  min-width: 0;
  flex: 0 1 auto;
  overflow: visible;
  white-space: normal;
}

/* ------------------------------ */

.back-to-top {
  position: fixed;
  right: calc(var(--side-pad) + 10px);
  bottom: 10px;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  border: 1px solid #bbb;
  background: #fff;
  color: #0f172a;
  box-shadow: var(--shadow);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transform: translateY(8px) scale(0.96);
  visibility: hidden;
  transition: opacity .2s, transform .2s, visibility .2s;
  z-index: 990;
  pointer-events: none;
  touch-action: manipulation;
}

body:not(.full-width) .back-to-top {
  right: max( calc(var(--side-pad) + 10px), calc((100vw - var(--maxw)) / 2 + var(--side-pad) + 10px) );
}

.back-to-top.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  visibility: visible;
  pointer-events: auto;
}

.back-to-top:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.back-to-top svg {
  width: 18px;
  height: 18px;
}

.supplier-pill a,
.material-pill a,
.desc a,
.model-tag a,
.link-email,
.link-phone {
  color: var(--text);
  text-decoration: none;
}

.supplier-pill a:hover,
.material-pill a:hover,
.desc a:hover,
.model-tag a:hover,
.link-email:hover,
.link-phone:hover {
  color: var(--text);
  text-decoration: underline;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.8);
  color: white;
  padding: 12px 20px;
  border-radius: 6px;
  z-index: 10000;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toast.show {
  opacity: 1;
}

.sku-stack.expanded .sku-pill,
.price-stack.expanded .price-pill,
.weight-stack.expanded .weight-pill {
  cursor: pointer;
}

/* NEW: Hide tier label and postfix for custom text pills */
.price-pill.text-pill .tier-label,
.price-pill.text-pill .postfix {
  display: none !important;
}

.price-pill.text-pill {
  justify-content: flex-start;
  font-weight: 400;
  padding-left: 10px;
}

/* Fallback text inside .media when no image is visible */
.media {
  position: relative; /* already set, but harmless to repeat */
}

.media .media-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 50px;
  text-align: center;
  color: #bbb;
  font-family: 'Roboto Condensed', sans-serif;
  font-weight: 700;
  line-height: 1.2;
  font-size: 20px;
  z-index: 1;
  pointer-events: none;
  word-break: break-word;
}

/* Instantly hide fallback text when we know images exist – no flash possible */
.media[data-has-images] .media-fallback {
  display: none !important;
}

#settingsModal .panel {
  width: min(250px, calc(100vw - 24px));
  height: auto;
}

.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 0;
}

.settings-item label {
  font-size: 16px;
  font-family: 'Roboto Condensed', sans-serif;
}

.toggle {
  display: flex;
  gap: 0;
}

.toggle-btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  font-family: 'Roboto Condensed', sans-serif;
}

.toggle-btn.active {
  background: var(--accent);
  color: #fff;
}

.toggle-btn:first-child {
  border-radius: var(--radius) 0 0 var(--radius);
  border-right: none;
}

.toggle-btn:last-child {
  border-radius: 0 var(--radius) var(--radius) 0;
}

/* Settings Controls */
.settings-select {
  padding: 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  font-family: 'Roboto Condensed', sans-serif;
  font-size: 14px;
  cursor: pointer;
  width: 120px;
  text-align: center;
  text-align-last: center;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0,0,0,0.05);
  padding: 4px;
  border-radius: 4px;
}

.secondary-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ddd;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  color: #333;
  font-weight: bold;
}
.secondary-btn:hover {
  opacity: 0.8;
}

.setting-val {
  font-family: 'Roboto Mono', monospace;
  font-size: 13px;
  min-width: 40px;
  text-align: center;
}

/* Dark Mode Overrides */
body.dark-mode {
  --bg: #18181b;
  --card-bg: #27272a;
  --text: #f4f4f5;
  --muted: #a1a1aa;
  --accent: #dc2626;
  --border: #3f3f46;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  --subtle-white: rgba(255, 255, 255, 0.6);
  background: var(--bg);
  color: var(--text);
}

/* Scrollbars */
body.dark-mode ::-webkit-scrollbar-track {
  background: var(--bg);
}
body.dark-mode ::-webkit-scrollbar-thumb {
  background: var(--border);
}
body.dark-mode ::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

/* UI Elements */
body.dark-mode .search-wrap,
body.dark-mode .sort-select,
body.dark-mode .view-btn,
body.dark-mode .settings-btn,
body.dark-mode .toggle-btn,
body.dark-mode .settings-select,
body.dark-mode .back-to-top,
body.dark-mode .modal .panel,
body.dark-mode .search {
  background: var(--card-bg);
  color: var(--text);
  border-color: var(--border);
}

body.dark-mode .view-btn[aria-pressed="true"],
body.dark-mode #fullWidthBtn[aria-pressed="true"] {
  background: #7f1d1d;
  color: #fca5a5;
  border-color: #991b1b;
}

body.dark-mode .search input {
  color: var(--text);
}

/* Category Chips */
body.dark-mode .cat-chip {
  background: #3f3f46;
  color: #f4f4f5;
  border-color: #52525b;
}
body.dark-mode .cat-chip.active {
  background: #7f1d1d;
  color: #fca5a5;
  border-color: #991b1b;
}

/* Cards & Media */
body.dark-mode .card {
  border-color: var(--border);
}
body.dark-mode .media,
body.dark-mode .media-emoji {
  background: #09090b;
}

/* Pills - Consistent Hierarchy */
/* Standard pills (SKU, Weight) blend with card in light mode, so match card in dark mode */
body.dark-mode .sku-pill,
body.dark-mode .weight-pill {
  background: var(--card-bg);
  color: var(--text);
  border-color: var(--border);
}

/* Grey pills (Barcode, Dim, Attr, Code) are darker in light mode, so lighter/distinct in dark mode */
body.dark-mode .sku-pill.barcode-pill,
body.dark-mode .weight-pill.dim-pill,
body.dark-mode .attr-pill,
body.dark-mode .code {
  background: #3f3f46;
  color: #f4f4f5;
  border-color: #52525b;
}

/* Expanded Stacks */
body.dark-mode .sku-stack.expanded .sku-pill,
body.dark-mode .weight-stack.expanded .weight-pill {
  background: var(--card-bg);
  border-color: var(--border);
}
body.dark-mode .sku-stack.expanded .sku-pill.barcode-pill,
body.dark-mode .weight-stack.expanded .weight-pill.dim-pill {
  background: #3f3f46;
  border-color: #52525b;
}

/* Model Tags */
body.dark-mode .model-tag,
body.dark-mode .type-badge {
  background: #7f1d1d;
  color: #fca5a5;
  border-color: #991b1b;
}

/* Dark Mode Recipe Body */
body.dark-mode .recipe-body code {
  background: #3f3f46;
  color: #f4f4f5;
}
body.dark-mode .recipe-body pre {
  background: #3f3f46;
}
body.dark-mode .recipe-body blockquote {
  border-color: #555;
  color: #aaa;
}
body.dark-mode .recipe-body th, body.dark-mode .recipe-body td {
  border-color: #555;
}
body.dark-mode .recipe-body th {
  background-color: #27272a;
  color: #fff;
}
body.dark-mode .recipe-body tr:nth-child(even) {
  background-color: #18181b;
}

/* Description & Links */
body.dark-mode .desc {
  color: #d4d4d8;
}
body.dark-mode a {
  color: #f4f4f5;
}
body.dark-mode .supplier-pill a:hover, 
body.dark-mode .material-pill a:hover, 
body.dark-mode .desc a:hover, 
body.dark-mode .model-tag a:hover {
  color: #fff;
}

/* Toggle Buttons */
body.dark-mode .toggle-btn.active {
  background: var(--accent);
  color: #fff;
}

body.dark-mode .control-group {
  background: rgba(255,255,255,0.1);
}
body.dark-mode .secondary-btn {
  background: #555;
  color: #fff;
}

/* Image CTAs */
body.dark-mode .img-cta {
  background: rgba(39, 39, 42, 0.9);
  color: #f4f4f5;
}
body.dark-mode .img-cta img {
  filter: invert(1);
}

/* Search Scope */
body.dark-mode .search-scope {
  background: #3f3f46;
  color: #f4f4f5;
  border-color: #52525b;
}
body.dark-mode .search-scope:hover {
  color: transparent;
}
body.dark-mode .search-scope:hover::after {
  color: #fff;
}

body.dark-mode .modal-close-x {
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
}

body.dark-mode .mobile-close-btn {
  background: #27272a;
  color: #fff;
  border-color: #52525b;
}

/* Custom Sort Dropdown */
.custom-sort {
  position: relative;
  width: 90px;
  height: var(--control-h);
  font-family: 'Roboto Condensed', sans-serif;
}

.custom-sort-trigger {
  width: 100%;
  height: 100%;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 12px;
  text-align: center;
  cursor: pointer;
  font-size: 15px;
  font-family: 'Roboto Condensed', sans-serif;
  color: #aaa;
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

body.dark-mode .custom-sort-trigger {
  background: var(--card-bg);
  color: var(--text);
  border-color: var(--border);
}

.custom-sort-options {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
  display: none;
  flex-direction: column;
  z-index: 100;
  overflow: hidden;
}

body.dark-mode .custom-sort-options {
  background: var(--card-bg);
  border-color: var(--border);
}

.custom-sort.open .custom-sort-options {
  display: flex;
}

.custom-sort-item {
  padding: 6px 0px;
  cursor: pointer;
  font-size: 15px;
  color: var(--text);
  text-align: center;
  transition: background 0.15s;
}

.custom-sort-item.selected {
  background: #fee2e2;
  color: #b91c1c;
}

body.dark-mode .custom-sort-item.selected {
  background: #7f1d1d;
  color: #fca5a5;
}