/* =========================================================
   팝업 전체 영역
========================================================= */
section#popupWrap {
    position: fixed;
    top: 100px;
    left: 5%;

    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;

    width: 90%;
    height: 700px;
    max-height: calc(100vh - 120px);
    margin: 0;

    overflow: visible;
    z-index: 10000;

    /*
     * 팝업의 빈 공간이 아래쪽 페이지 클릭을 막지 않도록 처리
     */
    pointer-events: none;
}

section#popupWrap > article {
    position: relative;

    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;

    /*
     * article의 빈 영역도 아래쪽 클릭이 가능하도록 처리
     */
    pointer-events: none;
}

section#popupWrap > article > .popup-fixed {
    position: absolute;
    top: 0;
    left: 0;

    width: 100%;
    height: 100%;
    max-height: 700px;

    /*
     * 실제 팝업 영역만 클릭 가능
     */
    pointer-events: auto;
}

/* 닫힌 팝업이 차지하는 그리드 영역 제거 */
section#popupWrap > article:has(> .popup-fixed.hidden) {
    display: none;
}


/* =========================================================
   팝업 박스
========================================================= */
.popup-fixed {
    position: relative;

    display: flex;
    flex-direction: column;

    width: 100%;
    height: 100%;

    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);

    overflow: hidden;
    z-index: 10000;

    pointer-events: auto;
}

.popup-fixed.hidden {
    display: none !important;
    pointer-events: none !important;
}


/* =========================================================
   팝업 내부 클릭 요소
========================================================= */
section#popupWrap .popup-fixed a,
section#popupWrap .popup-fixed button,
section#popupWrap .popup-fixed input,
section#popupWrap .popup-fixed label,
section#popupWrap .popup-fixed .tab,
section#popupWrap .popup-fixed .popup-btn,
section#popupWrap .popup-fixed .popup-close-btn {
    pointer-events: auto;
}


/* =========================================================
   팝업 이미지 - 단일 팝업
========================================================= */
section#popupWrap > article > .popup-fixed > .img {
    flex: 1;
    min-height: 0;

    width: 100%;

    background: #fff;
    overflow: hidden;
}

section#popupWrap > article > .popup-fixed > .img > a {
    display: block;

    width: 100%;
    height: 100%;
}

section#popupWrap img {
    display: block;

    width: 100%;
    height: 100%;

    object-fit: contain;
    object-position: center;
}

.popup-image {
    width: 100%;
    height: 100%;

    object-fit: contain;
    object-position: center;
}


/* =========================================================
   탭 팝업
========================================================= */
section#popupWrap .tabs-container {
    display: flex;
    flex: 1;
    flex-direction: column;

    width: 100%;
    min-height: 0;

    background: #fff;
    overflow: hidden;
}

section#popupWrap .tabs-header {
    display: flex;
    flex-shrink: 0;

    width: 100%;
    min-height: 42px;

    background: #f5f5f5;
    border-bottom: 2px solid #e0e0e0;
}

section#popupWrap .tab {
    flex: 1;
    min-width: 0;

    padding: 10px;
    margin-bottom: -2px;

    color: #666;
    font-size: 12px;
    font-weight: 600;
    line-height: 20px;
    text-align: center;

    background: transparent;
    border: 0;
    border-bottom: 3px solid transparent;

    cursor: pointer;
    user-select: none;

    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;

    transition:
        color 0.3s ease,
        background 0.3s ease,
        border-color 0.3s ease;
}

section#popupWrap .tab:hover {
    color: #333;
    background: #ececec;
}

section#popupWrap .tab.active {
    color: #000;

    background: #fff;
    border-bottom-color: #0868c9;
}

section#popupWrap .tabs-content {
    position: relative;

    flex: 1;

    width: 100%;
    min-height: 0;

    overflow: hidden;
}

section#popupWrap .tab-content {
    display: none;

    width: 100%;
    height: 100%;

    font-size: 0;
    line-height: 0;

    animation: fadeIn 0.3s ease;
}

section#popupWrap .tab-content.active {
    display: block;
}

section#popupWrap .tab-content > a {
    display: block;

    width: 100%;
    height: 100%;
}

section#popupWrap .tabs-content img {
    display: block;

    width: 100%;
    height: 100%;

    object-fit: contain;
    object-position: center;
}


/* =========================================================
   하단 버튼
========================================================= */
.popup-buttons {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: space-between;
    gap: 8px;

    min-height: 52px;
    padding: 8px;

    background: #eee;
    border-radius: 0 0 12px 12px;
}

span.popup-btn {
    display: inline-flex;
    align-items: center;

    padding: 8px 12px;

    color: #777;
    font-size: 14px;
    font-weight: 400;
    line-height: 20px;

    border: none;
    border-radius: 4px;

    cursor: pointer;
    user-select: none;

    transition:
        color 0.2s ease,
        background 0.2s ease;
}

