/* ===== 市場分析頁面專屬樣式 ===== */

body.market-tab {
    background-color: #f4f7f6;
}

/* 時間範圍區塊 */
.time-range-section {
    background: var(--color-bg-surface);
    padding: 1rem var(--section-px);
    border-radius: var(--radius-lg);
    margin-bottom: 1rem;
}

.time-range-section h2 {
    margin-bottom: 0.75rem;
    color: var(--color-text);
    font-size: 1.2rem;
}

.time-range-grid {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.time-range-grid select {
    padding: 0.6rem 0.8rem;
    border: 2px solid var(--color-border-input);
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    transition: border-color var(--transition-fast);
}

.time-range-grid select:focus-visible {
    outline: none;
    border-color: var(--color-primary-light);
}

.market-redesign .field-group[data-member-only="date-range"].member-locked .time-range-grid select {
    cursor: pointer;
}

.market-redesign .member-only-badge {
    display: inline-flex;
    align-items: center;
    min-height: 20px;
    margin-left: 6px;
    padding: 0 8px;
    border: 1px solid rgba(47, 140, 130, 0.24);
    border-radius: 999px;
    color: var(--m-teal);
    background: rgba(47, 140, 130, 0.08);
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1;
}

.market-redesign .field-group[data-member-only="date-range"]:not(.member-locked) .member-only-badge {
    display: none;
}

.time-range-separator {
    color: var(--color-text-muted);
    font-weight: 500;
    padding: 0 0.25rem;
}

/* 快速選擇區塊 */
.quick-select-section {
    background: var(--color-bg-surface);
    padding: 1rem var(--section-px);
    border-radius: var(--radius-lg);
    margin-bottom: 1rem;
}

.quick-select-section h2 {
    margin-bottom: 0.75rem;
    color: var(--color-text);
    font-size: 1.2rem;
}

.quick-select-group {
    margin-bottom: 0.5rem;
}

.quick-select-label {
    font-weight: 600;
    color: var(--color-text-secondary);
    font-size: 0.85rem;
    margin-bottom: 0.4rem;
}

.quick-cards-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}

.quick-card {
    background: white;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 0.6rem 1rem;
    cursor: pointer;
    transition: border-color var(--transition-fast), background-color var(--transition-fast), box-shadow var(--transition-fast);
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: 500;
    font-size: 0.95rem;
    color: var(--color-text);
    min-height: 44px;
}

@media (hover: hover) {
    .quick-card:hover {
        border-color: var(--color-primary);
        background-color: rgba(18, 118, 110, 0.08);
        box-shadow: var(--shadow-md);
    }
}

.quick-card:active {
    background-color: rgba(18, 118, 110, 0.15);
}

.quick-card i {
    color: var(--color-primary);
    font-size: 0.9rem;
}

/* 市場分析操作按鈕區塊 */
#market-tab > .filter-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    margin-bottom: 1.5rem;
}

/* 手機版市場分析調整 */
@media (max-width: 768px) {
    .time-range-section,
    .quick-select-section {
        padding-top: 0.5rem;
        padding-bottom: 0.5rem;
    }

    .time-range-section h2,
    .quick-select-section h2 {
        font-size: 1rem;
    }

    .time-range-grid select {
        padding: 0.5rem 0.6rem;
        font-size: 0.9rem;
    }

    .quick-card {
        padding: 0.5rem 0.8rem;
        font-size: 0.9rem;
    }
}

/* ===== 市場分析 v2 — 2 欄 sticky 工作台（PR2） =====
   非阻塞載入；critical layout 在 templates/partials/_market_critical.css.html。
   只在 .market-redesign 容器內生效，不影響其他 tab。 */

/* 寬度對齊 /developer：桌機 1440px、左右 16px gap、手機 10px gap */
body.market-tab .container {
    max-width: 1440px;
    padding-left: 16px;
    padding-right: 16px;
}
@media (max-width: 760px) {
    body.market-tab .container {
        padding-left: 10px;
        padding-right: 10px;
    }
}
/* 拔掉 main 預設白卡 padding（沿用 /developer 處理） */
body.market-tab #main-content {
    background: transparent;
    border-radius: 0;
    padding: 0;
    margin: 0;
    box-shadow: none;
}

#market-tab .market-redesign .workspace {
    margin-top: 0;
}

.market-redesign {
    --m-ink: #22313f;
    --m-muted: #64727f;
    --m-line: #dce4ea;
    --m-soft: #eef4f2;
    --m-paper: #ffffff;
    --m-brand: #12766e;
    --m-brand-dark: #245f8d;
    --m-teal: #2f8c82;
    --m-teal-soft: #dff0ed;
    --m-amber: #0891b2;
    --m-amber-soft: #e0f2fe;
    --m-red: #bf4f4b;
    --m-shadow: 0 14px 42px rgba(31, 45, 55, 0.10);
    --m-radius: 8px;
}

/* 控制面板：grid 容器，hero + search-stack 上下排 */
.market-redesign .control-panel {
    display: grid;
    gap: 0;
    border: 1px solid rgba(220, 228, 234, 0.95);
    border-radius: var(--m-radius);
    background: rgba(255, 255, 255, 0.92);
    box-shadow: var(--m-shadow);
}

