/* 하룹팝업 프론트엔드 스타일 - 최적화 버전 */

/* CSS 변수 정의 - 기본값 */
:root {
    --popup-padding: 20px;
    --popup-gap: 10px;
    --popup-radius: 10px;
    --popup-bg: #ffffff;
    --popup-border-width: 0px;
    --popup-border-color: #dddddd;
    --popup-text: #333333;
    --popup-text-hover: #666666;
    --popup-button-bg: #333333;
    --popup-button-text: #ffffff;
    --popup-button-hover: #555555;
    --popup-button-text-hover: #ffffff;
    --popup-font-size: 14px;
    --popup-font-weight: normal;
    --popup-line-height: 1.5;
    --popup-letter-spacing: 0px;
    --popup-text-transform: none;
    --popup-tab-gap: 5px;
    --popup-tab-margin: 15px;
    --popup-footer-margin: 15px;
    --popup-tab-bg: #f8f8f8;
    --popup-tab-bg-hover: #e8e8e8;
    --popup-tab-bg-active: #333333;
    --popup-tab-text: #999999;
    --popup-tab-text-hover: #666666;
    --popup-tab-text-active: #ffffff;
    --popup-box-shadow-offset: 5px;
    --popup-box-shadow-blur: 30px;
    --popup-box-shadow-color: rgba(0, 0, 0, 0.3);
}

/* 오버레이 */
.haroop-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 99998;
    display: none;
}

/* 디바이스별 표시 제어 */
.haroop-popup:not(.haroop-preview-popup) {
    display: none;
}

.haroop-popup.haroop-popup-active {
    display: block !important;
}

/* 미리보기 팝업 */
.haroop-preview-viewport .haroop-popup,
.haroop-preview-popup {
    display: block !important;
}

/* 기본 팝업 스타일 */
.haroop-popup {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    width: 600px;
    max-width: 95%;
    max-height: 90vh;
    overflow: auto;
    z-index: 99999 !important;
    padding: var(--popup-padding);
    border-radius: var(--popup-radius);
    background: var(--popup-bg);
    color: var(--popup-text);
    font-size: var(--popup-font-size);
    font-weight: var(--popup-font-weight);
    line-height: var(--popup-line-height);
    letter-spacing: var(--popup-letter-spacing);
    text-transform: var(--popup-text-transform);
    border: var(--popup-border-width) solid var(--popup-border-color);
    box-shadow: var(--popup-box-shadow-offset) var(--popup-box-shadow-offset) var(--popup-box-shadow-blur) var(--popup-box-shadow-color);
}

/* 이미지 스타일 */
.haroop-popup img,
.haroop-popup-image {
    max-width: 100%;
    height: auto;
    display: block;
}

.haroop-popup a {
    display: block;
    line-height: 0;
}

/* 슬라이드형 팝업 */
.haroop-popup-slide {
    padding: var(--popup-padding);
}

.haroop-popup-slide .haroop-slide-container {
    position: relative;
    border-radius: var(--popup-radius) var(--popup-radius) 0 0;
    overflow: hidden;
}

.haroop-popup-slide .haroop-slide {
    display: none;
}

.haroop-popup-slide .haroop-slide:first-child,
.haroop-popup-slide .haroop-slide.active {
    display: block;
}

/* 이미지와 푸터 사이 간격 */
.haroop-popup-slide .haroop-slide-container + .haroop-popup-footer {
    margin-top: var(--popup-footer-margin);
}

/* 슬라이드 컨트롤 */
.haroop-slide-controls {
    display: flex;
    gap: var(--popup-tab-gap);
    margin-bottom: var(--popup-tab-margin);
    position: relative;
    z-index: 10;
}

/* 슬라이드 버튼 */
.haroop-slide-button {
    flex: 1;
    padding: 10px 15px;
    background: var(--popup-tab-bg);
    color: var(--popup-tab-text);
    border: none;
    cursor: pointer;
    transition: all 0.3s ease;
    border-radius: var(--popup-radius);
    font-size: var(--popup-font-size);
    font-weight: var(--popup-font-weight);
    line-height: var(--popup-line-height);
    letter-spacing: var(--popup-letter-spacing);
    text-transform: var(--popup-text-transform);
}

