/* ============================================ */
/* Doosan Popup System                         */
/* Desktop: bottom-left floating card          */
/* Mobile:  bottom sheet with backdrop         */
/* ============================================ */

/* Mobile: lock background scroll when popup is open
   (html 요소에 적용해야 iOS Safari에서도 동작) */
@media (max-width: 640px) {
    html.dr-popup-open,
    html.dr-popup-open body {
        overflow: hidden !important;
    }
}

/* --- Reset main.css base .main-popup --- */
.main-popup.dr-popup-v2 {
    position: fixed;
    bottom: 32px;
    left: 32px;
    top: auto;
    right: auto;
    width: auto;
    height: auto;
    display: block;
    align-items: initial;
    justify-content: initial;
    padding: 0;
    z-index: 1000;
    pointer-events: none;
}

/* --- Backdrop (desktop: hidden) --- */
.dr-popup-v2 .dr-backdrop {
    display: none;
}

/* --- Card --- */
.dr-popup-v2 .dr-popup-card {
    pointer-events: auto;
    position: relative;
    display: flex;
    flex-direction: column;
    width: fit-content;
    max-width: min(520px, calc(100vw - 48px));
    max-height: calc(100vh - 64px);
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow:
        0 8px 40px rgba(0, 0, 0, .18),
        0 2px 8px rgba(0, 0, 0, .06);
    opacity: 0;
    transform: translateY(24px);
    animation: drPopupSlideIn .45s cubic-bezier(.22, .61, .36, 1) forwards;
}

@keyframes drPopupSlideIn {
    to { opacity: 1; transform: translateY(0); }
}

/* --- Sheet handle (desktop: hidden) --- */
.dr-popup-v2 .dr-sheet-handle {
    display: none;
}

/* --- Carousel slides --- */
.dr-popup-v2 .dr-slides {
    position: relative;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* Thin scrollbar (desktop) */
.dr-popup-v2 .dr-slides::-webkit-scrollbar { width: 4px; }
.dr-popup-v2 .dr-slides::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, .15);
    border-radius: 4px;
}
.dr-popup-v2 .dr-slides::-webkit-scrollbar-track { background: transparent; }

/* Prevent nested scroll from DB-stored popup HTML (inline styles) */
.dr-popup-v2 .popup-html-content > div {
    max-height: none !important;
    overflow-y: visible !important;
}

.dr-popup-v2 .dr-slide {
    display: none;
    width: 100%;
}

.dr-popup-v2 .dr-slide.active {
    display: block;
    animation: drFadeIn .35s ease;
}

@keyframes drFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* --- Image slide: scale to fit, card adapts to image size --- */
.dr-popup-v2 .dr-slide > img,
.dr-popup-v2 .dr-slide > a > img {
    display: block;
    max-width: 100%;
    height: auto;
    max-height: calc(100vh - 130px);
    margin: 0 auto;
}

/* --- HTML content slide --- */
.dr-popup-v2 .dr-slide .popup-html-content {
    min-height: 200px;
}

/* --- Bottom control bar --- */
.dr-popup-v2 .dr-popup-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: 52px;
    border-top: 1px solid #eee;
    background: #fafafa;
    flex-shrink: 0;
}

/* Nav: arrows + dots */
.dr-popup-v2 .dr-popup-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dr-popup-v2 .dr-popup-nav.hidden {
    visibility: hidden;
}

.dr-popup-v2 .dr-nav-arrow {
    width: 28px;
    height: 28px;
    border: none;
    background: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: background .15s;
    color: #333;
    padding: 0;
}

.dr-popup-v2 .dr-nav-arrow:hover {
    background: #e8e8e8;
}

.dr-popup-v2 .dr-nav-arrow svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.dr-popup-v2 .dr-dots {
    display: flex;
    gap: 6px;
    align-items: center;
}

.dr-popup-v2 .dr-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #ccc;
    border: none;
    padding: 0;
    cursor: pointer;
    transition: background .2s, transform .2s;
}

.dr-popup-v2 .dr-dot.active {
    background: #005EB8;
    transform: scale(1.25);
}

/* Action buttons */
.dr-popup-v2 .dr-popup-actions {
    display: flex;
    align-items: center;
    gap: 0;
}

.dr-popup-v2 .dr-popup-actions button {
    border: none;
    background: none;
    cursor: pointer;
    font-size: 13px;
    color: #666;
    padding: 6px 10px;
    line-height: 1;
    transition: color .15s;
    white-space: nowrap;
}