.market-redesign .hero-strip {
    min-height: 168px;
    padding: 18px 20px;
    color: #fff;
    background:
        linear-gradient(110deg, rgba(34, 49, 63, 0.94), rgba(34, 49, 63, 0.54)),
        linear-gradient(135deg, #2f8c82 0%, #1f594f 100%);
    border-radius: var(--m-radius) var(--m-radius) 0 0;
}
.market-redesign .hero-strip .eyebrow {
    display: inline-flex;
    align-items: center;
    padding: 4px 9px;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.14);
    font-size: 0.78rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.92);
}
.market-redesign .hero-strip h1 {
    margin: 14px 0 8px;
    font-size: clamp(1.45rem, 2.6vw, 1.95rem);
    line-height: 1.2;
    color: #fff;
    font-weight: 800;
}
.market-redesign .hero-strip p {
    margin: 0;
    color: rgba(255, 255, 255, 0.84);
    line-height: 1.6;
    font-size: 0.9rem;
}

.market-redesign .search-stack {
    display: grid;
    gap: 16px;
    padding: 16px;
}

.market-redesign .field-group {
    display: block;
}
.market-redesign .field-label {
    display: block;
    margin-bottom: 8px;
    color: var(--m-muted);
    font-size: 0.84rem;
    font-weight: 700;
}
.market-redesign .field-label i {
    margin-right: 4px;
}

.market-redesign .search-stack .time-range-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 14px 1fr 1fr;
    gap: 6px;
}
.market-redesign .search-stack .time-range-grid select {
    min-height: 36px;
    padding: 0 8px;
    border: 1px solid var(--m-line);
    border-radius: 6px;
    font-size: 0.86rem;
    background: #fff;
}
.market-redesign .search-stack .time-range-separator {
    color: var(--m-muted);
    text-align: center;
    line-height: 36px;
    padding: 0;
}

/* 快速 chip group（行政區 / 重劃區） */
.market-redesign .quick-group .quick-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 8px;
}
.market-redesign .quick-group .quick-head strong {
    font-size: 0.92rem;
    color: var(--m-ink);
}
.market-redesign .quick-group .quick-head span {
    color: var(--m-muted);
    font-size: 0.76rem;
    font-weight: 600;
}
.market-redesign .quick-group .quick-cards-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 0;
}

/* override 既有 .quick-card：sidebar context 內變小；
   一般入口維持白底，只有實際選到的行政區/重劃區才上底色。 */
.market-redesign .quick-card {
    min-height: 30px;
    padding: 4px 10px;
    border: 1px solid var(--m-line);
    border-radius: 6px;
    background: #fff;
    color: var(--m-ink);
    font-size: 0.82rem;
    font-weight: 600;
    box-shadow: none;
}
.market-redesign .quick-card.active,
.market-redesign .quick-card[aria-pressed="true"] {
    border-color: var(--m-teal);
    background: var(--m-teal-soft);
    color: var(--m-ink);
    font-weight: 750;
}
.market-redesign .quick-card i {
    color: var(--m-muted);
}
.market-redesign .quick-card[aria-pressed="true"] i {
    color: var(--m-teal);
}
@media (hover: hover) {
    .market-redesign .quick-card:hover:not(.active):not([aria-pressed="true"]) {
        border-color: var(--m-muted);
        background: #fff;
        box-shadow: none;
    }
    .market-redesign .quick-card.active:hover,
    .market-redesign .quick-card[aria-pressed="true"]:hover {
        border-color: var(--m-teal);
        background: var(--m-teal-soft);
        box-shadow: none;
    }
}

.market-redesign .zone-drawer-trigger {
    margin-top: 10px;
    width: 100%;
    min-height: 36px;
    padding: 0 12px;
    border: 1px dashed var(--m-line);
    border-radius: 6px;
    background: #fff;
    color: var(--m-teal);
    font-weight: 700;
    font-size: 0.86rem;
    cursor: pointer;
    transition: background 0.18s ease;
}
.market-redesign .zone-drawer-trigger:hover {
    border-color: rgba(47, 140, 130, 0.42);
    background: #fff;
}

/* 行政區「更多」popover — chip row 末尾觸發、彈出 4×n 網格選 26 個非熱門區 */
.market-redesign .quick-card.district-more-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #fff;
    border-color: var(--m-line);
    border-style: dashed;
    color: var(--m-teal);
}
.market-redesign .quick-card.district-more-btn[aria-pressed="true"] {
    background: var(--m-teal-soft);
    border-style: solid;
    border-color: var(--m-teal);
    color: var(--m-ink);
}
.market-redesign .quick-card.district-more-btn i {
    font-size: 0.7rem;
    color: inherit;
}

.market-redesign .quick-group[data-quick-group="district"] {
    position: relative;
}

.market-redesign .district-popover {
    position: absolute;
    z-index: 80;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    padding: 12px;
    background: #fff;
    border: 1px solid var(--m-line);
    border-radius: var(--m-radius);
    box-shadow: 0 18px 48px rgba(31, 45, 55, 0.14);
}
.market-redesign .district-popover[hidden] { display: none; }

.market-redesign .district-popover-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
}
.market-redesign .district-popover-btn {
    min-height: 30px;
    padding: 4px 6px;
    border: 1px solid var(--m-line);
    border-radius: 6px;
    background: #fff;
    color: var(--m-ink);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}
