/* Product cards, catalog, PDP */
.product-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
  transition:
    box-shadow 0.2s ease,
    border-color 0.2s ease,
    transform 0.2s var(--ease-out, cubic-bezier(0.22, 1, 0.36, 1));
}

.product-card:hover {
  border-color: color-mix(in srgb, var(--color-primary) 40%, var(--color-border));
  box-shadow: var(--shadow-lift);
  transform: translateY(-2px);
}

.product-card__media {
  position: relative;
  aspect-ratio: 4 / 3;
  background: #fff;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 10px;
  overflow: hidden;
  border-bottom: 1px solid var(--color-border);
}

.product-card__img-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  min-height: 0;
  text-decoration: none;
}

.product-card__media img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: center;
}

.product-card__placeholder {
  width: 72px;
  height: 72px;
  margin: auto;
  border-radius: 50%;
  background: color-mix(in srgb, var(--color-primary) 12%, #f3f4f6);
  color: var(--color-primary-dark);
  display: flex;
  align-items: center;
  justify-content: center;
}

.product-card__marks {
  position: absolute;
  left: 8px;
  top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 1;
}

.product-card__body {
  padding: 14px 14px 16px;
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 8px;
}

.product-card__title {
  margin: 0;
  font-size: 15px;
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.3;
  color: var(--color-secondary);
}

.product-card__title a {
  color: inherit;
  text-decoration: none;
}

.product-card__title a:hover {
  color: var(--color-primary-dark);
}

.product-card__spec {
  margin: 0;
  font-size: 12px;
  line-height: 1.35;
  color: var(--color-text-muted);
}

.product-card__price {
  margin-top: auto;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  color: var(--color-primary);
  line-height: 1.2;
}

.product-card__price span {
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-muted);
}

.product-card__meta {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 12px;
  color: var(--color-text-muted);
}

.product-card__meta li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--color-border) 80%, transparent);
}

.product-card__meta li:last-child {
  border-bottom: 0;
}

.product-card__meta strong {
  color: var(--color-text);
  font-weight: 600;
  text-align: right;
}

.product-card__buy {
  margin-top: 4px;
  min-height: 40px;
  font-weight: 600;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.catalog-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.catalog-main {
  min-width: 0;
}

.facets {
  background: var(--color-surface);
  padding: 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.facets h3,
.filter-drawer__title {
  font-size: 14px;
  text-transform: uppercase;
  margin: 0 0 10px;
}

.filter-drawer__title {
  margin: 0;
}

/* ERR-107: mobile toggle in toolbar next to sort */
.filter-toggle-btn {
  display: none;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  min-height: 44px;
  padding: 8px 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.filter-toggle-btn__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 6px;
  border-radius: var(--radius-pill);
  background: var(--color-primary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
}

.catalog-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.catalog-sort {
  margin-left: auto;
}

/* Drawer chrome — visible only ≤899; desktop uses sticky sidebar */
.filter-drawer__backdrop,
.filter-drawer__header,
.filter-drawer__footer {
  display: none;
}

.filter-drawer__body {
  min-height: 0;
}

body.is-filter-drawer-open {
  overflow: hidden;
}


.facet-group {
  margin-bottom: 14px;
}

.facet-group__title {
  font-weight: 700;
  margin-bottom: 6px;
  font-size: 13px;
}

.facet-group__list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.facet-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  margin-bottom: 0;
  font-size: 13px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.facet-group:not(.is-expanded) .facet-group__list > label:nth-child(n + 6) {
  display: none;
}

.facet-group__empty {
  color: var(--color-text-muted);
  font-size: 12px;
}

.facet-group__more {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  margin-top: 4px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--color-primary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
}

.facet-group__more:hover {
  text-decoration: underline;
}

.facet-group__more:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--color-primary) 55%, transparent);
  outline-offset: 2px;
  border-radius: 2px;
}

.child-cats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.child-cats a {
  padding: 6px 10px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-size: 13px;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.child-cats a:hover {
  border-color: var(--color-primary);
  text-decoration: none;
}

.pagination {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.pagination a,
.pagination span {
  padding: 6px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
}

.pdp-hero {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  background: var(--color-surface);
  padding: 16px;
  margin-bottom: 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

.pdp-gallery {
  background: #fff;
  aspect-ratio: 4 / 3;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: hidden;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
}

.pdp-gallery img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: center;
}

.pdp-attrs {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
}

.pdp-attrs li {
  display: grid;
  grid-template-columns: 40% 1fr;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--color-border);
  font-size: 13px;
}

.pdp-attrs span {
  color: var(--color-text-muted);
}

.pdp-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  border-bottom: 2px solid var(--color-border);
  margin-bottom: 16px;
}

