/* ==========================================================================
   navigation.css — 全站統一頂部導航欄（大氣動畫版）
   ========================================================================== */

:root {
    --nav-ease: cubic-bezier(0.4, 0, 0.2, 1);
    --nav-ease-out: cubic-bezier(0, 0, 0.2, 1);
    --nav-duration: 0.35s;
}

.nav-bar {
    position: sticky;
    top: 0;
    z-index: 1000;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background-color: #ffffff;
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.08);
    box-sizing: border-box;
}

/* --- Logo --- */
.nav-logo {
    display: flex;
    align-items: center;
    text-decoration: none;
    flex-shrink: 0;
}

.nav-logo-img {
    height: 2.5rem;
    width: auto;
    display: block;
    object-fit: contain;
}

/* --- Hamburger 按鈕（加大） --- */
.nav-toggle {
    width: 3rem;
    height: 3rem;
    background-color: var(--primary-orange);
    border: none;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: background-color 0.25s var(--nav-ease), transform 0.2s var(--nav-ease);
    flex-shrink: 0;
}

.nav-toggle:active {
    transform: scale(0.92);
}

.nav-toggle:hover {
    background-color: var(--primary-dark);
}

.nav-toggle span {
    display: block;
    width: 1.5rem;
    height: 3px;
    background-color: #ffffff;
    border-radius: 2px;
    transition: transform 0.4s var(--nav-ease), opacity 0.3s var(--nav-ease), width 0.3s var(--nav-ease);
}

/* 按鈕動畫 → X */
.nav-toggle.active span:nth-child(1) {
    transform: translateY(9px) rotate(45deg);
    width: 1.5rem;
}

.nav-toggle.active span:nth-child(2) {
    opacity: 0;
    width: 0;
}

.nav-toggle.active span:nth-child(3) {
    transform: translateY(-9px) rotate(-45deg);
    width: 1.5rem;
}

/* --- 菜單面板（全屏滑入） --- */
.nav-menu {
    position: fixed;
    top: 0;
    right: 0;
    width: 100%;
    max-width: 420px;
    height: 100dvh;
    background: linear-gradient(180deg, #ffffff 0%, #fafafa 100%);
    box-shadow: -8px 0 40px rgba(0, 0, 0, 0.15);
    transform: translateX(100%);
    transition: transform 0.45s var(--nav-ease);
    z-index: 1100;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
}

.nav-menu.open {
    transform: translateX(0);
}

/* --- 菜單頭部（固定關閉按鈕區域） --- */
.nav-menu-header {
    flex-shrink: 0;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 1.25rem 1.5rem;
    background: linear-gradient(180deg, #ffffff, #ffffff);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    position: relative;
    z-index: 10;
}

/* --- 菜單滾動區域 --- */
.nav-menu-body {
    flex: 1;
    overflow-y: scroll;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    padding: 0.5rem 0 2rem;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
}

/* 隱藏滾動條但保持可滾動 */
.nav-menu-body::-webkit-scrollbar {
    width: 0;
    display: none;
}

/* --- 菜單關閉按鈕（加大） --- */
.nav-close {
    width: 3rem;
    height: 3rem;
    background: rgba(0, 0, 0, 0.05);
    border: none;
    border-radius: 50%;
    font-size: 1.8rem;
    font-weight: 400;
    color: #555;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.25s var(--nav-ease), transform 0.2s var(--nav-ease);
}

.nav-close:hover {
    background: rgba(0, 0, 0, 0.1);
}

.nav-close:active {
    transform: scale(0.9);
}

/* --- 菜單項（大字體、大間距） --- */
.nav-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1.25rem 2rem;
    font-size: 1.55rem;
    font-weight: 600;
    color: #222;
    text-decoration: none;
    border-left: 5px solid transparent;
    transition: all 0.3s var(--nav-ease);
    position: relative;
    overflow: hidden;
}

/* 菜單圖標 */
.nav-icon {
    width: 1.4rem;
    height: 1.4rem;
    stroke-width: 2;
    flex-shrink: 0;
    color: #333;
    transition: color 0.3s var(--nav-ease);
}

.nav-item:hover .nav-icon,
.nav-item.active .nav-icon {
    color: var(--primary-orange);
}

/* 箭頭靠右 */
.nav-arrow {
    margin-left: auto;
    flex-shrink: 0;
}

.nav-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 0;
    height: 100%;
    background: linear-gradient(90deg, rgba(255, 114, 0, 0.08), transparent);
    transition: width 0.4s var(--nav-ease);
}

.nav-item:hover::before {
    width: 100%;
}

