/* =====================================================================
   DRIVIN — Best Sellers auto-carousel for Salla (v4)
   Paste in: Salla → Advanced customization → Customize with CSS
   (Replace the v3 CSS completely.)
   Every selector is scoped under .drivin-bs-root — nothing in the theme is touched.

   v4 changes vs v3 (design, sizes, spacing, typography unchanged)
   - Viewport/root use `overflow: clip` (hidden as fallback). A `hidden`
     element is still a scroll container: focusing a link inside it can make
     the browser scroll it sideways (breaking the loop position), and it can
     take part in scroll chaining. `clip` is not a scroll container.
   - Removed overscroll-behavior: it does nothing on a box nobody scrolls,
     and on some engines it can block vertical page-scroll chaining.
   - Removed image-rendering:-webkit-optimize-contrast: a non-standard value
     that some engines map to crisp/pixelated scaling. Product photos are
     downscaled here, which made edges aliased and shimmer while moving.
     Images now use the browser's normal high-quality scaling.
   - Kept: one GPU layer (the track), 2D zig-zag, containment, skeleton.
   ===================================================================== */

/* Theme's own duplicate "الأكثر مبيعاً" block (only if one exists), hidden while ours is mounted */
.drivin-bs-native-hidden {
  display: none !important;
}

/* ---------- Root ---------- */
.drivin-bs-root {
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  overflow: clip;
  background: #ffffff;
  direction: rtl;
  position: relative;
  clear: both;
}

/* ---------- Scoped reset (as original, minus image-rendering) ---------- */
.drivin-bs-root .drivin-v3-viewport,
.drivin-bs-root .drivin-v3-viewport * {
  box-sizing: border-box !important;
  -webkit-user-select: none !important;
  user-select: none !important;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased !important;
}

/* ---------- Title ---------- */
.drivin-bs-root .drivin-v3-static-title {
  width: 100%;
  margin: 0;
  padding: 36px 16px 0;
  background: #ffffff;
  text-align: center;
  direction: rtl;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, Geneva, sans-serif;
  font-size: clamp(34px, 8vw, 64px);
  font-weight: 800;
  line-height: 1.15;
  color: #000000;
  letter-spacing: -0.5px;
  -webkit-user-select: none;
  user-select: none;
  border: 0;
}

/* ---------- Viewport ----------
   direction:ltr keeps the transform math simple; card text is set back to RTL. */
.drivin-bs-root .drivin-v3-viewport {
  width: 100%;
  overflow: hidden !important;
  overflow: clip !important;
  background: #ffffff;
  padding: 30px 0 70px;
  position: relative;
  display: flex;
  direction: ltr;
  cursor: grab;
  touch-action: pan-y !important;            /* vertical page scroll stays native */
  min-height: 460px;
  contain: layout style paint;
  -webkit-tap-highlight-color: transparent;
}

.drivin-bs-root .drivin-v3-viewport.is-dragging { cursor: grabbing; }

/* Skeleton state: right-aligned (RTL), no grab cursor */
.drivin-bs-root .drivin-v3-viewport.is-loading {
  justify-content: flex-end;
  cursor: default;
}

/* ---------- Track (the ONLY GPU layer) ---------- */
.drivin-bs-root .drivin-v3-track {
  display: flex;
  flex-direction: row;
  flex-shrink: 0;
  width: max-content;
  direction: ltr;
  will-change: transform;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  transform: translate3d(0, 0, 0);
}

/* ---------- Loop group ---------- */
.drivin-bs-root .drivin-v3-group {
  display: flex;
  flex-direction: row;
  flex-shrink: 0;
  gap: 25px;
  padding-right: 25px;
}

/* ---------- Card ---------- */
.drivin-bs-root .drivin-v3-card {
  width: 220px;
  flex-shrink: 0;
  background: transparent;
  display: flex;
  flex-direction: column;
  position: relative;
  direction: rtl;
  color: inherit;
  text-decoration: none !important;
  outline-offset: 4px;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  --zig-offset: clamp(18px, 4vw, 32px);
}

.drivin-bs-root .drivin-v3-card:hover,
.drivin-bs-root .drivin-v3-card:focus {
  color: inherit;
  text-decoration: none !important;
}