.pdp-tabs button {
  border: 0;
  background: transparent;
  padding: 10px 14px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14px;
  color: var(--color-text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  -webkit-appearance: none;
}

.pdp-tabs button.is-active {
  color: var(--color-primary-dark);
  border-bottom-color: var(--color-primary);
}

.pdp-panel {
  display: none;
}

.pdp-panel.is-active {
  display: block;
}

.sku-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.qty-form {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.qty-form input[type="number"] {
  width: 72px;
  min-height: 44px;
  padding: 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 16px;
  -webkit-appearance: none;
  appearance: none;
}

.sku-price-empty {
  color: var(--color-text-muted);
  font-weight: 500;
}

.sku-cell--party-price strong {
  color: var(--color-primary-dark);
}

.wishlist-form {
  flex: 0 0 auto;
  margin: 0;
}

.wishlist-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 8px;
  color: var(--color-primary);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.wishlist-btn svg {
  display: block;
  transition: fill 0.15s ease;
}

.wishlist-btn.is-active {
  color: var(--color-danger);
  border-color: currentColor;
}

.wishlist-btn.is-active svg {
  fill: currentColor;
}

.wishlist-btn--lg {
  min-width: 48px;
  min-height: 48px;
}

.wishlist-btn--lg svg {
  width: 22px;
  height: 22px;
}

.sku-article {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Desktop: таблиця на всю ширину; зайвий простір — у «Назва», не справа від кнопок */
@media (min-width: 768px) {
  .data-table--sku {
    width: 100%;
    min-width: 1040px;
    table-layout: auto;
  }

  .data-table--sku th:nth-child(2),
  .data-table--sku td:nth-child(2) {
    width: 99%;
  }

  .data-table--sku th:last-child,
  .data-table--sku td.sku-cell--actions {
    width: 1%;
    white-space: nowrap;
    padding-left: 10px;
  }

  .data-table--sku .sku-actions {
    display: inline-flex;
    flex-wrap: nowrap;
    width: auto;
    max-width: none;
    vertical-align: middle;
  }

  .data-table--sku .sku-cell--actions .qty-form {
    display: inline-flex;
    flex-wrap: nowrap;
    width: auto;
  }
}

/* Mobile / tablet portrait: рядок → картка */
@media (max-width: 767px) {
  .table-wrap--sku {
    overflow: visible;
    margin: 0 -4px;
  }

  .data-table--sku {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: transparent;
  }

  .data-table--sku thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .data-table--sku tbody {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .data-table--sku tr {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin: 0;
    padding: 12px 14px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
  }

  .data-table--sku tr.is-highlight {
    border-color: color-mix(in srgb, var(--color-accent) 55%, var(--color-border));
    background: color-mix(in srgb, var(--color-accent) 14%, #fff);
  }

  .data-table--sku td {
    display: grid;
    grid-template-columns: minmax(96px, 34%) minmax(0, 1fr);
    align-items: start;
    gap: 8px 12px;
    width: 100%;
    margin: 0;
    padding: 8px 0;
    border: 0;
    border-bottom: 1px solid color-mix(in srgb, var(--color-border) 70%, transparent);
    font-size: 14px;
    line-height: 1.4;
    overflow-wrap: anywhere;
    word-break: break-word;
    -webkit-hyphens: auto;
    hyphens: auto;
  }

  .data-table--sku td:last-child {
    border-bottom: 0;
    padding-bottom: 0;
  }

  .data-table--sku td::before {
    content: attr(data-label);
    color: var(--color-text-muted);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.35;
    padding-top: 2px;
  }

  .data-table--sku td:not([data-label])::before,
  .data-table--sku td[data-label=""]::before {
    display: none;
  }

  .data-table--sku td[data-label=""] {
    grid-template-columns: 1fr;
    padding-top: 12px;
  }

  /* Порядок: розмір → ціна баз → ціна пар → наявність → артикул → назва → партія → дії */
  .data-table--sku td:nth-child(1) { order: 5; }
  .data-table--sku td:nth-child(2) { order: 6; }
  .data-table--sku td:nth-child(3) { order: 1; }
  .data-table--sku td:nth-child(4) { order: 7; }
  .data-table--sku td:nth-child(5) { order: 4; }
  .data-table--sku td:nth-child(6) { order: 2; }
  .data-table--sku td:nth-child(7) { order: 3; }
  .data-table--sku td:nth-child(8) { order: 8; }

  /* Підшипники: d → D → B → ціни → наявність → артикул → назва → партія → дії */
  .data-table--sku-bearing td:nth-child(1) { order: 7; }
  .data-table--sku-bearing td:nth-child(2) { order: 8; }
  .data-table--sku-bearing td:nth-child(3) { order: 1; }
  .data-table--sku-bearing td:nth-child(4) { order: 2; }
  .data-table--sku-bearing td:nth-child(5) { order: 3; }
  .data-table--sku-bearing td:nth-child(6) { order: 9; }
  .data-table--sku-bearing td:nth-child(7) { order: 6; }
  .data-table--sku-bearing td:nth-child(8) { order: 4; }
  .data-table--sku-bearing td:nth-child(9) { order: 5; }
  .data-table--sku-bearing td:nth-child(10) { order: 10; }

  .data-table--sku-auto td:nth-child(1) { order: 7; }
  .data-table--sku-auto td:nth-child(2) { order: 8; }
  .data-table--sku-auto td:nth-child(3) { order: 1; }
  .data-table--sku-auto td:nth-child(4) { order: 2; }
  .data-table--sku-auto td:nth-child(5) { order: 3; }
  .data-table--sku-auto td:nth-child(6) { order: 9; }
  .data-table--sku-auto td:nth-child(7) { order: 6; }
  .data-table--sku-auto td:nth-child(8) { order: 4; }
  .data-table--sku-auto td:nth-child(9) { order: 5; }
  .data-table--sku-auto td:nth-child(10) { order: 10; }

  .data-table--sku-mesh td:nth-child(1) { order: 6; }
  .data-table--sku-mesh td:nth-child(2) { order: 7; }
  .data-table--sku-mesh td:nth-child(3) { order: 1; }
  .data-table--sku-mesh td:nth-child(4) { order: 2; }
  .data-table--sku-mesh td:nth-child(5) { order: 8; }
  .data-table--sku-mesh td:nth-child(6) { order: 5; }
  .data-table--sku-mesh td:nth-child(7) { order: 3; }
  .data-table--sku-mesh td:nth-child(8) { order: 4; }
  .data-table--sku-mesh td:nth-child(9) { order: 9; }

  .data-table--sku-rebar td:nth-child(1) { order: 5; }
  .data-table--sku-rebar td:nth-child(2) { order: 6; }
  .data-table--sku-rebar td:nth-child(3) { order: 1; }
  .data-table--sku-rebar td:nth-child(4) { order: 7; }
  .data-table--sku-rebar td:nth-child(5) { order: 4; }
  .data-table--sku-rebar td:nth-child(6) { order: 2; }
  .data-table--sku-rebar td:nth-child(7) { order: 3; }
  .data-table--sku-rebar td:nth-child(8) { order: 8; }

  .data-table--sku-chem td:nth-child(1) { order: 8; }
  .data-table--sku-chem td:nth-child(2) { order: 9; }
  .data-table--sku-chem td:nth-child(3) { order: 1; }
  .data-table--sku-chem td:nth-child(4) { order: 2; }
  .data-table--sku-chem td:nth-child(5) { order: 3; }
  .data-table--sku-chem td:nth-child(6) { order: 4; }
  .data-table--sku-chem td:nth-child(7) { order: 10; }
  .data-table--sku-chem td:nth-child(8) { order: 7; }
  .data-table--sku-chem td:nth-child(9) { order: 5; }
  .data-table--sku-chem td:nth-child(10) { order: 6; }
  .data-table--sku-chem td:nth-child(11) { order: 11; }

  .data-table--sku .sku-cell--size,
  .data-table--sku .sku-cell--bearing-dim,
  .data-table--sku .sku-cell--auto-dim,
  .data-table--sku .sku-cell--mesh-dim,
  .data-table--sku .sku-cell--rebar-dim,
  .data-table--sku .sku-cell--chem-dim {
    font-size: 17px;
    padding-top: 0;
  }

  .data-table--sku .sku-cell--size strong,
  .data-table--sku .sku-cell--bearing-dim strong,
  .data-table--sku .sku-cell--auto-dim strong,
  .data-table--sku .sku-cell--mesh-dim strong,
  .data-table--sku .sku-cell--rebar-dim strong,
  .data-table--sku .sku-cell--chem-dim strong {
    font-family: var(--font-display);
    font-size: 1.15em;
    letter-spacing: 0.01em;
  }

  .sku-price-unit {
    display: block;
    font-size: 12px;
    font-weight: 400;
    color: var(--color-text-muted);
    margin-top: 2px;
  }

  .data-table--sku .sku-cell--price strong {
    font-family: var(--font-display);
    font-size: 18px;
    color: var(--color-primary-dark);
  }

  .data-table--sku .sku-actions {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr) auto;
    align-items: stretch;
    gap: 6px;
    width: 100%;
  }

  .data-table--sku .sku-cell--actions .qty-form,
  .data-table--sku .wishlist-form {
    display: contents;
    margin: 0;
  }

  .data-table--sku .sku-cell--actions .qty-form input[type="number"] {
    width: 72px;
    max-width: none;
    min-width: 0;
  }

  .data-table--sku .sku-cell--actions .qty-form .btn {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent;
  }

  .data-table--sku .wishlist-btn {
    min-height: 44px;
    min-width: 44px;
    width: 44px;
  }

  .data-table--sku .sku-row--empty {
    box-shadow: none;
  }

  .data-table--sku .sku-row--empty td {
    display: block;
    border: 0;
    text-align: center;
    color: var(--color-text-muted);
    padding: 16px 8px;
  }

  .data-table--sku .sku-row--empty td::before {
    display: none;
  }

  .section-card .section-body {
    padding-left: 12px;
    padding-right: 12px;
  }
}

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

@media (min-width: 768px) {
  .pdp-hero {
    grid-template-columns: 1fr 1fr;
    padding: 24px;
  }
}

@media (max-width: 899px) {
  .facet-group label {
    min-height: 40px;
  }

  .facet-group__more {
    min-height: 44px;
    padding: 4px 0;
  }

  .filter-toggle-btn {
    display: inline-flex;
  }

  /* Sidebar out of flow — cards visible on cold load (ERR-107) */
  .catalog-layout {
    display: block;
  }

  .filter-drawer {
    position: fixed;
    inset: 0;
    z-index: 80;
    pointer-events: none;
    width: auto;
    height: auto;
    margin: 0;
    padding: 0;
    border: 0;
  }

  .filter-drawer.is-open {
    pointer-events: auto;
  }

  .filter-drawer__backdrop {
    display: block;
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    transition: opacity 0.25s ease;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .filter-drawer.is-open .filter-drawer__backdrop {
    opacity: 1;
  }

  .filter-drawer__panel {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(400px, 92vw);
    max-width: 100%;
    margin: 0;
    padding: 0;
    border-radius: 0;
    border: 0;
    border-left: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    background: var(--color-surface);
    -webkit-overflow-scrolling: touch;
  }

  .filter-drawer.is-open .filter-drawer__panel {
    transform: translateX(0);
    visibility: visible;
  }

  .filter-drawer:not(.is-open) .filter-drawer__panel {
    visibility: hidden;
  }

  .filter-drawer__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
  }

  .filter-drawer__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    margin: -8px -8px -8px 0;
    border: 0;
    background: transparent;
    font-size: 28px;
    line-height: 1;
    color: var(--color-text);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .filter-drawer__body {
    flex: 1 1 auto;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 14px 16px;
  }

  .filter-drawer__footer {
    display: block;
    flex-shrink: 0;
    padding: 12px 16px;
    padding-bottom: calc(12px + var(--safe-bottom));
    border-top: 1px solid var(--color-border);
  }

  .filter-drawer__footer .btn {
    width: 100%;
  }
}

@media (min-width: 900px) {
  .catalog-layout {
    grid-template-columns: 260px minmax(0, 1fr);
    align-items: start;
  }

  .filter-drawer {
    position: static;
    pointer-events: auto;
  }

  .filter-drawer__panel {
    position: sticky;
    top: calc(var(--header-h, 112px) + 12px);
    max-height: calc(100vh - var(--header-h, 112px) - 24px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .filter-drawer__body {
    padding: 0;
  }

  .filter-toggle-btn {
    display: none;
  }
}

/* iOS number input */
input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

@media (max-width: 767px) {
  .product-card__media {
    aspect-ratio: 4 / 3;
    padding: 8px;
  }

  .pdp-gallery {
    aspect-ratio: 4 / 3;
    width: 100%;
    padding: 12px;
  }
}

@media (min-width: 768px) and (max-width: 1023px) {
  .product-card__media {
    padding: 10px;
  }

  .pdp-gallery {
    padding: 14px;
  }
}

@supports (-webkit-touch-callout: none) {
  .product-card__media img,
  .pdp-gallery img {
    -webkit-transform: translateZ(0);
  }
}
