/* --- 1. Global & Typography --- */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@400;500;700&display=swap');

:root {
    --bg-color: #f8f9fa;
    --panel-bg-color: #ffffff;
    --primary-color: #4a90e2;
    --text-color: #343a40;
    --text-secondary-color: #6c757d;
    --border-color: #dee2e6;
    --shadow-color: rgba(0, 0, 0, 0.05);
}

body { 
    font-family: 'Noto Sans TC', 'Segoe UI', 'Roboto', sans-serif;
    margin: 0; 
    padding: 10px;
    background-color: var(--bg-color); 
    color: var(--text-color);
}

.container { 
    max-width: 1600px; 
    margin: auto; 
}

h1 { 
    text-align: center; 
    color: var(--text-color); 
    margin-bottom: 10px;
    font-weight: 700;
    font-size: 24px;
}

h3 { 
    margin-top: 0; 
    color: var(--text-secondary-color);
    text-align: center;
    margin-bottom: 20px;
    font-weight: 500;
    font-size: 18px;
}

.chart-box { 
    background-color: var(--panel-bg-color); 
    padding: 15px; 
    border-radius: 12px; 
    box-shadow: 0 4px 12px var(--shadow-color); 
    margin-bottom: 20px;
}

.chart { 
    width: 100%; 
}

.clickable { 
    cursor: pointer; 
}

