/* 地圖找屋
   搭配 assets/js/map_search.js；桌機與手機同一頁，差別用 media query 處理 */

/* Leaflet 內部 z-index 很大（圖磚 400、控制項 1000、popup 700）。容器給 z-index:0
   建立堆疊脈絡，那些數字才只在地圖內部有效，不會壓到站台的導覽列。 */
.map-search .leaflet-container {
    z-index: 0;
}

.map-search {
    margin: 10px 0 20px;
}

/* ---- 篩選列 ---- */
.ms-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 10px 12px;
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-bottom: 0;
}

.ms-select {
    height: 32px;
    padding: 0 6px;
    font-size: 13px;
    color: #333;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 3px;
}

.ms-select:disabled {
    color: #aaa;
    background: #f0f0f0;
}

.ms-reset {
    height: 32px;
    padding: 0 12px;
    font-size: 13px;
    color: #555;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 3px;
    cursor: pointer;
}

.ms-reset:hover {
    border-color: #999;
}


/* ---- 降級橫幅 ---- */
.ms-notice {
    padding: 8px 12px;
    font-size: 13px;
    color: #7a4b00;
    background: #fff6e0;
    border: 1px solid #f0d9a0;
    border-bottom: 0;
}

.ms-notice a {
    margin-left: 6px;
    color: #1c4e80;
    text-decoration: underline;
}

/* ---- 地圖 + 側欄 ---- */
.ms-body {
    display: flex;
    align-items: stretch;
    border: 1px solid #ddd;
}

.ms-canvas-wrap {
    position: relative;
    /* 建立堆疊脈絡：裡面 .ms-overlay 的 z-index:500 才不會逃出來
       蓋到站台導覽列（mo 版 .nav 只有 z-index:4），同 .leaflet-container 的做法 */
    z-index: 0;
    flex: 1 1 auto;
    min-width: 0;
}

#ms-canvas {
    width: 100%;
    height: 620px;
}

/* 疊在地圖上方的提示條（超量、空狀態） */
/* 地圖上的浮層：導引按鈕在上、提示文字在下，由下緣往上堆疊。
   容器本身 pointer-events:none，空白處不會吃掉地圖拖曳。 */
.ms-overlay {
    position: absolute;
    left: 50%;
    bottom: 14px;
    transform: translateX(-50%);
    z-index: 500;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    max-width: 92%;
    pointer-events: none;
}

.ms-hint {
    max-width: 100%;
    padding: 6px 12px;
    font-size: 13px;
    line-height: 1.5;
    color: #fff;
    background: rgba(0, 0, 0, .72);
    border-radius: 16px;
    text-align: center;
}

/* 導引按鈕：「回到○○」（視野離開所選縣市）與「最近的物件在○○」（視野內 0 筆）共用 */
.ms-action {
    max-width: 100%;
    padding: 7px 16px;
    overflow: hidden;
    font-size: 13px;
    color: #1c4e80;
    text-overflow: ellipsis;
    white-space: nowrap;
    background: #fff;
    border: 1px solid #1c4e80;
    border-radius: 18px;
    box-shadow: 0 1px 5px rgba(0, 0, 0, .25);
    cursor: pointer;
    pointer-events: auto;
}

.ms-action:hover {
    background: #f0f6fc;
}

.ms-panel {
    flex: 0 0 300px;
    max-height: 620px;
    overflow-y: auto;
    background: #fff;
    border-left: 1px solid #ddd;
}

.ms-panel-head {
    position: sticky;
    top: 0;
    margin: 0;
    padding: 8px 12px;
    font-size: 13px;
    line-height: 1.5;
    color: #555;
    background: #f5f5f5;
    border-bottom: 1px solid #e2e2e2;
}

.ms-panel-head strong {
    font-size: 15px;
    color: #c1272d;
}

.ms-panel-items {
    margin: 0;
    padding: 0;
    list-style: none;
}

.ms-panel-items > li {
    border-bottom: 1px solid #eee;
}

/* ---- 物件卡片（側欄與 popup 共用） ---- */
.ms-card {
    display: flex;
    gap: 8px;
    padding: 8px 10px;
    color: #333;
    text-decoration: none;
}

.ms-card:hover {
    background: #fdf3f3;
}

.ms-card-img {
    flex: 0 0 80px;
    width: 80px;
    height: 60px;
    object-fit: cover;
    border-radius: 3px;
    background: #eee;
}

.ms-card-body {
    flex: 1 1 auto;
    min-width: 0;
}

.ms-card-name {
    display: block;
    font-size: 13px;
    line-height: 1.4;
    max-height: 2.8em;
    overflow: hidden;
}

.ms-card-price {
    display: block;
    margin-top: 2px;
    font-size: 15px;
    font-weight: bold;
    color: #c1272d;
}

.ms-card-meta,
.ms-card-addr {
    display: block;
    font-size: 12px;
    line-height: 1.5;
    color: #777;
}

/* ---- 聚合氣泡（縣市／行政區） ---- */
.map-search .leaflet-div-icon {
    background: transparent;
    border: 0;
}

.ms-bubble {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    border-radius: 50%;
    color: #fff;
    background: rgba(28, 78, 128, .88);
    border: 2px solid #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .3);
    transform: translate(-50%, -50%);
    cursor: pointer;
    white-space: nowrap;
}

.ms-bubble em {
    font-style: normal;
    line-height: 1.1;
}

.ms-bubble b {
    line-height: 1.1;
}

.ms-bubble-sm { width: 48px; height: 48px; font-size: 11px; }
.ms-bubble-md { width: 58px; height: 58px; font-size: 12px; }
.ms-bubble-lg { width: 68px; height: 68px; font-size: 13px; }

.ms-bubble:hover {
    background: rgba(193, 39, 45, .9);
}

/* ---- 個別物件價格標籤 ---- */
.ms-pin {
    display: inline-block;
    padding: 3px 7px;
    font-size: 12px;
    line-height: 1.3;
    white-space: nowrap;
    color: #fff;
    background: #c1272d;
    border: 1px solid #fff;
    border-radius: 3px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
    transform: translate(-50%, -100%);
}

.ms-pin-multi {
    background: #1c4e80;
}

.leaflet-marker-icon.is-hover .ms-pin,
.ms-pin:hover {
    background: #222;
    z-index: 500;
}

/* ---- popup ---- */
.ms-popup {
    max-height: 260px;
    overflow-y: auto;
}

.ms-popup-head {
    margin: 0 0 4px;
    padding: 4px 6px;
    font-size: 13px;
    font-weight: bold;
    color: #1c4e80;
    background: #eef3f8;
}

.ms-popup .ms-card {
    padding: 6px 4px;
    border-bottom: 1px solid #eee;
}

.ms-popup .ms-card:last-child {
    border-bottom: 0;
}

/* ---- 手機：側欄改成地圖下方的清單 ---- */
@media screen and (max-width: 768px) {
    /* 站台的桌機版型 #wrapper／#content 是固定 960px，窄畫面會整頁橫向溢出。
       這支 CSS 只有地圖找屋這一頁會載入，所以可以直接覆寫，不影響其他頁面。
       （頁首與頁尾本身已經是流動寬度，不用動。） */
    #wrapper,
    #content {
        width: auto;
        max-width: 100%;
        margin-right: 0;
    }

    .ms-body {
        display: block;
    }

    #ms-canvas {
        height: 58vh;
        min-height: 320px;
    }

    .ms-panel {
        max-height: 40vh;
        border-left: 0;
        border-top: 1px solid #ddd;
    }

    .ms-tolist {
        margin-left: 0;
    }

    .ms-select {
        flex: 1 1 44%;
    }
}