.nav-item:hover {
    background-color: transparent;
    color: var(--primary-orange);
    padding-left: 2.5rem;
}

.nav-item.active {
    color: var(--primary-orange);
    border-left-color: var(--primary-orange);
    background: linear-gradient(90deg, rgba(255, 114, 0, 0.06), transparent);
    font-weight: 700;
}

/* --- 下拉菜單容器 --- */
.nav-dropdown {
    display: flex;
    flex-direction: column;
}

/* --- 下拉觸發項 --- */
.nav-dropdown-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* 加大箭頭圖標 */
.nav-dropdown-toggle .nav-arrow {
    width: 1.4rem;
    height: 1.4rem;
    stroke-width: 2.5;
    transition: transform 0.4s var(--nav-ease);
    flex-shrink: 0;
    color: #888;
}

.nav-dropdown-toggle:hover .nav-arrow {
    color: var(--primary-orange);
}

.nav-dropdown-toggle.open .nav-arrow {
    transform: rotate(180deg);
    color: var(--primary-orange);
}

/* --- 下拉子菜單（動畫展開/收起） --- */
.nav-dropdown-menu {
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, #f5f5f5, #efefef);
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 0.5s var(--nav-ease), opacity 0.4s var(--nav-ease), padding 0.4s var(--nav-ease), margin 0.4s var(--nav-ease);
    padding: 0;
    border-radius: 12px;
    margin: 0.5rem 0.75rem;
}

.nav-dropdown-menu.open {
    max-height: 800px;
    opacity: 1;
    padding: 0.5rem 0;
}

/* --- 下拉子菜單項（大字體） --- */
.nav-dropdown-item {
    display: flex;
    align-items: center;
    padding: 1rem 1.5rem 1rem 2.5rem;
    font-size: 1.3rem;
    font-weight: 500;
    color: #444;
    text-decoration: none;
    border-left: 4px solid transparent;
    transition: all 0.3s var(--nav-ease);
    position: relative;
}

.nav-dropdown-item:hover {
    background-color: rgba(255, 114, 0, 0.08);
    color: var(--primary-orange);
    padding-left: 3rem;
}

.nav-dropdown-item.active {
    color: var(--primary-orange);
    border-left-color: var(--primary-orange);
    background: linear-gradient(90deg, rgba(255, 114, 0, 0.1), transparent);
    font-weight: 700;
}

/* --- 巢狀子選單（第二層） --- */
.nav-sub-dropdown {
    display: flex;
    flex-direction: column;
    margin: 0;
}

.nav-sub-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-sub-toggle .nav-arrow {
    width: 1.2rem;
    height: 1.2rem;
    stroke-width: 2.5;
    transition: transform 0.4s var(--nav-ease), color 0.3s var(--nav-ease);
    flex-shrink: 0;
    color: #888;
}

.nav-sub-toggle:hover .nav-arrow {
    color: var(--primary-orange);
}

.nav-sub-toggle.open .nav-arrow {
    transform: rotate(180deg);
    color: var(--primary-orange);
}

.nav-sub-menu {
    display: flex;
    flex-direction: column;
    background: transparent;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: max-height 0.45s var(--nav-ease), opacity 0.35s var(--nav-ease), padding 0.35s var(--nav-ease);
    padding: 0;
    border-radius: 10px;
    margin: 0.4rem 1rem;
}

.nav-sub-menu.open {
    max-height: 400px;
    opacity: 1;
    padding: 0.4rem 0;
}

.nav-sub-menu .nav-dropdown-item {
    padding-left: 3.5rem;
    font-size: 1.3rem;
    color: #555;
}

.nav-sub-menu .nav-dropdown-item:hover {
    padding-left: 4rem;
}

/* --- 遮罩層（漸變效果） --- */
.nav-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.3));
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s var(--nav-ease), visibility 0.4s var(--nav-ease);
    z-index: 1050;
}

.nav-overlay.show {
    opacity: 1;
    visibility: visible;
}

/* --- 菜單項進場動畫（交錯出現） --- */
.nav-menu.open .nav-item,
.nav-menu.open .nav-dropdown,
.nav-menu.open .nav-sub-dropdown {
    animation: navItemSlideIn 0.5s var(--nav-ease-out) forwards;
}

.nav-menu.open .nav-item:nth-child(1),
.nav-menu.open .nav-dropdown:nth-child(1),
.nav-menu.open .nav-sub-dropdown:nth-child(1) { animation-delay: 0.05s; }

.nav-menu.open .nav-item:nth-child(2),
.nav-menu.open .nav-dropdown:nth-child(2) { animation-delay: 0.1s; }