.dr-popup-v2 .dr-popup-actions button:hover {
    color: #005EB8;
}

.dr-popup-v2 .dr-popup-actions .dr-sep {
    width: 1px;
    height: 14px;
    background: #ddd;
    flex-shrink: 0;
}

/* --- Close X button (top-right) --- */
.dr-popup-v2 .dr-close-x {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(0, 0, 0, .45);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    transition: background .15s;
    padding: 0;
}

.dr-popup-v2 .dr-close-x:hover {
    background: rgba(0, 0, 0, .65);
}

.dr-popup-v2 .dr-close-x svg {
    width: 14px;
    height: 14px;
    stroke: #fff;
    stroke-width: 2.5;
    stroke-linecap: round;
    fill: none;
}

/* ============================================ */
/* Mobile: Bottom Sheet                        */
/* ============================================ */
@media (max-width: 640px) {
    /* Container becomes full-screen overlay */
    .main-popup.dr-popup-v2 {
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        display: flex;
        flex-direction: column;
        justify-content: flex-end;
    }

    /* Backdrop */
    .dr-popup-v2 .dr-backdrop {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0);
        pointer-events: auto;
        animation: drBackdropIn .4s ease forwards;
        z-index: 0;
    }

    @keyframes drBackdropIn {
        to { background: rgba(0, 0, 0, .5); }
    }

    .dr-popup-v2 .dr-backdrop.dr-closing {
        animation: drBackdropOut .3s ease forwards;
    }

    @keyframes drBackdropOut {
        to { background: rgba(0, 0, 0, 0); }
    }

    /* Card becomes bottom sheet */
    .dr-popup-v2 .dr-popup-card {
        position: relative;
        z-index: 1;
        width: 100%;
        max-height: 85vh;
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -4px 32px rgba(0, 0, 0, .12);
        opacity: 1;
        transform: translateY(100%);
        animation: drSheetUp .4s cubic-bezier(.32, .72, 0, 1) forwards;
    }

    @keyframes drSheetUp {
        to { transform: translateY(0); }
    }

    .dr-popup-v2 .dr-popup-card.dr-closing {
        animation: drSheetDown .3s ease forwards;
    }

    @keyframes drSheetDown {
        to { transform: translateY(100%); }
    }

    /* Sheet handle */
    .dr-popup-v2 .dr-sheet-handle {
        display: flex;
        justify-content: center;
        padding: 12px 0 4px;
        flex-shrink: 0;
        cursor: grab;
        touch-action: none;
    }

    .dr-popup-v2 .dr-sheet-handle .dr-handle-pill {
        width: 36px;
        height: 4px;
        background: #d0d0d0;
        border-radius: 2px;
    }

    /* During drag: disable card animation, follow finger */
    .dr-popup-v2 .dr-popup-card.dr-dragging {
        animation: none;
        transition: none;
    }

    /* Close X: lighter style on mobile */
    .dr-popup-v2 .dr-close-x {
        top: 6px;
        right: 12px;
        width: 28px;
        height: 28px;
        background: rgba(0, 0, 0, .08);
    }

    .dr-popup-v2 .dr-close-x svg {
        stroke: #999;
        width: 12px;
        height: 12px;
    }

    /* Hide scrollbar on mobile (use native touch scroll) */
    .dr-popup-v2 .dr-slides::-webkit-scrollbar {
        display: none;
    }
    .dr-popup-v2 .dr-slides {
        scrollbar-width: none;
    }

    /* Image: fill bottom sheet width, height proportional */
    .dr-popup-v2 .dr-slide > img,
    .dr-popup-v2 .dr-slide > a > img {
        width: 100%;
        max-height: none;
    }

    /* Hide arrow buttons on mobile (use swipe) */
    .dr-popup-v2 .dr-nav-arrow {
        display: none;
    }

    /* Bottom bar: iPhone safe area */
    .dr-popup-v2 .dr-popup-bar {
        padding: 0 16px;
        padding-bottom: env(safe-area-inset-bottom, 0);
        height: calc(52px + env(safe-area-inset-bottom, 0));
    }

    /* Larger tap targets on mobile */
    .dr-popup-v2 .dr-popup-actions button {
        font-size: 14px;
        padding: 8px 12px;
    }
}
