.fixed-header-wrapper {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 950;
  background-image: url('../media/back.jpg');
  background-color: #333;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
  padding-bottom: 15px;
  transition: top 0.3s ease-in-out;
}

.header-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  max-width: 1360px;
  margin: 0 auto;
  padding: 12px 20px;
  background: rgba(23, 19, 16, 0.82);
  border-top: 1px solid var(--brass);
  border-radius: 10px;
}

.search-group {
  display: contents;
}

.input-wrapper {
  position: relative;
  display: flex;
}

.header-controls input[type='text'] {
  padding: 9px 12px;
  width: 280px;
  border-radius: 6px;
  border: 1px solid var(--mist);
  background: var(--parchment);
  color: var(--ink);
}

.header-controls input[type='text']:focus {
  outline: none;
  border-color: var(--brass);
  box-shadow: 0 0 0 2px rgba(175, 121, 11, 0.25);
}

.autocomplete-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  width: 100%;
  background: var(--parchment);
  border: 1px solid var(--mist);
  border-radius: 6px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 250px;
  overflow-y: auto;
  z-index: 1000;
}

.autocomplete-list li {
  padding: 10px 12px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--ink);
  border-bottom: 1px solid var(--mist);
  text-align: left;
}

.autocomplete-list li:hover,
.autocomplete-list li.active {
  background-color: #fff;
  color: var(--shop-green);
  font-weight: bold;
}

.autocomplete-list li:last-child {
  border-bottom: none;
}

/* Shared shape of every control-bar button: add a selector here rather than
   redeclaring sizes elsewhere. */
.header-controls button,
.header-controls select,
.mass-filters button,
.mass-filters select,
.mass-progress-bar button,
.mass-filter-threshold,
.sort-toggle-btn,
.header-icon-btn,
.recalculate-cart-btn,
.back-to-cards-btn,
#retrySearchBtn {
  height: 36px;
  padding: 0 16px;
  font-weight: bold;
  font-size: 0.85rem;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid var(--mist);
  border-bottom: 3px solid var(--mist);
  background-color: var(--parchment);
  color: var(--ink);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition:
    border-color 0.15s ease,
    transform 0.1s ease;
}

/* Selects keep their case: options are data (set names). */
.header-controls select,
.mass-filters select {
  text-transform: none;
  letter-spacing: normal;
  padding: 0 8px;
}

.header-controls button:hover,
.header-controls select:hover,
.mass-filters button:hover,
.mass-filters select:hover,
.mass-progress-bar button:hover,
.sort-toggle-btn:hover,
.header-icon-btn:hover,
.recalculate-cart-btn:hover,
.back-to-cards-btn:hover {
  border-bottom-color: var(--brass);
  transform: translateY(-1px);
}

.header-controls button:active,
.mass-filters button:active,
.mass-progress-bar button:active,
.sort-toggle-btn:active,
.header-icon-btn:active,
.recalculate-cart-btn:active,
.back-to-cards-btn:active {
  transform: translateY(0);
}

button.icon-only-btn {
  width: 36px;
  padding: 0;
  flex-shrink: 0;
}

.icon-only-btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

#searchBtn.icon-only-btn,
.sort-toggle-btn.active,
.mass-filter-btn.active {
  background-color: var(--shop-green);
  border-color: #006600;
  border-bottom-color: #004d00;
  color: #fff;
}

#searchBtn.icon-only-btn:hover {
  background-color: #006600;
  border-bottom-color: var(--brass-light);
}

.filter-toggle-group,
.sort-toggle-group {
  display: inline-flex;
  gap: 6px;
  flex-shrink: 0;
}

.filter-toggle-btn,
.sort-toggle-btn {
  transition:
    background 0.2s ease,
    color 0.2s ease,
    border-color 0.15s ease,
    transform 0.1s ease;
}

.filter-toggle-btn {
  color: #7a6d55;
  padding: 0 12px;
  min-width: 36px;
}

.filter-toggle-btn:not(.active):hover,
.sort-toggle-btn:not(.active):hover {
  background-color: #fff;
  border-bottom-color: var(--brass);
  transform: translateY(-1px);
}

#filterRLBtn.active,
.mass-filter-rl.active {
  background-color: var(--wine) !important;
  color: white !important;
  border-color: var(--wine) !important;
}
#filterHideNotBoughtBtn.active,
#searchExactBtn.active {
  background-color: var(--brass) !important;
  color: white !important;
  border-color: var(--brass) !important;
}

.sort-toggle-btn {
  gap: 3px;
  padding: 0 10px;
  color: var(--ink);
}

