/**
 * layout.css — 단일 반응형 레이아웃 (데스크톱/태블릿/모바일 공용)
 * 담당: main, .global-header 및 내부, .content-wrapper, .filter-tabs,
 *       .fab-write-btn, 드로어 오버레이, 하단 탭바
 * 브레이크포인트: ~768px 모바일 / 769~1024px 태블릿 / 1025px~ 데스크톱
 * 검색 입력창 스타일은 desktop/search-overlay.css (Phase 1~3에서 통합 예정)
 */

/* 서버 렌더링 페이지 사이를 이동할 때 공통 셸을 같은 시각 요소로 연결한다.
   지원 브라우저에서는 헤더·사이드바·하단바가 다시 번쩍이지 않고 그대로
   유지된 것처럼 보이며, 미지원 브라우저는 기존 전체 페이지 이동으로 폴백한다. */
@view-transition {
    navigation: auto;
}

.global-header {
    view-transition-name: njp-global-header;
}

.sidebar-nav {
    view-transition-name: njp-sidebar;
}

.mobile-bottom-actions {
    view-transition-name: njp-mobile-bottom-bar;
}

.fab-write-btn {
    view-transition-name: njp-desktop-write-button;
}

::view-transition-group(njp-global-header),
::view-transition-group(njp-sidebar),
::view-transition-group(njp-mobile-bottom-bar),
::view-transition-group(njp-desktop-write-button),
::view-transition-image-pair(njp-global-header),
::view-transition-image-pair(njp-sidebar),
::view-transition-image-pair(njp-mobile-bottom-bar),
::view-transition-image-pair(njp-desktop-write-button),
::view-transition-old(njp-global-header),
::view-transition-new(njp-global-header),
::view-transition-old(njp-sidebar),
::view-transition-new(njp-sidebar),
::view-transition-old(njp-mobile-bottom-bar),
::view-transition-new(njp-mobile-bottom-bar),
::view-transition-old(njp-desktop-write-button),
::view-transition-new(njp-desktop-write-button) {
    animation: none;
    mix-blend-mode: normal;
}

::view-transition-group(root),
::view-transition-image-pair(root),
::view-transition-old(root),
::view-transition-new(root) {
    animation: none;
    mix-blend-mode: normal;
}

@media (prefers-reduced-motion: reduce) {
    ::view-transition-group(*),
    ::view-transition-old(*),
    ::view-transition-new(*) {
        animation-duration: 0.01ms !important;
    }
}

.container {
    max-width: 100%;
    padding: 0;
}

.main-layout {
    display: block;
    margin: 0;
}

main {
    margin-left: 0;
    padding: calc(var(--header-height, 72px) + 24px) 2rem 2rem;
    min-height: 100vh;
}

/* 데스크톱: 사이드바 너비만큼 본문을 밀어서 겹치지 않게 */
@media (min-width: 769px) {
    main {
        margin-left: var(--sidebar-collapsed, 70px);
    }
}

/* Global Header — 단일 정의. Figma 시안: 검정 72px 바 (워드마크 + 검색창 + Log In) */
.global-header {
    height: var(--header-height, 72px);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 900;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    background: var(--chrome-bg) !important;
    border-bottom: none;
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), left 0.3s ease;
}

/* 헤더 좌측 NANJANGPAN 워드마크 (모바일에서는 로고 아이콘으로 대체) */
.header-logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--font-logo);
    font-size: 1.25rem;
    color: var(--chrome-text);
    text-decoration: none;
    letter-spacing: 0.02em;
    white-space: nowrap;
    flex-shrink: 0;
}

.header-logo:hover {
    opacity: 0.8;
}

.header-logo-icon {
    display: block;
    width: 28px;
    height: 28px;
    object-fit: contain;
    flex-shrink: 0;
}

/* 헤더 우측 Log In / 프로필 */
.header-auth {
    flex-shrink: 0;
}

.header-auth-link {
    font-family: var(--font-logo);
    font-size: 1.125rem;
    color: var(--chrome-text);
    text-decoration: none;
    white-space: nowrap;
}

.header-auth-link:hover {
    opacity: 0.8;
}

/* 헤더 내부 컨테이너 (검색창 중앙 정렬) */
.header-container {
    flex: 1;
    min-width: 0;
    height: 100%;
    max-width: none;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}

