/* ============================================================
   MapProject – etowner design system
   Primary  : #b0812c  (etowner gold)
   Light bg : #f5f6f3 / card #ffffff / text #1a2018
   Dark  bg : #122720  / card #163020  / text #e8e4d0
   ============================================================ */

/* ── CSS tokens (light mode default) ─────────────────────────────────────── */
:root {
    --mp-primary: #b0812c;
    --mp-primary-dim: #8c6420;
    --mp-primary-bg: rgba(176, 129, 44, .12);

    --mp-body-bg: #f5f6f3;
    --mp-card-bg: #ffffff;
    --mp-topbar-bg: #b0812c;
    --mp-topbar-text: #f0ece0;
    --mp-border: #dde0da;
    --mp-text: #1a2018;
    --mp-text-muted: #6b7a68;
    --mp-text-inv: #ffffff;
    --mp-shadow: 0 2px 12px rgba(18, 39, 32, .14);
    --mp-shadow-lg: 0 4px 24px rgba(18, 39, 32, .20);
    --mp-input-bg: #f0f2ee;
    --mp-input-border: #c8cdc4;

    /* marker colours */
    --mp-m-district: #b0812c;
    --mp-m-area: #ff4c51;
    --mp-m-surface: #ffb400;
    --mp-m-pv: #16b1ff;
    --mp-m-pp: #56ca00;
    --mp-m-tank: #ff9f43;

    --mp-radius: 8px;
    --mp-topbar-h: 62px;
    --mp-filter-h: 52px;
    --mp-sidebar-w: 340px;
    --mp-transition: .22s ease;
}

/* ── Dark mode tokens ─────────────────────────────────────────────────────── */
[data-bs-theme="dark"] {
    --mp-body-bg: #122720;
    --mp-card-bg: #163020;
    --mp-topbar-bg: linear-gradient(135deg, #b0812c 0%, #b0812c 40%, #e1b96e 100%);
    --mp-topbar-text: #e8e4d0;
    --mp-border: #1e3a2a;
    --mp-text: #e8e4d0;
    --mp-text-muted: #7a9a84;
    --mp-text-inv: #e8e4d0;
    --mp-shadow: 0 2px 12px rgba(0, 0, 0, .40);
    --mp-shadow-lg: 0 4px 24px rgba(0, 0, 0, .55);
    --mp-input-bg: #1a3528;
    --mp-input-border: #244030;
}

/* ── Reset ────────────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    font-size: 14px;
    background: var(--mp-body-bg);
    color: var(--mp-text);
    transition: background var(--mp-transition), color var(--mp-transition);
}

/* ── Top Bar ──────────────────────────────────────────────────────────────── */
#topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--mp-topbar-h);
    border-radius: var(--mp-radius) var(--mp-radius) 0 0;
    background: var(--mp-topbar-bg);
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    color: var(--mp-topbar-text);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    z-index: 1100;
    box-shadow: var(--mp-shadow);
    transition: background var(--mp-transition);
}

/* ── Search ───────────────────────────────────────────────────────────────── */
#search-wrap {
    flex: 1;
    max-width: 460px;
    position: relative;
}

#search-input {
    width: 100%;
    padding: 10px 38px 10px 14px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, .18);
    font-size: 13px;
    background: rgba(255, 255, 255, .10);
    color: var(--mp-topbar-text);
    outline: none;
    transition: border-color var(--mp-transition), background var(--mp-transition);
}

#search-input::placeholder {
    color: rgba(231, 227, 252, .45);
}

#search-input:focus {
    border-color: var(--mp-primary);
    background: rgba(255, 255, 255, .15);
    box-shadow: 0 0 0 3px rgba(176, 129, 44, .30);
}

#search-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: rgba(231, 227, 252, .55);
    cursor: pointer;
    font-size: 15px;
    padding: 0;
}

