/* Manchester Heat Map — UI */

.mhm-map-wrapper {
    --mhm-navy: #050a28;
    --mhm-text: #1a3a4a;
    --mhm-muted: #5a6a7a;
    --mhm-border: rgba(5, 10, 40, 0.08);
    --mhm-border-soft: rgba(5, 10, 40, 0.05);
    --mhm-surface: #ffffff;
    --mhm-cream: #f5f1e8;
    --mhm-accent: #2a9d8f;
    --mhm-shadow: 0 10px 40px rgba(5, 10, 40, 0.1);
    --mhm-radius: 10px;
    --mhm-radius-sm: 6px;

    position: relative;
    width: 100%;
    background: var(--mhm-map-bg, #eef1f4);
    overflow: visible;
    font-family: inherit;
    color: var(--mhm-text);
}

.mhm-map-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.mhm-map-wrapper .mapboxgl-canvas,
.mhm-map-wrapper .mapboxgl-canvas-container.mapboxgl-interactive {
    touch-action: none;
}

.mhm-map-canvas .mapboxgl-map {
    overflow: visible;
}

/* Mapbox controls — softer than default */
.mhm-map-wrapper .mapboxgl-ctrl-group {
    border: 1px solid var(--mhm-border) !important;
    border-radius: var(--mhm-radius-sm) !important;
    box-shadow: 0 2px 10px rgba(5, 10, 40, 0.06) !important;
    overflow: hidden;
    background: var(--mhm-surface);
}

.mhm-map-wrapper .mapboxgl-ctrl-group:not(:empty) {
    box-shadow: 0 2px 10px rgba(5, 10, 40, 0.06) !important;
}

.mhm-map-wrapper .mapboxgl-ctrl-group button {
    border-color: var(--mhm-border-soft) !important;
}

.mhm-map-wrapper .mapboxgl-ctrl-group button + button {
    border-top-color: var(--mhm-border-soft) !important;
}

.mhm-map-wrapper .mapboxgl-ctrl-scale {
    border-color: var(--mhm-border) !important;
    border-radius: var(--mhm-radius-sm);
    background: rgba(255, 255, 255, 0.92);
    color: var(--mhm-muted);
    font-size: 10px;
    padding: 0 6px;
}

/* ── Toolbar ── */

.mhm-map-toolbar {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 6;
    display: flex;
    gap: 8px;
}

.mhm-sidebar-toggle,
.mhm-fullscreen-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 36px;
    min-width: 36px;
    padding: 0 10px !important;
    border: 1px solid var(--mhm-border) !important;
    background: var(--mhm-surface) !important;
    color: var(--mhm-text) !important;
    cursor: pointer;
    border-radius: var(--mhm-radius-sm) !important;
    box-shadow: 0 2px 10px rgba(5, 10, 40, 0.06) !important;
    transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
    line-height: 1;
}

.mhm-sidebar-toggle:hover,
.mhm-fullscreen-toggle:hover {
    background: var(--mhm-cream) !important;
    border-color: rgba(5, 10, 40, 0.12) !important;
    box-shadow: 0 4px 14px rgba(5, 10, 40, 0.08) !important;
}

.mhm-map-wrapper:not(.is-collapsed) .mhm-sidebar-toggle {
    background: var(--mhm-navy) !important;
    border-color: transparent !important;
    color: #fff !important;
    box-shadow: 0 4px 14px rgba(5, 10, 40, 0.15) !important;
}

.mhm-toggle-label {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.mhm-fullscreen-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.mhm-fullscreen-exit {
    display: none;
}

/* ── Sidebar ── */

.mhm-map-sidebar {
    position: absolute;
    top: 14px;
    left: 14px;
    z-index: 5;
    width: 300px;
    max-width: calc(100% - 28px);
    height: calc(100% - 28px);
    background: var(--mhm-surface) !important;
    border: 1px solid var(--mhm-border) !important;
    border-radius: var(--mhm-radius) !important;
    box-shadow: var(--mhm-shadow) !important;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform 0.28s ease, opacity 0.28s ease;
}

.mhm-map-wrapper.is-collapsed .mhm-map-sidebar {
    transform: translateX(calc(-100% - 20px));
    opacity: 0;
    pointer-events: none;
}

.mhm-sidebar-header {
    padding: 14px 14px 12px;
    border-bottom: 1px solid var(--mhm-border-soft) !important;
    flex-shrink: 0;
    background: linear-gradient(180deg, #fff 0%, #fcfcfd 100%) !important;
}

.mhm-sidebar-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}

.mhm-sidebar-header h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    color: var(--mhm-navy);
    letter-spacing: -0.01em;
}

