/* Index (Gallery) page styles */
/* Breakpoints: 768, 1024, 1280 (global.css) */

/* Buffering / Loading overlay */
.buffering-overlay {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.85);
}

.buffering-spinner {
    width: 2.5rem;
    height: 2.5rem;
    border: 3px solid var(--border-color);
    border-top-color: transparent;
    border-radius: 50%;
    animation: buffering-spin 0.8s linear infinite;
}

.buffering-text {
    margin: 0;
    font-size: 0.9rem;
}

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

/* 갤러리만 문서 흐름에 두어 페이지 스크롤 가능 */
.main-container.gallery-container {
    position: static;
}

.gallery-container {
    padding: var(--space-10);
    max-width: var(--max-content);
    margin-left: auto;
    margin-right: auto;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: var(--space-5);
}

/* 스크롤 시 10장씩 추가 로드용 감지 요소 (교차 감지용 최소 높이 확보) */
.gallery-load-more-sentinel {
    grid-column: 1 / -1;
    min-height: 24px;
    height: 24px;
    overflow: hidden;
    visibility: hidden;
    pointer-events: none;
}

/* 1700px 이상: 7단 → 6단 (1fr 줄임) */
@media (min-width: 1700px) {
    .gallery-grid {
        grid-template-columns: repeat(6, 1fr);
    }
}

.gallery-card {
    width: 100%;
    min-width: 0;
    aspect-ratio: 4 / 5;
    background: #fff;
    border: var(--border-width) solid var(--border-color);
    overflow: hidden;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    cursor: pointer;
    transition: box-shadow 0.2s ease, background-color 0.2s ease;
}

.gallery-card:hover {
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.12);
    background: #f0f0f0;
}

.gallery-card:focus,
.gallery-card:focus-visible {
    outline: none;
}

.gallery-card-image {
    overflow: hidden;
    background: #f5f5f5;
    flex: 1;
    min-height: 0;
}

.gallery-card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    max-width: 500px;
    max-height: 70vh;
}

.gallery-card-body {
    height: 100%;
    padding: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    text-align: center;
}

.gallery-card-row--2 {
    flex: 1;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}

/* 이미지+댓글 둘 다 있을 때: 이미지만 전체 표시, 호버 시 댓글 오버레이 (To·meta는 미포함) */
.gallery-card-row--2:has(.gallery-card-image):has(.gallery-card-comment) {
    position: relative;
    overflow: hidden;
}

.gallery-card-row--2:has(.gallery-card-image):has(.gallery-card-comment) .gallery-card-image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    flex: none;
}

.gallery-card-row--2:has(.gallery-card-image):has(.gallery-card-comment) .gallery-card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gallery-card-row--2:has(.gallery-card-image):has(.gallery-card-comment) .gallery-card-comment {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: var(--space-3) var(--space-5);
    overflow-y: auto;
    background: rgba(255, 255, 255, 0.92);
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

.gallery-card:hover .gallery-card-row--2:has(.gallery-card-image):has(.gallery-card-comment) .gallery-card-comment,
.gallery-card:focus-visible .gallery-card-row--2:has(.gallery-card-image):has(.gallery-card-comment) .gallery-card-comment {
    opacity: 1;
    pointer-events: auto;
}

.gallery-card-row--2 .gallery-card-image {
    flex: 1 1 auto;
    min-height: 0;
}

.gallery-card-comment {
    height: 100%;
}

.gallery-card-row--2 .gallery-card-comment {
    font-size: 1rem;
    flex: 1 1 auto;
    min-height: fit-content;
    max-height: none;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    align-self: center;
    flex-direction: column;
    text-align: center;
    justify-content: center;
}

@media screen and (max-width: 768px) {
.gallery-card-row--2 .gallery-card-comment {
    padding: var(--space-3) var(--space-12);
}

.gallery-card:first-child {
    margin-left: 50%;
}

.gallery-card:last-child {
    margin-right: 50%;
}
}

.gallery-card-body .gallery-card-image {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
}

.gallery-card-to {
    font-size: 0.75rem;
    padding: var(--space-2) var(--space-3);
    border-bottom: var(--border);
}

.gallery-card-comment {
    word-break: break-word;
    width: 100%;
    padding: var(--space-3) var(--space-3);
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    text-align: center;
}

@media screen and (max-width: 768px) {
.gallery-card-comment {
    justify-content: center;
    align-items: center;
}
}

.gallery-card-comment a {
    text-decoration: underline;
}

.gallery-card-meta {
    font-size: 0.5rem;
    padding: var(--space-2) var(--space-3);
    border-top: var(--border);
    flex-shrink: 0;
}

/* 모바일에서만 표시 (JS로 display 제어) */
.gallery-carousel-arrow {
    display: none;
}

.gallery-empty {
    text-align: center;
}

.gallery-fab-group {
    padding: 0;
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    gap: var(--space-3);
    z-index: 1000;
    font-family: var(--font-ui);
}

.gallery-fab-group--busy {
    pointer-events: none;
    opacity: 0.7;
}

.gallery-fab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    font: inherit;
}