.drivin-bs-root .drivin-v3-card:focus { outline: none; }
.drivin-bs-root .drivin-v3-card:focus-visible {
  outline: 2px solid #000000;
}

/* Zig-zag — same offsets as the original, 2D (no per-card GPU layers) */
.drivin-bs-root .drivin-v3-viewport.is-zig .drivin-v3-card:nth-child(odd)  { transform: translateY(calc(var(--zig-offset) * -1)); }
.drivin-bs-root .drivin-v3-viewport.is-zig .drivin-v3-card:nth-child(even) { transform: translateY(var(--zig-offset)); }

/* ---------- Image ---------- */
.drivin-bs-root .drivin-v3-img-box {
  width: 100%;
  aspect-ratio: 220 / 340;
  height: auto;
  overflow: hidden;
  position: relative;
  background: transparent;
  contain: layout paint;
}

.drivin-bs-root .drivin-v3-img-box img {
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  object-fit: contain;
  pointer-events: none;
  display: block;
  border: 0;
  border-radius: 0;
}

/* ---------- Overlay + "اشتري الآن" ---------- */
.drivin-bs-root .drivin-v3-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.05);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s ease;
  z-index: 5;
}

.drivin-bs-root .drivin-v3-btn {
  background: #000000;
  color: #ffffff;
  border: 1px solid #000000;
  padding: 12px 24px;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  white-space: nowrap;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
  transform: scale(0.9);
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.drivin-bs-root .drivin-v3-card.is-touched .drivin-v3-overlay { opacity: 1; visibility: visible; }
.drivin-bs-root .drivin-v3-card.is-touched .drivin-v3-btn { transform: scale(1); }

/* ---------- Info ---------- */
.drivin-bs-root .drivin-v3-info {
  text-align: center;
  padding-top: 12px;
}

.drivin-bs-root .drivin-v3-title {
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  color: #000000;
  text-transform: uppercase;
  margin-bottom: 4px;
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Prices (old price struck through next to the new one) ---------- */
.drivin-bs-root .drivin-v3-price {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: baseline;
  gap: 2px 8px;
  direction: rtl;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 12px;
  line-height: 1.4;
}

.drivin-bs-root .drivin-v3-price-now {
  white-space: nowrap;
  font-weight: 600;
  color: #000000;
}

.drivin-bs-root .drivin-v3-price-was {
  white-space: nowrap;
  font-weight: 400;
  color: #888888 !important;
  margin: 0 !important;
  text-decoration: line-through !important;
  text-decoration-thickness: 1px;
}

.drivin-bs-root .drivin-v3-price i {
  font-style: normal;
}

/* Availability */
.drivin-bs-root .drivin-v3-stock {
  display: block;
  flex-basis: 100%;
  margin-top: 2px;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 11px;
  color: #888888;
}

.drivin-bs-root .drivin-v3-card.is-oos .drivin-v3-img-box img {
  opacity: 0.55;
}

/* ---------- Skeleton (same box sizes as a real card → no layout shift) ---------- */
.drivin-bs-root .drivin-v3-card.is-skel { pointer-events: none; }
.drivin-bs-root .drivin-v3-card.is-skel .drivin-v3-img-box { background: #f4f4f4; }
.drivin-bs-root .drivin-v3-card.is-skel .drivin-v3-info { height: 49.6px; }
.drivin-bs-root .drivin-v3-skel-line {
  display: block;
  height: 10px;
  width: 70%;
  margin: 3px auto 0 !important;
  background: #f4f4f4;
  border-radius: 2px;
}
.drivin-bs-root .drivin-v3-skel-line + .drivin-v3-skel-line {
  width: 40%;
  margin-top: 10px !important;
}

/* ---------- Mobile ---------- */
@media (max-width: 768px) {
  .drivin-bs-root .drivin-v3-static-title { padding: 24px 12px 0; }
  .drivin-bs-root .drivin-v3-viewport { padding: 20px 0 45px; min-height: 340px; }
  .drivin-bs-root .drivin-v3-card { width: 165px; }
  .drivin-bs-root .drivin-v3-group { gap: 15px; padding-right: 15px; }
}