.mhm-active-count {
    font-size: 11px;
    font-weight: 600;
    color: var(--mhm-accent);
    background: rgba(42, 157, 143, 0.1);
    padding: 3px 8px;
    white-space: nowrap;
    border-radius: 999px;
}

.mhm-layer-search-wrap {
    position: relative;
}

.mhm-layer-search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    color: var(--mhm-muted) !important;
    opacity: 0.65;
    pointer-events: none;
    transform: translateY(-50%);
}

.mhm-layer-search-icon svg {
    display: block;
    width: 14px;
    height: 14px;
}

.mhm-layer-search {
    width: 100%;
    padding: 8px 10px 8px 32px !important;
    font-size: 13px !important;
    color: var(--mhm-text) !important;
    background: var(--mhm-surface) !important;
    border: 1px solid var(--mhm-border) !important;
    border-radius: var(--mhm-radius-sm) !important;
    appearance: none;
    box-shadow: none !important;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.mhm-layer-search:focus {
    outline: none !important;
    border-color: rgba(42, 157, 143, 0.35) !important;
    box-shadow: 0 0 0 3px rgba(42, 157, 143, 0.12) !important;
}

.mhm-layer-search::-webkit-search-decoration,
.mhm-layer-search::-webkit-search-cancel-button {
    -webkit-appearance: none;
    appearance: none;
}

.mhm-layer-search::placeholder {
    color: var(--mhm-muted);
}

/* ── Layer groups (scroll area) ── */

.mhm-layer-groups {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.mhm-layer-groups::-webkit-scrollbar {
    width: 6px;
}

.mhm-layer-groups::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.mhm-layer-empty {
    padding: 20px 16px;
    margin: 0;
    font-size: 13px;
    color: var(--mhm-muted);
    text-align: center;
    line-height: 1.45;
}

.mhm-layer-group + .mhm-layer-group {
    border-top: 1px solid var(--mhm-border-soft) !important;
}

.mhm-group-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    padding: 10px 14px !important;
    border: none !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    cursor: pointer;
    font-size: 11px !important;
    font-weight: 700 !important;
    color: var(--mhm-navy) !important;
    text-align: left;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    transition: background 0.15s ease;
}

.mhm-group-toggle:hover {
    background: rgba(245, 241, 232, 0.65) !important;
}

.mhm-group-label {
    flex: 1 1 auto;
    min-width: 0;
    text-align: left;
    padding-right: 8px;
}

.mhm-group-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    flex-shrink: 0;
    margin-left: auto;
}

.mhm-group-active-dots {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    flex-wrap: nowrap;
}

.mhm-group-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    border: 1.5px solid rgba(255, 255, 255, 0.95);
    box-shadow: 0 0 0 1px rgba(5, 10, 40, 0.08);
    flex-shrink: 0;
}

.mhm-group-count {
    font-size: 10px;
    font-weight: 600;
    color: var(--mhm-muted);
    letter-spacing: 0;
    text-transform: none;
    white-space: nowrap;
}

.mhm-layer-group.has-active .mhm-group-count {
    color: var(--mhm-accent);
}

.mhm-group-chevron {
    width: 8px;
    height: 8px;
    border-right: 1.5px solid var(--mhm-muted);
    border-bottom: 1.5px solid var(--mhm-muted);
    transform: rotate(45deg);
    transition: transform 0.2s ease;
    margin-top: -3px;
}

.mhm-layer-group.is-collapsed .mhm-group-chevron {
    transform: rotate(-45deg);
    margin-top: 3px;
}

.mhm-layer-group.is-collapsed .mhm-group-layers {
    display: none;
}

/* ── Layer items ── */