.sort-toggle-btn .sort-arrow {
  font-size: 0.8rem;
}

.results-message {
  color: white;
  font-size: 1.2rem;
  text-align: center;
}

.results-message-strong {
  font-weight: bold;
}

.results-message-error {
  color: #ffcccc;
  font-size: 1.1rem;
}

.results-retry-row {
  text-align: center;
}

.skeleton-slide {
  flex: 0 0 330px;
  width: 330px;
  height: 460px;
  border-radius: 8px;
  background: linear-gradient(100deg, #88888833 40%, #aaaaaa55 50%, #88888833 60%);
  background-size: 200% 100%;
  animation: skeletonShimmer 1.4s ease infinite;
}

@keyframes skeletonShimmer {
  0% {
    background-position: 120% 0;
  }
  100% {
    background-position: -80% 0;
  }
}

#results.list-view .skeleton-slide {
  flex: 0 0 auto;
  width: 100%;
  max-width: 1000px;
  height: 72px;
}

#results {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  padding: 20px;
  justify-content: center;
  transition: all 0.3s ease;
}

#results .slide,
.mass-card .slide {
  flex: 0 0 330px;
  width: 330px;
  display: flex;
  flex-direction: column;
}

#results.list-view {
  flex-direction: column;
  align-items: center;
}

#results.list-view .slide,
.mass-batch-grid.list-view .slide {
  flex: 0 0 auto;
  width: 100%;
  max-width: 1000px;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  padding: 10px 15px;
  border-radius: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  background-color: #88888855;
}

/* List view: the wrapper dissolves so its children become flex items of the
   row, each placed by `order`. */
#results.list-view .card-tile-wrap,
.mass-batch-grid.list-view .card-tile-wrap {
  display: contents;
}

#results.list-view card-tile,
.mass-batch-grid.list-view card-tile {
  order: 1;
  flex: 0 0 50px;
  width: 50px;
  margin: 0;
}

/* position:static is required: their containing block disappeared with
   display:contents above. */
#results.list-view .hot-seal,
.mass-batch-grid.list-view .hot-seal,
#results.list-view .contact-badge,
.mass-batch-grid.list-view .contact-badge {
  position: static;
  transform: none;
}

/* On request takes the price's place at the end of the pill. */
#results.list-view .contact-badge,
.mass-batch-grid.list-view .contact-badge {
  order: 4;
  align-self: center;
  margin: 0;
  box-shadow: none;
}

#results.list-view .hot-seal,
.mass-batch-grid.list-view .hot-seal {
  order: 4;
  width: 30px;
  height: 30px;
  font-size: 0.45rem;
  align-self: center;
  flex: 0 0 auto;
}

/* Every item of the row needs an explicit `order`: the default 0 would put it
   before the thumbnail (order 1). */
#results.list-view .already-in-cart-badge,
.mass-batch-grid.list-view .already-in-cart-badge {
  order: 8;
  align-self: center;
}

#results.list-view .card-name,
.mass-batch-grid.list-view .card-name {
  order: 2;
  text-align: left;
  flex: 1;
  margin: 0;
  font-size: 1.15rem;
  white-space: normal;
}
#results.list-view .card-set-info,
.mass-batch-grid.list-view .card-set-info {
  order: 3;
  margin: 0;
  min-width: 80px;
}
#results.list-view .card-price-pill,
.mass-batch-grid.list-view .card-price-pill {
  order: 4;
  /* Undo the grid view's width:100%, which here would squeeze the name to 0px. */
  width: auto;
  flex-wrap: nowrap;
  margin: 0;
  justify-content: flex-end;
}
#results.list-view .btn-add,
.mass-batch-grid.list-view .btn-add {
  order: 5;
  width: auto;
  margin: 0;
  padding: 8px 20px;
  white-space: nowrap;
}

/* Above 768px the drawer does not exist: its container is display:contents. */
.secondary-controls {
  display: contents;
}

/* Must be at least as specific as `.header-controls button`, which sets
   display:inline-flex. */
.header-controls .filters-toggle-btn,
.mass-filters .filters-toggle-btn {
  display: none;
}