@media (hover: hover) {
    .market-redesign .district-popover-btn:hover {
        border-color: var(--m-muted);
    }
}
.market-redesign .district-popover-btn[aria-pressed="true"],
.market-redesign .district-popover-btn.active {
    border-color: var(--m-teal);
    background: var(--m-teal-soft);
    font-weight: 750;
}
.market-redesign .district-popover-all {
    border-style: dashed;
    color: var(--m-teal);
}

/* mobile: popover 改成置中全寬 modal-like */
@media (max-width: 760px) {
    .market-redesign .district-popover {
        position: fixed;
        top: 50%;
        left: 16px;
        right: 16px;
        transform: translateY(-50%);
        max-height: 70vh;
        overflow-y: auto;
        z-index: 1000;
    }
    .market-redesign .district-popover-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

/* 操作按鈕 */
.market-redesign .filter-actions {
    display: flex;
    gap: 8px;
    margin: 0;
}
.market-redesign .filter-actions button {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 40px;
    padding: 0 12px;
    border-radius: 6px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    border: 1px solid transparent;
}
.market-redesign .filter-actions button i {
    width: 1em;
    text-align: center;
}
.market-redesign .filter-actions .btn-primary {
    background: var(--m-teal);
    color: #fff;
    border-color: var(--m-teal);
}
.market-redesign .filter-actions .btn-primary:hover {
    background: #237971;
}
.market-redesign .filter-actions .btn-secondary {
    background: #fff;
    color: var(--m-ink);
    border-color: var(--m-line);
}

/* === 右側 content panels === */
.market-redesign .content {
    display: grid;
    gap: 18px;
    min-width: 0;
    padding: 0;
}

/* 右欄底部 ad-slot：grid 環境下 .ad-slot 的 margin:auto 會 shrink-to-content，
   <ins class="adsbygoogle"> 初始寬度 0 → 整個 slot 塌成 label 寬，AdSense push 失敗。
   強制 stretch 到欄位寬（max-width 仍由 .ad-slot-bottom 970px 限制）。 */
.market-redesign .content > .ad-slot {
    justify-self: center;
    width: min(100%, 970px);
    margin-left: 0;
    margin-right: 0;
}

.market-redesign .panel {
    position: relative;
    border: 1px solid rgba(220, 228, 234, 0.95);
    border-radius: var(--m-radius);
    background: rgba(255, 255, 255, 0.92);
    box-shadow: var(--m-shadow);
    overflow: hidden;
}

.market-redesign .price-range-comparison,
.market-redesign .presale-statistics {
    margin-bottom: 0;
}

.market-redesign .panel .chart-container {
    background: transparent;
    border-radius: 0;
    box-shadow: none;
    margin: 0;
    padding: 16px 18px 18px;
}

.market-redesign #presale-statistics .chart-container {
    padding-top: 14px;
}

.market-redesign .panel > .panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 0;
    padding: 14px 18px;
    border-bottom: 1px solid var(--m-line);
}
.market-redesign .panel-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 800;
    font-size: 0.95rem;
    line-height: 1.35;
    color: var(--m-ink);
}
.market-redesign .panel-title i {
    color: var(--m-teal);
}
.market-redesign .panel-tools {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* 既有 chart panel 的 h2 改用 panel-head 後就用 panel-head 樣式
   （但仍保留向後相容：h2 直接放在 section 也能 work） */
.market-redesign .panel > h2 {
    margin: 0;
    padding: 16px 18px 10px;
    font-size: 0.95rem;
    color: var(--m-ink);
    border-bottom: 1px solid var(--m-line);
}
.market-redesign .panel-copy {
    margin: 5px 0 0;
    max-width: 720px;
    color: var(--m-muted);
    font-size: 0.82rem;
    line-height: 1.55;
    font-weight: 500;
}

.market-redesign .market-signal-strip {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0;
    border-bottom: 1px solid var(--m-line);
    background: rgba(255, 255, 255, 0.82);
}
.market-redesign .market-signal-period {
    margin-top: 5px;
    color: var(--m-muted);
    font-size: 0.78rem;
    line-height: 1.45;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
}
.market-redesign .market-signal-card {
    min-height: 88px;
    padding: 14px 18px;
    border-right: 1px solid var(--m-line);
    display: grid;
    align-content: center;
    gap: 5px;
    font-family: 'Noto Sans TC', 'Microsoft JhengHei', 'PingFang TC', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-variant-numeric: tabular-nums;
}
.market-redesign .market-signal-card:last-child {
    border-right: 0;
}
.market-redesign .market-signal-card .signal-label {
    color: var(--m-muted);
    font-size: 0.8rem;
    line-height: 1.35;
    font-weight: 800;
}
.market-redesign .market-signal-card strong {
    color: var(--m-ink);
    font-size: 1.15rem;
    line-height: 1.25;
    font-weight: 900;
}
.market-redesign .market-signal-card strong.signal-up {
    color: #b94e3d;
}
.market-redesign .market-signal-card strong.signal-down {
    color: #2f6f9f;
}
.market-redesign .market-signal-card strong.signal-flat {
    color: var(--m-teal);
}
.market-redesign .market-signal-card small {
    color: var(--m-muted);
    font-size: 0.8rem;
    line-height: 1.45;
    font-weight: 500;
}

/* Summary band */
.market-redesign .summary-band {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0;
    margin: 0;
    padding: 0;
    border: 1px solid rgba(220, 228, 234, 0.95);
    border-radius: var(--m-radius);
    background: rgba(255, 255, 255, 0.92);
    box-shadow: var(--m-shadow);
    overflow: hidden;
}
.market-redesign .summary-band .metric-card {
    min-height: 86px;
    padding: 14px 16px;
    border: 0;
    border-right: 1px solid rgba(220, 228, 234, 0.85);
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    display: grid;
    grid-template-rows: 18px 32px;
    align-content: center;
    gap: 8px;
}
.market-redesign .summary-band .metric-card:last-child {
    border-right: 0;
}
.market-redesign .summary-band .metric-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--m-muted);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    line-height: 1.2;
    min-width: 0;
}
.market-redesign .summary-band .metric-top span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
/* icon 改 inline 灰色，拔掉 teal-soft 背景塊（不要喧賓奪主） */
.market-redesign .summary-band .metric-top i {
    width: auto;
    height: auto;
    background: transparent;
    color: var(--m-muted);
    font-size: 0.86rem;
    opacity: 0.55;
}
.market-redesign .summary-band .metric-value {
    margin: 0;
    font-size: clamp(1.45rem, 2.4vw, 1.75rem);
    line-height: 32px;
    font-weight: 850;
    color: var(--m-ink);
    display: flex;
    align-items: baseline;
    gap: 6px;
    min-height: 32px;
}
.market-redesign .summary-band .metric-value small {
    font-size: 0.7rem;
    line-height: 1;
    color: var(--m-muted);
    font-weight: 600;
}

