html, body {
    height: 100%;
    margin: 0;
    overflow: hidden;
    font-family: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", sans-serif;
}
/* Chrome 相容性：移除所有元素的 focus ring */
*, *::before, *::after {
    outline: none !important;
}
button:focus, input:focus, select:focus, textarea:focus {
    outline: none !important;
}
#app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}
#main-container {
    flex: 1;
    min-height: 0;
    display: flex;
    width: 100%;
    overflow: hidden;
}
#map-wrapper {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    height: 100%;
}
#map {
    flex: 1;
    min-height: 0;
}
/* ── 右側面板外層抽屜（桌面版保持 contents 零干擾，手機版轉為 BottomSheet）── */
#info-drawer {
    display: contents;
}
#bottom-sheet-handle {
    display: none;
}
.mobile-info-fab {
    display: none;
}
#info {
    width: 530px;
    min-width: 530px;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    box-sizing: border-box;
    background-color: #f9f9f9;
    border-left: 1px solid #ddd;
    overflow-y: auto;
}
#info .info-hint {
    color: #6b7280;
    font-size: 0.9rem;
    margin-top: 1rem;
}
/* ── 詳細列表面板（從下方推擠地圖）── */
#detail-panel {
    position: relative;
    height: 0;
    background: #fff;
    border-top: 2px solid #4A90D9;
    box-shadow: 0 -4px 12px rgba(0,0,0,0.15);
    z-index: 100;
    transition: height 0.3s ease;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
#detail-panel.open {
    height: 50vh;
}
#info h2 {
    margin-top: 0;
    color: #333;
    border-bottom: 2px solid #4A90D9;
    padding-bottom: 0.4rem;
}
.town-count-badge {
    font-size: 0.75em;
    color: #666;
    font-weight: normal;
    margin-left: 0.3em;
}