#search-results {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: var(--mp-card-bg);
    border: 1px solid var(--mp-border);
    border-radius: var(--mp-radius);
    box-shadow: var(--mp-shadow-lg);
    max-height: 260px;
    overflow-y: auto;
    z-index: 2000;
    display: none;
}

#search-results.show {
    display: block;
}

.search-item {
    padding: 9px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--mp-border);
    transition: background var(--mp-transition);
}

.search-item:hover {
    background: var(--mp-primary-bg);
}

.search-item:last-child {
    border-bottom: none;
}

.search-item .si-id {
    font-weight: 600;
    font-size: 13px;
    color: var(--mp-primary);
}

.search-item .si-meta {
    font-size: 11px;
    color: var(--mp-text-muted);
    margin-top: 2px;
}

/* ── Counters ─────────────────────────────────────────────────────────────── */
#counters {
    display: flex;
    gap: 4px;
    white-space: nowrap;
    align-items: center;
}

.counter-chip {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 5px 11px;
    border-radius: 10px;
    background: rgba(255, 255, 255, .12);
    border: 1px solid rgba(255, 255, 255, .15);
}

.cc-icon {
    font-size: 15px;
    line-height: 1;
    flex-shrink: 0;
    color: rgba(255, 255, 255, .85);
}

.cc-content {
    display: flex;
    flex-direction: column;
    line-height: 1;
}

.cc-content b {
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    line-height: 1.1;
}

.cc-label {
    font-size: 8px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: rgba(255, 255, 255, .65);
    margin-top: 1px;
}

#btn-sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: rgba(231, 227, 252, .60);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 6px;
}

/* ── Filter Bar ───────────────────────────────────────────────────────────── */
#filter-bar {
    position: fixed;
    top: var(--mp-topbar-h);
    left: 0;
    right: var(--mp-sidebar-w);
    height: var(--mp-filter-h);
    background: var(--mp-card-bg);
    border-bottom: 1px solid var(--mp-border);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 16px;
    z-index: 1050;
    transition: background var(--mp-transition), border-color var(--mp-transition);
}

.filter-select {
    flex: 1;
    min-width: 0;
    padding: 6px 10px;
    border: 1px solid var(--mp-input-border);
    border-radius: var(--mp-radius);
    font-size: 13px;
    background: var(--mp-input-bg);
    color: var(--mp-text);
    outline: none;
    cursor: pointer;
    transition: border-color var(--mp-transition), background var(--mp-transition);
}

.filter-select:focus {
    border-color: var(--mp-primary);
    box-shadow: 0 0 0 3px var(--mp-primary-bg);
}

.filter-select:disabled {
    opacity: .45;
    cursor: default;
}

#btn-reset-filters {
    flex-shrink: 0;
    padding: 6px 14px;
    background: var(--mp-primary);
    color: #fff;
    border: none;
    border-radius: var(--mp-radius);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--mp-transition);
    white-space: nowrap;
}

#btn-reset-filters:hover {
    background: var(--mp-primary-dim);
}

/* ── Filter bar type badges ───────────────────────────────────────────────── */
.fb-type {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .5px;
    flex-shrink: 0;
    white-space: nowrap;
}

.fb-district {
    background: var(--mp-m-district);
    color: #fff;
}

.fb-area {
    background: var(--mp-m-area);
    color: #fff;
}

.fb-surface {
    background: var(--mp-m-surface);
    color: #333;
}

.fb-sep {
    color: var(--mp-text-muted);
    font-size: 18px;
    flex-shrink: 0;
    line-height: 1;
    opacity: .5;
}

/* ── Map container ────────────────────────────────────────────────────────── */
#map-wrap {
    position: fixed;
    top: calc(var(--mp-topbar-h) + var(--mp-filter-h));
    left: 0;
    right: var(--mp-sidebar-w);
    bottom: 0;
    z-index: 0;
}

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