.nav-menu.open .nav-item:nth-child(3),
.nav-menu.open .nav-dropdown:nth-child(3) { animation-delay: 0.15s; }

.nav-menu.open .nav-item:nth-child(4),
.nav-menu.open .nav-dropdown:nth-child(4) { animation-delay: 0.2s; }

.nav-menu.open .nav-item:nth-child(5) { animation-delay: 0.25s; }
.nav-menu.open .nav-item:nth-child(6) { animation-delay: 0.3s; }
.nav-menu.open .nav-item:nth-child(7) { animation-delay: 0.35s; }
.nav-menu.open .nav-item:nth-child(8) { animation-delay: 0.4s; }
.nav-menu.open .nav-item:nth-child(9) { animation-delay: 0.45s; }

@keyframes navItemSlideIn {
    from {
        opacity: 0;
        transform: translateX(30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* 子選單展開動畫 */
.nav-dropdown-menu.open .nav-dropdown-item,
.nav-sub-menu.open .nav-dropdown-item {
    animation: subItemFadeIn 0.35s var(--nav-ease-out) forwards;
}

.nav-dropdown-menu.open .nav-dropdown-item:nth-child(1) { animation-delay: 0.05s; }
.nav-dropdown-menu.open .nav-dropdown-item:nth-child(2) { animation-delay: 0.1s; }
.nav-dropdown-menu.open .nav-dropdown-item:nth-child(3) { animation-delay: 0.15s; }
.nav-dropdown-menu.open .nav-dropdown-item:nth-child(4) { animation-delay: 0.2s; }
.nav-dropdown-menu.open .nav-dropdown-item:nth-child(5) { animation-delay: 0.25s; }
.nav-dropdown-menu.open .nav-dropdown-item:nth-child(6) { animation-delay: 0.3s; }
.nav-dropdown-menu.open .nav-dropdown-item:nth-child(7) { animation-delay: 0.35s; }
.nav-dropdown-menu.open .nav-dropdown-item:nth-child(8) { animation-delay: 0.4s; }
.nav-dropdown-menu.open .nav-dropdown-item:nth-child(9) { animation-delay: 0.45s; }

@keyframes subItemFadeIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==========================================================================
   桌面端 ≥ 1024px — 水平導航
   ========================================================================== */
@media (min-width: 1024px) {
    body {
        /* padding-top: 76px; */
    }

    .nav-bar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 76px;
        padding: 0 3rem;
        box-shadow: 0 1px 0 rgba(0, 0, 0, 0.06);
        display: flex;
        align-items: center;
        justify-content: space-between;
        z-index: 999;
    }

    .nav-logo-img {
        height: 3rem;
    }

    /* 桌面端隱藏原始 logo（由 .nav-menu::before 偽元素顯示） */
    .nav-logo {
        display: none;
    }

    /* 隱藏漢堡按鈕 */
    .nav-toggle {
        display: none;
    }

    /* 桌面端選單：固定在同一行右側 */
    .nav-menu {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 76px;
        width: auto;
        max-width: none;
        background-color: transparent;
        box-shadow: none;
        transform: none !important;
        transition: none;
        flex-direction: row;
        align-items: center;
        justify-content: flex-end;
        padding: 0 3rem;
        overflow: visible;
        z-index: 1000;
        gap: 0;
        animation: none;
    }

    /* 桌面端 Logo 偽元素 */
    .nav-menu::before {
        content: '';
        position: absolute;
        left: 3rem;
        top: 50%;
        transform: translateY(-50%);
        width: 130px;
        height: 3rem;
        background: url('../images/logo.png') no-repeat center / contain;
        pointer-events: none;
    }

    /* 桌面端隱藏 header/body 結構 */
    .nav-menu-header,
    .nav-menu-body {
        display: none;
    }

    /* 桌面端直接顯示子元素 */
    .nav-menu > .nav-item,
    .nav-menu > .nav-dropdown,
    .nav-menu > .nav-sub-dropdown {
        display: inline-flex;
    }

    /* 隱藏關閉按鈕 */
    .nav-menu .nav-close {
        display: none;
    }

    /* 桌面端菜單項 */
    .nav-item {
        display: inline-flex;
        align-items: center;
        padding: 0.8rem 1.5rem;
        font-size: 1.2rem;
        font-weight: 500;
        border-left: none;
        border-bottom: 3px solid transparent;
        border-radius: 0;
        white-space: nowrap;
        transition: color 0.25s ease;
        animation: none;
        position: relative;
        overflow: hidden;
    }

    .nav-item::before {
        display: none !important;
    }

    .nav-item:hover {
        background-color: transparent;
        color: var(--primary-orange);
        padding: 0.8rem 1.5rem;
        border-left: none;
    }

    .nav-item.active {
        color: var(--primary-orange);
        border-left-color: transparent;
        border-bottom-color: var(--primary-orange);
        background-color: transparent;
    }

    /* 隱藏遮罩層 */
    .nav-overlay,
    .nav-overlay.show {
        display: none;
    }

    /* --- 桌面端下拉菜單 --- */
    .nav-dropdown {
        position: relative;
        display: inline-block;
        animation: none;
    }

    .nav-dropdown-toggle {
        display: inline-flex;
        align-items: center;
        cursor: pointer;
    }

    .nav-dropdown-toggle .nav-arrow {
        margin-left: 0.4rem;
        width: 1.2rem;
        height: 1.2rem;
        transition: transform 0.3s ease;
    }

    .nav-dropdown:hover .nav-dropdown-toggle .nav-arrow {
        transform: rotate(180deg);
    }

    /* 桌面端二級選單：高端簡潔面板 */
    .nav-dropdown-menu {
        display: flex;
        flex-direction: column;
        position: absolute;
        top: 100%;
        left: 0;
        min-width: 260px;
        max-height: none;
        overflow: visible;
        background: #fff;
        box-shadow: 0 20px 60px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.05);
        border-radius: 0;
        padding: 0.4rem 0;
        opacity: 0;
        visibility: hidden;
        transform: translateY(4px);
        transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
        z-index: 1200;
        margin: 0;
        border-top: 2px solid var(--primary-orange);
    }

    .nav-dropdown:hover .nav-dropdown-menu,
    .nav-dropdown.open .nav-dropdown-menu {
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
    }

    /* 選單項 */
    .nav-dropdown-item {
        padding: 0.9rem 2rem;
        font-size: 1.05rem;
        font-weight: 400;
        color: #555;
        border-left: none;
        background: none;
        white-space: nowrap;
        transition: color 0.2s ease;
        animation: none;
        display: flex;
        align-items: center;
        letter-spacing: 0.03em;
    }

    .nav-dropdown-item:hover {
        background: none;
        color: var(--primary-orange);
        padding: 0.9rem 2rem;
    }

    .nav-dropdown-item.active {
        color: var(--primary-orange);
        background: none;
        border-left: none;
        font-weight: 400;
    }

    /* --- 桌面端巢狀子選單 --- */
    .nav-sub-dropdown {
        position: relative;
    }

    .nav-sub-toggle {
        padding: 0.9rem 2rem;
        font-size: 1.05rem;
        font-weight: 400;
        color: #555;
        border-left: none;
        white-space: nowrap;
        transition: color 0.2s ease;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: space-between;
        letter-spacing: 0.03em;
    }

    .nav-sub-toggle:hover {
        background-color: #fff;
        color: var(--primary-orange);
    }

    .nav-sub-toggle .nav-arrow {
        margin-left: 0.4rem;
        transform: rotate(-90deg);
        width: 1.1rem;
        height: 1.1rem;
        opacity: 0.4;
        transition: opacity 0.2s ease;
    }

    .nav-sub-toggle:hover .nav-arrow {
        opacity: 1;
    }

    .nav-sub-menu {
        display: flex;
        flex-direction: column;
        position: absolute;
        top: 0;
        left: 100%;
        min-width: 220px;
        max-height: none;
        overflow: visible;
        background: #fff;
        box-shadow: 0 20px 60px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.05);
        border-radius: 0;
        padding: 0.4rem 0;
        opacity: 0;
        visibility: hidden;
        transform: translateX(4px);
        transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
        z-index: 1200;
        margin: 0;
        border-left: 2px solid var(--primary-orange);
    }

    .nav-sub-dropdown:hover .nav-sub-menu,
    .nav-sub-dropdown.open .nav-sub-menu {
        opacity: 1;
        visibility: visible;
        transform: translateX(0);
    }

    .nav-sub-menu .nav-dropdown-item {
        padding: 0.8rem 1.8rem;
        font-size: 1rem;
        border-left: none;
        background: none;
        font-weight: 400;
    }

    .nav-sub-menu .nav-dropdown-item:hover {
        padding: 0.8rem 1.8rem;
        background: none;
        border-left: none;
    }

    .nav-sub-menu .nav-dropdown-item.active {
        background: none;
        border-left: none;
        font-weight: 400;
    }
}

/* 窄桌面 1024px ~ 1279px：收窄菜單項間距 */
@media (min-width: 1024px) and (max-width: 1279px) {
    .nav-item {
        padding: 0.6rem 0.8rem;
        font-size: 1.05rem;
    }
}