.haroop-slide-button:hover {
    background: var(--popup-tab-bg-hover);
    color: var(--popup-tab-text-hover);
}

.haroop-slide-button.active {
    background: var(--popup-tab-bg-active);
    color: var(--popup-tab-text-active);
}

/* 일반형 팝업 */
.haroop-popup-general {
    padding: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    border: none !important;
    width: auto; /* 기본 width 오버라이드 - !important 제거 */
    max-width: 90vw; /* 기본 최대 너비 */
}

/* 이미지 개수에 따른 그리드 레이아웃만 설정 */
/* JavaScript에서 너비 조정 */

/* 1개 이미지 */
[data-image-count="1"] .haroop-general-container {
    grid-template-columns: 1fr;
    max-width: 100%;
}

[data-image-count="1"] .haroop-general-item {
    max-width: 100%;
    margin: 0 auto;
}

/* 2개 이미지 */
[data-image-count="2"] .haroop-general-container {
    grid-template-columns: repeat(2, 1fr);
    max-width: 100%;
}

/* 3개 이미지 */
[data-image-count="3"] .haroop-general-container {
    grid-template-columns: repeat(3, 1fr);
}

/* 4개 이상 - 3개씩 줄바꿈 */
[data-image-count="4"] .haroop-general-container,
[data-image-count="5"] .haroop-general-container,
[data-image-count="6"] .haroop-general-container {
    grid-template-columns: repeat(3, 1fr);
}

.haroop-general-container {
    display: grid;
    gap: var(--popup-gap);
    width: 100%;
    margin-bottom: var(--popup-footer-margin);
}

.haroop-general-item {
    background: var(--popup-bg);
    border-radius: var(--popup-radius);
    border: var(--popup-border-width) solid var(--popup-border-color);
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    position: relative;
    display: flex;
    flex-direction: column;
}

/* 일반팝업 아이템 내 이미지 */
.haroop-general-item img {
    width: 100%;
    height: auto;
    display: block;
    flex-grow: 1;
}

/* 일반팝업 아이템 내 이미지와 버튼 사이 간격 */
.haroop-general-item img + .haroop-popup-footer,
.haroop-general-item a + .haroop-popup-footer {
    margin-top: var(--popup-footer-margin);
}

/* 일반형 레이아웃 - 자동 균등 분배 */
/* 1개일 때 */
.haroop-layout-1row .haroop-general-container:has(.haroop-general-item:nth-child(1)):not(:has(.haroop-general-item:nth-child(2))) {
    grid-template-columns: 1fr;
}

/* 2개일 때 */
.haroop-layout-1row .haroop-general-container:has(.haroop-general-item:nth-child(2)):not(:has(.haroop-general-item:nth-child(3))) {
    grid-template-columns: repeat(2, 1fr);
}

/* 3개일 때 */
.haroop-layout-1row .haroop-general-container:has(.haroop-general-item:nth-child(3)):not(:has(.haroop-general-item:nth-child(4))) {
    grid-template-columns: repeat(3, 1fr);
}

/* 기본값 - 3개 이하일 때 */
.haroop-layout-1row .haroop-general-container {
    grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
    width: 100%;
}

/* 4개 이상일 때 - 3개씩 줄바꿈 */
.haroop-layout-2rows .haroop-general-container {
    grid-template-columns: repeat(3, 1fr);
    width: 100%;
}

/* 열 개수 지정 레이아웃 */
.haroop-layout-cols-1 .haroop-general-container {
    grid-template-columns: 1fr;
}

.haroop-layout-cols-2 .haroop-general-container {
    grid-template-columns: repeat(2, 1fr);
}

.haroop-layout-cols-3 .haroop-general-container {
    grid-template-columns: repeat(3, 1fr);
}

.haroop-layout-cols-4 .haroop-general-container {
    grid-template-columns: repeat(4, 1fr);
}

/* 팝업 푸터 */
.haroop-popup-footer {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: var(--popup-footer-margin);
}