/* ── Breadcrumb overlay ───────────────────────────────────────────────────── */
#breadcrumb-bar {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--mp-card-bg);
    border: 1px solid var(--mp-border);
    border-radius: 20px;
    padding: 5px 18px;
    font-size: 12px;
    box-shadow: var(--mp-shadow);
    z-index: 500;
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: 90%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
}

.bc-sep {
    color: var(--mp-text-muted);
}

.bc-item {
    color: var(--mp-primary);
    font-weight: 600;
    pointer-events: auto;
    cursor: pointer;
}

.bc-item:hover {
    text-decoration: underline;
}

.bc-item.bc-current {
    color: var(--mp-text);
    cursor: default;
    pointer-events: none;
}

/* ── Back Button ──────────────────────────────────────────────────────────── */
#btn-back {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 500;
    background: var(--mp-card-bg);
    border: 1px solid var(--mp-border);
    border-radius: var(--mp-radius);
    padding: 7px 14px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    color: var(--mp-primary);
    box-shadow: var(--mp-shadow);
    display: none;
    align-items: center;
    gap: 6px;
    transition: background var(--mp-transition);
}

#btn-back:hover {
    background: var(--mp-primary-bg);
}

#btn-back.visible {
    display: flex;
}

/* ── Map controls ─────────────────────────────────────────────────────────── */
#map-controls {
    position: absolute;
    bottom: 16px;
    right: 12px;
    z-index: 500;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.map-ctrl-btn {
    background: var(--mp-card-bg);
    border: 1px solid var(--mp-border);
    border-radius: var(--mp-radius);
    width: 34px;
    height: 34px;
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--mp-text);
    box-shadow: var(--mp-shadow);
    transition: background var(--mp-transition), color var(--mp-transition);
}

.map-ctrl-btn:hover {
    background: var(--mp-primary-bg);
    color: var(--mp-primary);
}

/* ── Layer Switcher ───────────────────────────────────────────────────────── */
#layer-control {
    position: relative;
}

#layer-panel {
    position: absolute;
    bottom: 0;
    right: calc(100% + 8px);
    background: var(--mp-card-bg);
    border: 1px solid var(--mp-border);
    border-radius: var(--mp-radius);
    box-shadow: var(--mp-shadow-lg);
    padding: 8px;
    display: none;
    flex-direction: row;
    gap: 8px;
    z-index: 600;
    white-space: nowrap;
}

#layer-panel.open {
    display: flex;
}

.layer-opt {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    border: 2px solid transparent;
    transition: border-color var(--mp-transition), background var(--mp-transition);
}

.layer-opt:hover {
    background: var(--mp-primary-bg);
}

.layer-opt.active {
    border-color: var(--mp-primary);
}

.layer-thumb {
    width: 54px;
    height: 40px;
    border-radius: 4px;
    border: 1px solid var(--mp-border);
}