/* 右側面板摘要卡片（KPI 設計）── */
.district-summary {
    display: flex;
    gap: 0.8rem;
    margin-bottom: 1rem;
    flex-direction: row;
}
.summary-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 0.5rem 1rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);

    flex: 1 1 50%;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.summary-card .card-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    line-height: 1.4;
}
/* 左側：標題靠上、大數字靠下 */
.summary-card .card-left {
    display: flex;
    flex-direction: column;
}
.summary-card .card-left .card-label {
    margin-bottom: auto;
}
.summary-card .card-right {
    display: flex;
    flex-direction: column;
    justify-content: center;
    text-align: right;
    line-height: 1.5;
}
.summary-card .card-label {
    font-size: 0.85rem;
    color: #6b7280;
    font-weight: 500;
}
.summary-card .compare-label {
    font-size: 0.75rem;
    color: #9ca3af;
    white-space: nowrap;
}
.summary-card .card-value-large {
    font-size: 1.5rem;
    font-weight: 700;
    color: #111827;
    line-height: 1.4;
    padding-top: 8px;
}
.summary-card .unit {
    font-size: 0.85rem;
    font-weight: 500;
    color: #6b7c93;
}
.summary-card .change-pill {
    font-size: 0.85rem;
}
.summary-card .pct-str {
    font-size: 0.75rem;
    color: #6b7280;
}
.summary-card .summary-change.up { color: #16a34a; }
.summary-card .summary-change.down { color: #ef4444; }
/* 表格列用變化徽章 */
.cell-main {
    display: inline-block;
    font-size: 1.05rem;
    font-weight: 500;
}
.cell-prev {
    display: inline-block;
    margin-left: 1rem;
    text-align: right;
}
.row-pct {
    display: inline-block;
    font-size: 0.75rem;
}
.row-pct.up { color: #16a34a; }
.row-pct.down { color: #ef4444; }
.row-change {
    display: inline;
    font-size: 0.85rem;
}
.row-change.up { color: #16a34a; }
.row-change.down { color: #ef4444; }

/* 全國排名表格：排名欄位 */
.rank-num {
    font-size: 0.85rem;
    color: #64748b;
    font-weight: 500;
}
.rank-trend {
    display: inline-block;
    margin-right: 3px;
    font-size: 0.75rem;
}
.rank-trend.up { color: #16a34a; }
.rank-trend.down { color: #ef4444; }
.stats-table th:nth-child(1),
.stats-table td:nth-child(1) { width: 75px; min-width: 75px !important; max-width: 75px !important; text-align: center; padding-left: 4px; padding-right: 4px; }
.stats-table th:nth-child(2),
.stats-table td:nth-child(2) { width: 75px; min-width: 75px !important; max-width: 75px !important; text-align: center; padding-left: 4px; padding-right: 4px; }
.stats-table th:nth-child(3),
.stats-table td:nth-child(3) { width: 90px; min-width: 90px !important; max-width: 90px !important; text-align: center; }
.stats-table th:nth-child(5),
.stats-table td:nth-child(5) { width: 90px; min-width: 90px !important; max-width: 90px !important; text-align: right; }

/* ── 響應式欄位切換（預設桌面版） ── */
.desktop-only-colgroup { display: table-column-group; }
.desktop-only-row { display: table-row; }
.desktop-only-col { display: table-cell; }
.desktop-only-inline { display: inline; }
.mobile-only-colgroup { display: none; }
.mobile-only-row { display: none; }
.mobile-only-col { display: none; }
.mobile-only-inline { display: none; }
.mobile-only-block { display: none; }

/* 箭頭縮小 */
.arrow {
    font-size: 0.75rem;
}
/* 交易卡片 */
.tx-card {}
/* tx-card 與 price-card 保持一致 */
/* 價格卡片 */
.price-card {}

/* 摘要區塊（保留給舊版兼容） */
.summary-box {
    background: #fff;
    border: 1px solid #d0e0f5;
    border-radius: 6px;
    padding: 0.8rem 1rem;
    margin-bottom: 1rem;
}
.summary-box p {
    margin: 0.3rem 0;
    font-size: 0.95rem;
}

/* 統計表格 */
.stats-table-wrap {
    margin-top: 0.5rem;
    border-radius: 8px;
    overflow: hidden;
    flex: 1 1 auto;
    min-height: 0;
    max-height: 34rem;
    display: flex;
    flex-direction: column;
}
.stats-table-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}
/* 向下箭頭呼吸提示（sticky 於 scrollable 區底部，蓋在最後一列上方） */
.scroll-hint {
    position: sticky;
    bottom: 0;
    text-align: center;
    font-size: 1.4rem;
    color: #6b7280;
    padding: 1.5rem 0 0.6rem;
    background: linear-gradient(to bottom, rgba(255,255,255,0) 0%, rgba(255,255,255,0.9) 60%, #fff 100%);
    pointer-events: none;
    transition: opacity 0.3s ease;
}
.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    table-layout: fixed;
}
.stats-table th, .stats-table td {
    border: 1px solid #d0d0d0;
    padding: 0.35rem 0.4rem;
    text-align: left;
    line-height: 1.35;
}
/* 均價欄位禁止換行，防止單位（萬）掉到下一列 */
#district-tbl td:nth-child(4) { white-space: nowrap; }
/* 欄寬設定：第1/3/5欄固定最小寬度，第2/4欄吃剩餘空間 */
#district-tbl th:nth-child(1), #district-tbl td:nth-child(1) { width: 70px; text-align: center; }
#district-tbl th:nth-child(3), #district-tbl td:nth-child(3) { min-width: 80px; text-align: right; }
#district-tbl th:nth-child(5), #district-tbl td:nth-child(5) { min-width: 80px; text-align: right; }
/* colspan 表頭置中 */
#district-tbl th[colspan] { text-align: center; }
/* 移除第2-3欄、第4-5欄之間的分隔線（鄉鎮表適用） */
#district-tbl td:nth-child(2), #district-tbl th:nth-child(2) { border-right: none; }
#district-tbl td:nth-child(3), #district-tbl th:nth-child(3) { border-left: none; }
#district-tbl td:nth-child(4), #district-tbl th:nth-child(4) { border-right: none; }
#district-tbl td:nth-child(5), #district-tbl th:nth-child(5) { border-left: none; padding-right: 15px; }
/* 全國排名表：所有欄位保留分隔線 */
#national-tbl td,
#national-tbl th {
    border-right: 1px solid #d0d0d0;
}
#national-tbl td:last-child,
#national-tbl th:last-child {
    padding-right: 15px;
}
#national-tbl th {
    background-color: #4A90D9; color: #fff; font-weight: 600;
    position: sticky; top: 0; z-index: 1;
}
#national-tbl tr:nth-child(even) { background-color: #f4f8ff; }
#national-tbl tr:hover { background-color: #e0edff; }
/* 本期筆數與較前期約 1:1 寬度 */
#national-tbl th:nth-child(4) { text-align: center; width: 80px; }
#national-tbl td:nth-child(4) { text-align: right; width: 80px; }
#national-tbl th:nth-child(5), #national-tbl td:nth-child(5) { width: 60px; }
#district-tbl tr:last-child td { padding-bottom: 0.15rem; }
#district-tbl th {
    background-color: #4A90D9; color: #fff; font-weight: 600;
    position: sticky; top: 0; z-index: 1;
}
#district-tbl th:first-child { text-align: center; }

#district-tbl tr:nth-child(even) { background-color: #f4f8ff; }
#district-tbl tr:hover { background-color: #e0edff; }

/* 數字欄位靠右對齊 */
#district-tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
/* 第2欄（本期筆數）靠右對齐 */
#district-tbl td:nth-child(2) { text-align: right; }

/* 鄉鎮市區欄位置中 */
#district-tbl td:first-child { text-align: center; }

/* 表格內單位字樣（萬、筆） */
.stats-table .unit {
    font-size: 0.85rem;
    color: #6b7c93;
    display: inline;
}
/* 表格內大數字與單位靠右對齐，使「萬」字垂直對齐 */
.stats-table .cell-main {
    display: inline-block;
    text-align: right;
}
.stats-table .cell-prev {
    display: inline-block;
    text-align: right;
}

/* ── 篩選列樣式 ── */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 0.8rem;
    align-items: center;
    padding: 8px 10px;
    background: #fff;
    border-radius: 8px;
    border: 1px solid #d0e0f5;
}
.filter-btn {
    padding: 5px 14px;
    border: 1.5px solid #4A90D9;
    border-radius: 16px;
    background: #fff;
    color: #4A90D9;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    outline: none;
}
.filter-btn:hover {
    background: #e8f0fe;
}
.filter-btn.active {
    background: #4A90D9;
    color: #fff;
}
.filter-label {
    font-size: 0.85rem;
    color: #666;
    margin-right: 4px;
}
/* ── 第一層分類 TAB（新建案 / 中古屋 / 租屋）── */
.ws-tabs {
    display: flex;
    gap: 4px;
    width: 100%;
    background: #eef4fb;
    border-radius: 8px;
    padding: 3px;
    margin-bottom: 2px;
}
.ws-tab {
    flex: 1;
    padding: 7px 16px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #4A6785;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    outline: none;
}
.ws-tab:hover {
    background: #dce8f7;
    color: #2c5a8f;
}
.ws-tab.active {
    background: #4A90D9;
    color: #fff;
    box-shadow: 0 1px 3px rgba(74, 144, 217, 0.4);
}
.exclude-special-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.82rem;
    color: #555;
    cursor: pointer;
}
.exclude-special-label input[type="checkbox"] {
    cursor: pointer;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.8rem 1rem;
    background: #4A90D9;
    color: #fff;
}
.panel-title {
    font-size: 1.1rem;
    font-weight: 600;
}
.panel-filter-badges {
    margin-left: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    justify-content: flex-end;
    align-items: center;
}
.panel-filter-badges .filter-badge {
    margin-left: 0;
}
.panel-close {
    background: none;
    border: 1px solid rgba(255,255,255,0.85);
    color: #fff;
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.25rem 0.55rem;
    border-radius: 6px;
    margin-left: 0.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.panel-close:hover {
    background: rgba(255,255,255,0.2);
}
.panel-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}
.panel-content-inner {
    flex: 1;
    min-height: 0;
    overflow: auto;
}
/* 捲動容器內層 padding：讓 sticky 表頭貼齊 scrollport 頂緣（內容在表頭處裁切），
   同時保留表格與面板邊緣的視覺間距 */
.panel-inner-pad {
    padding: 1rem;
}
/* 面板頂部 KPI 橫條：人口/所得/房貸 + 統計摘要，PC 版五張卡強制並列單一行 */
.kpi-strip {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 0.55rem;
    align-items: stretch;
    padding: 0.75rem 0.85rem 0;
    margin-bottom: 0;
    width: 100%;
    box-sizing: border-box;
    overflow-x: auto;
    scrollbar-width: thin;
}
.panel-content-inner:first-child {
    margin-top: 0;
}
/* 面板內的統計摘要（內容成為 KPI 橫條的直接 flex item） */
.panel-summary {
    display: contents;
}
.panel-summary-item {
    flex: 1 1 0;
    min-width: 0;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 0.5rem 0.65rem;
    box-sizing: border-box;
}
.panel-summary-item .unit {
    font-size: 0.76rem;
    color: #64748b;
    font-weight: 500;
    margin-left: 0.15rem;
}
.panel-summary-item .label {
    font-size: 0.78rem;
    color: #64748b;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.2rem;
}
.panel-summary-item .value {
    font-size: 1.15rem;
    font-weight: 700;
    color: #0f172a;
    word-break: break-word;
}
/* 篩選條件卡：badge 依內容換行，避免長日期區間溢出卡片 */
.panel-summary-item .value.filter-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    align-items: center;
    font-weight: 500;
}
/* 區域現況（人口 + 所得 + 房貸）：成為 KPI 橫條的直接 flex item */
#regional-status,
.regional-status-grid {
    display: contents;
}
.regional-status-card {
    flex: 1 1 0;
    min-width: 0;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 0.5rem 0.65rem;
    box-sizing: border-box;
}
.regional-status-card .label {
    font-size: 0.78rem;
    color: #64748b;
    font-weight: 500;
    margin-bottom: 0.2rem;
    display: flex;
    gap: 0.3rem;
    align-items: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.regional-status-card .period {
    color: #94a3b8;
    font-size: 0.72rem;
    font-weight: 400;
}
.regional-status-card .value {
    font-size: 1.15rem;
    font-weight: 700;
    color: #0f172a;
}
.regional-status-card .unit {
    font-size: 0.76rem;
    color: #64748b;
    font-weight: 500;
    margin-left: 0.15rem;
}
.regional-status-card .sub {
    font-size: 0.74rem;
    color: #64748b;
    margin-top: 0.2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* PC 端 5 張卡權重微調：所得與人口卡給予適度彈性，總筆數與均價卡緊湊對齊 */
.card-income {
    flex: 1.15 1 0;
}
.card-population {
    flex: 1.05 1 0;
}
.card-mortgage {
    flex: 1 1 0;
}
.card-tx-total {
    flex: 0.9 1 0;
}
.card-tx-price {
    flex: 0.9 1 0;
}
/* KPI 卡主要數值與變化量水平排列行 */
.value-row {
    display: flex;
    align-items: baseline;
    gap: 0.45rem;
    flex-wrap: wrap;
}
/* KPI 卡 YoY（年對年同期）變化：regional-status 卡與 panel-summary 卡共用 */
.regional-status-card .yoy,
.panel-summary-item .yoy {
    margin-top: 0;
    font-size: 0.78rem;
    font-weight: 500;
    color: #64748b;
    white-space: nowrap;
}
.regional-status-card .yoy .summary-change,
.panel-summary-item .yoy .summary-change {
    font-size: 0.78rem;
    font-weight: 600;
}
.regional-status-card .yoy .summary-change.up,
.panel-summary-item .yoy .summary-change.up { color: #16a34a; }
.regional-status-card .yoy .summary-change.down,
.panel-summary-item .yoy .summary-change.down { color: #ef4444; }
.regional-status-card .yoy .pct-str,
.panel-summary-item .yoy .pct-str {
    font-size: 0.72rem;
    color: #94a3b8;
    font-weight: 400;
}
.regional-status-card .yoy .yoy-na,
.panel-summary-item .yoy .yoy-na {
    color: #cbd5e1;
}
/* 面板內的交易表格 */
.detail-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.85rem;
}
.detail-table th {
    background: #4A90D9;
    color: #fff;
    padding: 0.6rem;
    text-align: left;
    position: sticky;
    top: 0;
    z-index: 10;
}
.detail-table th,
.detail-table td {
    white-space: nowrap;
}
.detail-table td {
    padding: 0.5rem 0.6rem;
    border-bottom: 1px solid #eee;
}
.detail-table tbody tr {
    position: relative;
    z-index: 0;
    cursor: pointer;
}
.detail-table tr:nth-child(even) {
    background: #f9f9f9;
}
.detail-table tr:hover {
    background: #e8f0fe;
}
.detail-table .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.detail-table .unit {
    font-size: 0.75em;
    color: #999;
    margin-left: 1px;
}
.detail-table th .unit {
    color: rgba(255, 255, 255, 0.8);
}
/* 分頁按鈕 */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1rem;
}
.pagination button {
    padding: 0.4rem 0.8rem;
    border: 1px solid #4A90D9;
    background: #fff;
    color: #4A90D9;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
}
.pagination button:hover:not(:disabled) {
    background: #e8f0fe;
}
.pagination button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.pagination button.active {
    background: #4A90D9;
    color: #fff;
}
.pagination .page-info {
    font-size: 0.85rem;
    color: #666;
}

.filter-divider {
    width: 100%;
    height: 0;
    border-top: 1px solid #e0e0e0;
    margin: 4px 0;
}
.custom-date-panel {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease, padding 0.25s ease;
    padding: 0 10px;
}
.custom-date-panel.open {
    max-height: 60px;
    padding: 8px 10px 10px;
}
.custom-date-inner {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
}
.custom-date-inner input[type="date"] {
    padding: 3px 6px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.82rem;
}
.date-sep {
    color: #888;
}
.custom-date-inner button {
    padding: 4px 10px;
    background: #4A90D9;
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 0.82rem;
    cursor: pointer;
}
.custom-date-inner button:hover {
    background: #357ABD;
}
/* 篩選徽章 */
.filter-badge {
    display: inline-block;
    background: #E3F2FD;
    color: #1565C0;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.8rem;
}

/* KPI 狀態提示 - 保留原卡片顏色，僅用文字顏色區分 */
.summary-card.status-up, .summary-card.status-down, .summary-card.status-stable {
    /* 保留原漸層背景 */
}
.summary-card .card-alert {
    margin-top: 0.4rem;
    padding: 0.35rem 0.5rem;
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
    border-radius: 6px;
    font-size: 0.78rem;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}
.price-card.status-down .card-value-large { color: #1a365d; }

/* 橘點對話泡泡（點選地點後顯示） */
.tx-bubble-tooltip {
    background: #fff;
    border: 2px solid #E86A10;
    border-radius: 8px;
    padding: 6px 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.18);
    font-size: 0.78rem;
    line-height: 1.4;
    white-space: nowrap;
}
.tx-bubble-tooltip::before {
    border-top-color: #E86A10;
}
.tx-bubble-price {
    font-weight: 700;
    color: #E86A10;
    font-size: 0.9rem;
}
.tx-bubble-price .unit {
    font-size: 0.7em;
    font-weight: 600;
    margin-left: 1px;
}
.tx-bubble-detail {
    color: #555;
    font-size: 0.72rem;
}
.tx-bubble-detail .unit {
    font-size: 0.85em;
    color: #999;
    margin-left: 1px;
}
.tx-card.status-down .card-value-large { color: #7c3a00; }

/* Address text cannot enlarge the column; JS scales only text that exceeds it. */
/* Compact numeric columns; give the address all remaining table width. */
.detail-table th:not(.address-column),
.detail-table td:not(.address-column) { width: 1%; }
.detail-table .address-column { width: auto; }
.detail-table th,
.detail-table td { padding-left: 0.35rem; padding-right: 0.35rem; }
.detail-table .address-fit {
    display: block;
    width: 0;
    min-width: 100%;
    white-space: nowrap;
}
.detail-table .address-fit > span {
    display: inline-block;
    white-space: nowrap;
}

/* ── 全頁底部版權聲明與資料來源列 ── */
#app-footer {
    flex-shrink: 0;
    min-height: 34px;
    background: #1e293b;
    color: #94a3b8;
    font-size: 0.74rem;
    padding: 0 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid #334155;
    z-index: 1000;
    box-sizing: border-box;
}
#app-footer a {
    color: #60a5fa;
    text-decoration: none;
    transition: color 0.15s ease;
}
#app-footer a:hover {
    color: #93c5fd;
    text-decoration: underline;
}
.footer-left, .footer-center, .footer-right {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}
.footer-sep {
    color: #475569;
    font-size: 0.7em;
}
.footer-about-btn {
    background: #334155;
    color: #e2e8f0;
    border: 1px solid #475569;
    border-radius: 4px;
    padding: 3px 8px;
    font-size: 0.72rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.15s ease;
    font-family: inherit;
}
.footer-about-btn:hover {
    background: #475569;
    color: #fff;
    border-color: #64748b;
}