.haroop-popup-slide .haroop-popup-footer {
    margin: 0;
    padding: 0;
    background: var(--popup-button-bg);
    border-radius: 0 0 var(--popup-radius) var(--popup-radius);
    overflow: hidden;
    gap: 0;
}

.haroop-general-item .haroop-popup-footer {
    margin: 0;
    padding: 0;
    background: var(--popup-button-bg);
    gap: 0;
}

/* 버튼 스타일 */
.haroop-popup-footer button,
.haroop-popup-footer a {
    padding: 10px 20px;
    background: var(--popup-button-bg);
    color: var(--popup-button-text);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    transition: background 0.3s ease;
    font-size: var(--popup-font-size);
    font-weight: var(--popup-font-weight);
    line-height: normal;
    letter-spacing: var(--popup-letter-spacing);
    text-transform: var(--popup-text-transform);
}

.haroop-popup-slide .haroop-popup-footer button,
.haroop-popup-slide .haroop-popup-footer a,
.haroop-general-item .haroop-popup-footer button,
.haroop-general-item .haroop-popup-footer a {
    flex: 1;
    background: transparent;
    border-radius: 0;
    margin: 0;
    padding: 12px 15px;
}

.haroop-popup-slide .haroop-popup-footer button:not(:last-child),
.haroop-popup-slide .haroop-popup-footer a:not(:last-child),
.haroop-general-item .haroop-popup-footer button:not(:last-child),
.haroop-general-item .haroop-popup-footer a:not(:last-child) {
    border-right: 1px solid rgba(255, 255, 255, 0.2);
}

.haroop-popup-footer button:hover,
.haroop-popup-footer a:hover {
    background: var(--popup-button-hover);
    color: var(--popup-button-text-hover);
}

/* 자세히 보기 링크 */
.haroop-popup-detail {
    display: flex !important;
    align-items: center;
    justify-content: center;
    line-height: normal !important;
}

/* 전체 닫기 버튼 */
.haroop-global-close {
    text-align: center;
    margin-top: 20px;
}

.haroop-global-close-bottom-wrap {
    grid-column: 1 / -1;
    text-align: center;
    margin-top: 20px;
}

.haroop-global-close-bottom {
    padding: 12px 30px;
    background: var(--popup-button-bg);
    color: var(--popup-button-text);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.3s ease;
    font-size: 14px;
    font-weight: 500;
}

.haroop-global-close-bottom:hover {
    background: var(--popup-button-hover);
    color: var(--popup-button-text-hover);
}

/* ==================== 프리셋 스타일 ==================== */

/* 기본형 프리셋 - CSS 변수만 설정 */
.haroop-preset-default {
    --popup-padding: 20px;
    --popup-radius: 10px;
    --popup-border-width: 0px;
    --popup-bg: #ffffff;
    --popup-text: #333333;
    --popup-button-bg: #333333;
    --popup-button-text: #ffffff;
    --popup-button-hover: #555555;
    --popup-button-text-hover: #ffffff;
    --popup-tab-bg: #f8f8f8;
    --popup-tab-bg-hover: #e8e8e8;
    --popup-tab-bg-active: #333333;
    --popup-tab-text: #999999;
    --popup-tab-text-hover: #666666;
    --popup-tab-text-active: #ffffff;
    --popup-tab-gap: 5px;
    --popup-tab-margin: 15px;
    --popup-footer-margin: 15px;
    --popup-box-shadow-offset: 5px;
    --popup-box-shadow-blur: 30px;
    --popup-box-shadow-color: rgba(0, 0, 0, 0.3);
}

/* 모던형 프리셋 */
.haroop-preset-modern {
    --popup-padding: 0px;
    --popup-radius: 0px;
    --popup-bg: #ffffff;
    --popup-text: #000000;
    --popup-font-weight: 300;
    --popup-line-height: 1.6;
    --popup-letter-spacing: 0.5px;
    --popup-button-bg: #000000;
    --popup-button-text: #ffffff;
    --popup-button-hover: #333333;
    --popup-button-text-hover: #ffffff;
    --popup-tab-bg: #f5f5f5;
    --popup-tab-bg-hover: #e0e0e0;
    --popup-tab-bg-active: #000000;
    --popup-tab-text: #999999;
    --popup-tab-text-hover: #666666;
    --popup-tab-text-active: #ffffff;
    --popup-tab-gap: 0px;
    --popup-tab-margin: 0px;
    --popup-footer-margin: 0px;
    --popup-box-shadow-offset: 0px;
    --popup-box-shadow-blur: 50px;
    --popup-box-shadow-color: rgba(0, 0, 0, 0.5);
}

