/**
 * Before After Image Compare Elementor – Frontend Styles
 * Author: Bapan Mondal (bapanmondal.com)
 * Version: 1.0.0
 */

/* ─── Reset & Base ──────────────────────────────────────────────────────────── */
.baice-root *,
.baice-root *::before,
.baice-root *::after {
  box-sizing: border-box;
}

/* ─── Root wrapper ──────────────────────────────────────────────────────────── */
.baice-root {
  width: 100%;
  font-family: inherit;
}

/* ─── Flex wrapper: main + sidebar ─────────────────────────────────────────── */
.baice-wrapper {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 20px;
  width: 100%;
}

/* When sidebar is on the left the order is reversed via flexbox order */
.baice-wrapper.baice-sidebar-left .baice-sidebar {
  order: -1;
}

/* ─── Main comparison area ──────────────────────────────────────────────────── */
.baice-main-area {
  flex: 1 1 0%;
  min-width: 0;
  position: relative;
}

/* ─── Individual comparison item ────────────────────────────────────────────── */
.baice-comparison-item {
  display: none;
  opacity: 0;
  transition: opacity var(--baice-transition, 400ms) ease;
}

.baice-comparison-item.baice-active {
  display: block;
  opacity: 1;
}

.baice-comparison-item.baice-fading-in {
  opacity: 1;
}

/* ─── Comparison frame ──────────────────────────────────────────────────────── */
.baice-compare-frame {
  position: relative;
  width: 100%;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  line-height: 0;          /* removes gap under inline images  */
  cursor: col-resize;
  background: #000;
}

/* Establish the intrinsic height via the before image */
.baice-before-layer {
  position: relative;
  width: 100%;
  display: block;
  line-height: 0;
}

.baice-before-layer img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  draggable: false;
}

/* ─── After (overlay) layer ─────────────────────────────────────────────────── */
/*
 * KEY TECHNIQUE:
 * The after layer is positioned absolutely over the before layer.
 * Its width (as a percentage of the frame) is controlled by JS.
 * The image inside is always 100% of the *frame* wide – achieved with
 * `width: 100vw` overridden to the frame width via a JS-set CSS custom
 * property, keeping it pixel-perfect regardless of clip width.
 */
.baice-after-layer {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  overflow: hidden;       /* this is the clip */
  line-height: 0;
  pointer-events: none;
}

.baice-after-layer img {
  display: block;
  /* Image must always fill the FULL frame, not just the visible clip area.
     We size it to match the parent frame with the CSS custom property
     --baice-frame-w set by JS, falling back to 100vw for resilience. */
  width: var(--baice-frame-w, 100%);
  max-width: none;        /* critical – prevents img from shrinking to clip box */
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

/* ─── Divider line ──────────────────────────────────────────────────────────── */
.baice-divider {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
  background-color: #fff;
  transform: translateX(-50%);
  pointer-events: none;
  will-change: left;
  z-index: 10;
}

/* ─── Draggable handle ──────────────────────────────────────────────────────── */
.baice-handle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background-color: #fff;
  border: 2px solid #fff;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: all;
  cursor: col-resize;
  transition: box-shadow 0.2s ease, transform 0.15s ease;
  outline: none;
}

.baice-handle:focus-visible {
  outline: 3px solid #2563EB;
  outline-offset: 2px;
}

.baice-handle:hover {
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.45);
  transform: translate(-50%, -50%) scale(1.08);
}

.baice-handle-icon {
  width: 60%;
  height: 60%;
  color: #333;
  pointer-events: none;
}

/* ─── Labels ────────────────────────────────────────────────────────────────── */
.baice-label {
  position: absolute;
  top: 12px;
  z-index: 20;
  padding: 4px 10px;
  border-radius: 4px;
  background-color: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  pointer-events: none;
  user-select: none;
}

.baice-label-before { left: 12px; }
.baice-label-after  { right: 12px; }

/* ─── Item content: title + description ─────────────────────────────────────── */
.baice-item-content {
  margin-top: 16px;
  line-height: 1.6;
}

.baice-item-title {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.3;
  color: #111;
}

.baice-item-desc {
  margin: 0;
  font-size: 15px;
  color: #555;
  line-height: 1.65;
}

/* ─── Sidebar ───────────────────────────────────────────────────────────────── */
.baice-sidebar {
  width: 220px;
  min-width: 220px;
  flex-shrink: 0;
}

.baice-sidebar-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.baice-sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
  background-color: #f5f5f5;
  cursor: pointer;
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
  outline: none;
}

.baice-sidebar-item:hover {
  background-color: #e8e8e8;
}

.baice-sidebar-item.baice-active {
  background-color: #2563EB;
}

.baice-sidebar-item:focus-visible {
  outline: 3px solid #2563EB;
  outline-offset: 2px;
}

.baice-sidebar-thumb {
  width: 60px;
  height: 42px;
  flex-shrink: 0;
  border-radius: 4px;
  overflow: hidden;
  background: #ddd;
}

.baice-sidebar-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

.baice-sidebar-title {
  font-size: 13px;
  font-weight: 600;
  color: #222;
  line-height: 1.4;
  flex: 1;
}

.baice-sidebar-item.baice-active .baice-sidebar-title {
  color: #fff;
}

/* ─── Responsive – Tablet ───────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .baice-wrapper.baice-has-sidebar {
    flex-direction: column;
  }

  .baice-wrapper.baice-sidebar-left .baice-sidebar {
    order: 1; /* sidebar goes below main on tablet */
  }

  .baice-sidebar {
    width: 100% !important;
    min-width: 0 !important;
  }

  .baice-sidebar-list {
    flex-direction: row;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 8px;
    padding-bottom: 6px;
  }

  .baice-sidebar-item {
    flex-direction: column;
    align-items: center;
    min-width: 100px;
    flex-shrink: 0;
    text-align: center;
  }

  .baice-sidebar-thumb {
    width: 80px;
    height: 55px;
  }
}

/* ─── Responsive – Mobile ───────────────────────────────────────────────────── */
@media (max-width: 767px) {
  .baice-wrapper {
    gap: 14px;
  }

  .baice-label {
    font-size: 11px;
    padding: 3px 8px;
  }

  .baice-handle {
    width: 36px !important;
    height: 36px !important;
  }

  .baice-item-title {
    font-size: 17px;
  }

  .baice-sidebar-item {
    min-width: 90px;
  }

  .baice-sidebar-thumb {
    width: 70px;
    height: 48px;
  }
}

/* ─── Elementor editor overlay fix ─────────────────────────────────────────── */
.elementor-editor-active .baice-compare-frame {
  pointer-events: none;
}
