/* ===================================
   基礎樣式設定 - 深一點的溫暖奶茶色系
   =================================== */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    line-height: 1.6;
    color: #4a3728;
    /* 更深的咖啡色文字 */
    background: linear-gradient(135deg, #f0ebe5 0%, #e8ddd4 50%, #ddd2c4 100%);
    /* 更深的奶茶色漸變 */
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
}

body.sidebar-open {
    overflow: hidden;
}

.container {
    padding-top: 80px;
    max-width: 1200px;
    margin: 0 auto;
    padding-left: 1.5rem;
    padding-right: 1.5rem;
}

/* ===================================
   Header 區域
   =================================== */
header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: rgba(240, 235, 229, 0.9);
    /* 深一點的奶茶色 */
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(180, 150, 120, 0.4);
    padding: 1.2rem 0;
    box-shadow: 0 4px 20px rgba(139, 115, 85, 0.12);
    z-index: 1000;
}

.header-logo {
    width: 40px;
    height: 40px;
    vertical-align: middle;
}

.header-content {
    display: flex;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

.header-text {
    flex: 1;
    text-align: center;
    margin-left: 1rem;
}

.header-text h1 {
    margin: 0;
    font-size: 1.6rem;
    color: #2d1810;
    /* 更深的棕色 */
    font-weight: 700;
    letter-spacing: -0.025em;
}

.header-text p {
    margin: 0.4rem 0 0;
    color: #6d5a47;
    /* 深一點的中等棕色 */
    font-size: 0.9rem;
    font-weight: 400;
}

/* ===================================
   側邊欄控制按鈕
   =================================== */
.sidebar-toggle {
    background: rgba(245, 240, 232, 0.9);
    /* 深一點的米白色 */
    backdrop-filter: blur(10px);
    border: 1px solid rgba(180, 150, 120, 0.5);
    border-radius: 8px;
    cursor: pointer;
    padding: 0.6rem;
    width: 2.8rem;
    height: 2.8rem;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 8px rgba(139, 115, 85, 0.15);
    z-index: 1001;
}

.sidebar-toggle:hover {
    background: rgba(250, 245, 237, 0.95);
    border-color: rgba(160, 82, 45, 0.6);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(160, 82, 45, 0.2);
    border-color: rgba(160, 82, 45, 0.5);
}

.hamburger-line {
    width: 100%;
    height: 2px;
    background: #5d4037;
    /* 更深的棕色 */
    transition: all 0.3s ease;
    border-radius: 1px;
}

.sidebar-toggle.active .hamburger-line {
    opacity: 0;
    transform: scale(0.8);
}

body.sidebar-open .sidebar-toggle {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* ===================================
   側邊欄主體 - 修正手機滾動問題
   =================================== */
.sidebar {
    position: fixed;
    top: 0;
    left: -320px;
    width: 320px;
    height: 100vh;
    /* 桌面版使用 100vh */
    background: rgba(240, 235, 229, 0.95);
    /* 深一點的奶茶色 */
    backdrop-filter: blur(12px);
    border-right: 1px solid rgba(180, 150, 120, 0.4);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 999;
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: 8px 0 32px rgba(139, 115, 85, 0.18);
    display: flex;
    flex-direction: column;
}

.sidebar.active {
    left: 0;
}

.sidebar-header {
    padding: 1.5rem 2rem;
    border-bottom: 1px solid rgba(180, 150, 120, 0.3);
    background: rgba(232, 221, 212, 0.8);
    /* 更深的背景 */
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 72px;
    margin-top: 110px;
    flex-shrink: 0;
    /* 防止被壓縮 */
}

.sidebar-header h3 {
    margin: 0;
    font-size: 1.2rem;
    color: #4a3728;
    font-weight: 600;
    letter-spacing: -0.025em;
}

.sidebar-close {
    background: rgba(245, 240, 232, 0.9);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(180, 150, 120, 0.4);
    border-radius: 6px;
    font-size: 1.2rem;
    cursor: pointer;
    color: #6d5a47;
    padding: 0.4rem;
    width: 1.8rem;
    height: 1.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.sidebar-close:hover {
    background: rgba(250, 245, 237, 1);
    color: #4a3728;
    transform: rotate(90deg);
    border-color: rgba(160, 82, 45, 0.5);
}

/* ===================================
   導航選單 - 修正滾動區域
   =================================== */
.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 2rem;
}

.sidebar-nav {
    padding: 2rem;
    padding-bottom: 1rem;
}

.nav-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.nav-list li {
    margin-bottom: 0.6rem;
}

.nav-link {
    display: block;
    padding: 1rem 1.5rem;
    text-decoration: none;
    color: #5d4037;
    border-radius: 10px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 500;
    position: relative;
    background: rgba(245, 240, 232, 0.8);
    /* 深一點的米白色 */
    backdrop-filter: blur(8px);
    border: 1px solid rgba(180, 150, 120, 0.3);
}

.nav-link::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 4px;
    background: linear-gradient(135deg, #a0522d 0%, #8b4513 100%);
    /* 更深的橘棕色漸變 */
    border-radius: 0 4px 4px 0;
    transform: scaleY(0);
    transition: transform 0.3s ease;
}

.nav-link:hover {
    background: rgba(250, 245, 237, 0.95);
    color: #2d1810;
    transform: translateX(4px);
    box-shadow: 0 4px 20px rgba(160, 82, 45, 0.2);
    border-color: rgba(160, 82, 45, 0.4);
}

.nav-link:hover::before {
    transform: scaleY(1);
}

/* ===================================
   側邊欄資訊區 - 確保可見
   =================================== */
.sidebar-info {
    margin: 0 2rem 2rem;
    padding: 1.5rem;
    background: rgba(238, 217, 196, 0.8);
    /* 深一點的橘米色 */
    backdrop-filter: blur(8px);
    border-radius: 12px;
    border: 1px solid rgba(218, 165, 32, 0.3);
    box-shadow: 0 2px 8px rgba(160, 82, 45, 0.12);
    flex-shrink: 0;
    /* 防止被壓縮 */
}

.sidebar-info h4 {
    margin: 0 0 0.8rem;
    font-size: 1rem;
    color: #4a3728;
    font-weight: 600;
}

.sidebar-info p {
    margin: 0;
    font-size: 0.9rem;
    color: #6d5a47;
    line-height: 1.6;
}

/* ===================================
   遮罩層
   =================================== */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(74, 55, 40, 0.25);
    /* 深一點的棕色遮罩 */
    backdrop-filter: blur(3px);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 998;
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* ===================================
   主要內容區域
   =================================== */
.main-content {
    padding: 5rem 0 3rem;
    min-height: calc(100vh - 8rem);
}

.content-wrapper {
    max-width: none;
    margin: 0;
    padding: 3rem;
    text-align: center;
    background: rgba(245, 240, 232, 0.9);
    /* 深一點的米白色 */
    backdrop-filter: blur(12px);
    border-radius: 0;
    box-shadow: 0 8px 32px rgba(139, 115, 85, 0.15);
    border: none;
}

/* ===================================
   滾動條樣式
   =================================== */
.sidebar::-webkit-scrollbar,
.sidebar-content::-webkit-scrollbar,
.search-results::-webkit-scrollbar,
.comparison-bars::-webkit-scrollbar,
#baseUnitSelect::-webkit-scrollbar,
.conversion-list::-webkit-scrollbar {
    width: 8px;
}

.sidebar::-webkit-scrollbar-track,
.sidebar-content::-webkit-scrollbar-track,
.search-results::-webkit-scrollbar-track,
.comparison-bars::-webkit-scrollbar-track,
#baseUnitSelect::-webkit-scrollbar-track,
.conversion-list::-webkit-scrollbar-track {
    background: rgba(232, 221, 212, 0.5);
    border-radius: 4px;
}

.sidebar::-webkit-scrollbar-thumb,
.sidebar-content::-webkit-scrollbar-thumb,
.search-results::-webkit-scrollbar-thumb,
.comparison-bars::-webkit-scrollbar-thumb,
#baseUnitSelect::-webkit-scrollbar-thumb,
.conversion-list::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #bc9a6a 0%, #a0826e 100%);
    border-radius: 4px;
}

.sidebar::-webkit-scrollbar-thumb:hover,
.sidebar-content::-webkit-scrollbar-thumb:hover,
.search-results::-webkit-scrollbar-thumb:hover,
.comparison-bars::-webkit-scrollbar-thumb:hover,
#baseUnitSelect::-webkit-scrollbar-thumb:hover,
.conversion-list::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #a0522d 0%, #8b4513 100%);
}


