/*
 * Before After Image Compare Elementor – Frontend Styles
 * Plugin:  before-after-image-compare-elementor
 * Author:  Bapan Mondal (bapanmondal.com)
 * Version: 1.0.0
 */

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

/* ─── Wrapper ───────────────────────────────────────────────────────────────── */
.baice-wrapper {
    display: flex;
    align-items: stretch;
    gap: 20px;
    width: 100%;
    font-family: inherit;
}

/* Sidebar on right (default) */
.baice-wrapper.baice-sidebar-right {
    flex-direction: row;
}

/* Sidebar on left */
.baice-wrapper.baice-sidebar-left {
    flex-direction: row-reverse;
}

/* No sidebar */
.baice-wrapper.baice-no-sidebar .baice-main {
    flex: 1;
}

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

/* ─── Comparison Items ──────────────────────────────────────────────────────── */
.baice-comparison-item {
    display: none;
    flex-direction: column;
    gap: 0;
    animation: baiceItemFadeIn 0.4s ease forwards;
}

.baice-comparison-item.is-active {
    display: flex;
}

@keyframes baiceItemFadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ─── Slider Container ──────────────────────────────────────────────────────── */
.baice-slider-container {
    position: relative;
    width: 100%;
    overflow: hidden;
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
    cursor: col-resize;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    line-height: 0; /* Removes inline-block gap */
    background: #e2e8f0;
}

.baice-slider-container:focus-within {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* ─── After Image (base layer) ──────────────────────────────────────────────── */
.baice-after-wrap {
    position: relative;
    width: 100%;
    display: block;
}

.baice-after-img,
.baice-before-img {
    display: block;
    width: 100%;
    height: auto;
    max-height: 560px;
    object-fit: cover;
    pointer-events: none;
}

/* ─── Before Image (clipped overlay) ───────────────────────────────────────── */
.baice-before-wrap {
    position: absolute;
    top: 0;
    left: 0;
    width: 50%; /* JS overrides this live */
    height: 100%;
    overflow: hidden;
}

.baice-before-wrap .baice-before-img {
    width: 100%; /* always 100% of container – clip parent handles the reveal */
    min-width: 100%; /* stretch to fill, avoids blank edge during resize */
    max-width: none;
    height: 100%;
    object-fit: cover;
    object-position: left center;
}

/* Ensure before-img fills slider container width dynamically via JS */
.baice-slider-container .baice-before-img {
    /* JS sets explicit pixel width equal to slider container width */
    position: absolute;
    top: 0;
    left: 0;
}

/* ─── Labels ────────────────────────────────────────────────────────────────── */
.baice-label {
    position: absolute;
    top: 12px;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    line-height: 1;
    pointer-events: none;
}

.baice-label-before {
    left: 10px;
    background-color: rgba(0, 0, 0, 0.55);
    color: #fff;
}

.baice-label-after {
    right: 10px;
    background-color: rgba(0, 0, 0, 0.55);
    color: #fff;
}

/* ─── Handle ────────────────────────────────────────────────────────────────── */
.baice-handle-wrap {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%; /* JS overrides */
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none;
    z-index: 10;
}

.baice-handle-line {
    flex: 1;
    width: 2px;
    background-color: #fff;
    opacity: 0.85;
}

.baice-handle {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background-color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
    color: #374151;
    flex-shrink: 0;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.baice-slider-container:hover .baice-handle,
.baice-slider-container.is-dragging .baice-handle {
    transform: scale(1.1);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.baice-handle svg {
    pointer-events: none;
}

/* ─── Caption ───────────────────────────────────────────────────────────────── */
.baice-caption {
    padding: 18px 4px 8px;
}

.baice-main-title {
    margin: 0 0 6px;
    font-size: 1.2rem;
    font-weight: 700;
    color: #1e293b;
    line-height: 1.4;
}

.baice-main-desc {
    margin: 0;
    font-size: 0.95rem;
    color: #475569;
    line-height: 1.65;
}

/* ─── Sidebar ───────────────────────────────────────────────────────────────── */
.baice-sidebar {
    width: 240px;
    min-width: 240px;
    background-color: #f8f9fa;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.07);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-self: flex-start;
}

/* ─── Sidebar Item ──────────────────────────────────────────────────────────── */
.baice-sidebar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    outline: none;
}

.baice-sidebar-item:last-child {
    border-bottom: none;
}

.baice-sidebar-item:not(.is-active):hover {
    background-color: #e2e8f0;
}

.baice-sidebar-item.is-active {
    background-color: #3b82f6;
}

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

/* Focus ring for keyboard nav */
.baice-sidebar-item:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: -2px;
}

/* ─── Sidebar Thumbnail ─────────────────────────────────────────────────────── */
.baice-sidebar-thumb-wrap {
    width: 56px;
    height: 42px;
    border-radius: 6px;
    overflow: hidden;
    flex-shrink: 0;
    background: #e2e8f0;
}

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

/* ─── Sidebar Item Title ────────────────────────────────────────────────────── */
.baice-sidebar-item-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: #374151;
    line-height: 1.4;
    transition: color 0.2s ease;
}

/* ─── Numbered badge ────────────────────────────────────────────────────────── */
.baice-sidebar-item-num {
    font-size: 11px;
    font-weight: 700;
    color: #94a3b8;
    min-width: 20px;
    transition: color 0.2s ease;
}

.baice-sidebar-item.is-active .baice-sidebar-item-num {
    color: rgba(255, 255, 255, 0.8);
}

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

    .baice-sidebar {
        width: 100% !important;
        min-width: 100% !important;
        flex-direction: row;
        flex-wrap: wrap;
        border-radius: 12px;
        gap: 0;
    }

    .baice-sidebar-item {
        flex: 0 0 auto;
        width: calc(50% - 0px);
        border-bottom: 1px solid rgba(0, 0, 0, 0.06);
        border-right: 1px solid rgba(0, 0, 0, 0.06);
    }

    .baice-sidebar-item:nth-child(even) {
        border-right: none;
    }
}

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

    .baice-sidebar {
        overflow-x: auto;
        overflow-y: hidden;
        flex-direction: row;
        flex-wrap: nowrap;
        border-radius: 10px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .baice-sidebar::-webkit-scrollbar {
        display: none;
    }

    .baice-sidebar-item {
        flex: 0 0 auto;
        width: auto;
        min-width: 140px;
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
        border-right: 1px solid rgba(0, 0, 0, 0.06);
        border-bottom: none;
    }

    .baice-sidebar-thumb-wrap {
        width: 100%;
        height: 72px;
    }

    .baice-after-img,
    .baice-before-img {
        max-height: 320px;
    }

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

    .baice-main-title {
        font-size: 1.05rem;
    }
}

/* ─── Transition overlay (JS adds .baice-transitioning) ─────────────────────── */
.baice-main.baice-transitioning .baice-comparison-item.is-active {
    animation: baiceItemFadeIn 0.35s ease forwards;
}