.mhm-layer-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px 8px 18px !important;
    cursor: pointer;
    border-top: 1px solid var(--mhm-border-soft) !important;
    border-left: none !important;
    border-right: none !important;
    border-bottom: none !important;
    border-radius: 0 !important;
    transition: background 0.15s ease;
}

.mhm-layer-item:hover {
    background: #fafbfc !important;
}

.mhm-layer-item.is-active {
    background: rgba(42, 157, 143, 0.05) !important;
}

.mhm-layer-item--error {
    opacity: 0.55;
}

.mhm-layer-swatch {
    flex-shrink: 0;
    background: var(--swatch, #888);
    border: 1.5px solid rgba(255, 255, 255, 0.9);
    box-shadow: 0 0 0 1px rgba(5, 10, 40, 0.08);
}

.mhm-layer-swatch--point {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.mhm-layer-swatch--line {
    width: 14px;
    height: 3px;
    border-radius: 2px;
}

.mhm-layer-swatch--polygon,
.mhm-layer-swatch--choropleth {
    width: 10px;
    height: 10px;
    border-radius: 2px;
}

.mhm-layer-name {
    flex: 1;
    min-width: 0;
    font-size: 12px;
    font-weight: 500;
    color: var(--mhm-text);
    line-height: 1.25;
}

.mhm-layer-status {
    margin-left: 4px;
    font-size: 11px;
    font-weight: 700;
}

.mhm-layer-status--error {
    color: #c0392b;
}

.mhm-layer-status--loading {
    color: #999;
}

/* Toggle switch */

.mhm-layer-toggle {
    position: relative;
    flex-shrink: 0;
}

.mhm-layer-toggle input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.mhm-layer-toggle-track {
    position: relative;
    display: block;
    width: 30px;
    height: 17px;
    background: #d1d5db;
    border-radius: 9px;
    transition: background 0.2s ease;
    cursor: pointer;
}

.mhm-layer-toggle-track::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 13px;
    height: 13px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 2px rgba(5, 10, 40, 0.12);
    transition: transform 0.2s ease;
}

.mhm-layer-toggle input:checked + .mhm-layer-toggle-track {
    background: var(--mhm-accent);
}

.mhm-layer-toggle input:checked + .mhm-layer-toggle-track::after {
    transform: translateX(13px);
}

.mhm-layer-toggle input:focus-visible + .mhm-layer-toggle-track {
    outline: 2px solid var(--mhm-accent);
    outline-offset: 2px;
}

/* ── Footer ── */

.mhm-sidebar-footer {
    flex-shrink: 0;
    border-top: 1px solid var(--mhm-border-soft) !important;
    background: #fcfcfd !important;
}

.mhm-map-actions {
    display: flex;
    gap: 6px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--mhm-border-soft) !important;
}

.mhm-map-actions button {
    flex: 1;
    padding: 7px 6px !important;
    font-size: 11px !important;
    font-weight: 600 !important;
    letter-spacing: 0.01em;
    border: 1px solid var(--mhm-border) !important;
    background: var(--mhm-surface) !important;
    color: var(--mhm-text) !important;
    cursor: pointer;
    border-radius: var(--mhm-radius-sm) !important;
    box-shadow: none !important;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
    white-space: nowrap;
}

.mhm-map-actions button:hover {
    background: var(--mhm-cream) !important;
    border-color: rgba(5, 10, 40, 0.12) !important;
}

.mhm-show-all {
    background: var(--mhm-navy) !important;
    border-color: transparent !important;
    color: #fff !important;
    box-shadow: 0 2px 8px rgba(5, 10, 40, 0.12) !important;
}

.mhm-show-all:hover {
    background: var(--mhm-cream) !important;
    border-color: rgba(5, 10, 40, 0.12) !important;
    color: var(--mhm-text) !important;
    box-shadow: none !important;
}

.mhm-legend-wrap {
    padding: 0;
}

.mhm-legend-wrap.is-empty {
    display: none;
}

.mhm-legend {
    padding: 0;
}

.mhm-legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 10px;
    border-bottom: 1px solid var(--mhm-border-soft) !important;
}

.mhm-legend-item:last-child {
    border-bottom: none !important;
}

.mhm-legend-item.is-dimmed {
    opacity: 0.45;
}