/* ===================================
   基準單位選擇器樣式
   =================================== */
#baseUnitSelect {
    max-height: 200px;
    overflow-y: auto;
}

/* ===================================
   卡片樣式
   =================================== */
.card {
    background: rgba(245, 240, 232, 0.9);
    /* 深一點的米白色 */
    backdrop-filter: blur(12px);
    border: 1px solid rgba(180, 150, 120, 0.3);
    border-radius: 12px;
    padding: 2rem;
    margin-bottom: 2rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 20px rgba(139, 115, 85, 0.12);
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 32px rgba(160, 82, 45, 0.18);
    border-color: rgba(160, 82, 45, 0.4);
    background: rgba(250, 245, 237, 0.95);
}

/* ===================================
   語言切換器
   =================================== */
.language-switcher {
    position: relative;
    margin-left: auto;
}

.language-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(245, 240, 232, 0.9);
    /* 深一點的溫暖背景 */
    backdrop-filter: blur(12px);
    border: 1px solid rgba(180, 150, 120, 0.4);
    border-radius: 25px;
    padding: 0.5rem 1rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 8px rgba(139, 115, 85, 0.12);
    font-size: 0.9rem;
    font-weight: 500;
    color: #4a3728;
}

.language-btn:hover {
    background: rgba(250, 245, 237, 0.95);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(160, 82, 45, 0.2);
    border-color: rgba(160, 82, 45, 0.5);
}