.lt-street {
    background: linear-gradient(135deg, #f2ede4 0%, #cfc8b8 100%);
}

.lt-satellite {
    background: linear-gradient(135deg, #1a2a1a 0%, #2e5030 60%, #4a7050 100%);
}

.lt-dark {
    background: linear-gradient(135deg, #0f0f1a 0%, #1a1a2e 60%, #252540 100%);
}

.lt-terrain {
    background: linear-gradient(135deg, #c8d8b0 0%, #a0c080 50%, #80a860 100%);
}

.layer-opt span {
    font-size: 11px;
    font-weight: 500;
    color: var(--mp-text);
}

.layer-opt.active span {
    color: var(--mp-primary);
    font-weight: 700;
}

/* ── Legend (floating inside #map-wrap) ──────────────────────────────────── */
#legend {
    position: absolute;
    bottom: 14px;
    left: 14px;
    background: var(--mp-card-bg);
    border: 1px solid var(--mp-border);
    border-radius: var(--mp-radius);
    box-shadow: var(--mp-shadow);
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    z-index: 500;
    overflow-x: auto;
    max-width: calc(100% - 28px);
    transition: background var(--mp-transition), border-color var(--mp-transition);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--mp-text-muted);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    transition: opacity var(--mp-transition);
    border-radius: 6px;
    padding: 2px 6px;
}

.legend-item:hover {
    background: var(--mp-primary-bg);
    color: var(--mp-text);
}

.legend-item.hidden-layer {
    opacity: 0.38;
}

.legend-item.hidden-layer .legend-icon {
    filter: grayscale(1);
}

.legend-item.hidden-layer span {
    text-decoration: line-through;
}

.legend-icon {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    color: #fff;
    font-weight: 700;
    flex-shrink: 0;
}

.l-district {
    background: var(--mp-m-district);
}

.l-area {
    background: var(--mp-m-area);
}

.l-surface {
    background: var(--mp-m-surface);
}

.l-pv {
    background: var(--mp-m-pv);
}

.l-pp {
    background: var(--mp-m-pp);
}

.l-tank {
    background: var(--mp-m-tank);
}

/* ── Right Sidebar ────────────────────────────────────────────────────────── */
#sidebar {
    position: fixed;
    top: var(--mp-topbar-h);
    right: 0;
    width: var(--mp-sidebar-w);
    bottom: 0;
    background: var(--mp-card-bg);
    border-left: 1px solid var(--mp-border);
    z-index: 1060;
    display: flex;
    flex-direction: column;
    box-shadow: -2px 0 10px rgba(0, 0, 0, .08);
    transition: transform var(--mp-transition), background var(--mp-transition), border-color var(--mp-transition);
}

#sidebar-header {
    padding: 9px 16px;
    border-bottom: 1px solid var(--mp-border);
    background: var(--mp-card-bg);
    color: var(--mp-text);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

#sidebar-title {
    font-size: 15px;
    font-weight: 700;
}

#sidebar-stats {
    font-size: 11px;
    opacity: .82;
    margin-top: 3px;
    font-weight: 500;
}

#sidebar-body {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

/* Sidebar content pieces */
.sb-section {
    margin-bottom: 18px;
    padding: 0 16px;
}

.sb-section:first-child {
    padding-top: 14px;
}

.sb-section-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .7px;
    color: var(--mp-text-muted);
    margin-bottom: 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--mp-border);
}

.sb-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 5px 0;
    border-bottom: 1px solid var(--mp-border);
    gap: 8px;
}

.sb-row:last-child {
    border-bottom: none;
}

.sb-label {
    color: var(--mp-text-muted);
    font-size: 12px;
    flex-shrink: 0;
    min-width: 90px;
}

.sb-value {
    font-size: 13px;
    font-weight: 500;
    color: var(--mp-text);
    text-align: right;
    word-break: break-word;
}

.sb-stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding-bottom: 8px;
}

.sb-stat {
    background: var(--mp-body-bg);
    border: 1px solid var(--mp-border);
    border-radius: var(--mp-radius);
    padding: 10px 12px;
    text-align: center;
}

.sb-stat-num {
    font-size: 22px;
    font-weight: 700;
    color: var(--mp-primary);
    line-height: 1;
}

.sb-stat-lbl {
    font-size: 10px;
    color: var(--mp-text-muted);
    text-transform: uppercase;
    margin-top: 3px;
}

.sb-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}

.sb-badge.active {
    background: rgba(86, 202, 0, .15);
    color: #56ca00;
}

.sb-badge.inactive {
    background: rgba(255, 76, 81, .12);
    color: #ff4c51;
}

.sb-badge.pending {
    background: rgba(255, 180, 0, .15);
    color: #ffb400;
}

.sb-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--mp-text-muted);
}

.sb-empty .sb-empty-icon {
    font-size: 40px;
    margin-bottom: 10px;
}

.sb-empty p {
    font-size: 13px;
}

.asset-type-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 14px;
    font-size: 12px;
    font-weight: 700;
    margin-bottom: 12px;
}