.mhm-legend-item.is-dimmed .mhm-legend-bar {
    filter: grayscale( 0.35 );
}

.mhm-legend-title {
    flex-shrink: 0;
    width: 90px;
    font-size: 9px;
    font-weight: 600;
    color: var(--mhm-muted);
    line-height: 1.2;
}

.mhm-legend-bar {
    flex: 1;
    display: flex;
    height: 6px;
    overflow: hidden;
    border: 1px solid var(--mhm-border) !important;
    border-radius: var(--mhm-radius-sm) !important;
}

.mhm-legend-stop {
    flex: 1;
}

.mhm-legend-range {
    flex-shrink: 0;
    font-size: 9px;
    color: var(--mhm-muted);
    white-space: nowrap;
}

/* ── Popup ── */

.mhm-map-wrapper .mhm-map-popup.mapboxgl-popup {
    z-index: 7 !important;
    max-height: calc(100% - 40px);
    font-family: inherit;
}

.mhm-map-wrapper .mhm-map-popup .mapboxgl-popup-content {
    padding: 0 !important;
    margin: 0 !important;
    border-radius: var(--mhm-radius) !important;
    box-shadow: 0 12px 40px rgba(5, 10, 40, 0.14) !important;
    overflow: hidden !important;
    border: 1px solid var(--mhm-border) !important;
    background: var(--mhm-surface) !important;
    color: var(--mhm-text) !important;
    font-family: inherit !important;
    font-size: 13px !important;
    line-height: 1.45 !important;
    max-height: min(320px, calc(100vh - 120px));
}

.mhm-map-wrapper .mhm-map-popup .mapboxgl-popup-close-button {
    font-size: 18px !important;
    font-weight: 400 !important;
    line-height: 1 !important;
    color: var(--mhm-muted) !important;
    padding: 6px 10px !important;
    margin: 0 !important;
    z-index: 2;
    background: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    min-height: 0 !important;
    width: auto !important;
    height: auto !important;
    transition: color 0.15s ease;
    appearance: none;
}

.mhm-map-wrapper .mhm-map-popup .mapboxgl-popup-close-button:hover,
.mhm-map-wrapper .mhm-map-popup .mapboxgl-popup-close-button:focus {
    background: transparent !important;
    color: var(--mhm-navy) !important;
    border: none !important;
    box-shadow: none !important;
    outline: none !important;
}

.mhm-map-wrapper .mhm-map-popup .mapboxgl-popup-tip {
    border-top-color: var(--mhm-surface) !important;
}

.mhm-map-wrapper .mhm-map-popup.mapboxgl-popup-anchor-bottom .mapboxgl-popup-tip {
    border-bottom-color: var(--mhm-surface) !important;
    border-top-color: transparent !important;
}

.mhm-map-wrapper .mhm-map-popup.mapboxgl-popup-anchor-left .mapboxgl-popup-tip {
    border-right-color: var(--mhm-surface) !important;
    border-top-color: transparent !important;
}

.mhm-map-wrapper .mhm-map-popup.mapboxgl-popup-anchor-right .mapboxgl-popup-tip {
    border-left-color: var(--mhm-surface) !important;
    border-top-color: transparent !important;
}

.mhm-map-wrapper .mhm-map-popup .mhm-popup-inner {
    position: relative;
    display: flex !important;
    min-width: 260px;
    max-width: 340px;
    margin: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
}

