/* ============================================================
   Template Gallery Viewer — Modal Styles
   ============================================================ */

/* ----- 모달 오버레이 ----- */
.tgv-modal {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.tgv-modal[aria-hidden="false"] {
    opacity: 1;
    pointer-events: auto;
}

.tgv-modal[aria-hidden="false"] .tgv-modal__container {
    transform: translateY(0);
}

/* ----- backdrop ----- */
.tgv-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    cursor: pointer;
}

/* ----- 모달 컨테이너 ----- */
.tgv-modal__container {
    position: relative;
    z-index: 1;
    width: 90vw;
    max-width: 1400px;
    height: 88vh;
    background: #1e1e1e;
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
    transform: translateY(20px);
    transition: transform 0.25s ease;
}

/* ----- 헤더 ----- */
.tgv-modal__header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 12px 16px;
    background: #2a2a2a;
    border-bottom: 1px solid #3a3a3a;
    flex-shrink: 0;
}

.tgv-modal__title {
    font-size: 14px;
    font-weight: 600;
    color: #e0e0e0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    justify-self: start;
}

/* ----- 디바이스 버튼 ----- */
.tgv-modal__devices {
    display: flex;
    gap: 4px;
    justify-self: center;
}

.tgv-device-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 10px;
    background: transparent;
    border: 1px solid #444;
    border-radius: 6px;
    color: #999;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    white-space: nowrap;
}

.tgv-device-btn:hover {
    background: #3a3a3a;
    color: #e0e0e0;
    border-color: #555;
}

.tgv-device-btn.active {
    background: #4a90e2;
    border-color: #4a90e2;
    color: #fff;
}

.tgv-device-btn svg {
    flex-shrink: 0;
}

/* ----- 닫기 버튼 ----- */
.tgv-modal__close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: transparent;
    border: 1px solid #444;
    border-radius: 6px;
    color: #999;
    cursor: pointer;
    flex-shrink: 0;
    justify-self: end;
    transition: background 0.15s ease, color 0.15s ease;
}

.tgv-modal__close:hover {
    background: #e53e3e;
    border-color: #e53e3e;
    color: #fff;
}

/* ----- 뷰포트 ----- */
.tgv-modal__viewport {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}


/* ----- 아이프레임 외부 (여백 영역) ----- */
.tgv-iframe-outer {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    width: 100%;
    flex: 1;
    background: #e8e8e8;
    overflow: auto;
    position: relative;
}

/* ----- 아이프레임 내부 (너비 전환 대상) ----- */
.tgv-iframe-inner {
    position: relative;
    transition: width 0.3s ease;
    height: 100%;
    min-height: 100%;
    width: 100%;
    flex-shrink: 0;
    background: #fff;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
}

/* ----- Skeleton 블러 배경 ----- */
.tgv-skeleton-bg {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    filter: blur(12px);
    transform: scale(1.05);
    opacity: 1;
    transition: opacity 0.2s ease;
    z-index: 1;
}

.tgv-skeleton-bg.hidden {
    opacity: 0;
    pointer-events: none;
}

/* ----- 아이프레임 ----- */
#tgv-iframe {
    width: 100%;
    height: 100%;
    display: block;
    border: none;
    position: relative;
    z-index: 2;
    opacity: 0;
    transition: opacity 0.15s ease;
}

#tgv-iframe.loaded {
    opacity: 1;
}

/* ----- 로딩 스피너 ----- */
.tgv-loading {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: rgba(232, 232, 232, 0.7);
    z-index: 10;
    pointer-events: none;
}

.tgv-loading.hidden {
    display: none;
}

.tgv-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(74, 144, 226, 0.25);
    border-top-color: #4a90e2;
    border-radius: 50%;
    animation: tgv-spin 0.75s linear infinite;
}

@keyframes tgv-spin {
    to { transform: rotate(360deg); }
}

.tgv-loading span {
    font-size: 13px;
    color: #555;
}

/* ----- 에러 UI ----- */
.tgv-error {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: #f5f5f5;
    z-index: 10;
    text-align: center;
    padding: 24px;
}

.tgv-error__icon {
    font-size: 40px;
}

.tgv-error p {
    font-size: 15px;
    color: #444;
    margin: 0;
    line-height: 1.5;
}

.tgv-error a {
    display: inline-block;
    margin-top: 4px;
    padding: 8px 18px;
    background: #4a90e2;
    color: #fff;
    border-radius: 6px;
    font-size: 13px;
    text-decoration: none;
    transition: background 0.15s ease;
}

.tgv-error a:hover {
    background: #357abd;
}

/* ----- 푸터 ----- */
.tgv-modal__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: #2a2a2a;
    border-top: 1px solid #3a3a3a;
    flex-shrink: 0;
}

.tgv-device-info {
    font-size: 12px;
    color: #888;
}

.tgv-open-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: #4a90e2;
    text-decoration: none;
    padding: 4px 10px;
    border: 1px solid #4a90e2;
    border-radius: 5px;
    transition: background 0.15s ease, color 0.15s ease;
}

.tgv-open-btn:hover {
    background: #4a90e2;
    color: #fff;
}

/* ----- 모바일 전체화면 + 해상도 전환 버튼 숨김 ----- */
@media (max-width: 767px) {
    .tgv-modal__container {
        width: 100vw !important;
        height: 100vh !important;
        max-width: 100% !important;
        max-height: 100% !important;
        border-radius: 0 !important;
        margin: 0 !important;
    }

    /* 해상도 전환 버튼 완전 숨김 */
    .tgv-modal__devices {
        display: none !important;
    }

    /* 헤더를 2열로 변경 (타이틀 + 닫기 버튼) */
    .tgv-modal__header {
        grid-template-columns: 1fr auto;
    }

    .tgv-modal__title {
        font-size: 12px;
    }

    /* iframe 항상 100% 너비 (모바일 전체화면이므로) */
    .tgv-iframe-inner {
        width: 100% !important;
        transition: none;
    }
}
