/* === LAYOUT & NAVIGATION === */

/* --- 1. Header & 主布局 (Header & Main Layout) --- */
header {
    flex-shrink: 0;
    background-color: var(--surface-color);
    box-shadow: var(--shadow-md);
    border-bottom: 1px solid var(--border-color);
    z-index: 1000;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    height: 60px;
}

header h1 {
    margin: 0;
    font-size: 1.5rem;
}

header h1 a {
    text-decoration: none;
    color: inherit;
}

.main-wrapper {
    display: flex;
    flex-grow: 1;
    overflow: hidden;
}

main {
    flex-grow: 1;
    overflow-y: auto;
    padding-bottom: 4rem;
}

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

/* --- 2. 側邊欄 (Sidebar) --- */
#category-sidebar {
    width: 260px;
    flex-shrink: 0;
    background-color: var(--surface-color);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    transition: transform 0.3s ease-in-out;
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
}

.sidebar-actions {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.sidebar-actions .btn {
    width: 100%;
}

/* --- 3. 漢堡選單 & 主題切換 (Toggle Buttons & Icons) --- */
.menu-toggle-btn,
#theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    transition: background-color 0.2s, color 0.2s;
}

.menu-toggle-btn:hover,
#theme-toggle:hover {
    background-color: var(--border-color);
    color: var(--text-primary);
}

/* 核心：SVG 圖示切換邏輯 (乾淨版) */
.icon-moon {
    display: none;
}

.icon-sun {
    display: block;
}

body.dark-mode .icon-moon {
    display: block;
}

body.dark-mode .icon-sun {
    display: none;
}

/* 側邊欄遮罩 */
#page-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1001;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

body.sidebar-open #page-overlay {
    opacity: 1;
    pointer-events: auto;
}

/* --- 4. 分類樹 (Category Tree) --- */
#category-tree,
#category-tree ul {
    list-style: none;
    padding: 0;
}

#category-tree ul {
    padding-left: 1rem;
    border-left: 1px solid var(--border-color);
    margin-left: 0.5rem;
    transition: max-height 0.4s cubic-bezier(0.25, 1, 0.5, 1);
    overflow: hidden;
}

#category-tree ul.hidden {
    max-height: 0;
}

#category-tree li a {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 1rem;
    text-decoration: none;
    color: var(--text-secondary);
    border-radius: var(--border-radius-md);
    transition: background-color 0.2s ease, color 0.2s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

#category-tree li.has-children > a {
    cursor: pointer;
}

#category-tree li a:hover {
    background-color: var(--border-color);
    color: var(--text-primary);
}

#category-tree li a.active {
    background-color: var(--primary-color);
    color: white;
    font-weight: 700;
}

.category-toggle-icon {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    transition: transform 0.3s ease;
    flex-shrink: 0;
    margin-left: 0.5rem;
}

.category-toggle-icon.expanded {
    transform: rotate(90deg);
}

/* --- 5. 響應式佈局 (Responsive Layout) --- */
@media (max-width: 768px) {
    header h1 {
        font-size: 1.25rem;
    }

    #category-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 1002;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
        border-right: none;
    }

    body.sidebar-open #category-sidebar {
        transform: translateX(0);
    }
}