span.popup-btn > i {
    margin-right: 3px;
    font-size: 16px;
}

span.popup-btn:hover {
    color: #111;
}

button.popup-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    padding: 8px 14px;

    color: #555;
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    line-height: 20px;

    border: none;
    border-radius: 4px;

    cursor: pointer;

    transition:
        color 0.2s ease,
        background 0.2s ease;
}

.popup-btn-hide {
    color: #555 !important;
    background: #fff;
}

.popup-btn-hide:hover {
    color: #111 !important;
    background: #f0f0f0;
}

.popup-btn-close {
    color: #555 !important;
    background: rgba(255, 255, 255, 0.8);
}

.popup-btn-close:hover {
    color: #111 !important;
    background: #fff;
}


/* =========================================================
   우측 상단 닫기 버튼
========================================================= */
.popup-close-btn {
    position: absolute;
    top: 8px;
    right: 8px;

    display: flex;
    align-items: center;
    justify-content: center;

    width: 28px;
    height: 28px;
    padding: 0;

    color: #fff;
    font-family: inherit;
    font-size: 18px;
    line-height: 1;

    background: rgba(0, 0, 0, 0.6);
    border: none;
    border-radius: 50%;

    cursor: pointer;

    transition: background 0.2s ease;
    z-index: 10001;
}

.popup-close-btn:hover {
    background: rgba(0, 0, 0, 0.8);
}


/* =========================================================
   애니메이션
========================================================= */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}


/* =========================================================
   태블릿
========================================================= */
@media (max-width: 1024px) and (min-width: 769px) {
    section#popupWrap {
        left: 3%;

        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 12px;

        width: 94%;
    }
}


/* =========================================================
   모바일
========================================================= */
@media (max-width: 768px) {
    section#popupWrap {
        top: 20px;
        left: 5%;

        display: block;

        width: 90%;
        height: auto;
        max-height: calc(100vh - 40px);
        margin: 0;

        overflow-x: hidden;
        overflow-y: auto;

        /*
         * 실제 팝업 위에서 모바일 세로 스크롤 허용
         */
        touch-action: pan-y;
        -webkit-overflow-scrolling: touch;
    }

    section#popupWrap > article {
        width: 100%;
        height: auto;
        margin-bottom: 15px;
    }

    section#popupWrap > article:last-child {
        margin-bottom: 0;
    }

    section#popupWrap > article > .popup-fixed {
        position: relative;
        top: auto;
        left: auto;

        width: 100%;
        height: auto;
        max-height: calc(100vh - 40px);

        touch-action: pan-y;
    }

    .popup-fixed {
        width: 100%;
        height: auto;
        max-height: calc(100vh - 40px);
    }

    section#popupWrap > article > .popup-fixed > .img {
        flex: none;

        height: auto;
        max-height: calc(100vh - 95px);
    }

    section#popupWrap > article > .popup-fixed > .img > a {
        height: auto;
    }

    section#popupWrap > article > .popup-fixed > .img img {
        width: 100%;
        height: auto;
        max-height: calc(100vh - 95px);

        object-fit: contain;
    }

    section#popupWrap .tabs-container {
        flex: none;

        height: auto;
        max-height: calc(100vh - 95px);
    }

    section#popupWrap .tabs-content {
        flex: none;

        height: auto;
        max-height: calc(100vh - 140px);
    }

    section#popupWrap .tab-content.active {
        height: auto;
    }

    section#popupWrap .tab-content > a {
        height: auto;
    }

    section#popupWrap .tabs-content img {
        width: 100%;
        height: auto;
        max-height: calc(100vh - 140px);

        object-fit: contain;
    }

    section#popupWrap .tab {
        padding: 8px 5px;

        font-size: 11px;
    }

    .popup-buttons {
        min-height: 46px;
        padding: 7px 8px;
    }

    span.popup-btn {
        padding: 4px 6px;

        font-size: 12px;
    }

    span.popup-btn > i {
        font-size: 14px;
    }

    button.popup-btn {
        padding: 5px 10px;

        font-size: 12px;
    }
}


/* =========================================================
   작은 모바일
========================================================= */
@media (max-width: 380px) {
    section#popupWrap {
        left: 3%;

        width: 94%;
    }

    section#popupWrap .tab {
        padding: 7px 3px;

        font-size: 10px;
    }

    .popup-buttons {
        gap: 4px;
        padding: 6px;
    }

    span.popup-btn {
        padding: 4px;

        font-size: 11px;
    }

    button.popup-btn {
        padding: 5px 8px;

        font-size: 11px;
    }
}