/**
 * sidebar.css — 좌측 사이드바 (반응형 단일 정의)
 * .sidebar-nav, 게시판 목록, 인기 태그, 로그인 영역. 레이아웃/헤더는 layout.css
 * 1025px~: 항상 펼쳐진 200px 검정 사이드바 (Figma 시안)
 * 769~1024px: 아이콘 사이드바 + 필요 시 전체 메뉴 드로어
 * ~768px: 오프캔버스 드로어 (body.drawer-open으로 열림, js/mobile/navigation.js)
 */
:root {
    --sidebar-width: 200px;
    --sidebar-collapsed: 200px;
}

@media (min-width: 769px) and (max-width: 1024px) {
    :root {
        --sidebar-width: 64px;
        --sidebar-collapsed: 64px;
    }
}

.sidebar-nav {
    position: fixed;
    left: 0;
    top: var(--header-height, 72px);
    width: var(--sidebar-width);
    height: calc(100vh - var(--header-height, 72px));
    background: var(--chrome-bg);
    color: var(--chrome-text);
    border-right: none;
    padding: 0 0 1rem 0;
    display: flex;
    flex-direction: column;
    z-index: 100;
    overflow: hidden;
}

/* 세로 웨이브 텍스처 (시안의 사운드웨이브, 가로 원본을 90도 회전) */
.sidebar-nav::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    width: calc(100vh - var(--header-height, 72px));
    height: var(--sidebar-width);
    transform: rotate(90deg) translateY(-100%);
    transform-origin: top left;
    background: url('/images/sidebar-texture.png') repeat-x left center / auto 100%;
    opacity: 0.2;
    pointer-events: none;
}

.sidebar-nav > * {
    position: relative;
    z-index: 1;
}

