/* =====================================================================
   map.css – giao diện bản đồ (dùng chung các trang có Leaflet)
   ===================================================================== */

/* ---------- Trang bản đồ toàn màn hình ---------- */
body.page-map { overflow: hidden; padding-bottom: 0; overscroll-behavior: none; }
.map-app { position: relative; height: calc(100vh - var(--header-h) - var(--bottom-nav-h) - var(--safe-b)); height: calc(100dvh - var(--header-h) - var(--bottom-nav-h) - var(--safe-b)); overflow: hidden; }
@media (min-width: 992px) { .map-app { height: calc(100vh - var(--header-h)); height: calc(100dvh - var(--header-h)); } }
.map-canvas { position: absolute; inset: 0; background: #f2efe9; }

/* Thanh tìm kiếm nổi */
.map-search { position: absolute; z-index: 1002; top: 10px; left: 10px; right: 10px; }
.ms-box { display: flex; align-items: center; background: #fff; border-radius: 12px; box-shadow: var(--shadow-lg); padding: 3px; gap: 2px; }
.ms-input { flex: 1; min-width: 0; border: 0; outline: 0; height: 44px; padding: 0 .5rem; font-size: .95rem; background: transparent; }
.ms-btn { width: 44px; height: 44px; border: 0; background: transparent; border-radius: 10px; display: grid; place-items: center; color: var(--c-ink); flex-shrink: 0; }
.ms-btn:hover { background: var(--c-bg); }
.ms-go { background: var(--c-primary); color: #fff; }
.ms-go:hover { background: var(--c-primary-600); }
.ms-results { margin-top: 6px; background: #fff; border-radius: 12px; box-shadow: var(--shadow-lg); max-height: min(60vh, 420px); overflow-y: auto; }
.ms-results a { display: flex; gap: .55rem; align-items: flex-start; padding: .7rem .9rem; color: var(--c-ink); border-bottom: 1px solid var(--c-border); font-size: .9rem; }
.ms-results a:hover { background: var(--c-primary-50); }
.ms-results a .ic { margin-top: 2px; color: var(--c-primary); }
.ms-results a span { flex: 1; min-width: 0; }
.ms-results a small { color: var(--c-muted); font-size: .7rem; white-space: nowrap; }
.ms-empty { padding: .9rem 1rem; color: var(--c-muted); font-size: .9rem; }
@media (min-width: 992px) {
    .map-search { left: 364px; right: auto; width: min(460px, calc(100% - 460px)); top: 12px; }
    body.panel-collapsed .map-search { left: 140px; }
}

/* Nút công cụ nổi */
.map-fab { position: absolute; z-index: 1001; right: 10px; top: 66px; display: flex; flex-direction: column; gap: 8px; }
.fab { width: 46px; height: 46px; border-radius: 12px; border: 0; background: #fff; box-shadow: var(--shadow-lg); display: grid; place-items: center; color: var(--c-ink); padding: 0; }
.fab .ic { width: 21px; height: 21px; }
.fab span { display: none; }
.fab:hover { color: var(--c-primary); }
.fab.on { background: var(--c-primary); color: #fff; }
@media (min-width: 992px) {
    .map-fab { top: 12px; right: 12px; }
    .fab { width: 62px; height: 56px; grid-template-rows: auto auto; gap: 1px; align-content: center; }
    .fab span { display: block; font-size: .64rem; font-weight: 600; line-height: 1; }
}

/* Thanh đo */
.measure-bar { position: absolute; z-index: 1003; left: 10px; right: 66px; top: 66px; background: #1d2a2f; color: #fff; border-radius: 12px; padding: .5rem .6rem .5rem .9rem; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; box-shadow: var(--shadow-lg); }
.measure-bar[hidden] { display: none; }
.measure-bar .mb-text { flex: 1 1 160px; font-size: .88rem; }
.measure-bar .mb-text b { color: #ffd38f; font-size: .98rem; }
.measure-bar .mb-acts { display: flex; gap: .35rem; }
.measure-bar .btn { min-height: 36px; }
@media (min-width: 992px) { .measure-bar { left: 50%; right: auto; transform: translateX(-50%); top: auto; bottom: 28px; min-width: 420px; } body:not(.panel-collapsed) .measure-bar { left: calc(50% + 176px); } }
.measure-tip { background: rgba(29, 42, 47, .9); color: #fff; border: 0; border-radius: 6px; font-weight: 600; font-size: .78rem; padding: 4px 8px; box-shadow: none; text-align: center; }
.measure-tip::before { display: none; }

/* ---------- Panel / Bottom sheet ---------- */
.map-panel { background: #fff; display: flex; flex-direction: column; }
.sheet-handle { position: relative; display: flex; align-items: center; gap: .5rem; padding: 14px 14px 10px; border-bottom: 1px solid var(--c-border); cursor: grab; touch-action: none; user-select: none; flex-shrink: 0; }
.sheet-handle .grip { position: absolute; top: 5px; left: 50%; transform: translateX(-50%); width: 42px; height: 5px; border-radius: 3px; background: #cfd8d4; }
.sh-title { flex: 1; min-width: 0; display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; }
.sh-title b { font-size: .98rem; }
.sh-title small { color: var(--c-muted); font-size: .78rem; width: 100%; padding-left: 1.6rem; margin-top: -2px; }
#infoTitle small { padding-left: 0; }
.sh-close, .sh-collapse { width: 40px; height: 40px; border: 0; background: var(--c-bg); border-radius: 10px; display: grid; place-items: center; flex-shrink: 0; }
.sheet-body { padding: 12px 14px 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }

/* mobile: bottom sheet */
@media (max-width: 991.98px) {
    .sheet {
        position: fixed; left: 0; right: 0; top: 0; height: 100vh; height: 100dvh; z-index: 1030;
        border-radius: 16px 16px 0 0; box-shadow: 0 -6px 24px rgba(0, 0, 0, .14);
        transition: transform .25s cubic-bezier(.2, .8, .2, 1); will-change: transform;
    }
    .sheet.dragging { transition: none; }
    #panelLayers { --peek: 192px; }
    #panelInfo { --peek: 260px; z-index: 1032; }
    .sheet[data-state="full"] { transform: translateY(12vh); }
    .sheet[data-state="half"] { transform: translateY(50vh); }
    .sheet[data-state="peek"] { transform: translateY(calc(100vh - var(--peek))); }
    .sheet[data-state="hidden"] { transform: translateY(105vh); }
    .sheet[data-state="full"] .sheet-body { max-height: calc(88vh - 64px - var(--bottom-nav-h) - var(--safe-b)); }
    .sheet[data-state="half"] .sheet-body { max-height: calc(50vh - 64px - var(--bottom-nav-h) - var(--safe-b)); }
    .sheet[data-state="peek"] .sheet-body { max-height: calc(var(--peek) - 64px - var(--bottom-nav-h)); overflow: hidden; }
    .page-map .leaflet-bottom { bottom: 136px; }
    body.info-open .map-fab { display: none; }
}
/* desktop: panel nổi */
@media (min-width: 992px) {
    #panelLayers { position: absolute; z-index: 1001; left: 12px; top: 12px; bottom: 12px; width: 340px; border-radius: 14px; box-shadow: var(--shadow-lg); overflow: hidden; }
    #panelLayers .sheet-handle { cursor: default; }
    #panelLayers .grip { display: none; }
    #panelLayers .sheet-body { flex: 1; }
    body.panel-collapsed #panelLayers { display: none; }
    #panelInfo { position: absolute; z-index: 1002; right: 86px; top: 12px; width: 370px; max-height: calc(100% - 24px); border-radius: 14px; box-shadow: var(--shadow-lg); overflow: hidden; }
    #panelInfo[data-state="hidden"] { display: none; }
    #panelInfo .grip { display: none; }
    .panel-open { position: absolute; z-index: 1001; left: 12px; top: 12px; border: 0; background: #fff; border-radius: 12px; box-shadow: var(--shadow-lg); height: 50px; padding: 0 1rem; font-weight: 600; display: flex; align-items: center; gap: .4rem; }
    .panel-open.d-none { display: none !important; }
    .page-map .leaflet-left .leaflet-control-scale { margin-left: 364px; }
    body.panel-collapsed .leaflet-left .leaflet-control-scale { margin-left: 12px; }
}

/* Danh sách lớp */
.layer-item { border: 1px solid var(--c-border); border-radius: 10px; padding: .55rem .6rem; margin-bottom: .5rem; position: relative; background: #fff; }
.layer-item.on { border-color: var(--c-primary); background: #f6fbf9; }
.layer-item .li-head { display: flex; gap: .55rem; align-items: flex-start; cursor: pointer; padding-right: 40px; margin: 0; }
.layer-item .li-head .form-check-input { width: 1.25em; height: 1.25em; margin-top: .1rem; flex-shrink: 0; }
.layer-item .li-name { min-width: 0; }
.layer-item .li-name b { display: block; font-size: .88rem; line-height: 1.3; }
.layer-item .li-name small { color: var(--c-muted); font-size: .74rem; }
.layer-item .li-zoom { position: absolute; top: .35rem; right: .35rem; width: 36px; height: 36px; border: 0; border-radius: 8px; background: transparent; color: var(--c-muted); display: grid; place-items: center; }
.layer-item .li-zoom:hover { background: var(--c-bg); color: var(--c-primary); }
.layer-item .li-opacity { display: flex; align-items: center; gap: .5rem; margin-top: .45rem; font-size: .78rem; color: var(--c-muted); }
.layer-item .li-opacity input { flex: 1; }
.layer-item .li-opacity output { width: 38px; text-align: right; font-weight: 600; color: var(--c-ink); }
.layer-item .li-meta { font-size: .72rem; color: var(--c-muted); margin-top: .25rem; padding-left: 1.8rem; }
.layer-item .li-out { display: none; color: #a8650c; padding-left: 1.8rem; margin-top: .2rem; font-size: .72rem; }
.layer-item.out-of-view .li-out { display: block; }
.form-range::-webkit-slider-thumb { background: var(--c-primary); }
.form-range::-moz-range-thumb { background: var(--c-primary); }

/* Chú giải */
.legend summary { font-weight: 600; font-size: .9rem; cursor: pointer; padding: .3rem 0; list-style: none; display: flex; align-items: center; gap: .4rem; }
.legend summary::-webkit-details-marker { display: none; }
.legend summary::after { content: "▾"; margin-left: auto; color: var(--c-muted); }
.legend:not([open]) summary::after { content: "▸"; }
.legend-body { max-height: 260px; overflow-y: auto; padding-right: 4px; }
.lg-title { font-size: .72rem; font-weight: 700; text-transform: uppercase; color: var(--c-muted); margin: .5rem 0 .25rem; letter-spacing: .03em; }
.lg-item { display: flex; align-items: center; gap: .45rem; font-size: .8rem; padding: .15rem 0; }
.lg-item i { width: 22px; height: 14px; border-radius: 3px; border: 1px solid rgba(0, 0, 0, .2); flex-shrink: 0; }
.lg-item b { width: 32px; flex-shrink: 0; font-size: .74rem; }
.lg-item span { color: var(--c-ink); }

/* Thông tin thửa */
.info-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; margin-bottom: .75rem; }
.info-actions .btn { font-size: .84rem; min-height: 42px; padding: .3rem .5rem; }
.info-table { width: 100%; font-size: .9rem; }
.info-table th { color: var(--c-muted); font-weight: 500; width: 34%; padding: .4rem 0; vertical-align: top; border-bottom: 1px dashed var(--c-border); }
.info-table td { font-weight: 600; padding: .4rem 0; border-bottom: 1px dashed var(--c-border); overflow-wrap: anywhere; }
.info-sub { font-weight: 700; font-size: .85rem; margin: .8rem 0 .35rem; color: var(--c-primary-600); }
.price-ref { background: var(--c-bg); border-radius: 8px; padding: .5rem .65rem; margin-bottom: .4rem; font-size: .86rem; }
.lt-dot { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; border: 1px solid rgba(0, 0, 0, .25); }
.coord-box { margin-top: .75rem; background: var(--c-bg); border-radius: 8px; padding: .5rem .7rem; font-size: .84rem; }
.coord-box > div { display: flex; flex-wrap: wrap; align-items: center; gap: .1rem .5rem; padding: .15rem 0; }
.coord-box small { color: var(--c-muted); width: 100%; font-size: .72rem; }
.btn-link-x { border: 0; background: transparent; color: var(--c-primary); padding: 0 .2rem; }

/* ---------- Popup tin đăng ---------- */
.listing-popup .leaflet-popup-content { margin: 0; width: 260px !important; }
.listing-popup .leaflet-popup-content-wrapper { padding: 0; overflow: hidden; border-radius: 12px; }
.lp { display: block; color: var(--c-ink); }
.lp:hover { color: var(--c-ink); }
.lp img { width: 100%; height: 140px; object-fit: cover; display: block; background: #ddd; }
.lp-b { padding: .55rem .7rem .7rem; font-size: .84rem; }
.lp-t { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.3; margin-bottom: .2rem; }
.lp-price { color: var(--c-danger); font-weight: 800; }
.lp-addr { color: var(--c-muted); font-size: .76rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.pin-icon { background: transparent; border: 0; }
.leaflet-control-locate a { width: 34px; height: 34px; }
.page-map .leaflet-control-locate { display: none; }   /* dùng nút #fabLocate */
.leaflet-touch .leaflet-bar a { width: 40px; height: 40px; line-height: 40px; }
.map-loading { position: absolute; z-index: 1001; top: 10px; left: 50%; transform: translateX(-50%); background: #fff; padding: .3rem .8rem; border-radius: 999px; font-size: .8rem; box-shadow: var(--shadow); }

/* Mini-map công cụ chọn lớp (trang chi tiết tin, tra cứu thửa) */
.mini-layer-ctl { position: absolute; z-index: 1000; top: 10px; left: 10px; right: 10px; display: flex; gap: .4rem; flex-wrap: wrap; pointer-events: none; }
.mini-layer-ctl > * { pointer-events: auto; }
.mini-layer-ctl .btn { background: #fff; box-shadow: var(--shadow); min-height: 38px; font-size: .82rem; }
.mini-layer-ctl .btn.on { background: var(--c-primary); color: #fff; }
.mini-layer-ctl .form-range { width: 110px; }
.mini-layer-ctl .opacity-box { background: #fff; border-radius: 8px; padding: 0 .6rem; display: flex; align-items: center; gap: .4rem; font-size: .78rem; box-shadow: var(--shadow); min-height: 38px; }

/* ---------- Quy hoạch tại điểm (nhận dạng theo màu) ---------- */
.plan-pick { border: 1px solid var(--c-border); border-radius: 10px; padding: .55rem .7rem; margin-bottom: .75rem; background: #fff; }
.plan-pick .pp-head { font-weight: 700; font-size: .84rem; display: flex; align-items: center; gap: .35rem; margin-bottom: .4rem; color: var(--c-ink); }
.plan-pick .pp-head .ic { color: var(--c-primary); }
.pp-row { display: flex; gap: .6rem; align-items: flex-start; padding: .4rem 0; border-top: 1px dashed var(--c-border); }
.pp-row:first-of-type { border-top: 0; }
.pp-row > div { min-width: 0; flex: 1; font-size: .88rem; line-height: 1.35; }
.pp-row b { font-weight: 600; }
.pp-sw { flex-shrink: 0; width: 30px; height: 30px; border-radius: 7px; border: 1px solid rgba(0, 0, 0, .18); margin-top: 1px; }
.pp-sw-empty { background: repeating-linear-gradient(45deg, #f1f4f3, #f1f4f3 4px, #fff 4px, #fff 8px); }
.pp-code { display: inline-block; font-size: .72rem; font-weight: 700; letter-spacing: .02em; background: var(--c-ink); color: #fff; border-radius: 5px; padding: 1px 6px; margin: 0 .3rem .15rem 0; vertical-align: 1px; }
.pp-layer, .pp-note { display: block; font-size: .74rem; color: var(--c-muted); margin-top: 2px; }
.pp-note { color: #8a5a00; }
.pp-muted b { color: #4b5a60; }
.pp-none { font-size: .84rem; color: var(--c-muted); }
.pp-foot { font-size: .7rem; color: var(--c-muted); margin-top: .35rem; }

/* ---------- So sánh 2 lớp (swipe) ---------- */
.swipe-divider { position: absolute; top: 0; bottom: 0; left: 50%; width: 0; z-index: 650; pointer-events: none; }
.swipe-divider[hidden] { display: none; }
.swipe-divider::before { content: ""; position: absolute; top: 0; bottom: 0; left: -2px; width: 4px; background: #fff; box-shadow: 0 0 0 1px rgba(29, 42, 47, .35), 0 0 12px rgba(0, 0, 0, .25); }
.swipe-divider .sw-handle { pointer-events: auto; position: absolute; top: 50%; left: 0; transform: translate(-50%, -50%); width: 44px; height: 44px; border-radius: 50%; border: 3px solid #fff; background: var(--c-primary); color: #fff; display: grid; place-items: center; box-shadow: var(--shadow-lg); cursor: ew-resize; touch-action: none; padding: 0; }
.swipe-divider .sw-handle .ic { width: 22px; height: 22px; }
.swipe-divider .sw-handle:focus-visible { outline: 3px solid #ffd38f; }
.swipe-divider .sw-label { position: absolute; bottom: 34px; white-space: nowrap; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; background: rgba(29, 42, 47, .86); color: #fff; font-size: .74rem; font-weight: 600; padding: 3px 8px; border-radius: 6px; }
.swipe-divider .sw-l { right: 10px; }
.swipe-divider .sw-r { left: 10px; }

.compare-bar { position: absolute; z-index: 1003; left: 10px; right: 66px; top: 66px; background: #fff; border-radius: 12px; padding: .5rem .6rem .55rem .8rem; box-shadow: var(--shadow-lg); display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .6rem; }
.compare-bar[hidden] { display: none; }
.compare-bar .cb-title { display: flex; align-items: center; gap: .35rem; font-size: .88rem; flex: 1 1 auto; }
.compare-bar .cb-title .ic { color: var(--c-primary); }
.compare-bar .cb-title small { color: var(--c-muted); font-size: .74rem; }
.compare-bar .cb-sel { display: flex; align-items: flex-end; gap: .4rem; width: 100%; order: 3; }
.compare-bar .cb-sel label { flex: 1; min-width: 0; }
.compare-bar .cb-sel label span { display: block; font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--c-muted); margin-bottom: 2px; }
.compare-bar .form-select { min-height: 36px; font-size: .82rem; }
.compare-bar .btn { min-height: 36px; }
.compare-bar .cb-swap { width: 36px; padding: 0; font-size: 1rem; flex-shrink: 0; }
.compare-bar .cb-close { width: 36px; padding: 0; order: 2; }
body.comparing .measure-bar { display: none; }
@media (min-width: 992px) {
    .compare-bar { left: auto; right: 86px; top: 12px; width: 420px; }
    body.info-open .compare-bar { right: 470px; }
    .swipe-divider .sw-label { max-width: 26vw; }
}
@media (max-width: 991.98px) { .swipe-divider .sw-label { bottom: auto; top: 186px; max-width: 44vw; } }

/* ---------- Kết quả tìm địa chỉ ---------- */
.ms-results a span b { font-weight: 600; }
.ms-results a span i { display: block; font-style: normal; font-size: .78rem; color: var(--c-muted); margin-top: 1px; }
.ms-results a.active { background: var(--c-primary-50); }
.ms-results a.ms-more { color: var(--c-primary); font-weight: 500; }
.ms-results a.ms-more small { border: 1px solid var(--c-border); border-radius: 4px; padding: 0 5px; }
.ms-approx { font-style: normal; font-size: .68rem; font-weight: 700; color: #8a5a00; background: #fff4e0; border-radius: 4px; padding: 0 5px; vertical-align: 1px; }
.ms-warn { padding: .7rem .9rem; color: #a33; background: #fff6f6; font-size: .85rem; display: flex; gap: .4rem; align-items: center; }
.ms-hint { padding: .45rem .9rem; color: var(--c-muted); font-size: .76rem; background: #fafcfb; }

/* ---------- Chọn nhanh lớp quy hoạch (chip) ---------- */
.layer-chips { position: absolute; z-index: 1000; left: 10px; right: 66px; top: 62px; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 2px; -webkit-overflow-scrolling: touch; }
.layer-chips::-webkit-scrollbar { display: none; }
.layer-chips[hidden], body.comparing .layer-chips { display: none; }
.lc-chip { flex-shrink: 0; border: 1px solid rgba(29, 42, 47, .12); background: #fff; color: var(--c-ink); border-radius: 999px; padding: 0 .8rem; height: 34px; font-size: .8rem; font-weight: 600; white-space: nowrap; box-shadow: var(--shadow); }
.lc-chip:hover { border-color: var(--c-primary); color: var(--c-primary); }
.lc-chip.on { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }
.lc-chip.out:not(.on) { color: var(--c-muted); }
.lc-chip:focus-visible { outline: 3px solid #ffd38f; outline-offset: 1px; }
@media (min-width: 992px) {
    .layer-chips { top: auto; bottom: 34px; left: 364px; right: 86px; }
    .lc-chip:first-child { margin-left: auto; }
    .lc-chip:last-child { margin-right: auto; }
    body.panel-collapsed .layer-chips { left: 12px; }
    body.info-open .layer-chips { right: 470px; }
    .measure-bar { bottom: 82px; }
}

/* ---------- Quy hoạch theo cấp tại điểm ---------- */
.pp-sec { padding: .45rem 0 .2rem; border-top: 1px solid var(--c-border); }
.pp-head + .pp-sec { border-top: 0; padding-top: 0; }
.pp-title { display: flex; align-items: center; gap: .5rem; }
.pp-title span { flex: 1; min-width: 0; font-weight: 700; font-size: .84rem; color: var(--c-primary-600); line-height: 1.3; }
.pp-show { flex-shrink: 0; border: 1px solid var(--c-border); background: #fff; color: var(--c-primary); border-radius: 6px; font-size: .7rem; font-weight: 600; padding: 2px 8px; min-height: 26px; }
.pp-show:hover { border-color: var(--c-primary); }
.pp-show.on { background: var(--c-primary-50); border-color: transparent; color: var(--c-primary-600); cursor: default; }
.pp-sec .pp-row { border-top: 0; padding: .35rem 0 .25rem; }
.pp-area { flex-shrink: 0; font-size: .8rem; font-weight: 600; color: var(--c-ink); min-width: 64px; padding-top: 6px; }
.pp-desc { display: block; font-size: .76rem; color: #4b5a60; margin-top: 2px; }

/* ---------- Đơn vị hành chính mới / cũ ---------- */
.unit-box { background: var(--c-bg); border-radius: 10px; padding: .45rem .7rem; margin-bottom: .7rem; font-size: .86rem; }
.unit-box[hidden] { display: none; }
.ub-row { display: flex; gap: .4rem; align-items: flex-start; padding: .15rem 0; }
.ub-row .ic { width: 15px; height: 15px; margin-top: 3px; color: var(--c-primary); flex-shrink: 0; }
.ub-row em { font-style: normal; font-size: .66rem; font-weight: 700; border-radius: 4px; padding: 0 5px; vertical-align: 1px; background: #e6e9e8; color: #4b5a60; }
.ub-row em.ub-new { background: var(--c-primary); color: #fff; }
.ub-old { color: #4b5a60; }
.ub-old .ic { color: var(--c-muted); }
.ub-src { display: block; font-size: .68rem; color: var(--c-muted); margin-top: 2px; padding-left: 1.3rem; }

