/* ==========================================================================
   0. 全域變數與基礎重置 (Variables & Reset)
   ========================================================================== */
:root {
    /* 基礎背景與版面色彩 */
    --bg-global: #ededed;          /* 全站灰色背景 */
    --bg-card: #ffffff;            /* 卡片、容器白色背景 */
    --bg-ad-box: #fafafa;          /* 廣告盒淡灰色背景 */
    
    /* 品牌與互動色彩 */
    --color-primary: #EE0000;      /* 品牌主色 */
    --color-border-danger: blue;
    
    /* 文字色彩 */
    --text-dark: #111111;          /* 標題極深色 */
    --text-main: #333333;          /* 一般內文深灰色 */
    --text-muted: #444444;         /* 次要內文灰色 */
    --text-light: #999999;         /* 廣告字樣等極淡灰色 */
    
    /* 邊框與陰影 */
    --border-color: #eeeeee;       /* 淺色分割線與邊框 */
    --border-ad: #cccccc;          /* 廣告虛線邊框 */
    --shadow-nav: rgba(0, 0, 0, 0.1);
}

* {
    box-sizing: border-box;
}

html, body {
    background-color: var(--bg-global);
    margin: 0;
}

/* 鎖定頁面背景滾動 (選單開啟時使用) */
body.no-scroll {
    overflow: hidden !important;
}

/* 全站主容器 */
.main-container {
    width: 100%; 
    margin: 0 auto;
    padding-left: 3px;
    padding-right: 3px;
}

@media (min-width: 768px) {
    .main-container {
        max-width: 1400px;
        padding-left: 20px;  
        padding-right: 20px;
    }
}

/* ==========================================================================
   1. 導航列 - 基礎與通用組件 (Navbar Base)
   ========================================================================== */
.it-navbar {
    background-color: #ffffff;
    box-shadow: 0 2px 4px var(--shadow-nav);
    width: 100%;
    z-index: 10000;
    position: relative;
    padding: 0;
}

.nav-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-brand {
    text-decoration: none;
    display: flex;
    align-items: center;
}

/* 搜尋框通用樣式 */
.search-input-group {
    display: flex;
}
.search-input-group input {
    padding: 6px 12px;
    border: 1px solid #ccc;
    border-radius: 4px 0 0 4px;
    outline: none;
}
.search-input-group button {
    padding: 6px 12px;
    border: 1px solid var(--color-primary);
    background-color: var(--color-primary);
    color: white;
    border-radius: 0 4px 4px 0;
    cursor: pointer;
}

/* ==========================================================================
   2. 導航列 - 桌機版 (Desktop Navbar >= 992px)
   ========================================================================== */
@media (min-width: 992px) {
    .desktop-only-menu {
        display: flex !important;
        align-items: center;
        gap: 30px;
        flex-grow: 1;
        justify-content: space-between;
        margin-left: 250px;
    }
    
    .desktop-nav-list {
        display: flex;
        list-style: none;
        margin: 0;
        padding: 0;
        gap: 20px;
        align-items: center;
    }

    .desktop-nav-list > li {
        position: relative;
        padding: 10px 0;
        display: flex;
        align-items: center;
    }
    
    .desktop-nav-list a {
        color: var(--color-primary);
        text-decoration: none;
        font-weight: 500;
    }

    /* 下拉選單 (Hover 觸發) */
    .desktop-submenu {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        background-color: #ffffff;
        min-width: 160px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        border-radius: 4px;
        padding: 10px 0;
        margin: 0;
        list-style: none;
        z-index: 999;
    }

    .desktop-submenu li {
        width: 100%;
    }

    .desktop-submenu a {
        display: block;
        padding: 8px 16px;
        color: #333333 !important;
        font-weight: normal;
        text-decoration: none;
        font-size: 14px;
        white-space: nowrap;
        transition: background-color 0.2s ease;
    }

    .desktop-submenu a:hover {
        background-color: #f5f5f5;
        color: #007bff !important;
    }

    .nav-item-has-submenu:hover .desktop-submenu {
        display: block;
    }

    /* 桌機時隱藏手機版開關與下拉選單 */
    .mobile-toggle-btn,
    .mobile-only-dropdown,
    #mobileDropdownMenu,
    #mobileMenuOverlay {
        display: none !important;
    }
}

/* ==========================================================================
   3. 導航列 - 手機版 (Mobile Navbar < 991px)
   ========================================================================== */
