/* Styles for shop.html only. Shared tokens and components live in css/styles.css.
   Layout: page title row, then a 240px filter sidebar beside the results (desktop).
   Under 1024px the sidebar becomes a bottom sheet, opened by the "Filters" button above the grid
   (or the floating "Filter & sort" button once that has scrolled away). */

.shop { padding-bottom: var(--s8, 64px); }
.shop-toolbar, .shop-grid { scroll-margin-top: calc(var(--header-h, 64px) + var(--s3, 12px)); }

/* ---------- Title row ---------- */
.shop-head { padding-top: var(--s6, 24px); padding-bottom: var(--s5, 20px); }
.shop-head .crumbs { margin-bottom: var(--s3, 12px); }
.shop-head-row {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  gap: var(--s4, 16px) var(--s6, 24px);
}
.shop-head-row .shop-title { flex: 1 1 320px; min-width: 0; }

/* ---------- Search box ---------- */
.shop-search { position: relative; flex: 0 1 380px; min-width: 0; margin: 0; }
.shop-search .input {
  width: 100%;
  min-height: 44px;
  padding-left: 42px; padding-right: 44px;
  border-radius: var(--radius-pill, 999px);
  background: var(--surface);
}
.shop-search .input:focus-visible { background: var(--bg); }
.shop-search input::-webkit-search-cancel-button,
.shop-search input::-webkit-search-decoration { -webkit-appearance: none; appearance: none; }
.shop-search-icon { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.shop-search-clear {
  position: absolute; right: 2px; top: 50%; transform: translateY(-50%);
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; padding: 0;
  border: 0; border-radius: 50%;
  background: transparent; color: var(--muted);
  cursor: pointer;
}
.shop-search-clear:hover { color: var(--ink); background: var(--surface-2); }
.shop-search-clear:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.shop-search-clear[hidden] { display: none; }

/* ---------- Quick category chips (scroll sideways when they don't fit) ---------- */
.shop-cats {
  display: flex; gap: var(--s2, 8px);
  margin-top: var(--s5, 20px);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  /* room for focus rings, which would otherwise be clipped by the scroller */
  padding: 3px; margin-inline: -3px;
  scroll-padding-inline: var(--s4, 16px);
}
.shop-cats::-webkit-scrollbar { display: none; }
.shop-cats[hidden] { display: none; }
.shop-cat { flex: none; min-height: 40px; }
.shop-cat:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.shop-cat.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}
.shop-cat.is-active:hover { background: var(--ink); border-color: var(--ink); }
.shop-cat-count {
  color: var(--muted);
  font-size: var(--t-xs, 0.75rem);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}
.shop-cat.is-active .shop-cat-count { color: inherit; opacity: 0.7; }
.shop-cat.is-empty { color: var(--muted); }
.shop-title {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s2, 8px) var(--s3, 12px);
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--t-3xl, 2.25rem);
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.shop-count {
  font-family: var(--font-body);
  font-size: var(--t-md, 1rem);
  font-weight: 400;
  letter-spacing: 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------- Two-column layout ---------- */
.shop-layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: var(--s7, 32px);
  align-items: start;
}

/* ---------- Sidebar (desktop) ---------- */
.shop-filters {
  min-width: 0;
  /* room for the option hover fill, which bleeds 8px past the text column */
  padding: 0 var(--s2, 8px);
  margin: 0 calc(var(--s2, 8px) * -1);
}
.shop-sheet-head, .shop-sheet-foot, .shop-sheet-sort { display: none; }
.shop-sheet-sort { border: 0; margin: 0; padding: 0; min-width: 0; }