.pill-pv {
    background: rgba(22, 177, 255, .15);
    color: #16b1ff;
}

.pill-pp {
    background: rgba(86, 202, 0, .15);
    color: #56ca00;
}

.pill-tank {
    background: rgba(255, 159, 67, .15);
    color: #ff9f43;
}

/* ── Custom marker styles ─────────────────────────────────────────────────── */
.map-marker {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 2.5px solid rgba(255, 255, 255, .9);
    box-shadow: 0 2px 8px rgba(0, 0, 0, .30);
    font-weight: 800;
    font-size: 11px;
    color: #fff;
    cursor: pointer;
    transition: transform .15s, box-shadow .15s;
}

.map-marker:hover {
    transform: scale(1.15);
    box-shadow: 0 4px 16px rgba(0, 0, 0, .38);
}

.map-marker.highlighted {
    animation: mp-pulse 1.2s ease-in-out infinite;
    box-shadow: 0 0 0 4px rgba(176, 129, 44, .45), 0 4px 16px rgba(0, 0, 0, .38);
}

@keyframes mp-pulse {

    0%,
    100% {
        box-shadow: 0 0 0 4px rgba(176, 129, 44, .45), 0 4px 16px rgba(0, 0, 0, .38);
    }

    50% {
        box-shadow: 0 0 0 8px rgba(176, 129, 44, .20), 0 4px 16px rgba(0, 0, 0, .38);
    }
}

.m-district {
    background: var(--mp-m-district);
    width: 40px;
    height: 40px;
    font-size: 12px;
}

.m-area {
    background: var(--mp-m-area);
    width: 34px;
    height: 34px;
}

.m-surface {
    background: var(--mp-m-surface);
    width: 28px;
    height: 28px;
    color: #1a2018;
}

.m-pv {
    background: var(--mp-m-pv);
    width: 24px;
    height: 24px;
    font-size: 9px;
}

.m-pp {
    background: var(--mp-m-pp);
    width: 24px;
    height: 24px;
    font-size: 9px;
}

.m-tank {
    background: var(--mp-m-tank);
    width: 24px;
    height: 24px;
    font-size: 9px;
}

/* ── Leaflet popup overrides ──────────────────────────────────────────────── */
.leaflet-popup-content-wrapper {
    background: var(--mp-card-bg) !important;
    color: var(--mp-text) !important;
    border-radius: var(--mp-radius) !important;
    box-shadow: var(--mp-shadow-lg) !important;
    border: 1px solid var(--mp-border);
    min-width: 180px;
}

.leaflet-popup-tip {
    background: var(--mp-card-bg) !important;
}

.leaflet-popup-content {
    margin: 12px 16px !important;
}

.lp-title {
    font-weight: 700;
    font-size: 14px;
    color: var(--mp-primary);
    margin-bottom: 4px;
}

.lp-sub {
    font-size: 12px;
    color: var(--mp-text-muted);
    margin-bottom: 6px;
}

.lp-meta {
    font-size: 11px;
    color: var(--mp-text-muted);
}

/* ── Loading overlay ──────────────────────────────────────────────────────── */
#loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(18, 39, 32, .55);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9000;
}

#loading-overlay.show {
    display: flex;
}

.spinner {
    width: 42px;
    height: 42px;
    border: 3.5px solid var(--mp-border);
    border-top-color: var(--mp-primary);
    border-radius: 50%;
    animation: mp-spin .75s linear infinite;
}

@keyframes mp-spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-msg {
    margin-top: 14px;
    font-size: 13px;
    color: var(--mp-text-muted);
}

/* ── Toast ────────────────────────────────────────────────────────────────── */
#toast-container {
    position: fixed;
    bottom: 56px;
    right: calc(var(--mp-sidebar-w) + 14px);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: var(--mp-primary);
    color: #fff;
    padding: 10px 18px;
    border-radius: var(--mp-radius);
    font-size: 13px;
    box-shadow: var(--mp-shadow-lg);
    animation: mp-fadeUp .3s ease;
    pointer-events: auto;
    max-width: 300px;
}