/* Map panel */
.market-redesign .market-map-panel .seg {
    display: inline-flex;
    border: 1px solid var(--m-line);
    border-radius: 6px;
    overflow: hidden;
    background: #fff;
}
.market-redesign .market-map-panel .seg-btn {
    min-height: 30px;
    padding: 0 10px;
    border: 0;
    border-right: 1px solid var(--m-line);
    background: transparent;
    color: var(--m-muted);
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.18s ease, color 0.18s ease;
}
.market-redesign .market-map-panel .seg-btn:last-child {
    border-right: 0;
}
.market-redesign .market-map-panel .seg-btn.active {
    background: var(--m-teal);
    color: #fff;
}
.market-redesign .market-map-panel .seg-btn:disabled {
    cursor: wait;
    opacity: 0.62;
}
/* PR4: map-board = stage + side rail */
.market-redesign .market-map-panel .map-board {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 240px;
    gap: 0;
}
@media (max-width: 1180px) {
    .market-redesign .market-map-panel .map-board {
        grid-template-columns: 1fr;
    }
}

.market-redesign .market-map-panel .map-stage {
    position: relative;
    background: #eef4f1;
}
.market-redesign .market-map-panel .map-reset-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 450;
    width: 36px;
    height: 36px;
    display: inline-grid;
    place-items: center;
    border: 1px solid rgba(34, 49, 63, 0.14);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.95);
    color: #4d5c68;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(31, 45, 55, 0.14);
    transition: border-color 0.18s ease, color 0.18s ease, background 0.18s ease;
}
.market-redesign .market-map-panel .map-reset-btn:hover {
    border-color: rgba(47, 140, 130, 0.42);
    color: var(--m-teal);
    background: #fff;
}
.market-redesign .market-map-panel .map-skeleton {
    position: absolute;
    inset: 0;
    display: block;
    background: rgba(255, 255, 255, 0.96);
    color: var(--m-muted);
    font-size: 0.86rem;
    z-index: 1200;
    padding: 14px 18px;
}
.market-redesign .market-map-panel .map-skeleton-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 220px;
    grid-template-rows: 22px minmax(240px, 1fr) 12px 12px;
    gap: 12px 18px;
    height: 100%;
    min-height: 430px;
}
.market-redesign .market-map-panel .map-skeleton-layout span {
    display: block;
    border-radius: 8px;
    background: linear-gradient(90deg, rgba(220, 228, 234, 0.78), rgba(244, 247, 246, 0.96), rgba(220, 228, 234, 0.78));
    background-size: 220% 100%;
    animation: skeleton-shimmer 1.15s ease-in-out infinite;
}
.market-redesign .market-map-panel .map-skeleton-title {
    grid-column: 1;
    width: 180px;
}
.market-redesign .market-map-panel .map-skeleton-pill {
    grid-column: 2;
    width: 100%;
}
.market-redesign .market-map-panel .map-skeleton-canvas {
    grid-column: 1;
    grid-row: 2 / span 3;
    min-height: 360px;
}
.market-redesign .market-map-panel .map-skeleton-row {
    grid-column: 2;
    width: 100%;
}
.market-redesign .market-map-panel .map-skeleton-row.short {
    width: 72%;
}
.market-redesign .market-map-panel .map-skeleton-status {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 10px;
    pointer-events: none;
}
.market-redesign .market-map-panel .map-skeleton-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(47, 140, 130, 0.22);
    border-top-color: var(--m-teal);
    border-radius: 50%;
    animation: m-spin 0.8s linear infinite;
}
@keyframes m-spin {
    to { transform: rotate(360deg); }
}
.market-redesign .market-map-panel.is-ready .map-skeleton {
    display: none;
}
@media (max-width: 1180px) {
    .market-redesign .market-map-panel .map-skeleton-layout {
        grid-template-columns: 1fr;
        grid-template-rows: 22px minmax(260px, 1fr) 12px 12px;
        min-height: 520px;
    }
    .market-redesign .market-map-panel .map-skeleton-pill,
    .market-redesign .market-map-panel .map-skeleton-row,
    .market-redesign .market-map-panel .map-skeleton-row.short {
        grid-column: 1;
    }
    .market-redesign .market-map-panel .map-skeleton-canvas {
        grid-column: 1;
        grid-row: 2;
    }
}