.shop-group { border-top: 1px solid var(--line); }
.shop-group:last-child { border-bottom: 1px solid var(--line); }
.shop-group-title {
  display: flex; align-items: center; justify-content: space-between;
  min-height: 48px;
  padding: 0;
  font-size: var(--t-sm, 0.875rem);
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.shop-group-title::-webkit-details-marker { display: none; }
.shop-group-title:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.shop-chev { color: var(--muted); transition: transform 0.18s ease; flex: none; }
.shop-group[open] > .shop-group-title .shop-chev { transform: rotate(180deg); }

.shop-options { display: grid; gap: 2px; padding-bottom: var(--s4, 16px); }
.shop-option {
  position: relative;
  display: flex; align-items: center; gap: var(--s3, 12px);
  min-height: 36px;
  padding: 0 var(--s2, 8px);
  margin: 0 calc(var(--s2, 8px) * -1);
  border-radius: var(--radius-btn, 6px);
  font-size: var(--t-sm, 0.875rem);
  color: var(--ink-2);
  cursor: pointer;
}
.shop-option:hover { background: var(--surface); color: var(--ink); }
.shop-option input {
  flex: none;
  width: 16px; height: 16px; margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
.shop-option input:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.shop-option:has(input:checked) { color: var(--ink); font-weight: 500; }
.shop-option-label { flex: 1; min-width: 0; }
.shop-option-count {
  color: var(--muted);
  font-size: var(--t-xs, 0.75rem);
  font-variant-numeric: tabular-nums;
}
.shop-option.is-empty { color: var(--muted); }
.shop-option.is-empty .shop-option-label { opacity: 0.6; }

/* ---------- Toolbar: active chips + sort ---------- */
.shop-toolbar {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  gap: var(--s3, 12px) var(--s5, 24px);
  min-height: 40px;
  margin-bottom: var(--s5, 24px);
}
.shop-filter-btn { display: none; }
.shop-active { order: -1; flex: 1 1 0; display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2, 8px); min-width: 0; }
.shop-active[hidden] { display: none; }
.shop-active .chip { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.shop-clear { font-size: var(--t-sm, 0.875rem); }
.shop-sort { display: flex; align-items: center; gap: var(--s2, 8px); margin-left: auto; }
.shop-sort label { font-size: var(--t-sm, 0.875rem); color: var(--muted); white-space: nowrap; }
.shop-sort .select { width: auto; min-width: 190px; }

.shop-note {
  margin-top: var(--s6, 24px);
  font-size: var(--t-xs, 0.75rem);
  color: var(--muted);
}

/* ---------- Empty state ---------- */
.shop-grid.is-empty { display: block; }
/* Layout comes from the shared .empty-state; this only spaces the extra rows. */
.shop-empty { padding-inline: var(--s6, 24px); }
.shop-empty h2 { color: var(--ink); overflow-wrap: anywhere; }
.shop-suggest-label { margin-top: var(--s4, 16px); font-size: var(--t-sm, 0.875rem); font-weight: 600; color: var(--ink) !important; }
.shop-suggest { max-width: 520px; margin-top: 0 !important; }
.shop-suggest .chip { text-decoration: none; }
.shop-suggest .shop-option-count { margin-left: 2px; }
.shop-empty-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--s3, 12px); margin-top: var(--s4, 16px); }

/* ---------- Mobile button and scrim (hidden on desktop) ---------- */
.shop-fab { display: none; }
.shop-scrim { display: none; }

