/* CASES SECTION - Inverted Design */
#cases {
    position: relative;
    width: 100%;
    background-color: var(--color-primary); /* Yellow Background */
    color: var(--color-secondary); /* Black Text */
    padding: 120px 0;
    overflow: hidden;
    z-index: 10;
}

/* Background Texture */
#cases::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: linear-gradient(rgba(7, 7, 7, 0.05) 1px, transparent 1px),
                      linear-gradient(90deg, rgba(7, 7, 7, 0.05) 1px, transparent 1px);
    background-size: 50px 50px;
    opacity: 0.3;
    pointer-events: none;
}

.cases-header {
    text-align: center;
    margin-bottom: 60px;
    position: relative;
    z-index: 2;
    padding: 0 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.cases-label {
    font-family: var(--font-primary);
    font-size: 0.9rem;
    color: var(--color-secondary);
    letter-spacing: 0.2em;
    text-transform: uppercase;
    margin-bottom: 1rem;
    display: block;
    font-weight: 700;
    opacity: 0.7;
}

.cases-title {
    font-size: clamp(2.5rem, 5vw, 4.5rem);
    color: var(--color-secondary);
    line-height: 1;
    font-weight: 700;
    margin-bottom: 40px;
}

.cases-title span {
    color: var(--color-white); /* White accent on yellow */
    font-weight: 300;
}

/* CONTROLS */
.cases-controls {
    display: flex;
    gap: 20px;
    margin-top: 20px;
}

.case-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 2px solid var(--color-secondary);
    background: transparent;
    color: var(--color-secondary);
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.case-btn:hover {
    background: var(--color-secondary);
    color: var(--color-primary);
    transform: scale(1.1);
}

.case-btn:active {
    transform: scale(0.95);
}

/* CAROUSEL CONTAINER */
.cases-carousel-wrapper {
    position: relative;
    width: 100%;
    /* Align with container logic, but ensure it's scrollable */
    padding-left: max(2rem, calc((100vw - 1400px) / 2)); 
    padding-right: 2rem; /* Add padding right for balance */
    overflow-x: auto;
    overflow-y: hidden;
    display: flex;
    flex-wrap: nowrap; /* FORCE NO WRAP to prevent staircase effect */
    align-items: flex-start; /* Ensure all cards hang from the top line perfectly */
    gap: 40px;
    padding-bottom: 60px; /* Space for shadow */
    cursor: grab;
    -ms-overflow-style: none;  /* IE and Edge */
    scrollbar-width: none;  /* Firefox */
    scroll-behavior: smooth; /* Native smooth scroll */
}

.cases-carousel-wrapper::-webkit-scrollbar {
    display: none;
}

.cases-carousel-wrapper:active,
.cases-carousel-wrapper.active {
    cursor: grabbing;
}

/* CAROUSEL CARD */
.case-card {
    position: relative;
    flex: 0 0 450px; /* Fixed width cards */
    height: 600px;
    border-radius: 30px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 20px 40px rgba(0,0,0,0.1);
    transition: transform 0.4s cubic-bezier(0.25, 1, 0.5, 1), box-shadow 0.4s ease;
    user-select: none;
    /* Ensure no weird margins causing steps */
    margin: 0; 
}

.case-card:hover {
    transform: translateY(-10px);
    box-shadow: 0 30px 60px rgba(0,0,0,0.15);
}

/* CARD CONTENT */
.case-card-inner {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Image Area (Slider) */
.case-visual {
    position: relative;
    width: 100%;
    height: 70%; /* Takes up most of the card */
    overflow: hidden;
}

/* Before/After Structure */
.ba-slider {
    position: relative;
    width: 100%;
    height: 100%;
}

.ba-image-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.ba-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none; /* Let clicks pass to slider */
}

/* The "Before" image sits on top and is clipped */
.img-before {
    width: 50%; /* Initial state */
    z-index: 2;
    border-right: 2px solid var(--color-white);
}

.img-before .ba-img {
    width: 450px; /* Must match card width to prevent squashing */
    max-width: none; 
}

/* The "After" image is the base */
.img-after {
    z-index: 1;
}

/* Visual Labels */
.ba-label {
    position: absolute;
    top: 20px;
    padding: 6px 14px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    border-radius: 20px;
    z-index: 3;
    pointer-events: none;
}

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

/* Slider Handle */
.ba-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%; /* Matches img-before width */
    width: 40px;
    transform: translateX(-50%);
    z-index: 10;
    cursor: ew-resize;
    display: flex;
    align-items: center;
    justify-content: center;
}