/* PR4: 側欄 hbar */
.market-redesign .market-map-panel .map-aside {
    border-left: 1px solid var(--m-line);
    background: rgba(255, 255, 255, 0.78);
    padding: 14px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
@media (max-width: 1180px) {
    .market-redesign .market-map-panel .map-aside {
        border-left: 0;
        border-top: 1px solid var(--m-line);
    }
}
.market-redesign .map-aside-head {
    font-size: 0.8rem;
    font-weight: 800;
    color: var(--m-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}
.market-redesign .map-aside-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.market-redesign .map-aside-row {
    display: grid;
    grid-template-columns: 22px minmax(0, 1fr) minmax(74px, max-content);
    grid-template-rows: auto auto;
    grid-template-areas: "rank name value" "rank bar  bar";
    align-items: center;
    gap: 4px 8px;
    padding: 4px 0;
    font-size: 0.8rem;
}
.market-redesign .map-aside-rank {
    grid-area: rank;
    display: grid;
    place-items: center;
    width: 20px;
    height: 20px;
    border-radius: 4px;
    background: rgba(47, 140, 130, 0.12);
    color: var(--m-teal);
    font-weight: 800;
    font-size: 0.74rem;
}
.market-redesign .map-aside-name {
    grid-area: name;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 700;
    color: var(--m-ink);
}
.market-redesign .map-aside-bar {
    grid-area: bar;
    display: block;
    height: 6px;
    background: rgba(47, 140, 130, 0.10);
    border-radius: 3px;
    overflow: hidden;
}
.market-redesign .map-aside-fill {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, #56b8aa, #2f8c82);
    border-radius: inherit;
}
.market-redesign .map-aside-value {
    grid-area: value;
    display: inline-flex;
    align-items: baseline;
    justify-content: flex-end;
    min-width: 74px;
    text-align: right;
    white-space: nowrap;
    color: var(--m-ink);
    font-weight: 800;
    font-size: 0.84rem;
}
.market-redesign .map-aside-value small {
    flex: 0 0 auto;
    margin-left: 2px;
    color: var(--m-muted);
    font-size: 0.66rem;
    font-weight: 600;
}
.market-redesign .map-aside-empty {
    color: var(--m-muted);
    font-size: 0.84rem;
    font-style: italic;
    padding: 8px 0;
}
.market-redesign .map-aside-loading {
    display: grid;
    gap: 8px;
    padding: 4px 0;
}
.market-redesign .map-aside-loading span {
    display: block;
    height: 10px;
    border-radius: 999px;
    background: linear-gradient(90deg, rgba(220, 228, 234, 0.8), rgba(244, 247, 246, 0.95), rgba(220, 228, 234, 0.8));
    background-size: 220% 100%;
    animation: skeleton-shimmer 1.15s ease-in-out infinite;
}
.market-redesign .map-aside-loading span:nth-child(1) { width: 90%; }
.market-redesign .map-aside-loading span:nth-child(2) { width: 74%; }
.market-redesign .map-aside-loading span:nth-child(3) { width: 82%; }
.market-redesign .map-aside-loading span:nth-child(4) { width: 66%; }
.market-redesign .map-legend-loading {
    min-width: 180px;
    height: 9px;
    border-radius: 999px;
    background: linear-gradient(90deg, rgba(220, 228, 234, 0.8), rgba(244, 247, 246, 0.95), rgba(220, 228, 234, 0.8));
    background-size: 220% 100%;
    animation: skeleton-shimmer 1.15s ease-in-out infinite;
}

/* PR4: error overlay */
.market-redesign .market-map-panel .map-error-overlay {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 12px;
    background: rgba(255, 255, 255, 0.94);
    color: var(--m-ink);
    z-index: 5;
    padding: 24px;
}
.market-redesign .market-map-panel .map-error-overlay i {
    font-size: 1.8rem;
    color: var(--m-red);
}
.market-redesign .market-map-panel .map-error-overlay p {
    margin: 0;
    text-align: center;
    color: var(--m-muted);
    font-size: 0.92rem;
}
.market-redesign .market-map-panel .map-error-overlay .map-error-retry {
    padding: 8px 18px;
    border-radius: 6px;
    border: 1px solid var(--m-line);
    background: #fff;
    cursor: pointer;
    font-weight: 700;
    color: var(--m-ink);
}
.market-redesign .market-map-panel .map-error-overlay .map-error-retry:hover {
    border-color: var(--m-teal);
    color: var(--m-teal);
}

/* PR4: a11y — visually-hidden helper（aria-live region） */
.market-redesign .visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* PR4: 稀疏資料 polygon — 增加視覺辨識（透明度 + 斜線陰影） */
.market-map-poly-sparse {
    stroke-dasharray: 3 3;
}

.market-redesign .map-legend-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 18px;
    border-top: 1px solid var(--m-line);
    background: rgba(255, 255, 255, 0.78);
    font-size: 0.78rem;
    color: var(--m-muted);
    flex-wrap: wrap;
    min-height: 38px;
}
.market-redesign .map-legend-gradient {
    display: inline-block;
    width: 120px;
    height: 8px;
    border-radius: 4px;
    background: linear-gradient(90deg, #eef2f6, #8fb7d6, #f2c66d, #d0644d);
}
.market-redesign .map-legend-range {
    margin-left: auto;
}
.market-redesign .map-legend-swatch {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
    vertical-align: middle;
    margin-right: 4px;
}

/* Leaflet polygon styling (global — Leaflet 不吃 scoped class) */
.market-map-poly {
    transition: fill-opacity 0.18s ease, stroke-width 0.18s ease;
}
.market-map-poly-tooltip {
    background: #22313f !important;
    color: #fff !important;
    padding: 6px 10px;
    border: 0 !important;
    border-radius: 6px;
    font-size: 0.82rem;
    line-height: 1.5;
    /* 用 outline + drop shadow filter 取代 box-shadow，避免 leaflet 預設 outline:white 殘留 */
    outline: 0 !important;
    outline-offset: 0 !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18) !important;
    white-space: nowrap;
}
/* 4 個方向 arrow 都蓋掉 leaflet 預設白色（否則箭頭呈白塊外框感） */
.leaflet-tooltip-top.market-map-poly-tooltip::before { border-top-color: #22313f !important; }
.leaflet-tooltip-bottom.market-map-poly-tooltip::before { border-bottom-color: #22313f !important; }
.leaflet-tooltip-left.market-map-poly-tooltip::before { border-left-color: #22313f !important; }
.leaflet-tooltip-right.market-map-poly-tooltip::before { border-right-color: #22313f !important; }
.market-map-permanent-label {
    box-sizing: border-box;
    display: inline-block;
    width: max-content;
    min-width: 0;
    max-width: 160px;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid rgba(47, 140, 130, 0.55);
    border-radius: 6px;
    padding: 5px 8px;
    font-size: 0.78rem;
    font-weight: 800;
    color: var(--m-ink);
    box-shadow: 0 4px 14px rgba(31, 45, 55, 0.22);
    white-space: normal;
    text-align: center;
    line-height: 1.35;
    pointer-events: none;
}
.market-map-permanent-label .label-name {
    display: block;
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: keep-all;
}
.market-map-permanent-label .label-value {
    display: block;
    margin-top: 1px;
    color: var(--m-teal);
    font-weight: 850;
    white-space: nowrap;
}
.market-map-permanent-label .label-subvalue {
    display: block;
    margin-top: 1px;
    color: #64727f;
    font-size: 0.68rem;
    font-weight: 750;
    white-space: nowrap;
}
.market-map-permanent-label-icon {
    background: transparent !important;
    border: 0 !important;
}
.market-map-label-leader {
    stroke: var(--m-teal);
    stroke-width: 1.5;
    stroke-dasharray: 3 3;
    opacity: 0.75;
    pointer-events: none;
}

/* Top-project marker (DivIcon) */
.market-project-marker {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #0891b2;
    border: 2px solid #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}
.market-project-marker.presale { background: #0891b2; }
.market-project-marker.completed { background: #2f8c82; }

/* Ranking tabs panel */
.market-redesign .ranking-tabs {
    display: inline-flex;
    border: 1px solid var(--m-line);
    border-radius: 6px;
    overflow: hidden;
    background: #fff;
}
.market-redesign .ranking-tab {
    min-height: 32px;
    padding: 0 14px;
    border: 0;
    border-right: 1px solid var(--m-line);
    background: transparent;
    color: var(--m-muted);
    font-family: inherit;
    font-weight: 700;
    font-size: 0.86rem;
    cursor: pointer;
    transition: background 0.18s ease;
}
.market-redesign .ranking-tab:last-child { border-right: 0; }
.market-redesign .ranking-tab.active {
    background: var(--m-teal);
    color: #fff;
}
.market-redesign .ranking-table-wrap {
    overflow-x: auto;
    padding: 14px 18px 18px;
}
.market-redesign .ranking-table {
    width: 100%;
    border-collapse: collapse;
    font-family: 'Microsoft JhengHei', 'PingFang TC', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Heiti TC', 'Noto Sans TC', 'Noto Sans', Roboto, sans-serif;
    font-size: 0.86rem;
    font-variant-numeric: tabular-nums;
}
.market-redesign .ranking-table thead th {
    text-align: left;
    padding: 8px 10px;
    border-bottom: 1px solid var(--m-line);
    color: var(--m-muted);
    font-weight: 700;
    font-size: 0.78rem;
    white-space: nowrap;
}
.market-redesign .ranking-table tbody td {
    padding: 8px 10px;
    border-bottom: 1px solid rgba(220, 228, 234, 0.6);
    color: var(--m-ink);
    font-weight: 500;
    white-space: nowrap;
}
.market-redesign .ranking-table tbody td.rank-project {
    white-space: normal;
    max-width: 240px;
    word-break: keep-all;
    overflow-wrap: anywhere;
}
.market-redesign .ranking-table tbody td.rank-project a {
    color: var(--m-ink);
    font-family: inherit;
    font-weight: 650;
    text-decoration: none;
}
.market-redesign .ranking-table tbody td.rank-project a:hover {
    color: var(--m-teal);
}
.market-redesign .ranking-table tbody tr:hover {
    background: rgba(47, 140, 130, 0.04);
}
.market-redesign .ranking-table .rank-num {
    display: inline-grid;
    place-items: center;
    width: 22px;
    height: 22px;
    border-radius: 5px;
    background: rgba(47, 140, 130, 0.10);
    color: var(--m-teal);
    font-size: 0.74rem;
    font-weight: 850;
}
.market-redesign .ranking-table tbody tr.ranking-empty td {
    text-align: center;
    color: var(--m-muted);
    padding: 24px;
    font-style: italic;
}
.market-redesign .ranking-expand-btn {
    display: none;
    width: calc(100% - 24px);
    min-height: 38px;
    margin: 0 12px 12px;
    border: 1px solid var(--m-line);
    border-radius: 6px;
    background: #fff;
    color: var(--m-ink);
    font-family: inherit;
    font-weight: 750;
}
.market-redesign .ranking-expand-btn[hidden] {
    display: none;
}

/* Zone drawer */
.zone-drawer {
    width: min(560px, 92vw);
    max-height: 80vh;
    padding: 0;
    border: 0;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.30);
    overflow: hidden;
}
.zone-drawer::backdrop {
    background: rgba(0, 0, 0, 0.4);
}
.zone-drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid #dce4ea;
    font-weight: 800;
    color: #22313f;
}
.zone-drawer-close {
    border: 0;
    background: transparent;
    font-size: 1rem;
    color: #64727f;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 6px;
}
.zone-drawer-close:hover {
    background: #eef4f2;
}
.zone-drawer-search {
    position: relative;
    padding: 10px 18px;
    border-bottom: 1px solid #dce4ea;
}
.zone-drawer-search i {
    position: absolute;
    left: 30px;
    top: 50%;
    transform: translateY(-50%);
    color: #64727f;
    font-size: 0.8rem;
    pointer-events: none;
}
.zone-drawer-search input {
    width: 100%;
    min-height: 36px;
    padding: 0 12px 0 32px;
    border: 1px solid #dce4ea;
    border-radius: 6px;
    font-size: 0.92rem;
}
.zone-drawer-body {
    max-height: calc(80vh - 200px);
    overflow-y: auto;
    padding: 8px 18px;
}
.zone-drawer-district-group {
    margin-bottom: 4px;
}
.zone-drawer-district-group summary {
    list-style: none;
    cursor: pointer;
    padding: 8px 0;
    font-weight: 700;
    font-size: 0.92rem;
    color: #22313f;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.zone-drawer-district-group summary::-webkit-details-marker { display: none; }
.zone-drawer-district-group summary::after {
    content: "\f078";
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    font-size: 0.74rem;
    color: #64727f;
    transition: transform 0.18s ease;
}
.zone-drawer-district-group[open] summary::after {
    transform: rotate(180deg);
}
.zone-drawer-district-group .zone-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 2px;
    padding: 4px 0 8px;
}
.zone-drawer-district-group .zone-list label {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    font-size: 0.84rem;
    color: #22313f;
    cursor: pointer;
    border-radius: 4px;
}
.zone-drawer-district-group .zone-list label:hover {
    background: #eef4f2;
}
.zone-drawer-district-group .zone-list input[type="radio"] {
    width: 14px;
    height: 14px;
    cursor: pointer;
}
.zone-drawer-foot {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 18px;
    border-top: 1px solid #dce4ea;
    background: #f4f7f6;
}
.zone-drawer-count {
    flex: 1;
    font-size: 0.84rem;
    color: #64727f;
}
.zone-drawer-foot button {
    min-height: 36px;
    padding: 0 16px;
    border-radius: 6px;
    font-weight: 700;
    cursor: pointer;
    border: 1px solid transparent;
}
.zone-drawer-foot .btn-primary {
    background: #2f8c82;
    color: #fff;
    border-color: #2f8c82;
}
.zone-drawer-foot .btn-secondary {
    background: #fff;
    color: #22313f;
    border-color: #dce4ea;
}

/* === 隱藏舊 v1 樣式：時間範圍/快速選擇 section（新版用 .field-group 和 .quick-group 取代） === */
.market-redesign .time-range-section,
.market-redesign .quick-select-section {
    display: none;
}

/* 篩選資訊：左面板內 inline 顯示（無 toggle，直接 chips）
   注意：style.css 有 .filter-info 預設 max-height:0 + opacity:0（為舊 toggle 模式），這裡蓋掉 */
.market-redesign .control-panel #filter-info {
    background: transparent;
    border: 0;
    padding: 0;
    margin-top: 8px;
    color: var(--m-ink);
    font-size: 0.78rem;
    line-height: 1.55;
    max-height: none;
    opacity: 1;
    overflow: visible;
}
.market-redesign .control-panel #filter-info[hidden] { display: none; }

/* === Market intro：搬到 workspace 下方的 SEO 摘要卡（不在右欄上方）=== */
.market-redesign + .market-intro,
body.market-tab .market-intro {
    margin: 24px auto 0;
    max-width: 1440px;
    padding: 22px 24px;
    border: 1px solid var(--m-line);
    border-radius: var(--m-radius);
    background: rgba(255, 255, 255, 0.92);
    box-shadow: var(--m-shadow);
    color: var(--m-ink);
    font-size: 0.92rem;
    line-height: 1.75;
}
body.market-tab .market-intro .market-intro-title {
    margin: 0 0 10px;
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--m-ink);
    letter-spacing: 0.01em;
}
body.market-tab .market-intro p {
    margin: 0 0 14px;
    color: var(--m-muted);
}
body.market-tab .market-intro p strong a,
body.market-tab .market-intro p a {
    color: var(--m-teal);
    font-weight: 700;
    text-decoration: none;
}
body.market-tab .market-intro p a:hover {
    text-decoration: underline;
}
/* details 收合條 */
body.market-tab .market-intro .raw-data-glossary {
    border: 1px solid var(--m-line);
    background: transparent;
    border-radius: 6px;
    overflow: hidden;
}
body.market-tab .market-intro .raw-data-glossary summary {
    padding: 8px 12px;
    background: var(--m-soft);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--m-ink);
}
body.market-tab .market-intro .raw-data-glossary[open] summary {
    border-bottom: 1px solid var(--m-line);
}
body.market-tab .market-intro .raw-data-glossary ol {
    padding: 12px 16px 12px 36px;
    background: #fff;
    font-size: 0.85rem;
    line-height: 1.65;
}
body.market-tab .market-intro .raw-data-glossary li {
    color: var(--m-muted);
}
body.market-tab .market-intro .raw-data-glossary li a {
    color: var(--m-ink);
    font-weight: 600;
    text-decoration: none;
}
body.market-tab .market-intro .raw-data-glossary li a:hover {
    color: var(--m-teal);
}

/* chip 風格：時間/行政區/重劃區 */
.market-redesign #filter-info .finfo-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.market-redesign #filter-info .finfo-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border: 1px solid var(--m-line);
    border-radius: 999px;
    background: #fff;
    color: var(--m-ink);
    font-size: 0.76rem;
    font-weight: 600;
    line-height: 1.4;
}
.market-redesign #filter-info .finfo-chip i {
    color: var(--m-muted);
    font-size: 0.7rem;
}
.market-redesign #filter-info .finfo-chip-muted {
    background: transparent;
    color: var(--m-muted);
    font-weight: 500;
}

