/* ========================================
   하나아트갤러리 반응형 스타일
   Bootstrap 5 표준 Breakpoints 기반
   ======================================== */

/* CSS Variables (반응형 전용) */
:root {
    /* Bootstrap 5 Breakpoints */
    --breakpoint-xs: 0;
    --breakpoint-sm: 576px;
    --breakpoint-md: 768px;
    --breakpoint-lg: 992px;
    --breakpoint-xl: 1200px;
    --breakpoint-xxl: 1400px;

    /* 모바일 네비게이션 */
    --mobile-nav-width: 280px;
    --mobile-nav-bg: rgba(255, 255, 255, 0.98);
    --mobile-nav-shadow: 0 0 50px rgba(0, 0, 0, 0.3);
    --transition-nav: 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    /* 터치 최적화 */
    --touch-target-min: 44px; /* Apple HIG, WCAG 2.1 AA 권장 */
    --touch-spacing: 12px;
}

/* ========================================
   햄버거 메뉴 버튼
   ======================================== */
.mobile-menu-toggle {
    width: var(--touch-target-min);
    height: var(--touch-target-min);
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 0;
    display: none; /* 기본 숨김, 992px 이하에서 표시 */
    align-items: center;
    justify-content: center;
    z-index: 1060;
}

.mobile-menu-toggle:focus {
    outline: 2px solid var(--accent, #d4af37);
    outline-offset: 2px;
}

/* 햄버거 아이콘 */
.hamburger {
    width: 24px;
    height: 18px;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.hamburger span {
    display: block;
    width: 100%;
    height: 2px;
    background: #333;
    border-radius: 1px;
    transition: all 0.3s ease;
    transform-origin: center;
}

/* 햄버거 → X 애니메이션 */
.mobile-menu-toggle.active .hamburger span:nth-child(1) {
    transform: translateY(8px) rotate(45deg);
}

.mobile-menu-toggle.active .hamburger span:nth-child(2) {
    opacity: 0;
    transform: scaleX(0);
}

.mobile-menu-toggle.active .hamburger span:nth-child(3) {
    transform: translateY(-8px) rotate(-45deg);
}

/* ========================================
   슬라이드 메뉴 (좌측에서)
   ======================================== */
.mobile-nav-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1040;
    opacity: 0;
    transition: opacity var(--transition-nav);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

.mobile-nav-overlay.active {
    display: block;
    opacity: 1;
}

.mobile-nav-menu {
    position: fixed;
    top: 0;
    left: -100%;
    width: var(--mobile-nav-width);
    max-width: 85vw;
    height: 100%;
    background: var(--mobile-nav-bg);
    box-shadow: var(--mobile-nav-shadow);
    z-index: 1050;
    overflow-y: auto;
    overflow-x: hidden;
    transition: left var(--transition-nav);
    -webkit-overflow-scrolling: touch;
}

.mobile-nav-menu.active {
    left: 0;
}

/* 모바일 메뉴 헤더 */
.mobile-nav-header {
    padding: 16px 20px;
    border-bottom: 1px solid #e8e8e8;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    background: inherit;
    z-index: 1;
}

.mobile-nav-logo img {
    height: 40px;
    width: auto;
}

.mobile-nav-close {
    width: var(--touch-target-min);
    height: var(--touch-target-min);
    border: none;
    background: transparent;
    font-size: 28px;
    cursor: pointer;
    padding: 0;
    color: #333;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.mobile-nav-close:hover {
    background: #f0f0f0;
}

.mobile-nav-close:focus {
    outline: 2px solid var(--accent, #d4af37);
    outline-offset: 2px;
}

/* 모바일 메뉴 아이템 */
.mobile-nav-items {
    padding: 16px 0;
}

.mobile-nav-item {
    display: flex;
    align-items: center;
    padding: 14px 20px;
    color: #333;
    text-decoration: none;
    font-size: 16px;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: all 0.2s ease;
    min-height: var(--touch-target-min);
}

.mobile-nav-item:hover,
.mobile-nav-item:focus {
    background: #f5f5f5;
    border-left-color: var(--accent, #d4af37);
    color: var(--accent, #d4af37);
    text-decoration: none;
}

.mobile-nav-item.active {
    background: #f5f5f5;
    border-left-color: var(--accent, #d4af37);
    color: var(--accent, #d4af37);
    font-weight: 600;
}

.mobile-nav-item.admin-link {
    color: #dc3545;
    border-top: 1px solid #e8e8e8;
    margin-top: 8px;
    padding-top: 22px;
}

.mobile-nav-item.admin-link:hover {
    background: #fff5f5;
    border-left-color: #dc3545;
}

/* Body 스크롤 방지 */
body.mobile-menu-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

/* ========================================
   이미지 지연 로딩
   ======================================== */
img[data-lazy] {
    opacity: 0;
    transition: opacity 0.4s ease;
}

img[data-lazy].loaded {
    opacity: 1;
}

img.lazy-loading {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* 이미지 로딩 에러 플레이스홀더 */
img.load-error {
    opacity: 1;
    background: #f5f5f5;
    border: 1px dashed #ccc;
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

img.load-error::after {
    content: attr(alt);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #999;
    font-size: 0.85rem;
    text-align: center;
    padding: 0.5rem;
}

/* ========================================
   터치 친화적 UI
   ======================================== */
@media (hover: none) and (pointer: coarse) {
    /* 터치 디바이스 전용 스타일 */
    .card:hover {
        transform: none;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
    }

    .card:active {
        transform: scale(0.98);
        transition: transform 0.1s;
    }

    .gallery-item:hover {
        transform: none;
    }

    .gallery-item:active {
        transform: scale(0.98);
    }

    /* 스크롤 성능 개선 */
    * {
        -webkit-tap-highlight-color: transparent;
    }

    /* 버튼/링크 터치 피드백 */
    .btn:active,
    .nav-link:active {
        opacity: 0.8;
    }
}

/* 터치 타겟 최소 크기 보장 */
@media (max-width: 991.98px) {
    .btn,
    .nav-link,
    .card-link {
        min-height: var(--touch-target-min);
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}

/* ========================================
   Bootstrap 5 표준 Breakpoints
   Mobile First 접근법
   ======================================== */

/* Base (XS: 0 - 575.98px) - 모바일 */
.container {
    padding-left: 15px;
    padding-right: 15px;
}

/* ========================================
   SM: 576px 이상 (큰 모바일)
   ======================================== */
@media (min-width: 576px) {
    .container {
        max-width: 540px;
    }

    .gallery-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 20px;
    }
}

/* ========================================
   MD: 768px 이상 (태블릿)
   ======================================== */
@media (min-width: 768px) {
    .container {
        max-width: 720px;
    }

    h1 { font-size: 2.25rem; }
    h2 { font-size: 1.875rem; }
    h3 { font-size: 1.625rem; }

    .section {
        padding: 45px 0;
    }

    .section-title {
        font-size: 2.25rem;
    }

    .gallery-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 25px;
    }

    .card-img-top {
        height: 220px;
    }
}

/* ========================================
   LG: 992px 이상 (데스크톱)
   ======================================== */
@media (min-width: 992px) {
    .container {
        max-width: 960px;
    }

    h1 { font-size: 2.5rem; }
    h2 { font-size: 2rem; }
    h3 { font-size: 1.75rem; }

    .section {
        padding: 50px 0;
    }

    .section-title {
        font-size: 2.5rem;
    }

    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    }

    .card-img-top {
        height: 250px;
    }

    /* 데스크톱: 기존 네비게이션 표시 */
    .navbar-collapse {
        display: flex !important;
    }

    /* 데스크톱: 모바일 메뉴 숨김 */
    .mobile-menu-toggle {
        display: none !important;
    }

    .mobile-nav-menu,
    .mobile-nav-overlay {
        display: none !important;
    }
}

/* ========================================
   XL: 1200px 이상 (큰 데스크톱)
   ======================================== */
@media (min-width: 1200px) {
    .container {
        max-width: 1140px;
    }

    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    }
}

/* ========================================
   XXL: 1400px 이상 (초대형 데스크톱)
   ======================================== */
@media (min-width: 1400px) {
    .container {
        max-width: 1320px;
    }
}

/* ========================================
   Max-width Breakpoints (하향식)
   ======================================== */

/* LG 이하: 992px 미만 (태블릿/모바일) */
@media (max-width: 991.98px) {
    /* 햄버거 메뉴 표시 */
    .mobile-menu-toggle {
        display: flex;
    }

    /* 기존 navbar-collapse 숨김 */
    .navbar-collapse {
        display: none !important;
    }

    /* 카드 간격 조정 */
    .card {
        margin-bottom: 20px;
    }

    /* Footer 반응형 */
    .footer .row {
        text-align: center;
    }

    .footer .col-md-3 {
        margin-bottom: 20px;
    }

    .footer img {
        height: 60px;
    }
}

/* MD 이하: 768px 미만 (모바일) */
@media (max-width: 767.98px) {
    h1 { font-size: 1.875rem; }
    h2 { font-size: 1.625rem; }
    h3 { font-size: 1.375rem; }

    .section {
        padding: 35px 0;
    }

    .section-title {
        font-size: 1.875rem;
    }

    .gallery-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }

    .gallery-item img {
        height: 180px;
    }

    .card-img-top {
        height: 200px;
    }

    /* Navbar 로고 크기 조정 */
    .navbar-brand img {
        height: 38px;
    }

    /* Footer 푸터 조정 */
    .footer h5 {
        font-size: 0.9rem;
    }

    .footer p {
        font-size: 0.8rem;
    }
}

/* SM 이하: 576px 미만 (소형 모바일) */
@media (max-width: 575.98px) {
    :root {
        --section-spacing: 30px;
        --card-spacing: 15px;
    }

    h1 { font-size: 1.625rem; }
    h2 { font-size: 1.5rem; }

    .section-title {
        font-size: 1.625rem;
    }

    .gallery-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .gallery-item img {
        height: 220px;
    }

    .navbar-brand img {
        height: 35px;
    }

    /* 버튼 전체 너비 */
    .btn-lg {
        width: 100%;
        max-width: 300px;
    }

    /* 모달 전체 너비 */
    .modal-dialog {
        margin: 10px;
        max-width: calc(100% - 20px);
    }
}

/* ========================================
   Navbar Pill 버튼 반응형
   ======================================== */
@media (max-width: 991.98px) {
    .navbar-nav .nav-link {
        padding: 0.5rem 1rem;
        font-size: 0.8rem;
    }
}

/* ========================================
   갤러리 모달 반응형
   ======================================== */
@media (max-width: 767.98px) {
    .modal-gallery .modal-dialog {
        margin: 0;
        max-width: 100%;
        height: 100%;
    }

    .modal-gallery .modal-content {
        height: 100%;
        border-radius: 0;
    }

    .modal-gallery .modal-gallery-img {
        max-height: 60vh;
    }

    .modal-gallery .carousel-control-prev,
    .modal-gallery .carousel-control-next {
        width: 15%;
    }
}

/* ========================================
   관리자 패널 반응형 (보완)
   ======================================== */
@media (max-width: 767.98px) {
    .admin-content {
        padding: 1rem;
    }

    .admin-header .brand {
        font-size: 1rem;
    }

    .admin-header .user-info {
        gap: 0.5rem;
    }

    .admin-header .user-info span {
        display: none;
    }
}

/* ========================================
   유틸리티 클래스
   ======================================== */
.d-touch-none {
    display: none;
}

@media (hover: none) and (pointer: coarse) {
    .d-touch-block {
        display: block !important;
    }

    .d-touch-none {
        display: none !important;
    }
}

/* 스크롤 스냅 (갤러리) */
.scroll-snap-x {
    scroll-snap-type: x mandatory;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.scroll-snap-x > * {
    scroll-snap-align: start;
}

/* Safe Area (iPhone X 이후 노치 대응) */
@supports (padding: env(safe-area-inset-bottom)) {
    .mobile-nav-menu {
        padding-bottom: env(safe-area-inset-bottom);
    }

    .footer {
        padding-bottom: calc(2rem + env(safe-area-inset-bottom));
    }
}