@media (max-width: 991px) {
    .desktop-only-menu {
        display: none !important;
    }

    /* 1. 漢堡選單按鈕 (預設三條線) */
    .mobile-toggle-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
        background: none;
        border: 1px solid #ccc;
        padding: 8px 10px;
        cursor: pointer;
        border-radius: 4px;
        width: 40px;
        height: 36px;
        position: relative;
    }

    /* 利用漸層繪製三條橫線 */
    .mobile-toggle-btn::before {
        content: '';
        display: block;
        width: 20px;
        height: 14px;
        background: linear-gradient(
            to bottom,
            #333 0, #333 2px,
            transparent 2px, transparent 6px,
            #333 6px, #333 8px,
            transparent 8px, transparent 12px,
            #333 12px, #333 14px
        );
        transition: all 0.3s ease;
    }

    /* 2. 漢堡選單點擊展開時 (.active) 變紅 X */
    .mobile-toggle-btn.active {
        border-color: var(--color-primary, #EE0000);
    }

    .mobile-toggle-btn.active::before {
        background: 
            linear-gradient(45deg, transparent 45%, #EE0000 45%, #EE0000 55%, transparent 55%),
            linear-gradient(-45deg, transparent 45%, #EE0000 45%, #EE0000 55%, transparent 55%);
    }

    /* 3. 手機版展開選單容器 */
    .mobile-only-dropdown {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        width: 100%;
        max-height: 75vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        background-color: #ffffff !important;
        box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2) !important;
        padding: 15px 20px;
        z-index: 1000 !important;
        flex-direction: column; /* 啟用 Flex 垂直排列以支援 order */
    }

    .mobile-only-dropdown.show-menu,
    .mobile-only-dropdown.active {
        display: flex !important;
    }

    /* 4. 手機版搜尋框 (已修正重複覆蓋，確保置頂) */
    .mobile-search-form {
        width: 100%;
        order: -1;              /* 強制移至 Menu 列表的前面 */
        margin-bottom: 15px;    /* 與下方選單拉開距離 */
        padding-bottom: 15px;
        border-bottom: 1px solid #eeeeee; /* 選用：下方分隔線 */
        flex: 1
    }

    .mobile-search-form input{
        flex: 1 !important;
    }

    .mobile-search-form button {
        white-space: nowrap;
    }

    /* 5. 手機版選單列表 */
    .mobile-nav-list {
        list-style: none;
        padding: 0;
        margin: 0 0 15px 0;
    }

    .mobile-nav-list > li {
        border-bottom: 1px solid #f5f5f5;
        padding: 10px 0;
    }

    .mobile-main-link {
        display: flex !important;
        justify-content: space-between;
        align-items: center;
        color: #333333;
        text-decoration: none;
        font-size: 16px;
        font-weight: 500;
        width: 100%;
    }

    /* 6. 手機版子選單 (手風琴效果) */
    .mobile-submenu {
        display: none;
        list-style: none;
        padding-left: 15px;
        margin: 8px 0 0 0;
        border-left: 2px solid #007bff;
    }

    .mobile-submenu.show-submenu {
        display: block !important;
    }

    .mobile-submenu li {
        padding: 6px 0;
    }

    .mobile-submenu a {
        color: #555555 !important;
        text-decoration: none;
        font-size: 14px;
        display: block;
    }

    .arrow-icon {
        font-size: 0.8em;
        margin-left: 5px;
        color: #888;
        display: inline-block;
        transition: transform 0.2s ease;
    }
}

/* ==========================================================================
   4. 首頁 Section 1: 頭條網格 (Headline Grid)
   ========================================================================== */
@media (min-width: 768px) {
    .section-headline-grid {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 24px;
        margin-top: 30px;
        margin-bottom: 40px;
    }

    .headline-main { grid-column: span 2; }
    .headline-ad   { grid-column: span 1; }
    .headline-sub  { grid-column: span 1; }
}

@media (max-width: 767px) {
    .section-headline-grid {
        display: flex;
        flex-direction: column;
        gap: 20px;
        margin-top: 20px;
        margin-bottom: 30px;
    }
}

.headline-card {
    background: var(--bg-card);
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.headline-card .card-img-wrapper {
    width: 100%;
    position: relative;
    background-color: #eee;
}

.headline-main .card-img-wrapper { padding-top: 56.25%; }
.headline-sub .card-img-wrapper  { padding-top: 65%; }

.headline-card img {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    object-fit: cover;
}

.headline-card .card-content {
    padding: 15px;
}

.headline-card h2 {
    font-size: 20px;
    line-height: 1.4;
    margin: 0 0 10px 0;
    color: var(--text-dark);
    font-weight: 700;
}

.headline-main h2 {
    font-size: 26px;
}

.headline-card p {
    font-size: 16px !important;
    color: var(--text-muted) !important;
    line-height: 1.65;
    margin: 0;
}

.headline-ad-box {
    background: var(--bg-ad-box);
    border: 1px dashed var(--border-ad);
    border-radius: 8px;
    height: 100%;
    min-height: 250px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-light);
}

/* ==========================================================================
   5. 首頁 Section 2: 文章列表與磁鐵側邊欄 (Main Content & Sticky Sidebar)
   ========================================================================== */

/* 桌機版（>= 992px）：雙欄網格佈局 */
@media (min-width: 992px) {
    .section-main-layout {
        display: grid;
        grid-template-columns: 2fr 1fr;
        gap: 20px;
        align-items: stretch !important;
    }

    .sidebar-sticky-area {
        position: sticky !important;
        top: 20px !important;
        align-self: start !important;
        height: fit-content !important;
    }
}

/* 平板與手機版（< 992px）：上下垂直排列 */
@media (max-width: 991px) {
    .section-main-layout {
        display: flex;
        flex-direction: column;
        gap: 30px;
    }
}

/* 左側文章列表容器 */
.article-list-container {
    display: flex;
    flex-direction: column;
    gap: 24px;
    /* 移除 min-height: 1400px; 避免文章少時下方留白過大 */
}

/* -------------------------------------------------- */
/* 單張文章卡片 (桌機版預設：2/5 圖 + 3/5 文) */
.row-item-card {
    display: grid;
    /* 調整比例：2fr 3fr 代表圖片佔 40%、文字佔 60% */
    grid-template-columns: 2fr 3fr; 
    gap: 20px;
    align-items: center; /* 垂直居中 */
    background-color: #ffffff;
    border-radius: 8px;
    overflow: hidden;
}

/* 圖片外框與圖片設定 */
.row-item-card .item-img-wrapper {
    width: 100%;
    aspect-ratio: 16 / 9; /* 維持 16:9 黃金比例 */
    overflow: hidden;
    background-color: #f5f5f5;
}

.row-item-card .item-img-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover; /* 自動裁切滿版，不變形 */
    display: block;
}