/* ── 授權與圖資詳細說明彈出視窗 (Modal) ── */
.about-modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(2px);
    z-index: 99999;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}
.about-modal-backdrop.show {
    opacity: 1;
    pointer-events: auto;
}
.about-modal {
    background: #ffffff;
    border-radius: 12px;
    width: 90%;
    max-width: 680px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.25), 0 10px 10px -5px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
}
.about-modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8fafc;
    border-radius: 12px 12px 0 0;
}
.about-modal-header h3 {
    margin: 0;
    font-size: 1.15rem;
    color: #0f172a;
    display: flex;
    align-items: center;
    gap: 8px;
}
.about-modal-close {
    background: transparent;
    border: none;
    font-size: 1.25rem;
    color: #64748b;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    line-height: 1;
}
.about-modal-close:hover {
    background: #e2e8f0;
    color: #0f172a;
}
.about-modal-body {
    padding: 20px 24px;
    color: #334155;
    font-size: 0.88rem;
    line-height: 1.6;
}
.about-section {
    margin-bottom: 18px;
}
.about-section:last-child {
    margin-bottom: 0;
}
.about-section h4 {
    margin: 0 0 6px 0;
    color: #0f172a;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 6px;
}
.about-section p, .about-section ul {
    margin: 0 0 6px 0;
    color: #475569;
}
.about-section ul {
    padding-left: 20px;
}
.about-section li {
    margin-bottom: 4px;
}
.about-section a {
    color: #2563eb;
    text-decoration: none;
}
.about-section a:hover {
    text-decoration: underline;
}
.about-badge {
    display: inline-block;
    background: #e0f2fe;
    color: #0369a1;
    font-size: 0.72rem;
    padding: 1px 6px;
    border-radius: 4px;
    font-weight: 500;
}
.about-disclaimer {
    background: #fef2f2;
    border: 1px solid #fee2e2;
    border-radius: 8px;
    padding: 10px 14px;
    color: #991b1b;
    font-size: 0.82rem;
    margin-top: 14px;
}

