/**
 * PC Web · 듀얼스크린 레이아웃 (DEV-1987 / DP-375)
 *
 * 기존 화면 CSS 는 건드리지 않고 html.pc-layout 아래에서만 덮어쓴다
 * #wrap 이 없는 화면(결제 팝업 등)은 :has(#wrap) 조건에 걸리지 않아 기존 그대로 보인다
 *
 * 구간
 *  - 1단: 폭 744 미만 또는 높이 480 미만 → 가운데 화면만, 상한 480
 *  - 2단: 폭 744 이상 1224 미만 (앱은 744 이상 전체) → A Side + 가운데 화면, 744~960 반반 분할
 *  - 3단: 폭 1224 이상, 앱 아님 → A Side + 가운데 화면(480) + B Side
 *
 * 2·3단은 body 를 가운데 화면 자리로 옮기고 contain: layout 으로 position: fixed 의 기준을 body 로 바꾼다
 * 그래서 기존 바텀시트·모달·딤·뷰어는 수정 없이 가운데 화면 안에 맞는다
 */

:root {
    --pc-main-max: 480px;
    --pc-side-inner: 372px;

    /* 프로젝트 팔레트에 없는 Figma 색 */
    --pc-bg: #F2F6FD;
    --pc-heading-color: #17243D;
    --pc-chip-border: #E8E8E8;
    --pc-chip-text: #181D27;
    --pc-highlight-gradient: linear-gradient(135deg, var(--primary-color) 0%, #00EAFF 100%);
}

/* 양옆 영역은 2·3단에서만 노출 */
.pc-side {
    display: none;
}

html.pc-layout:has(#wrap) {
    background: var(--pc-bg);

    body {
        background: var(--pc-bg);
    }

    /* 1단 포함 전 구간: 기존 390 상한 → 480 */
    :is(#wrap, #top, #transferTop, .header, .footer--msg,
        .modal--sec.bottom, .input-modal, .fullsheet,
        .amount-sheet-panel, .list-modal-panel, .comment-write-modal-sheet,
        .badge-detail-sheet, .badge-nudge-sheet, .register-splash,
        .secure-keypad-modal, .toss-modal-content, .vo-postcode-layer,
        #iv2-overlay, #vv-overlay, .filter-overlay, .bottom-sheet-panel, .setting-done, .max-w-540,
        .date-range-modal .modal-content, .dolgo-terms-modal-content, .dolgo-terms-detail-content) {
        max-width: var(--pc-main-max) !important;
    }
}

/* ===== 2단 (앱은 1224 이상도 여기까지만) · 인쇄물에는 적용하지 않음 ===== */
@media screen and (min-width: 744px) and (min-height: 480px) {
    html.pc-layout:has(#wrap) {
        --pc-mobile-w: clamp(372px, 50vw, var(--pc-main-max));
        --pc-aside-w: var(--pc-mobile-w);
        --pc-gap: clamp(0px, 100vw - 2 * var(--pc-main-max), 40px);
        --pc-group: calc(var(--pc-aside-w) + var(--pc-gap) + var(--pc-mobile-w));
        --pc-mobile-x: calc((100vw - var(--pc-group)) / 2 + var(--pc-aside-w) + var(--pc-gap));

        body {
            width: var(--pc-mobile-w);
            margin-left: var(--pc-mobile-x);
            contain: layout;
            /*
             * contain 이 걸린 body 는 overflow 가 화면으로 넘어가지 않고 body 자체를 잘라 바깥의 양옆 영역이 사라진다
             * 모달을 열 때 body 에 overflow: hidden/auto 를 거는 기존 코드가 많아(hscms.js·toss-payments.js·common-script.js,
             * badge-detail-open 등 클래스) 항상 visible 로 고정한다. 스크롤은 #innerCnt 안에서만 일어나 영향 없음
             */
            overflow: visible !important;
        }

        /* body(가운데 칸) 폭을 꽉 채움 */
        :is(#wrap, #top, #transferTop, .header, .footer--msg,
            .modal--sec.bottom, .input-modal, .fullsheet,
            .amount-sheet-panel, .list-modal-panel, .comment-write-modal-sheet,
            .badge-detail-sheet, .badge-nudge-sheet, .register-splash,
            .secure-keypad-modal, .toss-modal-content, .vo-postcode-layer,
            #iv2-overlay, #vv-overlay, .filter-overlay, .bottom-sheet-panel, .setting-done, .max-w-540,
            .date-range-modal .modal-content, .dolgo-terms-modal-content, .dolgo-terms-detail-content) {
            max-width: 100% !important;
        }

        /*
         * 화면 좌표를 그대로 position: fixed 에 넣는 팝업은 body 이동 거리만큼 어긋나므로 되돌린다
         * (fragments/tooltip.js, fragments/moreMenu.js, text-popover.js)
         */
        .tooltip-pop,
        .more-menu-pop[style*="position: fixed"],
        [id$="Popover"][style*="position: fixed"] {
            translate: calc(-1 * var(--pc-mobile-x)) 0;
        }

        /*
         * 외부 SDK 가 body 에 붙이는 화면 전체 레이어는 가운데 칸에 갇히므로 화면 전체로 되돌린다
         * 토스페이먼츠 v2: 결제창·결제 위젯 결제창·브랜드페이 dimmer (인라인 스타일이라 !important)
         */
        #__tosspayments_payment-gateway_dimmer__,
        #__tosspayments_payment_widget_window_dimmer__,
        #___tosspayments_brandpay_dimmer___ {
            left: calc(-1 * var(--pc-mobile-x)) !important;
            width: 100vw !important;
        }

        .pc-side {
            position: fixed;
            top: 0;
            bottom: 0;
            z-index: 0;
            display: flex;
            justify-content: center;
            overflow-y: auto;
            box-sizing: border-box;
            /* history-guard.js 는 bfcache 로 들어가는 페이지를 떠날 때 html 을 visibility:hidden 으로 숨긴다
               새 페이지가 그려지기 전까지 그 숨긴 화면이 50~100ms 보여 양옆이 깜빡이므로, 양옆은 항상 보이게 둔다
               (양옆 내용은 어느 페이지든 같아 뒤로 가기 판단 중에 보여도 문제없다) */
            visibility: visible;
        }

        .pc-side-a {
            left: calc(-1 * (var(--pc-aside-w) + var(--pc-gap)));
            width: var(--pc-aside-w);
            /* 세로 가운데, 높이가 모자라면 위에서부터 스크롤 */
            align-items: safe center;
        }

        /* B Side 는 3단에서만 */
        .pc-side-b {
            display: none;
        }
    }
}