/* --- 2. overview.html specific styles --- */
#active-filters-container { display: flex; justify-content: center; align-items: center; gap: 12px; min-height: 30px; margin-bottom: 25px; flex-wrap: wrap; }
.filter-tag { display: flex; align-items: center; background-color: var(--primary-color); color: #fff; padding: 6px 12px; border-radius: 16px; font-size: 14px; box-shadow: 0 2px 4px rgba(74, 144, 226, 0.3); transition: all 0.2s ease; }
.filter-tag .close-btn { margin-left: 10px; cursor: pointer; font-weight: bold; font-size: 18px; line-height: 1; transition: transform 0.2s ease; }
.filter-tag .close-btn:hover { transform: scale(1.2); }
.controls-wrapper { text-align: center; margin-top: -10px; margin-bottom: 15px; position: relative; z-index: 10; }
.toggle-switch { display: inline-flex; align-items: center; position: relative; height: 24px; }
.toggle-switch label { margin-left: 50px; font-size: 14px; cursor: pointer; color: var(--text-secondary-color); line-height: 24px; }
.toggle-switch input[type="checkbox"] { height: 0; width: 0; visibility: hidden; position: absolute; }
.toggle-switch input[type="checkbox"] + label::before { content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%); width: 44px; height: 24px; background: #ccc; display: block; border-radius: 24px; transition: background-color .2s; cursor: pointer; }
.toggle-switch input[type="checkbox"] + label::after { content: ''; position: absolute; top: 50%; left: 4px; transform: translateY(-50%); width: 20px; height: 20px; background: #fff; border-radius: 50%; transition: left .2s; cursor: pointer; }
.toggle-switch input:checked + label::before { background: var(--primary-color); }
.toggle-switch input:checked + label::after { left: 20px; }
#monthly-revenue-chart { height: 250px; }
.dual-chart-container, .consumer-profile-container { display: flex; gap: 20px; flex-wrap: wrap; }

.chart-wrapper { 
    flex: 1; 
    min-width: 300px;
    display: flex;
    flex-direction: column;
}
.chart-wrapper h3 {
    flex-shrink: 0;
    margin-bottom: 15px;
}

.bar-chart, .consumer-chart, .geo-chart { 
    /* 【本次修改】將圖表高度從 350px 增加到 450px */
    height: 450px;
    flex-grow: 1;
}

#geo-map-chart { height: 400px; flex: 1; }
#geo-ranking-chart { height: 400px; flex: 1; }
#treemap-header { display: flex; flex-wrap: wrap; align-items: center; margin-bottom: 10px; padding-left: 5px; }
.header-label { font-size: 16px; font-weight: 600; color: #555; margin-right: 10px; }
.filter-select { font-size: 15px; padding: 5px 8px; border-radius: 4px; border: 1px solid var(--border-color); }
#overview-treemap-chart { height: 450px; }
#custom-legend-container { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; padding: 10px 0; margin-top: 15px; border-top: 1px solid var(--border-color); }
.legend-item { display: flex; align-items: center; margin: 5px 12px; font-size: 13px; cursor: default; }
.legend-color-box { width: 14px; height: 14px; margin-right: 8px; border: 1px solid var(--border-color); }
.tabs-nav { border-bottom: 2px solid var(--border-color); margin-bottom: 20px; display: flex; flex-wrap: wrap; }
.tab-btn { padding: 10px 15px; cursor: pointer; background-color: transparent; border: none; font-size: 15px; font-weight: 500; color: var(--text-secondary-color); position: relative; transition: color 0.2s ease; }
.tab-btn::after { content: ''; position: absolute; bottom: -2px; left: 0; width: 100%; height: 2px; background-color: var(--primary-color); transform: scaleX(0); transition: transform 0.3s ease; }
.tab-btn.active { color: var(--primary-color); }
.tab-btn.active::after { transform: scaleX(1); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* --- 3. index.html specific styles --- */
.controls { display: flex; flex-direction: column; gap: 20px; align-items: stretch; padding: 15px; background-color: var(--panel-bg-color); border-radius: 8px; box-shadow: 0 4px 12px var(--shadow-color); margin-bottom: 20px; }
.controls>div { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.controls>div .radio-group-container { display: flex; flex-wrap: wrap; gap: 15px; }
.controls label { font-weight: bold; white-space: nowrap; }
.controls select, .controls input[type="number"] { width: 100%; padding: 8px; border: 1px solid var(--border-color); border-radius: 4px; box-sizing: border-box; }
.hot-items-control, .radio-group-label { display: flex; align-items: center; gap: 5px; }
.radio-group-label label { font-weight: normal; cursor: pointer; }
.radio-group-label input { cursor: pointer; }
#category-treemap-wrapper { background-color: var(--panel-bg-color); padding: 20px; border-radius: 8px; box-shadow: 0 4px 12px var(--shadow-color); margin-bottom: 20px; }
#category-treemap-wrapper h3 { margin-top: 0; margin-bottom: 15px; text-align: center; }
#category-treemap-container { width: 100%; height: 250px; }
#chart-container { width: 100%; height: 50vh; min-height: 400px; background-color: var(--panel-bg-color); border-radius: 8px; box-shadow: 0 4px 12px var(--shadow-color); }
#table-wrapper { margin-top: 20px; background-color: var(--panel-bg-color); border-radius: 8px; box-shadow: 0 4px 12px var(--shadow-color); padding: 10px; overflow-x: auto; }
.data-table { border-collapse: collapse; }
.data-table th, .data-table td { padding: 10px; border-bottom: 1px solid #e0e0e0; text-align: left; white-space: nowrap; }
.data-table th { background-color: #f5f5f5; font-weight: bold; }
.data-table tbody tr:hover { background-color: #f0f8ff; }
.data-table tbody tr.highlight { background-color: #ffeeba; }
.data-table td.number { text-align: right; }
.rank-up::before { content: '↑'; color: #d9534f; margin-right: 4px; }
.rank-down::after { content: '↓'; color: #5cb85c; margin-left: 4px; }
#pagination-container { display: flex; justify-content: center; align-items: center; gap: 10px; padding-top: 20px; }
.page-btn { padding: 8px 12px; border: 1px solid #ccc; background-color: white; border-radius: 4px; cursor: pointer; }
.page-btn:disabled { cursor: not-allowed; background-color: #f8f8f8; color: #aaa; }
#page-info { font-size: 14px; }
#hot-items-settings-btn { padding: 5px 8px; cursor: pointer; font-size: 16px; background: #eee; border-color: #ccc; }
#hot-items-settings-panel { display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 90%; max-width: 380px; padding: 20px; background: white; border: 1px solid #ccc; border-radius: 8px; box-shadow: 0 5px 15px rgba(0,0,0,0.2); z-index: 1000; }
.settings-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
.settings-row.rank-filter { justify-content: flex-start; gap: 10px; }
.settings-row label { font-weight: normal; }
.settings-row input[type="number"] { width: 80px; padding: 5px; }
.settings-actions { text-align: right; margin-top: 20px; }
.settings-actions button { margin-left: 10px; }
#settings-panel-close { position: absolute; top: 10px; right: 15px; font-size: 24px; color: #aaa; cursor: pointer; border: none; background: none; }


/* --- 4. Media Queries for Responsive Design --- */
@media (min-width: 992px) {
    body {
        padding: 20px;
    }
    h1 {
        font-size: 32px;
    }
    h3 {
        font-size: 20px;
    }
    .chart-box {
        padding: 25px;
    }
    .controls-wrapper {
        text-align: right;
        margin-top: -45px;
        margin-right: 15px;
        height: 0;
        margin-bottom: 0;
    }
    /* index.html controls on desktop */
    .controls {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 20px;
    }
    .controls > div {
        flex-direction: row;
        align-items: center;
        gap: 10px;
    }
    .controls select, .controls input[type="number"] {
        width: auto;
    }
    .data-table {
        width: 100%;
    }
}

.action-col {
    text-align: center;
}

.action-col-cell {
    text-align: center;
    font-weight: bold;
    font-size: 20px;
    color: var(--primary-color);
}
/* --- 【本次新增】品項通路排行表格樣式 --- */
#channel-category-ranking-wrapper {
    margin-top: 25px;
}

.ranking-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 15px;
}

.ranking-table th,
.ranking-table td {
    padding: 12px 15px;
    border-bottom: 1px solid var(--border-color);
    text-align: left;
}

.ranking-table th {
    background-color: #f8f9fa;
    font-weight: 600;
    color: var(--text-secondary-color);
}

.ranking-table tbody tr:hover {
    background-color: #f0f8ff;
}

.ranking-table .rank-cell {
    font-weight: 700;
    font-size: 16px;
    text-align: center;
    color: var(--primary-color);
}

.ranking-table .strength-cell {
    font-weight: 500;
}

.ranking-table .action-cell {
    text-align: center;
}

.ranking-table .action-link {
    font-size: 22px; /* 放大圖示 */
    text-decoration: none;
    margin: 0 10px;
    color: var(--text-secondary-color);
    transition: color 0.2s ease, transform 0.2s ease;
}

.ranking-table .action-link:hover {
    color: var(--primary-color);
    transform: scale(1.2);
}
/* --- 【本次新增】套用品項通路排行表格的分頁樣式 --- */
#ranking-table-pagination-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    padding-top: 20px;
}
/* --- 5. 【本次新增】針對 overview.html 的手機版優化 --- */
@media (max-width: 767px) {
    /* 強制圖表容器在手機上垂直堆疊，避免寬度計算問題 */
    #overview-treemap-chart {
        height: 350px; /* 手機上 Treemap 不需要太高 */
    }

    .dual-chart-container, .consumer-profile-container {
        flex-direction: column;
        gap: 25px;
    }
}
/* --- 【建議新增】手機版表格 UI 優化 --- */
@media (max-width: 767px) {
    /* 隱藏電腦版的表頭 */
    .data-table thead, .ranking-table thead {
        display: none;
    }

    /* 將表格轉換為區塊，並移除邊框 */
    .data-table, .data-table tbody, .data-table tr, .data-table td,
    .ranking-table, .ranking-table tbody, .ranking-table tr, .ranking-table td {
        display: block;
        width: 100%;
        border: none;
    }

    /* 每一行(tr)變成一張卡片 */
    .data-table tr, .ranking-table tr {
        margin-bottom: 15px;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        padding: 10px;
        box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    }

    /* 每一個儲存格(td)自己佔一行 */
    .data-table td, .ranking-table td {
        /* --- 【本次修復】--- */
        box-sizing: border-box; /* 確保 padding 不會讓寬度溢出 */
        
        text-align: right; /* 數值靠右 */
        padding-left: 50%; /* 留出空間給標籤 */
        position: relative;
        padding-top: 5px;
        padding-bottom: 5px;
    }

    /* 透過偽元素(::before)將 data-label 的內容顯示為欄位標籤 */
    .data-table td::before, .ranking-table td::before {
        content: attr(data-label);
        position: absolute;
        left: 10px;
        width: 45%;
        text-align: left;
        font-weight: bold;
        color: var(--text-secondary-color);
    }

/* 針對不需要標籤的欄位微調 */
.data-table td.action-col-cell {
    text-align: center;
    padding-left: 0;
}
/*
.data-table td.action-col-cell::before {
    display: none;
}*/
}
/* --- 【建議新增】頂層主導覽列樣式 --- */
.main-nav {
    display: flex;
    justify-content: center;
    background-color: var(--panel-bg-color);
    padding: 10px 0;
    margin-bottom: 25px;
    border-radius: 12px;
    box-shadow: 0 4px 12px var(--shadow-color);
    border: 1px solid var(--border-color);
}

.main-nav-list {
    display: flex;
    list-style-type: none;
    margin: 0;
    padding: 0;
    gap: 15px;
}

.main-nav-list a {
    display: block;
    padding: 10px 20px;
    text-decoration: none;
    color: var(--text-secondary-color);
    font-weight: 500;
    font-size: 16px;
    border-radius: 8px;
    transition: all 0.2s ease-in-out;
}

.main-nav-list a:hover {
    color: var(--text-color);
    background-color: #f0f8ff;
}

/* 當前所在頁面的高亮樣式 */
.main-nav-list .active a {
    background-color: var(--primary-color);
    color: #fff;
    box-shadow: 0 2px 8px rgba(74, 144, 226, 0.4);
}

/* 手機版樣式 */
@media (max-width: 767px) {
    .main-nav-list {
        gap: 5px;
    }
    .main-nav-list a {
        padding: 8px 12px;
        font-size: 14px;
    }
}
/* --- 【建議新增】頂層導覽列搜尋框樣式 --- */

.main-nav-list .nav-search-item {
    display: flex;
    align-items: center;
    margin-left: 15px; /* 與其他選單項目的間距 */
}
/* --- 【建議新增】頂層導覽列搜尋框樣式 --- */

.main-nav-list .nav-search-item {
    display: flex;
    align-items: center;
    margin-left: 15px; /* 與其他選單項目的間距 */
}

.nav-search-container {
    position: relative; /* 關鍵：讓按鈕可以相對於此容器定位 */
}

#nav-search-input {
    /* 【修改】增加右側內距，為按鈕騰出空間 */
    padding: 8px 40px 8px 15px; 
    border: 1px solid var(--border-color);
    border-radius: 20px;
    width: 180px;
    font-size: 14px;
    transition: all 0.3s ease-in-out;
}

/* 【重要！新增此段樣式】 */
#nav-search-btn {
    position: absolute;
    top: 50%;
    right: 5px; /* 將按鈕定位在容器的右側 */
    transform: translateY(-50%); /* 確保垂直置中 */
    border: none;
    background-color: transparent;
    cursor: pointer;
    padding: 5px;
    font-size: 18px; /* 調整圖示大小 */
    color: var(--text-secondary-color); /* 設定一個清晰可見的顏色 */
    transition: color 0.2s ease;
}

#nav-search-btn:hover {
    color: var(--primary-color); /* 滑鼠懸停時變色，增加互動性 */
}

#nav-search-input:focus {
    width: 250px; /* 點擊時展開，提供更好的輸入體驗 */
    border-color: var(--primary-color);
    box-shadow: 0 0 8px rgba(74, 144, 226, 0.2);
}

.nav-search-results {
    display: none; /* 預設隱藏 */
    position: absolute;
    top: 110%; /* 稍微往下，避免重疊 */
    left: 0;
    right: 0;
    background-color: #fff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    z-index: 110;
    max-height: 300px;
    overflow-y: auto;
}

.nav-search-results .result-item {
    padding: 10px 15px;
    cursor: pointer;
    font-size: 14px;
}

.nav-search-results .result-item:hover {
    background-color: #f0f8ff;
    color: var(--primary-color);
}
/* --- 手機版導覽列換行樣式 --- */
/* --- 手機版導覽列換行與間距樣式 (更新版) --- */
@media (max-width: 767px) {

    /* 1. 讓導覽列主容器允許換行、置中，並增加項目間的垂直距離 */
    .main-nav-list {
        flex-wrap: wrap;
        justify-content: center;
        row-gap: 12px; /* 【本次修改重點】增加行之間的垂直間距為 12px */
    }

    /* 2. 讓搜尋區塊單獨佔據一行 */
    .main-nav-list .nav-search-item {
        width: 100%;
        margin-left: 0;
    }

    /* 3. 讓搜尋框的容器置中，並設定寬度 */
    .nav-search-container {
        width: 90%;
        margin: 0 auto;
    }

    /* 4. 讓搜尋輸入框填滿其容器的寬度 */
    #nav-search-input,
    #nav-search-input:focus {
        width: 100%;
        box-sizing: border-box;
    }
}