/* 文字區域設定 */
.row-item-card .item-text-wrapper {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    padding: 15px 15px 15px 0; /* 右上下留白，左側與 gap 銜接 */
}

.row-item-card h2 {
    font-size: 20px;
    line-height: 1.4;
    margin: 0 0 8px 0;
    color: var(--text-dark);
    font-weight: 700;
}

.row-item-card p {
    font-size: 16px !important;
    color: var(--text-muted) !important;
    line-height: 1.65;
    margin: 0;
    
    /* 建議：加上 3 行省略，防範文字太多拉長卡片 */
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp:3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* 右側側邊欄廣告框 */
.sidebar-ad-box {
    background: var(--bg-ad-box);
    border: 1px dashed var(--border-ad);
    border-radius: 8px;
    width: 100%;
    height: 600px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-light);
    text-align: center;
    font-size: 16px;
}

/* -------------------------------------------------- */
/* 手機版（<= 576px）：自動轉為「上圖下文」 */
@media (max-width: 576px) {
    .row-item-card {
        grid-template-columns: 1fr; /* 【關鍵修正】將 Grid 改為單欄 */
        gap: 0;
    }
    
    .row-item-card .item-text-wrapper {
        padding: 15px; /* 手機版四周皆留白 */
    }
}

/* ==========================================================================
   SEO / 無障礙輔助： visually-hidden 類別
   (讓螢幕閱讀器與 Google 爬蟲讀取，但視覺上完全隱藏)
   ========================================================================== */
.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}
/* 讓文字區域變成 Flex 佈局，使「閱讀全文」按鈕固定在底部 */
.card-content, 
.item-text-wrapper {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

/* 右下角按鈕容器 */
.card-action {
    display: flex;
    justify-content: flex-end; /* 置右 */
    margin-top: 15px; /* 與上方文字保持距離 */
}

/* 閱讀全文按鈕樣式 */
.btn-read-more {
    display: inline-block;
    padding: 6px 14px;
    font-size: 0.875rem;
    font-weight: 600;
    color: #0d6efd;
    background-color: #f0f7ff;
    border: 1px solid #cfe2ff;
    border-radius: 4px;
    text-decoration: none;
    transition: all 0.2s ease-in-out;
}

.btn-read-more:hover {
    color: #ffffff;
    background-color: #0d6efd;
    border-color: #0d6efd;
    text-decoration: none;
}

/* 廣告卡片的按鈕可做顏色微調 */
.btn-read-more.ad-btn {
    color: #198754;
    background-color: #f0fff4;
    border-color: #c3e6cb;
}

.btn-read-more.ad-btn:hover {
    color: #ffffff;
    background-color: #198754;
    border-color: #198754;
}

/* 分類標籤區塊 */
.card-badges {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
    font-size: 0.8rem;
}

/* 主分類標籤 */
.badge-class {
    color: #0d6efd;
    font-weight: 600;
    text-decoration: none;
    background-color: #e7f1ff;
    padding: 2px 8px;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.badge-class:hover {
    background-color: #d0e2ff;
    text-decoration: none;
}

/* 子分類標籤 */
.badge-category {
    color: #495057;
    font-weight: 500;
    text-decoration: none;
    background-color: #f1f3f5;
    padding: 2px 8px;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.badge-category:hover {
    background-color: #e9ecef;
    color: #212529;
    text-decoration: none;
}

/* 分隔符號 */
.badge-sep {
    color: #adb5bd;
    font-size: 0.75rem;
}

/* 廣告贊助標籤 */
.badge-ad {
    color: #198754;
    background-color: #e8f5e9;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}