.toast.success {
    background: #56ca00;
}

.toast.error {
    background: #ff4c51;
}

.toast.warning {
    background: #ffb400;
    color: #1a2018;
}

@keyframes mp-fadeUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ── Iframe embed mode — full UI visible, no overrides needed ─────────────── */
body.iframe-mode #toast-container {
    bottom: 10px;
    right: calc(var(--mp-sidebar-w) + 10px);
}

/* ============================================================
   Responsive – Tablet ≤ 991px
   ============================================================ */
@media (max-width: 991px) {
    :root {
        --mp-sidebar-w: 0px;
    }

    #sidebar {
        --mp-sidebar-w: 320px;
        width: 320px;
        transform: translateX(100%);
    }

    #sidebar.open {
        transform: translateX(0);
    }

    #filter-bar {
        right: 0;
    }

    #map-wrap {
        right: 0;
    }

    #toast-container {
        right: 14px;
    }

    #btn-sidebar-toggle {
        display: block;
    }
}

/* ============================================================
   Responsive – Mobile ≤ 600px
   ============================================================ */
@media (max-width: 600px) {
    #filter-bar {
        flex-wrap: wrap;
        height: auto;
        padding: 8px 10px;
        gap: 6px;
    }

    .filter-select {
        flex: 1 1 calc(50% - 6px);
    }

    #map-wrap {
        top: calc(var(--mp-topbar-h) + 108px);
    }

    #counters {
        display: none;
    }

    #sidebar {
        top: auto;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 55vh;
        transform: translateY(100%);
        border-left: none;
        border-top: 2px solid var(--mp-border);
    }

    #sidebar.open {
        transform: translateY(0);
    }

    #legend {
        display: none;
    }

    #toast-container {
        bottom: 10px;
        right: 10px;
    }
}

/* ============================================================
   Measure Tool
   ============================================================ */
#measure-control {
    position: relative;
}

#measure-panel {
    position: absolute;
    bottom: 0;
    right: calc(100% + 8px);
    background: var(--mp-card-bg);
    border: 1px solid var(--mp-border);
    border-radius: var(--mp-radius);
    box-shadow: var(--mp-shadow-lg);
    padding: 8px;
    display: none;
    flex-direction: column;
    gap: 6px;
    z-index: 600;
    min-width: 140px;
    white-space: nowrap;
}

#measure-panel.open {
    display: flex;
}

.measure-mode-btn {
    background: none;
    border: 1px solid var(--mp-border);
    border-radius: 6px;
    padding: 7px 10px;
    color: var(--mp-text);
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    transition: background var(--mp-transition), border-color var(--mp-transition), color var(--mp-transition);
}

.measure-mode-btn:hover {
    background: var(--mp-primary-bg);
    border-color: var(--mp-primary);
}

.measure-mode-btn.active {
    background: var(--mp-primary-bg);
    border-color: var(--mp-primary);
    color: var(--mp-primary);
    font-weight: 600;
}

#btn-measure-clear {
    background: none;
    border: 1px solid var(--mp-border);
    border-radius: 6px;
    padding: 6px 10px;
    color: var(--mp-text-muted);
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    text-align: left;
    transition: background var(--mp-transition), color var(--mp-transition), border-color var(--mp-transition);
}

#btn-measure-clear:hover {
    background: rgba(255, 76, 81, .10);
    border-color: #ff4c51;
    color: #ff4c51;
}

#btn-measure.active {
    background: var(--mp-primary);
    color: #fff;
    border-color: var(--mp-primary);
}

/* ── Measure info box ─────────────────────────────────────── */
#measure-box {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--mp-card-bg);
    border: 1.5px solid var(--mp-primary);
    border-radius: var(--mp-radius);
    box-shadow: var(--mp-shadow-lg);
    padding: 10px 16px;
    z-index: 600;
    display: flex;
    align-items: center;
    gap: 12px;
    white-space: nowrap;
}