.sidebar-middle {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 1rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Hide scrollbar for sidebar middle */
.sidebar-middle::-webkit-scrollbar {
    display: none;
}

.sidebar-middle {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.sidebar-bottom {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 1rem 1rem 0 1rem;
    flex-shrink: 0;
}

/* Dynamic adjustments based on height — 데스크톱/태블릿 고정 사이드바 전용.
   모바일 드로어는 자체 스크롤이 있으므로 이 높이 기준으로 게시판/태그 섹션을 숨기지 않음 */
@media (max-height: 750px) and (min-width: 769px) {
    .sidebar-section {
        display: none !important;
        margin-top: 0.5rem;
    }
}

@media (max-height: 600px) {
    .sidebar-menu-item {
        padding: 0.5rem !important;
    }

    .sidebar-middle {
        gap: 1rem;
    }
}

.sidebar-menu {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0 1rem;
}

/* Sidebar Sections (e.g., Popular Tags) — 항상 표시 */
.sidebar-section {
    padding: 0 1rem;
    display: block;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    /* Space for directory button */
    gap: 0.5rem;
    padding: 0.25rem;
    margin-bottom: 0.25rem;
}

.section-header-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.directory-link {
    color: var(--chrome-text-muted);
    font-size: 0.75rem;
    transition: all 0.2s;
    padding: 2px;
}

.directory-link:hover {
    color: var(--chrome-text);
    transform: scale(1.1);
}

.section-header i {
    font-size: 0.875rem;
    color: var(--chrome-text-muted);
}

.section-title {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--chrome-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

/* Sidebar Boards List (게시판 목록 - 인기 태그와 동일 스타일) */
.sidebar-boards-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

/* 태그와 동일한 스타일 재사용: .tag-item-sidebar, .tag-name, .tag-count */
.board-item-sidebar .board-name-sidebar {
    /* tag-name과 동일 (해시 없이 이름만) */
}

/* Popular Boards List (legacy) */
.popular-boards-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.sidebar-menu-item.compact {
    padding: 0.35rem;
    font-size: 0.8125rem;
}

.activity-dot {
    width: 6px;
    height: 6px;
    background-color: var(--primary-color);
    border-radius: 50%;
    margin-left: auto;
    box-shadow: 0 0 0 2px var(--chrome-bg);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    }

    70% {
        transform: scale(1);
        box-shadow: 0 0 0 6px rgba(16, 185, 129, 0);
    }

    100% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

/* Popular Tags List */
.popular-tags-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.tag-item-sidebar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.35rem;
    border-radius: var(--radius-sm);
    text-decoration: none;
    transition: all 0.2s;
    background: transparent;
}

.tag-item-sidebar:hover {
    background: var(--chrome-hover);
}

.tag-item-sidebar .tag-name {
    font-size: 0.8125rem;
    color: var(--chrome-text);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tag-item-sidebar .tag-count {
    font-size: 0.6875rem;
    color: var(--chrome-text-muted);
    background: rgba(255, 255, 255, 0.15);
    padding: 0.125rem 0.375rem;
    border-radius: var(--radius-sm);
    min-width: 20px;
    text-align: center;
}

.sidebar-bottom {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0 1rem;
}

.sidebar-menu-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 0.5rem;
    border-radius: var(--radius-md);
    color: rgba(255, 255, 255, 0.85);
    font-weight: 500;
    font-size: 0.9375rem;
    transition: all 0.2s;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
}

.sidebar-menu-item i {
    min-width: 20px;
    text-align: center;
    font-size: 1.125rem;
}

.sidebar-menu-item .menu-icon-img {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.sidebar-menu-item .menu-shortcut {
    margin-left: auto;
    font-size: 0.75rem;
    opacity: 0.5;
}

.sidebar-menu-item:hover,
.sidebar-menu-item.active {
    background-color: var(--chrome-hover);
    color: var(--chrome-text);
}

/* User Level Badge - Clean & Professional */
.user-level-badge {
    display: inline-flex;
    align-items: center;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    margin-left: 6px;
    vertical-align: middle;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

/* 데스크톱 사용자 메뉴에서는 프로필 이름만 간결하게 표시한다.
   태블릿 아이콘 사이드바와 모바일 드로어에서는 기존 동작을 유지한다. */
@media (min-width: 1025px) {
    .sidebar-user-profile .user-level-badge {
        display: none;
    }
}

/* ==========================================================================
   769~1024px 태블릿: 아이콘 사이드바, 햄버거로 전체 메뉴 확장
   ========================================================================== */
@media (min-width: 769px) and (max-width: 1024px) {
    .sidebar-nav .menu-text,
    .sidebar-nav .section-title,
    .sidebar-nav .tag-name,
    .sidebar-nav .tag-count,
    .sidebar-nav .board-name-sidebar,
    .sidebar-nav .directory-link,
    .sidebar-nav .user-level-badge,
    .sidebar-nav .menu-shortcut {
        display: none;
    }

    .sidebar-menu-item {
        justify-content: center;
        padding: 0.6rem;
    }

    .section-header {
        justify-content: center;
    }

    .sidebar-boards-list,
    .popular-tags-list {
        align-items: center;
    }

    .tag-item-sidebar,
    .board-item-sidebar {
        justify-content: center;
    }

    .sidebar-nav {
        transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s ease;
    }

    body.drawer-open .sidebar-nav {
        --sidebar-width: 280px;
        width: 280px;
        max-width: 80vw;
        z-index: 1000;
        box-shadow: var(--shadow-lg);
    }

    /* 확장 중에는 모바일 드로어와 동일하게 모든 메뉴 라벨을 보여 준다. */
    body.drawer-open .sidebar-nav .menu-text,
    body.drawer-open .sidebar-nav .section-title,
    body.drawer-open .sidebar-nav .tag-name,
    body.drawer-open .sidebar-nav .tag-count,
    body.drawer-open .sidebar-nav .board-name-sidebar,
    body.drawer-open .sidebar-nav .directory-link,
    body.drawer-open .sidebar-nav .user-level-badge,
    body.drawer-open .sidebar-nav .menu-shortcut {
        display: revert;
    }

    body.drawer-open .sidebar-menu-item,
    body.drawer-open .tag-item-sidebar,
    body.drawer-open .board-item-sidebar {
        justify-content: flex-start;
    }

    body.drawer-open .section-header {
        justify-content: space-between;
    }

    body.drawer-open .sidebar-boards-list,
    body.drawer-open .popular-tags-list {
        align-items: stretch;
    }
}

/* ==========================================================================
   ~768px 모바일: 오프캔버스 드로어 (js/mobile/navigation.js가 body.drawer-open 토글)
   ========================================================================== */
@media (max-width: 768px) {
    .sidebar-nav {
        /* ::before 웨이브 텍스처가 실제 사이드바 폭(280px)을 그대로 참조하도록 동기화 */
        --sidebar-width: 280px;
        width: 280px;
        max-width: 80vw;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 1000;
        box-shadow: var(--shadow-lg);
    }

    body.drawer-open .sidebar-nav {
        transform: translateX(0);
    }

    /* 드로어 안에서는 항상 텍스트 라벨 표시 */
    .sidebar-nav .menu-text,
    .sidebar-nav .section-title,
    .sidebar-nav .tag-name,
    .sidebar-nav .tag-count,
    .sidebar-nav .board-name-sidebar,
    .sidebar-nav .directory-link,
    .sidebar-nav .user-level-badge {
        display: revert;
    }

    .sidebar-menu-item {
        justify-content: flex-start;
    }
}
.sidebar-logout-form {
    margin: 0;
}

.sidebar-menu-button {
    width: 100%;
    border: 0;
    background: transparent;
    font: inherit;
    text-align: left;
    cursor: pointer;
}