.gallery-fab-item .gallery-fab {
    width: 3.5rem;
    height: 3.5rem;
    min-width: var(--touch-target, 44px);
    min-height: var(--touch-target, 44px);
    border-radius: 50%;
    border: var(--border-width) solid #000;
    background: #000;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.gallery-fab-item:hover .gallery-fab {
    background: #fff;
    color: #000;
    border-color: var(--border-color);
}

.gallery-fab-item:hover .gallery-fab img {
    filter: none;
}

.gallery-fab-label {
    font-family: var(--font-ui);
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--color-text, #111);
    white-space: nowrap;
    background: #fff;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--btn-radius, 4px);
    border: var(--border);
}

.gallery-fab img {
    display: block;
    width: 24px;
    height: 24px;
    filter: brightness(0) invert(1);
}

.gallery-fab-item.exhibition-fab .gallery-fab img {
    width: 2rem;
    height: 2rem;
}

.gallery-fab-item.booking-fab .gallery-fab img {
    width: 2rem;
    height: 2rem;
}

.gallery-fab-item .gallery-fab {
    font-family: var(--font-ui);
}

/* When gallery fly-away is active */
body.gallery-fly-away-active .gallery-container,
body.gallery-fly-away-active .gallery-grid {
    overflow: visible !important;
}

body.gallery-cards-on-top .main-container.gallery-container {
    position: relative;
    z-index: 950;
}

/* Post View Modal (확대 보기) - 데스크톱에서만 크기 제한 (모바일은 global 유지) */
@media (min-width: 769px) {
    .post-view-modal .modal-content {
        max-width: min(440px, 95%);
        max-height: 82vh;
    }
}
.post-view-modal .post-view-modal-content {
    display: flex;
    flex-direction: column;
    position: relative;
    min-height: 0;
}

/* 헤더 한 줄: flex로 제목(To. xxx 왼쪽) + X(오른쪽) — 갤러리/맵 모달과 동일 패턴 */
.post-view-modal .modal-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    border-bottom: var(--border);
}

.post-view-modal .modal-header-row .post-view-to {
    font-weight: bold;
    flex: 1;
    min-width: 0;
}

.post-view-image-wrap {
    width: 100%;
    overflow: hidden;
    background: #f5f5f5;
    flex-shrink: 0;
}

.post-view-image-wrap .post-view-image {
    width: 100%;
    height: 60vh;
    object-fit: cover;
    display: block;
}


.post-view-comment {
    word-break: break-word;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: var(--space-3) 0;
    width: 100%;
    height: 100%;
    text-align: center;
}

.post-view-comment a {
    text-decoration: underline;
}

.post-view-meta {
    flex-shrink: 0;
    margin-top: auto;
    border-top: var(--border);
    padding: var(--space-2) 0;
    background: white;
    font-size: 0.9em;
}

/* 글쓰기 모달 - 스크롤을 내부 래퍼에서 하게 해서 padding-bottom이 끝에 확실히 보이게 */
.gallery-modal .gallery-modal-content {
    display: flex;
    flex-direction: column;
    position: relative;
    min-height: 0;
    overflow: hidden;
}

/* 이 래퍼만 스크롤, padding-bottom이 스크롤 영역에 포함됨 → 올리기 밑 1rem 여백 */
.gallery-modal .gallery-modal-scroll {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.gallery-modal .gallery-modal-scroll::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
}

.gallery-modal .gallery-modal-body {
    display: block;
    background: #fff;
}

.gallery-modal .gallery-modal-body .modal-content-end-pad {
    display: none;
}

.gallery-modal .gallery-post-form {
    display: block;
    min-height: 0;
}

.gallery-modal .modal-title {
    font-weight: normal;
    font-size: 1rem;
    margin-bottom: var(--space-5);
}