/* 統計口徑說明收進 details，預設收合 */
.market-redesign #filter-info .finfo-details {
    margin-top: 8px;
    color: #536371;
    font-family: 'Noto Sans TC', 'Microsoft JhengHei', 'PingFang TC', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 0.76rem;
    line-height: 1.65;
}
.market-redesign #filter-info .finfo-details summary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    color: var(--m-ink);
    font-size: 0.78rem;
    font-weight: 800;
    user-select: none;
}
.market-redesign #filter-info .finfo-details[open] summary {
    margin-bottom: 6px;
}
.market-redesign #filter-info .finfo-details > div {
    padding-left: 12px;
    line-height: 1.65;
}
.market-redesign #filter-info .finfo-details > div + div {
    margin-top: 2px;
}

/* === 響應式：mobile 折疊 === */
@media (max-width: 1180px) {
    #market-tab .market-redesign .workspace {
        grid-template-columns: minmax(0, 1fr);
    }
    #market-tab .market-redesign .control-panel,
    #market-tab .market-redesign .content {
        min-width: 0;
    }
    #market-tab .market-redesign .control-panel > *,
    #market-tab .market-redesign .content > * {
        min-width: 0;
        max-width: 100%;
    }
    body.market-tab #main-content,
    #market-tab,
    #market-tab .market-redesign {
        overflow-x: hidden;
    }
    .market-redesign .summary-band {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .market-redesign .market-signal-strip {
        grid-template-columns: 1fr;
    }
    .market-redesign .market-signal-card {
        border-right: 0;
        border-bottom: 1px solid var(--m-line);
    }
    .market-redesign .market-signal-card:last-child {
        border-bottom: 0;
    }
    .market-redesign .summary-band .metric-card {
        border-right: 1px solid rgba(220, 228, 234, 0.85);
        border-bottom: 1px solid rgba(220, 228, 234, 0.85);
    }
    .market-redesign .summary-band .metric-card:nth-child(2n) {
        border-right: 0;
    }
    .market-redesign .summary-band .metric-card:nth-last-child(-n + 2) {
        border-bottom: 0;
    }
    .market-redesign .panel-tools .seg-btn {
        padding: 0 8px;
        font-size: 0.78rem;
    }
}
@media (max-width: 768px) {
    .market-redesign .summary-band {
        gap: 0;
    }
    .market-redesign .summary-band .metric-card {
        min-height: 78px;
        padding: 11px 12px;
        gap: 6px;
        grid-template-rows: 17px 30px;
    }
    .market-redesign .summary-band .metric-value {
        font-size: 1.45rem;
        line-height: 30px;
        min-height: 30px;
    }
    .market-redesign .panel-head {
        padding: 12px;
        min-height: 0;
        flex-wrap: wrap;
    }
    .market-redesign .panel-tools {
        flex-wrap: wrap;
        gap: 6px;
    }
    .market-redesign .ranking-table-wrap {
        padding: 10px 12px 12px;
    }
    .market-redesign .ranking-table {
        min-width: 560px;
    }
    .market-redesign .ranking-tables-panel:not(.show-all) .ranking-table tbody tr.ranking-extra {
        display: none;
    }
    .market-redesign .ranking-expand-btn {
        display: block;
    }
}