.language-flag {
    font-size: 1.1rem;
}

.language-arrow {
    font-size: 0.7rem;
    transition: transform 0.3s ease;
    color: #6d5a47;
}

.language-btn:hover .language-arrow {
    transform: rotate(180deg);
}

.language-dropdown {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    background: rgba(245, 240, 232, 0.95);
    /* 深一點的溫暖背景 */
    backdrop-filter: blur(15px);
    border: 1px solid rgba(180, 150, 120, 0.4);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(139, 115, 85, 0.2);
    min-width: 160px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
}

.language-dropdown.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.language-option {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-size: 0.9rem;
}

.language-option:hover {
    background: rgba(238, 217, 196, 0.8);
    /* 深一點的橘米色 hover */
}

.language-option:first-child {
    border-radius: 12px 12px 0 0;
}

.language-option:last-child {
    border-radius: 0 0 12px 12px;
}

.language-option .flag {
    font-size: 1.1rem;
}

.language-option .text {
    color: #4a3728;
    font-weight: 500;
}

/* ===================================
   響應式設計 - 桌面版
   =================================== */
@media (min-width: 1024px) {
    .sidebar {
        left: 0;
        top: 80px;
        height: calc(100vh - 80px);
        border-top: none;
        box-shadow: 4px 0 20px rgba(139, 115, 85, 0.15);
    }

    .sidebar-header {
        display: none;
        margin-top: 0;
    }

    .sidebar-close {
        display: none;
    }

    .sidebar-toggle {
        display: none;
    }

    .main-content {
        margin-left: 320px;
        padding: 5rem 0 3rem;
    }

    .content-wrapper {
        max-width: none;
        padding: 3rem;
        margin: 0;
        border-radius: 0;
        border: none;
    }

    .sidebar-overlay {
        display: none;
    }

    .sidebar-nav {
        padding-top: 1.5rem;
    }

    .sidebar-content {
        flex: 1;
        overflow-y: auto;
        padding-bottom: 2rem;
    }
}