.gallery-post-form .gallery-form-two-col {
    display: flex;
    flex-direction: column;
    align-items: start;
    width: 100%;
    flex: 0 0 auto;
    min-height: 0;
    min-width: 0;
}

.gallery-post-form .gallery-form-two-col > * {
    width: 100%;
    min-width: 0;
}

/* 이미지 추가 영역: exhibition과 동일 마크업 (exhibition-form-col-left, exhibition-add-image-label, exhibition-image-previews) */
.gallery-modal .exhibition-form-col-left {
    position: relative;
    flex: 0 0 auto;
    height: 10rem;
    min-height: 10rem;
    min-width: 0;
    overflow: hidden;
}

.gallery-modal .exhibition-form-col-left .exhibition-add-image-label {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    border: 1px dashed var(--border-color);
    cursor: pointer;
    z-index: 0;
}

.gallery-modal .exhibition-form-col-left .exhibition-add-image-label:hover {
    background: #f5f5f5;
}

.gallery-modal .exhibition-add-image-icon {
    font-size: 1.25rem;
    font-family: var(--font-ui);
    font-weight: 500;
}

.gallery-modal .exhibition-form-col-left .exhibition-image-previews {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: flex;
    flex-wrap: wrap;
    align-content: start;
    justify-content: center;
    gap: var(--space-2);
    overflow: hidden;
    pointer-events: none;
}

.gallery-modal .exhibition-form-col-left .exhibition-image-previews .exhibition-preview-item {
    position: relative;
    pointer-events: auto;
    flex-shrink: 0;
    width: 100%;
    height: 100%;
    border: var(--border);
    overflow: hidden;
}