/*
 * 페이지 전환 깜빡임은 양옆 마크업을 body 맨 앞에 두는 것으로 해결한다 (layout/default.html)
 * Cross-document View Transitions 는 뒤로 가기(bfcache 복원) 때 양옆 뒤로 흰 스냅샷 박스가 0.2초 보여 쓰지 않는다
 */

/* ===== 3단 ===== */
@media screen and (min-width: 1224px) and (min-height: 480px) {
    html.pc-layout:not(.pc-no-bside):has(#wrap) {
        --pc-aside-w: var(--pc-side-inner);
        --pc-mobile-w: var(--pc-main-max);
        --pc-gap: clamp(0px, (100vw - 1224px) / 2, 40px);
        --pc-mobile-x: calc((100vw - var(--pc-mobile-w)) / 2);

        .pc-side-b {
            display: flex;
            left: calc(100% + var(--pc-gap));
            width: var(--pc-aside-w);
        }
    }
}

/* ===== 양옆 영역 공통 ===== */
.pc-side-inner {
    display: flex;
    flex-direction: column;
    width: var(--pc-side-inner);
    padding: 0 10px;
    box-sizing: border-box;
    flex-shrink: 0;
}

/* ===== A Side: 기부·봉사 탐색 ===== */
.pc-side-a {
    .pc-side-inner {
        padding-top: 24px;
        padding-bottom: 24px;
    }

    .pc-explore-title {
        margin: 0;
        font-size: 36px;
        font-weight: 800;
        line-height: 50px;
        color: var(--primary9-color);
    }

    .pc-explore-tab {
        display: inline-flex;
        align-self: flex-start;
        gap: 4px;
        margin-top: 40px;
        padding: 4px;
        border-radius: 9999px;
        background: var(--gray-100);

        button {
            height: 36px;
            padding: 0 20px;
            border: 0;
            border-radius: 9999px;
            background: transparent;
            font-size: 15px;
            font-weight: 500;
            color: var(--gray-500);
            cursor: pointer;
        }
    }

    .pc-search {
        display: flex;
        align-items: center;
        gap: 8px;
        height: 56px;
        margin-top: 12px;
        padding: 0 6px 0 22px;
        border: 1px solid var(--gray-100);
        border-radius: 9999px;
        background: var(--white-color);
        box-sizing: border-box;

        input {
            flex: 1;
            min-width: 0;
            border: 0;
            outline: none;
            background: transparent;
            font-size: 15px;
            color: var(--gray-900);

            &::placeholder {
                color: var(--gray-400);
            }

            &::-webkit-search-cancel-button {
                display: none;
            }
        }

        .pc-search-btn {
            display: flex;
            align-items: center;
            justify-content: center;
            flex-shrink: 0;
            width: 44px;
            height: 44px;
            padding: 0;
            border: 0;
            border-radius: 9999px;
            background: var(--primary-color);
            cursor: pointer;

            /* 기존 회색 검색 아이콘을 mask 로 재사용해 흰색으로 칠한다 (24px 원본을 18px 로 → 돋보기 15px, Figma 와 동일) */
            .pc-search-icon {
                width: 18px;
                height: 18px;
                background-color: var(--white-color);
                -webkit-mask: url('/assets/images/icon/ic-ds-search-gray-400-fb68b116158a1c0713c7e4a2324a9761.svg') center / contain no-repeat;
                mask: url('/assets/images/icon/ic-ds-search-gray-400-fb68b116158a1c0713c7e4a2324a9761.svg') center / contain no-repeat;
            }
        }
    }

    .pc-explore-panel {
        display: none;
        margin-top: 28px;

        .pc-explore-label {
            margin: 0 0 12px;
            font-size: 14px;
            font-weight: 600;
            line-height: 17px;
            color: var(--gray-800);
        }

        .pc-chip-list {
            display: flex;
            flex-wrap: wrap;
            gap: 12px 8px;

            .pc-chip {
                display: inline-flex;
                align-items: center;
                height: 42px;
                padding: 0 17px;
                border: 1px solid var(--pc-chip-border);
                border-radius: 9999px;
                background: var(--white-color);
                box-sizing: border-box;
                font-size: 15px;
                font-weight: 500;
                color: var(--pc-chip-text);
                text-decoration: none;
                white-space: nowrap;

                &.highlight {
                    border: 1px solid transparent;
                    background: linear-gradient(var(--white-color), var(--white-color)) padding-box,
                                var(--pc-highlight-gradient) border-box;
                    font-weight: 600;

                    span {
                        background: var(--pc-highlight-gradient);
                        -webkit-background-clip: text;
                        background-clip: text;
                        color: transparent;
                    }
                }
            }
        }
    }
}