.mhm-map-wrapper .mhm-map-popup .mhm-popup-accent {
    width: 4px;
    flex-shrink: 0;
    background: var(--mhm-accent, #2a9d8f) !important;
    border: none !important;
    margin: 0 !important;
    padding: 0 !important;
}

.mhm-map-wrapper .mhm-map-popup .mhm-popup-content {
    flex: 1;
    padding: 14px 16px 16px !important;
    margin: 0 !important;
    max-height: min(280px, calc(100vh - 160px));
    overflow-y: auto;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
}

.mhm-map-wrapper .mhm-map-popup .mhm-popup-badge {
    display: inline-block !important;
    font-size: 9px !important;
    font-weight: 700 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.06em !important;
    color: var(--mhm-accent) !important;
    background: rgba(42, 157, 143, 0.1) !important;
    padding: 3px 7px !important;
    margin: 0 0 6px !important;
    border: none !important;
    border-radius: 999px !important;
    line-height: 1.3 !important;
}

.mhm-map-wrapper .mhm-map-popup .mhm-popup-title,
.mhm-map-wrapper .mhm-map-popup h4.mhm-popup-title {
    margin: 0 0 12px !important;
    padding: 0 16px 0 0 !important;
    font-size: 15px !important;
    font-weight: 700 !important;
    font-family: inherit !important;
    color: var(--mhm-navy) !important;
    line-height: 1.35 !important;
    letter-spacing: normal !important;
    text-transform: none !important;
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
}

.mhm-map-wrapper .mhm-map-popup .mhm-popup-rows {
    display: flex !important;
    flex-direction: column !important;
    gap: 8px;
    margin: 0 !important;
    padding: 0 !important;
}

.mhm-map-wrapper .mhm-map-popup .mhm-popup-row {
    display: flex !important;
    flex-direction: column !important;
    gap: 2px;
    padding: 0 0 8px !important;
    margin: 0 !important;
    border-bottom: 1px solid var(--mhm-border-soft) !important;
    background: transparent !important;
}

.mhm-map-wrapper .mhm-map-popup .mhm-popup-row:last-child {
    border-bottom: none !important;
    padding-bottom: 0 !important;
}

.mhm-map-wrapper .mhm-map-popup .mhm-popup-label {
    display: block !important;
    font-size: 10px !important;
    font-weight: 700 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.04em !important;
    color: var(--mhm-muted) !important;
    margin: 0 !important;
    padding: 0 !important;
    line-height: 1.3 !important;
    border: none !important;
    background: transparent !important;
}

.mhm-map-wrapper .mhm-map-popup .mhm-popup-value {
    display: block !important;
    font-size: 13px !important;
    font-weight: 400 !important;
    color: var(--mhm-text) !important;
    line-height: 1.45 !important;
    word-break: break-word;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    background: transparent !important;
}

.mhm-map-wrapper .mhm-map-popup .mhm-popup-value a,
.mhm-map-wrapper .mhm-map-popup .mhm-popup-value a:link,
.mhm-map-wrapper .mhm-map-popup .mhm-popup-value a:visited {
    color: var(--mhm-accent) !important;
    font-weight: 600 !important;
    text-decoration: none !important;
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
}

.mhm-map-wrapper .mhm-map-popup .mhm-popup-value a:hover,
.mhm-map-wrapper .mhm-map-popup .mhm-popup-value a:focus {
    color: var(--mhm-accent) !important;
    text-decoration: underline !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    outline: none !important;
}

.mhm-map-wrapper .mhm-map-popup .mhm-popup-fallback,
.mhm-map-wrapper .mhm-map-popup p.mhm-popup-fallback {
    margin: 0 !important;
    padding: 0 !important;
    font-size: 13px !important;
    font-weight: 400 !important;
    font-family: inherit !important;
    color: var(--mhm-muted) !important;
    line-height: 1.5 !important;
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
}

/* ── Fullscreen ── */

.mhm-map-wrapper:fullscreen,
.mhm-map-wrapper:-webkit-full-screen {
    width: 100vw;
    height: 100vh;
}

.mhm-map-wrapper:fullscreen .mhm-map-sidebar,
.mhm-map-wrapper:-webkit-full-screen .mhm-map-sidebar {
    height: calc(100% - 28px);
}

/* ── Mobile ── */

@media (max-width: 640px) {
    .mhm-map-sidebar {
        width: calc(100% - 28px);
        height: min(70%, calc(100% - 28px));
        max-height: none;
        bottom: 14px;
        top: auto;
    }

    .mhm-layer-groups {
        max-height: none;
    }

    .mhm-map-wrapper.is-collapsed .mhm-map-sidebar {
        transform: translateY(calc(100% + 20px));
    }

    .mhm-map-toolbar {
        top: 10px;
        right: 10px;
    }

    .mhm-toggle-label {
        display: none;
    }

    .mhm-sidebar-toggle {
        padding: 0 !important;
        width: 36px;
    }
}