/* post-detail / content-wrapper와 같은 800px 중앙 영역 */
.header-center-wrapper {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    position: relative;
}

.header-search-wrapper {
    pointer-events: auto;
}

/* 데스크톱 현재 위치는 툴바의 자식이 아니라, 툴바와 본문 사이 24px 여백에
   독립적으로 고정한다. 사이드바를 제외한 본문 영역의 중앙축을 따른다. */
.desktop-breadcrumb-row {
    position: fixed;
    top: var(--header-height, 72px);
    left: var(--sidebar-collapsed, 70px);
    right: 0;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 850;
    pointer-events: none;
}

.desktop-breadcrumb-row .content-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 0 2rem;
}

.desktop-breadcrumb-row .breadcrumb {
    pointer-events: auto;
}

.desktop-breadcrumb-row a,
.desktop-breadcrumb-row span {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.header-search-wrapper {
    width: 100%;
    max-width: 320px;
    transition: max-width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    justify-content: center;
    position: relative;
    z-index: 900;
}

.header-center-wrapper.search-focused {
    max-width: 800px;
}

.header-center-wrapper.search-focused .header-search-wrapper {
    max-width: 800px;
}

.global-search-container {
    width: 100%;
    max-width: 800px;
    position: relative;
}

/* 헤더/푸터와 동일한 800px 중앙 영역 (넓은 모니터에서도 일관된 레이아웃) */
.content-wrapper {
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
    width: 100%;
    box-sizing: border-box;
}

/* Top Filter Tabs */
.filter-tabs {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--border-light);
    padding-bottom: 0.5rem;
}