@media (max-width: 1024px) {
    /* ── 行動裝置外層容器重構 ── */
    #main-container {
        position: relative;
        width: 100%;
        height: 100%;
        flex: 1;
        min-height: 0;
        overflow: hidden;
        display: block;
    }

    #map-wrapper {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        z-index: 1;
    }

    #map {
        width: 100%;
        height: 100%;
    }

    /* ── BottomSheet 抽屜容器 ── */
    #info-drawer {
        display: flex;
        flex-direction: column;
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        background: #ffffff;
        border-radius: 24px 24px 0 0;
        box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.16), 0 -1px 3px rgba(0, 0, 0, 0.06);
        z-index: 1000;
        overflow: hidden;
        transition: height 0.32s cubic-bezier(0.32, 0.72, 0, 1);
        touch-action: pan-y;
    }

    /* 三段式高度 */
    #info-drawer.sheet-peek {
        height: 140px;
    }
    #info-drawer.sheet-half {
        height: 52vh;
    }
    #info-drawer.sheet-full {
        height: calc(100% - 44px);
    }

    /* 抽屜拖曳手柄與狀態列 */
    #bottom-sheet-handle {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 9px 0 6px 0;
        cursor: pointer;
        user-select: none;
        background: #ffffff;
        border-bottom: 1px solid #f1f5f9;
        flex-shrink: 0;
        width: 100%;
    }
    .handle-bar {
        width: 44px;
        height: 5px;
        border-radius: 999px;
        background: #cbd5e1;
        transition: background 0.2s, transform 0.2s;
    }
    #bottom-sheet-handle:active .handle-bar {
        background: #94a3b8;
        transform: scaleX(1.12);
    }
    .handle-hint {
        font-size: 10.5px;
        color: #94a3b8;
        font-weight: 500;
        margin-top: 3px;
        letter-spacing: 0.02em;
    }

    /* 抽屜內容容器 */
    #info {
        width: 100%;
        min-width: 0;
        flex: 1;
        height: auto;
        min-height: 0;
        border-left: none;
        padding: 0.75rem 1rem calc(env(safe-area-inset-bottom, 12px) + 1.25rem) 1rem;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        background-color: #ffffff;
        box-sizing: border-box;
    }

    #info h2 {
        font-size: 1.2rem;
        margin-top: 0;
        margin-bottom: 0.5rem;
        padding-bottom: 0.35rem;
    }

    /* KPI 卡片自適應縮放 */
    .district-summary {
        gap: 0.5rem;
        margin-bottom: 0.75rem;
    }
    .summary-card {
        padding: 0.4rem 0.65rem;
    }
    .summary-card .card-main-val {
        font-size: 1.35rem;
    }

    /* 篩選列緊湊設計 */
    .filter-bar {
        padding: 6px 8px;
        gap: 4px;
        margin-bottom: 0.6rem;
    }
    .filter-btn {
        padding: 4px 10px;
        font-size: 0.8rem;
    }
    .ws-tab {
        padding: 5px 10px;
        font-size: 0.85rem;
    }

    /* 詳細交易清單面板（全螢幕彈出層） */
    #detail-panel {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 0;
        z-index: 1100;
        border-radius: 24px 24px 0 0;
        box-shadow: 0 -12px 36px rgba(0, 0, 0, 0.28);
        border-top: none;
        transition: height 0.35s cubic-bezier(0.32, 0.72, 0, 1);
        background: #ffffff;
    }
    #detail-panel.open {
        height: 82vh;
    }
    .panel-header {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        padding: 10px 14px 8px 14px;
    }
    .panel-title {
        order: 1;
        font-size: 1.1rem;
        font-weight: 700;
        white-space: nowrap;
        color: #ffffff;
    }
    .panel-close {
        order: 2;
        margin-left: auto;
        padding: 0.2rem 0.55rem;
    }
    .panel-filter-badges {
        order: 3;
        width: 100%;
        margin-top: 6px;
        margin-left: 0;
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        gap: 4px;
        justify-content: flex-start;
        padding-bottom: 2px;
    }
    .panel-filter-badges::-webkit-scrollbar {
        display: none;
    }
    .panel-filter-badges .filter-badge {
        white-space: nowrap;
        flex-shrink: 0;
        font-size: 0.74rem;
        padding: 2px 8px;
    }

    /* 頁尾在手機版收納，避免遮蔽地圖 */
    #app-footer {
        display: none;
    }

    /* 手機版頂部浮動資訊按鈕（供查看授權與說明） */
    .mobile-info-fab {
        display: flex;
        align-items: center;
        justify-content: center;
        position: absolute;
        top: 12px;
        right: 12px;
        width: 36px;
        height: 36px;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.92);
        backdrop-filter: blur(6px);
        border: 1px solid rgba(0, 0, 0, 0.1);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
        z-index: 900;
        cursor: pointer;
        font-size: 14px;
        color: #475569;
        transition: transform 0.15s, background 0.15s;
    }
    .mobile-info-fab:active {
        transform: scale(0.92);
        background: #e2e8f0;
    }

    /* ── 響應式表格切換（行動版） ── */
    .desktop-only-colgroup { display: none !important; }
    .desktop-only-row { display: none !important; }
    .desktop-only-col { display: none !important; }
    .desktop-only-inline { display: none !important; }
    .mobile-only-colgroup { display: table-column-group !important; }
    .mobile-only-row { display: table-row !important; }
    .mobile-only-col { display: table-cell !important; }
    .mobile-only-inline { display: inline-block !important; }
    .mobile-only-block { display: block !important; }

    /* ── 行動版緊湊統計表格與整合欄位 ── */
    .stats-table-wrap {
        margin-top: 0.35rem;
        max-height: none;
        border: 1px solid #e2e8f0;
        border-radius: 8px;
    }
    .stats-table-scroll {
        overflow-y: visible;
    }
    .scroll-hint {
        display: none;
    }

    .stats-table {
        font-size: 0.82rem;
        table-layout: auto;
    }
    .stats-table th,
    .stats-table td {
        padding: 0.22rem 0.35rem;
        line-height: 1.25;
    }

    /* 重設桌面版寫死之欄寬限制 */
    .stats-table th:nth-child(1), .stats-table td:nth-child(1),
    .stats-table th:nth-child(2), .stats-table td:nth-child(2),
    .stats-table th:nth-child(3), .stats-table td:nth-child(3),
    .stats-table th:nth-child(4), .stats-table td:nth-child(4),
    .stats-table th:nth-child(5), .stats-table td:nth-child(5) {
        width: auto;
        min-width: 0 !important;
        max-width: none !important;
    }

    /* 全國排名表手機專用排版 */
    #national-tbl th.col-rank,
    #national-tbl td.rank-num {
        width: 72px;
        min-width: 72px !important;
        text-align: center;
        padding-left: 2px;
        padding-right: 2px;
        white-space: nowrap;
    }
    #national-tbl th.col-county,
    #national-tbl td.col-county {
        width: 60px;
        min-width: 60px !important;
        text-align: center;
        white-space: nowrap;
    }
    #national-tbl th.col-tx,
    #national-tbl td.cell-tx-main {
        text-align: right;
        padding-right: 8px;
        border-right: none !important;
    }

    /* 鄉鎮市區表手機專用排版 */
    #district-tbl th.col-township,
    #district-tbl td.col-township {
        width: 68px;
        min-width: 68px !important;
        text-align: center;
        white-space: nowrap;
    }
    #district-tbl th.col-tx,
    #district-tbl td.cell-tx-main {
        text-align: right;
        padding-right: 6px;
        border-right: 1px solid #e2e8f0 !important;
    }
    #district-tbl th.col-price,
    #district-tbl td.cell-price-main {
        text-align: right;
        padding-right: 8px;
        border-right: none !important;
    }

    /* 整合欄位內的標籤與變化量徽章 */
    .rank-sub-th {
        font-size: 0.68rem;
        font-weight: 400;
        opacity: 0.88;
        margin-left: 2px;
    }
    .rank-prev-val {
        font-size: 0.7rem;
        color: #64748b;
        background: #f1f5f9;
        border: 1px solid #e2e8f0;
        border-radius: 3px;
        padding: 0px 3px;
        margin-left: 3px;
        font-weight: 500;
        display: inline-block;
        vertical-align: baseline;
    }
    .cell-tx-diff,
    .cell-price-diff {
        margin-left: 4px;
        font-size: 0.72rem;
        font-weight: 500;
        white-space: nowrap;
    }
    .cell-tx-diff .row-change,
    .cell-price-diff .row-change {
        font-size: 0.72rem;
    }
    .cell-tx-diff .row-pct,
    .cell-price-diff .row-pct {
        font-size: 0.68rem;
        font-weight: 400;
        opacity: 0.85;
    }
    .stats-table .cell-main {
        font-weight: 600;
        font-size: 0.84rem;
    }

    /* ── 詳細交易明細彈出視窗（行動端極致排版與欄寬再分配） ── */
    .panel-inner-pad {
        padding: 0.4rem 0.35rem 1.2rem 0.35rem;
    }
    .kpi-strip {
        padding: 0.5rem 0.45rem 0;
        gap: 0.45rem;
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
    }
    .panel-summary-item,
    .regional-status-card {
        padding: 0.42rem 0.55rem;
        border-radius: 8px;
        box-sizing: border-box;
    }

    /* 卡片標題與日期 */
    .regional-status-card .label,
    .panel-summary-item .label {
        font-size: 0.74rem;
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        white-space: nowrap;
        margin-bottom: 0.2rem;
    }

    /* 左邊主要數字稍微放大 */
    .panel-summary-item .value,
    .regional-status-card .value {
        font-size: 1.18rem !important;
        font-weight: 700;
        line-height: 1.15;
        letter-spacing: -0.01em;
    }
    .panel-summary-item .unit,
    .regional-status-card .unit {
        font-size: 0.75rem;
        margin-left: 2px;
    }

    /* 數值變化區塊：數字在上，百分比在下，緊湊排列 */
    .regional-status-card .value-row,
    .panel-summary-item .value-row {
        display: flex;
        align-items: center;
        gap: 0.35rem;
        flex-wrap: nowrap;
    }
    .regional-status-card .yoy,
    .panel-summary-item .yoy {
        display: inline-flex;
        flex-direction: column;
        align-items: flex-start;
        justify-content: center;
        line-height: 1.1;
        margin-left: 0.2rem;
        flex-shrink: 0;
    }
    .regional-status-card .yoy .summary-change,
    .panel-summary-item .yoy .summary-change {
        font-size: 0.72rem;
        font-weight: 600;
        white-space: nowrap;
        line-height: 1.1;
    }
    .regional-status-card .yoy .pct-str,
    .panel-summary-item .yoy .pct-str {
        font-size: 0.66rem;
        color: #94a3b8;
        font-weight: 400;
        white-space: nowrap;
        line-height: 1.1;
        margin-top: 1px;
    }
    .regional-status-card .sub {
        font-size: 0.70rem;
        color: #64748b;
        margin-top: 0.2rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* 最大兩張資訊卡（人口現況、平均每戶可支配所得）在手機版並排顯示 (50% / 50%) */
    .card-population,
    .card-income {
        order: 1;
        flex: 1 1 calc(50% - 0.25rem) !important;
        width: calc(50% - 0.25rem) !important;
        min-width: 0 !important;
        max-width: calc(50% - 0.25rem) !important;
    }
    .card-income {
        order: 2;
    }

    /* 總筆數與成交均價在手機版亦並排顯示 (50% / 50%) */
    .card-tx-total {
        order: 3;
        flex: 1 1 calc(50% - 0.25rem) !important;
        width: calc(50% - 0.25rem) !important;
        min-width: 0 !important;
        max-width: calc(50% - 0.25rem) !important;
    }
    .card-tx-price {
        order: 4;
        flex: 1 1 calc(50% - 0.25rem) !important;
        width: calc(50% - 0.25rem) !important;
        min-width: 0 !important;
        max-width: calc(50% - 0.25rem) !important;
    }

    /* 房貸負擔率佔整列，作為緊湊橫向列 */
    .card-mortgage {
        order: 5;
        flex: 1 1 100% !important;
        width: 100% !important;
        min-width: 0 !important;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        padding: 0.35rem 0.65rem;
    }
    .card-mortgage .label {
        margin-bottom: 0;
        font-size: 0.76rem;
    }
    .card-mortgage .value-row {
        margin: 0;
    }
    .card-mortgage .value {
        font-size: 1.15rem !important;
    }
    .card-mortgage .sub {
        margin-top: 0;
        font-size: 0.74rem;
        color: #64748b;
    }

    .detail-table {
        font-size: 0.76rem;
        table-layout: auto;
        width: 100%;
    }
    .detail-table th {
        font-size: 0.70rem;
        padding: 0.32rem 0.15rem;
        line-height: 1.15;
        text-align: center;
        letter-spacing: -0.01em;
    }
    .detail-table th .unit {
        display: block;
        font-size: 0.65em;
        line-height: 1;
        margin-top: 1px;
    }
    .detail-table td {
        padding: 0.30rem 0.15rem;
        line-height: 1.2;
    }

    /* 交易年月：縮小字級、緊湊字距、置中 */
    .detail-table th.col-date,
    .detail-table td.col-date {
        width: 44px;
        min-width: 42px;
        max-width: 46px;
        font-size: 0.68rem;
        font-variant-numeric: tabular-nums;
        letter-spacing: -0.02em;
        text-align: center;
        white-space: nowrap;
    }

    /* 屋齡與樓層 */
    .detail-table th.col-age,
    .detail-table td.col-age {
        width: 32px;
        min-width: 30px;
        max-width: 34px;
        text-align: right;
        white-space: nowrap;
    }
    .detail-table th.col-floor,
    .detail-table td.col-floor {
        width: 28px;
        min-width: 26px;
        max-width: 32px;
        text-align: center;
        white-space: nowrap;
    }

    /* 格局：緊湊單位文字 */
    .detail-table th.col-layout,
    .detail-table td.col-layout {
        width: 44px;
        min-width: 42px;
        max-width: 48px;
        font-size: 0.70rem;
        text-align: center;
        white-space: nowrap;
    }
    .detail-table th.col-layout .unit,
    .detail-table td.col-layout .unit {
        font-size: 0.65em;
        margin: 0;
    }

    /* 土地、建物、總價、單價：緊湊欄寬 */
    .detail-table th.col-land,
    .detail-table td.col-land,
    .detail-table th.col-building,
    .detail-table td.col-building {
        width: 34px;
        min-width: 32px;
        max-width: 38px;
        text-align: right;
        white-space: nowrap;
    }
    .detail-table th.col-price,
    .detail-table td.col-price {
        width: 34px;
        min-width: 32px;
        max-width: 40px;
        text-align: right;
        white-space: nowrap;
    }
    .detail-table th.col-unit-price,
    .detail-table td.col-unit-price {
        width: 36px;
        min-width: 34px;
        max-width: 42px;
        text-align: right;
        white-space: nowrap;
    }

    /* 所在地址：獲取剩餘所有彈性寬度，最低預留 80px+ */
    .detail-table th.address-column,
    .detail-table td.address-column {
        width: auto !important;
        min-width: 80px;
        padding-left: 0.25rem;
        padding-right: 0.25rem;
        text-align: left;
    }
    .detail-table .address-fit {
        font-size: 0.78rem;
    }
}
