/* ============================================
   모바일 하단 네비게이션 (Modern iOS/Android Style)
   - 768px 미만에서만 활성화
   - 상단: 로고만 고정
   - 하단: 5개 이하 탭 메뉴 (아이콘 + 2자 텍스트)
   - PC 버전 영향 없음
   ============================================ */

/* 기본: 모든 크기에서 하단 네비게이션 숨김 */
.mobile-bottom-nav,
.mobile-top-header {
    display: none !important;
}

/* 모바일 전용 (768px 미만 - 현대적인 스마트폰) */
@media (max-width: 767px) {
    /* ========== Body 및 HTML 설정 ========== */
    body.mobile-nav-active {
        padding-top: 56px !important; /* 상단 헤더 높이 */
        padding-bottom: 60px !important; /* 하단 네비게이션 높이 */
        margin: 0 !important;
        overflow-x: hidden !important;
    }

    /* ========== 상단 헤더 (로고만) ========== */
    .mobile-top-header {
        display: flex !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        height: 56px !important;
        background-color: #ffffff !important;
        border-bottom: 1px solid #e0e0e0 !important;
        z-index: 1030 !important;
        align-items: center !important;
        justify-content: center !important;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08) !important;
    }

    .mobile-top-header .mobile-logo {
        max-height: 40px !important;
        height: auto !important;
        width: auto !important;
        max-width: 200px !important;
    }

    /* ========== 기존 데스크톱 네비게이션 완전 제거 ========== */
    body.mobile-nav-active #top_search_form,
    body.mobile-nav-active #navbar-region,
    body.mobile-nav-active #main-navbar,
    body.mobile-nav-active #main-navbar-item,
    body.mobile-nav-active #logo-navbar,
    body.mobile-nav-active #sticky-anchor,
    body.mobile-nav-active .clearfix {
        display: none !important;
        height: 0 !important;
        max-height: 0 !important;
        min-height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        border: 0 !important;
        position: absolute !important;
        visibility: hidden !important;
        overflow: hidden !important;
        opacity: 0 !important;
        z-index: -9999 !important;
        pointer-events: none !important;
        line-height: 0 !important;
    }

    /* form 요소도 완전 제거 */
    body.mobile-nav-active form#top_search_form {
        display: none !important;
        height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* ========== 컨텐츠 영역 조정 (빈 공간 완전 제거) ========== */
    body.mobile-nav-active .container {
        padding-top: 0 !important; /* body에 이미 padding 있음 */
        padding-bottom: 0 !important;
        margin-top: 0 !important;
        margin-bottom: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    /* 모든 첫 번째 자식 요소의 여백 강제 제거 */
    body.mobile-nav-active .container > *:first-child,
    body.mobile-nav-active .container > *:first-of-type,
    body.mobile-nav-active .content,
    body.mobile-nav-active .content > *:first-child,
    body.mobile-nav-active .content > *:first-of-type,
    body.mobile-nav-active .masonry,
    body.mobile-nav-active .page-content,
    body.mobile-nav-active .row:first-child,
    body.mobile-nav-active main,
    body.mobile-nav-active article {
        margin-top: 0 !important;
        padding-top: 0 !important;
    }

    /* 상단 여백이 있는 모든 요소 강제 제거 */
    body.mobile-nav-active * {
        margin-block-start: 0 !important;
    }

    body.mobile-nav-active .container * {
        margin-block-start: unset !important;
    }

    /* ========== 하단 네비게이션 바 ========== */
    .mobile-bottom-nav {
        display: flex !important;
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        height: 60px !important;
        background-color: #ffffff !important;
        border-top: 1px solid #e0e0e0 !important;
        z-index: 1030 !important;
        box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.08) !important;
        justify-content: space-around !important;
        align-items: stretch !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    /* ========== 네비게이션 아이템 ========== */
    .mobile-nav-item {
        flex: 1 !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        text-decoration: none !important;
        color: #757575 !important;
        padding: 6px 4px !important;
        transition: all 0.2s ease !important;
        position: relative !important;
        border: none !important;
        background: transparent !important;
        min-width: 0 !important;
        overflow: hidden !important;
    }

    .mobile-nav-item:hover,
    .mobile-nav-item:focus {
        background-color: rgba(0, 0, 0, 0.04) !important;
        text-decoration: none !important;
        outline: none !important;
    }

    /* 활성 상태 */
    .mobile-nav-item.active {
        color: #007bff !important;
    }

    .mobile-nav-item.active::before {
        content: '' !important;
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        height: 3px !important;
        background-color: #007bff !important;
    }

    /* ========== 아이콘 ========== */
    .mobile-nav-icon {
        font-size: 22px !important;
        line-height: 1 !important;
        margin-bottom: 4px !important;
        display: block !important;
    }

    .mobile-nav-item.active .mobile-nav-icon {
        transform: scale(1.1) !important;
        transition: transform 0.2s ease !important;
    }

    /* ========== 텍스트 (2자) ========== */
    .mobile-nav-text {
        font-size: 11px !important;
        line-height: 1.2 !important;
        font-weight: 500 !important;
        display: block !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        max-width: 100% !important;
        letter-spacing: -0.3px !important;
    }

    .mobile-nav-item.active .mobile-nav-text {
        font-weight: 600 !important;
    }

    /* ========== Safe Area (아이폰 노치 대응) ========== */
    @supports (padding-bottom: env(safe-area-inset-bottom)) {
        .mobile-bottom-nav {
            padding-bottom: env(safe-area-inset-bottom) !important;
            height: calc(60px + env(safe-area-inset-bottom)) !important;
        }

        body.mobile-nav-active {
            padding-bottom: calc(60px + env(safe-area-inset-bottom)) !important;
        }
    }

    /* ========== 뱃지 (알림 등) ========== */
    .mobile-nav-badge {
        position: absolute !important;
        top: 2px !important;
        right: calc(50% - 16px) !important;
        background-color: #ff4444 !important;
        color: white !important;
        font-size: 10px !important;
        font-weight: bold !important;
        padding: 2px 5px !important;
        border-radius: 10px !important;
        min-width: 18px !important;
        text-align: center !important;
        line-height: 1.2 !important;
    }

    /* ========== 다크 모드 지원 ========== */
    body.dark-theme .mobile-top-header,
    body.dark-theme .mobile-bottom-nav {
        background-color: #1a1a1a !important;
        border-color: #333333 !important;
    }

    body.dark-theme .mobile-nav-item {
        color: #b0b0b0 !important;
    }

    body.dark-theme .mobile-nav-item.active {
        color: #4da6ff !important;
    }

    body.dark-theme .mobile-nav-item.active::before {
        background-color: #4da6ff !important;
    }

    body.dark-theme .mobile-nav-item:hover {
        background-color: rgba(255, 255, 255, 0.08) !important;
    }

    /* ========== 터치 반응 최적화 (iOS/Android) ========== */
    .mobile-nav-item {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.04) !important;
        -webkit-touch-callout: none !important;
        -webkit-user-select: none !important;
        user-select: none !important;
    }

    .mobile-nav-item:active {
        transform: scale(0.96) !important;
        transition: transform 0.1s ease !important;
    }

    /* ========== 작은 화면 (iPhone SE, 320px) ========== */
    @media (max-width: 375px) {
        .mobile-nav-icon {
            font-size: 20px !important;
        }

        .mobile-nav-text {
            font-size: 10px !important;
        }
    }

    /* ========== 큰 화면 (iPhone 14 Pro Max, 430px) ========== */
    @media (min-width: 428px) and (max-width: 767px) {
        .mobile-nav-icon {
            font-size: 24px !important;
        }

        .mobile-nav-text {
            font-size: 12px !important;
        }
    }
}

/* ========== 768px 이상 - PC/태블릿 (절대 적용 안 됨) ========== */
@media (min-width: 768px) {
    .mobile-bottom-nav,
    .mobile-top-header {
        display: none !important;
    }

    body.mobile-nav-active {
        padding-top: 0 !important;
        padding-bottom: 0 !important;
    }
}
