/* Best Alternative component — root: .best_alternative, prefix: ba-
   No font-family / outer max-width / outer margin: inherited from page master CSS.
   Score colours come from the existing p-{score} classes (not redefined here). */

.best_alternative {
  --ba-line: #e5e5e5;
  --ba-cur-bg: #f1f1f1;
  --ba-colw: 50%;          /* column width inside scroll mode (mobile) */
  --ba-slots: 6;           /* desktop: current + up to 5 alternatives */
  --ba-img-h: 110px;
  --ba-arrow-top: 160px;   /* vertical position of scroll arrow (header area) */
  color: #222;
}
.best_alternative *,
.best_alternative *::before,
.best_alternative *::after { box-sizing: border-box; }
.best_alternative a { color: inherit; text-decoration: none; }
.best_alternative img { display: block; max-width: 100%; }

.best_alternative .ba-title {
  margin: 0 0 12px;
  font-size: 1.0625rem;
  font-weight: 600;
  line-height: 1.3;
}

/* ---------- Frame + scroll ---------- */
.best_alternative .ba-wrap {
  position: relative;
  border: 1px solid var(--ba-line);
  border-radius: 16px;
  overflow: hidden;
  background: #fff;
}
.best_alternative .ba-scroll {
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scroll-padding-left: var(--ba-colw);
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.best_alternative .ba-scroll::-webkit-scrollbar { display: none; }
.best_alternative .ba-table { width: calc(var(--ba-cols) * var(--ba-colw)); }
.best_alternative .ba-row {
  display: grid;
  grid-template-columns: repeat(var(--ba-cols), 1fr);
}

/* ---------- Cells (one cell = one product in one row) ---------- */
.best_alternative .ba-cell {
  min-width: 0;
  border-right: 1px solid var(--ba-line);
  border-bottom: 1px solid var(--ba-line);
}
.best_alternative .ba-cell:last-child { border-right: 0; }
.best_alternative .ba-row:last-child .ba-cell { border-bottom: 0; }
.best_alternative .ba-head:not(.ba-cur) { scroll-snap-align: start; }
.best_alternative .ba-cur { background: var(--ba-cur-bg); }

/* Current product column stays fixed while alternatives scroll */
.best_alternative .ba-cell:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  box-shadow: 2px 0 6px rgba(0, 0, 0, .06);
}

/* ---------- Header cell ---------- */
.best_alternative .ba-head {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 10px;
  text-align: center;
}
.best_alternative .ba-score {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 1;
  min-width: 30px;
  padding: 3px 6px;
  border-radius: 4px;
  font-size: .875rem;
  font-weight: 700;
  line-height: 1.2;
  color: #fff;
}
.best_alternative .ba-disc {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1;
  padding: 2px 8px;
  border-radius: 20px;
  background: #7fba6a;
  color: #fff;
  font-size: .6875rem;
  font-weight: 600;
  line-height: 1.5;
}
.best_alternative .ba-img-box {
  display: block;
  width: 100%;
  height: var(--ba-img-h);
  padding: 0 26px;
}
.best_alternative .ba-img {
  width: 100%;
  height: 100%;
  object-fit: contain;   /* any image size/ratio fits inside the fixed box */
}
.best_alternative .ba-name {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 2.6em;     /* reserves 2 lines so price/logo align across columns */
  margin-top: 8px;
  font-size: .9375rem;
  font-weight: 600;
  line-height: 1.3;
}
.best_alternative .ba-clamp {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.best_alternative .ba-price {
  margin-top: 4px;
  color: #e0485e;
  font-size: 1.125rem;
  font-weight: 700;
  line-height: 1.3;
}
.best_alternative .ba-store {
  height: 18px;
  width: auto;
  margin-top: 4px;
}

/* ---------- Spec rows ---------- */
.best_alternative .ba-spec {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px 12px;
  font-size: .875rem;
  line-height: 1.3;
}
.best_alternative .ba-icon {
  flex: 0 0 20px;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.best_alternative .ba-val {
  min-width: 0;
  overflow-wrap: anywhere;
}
.best_alternative .ba-cur .ba-val { font-weight: 600; }

/* ---------- "vs" row ---------- */
.best_alternative .ba-vs-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px 8px;
  text-align: center;
}
.best_alternative .ba-cur-label {
  color: #555;
  font-weight: 600;
}
.best_alternative .ba-vs {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  font-size: .875rem;
  font-weight: 600;
  line-height: 1.3;
}
.best_alternative .ba-vs-a,
.best_alternative .ba-vs-b {
  display: flex;
  justify-content: center;
  width: 100%;
  min-height: 2.6em;
}
.best_alternative .ba-vs-a { align-items: flex-end; }
.best_alternative .ba-vs-b { align-items: flex-start; }
.best_alternative .ba-vs-t { font-size: 1.125rem; font-weight: 700; }

/* ---------- Scroll arrow (mobile / tablet only) ---------- */
.best_alternative .ba-arrow {
  position: absolute;
  top: var(--ba-arrow-top);
  right: 8px;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(225, 225, 225, .8);
  color: #555;
  cursor: pointer;
  transition: opacity .2s;
}
.best_alternative .ba-arrow:focus-visible { outline: 2px solid #555; outline-offset: 2px; }
.best_alternative .ba-arrow svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.best_alternative .ba-arrow.ba-hide { opacity: 0; pointer-events: none; }

/* ---------- Tablet: ~3 columns visible ---------- */
@media (min-width: 640px) {
  .best_alternative { --ba-colw: 33.3333%; --ba-img-h: 120px; --ba-arrow-top: 175px; }
}

/* ---------- Desktop: all columns visible, no scroll, no sticky ---------- */
@media (min-width: 1024px) {
  .best_alternative .ba-scroll { overflow: hidden; }
  /* +1px hides the last cell's right border under the frame when all 6 slots are used */
  .best_alternative .ba-table { width: calc(100% + 1px); }
  .best_alternative .ba-row {
    grid-template-columns: repeat(var(--ba-cols), calc(100% / var(--ba-slots)));
  }
  /* relative (not static) so score/discount badges stay inside the current product cell */
  .best_alternative .ba-cell:first-child { position: relative; box-shadow: none; }
  /* closes the table on the right when fewer than 6 slots are filled */
  .best_alternative .ba-cell:last-child { border-right: 1px solid var(--ba-line); }
  .best_alternative .ba-arrow { display: none; }
}