.filter-tab {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.filter-tab.active {
    color: var(--text-primary);
    border-bottom-color: var(--text-primary);
}

/* Floating Action Button (우측 하단 글쓰기) — 모바일은 하단 탭에 글쓰기가 있으므로 숨김 */
.fab-write-btn {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 56px;
    height: 56px;
    min-width: 56px;
    min-height: 56px;
    background-color: var(--primary-color, #49c48d);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25), 0 2px 6px rgba(0, 0, 0, 0.2);
    font-size: 1.25rem;
    z-index: 850;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
    text-decoration: none;
    border: none;
    cursor: pointer;
}

.fab-write-btn:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3), 0 4px 12px rgba(0, 0, 0, 0.25);
    background-color: var(--primary-hover, #3aa878);
    color: #fff;
}

.fab-write-btn:active {
    transform: translateY(0) scale(0.98);
}

.fab-write-btn i {
    color: inherit;
    pointer-events: none;
}

/* ==========================================================================
   ≥1025px (데스크톱): 드로어 전용 요소 숨김
   ========================================================================== */
@media (min-width: 1025px) {

    .header-hamburger.mobile-only,
    .drawer-overlay.mobile-only {
        display: none;
    }
}

/* 하단 탭바는 휴대폰 전용이다. 태블릿은 아이콘 사이드바와 확장 드로어를 쓴다. */
@media (min-width: 769px) {
    .mobile-bottom-actions {
        display: none;
    }
}

/* ===========================================================================
   769~1024px 태블릿: 아이콘 사이드바를 전체 메뉴 드로어로 확장
   ========================================================================== */
@media (min-width: 769px) and (max-width: 1024px) {
  .header-logo {
    order: 1;
  }

  .header-container {
    order: 2;
    flex: 1;
    min-width: 0;
  }

  .header-auth {
    display: none;
  }

  .header-hamburger.mobile-only {
    display: flex;
    order: 3;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin-left: 8px;
        background: none;
        border: none;
        color: var(--chrome-text);
        font-size: 1.15rem;
        cursor: pointer;
    }

    body.drawer-open {
        position: fixed;
        left: 0;
        right: 0;
        width: 100%;
        overflow: hidden;
    }

    .drawer-overlay.mobile-only {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }

    body.drawer-open .drawer-overlay.mobile-only {
        opacity: 1;
        pointer-events: auto;
    }
}

/* ==========================================================================
   ~768px 모바일: 검정 헤더 축소, 드로어 오버레이 + 하단 탭바 표시
   ========================================================================== */
@media (max-width: 768px) {
    :root {
        /* 사이드바가 이 값을 기준으로 헤더 아래에서 시작하므로 실제 모바일
           헤더 높이(60px)와 동기화 */
        --header-height: 60px;
    }

    .global-header {
        left: 0;
        height: 60px;
        padding: 0 0.75rem;
        gap: 0.5rem;
    }

    .desktop-breadcrumb-row {
        display: none !important;
    }

    /* "마이" 하단 탭이 로그인/프로필로 이미 연결되므로 헤더의 Log In 링크는 숨김 */
    .header-auth {
        display: none;
    }

    /* 워드마크 대신 로고 아이콘만 표시 — 검색창이 쓸 폭을 넓게 확보 */
    .header-logo-icon {
        display: block;
        width: 30px;
        height: 30px;
    }

    .header-logo-text {
        display: none;
    }

    /* 배치 순서: 로고 - 검색창 - 더보기(드로어) 버튼
       오른손 엄지가 자연스럽게 닿는 우측에 "더보기"를 두고, 실수로 누르면
       홈으로 이동해버리는 로고는 반대편(좌측)에 둬서 오탭을 방지 */
    .header-logo {
        order: 1;
    }

    .header-container {
        order: 2;
        flex: 1;
        min-width: 0;
    }

    .header-hamburger.mobile-only {
        order: 3;
    }

    .header-center-wrapper {
        max-width: none;
    }

    .header-search-wrapper {
        max-width: none;
        width: 100%;
    }

    .search-input-wrapper {
        width: 100%;
    }

    main {
        padding: 72px 1rem calc(96px + env(safe-area-inset-bottom, 0)) 1rem;
    }

    footer {
        margin-left: 0;
        padding-bottom: calc(96px + env(safe-area-inset-bottom, 0));
    }

    .fab-write-btn {
        display: none;
        /* 모바일은 하단 탭의 '글쓰기'로 대체 */
    }

    .header-hamburger.mobile-only {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        background: none;
        border: none;
        color: var(--chrome-text);
        font-size: 1.15rem;
        cursor: pointer;
    }

    /* 드로어(사이드바)가 열린 동안 뒤 배경 스크롤 자체를 막음 — 스크롤이 되면
       search-overlay.js의 scroll-hide 로직이 헤더를 숨겨버려 위쪽이 뻥 뚫려 보였음.
       position:fixed + 저장해둔 scrollY 복원 방식(navigation.js)으로 iOS Safari까지 대응. */
    body.drawer-open {
        position: fixed;
        left: 0;
        right: 0;
        width: 100%;
        overflow: hidden;
    }

    .drawer-overlay.mobile-only {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }

    body.drawer-open .drawer-overlay.mobile-only {
        opacity: 1;
        pointer-events: auto;
    }

    body.mobile-header-hidden:not(.drawer-open):not(.search-open) .global-header {
        transform: translateY(calc(-100% - 4px));
    }

    body.drawer-open .global-header,
    body.search-open .global-header {
        transform: translateY(0) !important;
    }

    /* 플로팅 하단 내비게이션: 알약 탭바 + 원형 글쓰기 버튼.
       두 요소를 각각 fixed로 두고 left/right/bottom을 따로 맞추면 축소 상태에서
       기준선과 간격이 어긋나 어색해 보였다. 지금은 바깥 컨테이너 하나만 fixed로
       두고 내부는 flex로 배치해, 높이가 바뀌어도 아래 기준선과 간격이 항상 같다. */
    .mobile-bottom-actions {
        display: flex;
        align-items: flex-end;
        gap: var(--bottom-dock-gap, 10px);
        position: fixed;
        inset: auto 0 0;
        padding: 0 12px calc(var(--bottom-dock-inset, 14px) + env(safe-area-inset-bottom, 0));
        z-index: 900;
        pointer-events: none;
    }

    .bottom-tab-bar {
        flex: 1;
        min-width: 0;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 2px;
        height: var(--bottom-dock-size, 58px);
        padding: 4px;
        /* 뒤로 콘텐츠가 비쳐 아이콘 대비가 무너지던 문제 때문에 불투명도를 올렸다.
           블러는 그대로 둬서 스크롤 중에도 떠 있는 판처럼 보인다. */
        background: color-mix(in srgb, var(--bg-card) 96%, transparent);
        border: 1px solid color-mix(in srgb, var(--border-color) 90%, transparent);
        border-radius: 999px;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22), 0 1px 2px rgba(0, 0, 0, 0.12);
        backdrop-filter: blur(22px) saturate(150%);
        -webkit-backdrop-filter: blur(22px) saturate(150%);
        pointer-events: auto;
        transition: height 0.22s ease, box-shadow 0.22s ease;
    }

    .bottom-tab-item {
        position: relative;
        flex: 1 1 0;
        min-width: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        height: 100%;
        border-radius: 999px;
        color: var(--text-secondary);
        text-decoration: none;
        font-size: 0.6875rem;
        font-weight: 600;
        letter-spacing: -0.01em;
        transition: color 0.2s ease;
    }

    /* 활성 탭은 색만 바꾸지 않고 뒤에 옅은 알약을 깔아 어느 탭에 있는지
       한눈에 들어오게 한다. */
    .bottom-tab-item::before {
        content: '';
        position: absolute;
        inset: 0;
        border-radius: inherit;
        background: color-mix(in srgb, var(--primary-color, #49c48d) 16%, transparent);
        opacity: 0;
        transform: scale(0.86);
        transition: opacity 0.2s ease, transform 0.2s ease;
    }

    .bottom-tab-item.active::before {
        opacity: 1;
        transform: none;
    }

    .bottom-tab-item i,
    .bottom-tab-label {
        position: relative;
        z-index: 1;
    }

    .bottom-tab-item i {
        font-size: 1.0625rem;
        line-height: 1;
    }

    .bottom-tab-item.active {
        color: var(--primary-color, #49c48d);
    }

    .bottom-tab-label {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100%;
        /* 축소 상태에서 font-size를 0으로 만들면 글자가 뭉개지며 사라져서
           어색했다. 높이와 투명도만 접어 위로 흡수되게 한다.
           max-height는 한글 글자가 잘리지 않도록 line-height와 맞춘다. */
        line-height: 1.2;
        max-height: 1.2em;
        opacity: 1;
        transition: max-height 0.22s ease, opacity 0.16s ease;
    }

    .mobile-write-button {
        flex: 0 0 auto;
        width: var(--bottom-dock-size, 58px);
        height: var(--bottom-dock-size, 58px);
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        background: var(--primary-color, #49c48d);
        color: #fff;
        border: none;
        /* 탭바와 같은 그림자 언어를 쓰고, 테두리 대신 원색 링으로 띄운다.
           흰끼 도는 1px 테두리 때문에 옆의 탭바와 재질이 달라 보였다. */
        box-shadow: 0 8px 24px color-mix(in srgb, var(--primary-color, #49c48d) 38%, transparent),
            0 1px 2px rgba(0, 0, 0, 0.18);
        font-size: 1.0625rem;
        text-decoration: none;
        pointer-events: auto;
        transition: width 0.22s ease, height 0.22s ease, transform 0.18s ease,
            box-shadow 0.22s ease, font-size 0.22s ease;
    }

    .mobile-write-button:active {
        transform: scale(0.92);
    }

    /* 아래로 스크롤할 때는 콘텐츠를 가리지 않도록 하단바도 함께 축소한다.
       navigation.js가 바를 누르거나 위로 스크롤할 때 클래스를 해제한다.
       변수 하나만 바꾸면 탭바·버튼·기준선이 같이 줄어든다. */
    body.mobile-bottom-compact .mobile-bottom-actions {
        --bottom-dock-size: 46px;
        --bottom-dock-inset: 10px;
        --bottom-dock-gap: 8px;
    }

    body.mobile-bottom-compact .bottom-tab-bar,
    body.mobile-bottom-compact .mobile-write-button {
        box-shadow: 0 5px 14px rgba(0, 0, 0, 0.18);
    }

    body.mobile-bottom-compact .bottom-tab-label {
        max-height: 0;
        opacity: 0;
    }

    @media (prefers-reduced-motion: reduce) {

        .bottom-tab-bar,
        .bottom-tab-item,
        .bottom-tab-item::before,
        .bottom-tab-label,
        .mobile-write-button {
            transition: none;
        }
    }
}