.gallery-modal .exhibition-form-col-left .exhibition-image-previews .exhibition-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.gallery-modal .exhibition-image-previews .exhibition-preview-item button,
.gallery-modal .exhibition-preview-item button {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    border: var(--border-width) solid var(--border-color);
    border-radius: var(--btn-radius);
    background: rgba(0,0,0,0.7);
    color: #fff;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.gallery-modal .exhibition-image-previews .exhibition-preview-item button:hover,
.gallery-modal .exhibition-preview-item button:hover {
    background: #000;
    color: #fff;
}

.gallery-form-col-right {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    flex: 1 1 0;
    min-height: 0;
    min-width: 0;
}

.gallery-form-col-right .form-group {
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
}

/* 댓글+올리기 한 묶음: form-group이 남는 높이 차지, textarea 반응형, 올리기는 맨 아래 */
.gallery-form-col-right .form-group-comment {
    margin-bottom: 0;
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.gallery-form-col-right .form-group-comment textarea {
    flex: 1 1 0;
    min-height: 8rem;
    resize: none;
}

.gallery-form-col-right .form-group-comment .btn-submit {
    flex-shrink: 0;
    margin-bottom: var(--space-3);
}

.gallery-to-wrap {
    position: relative;
    width: 100%;
    overflow: visible;
}

/* To(참여 주체) 선택: 폼 input과 동일한 border/배경으로 구분 */
.gallery-to-trigger {
    width: 100%;
    background: var(--bg-write, #fff);
    color: inherit;
    border: var(--border-width) solid var(--border-color);
    border-radius: var(--btn-radius);
    box-sizing: border-box;
    cursor: pointer;
    text-align: left;
    appearance: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 2.5rem;
    font-family: var(--font-ui);
    font-size: var(--font-ui-size);
    font-weight: 500;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.gallery-to-trigger[aria-expanded="true"] {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.gallery-to-trigger:focus {
    outline: none;
    border-color: var(--border-color);
}

.gallery-to-trigger-icon {
    flex-shrink: 0;
    width: 1.25rem;
    height: 1.25rem;
    opacity: 0.85;
    transition: transform 0.2s ease, opacity 0.15s ease;
    display: block;
}

.gallery-to-trigger[aria-expanded="true"] .gallery-to-trigger-icon {
    transform: rotate(180deg);
}

.gallery-to-trigger:hover .gallery-to-trigger-icon,
.gallery-to-trigger:focus .gallery-to-trigger-icon {
    opacity: 1;
}

/* 드롭다운 리스트: 트리거와 한 덩어리처럼 보이게 */
.gallery-to-list {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    margin-top: calc(-1 * var(--border-width));
    padding: 0;
    border: var(--border-width) solid var(--border-color);
    border-radius: 0 0 var(--btn-radius) var(--btn-radius);
    background: #fff;
    max-height: 12rem;
    overflow-y: auto;
    z-index: 20;
    display: none;
    box-sizing: border-box;
}

.gallery-to-list.open {
    display: block;
}

.gallery-to-item {
    margin: 0 0 var(--space-1);
    border-bottom: var(--border);
    cursor: pointer;
}

.gallery-to-item:last-child {
    margin-bottom: 0;
    border-bottom: none;
}

.gallery-to-item:hover {
    background: #f5f5f5;
}

.gallery-to-item.selected {
    background: #f0f0f0;
}

@media (max-width: 1280px) {
    .gallery-grid {
        grid-template-columns: repeat(5, 1fr);
    }
}

@media (max-width: 1024px) {
    .gallery-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 768px) {
    /* FAB 아이콘: 푸터에 가려지지 않도록 살짝 위로 */
    .gallery-fab-group {
        bottom: var(--space-5);
    }

    /* 갤러리 페이지에서 세로 스크롤 제거 - 포스트가 화면 중앙에 보이도록 */
    html:has(.main-container.gallery-container),
    body:has(.main-container.gallery-container) {
        overflow-y: hidden;
    }
    html:has(.main-container.gallery-container) {
        height: 100%;
    }
    body:has(.main-container.gallery-container) {
        height: 100%;
        min-height: 100dvh;
    }

    /* post-view 모달 크기는 global 768px .modal-content와 동일 */

    /* 가로 스크롤: 네비 아래 영역 전체 사용, 포스트 세로 중앙 (z-index는 FAB/맵보다 낮게) */
    .main-container.gallery-container {
        max-width: none;
        min-width: 0;
        overflow: visible;
        padding: 0;
        top: calc(var(--nav-height) + env(safe-area-inset-top, 0));
        height: calc(100vh - var(--nav-height) - env(safe-area-inset-top, 0) - env(safe-area-inset-bottom, 0));
        position: fixed;
        left: 0;
        right: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 1;
    }

    .gallery-grid {
        display: flex;
        padding-bottom: var(--pad-bottom-pct);
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: center;
        justify-content: flex-start;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
        scroll-snap-type: x mandatory;
        scroll-padding-inline: 0;
        min-width: 0;
        height: 100%;
        width: 100%;
        position: fixed;
        top: 0;
    }

    .gallery-load-more-sentinel {
        min-width: 24px;
        flex-shrink: 0;
    }

    .gallery-card {
        width: min(16rem, 80vw);
        min-width: min(16rem, 80vw);
        max-width: min(16rem, 80vw);
        aspect-ratio: 4 / 5;
        flex-shrink: 0;
        scroll-snap-align: center;
        box-sizing: border-box;
    }

    .gallery-card-body {
        text-align: center;
    }

    .gallery-card-to {
        padding: var(--space-2h) var(--space-4h);
        text-align: center;
    }

    .gallery-card-comment {
        padding: var(--space-3) var(--space-5) var(--space-2);
        text-align: center;
    }

    .gallery-card-meta {
        padding: var(--space-2h) var(--space-4h);
        text-align: center;
    }

    /* 모바일: 좌우 화살표 - 뷰포트 고정, 그리드에 가려지지 않도록 */
    .gallery-carousel-arrow {
        position: fixed;
        top: 50%;
        transform: translateY(-50%);
        z-index: 10000;
        pointer-events: auto;
        width: 2.5rem;
        height: 2.5rem;
        min-width: var(--touch-target, 44px);
        min-height: var(--touch-target, 44px);
        padding: 0;
        border: var(--border);
        background: #000;
        color: #fff;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .gallery-carousel-prev {
        left: var(--space-5);
    }

    .gallery-carousel-next {
        right: var(--space-5);
    }

    .gallery-carousel-next img {
        transform: rotate(180deg);
    }

    .gallery-carousel-arrow img {
        display: block;
        width: 1rem;
        height: auto;
        max-height: 1.5rem;
        filter: brightness(0) invert(1);
    }

    .gallery-empty {
        font-size: 0.9rem;
    }

    .gallery-carousel-arrow:hover {
        background: #333;
        border-color: #000;
        color: #fff;
    }

    .gallery-carousel-arrow:hover img {
        filter: brightness(0) invert(1);
    }

    .gallery-carousel-arrow:disabled {
        opacity: 0.35;
        cursor: not-allowed;
    }

    .gallery-carousel-arrow:disabled:hover {
        background: #000;
        border-color: var(--border-color);
    }

    .gallery-carousel-arrow:disabled:hover img {
        filter: brightness(0) invert(1);
    }
}