.haroop-preset-modern .haroop-slide-container,
.haroop-preset-modern .haroop-general-container {
    margin-left: calc(var(--popup-padding) * -1);
    margin-right: calc(var(--popup-padding) * -1);
    margin-bottom: 0;
}

.haroop-preset-modern .haroop-popup-footer {
    margin-left: calc(var(--popup-padding) * -1);
    margin-right: calc(var(--popup-padding) * -1);
    margin-bottom: calc(var(--popup-padding) * -1);
}

/* 미니멀형 프리셋 */
.haroop-preset-minimal {
    --popup-padding: 30px;
    --popup-radius: 0px;
    --popup-border-width: 1px;
    --popup-border-color: #e0e0e0;
    --popup-bg: #ffffff;
    --popup-text: #666666;
    --popup-font-size: 13px;
    --popup-line-height: 1.8;
    --popup-button-bg: transparent;
    --popup-button-text: #666666;
    --popup-button-hover: #333333;
    --popup-button-text-hover: #ffffff;
    --popup-tab-bg: transparent;
    --popup-tab-bg-hover: #f9f9f9;
    --popup-tab-bg-active: #f5f5f5;
    --popup-tab-text: #999999;
    --popup-tab-text-hover: #666666;
    --popup-tab-text-active: #000000;
    --popup-tab-gap: 10px;
    --popup-tab-margin: 20px;
    --popup-footer-margin: 20px;
    --popup-box-shadow-offset: 0px;
    --popup-box-shadow-blur: 0px;
    --popup-box-shadow-color: transparent;
}

.haroop-preset-minimal .haroop-slide-button {
    border: 1px solid #e0e0e0;
}

.haroop-preset-minimal .haroop-slide-button.active {
    border-color: #666666;
}

.haroop-preset-minimal .haroop-popup-footer {
    border-top: 1px solid #e0e0e0;
    padding-top: 15px;
}

.haroop-preset-minimal .haroop-popup-overlay {
    background-color: rgba(255, 255, 255, 0.95);
}

/* ==================== 미디어 쿼리 ==================== */

@media (max-width: 768px) {
    .haroop-popup {
        width: 90%;
        max-width: 400px;
        padding: 15px;
    }
    
    .haroop-slide-controls {
        flex-wrap: wrap;
    }
    
    .haroop-slide-button {
        padding: 8px 12px;
        font-size: 12px;
    }
    
    .haroop-general-item {
        min-width: 100%;
    }
    
    .haroop-popup-footer {
        flex-direction: column;
    }
    
    .haroop-popup-footer button,
    .haroop-popup-footer a {
        width: 100%;
    }
}

/* ==================== 애니메이션 ==================== */

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

@keyframes haroopSlideUp {
    from {
        transform: translate(-50%, -40%);
        opacity: 0;
    }
    to {
        transform: translate(-50%, -50%);
        opacity: 1;
    }
}

.haroop-popup {
    animation: haroopSlideUp 0.3s ease;
}

.haroop-popup-overlay {
    animation: haroopFadeIn 0.3s ease;
}

/* ==================== 스크롤바 스타일 ==================== */

.haroop-popup::-webkit-scrollbar {
    width: 8px;
}

.haroop-popup::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.haroop-popup::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.haroop-popup::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* ==================== 디버그 모드 ==================== */

.haroop-popup-debug {
    border: 2px solid red;
}

.haroop-popup-debug::before {
    content: 'DEBUG MODE';
    position: absolute;
    top: 0;
    left: 0;
    background: red;
    color: white;
    padding: 2px 5px;
    font-size: 10px;
    z-index: 100000;
}

/* ==================== 프린트 시 숨김 ==================== */

@media print {
    .haroop-popup,
    .haroop-popup-overlay {
        display: none !important;
    }
}