/*
 * 선택 탭: 세션 값으로 pc-layout.js 가 렌더 전에 html.pc-tab-volunteer 를 붙인다 (페이지를 옮겨도 깜빡임 없이 유지)
 */
html:not(.pc-tab-volunteer) .pc-side-a [data-pc-tab="donation"],
html.pc-tab-volunteer .pc-side-a [data-pc-tab="volunteer"] {
    background: var(--white-color);
    font-weight: 700;
    color: var(--gray-900);
    box-shadow: 0 1px 2px rgba(17, 24, 39, 0.08);
}

html:not(.pc-tab-volunteer) .pc-side-a [data-pc-panel="donation"],
html.pc-tab-volunteer .pc-side-a [data-pc-panel="volunteer"] {
    display: block;
}

/* ===== B Side: 참여·문의, 앱 다운로드 ===== */
.pc-side-b {
    .pc-side-inner {
        min-height: 100%;
        padding-top: 24px;
        padding-bottom: clamp(24px, 14vh, 138px);
    }

    .pc-side-heading {
        margin: 0;
        font-size: 18px;
        font-weight: 700;
        line-height: 25px;
        color: var(--pc-heading-color);
    }

    .pc-join {
        margin: auto 0;
        padding-bottom: 40px;

        .pc-side-heading {
            margin-bottom: 12px;
        }

        .pc-join-item {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 16px;
            padding: 18px 0;
            border-top: 1px solid var(--pc-chip-border);

            &:last-child {
                border-bottom: 1px solid var(--pc-chip-border);
            }

            .pc-join-name {
                margin: 0;
                font-size: 15px;
                font-weight: 700;
                line-height: 18px;
                color: var(--pc-heading-color);
            }

            .pc-join-desc {
                margin: 4px 0 0;
                font-size: 13px;
                line-height: 16px;
                color: var(--gray-700);
            }

            .pc-join-cta {
                display: inline-flex;
                align-items: center;
                gap: 2px;
                flex-shrink: 0;
                font-size: 13px;
                font-weight: 600;
                line-height: 16px;
                color: var(--primary-color);
                text-decoration: none;

                img {
                    width: 14px;
                    height: 14px;
                }
            }
        }
    }

    .pc-app {
        .pc-side-heading {
            margin-bottom: 12px;
        }

        .pc-app-row {
            display: flex;
            align-items: flex-end;
            justify-content: space-between;

            .pc-app-stores {
                display: flex;
                flex-direction: column;
                gap: 12px;

                a {
                    display: block;
                    width: 210px;
                    height: 60px;
                    border-radius: 12px;
                    overflow: hidden;
                    background: var(--white-color);
                }

                img {
                    display: block;
                    width: 100%;
                    height: 100%;
                    object-fit: contain;
                }
            }

            .pc-app-qr {
                width: 132px;
                height: 132px;
                border-radius: 12px;
                background: var(--white-color);
            }
        }
    }
}