#measure-box.hidden {
    display: none;
}

#measure-box-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--mp-primary);
}

#measure-box-value {
    font-size: 16px;
    font-weight: 700;
    color: var(--mp-text);
}

#measure-box-hint {
    font-size: 11px;
    color: var(--mp-text-muted);
}

#measure-box-btns {
    display: flex;
    gap: 6px;
    margin-left: 4px;
}

#measure-box-btns button {
    background: none;
    border: 1px solid var(--mp-border);
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 11px;
    font-family: inherit;
    cursor: pointer;
    color: var(--mp-text);
    transition: background var(--mp-transition), color var(--mp-transition), border-color var(--mp-transition);
    white-space: nowrap;
}

#btn-measure-done {
    border-color: var(--mp-primary) !important;
    color: var(--mp-primary) !important;
    font-weight: 600;
}

#btn-measure-done:hover {
    background: var(--mp-primary-bg) !important;
}

#btn-measure-stop:hover {
    background: rgba(255, 76, 81, .10);
    border-color: #ff4c51;
    color: #ff4c51;
}

/* ============================================================
   Cluster Sidebar List
   ============================================================ */
.cg-header {
    padding: 14px 16px 10px;
    border-bottom: 1px solid var(--mp-border);
}

.cg-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--mp-text);
    margin-bottom: 8px;
}

.cg-summary {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.cg-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    color: #fff;
}

.cg-badge.m-district {
    background: var(--mp-m-district);
}

.cg-badge.m-area {
    background: var(--mp-m-area);
}

.cg-badge.m-surface {
    background: var(--mp-m-surface);
    color: #333;
}

.cg-badge.m-pv {
    background: var(--mp-m-pv);
}

.cg-badge.m-pp {
    background: var(--mp-m-pp);
}

.cg-badge.m-tank {
    background: var(--mp-m-tank);
}

.cg-list {
    overflow-y: auto;
    max-height: calc(100vh - 320px);
}

.cg-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--mp-border);
    cursor: pointer;
    transition: background var(--mp-transition);
}

.cg-row:hover {
    background: var(--mp-primary-bg);
}

.cg-row:last-child {
    border-bottom: none;
}

.cg-row-info {
    flex: 1;
    min-width: 0;
}