@media (max-width: 768px) {
  body.is-scrolled .fixed-header-wrapper {
    /* --header-collapse-offset is measured from JS; 180px covers the first render. */
    top: calc(-1 * var(--header-collapse-offset, 180px));
  }

  .header-controls {
    padding: 10px;
    gap: 8px;
  }

  /* The field shares its row with the search and drawer buttons: the
     suggestion list (z-index 1000) would otherwise cover the drawer button and
     swallow its taps. */
  .input-wrapper {
    flex: 1 1 120px;
    width: auto;
    min-width: 0;
    order: 2;
  }

  #searchExactBtn {
    order: 1;
  }
  #searchBtn {
    order: 3;
  }
  .header-controls .filters-toggle-btn {
    order: 4;
  }
  .header-controls .results-count {
    order: 5;
  }
  .secondary-controls.is-open {
    order: 6;
  }

  .header-controls input[type='text'] {
    width: 100%;
  }

  #results .slide {
    flex: 0 0 100%;
    max-width: 350px;
  }

  #results.list-view .slide,
  .mass-batch-grid.list-view .slide {
    flex-wrap: wrap;
    padding: 8px 12px;
    gap: 4px;
  }

  #results.list-view card-tile,
  .mass-batch-grid.list-view card-tile {
    flex-basis: 42px;
    width: 42px;
  }

  #results.list-view .card-name,
  .mass-batch-grid.list-view .card-name {
    width: calc(100% - 55px);
    flex: none;
    font-size: 0.95rem;
  }

  #results.list-view .card-price-pill,
  .mass-batch-grid.list-view .card-price-pill {
    display: contents;
  }

  /* :not(select) and :not(button) keep the bulk set selector and the pasted list's
     printing picker at touch size. */
  #results.list-view .card-set-info:not(select):not(button),
  .mass-batch-grid.list-view .card-set-info:not(select):not(button) {
    order: 3;
    width: auto;
    padding: 0;
    font-size: 0.7rem;
    font-weight: normal;
    background: none;
    color: #bbb;
    align-self: center;
  }

  #results.list-view .status-toggle,
  .mass-batch-grid.list-view .status-toggle,
  #results.list-view .card-tags,
  .mass-batch-grid.list-view .card-tags {
    order: 4;
  }

  #results.list-view .condition-select,
  .mass-batch-grid.list-view .condition-select {
    padding: 2px 4px;
    font-size: 0.8rem;
  }

  /* The row's item is the selector's wrapper, which also holds its help link: without
     `order` it would fall to 0, at the head of the row. */
  #results.list-view .condition-field,
  .mass-batch-grid.list-view .condition-field {
    order: 5;
  }

  #results.list-view .language-select,
  .mass-batch-grid.list-view .language-select {
    order: 6;
    padding: 2px 4px;
    font-size: 0.8rem;
  }

  #results.list-view .price-display,
  .mass-batch-grid.list-view .price-display {
    order: 7;
    margin-left: auto;
    align-self: center;
  }

  #results.list-view .contact-badge,
  .mass-batch-grid.list-view .contact-badge {
    order: 7;
    margin-left: auto;
  }

  /* After the in-cart badge (order 8). */
  #results.list-view .btn-add,
  .mass-batch-grid.list-view .btn-add {
    order: 11;
    width: 100%;
    margin-top: 4px;
    padding: 8px;
    font-size: 0.9rem;
  }

  .secondary-controls {
    display: none;
  }

  .secondary-controls.is-open {
    display: flex;
    flex-basis: 100%;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding-top: 4px;
  }

  .secondary-controls.is-open select {
    flex: 1 1 100%;
  }

  .header-controls .filters-toggle-btn,
  .mass-filters .filters-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    position: relative;
    padding: 0 12px;
    min-width: 44px;
    color: var(--ink);
  }

  .header-controls .filters-toggle-btn[aria-expanded='true'],
  .mass-filters .filters-toggle-btn[aria-expanded='true'] {
    background-color: var(--brass);
    color: #fff;
    border-color: var(--brass);
  }

  .filters-count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 17px;
    height: 17px;
    padding: 0 4px;
    border-radius: 9px;
    background: var(--wine);
    color: #fff;
    font-size: 0.62rem;
    line-height: 1;
  }

  .filters-count-badge[hidden] {
    display: none;
  }
}

/* Three-state foil filter: none, .foil-only, .normal-only. */
#filterFoilBtn,
.mass-filter-foil {
  background: #1a1410 !important;
  color: #f3ead8 !important;
  font-size: 1rem;
  letter-spacing: 0;
}

#filterFoilBtn.foil-only,
.mass-filter-foil.foil-only {
  background: var(--foil-gradient) !important;
  color: #5a3c00 !important;
}

#filterFoilBtn.normal-only,
.mass-filter-foil.normal-only {
  background: var(--parchment) !important;
  color: var(--ink) !important;
}

.results-count {
  font-size: 0.78rem;
  color: var(--mist);
  font-weight: 500;
  white-space: nowrap;
  align-self: center;
  padding: 0 4px;
}