.handle-line {
    width: 2px;
    height: 100%;
    background: var(--color-white);
    box-shadow: 0 0 10px rgba(0,0,0,0.3);
}

.handle-circle {
    position: absolute;
    width: 40px;
    height: 40px;
    background: var(--color-white);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    color: var(--color-secondary);
    font-size: 0.9rem;
}

/* Card Info */
.case-info {
    height: 30%;
    padding: 30px;
    background: #fff;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.case-meta {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.case-tag {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-secondary);
    border: 1px solid var(--color-secondary);
    padding: 4px 10px;
    border-radius: 100px;
}

.case-info h3 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 5px;
    line-height: 1.2;
    color: var(--color-secondary);
}

.case-location {
    font-family: var(--font-secondary);
    color: var(--color-gray);
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 6px;
}

.case-expand-btn {
    align-self: flex-start;
    margin-top: 15px;
    background: transparent;
    border: none;
    color: var(--color-secondary);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0;
}

.case-expand-btn i {
    transition: transform 0.3s ease;
}

.case-expand-btn:hover i {
    transform: translateX(4px);
}

/* FULLSCREEN MODAL */
.case-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100dvh;
    background: rgba(0,0,0,0.95);
    z-index: 10002; /* Ensure this is higher than header (1000) and mobile toggle (1002) */
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
    display: flex;
    flex-direction: column;
}

.case-modal.active {
    opacity: 1;
    pointer-events: all;
}

.modal-close {
    position: absolute;
    top: 30px;
    right: 30px;
    background: rgba(255,255,255,0.1);
    border: none;
    color: #fff;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    z-index: 10005; /* Extremely high z-index for the button itself */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: background 0.3s ease;
}

.modal-close:hover {
    background: rgba(255,255,255,0.2);
}

.modal-content {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.modal-visual-wrapper {
    width: 90%;
    height: 80%;
    position: relative;
    border-radius: 20px;
    overflow: hidden;
}

/* Modal text */
.modal-info-bar {
    width: 90%;
    margin-top: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
}

.modal-info-bar h2 {
    font-size: 2rem;
    margin-bottom: 5px;
}

/* Responsive */
@media (max-width: 1024px) {
    .case-card {
        flex: 0 0 350px;
        height: 500px;
    }
    
    .img-before .ba-img {
        width: 350px;
    }
}

@media (max-width: 768px) {
    #cases {
        padding: 80px 0;
    }

    .cases-carousel-wrapper {
        padding-left: 20px;
        gap: 20px;
    }

    .case-card {
        /* Make card responsive: 85% of viewport width but max 350px */
        flex: 0 0 85vw;
        max-width: 350px;
        height: auto;
        min-height: 500px;
        display: flex;
        flex-direction: column;
    }
    
    .case-visual {
        height: 300px; /* Fixed height for visual on mobile */
        flex-shrink: 0;
    }

    .case-info {
        height: auto; /* Let content dictate height */
        flex-grow: 1;
        padding: 24px;
    }

    .img-before .ba-img {
        /* Image must match the card width exactly to prevent aspect ratio distortion when clipping */
        width: 85vw;
        max-width: 350px; 
    }
    
    .cases-title {
        font-size: 2.5rem;
    }
    
    .handle-circle {
        width: 30px;
        height: 30px;
        font-size: 0.7rem;
    }
    
    .cases-controls {
        display: none; /* Hide buttons on mobile, swipe is better */
    }
    
    /* On mobile, hints for slider */
    .ba-slider::after {
        content: 'ARRASTE';
        position: absolute;
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
        color: rgba(255,255,255,0.8);
        font-size: 0.7rem;
        background: rgba(0,0,0,0.5);
        padding: 4px 10px;
        border-radius: 10px;
        pointer-events: none;
        opacity: 0.7;
    }
}