/* ---------- Tablet and phone: bottom sheet ---------- */
@media (max-width: 1023px) {
  .shop-layout { grid-template-columns: minmax(0, 1fr); gap: 0; }
  /* Toolbar: [Filters (n)] [Sort ▾] side by side, active filter chips below */
  .shop-toolbar {
    display: grid; grid-template-columns: auto minmax(0, 1fr);
    gap: var(--s3, 12px);
    min-height: 0;
    margin-bottom: var(--s4, 16px);
  }
  .shop-filter-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--s2, 8px);
    min-height: 48px; padding: 0 var(--s4, 16px);
    font-weight: 600;
  }
  .shop-sort { margin-left: 0; min-width: 0; justify-content: flex-end; }
  .shop-sort .select { min-width: 0; width: 100%; max-width: 260px; min-height: 48px; }
  .shop-active {
    order: 0; grid-column: 1 / -1;
    flex-wrap: nowrap;
    overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none;
    padding: 3px; margin: -3px;
  }
  .shop-active::-webkit-scrollbar { display: none; }
  .shop-active .chip { flex: none; max-width: 70vw; }
  .shop-active .shop-clear { flex: none; min-height: 40px; }

  .shop-fab {
    position: fixed;
    left: 50%;
    bottom: calc(var(--s4, 16px) + env(safe-area-inset-bottom, 0px));
    z-index: var(--z-fab);
    transform: translateX(-50%);
    display: inline-flex; align-items: center; gap: var(--s2, 8px);
    min-height: 48px;
    padding: 0 var(--s5, 20px);
    border: 0;
    border-radius: var(--radius-btn, 6px);
    background: var(--ink);
    color: var(--bg);
    font: 600 var(--t-sm, 0.875rem)/1 var(--font-body);
    box-shadow: 0 6px 20px rgb(0 0 0 / 0.18);
    cursor: pointer;
    /* hidden until the in-page Filters button scrolls away (js adds .is-shown) */
    opacity: 0; visibility: hidden;
    translate: 0 12px;
    transition: opacity 0.2s ease, translate 0.2s ease, visibility 0s linear 0.2s;
  }
  .shop-fab.is-shown { opacity: 1; visibility: visible; translate: 0 0; transition: opacity 0.2s ease, translate 0.2s ease, visibility 0s; }
  .shop-fab:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
  .shop-fab-count {
    display: inline-grid; place-items: center;
    min-width: 20px; height: 20px; padding: 0 6px;
    border-radius: 999px;
    background: var(--accent);
    color: var(--on-accent);
    font-size: var(--t-xs, 0.75rem);
    font-variant-numeric: tabular-nums;
  }
  .shop-fab-count[hidden] { display: none; }
  html.shop-locked .shop-fab { visibility: hidden; }
  /* Toasts sit above the floating button (16px gap + 48px button + 12px). */
  body:has(.shop-fab.is-shown) { --toast-lift: 76px; }
  /* No category strip on this page here, so don't reserve room for it. */
  body[data-page="shop"] #site-header:empty { margin-bottom: 0; }
  html.shop-locked { overflow: hidden; }

  .shop-scrim {
    display: block;
    position: fixed; inset: 0; z-index: var(--z-scrim);
    background: rgb(0 0 0 / 0.45);
  }
  .shop-scrim[hidden] { display: none; }

  .shop-filters {
    position: fixed;
    left: 0; right: 0; bottom: 0; top: auto;
    z-index: var(--z-sheet);
    display: flex; flex-direction: column;
    max-height: 88vh; max-height: 88dvh;
    padding: 0;
    margin: 0;
    overflow: hidden;
    background: var(--bg);
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -8px 32px rgb(0 0 0 / 0.2);
    transform: translateY(100%);
    visibility: hidden;
    transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s linear 0.28s;
  }
  .shop-filters.is-open {
    transform: none;
    visibility: visible;
    transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s;
  }
  .shop-sheet-head {
    position: relative;
    display: flex; align-items: center; justify-content: space-between;
    padding: var(--s4, 16px) var(--s2, 8px) var(--s2, 8px) var(--s5, 20px);
    border-bottom: 1px solid var(--line);
    touch-action: none;
  }
  .shop-sheet-grab {
    position: absolute; top: 6px; left: 50%; transform: translateX(-50%);
    width: 40px; height: 4px; border-radius: 999px;
    background: var(--line-strong, var(--line));
  }
  .shop-filters-title { margin: 0; font-family: var(--font-display); font-size: var(--t-lg, 1.125rem); color: var(--ink); }
  .shop-sheet-close { min-width: 44px; min-height: 44px; padding: 0; display: inline-grid; place-items: center; }
  .shop-sheet-body {
    flex: 1; min-height: 0;
    overflow-y: auto; overscroll-behavior: contain;
    padding: var(--s2, 8px) var(--s5, 20px) var(--s5, 20px);
  }
  .shop-sheet-sort { display: block; padding-bottom: var(--s2, 8px); }
  .shop-sheet-sort .shop-group-title { cursor: default; padding: 0; }
  .shop-sheet-sort .shop-options { padding-bottom: var(--s3, 12px); }
  .shop-option { min-height: 44px; font-size: var(--t-md, 1rem); }
  .shop-option input { width: 20px; height: 20px; }
  /* Sort choices as a compact 2 x 2 set of pills, so the filters start higher up the sheet */
  .shop-sheet-sort .shop-options { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s2, 8px); }
  .shop-sheet-sort .shop-option {
    justify-content: center;
    margin: 0; padding: 0 var(--s2, 8px);
    border: 1px solid var(--line-strong, var(--line));
    border-radius: var(--radius-pill, 999px);
    font-size: var(--t-sm, 0.875rem);
    text-align: center;
  }
  .shop-sheet-sort .shop-option-label { flex: none; }
  .shop-sheet-sort .shop-option input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; margin: 0; }
  .shop-sheet-sort .shop-option:has(input:checked) { background: var(--ink); border-color: var(--ink); color: var(--bg); }
  .shop-sheet-sort .shop-option:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
  .shop-group:last-child { border-bottom: 0; }
  .shop-sheet-foot {
    display: grid; grid-template-columns: auto 1fr; gap: var(--s3, 12px);
    padding: var(--s3, 12px) var(--s5, 20px) calc(var(--s3, 12px) + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--line);
    background: var(--bg);
  }
  .shop-sheet-foot .btn { min-height: 48px; }

  .shop-empty { padding: var(--s7, 32px) 0; }
  .shop { padding-bottom: calc(var(--s9, 96px) + env(safe-area-inset-bottom, 0px)); }
}