/* ===================================
   響應式設計 - 平板版
   =================================== */
@media (max-width: 768px) {
    .header-text h1 {
        font-size: 1.4rem;
    }

    .container {
        padding-top: 60px !important;
    }

    .main-content {
        margin-left: 0;
        padding: 4rem 0 3rem;
    }

    .content-wrapper {
        margin: 0;
        padding: 2rem;
        border-radius: 0;
        border: none;
    }

    .sidebar {
        width: 300px;
        left: -300px;
        height: 100vh;
    }

    .sidebar-header {
        margin-top: 100px;
    }

    .header-content {
        flex-wrap: wrap;
        gap: 1rem;
    }

    .language-switcher {
        order: 3;
        margin-left: 0;
    }

    .language-btn {
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
    }

    .language-text {
        display: none;
    }

    .language-dropdown {
        right: 0;
        left: auto;
    }
}

/* ===================================
   響應式設計 - 手機版 (修正滾動問題)
   =================================== */
@media (max-width: 480px) {
    .sidebar {
        width: 100%;
        left: -100%;
        /* 手機版使用更安全的高度計算 */
        height: 100vh;
        height: 100dvh;
        /* 支援的瀏覽器使用動態 viewport */
        max-height: -webkit-fill-available;
        /* Safari 支援 */
    }

    .header-content {
        padding: 0 1rem;
    }

    .content-wrapper {
        margin: 0;
        padding: 1.5rem;
        border-radius: 0;
        border: none;
    }

    .main-content {
        padding: 6rem 0 3rem;
    }

    /* 手機版專用：確保底部內容可見 */
    .sidebar-content {
        flex: 1;
        overflow-y: auto;
        padding-bottom: 4rem;
        /* 手機版增加更多底部空間 */
        padding-bottom: calc(4rem + env(safe-area-inset-bottom));
        /* 考慮安全區域 */
    }

    .sidebar-info {
        margin-bottom: 3rem;
        /* 增加底部邊距 */
    }

    /* 手機版強制滾動到底部的額外空間 */
    .sidebar-content::after {
        content: '';
        display: block;
        height: 2rem;
        flex-shrink: 0;
    }
}

/* ===================================
   手機瀏覽器特殊處理
   =================================== */
@supports (-webkit-touch-callout: none) {
    /* iOS Safari 特殊處理 */
    @media (max-width: 480px) {
        .sidebar {
            height: -webkit-fill-available;
        }
    }
}

/* ===================================
   極小螢幕 - 額外的手機優化
   =================================== */
@media (max-width: 360px) {
    .sidebar-content {
        padding-bottom: 5rem;
        /* 更多底部空間 */
        padding-bottom: calc(5rem + env(safe-area-inset-bottom));
    }

    .sidebar-info {
        margin-bottom: 4rem;
    }
}

/* ========== Sidebar 摺疊樣式 ========== */
.collapsible-trigger {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding-right: calc(var(--spacing-unit) * 3);
    position: relative;
}

/* 新增 + 符號 */
.collapsible-trigger::after {
    content: "+";
    font-size: 20px;
    font-weight: bold;
    color: #5d4037;
    transition: all 0.3s ease;
    margin-left: 8px;
}

.collapsible-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
}

.nav-category.open .collapsible-content {
    max-height: 5000px; /* 設置一個足夠大的值 */
    transition: max-height 0.5s ease-in;
}

/* 修改為在開啟狀態顯示 - 符號 */
.nav-category.open .collapsible-trigger::after {
    content: "-";
    transform: rotate(0deg);
    font-size: 20px;
    font-weight: bold;
    color: #5d4037;
    transition: all 0.3s ease;
    margin-left: 8px;
}