/* Порівняння товарів
   Desktop: sticky ліва колонка характеристик
   Mobile (≤768px): sticky шапка товарів зверху, підписи над значеннями, без sticky зліва
*/

.compare-page {
  max-width: var(--container, 1200px);
  margin: 0 auto;
  padding: var(--sp-6) var(--sp-4) var(--sp-10);
}

.compare-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
}

.compare-toolbar__count {
  margin: 0;
  color: var(--color-muted, #64748b);
  font-size: 0.95rem;
}

.compare-scroll-hint {
  display: none;
  margin: 0 0 var(--sp-2);
  color: var(--color-muted, #64748b);
  font-size: 0.8125rem;
  line-height: 1.3;
  letter-spacing: 0.01em;
}

.compare-scroll,
.comparison-container,
.comparison-table-wrapper {
  position: relative;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  border: 1px solid var(--border-color, var(--color-border));
  border-radius: 12px;
  background: #ffffff;
  background: var(--bg-card, var(--color-surface, #ffffff));
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--color-muted, #94a3b8) 55%, transparent) transparent;
}

.compare-scroll::-webkit-scrollbar {
  height: 6px;
}

.compare-scroll::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: color-mix(in srgb, var(--color-muted, #94a3b8) 55%, transparent);
}

.compare-scroll-fade {
  display: none;
}

.compare-table {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: auto;
}

.compare-table th,
.compare-table td {
  box-sizing: border-box;
  width: 12.5rem;
  min-width: 11rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid #e5e7eb;
  border-right: 1px solid #f0f0f0;
  vertical-align: top;
  text-align: left;
  font-size: 0.925rem;
  line-height: 1.4;
  word-break: break-word;
  overflow-wrap: anywhere;
  -webkit-hyphens: auto;
  hyphens: auto;
  background: #ffffff;
}

.compare-table tr:last-child th,
.compare-table tr:last-child td {
  border-bottom: 0;
}

.compare-table tbody tr:nth-child(even) > th,
.compare-table tbody tr:nth-child(even) > td {
  background: #f9fafb;
}

.compare-table__sticky {
  position: sticky;
  left: 0;
  z-index: 2;
  width: 9.5rem;
  min-width: 8.5rem;
  max-width: 10rem;
  background-color: #ffffff;
  font-weight: 600;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.06);
}

.compare-table tbody tr:nth-child(even) > .compare-table__sticky {
  background-color: #f9fafb;
}

.compare-table thead .compare-table__sticky {
  z-index: 3;
}

.compare-table__price,
.compare-card__price {
  margin: 0;
  font-weight: 700;
  color: var(--color-accent, var(--accent-orange, #ff6b00));
  font-variant-numeric: tabular-nums;
}

/* Ціна в картці — лише mobile (у sticky-шапці) */
.compare-card__price {
  display: none;
}

.compare-card {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  min-width: 0;
}

.compare-card__media {
  display: block;
  aspect-ratio: 1;
  max-height: 10rem;
  border-radius: 10px;
  overflow: hidden;
  background: color-mix(in srgb, var(--color-muted, #94a3b8) 10%, transparent);
}

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

.compare-card__title {
  color: var(--color-text, #0f172a);
  text-decoration: none;
  font-weight: 600;
  line-height: 1.35;
}

.compare-card__title:hover {
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

.compare-card__remove {
  align-self: flex-start;
  border: 0;
  padding: 0.15rem 0;
  background: transparent;
  color: var(--color-muted, #64748b);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 0.15em;
  -webkit-tap-highlight-color: transparent;
}

.compare-card__remove:hover,
.compare-card__remove:focus-visible {
  color: var(--color-accent, var(--accent-orange, #ff6b00));
}

/* ——— Mobile: Variant 1 — sticky top product headers, no left sticky ——— */
@media (max-width: 768px) {
  .compare-page {
    padding-inline: var(--sp-3);
  }

  .compare-scroll-hint {
    display: block;
  }

  .compare-scroll,
  .comparison-container,
  .comparison-table-wrapper {
    max-height: min(72dvh, calc(100dvh - var(--header-h) - var(--safe-t, 0px) - 5rem));
    overflow: auto;
    overscroll-behavior: contain;
    border-radius: 10px;
  }

  .compare-scroll-fade {
    display: none;
  }

  .compare-table {
    min-width: 0;
    width: max-content;
  }

  /* Прибрати ліву sticky-колонку — назви йдуть підписом над значенням */
  .compare-table__sticky {
    display: none;
    position: static;
    box-shadow: none;
    z-index: auto;
  }

  /* Ціна вже в шапці картки */
  .compare-table__row--price {
    display: none;
  }

  .compare-table th,
  .compare-table td {
    width: 145px;
    min-width: 145px;
    max-width: 145px;
    padding: 8px 10px;
    font-size: 12px;
    line-height: 1.3;
    border-bottom: 1px solid #e5e7eb;
    border-right: 1px solid #f0f0f0;
  }

  .compare-table tbody tr:nth-child(odd) > td {
    background: #ffffff;
  }

  .compare-table tbody tr:nth-child(even) > td {
    background: #f9fafb;
  }

  /* Sticky шапка товарів зверху (всередині контейнера скролу) */
  .compare-table thead th.compare-table__product {
    position: sticky;
    top: 0;
    z-index: 20;
    background: #ffffff;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.08);
    vertical-align: bottom;
  }

  .compare-card {
    gap: 0.35rem;
  }

  .compare-card__media {
    aspect-ratio: auto;
    height: 88px;
    max-height: 88px;
    border-radius: 8px;
  }

  .compare-card__media img {
    height: 100%;
    max-height: 88px;
  }

  .compare-card__title {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    font-size: 12px;
    line-height: 1.3;
  }

  .compare-card__price {
    display: block;
    font-size: 13px;
    line-height: 1.25;
  }

  .compare-card__remove {
    font-size: 11px;
    color: var(--color-accent, var(--accent-orange, #ff6b00));
  }

  /* Дрібний підпис характеристики над значенням */
  .compare-table tbody td[data-label]::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 0.2rem;
    color: #6b7280;
    font-size: 10px;
    font-weight: 500;
    line-height: 1.2;
    letter-spacing: 0.01em;
  }
}

@supports (-webkit-touch-callout: none) {
  .compare-scroll,
  .comparison-container,
  .comparison-table-wrapper {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
  }
}