@media (max-width: 767px) {
  .shop-head { padding-top: var(--s4, 16px); padding-bottom: var(--s4, 16px); }
  .shop-title { font-size: var(--t-2xl, 1.75rem); }
  .shop-head-row { gap: var(--s3, 12px); }
  .shop-head-row .shop-title { flex-basis: 100%; }
  .shop-search { flex: 1 1 100%; }
  /* 16px+ text so iOS doesn't zoom in on focus */
  .shop-search .input { min-height: 48px; font-size: max(16px, var(--t-md, 1rem)); }
  .shop-search-clear { width: 44px; height: 44px; }
  /* chips run edge to edge and scroll sideways */
  .shop-cats {
    margin-top: var(--s4, 16px);
    margin-inline: calc(-1 * var(--gutter, 16px));
    padding-inline: var(--gutter, 16px);
    scroll-padding-inline: var(--gutter, 16px);
  }
  .shop-cat { min-height: 44px; }
  .shop-sort .select { max-width: none; }
  .shop-sort-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .shop-count { font-size: var(--t-sm, 0.875rem); }
  .shop-empty h2 { font-size: var(--t-xl, 1.375rem); }
}

@media (prefers-reduced-motion: reduce) {
  .shop-filters, .shop-filters.is-open, .shop-chev, .shop-fab, .shop-fab.is-shown { transition: none; }
}

/* Wide screens already have the header search box (900px+) and the category sidebar (1024px+),
   so the in-page search and quick chips would only repeat them. */
@media (min-width: 900px) {
  .shop-search { display: none; }
}
@media (min-width: 1024px) {
  .shop-cats { display: none; }
}

/* The shop has its own category chips (with counts) under 1024px, so hide the header strip there to avoid two rows. */
@media (max-width: 1023px) { body[data-page="shop"] .cat-strip { display: none; } }