.cg-row-id {
    font-size: 13px;
    font-weight: 600;
    color: var(--mp-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cg-row-type {
    font-size: 11px;
    color: var(--mp-text-muted);
    margin-top: 2px;
}

.cg-row-status {
    font-size: 10px;
    font-weight: 600;
    color: var(--mp-primary);
    margin-top: 2px;
}

.cg-row-dot {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    font-weight: 800;
    color: #fff;
    border: 2px solid rgba(255, 255, 255, .7);
    box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
}

.cg-hint {
    padding: 10px 16px;
    font-size: 11px;
    color: var(--mp-text-muted);
    text-align: center;
    border-top: 1px solid var(--mp-border);
}

/* ── Row detail toggle ───────────────────────────────────────────────────── */
.cg-row-toggle {
    background: none;
    border: 1px solid var(--mp-border);
    border-radius: 6px;
    cursor: pointer;
    color: var(--mp-text-muted);
    font-size: 13px;
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--mp-transition), color var(--mp-transition), background var(--mp-transition);
    line-height: 1;
}

.cg-row-toggle:hover {
    color: var(--mp-primary);
    background: var(--mp-primary-bg);
    border-color: var(--mp-primary);
}

.cg-row-toggle.open {
    transform: rotate(180deg);
    color: var(--mp-primary);
    border-color: var(--mp-primary);
}

/* ── Expandable detail panel ─────────────────────────────────────────────── */
.cg-row-detail {
    padding: 8px 16px 10px 54px;
    background: var(--mp-primary-bg);
    border-bottom: 1px solid var(--mp-border);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 12px;
}

.cg-row-detail.hidden {
    display: none;
}

.cg-detail-field {
    display: flex;
    flex-direction: column;
    padding: 4px 0;
    border-bottom: 1px solid var(--mp-border);
    min-width: 0;
}

.cg-detail-field:last-child,
.cg-detail-field:nth-last-child(2):nth-child(odd) {
    border-bottom: none;
}

.cg-detail-label {
    font-size: 10px;
    color: var(--mp-text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .4px;
    margin-bottom: 1px;
}

.cg-detail-value {
    font-size: 12px;
    color: var(--mp-text);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================================
   Sidebar Card List  (Districts / Areas / Surfaces redesign)
   ============================================================ */
.sb-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--mp-border);
    transition: background var(--mp-transition);
}

.sb-card:hover {
    background: var(--mp-body-bg);
}

.sb-card-dot {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 800;
    color: #fff;
    border: 2px solid rgba(255, 255, 255, .7);
    box-shadow: 0 1px 5px rgba(0, 0, 0, .22);
}

.sb-card-dot.m-district {
    background: var(--mp-m-district);
}

.sb-card-dot.m-area {
    background: var(--mp-m-area);
}

.sb-card-dot.m-surface {
    background: var(--mp-m-surface);
    color: #333;
}

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

.sb-card-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--mp-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sb-card-sub {
    font-size: 11px;
    color: var(--mp-text-muted);
    margin-top: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sb-card-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.sb-card-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    padding: 3px 9px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 700;
    color: #fff;
}

.sb-card-count.m-district {
    background: var(--mp-m-district);
}

.sb-card-count.m-area {
    background: var(--mp-m-area);
}

.sb-card-count.m-surface {
    background: var(--mp-m-surface);
    color: #333;
}

.sb-card-toggle {
    background: none;
    border: 1px solid var(--mp-border);
    border-radius: 6px;
    cursor: pointer;
    color: var(--mp-text-muted);
    font-size: 12px;
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--mp-transition), color var(--mp-transition), background var(--mp-transition), border-color var(--mp-transition);
    line-height: 1;
}

.sb-card-toggle:hover {
    color: var(--mp-primary);
    background: var(--mp-body-bg);
    border-color: var(--mp-primary);
}

.sb-card-toggle.open {
    transform: rotate(180deg);
    color: var(--mp-primary);
    border-color: var(--mp-primary);
}

.sb-card-detail {
    padding: 8px 16px 10px 62px;
    background: var(--mp-body-bg);
    border-bottom: 1px solid var(--mp-border);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 12px;
}

.sb-card-detail.hidden {
    display: none;
}

/* ============================================================
   Print
   ============================================================ */
@media print {
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    #topbar,
    #filter-bar,
    #map-controls,
    #breadcrumb-bar,
    #btn-back,
    #toast-container,
    #sidebar,
    #measure-box,
    .leaflet-control-attribution {
        display: none !important;
    }

    body {
        margin: 0 !important;
        padding: 0 !important;
        height: 100vh !important;
        overflow: hidden !important;
    }

    #map-wrap {
        position: fixed !important;
        top: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        height: 100vh !important;
        width: 100vw !important;
        z-index: 1 !important;
    }

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

    #legend {
        position: fixed !important;
        bottom: 8mm !important;
        right: 8mm !important;
        left: auto !important;
        background: #fff !important;
        border: 1px solid #bbb !important;
        border-radius: 6px !important;
        padding: 10px 14px !important;
        z-index: 9999 !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 6px !important;
        height: auto !important;
        width: auto !important;
        max-width: 180px !important;
        overflow: visible !important;
    }

    .legend-item {
        display: flex !important;
        opacity: 1 !important;
    }

    .legend-item.hidden-layer {
        display: none !important;
    }
}