:root {
    --header-height: 64px;
    --sidebar-width: 330px;
    --details-width: 360px;
    --surface: #ffffff;
    --background: #edf1f3;
    --text: #17202a;
    --muted: #68727d;
    --border: #dce2e7;
    --primary: #176b55;
    --shadow: 0 10px 30px rgba(22, 32, 42, 0.15);
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
}

body {
    font-family: Arial, Helvetica, sans-serif;
    color: var(--text);
    background: var(--background);
}

button,
input {
    font: inherit;
}

a {
    color: var(--primary);
}

.map-app {
    height: 100vh;
    display: grid;
    grid-template:
        "header header" var(--header-height)
        "sidebar map" 1fr
        / var(--sidebar-width) 1fr;
    overflow: hidden;
}

.map-header {
    grid-area: header;
    z-index: 1001;
    padding: 0 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.map-header > div {
    display: grid;
    gap: 2px;
}

.map-header strong {
    font-size: 1.15rem;
}

.map-header span {
    color: var(--muted);
    font-size: 0.82rem;
}

.map-header nav a {
    font-weight: 700;
    text-decoration: none;
}

.map-sidebar {
    grid-area: sidebar;
    z-index: 900;
    padding: 22px;
    overflow-y: auto;
    background: var(--surface);
    border-right: 1px solid var(--border);
}

.sidebar-heading,
.section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.sidebar-heading h1 {
    margin: 0;
    font-size: 1.25rem;
}

.map-sidebar section {
    margin-top: 24px;
}

.map-sidebar h2 {
    margin: 0;
    font-size: 0.95rem;
}

.section-title button {
    padding: 0;
    border: 0;
    color: var(--primary);
    background: transparent;
    cursor: pointer;
}

.search-field {
    margin-top: 20px;
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 700;
}

.search-field input {
    width: 100%;
    padding: 12px 13px;
    border: 1px solid var(--border);
    border-radius: 8px;
    outline: none;
}

.search-field input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(23, 107, 85, 0.12);
}

.category-filters {
    margin-top: 12px;
    display: grid;
    gap: 5px;
}

.category-filter {
    --category-color: #176b55;
    min-height: 42px;
    padding: 8px;
    display: grid;
    grid-template-columns: auto auto 1fr auto;
    align-items: center;
    gap: 9px;
    border: 1px solid transparent;
    border-radius: 7px;
    cursor: pointer;
    opacity: 0.58;
}

.category-filter.is-active {
    opacity: 1;
    border-color: color-mix(
        in srgb,
        var(--category-color) 30%,
        transparent
    );
    background: color-mix(
        in srgb,
        var(--category-color) 8%,
        transparent
    );
}

.category-filter:hover {
    background: #f3f6f7;
}

.category-dot,
.legend-color,
.search-result-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--category-color);
    box-shadow: 0 0 0 3px color-mix(
        in srgb,
        var(--category-color) 18%,
        transparent
    );
}

.category-name {
    font-size: 0.91rem;
}

.category-count {
    min-width: 28px;
    padding: 3px 7px;
    border-radius: 999px;
    color: var(--muted);
    background: #edf1f3;
    font-size: 0.76rem;
    text-align: center;
}

.map-legend {
    margin-top: 12px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px 12px;
}

.legend-item {
    --category-color: #176b55;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    color: var(--muted);
    font-size: 0.78rem;
}

.legend-item span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.search-results {
    margin-top: 12px;
    display: grid;
    gap: 7px;
}

.search-result {
    --result-color: #176b55;
    width: 100%;
    padding: 10px;
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 9px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--surface);
    text-align: left;
    cursor: pointer;
}

.search-result:hover {
    border-color: var(--result-color);
}

.search-result-dot {
    --category-color: var(--result-color);
}

.search-result strong,
.search-result small {
    display: block;
}

.search-result strong {
    font-size: 0.86rem;
}

.search-result small,
.muted {
    color: var(--muted);
    font-size: 0.78rem;
}

.map-main {
    grid-area: map;
    position: relative;
    min-width: 0;
    min-height: 0;
}

#map,
.leaflet-container {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #dfe6ec;
}

.leaflet-container img,
.leaflet-pane img,
.leaflet-tile {
    max-width: none !important;
    max-height: none !important;
}

.map-status {
    position: absolute;
    z-index: 700;
    right: 12px;
    bottom: 12px;
    padding: 8px 11px;
    border-radius: 6px;
    color: var(--muted);
    background: rgba(255, 255, 255, 0.94);
    box-shadow: var(--shadow);
    font-size: 0.78rem;
}

.map-status.is-error {
    color: #b42318;
}

.map-floating-button {
    position: absolute;
    z-index: 700;
    top: 12px;
    left: 12px;
    padding: 9px 12px;
    border: 0;
    border-radius: 7px;
    color: #ffffff;
    background: var(--primary);
    box-shadow: var(--shadow);
    cursor: pointer;
}

.reset-button {
    top: auto;
    right: 12px;
    bottom: 48px;
    left: auto;
}

.details-panel {
    position: fixed;
    z-index: 1100;
    top: var(--header-height);
    right: 0;
    bottom: 0;
    width: min(var(--details-width), 100%);
    padding: 28px;
    overflow-y: auto;
    background: var(--surface);
    box-shadow: var(--shadow);
    transform: translateX(105%);
    transition: transform 180ms ease;
}

.details-panel.is-open {
    transform: translateX(0);
}

.details-close,
.icon-button {
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
}

.details-close {
    position: absolute;
    top: 15px;
    right: 18px;
    font-size: 1.8rem;
}

.details-category {
    display: inline-flex;
    margin-bottom: 14px;
    padding: 5px 9px;
    border-radius: 999px;
    color: #ffffff;
    background: var(--category-color);
    font-size: 0.75rem;
    font-weight: 700;
}

.details-panel h2 {
    margin: 0 0 18px;
    padding-right: 22px;
}

.details-panel p,
.details-description {
    line-height: 1.55;
}

.details-description {
    margin-bottom: 18px;
    white-space: pre-line;
}

.details-action {
    display: inline-flex;
    margin-top: 12px;
    padding: 10px 14px;
    border-radius: 7px;
    color: #ffffff;
    background: var(--primary);
    text-decoration: none;
}

.details-photo {
    width: 100%;
    max-height: 240px;
    margin: 0 0 16px;
    object-fit: cover;
    border-radius: 10px;
}

.category-marker-wrapper,
.clep-cluster-wrapper {
    background: transparent;
    border: 0;
}

.category-marker {
    display: block;
    width: 22px;
    height: 22px;
    background: var(--marker-color);
    border: 3px solid #ffffff;
    box-shadow:
        0 0 0 2px var(--marker-color),
        0 4px 10px rgba(0, 0, 0, 0.28);
    transition:
        transform 0.15s ease,
        box-shadow 0.15s ease;
}

.category-marker-circle {
    border-radius: 50%;
}

.category-marker-square {
    border-radius: 4px;
}

.category-marker-diamond {
    border-radius: 4px;
    transform: rotate(45deg);
}

.category-marker-pin {
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
}

.category-marker.is-selected {
    transform: scale(1.35);
    box-shadow:
        0 0 0 4px rgba(255, 255, 255, 0.95),
        0 0 0 7px var(--marker-color),
        0 6px 16px rgba(0, 0, 0, 0.38);
}

.category-marker-diamond.is-selected {
    transform: rotate(45deg) scale(1.35);
}

.category-marker-pin.is-selected {
    transform: rotate(-45deg) scale(1.35);
}

.clep-cluster {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border: 4px solid #ffffff;
    border-radius: 50%;
    color: #ffffff;
    background: var(--cluster-color);
    box-shadow:
        0 0 0 3px var(--cluster-color),
        0 5px 14px rgba(0, 0, 0, 0.3);
    font-size: 0.82rem;
    font-weight: 700;
}

.mobile-only {
    display: none;
}

@media (max-width: 760px) {
    .map-app {
        grid-template:
            "header" var(--header-height)
            "map" 1fr
            / 1fr;
    }

    .map-header {
        padding: 0 15px;
    }

    .map-sidebar {
        position: fixed;
        z-index: 1200;
        top: var(--header-height);
        bottom: 0;
        left: 0;
        width: min(340px, 92vw);
        transform: translateX(-105%);
        transition: transform 180ms ease;
        box-shadow: var(--shadow);
    }

    .map-sidebar.is-open {
        transform: translateX(0);
    }

    .mobile-only {
        display: inline-flex;
    }

    .reset-button {
        bottom: 52px;
    }

    .details-panel {
        top: var(--header-height);
        width: 100%;
    }

    .map-legend {
        grid-template-columns: 1fr;
    }
}

/* Quartiers séparés V3.1 */
.district-filters {
    margin-top: 12px;
    display: grid;
    gap: 5px;
}

.district-filter {
    --district-color: #607D8B;
    min-height: 40px;
    padding: 8px;
    display: grid;
    grid-template-columns: auto auto 1fr;
    align-items: center;
    gap: 9px;
    border: 1px solid transparent;
    border-radius: 7px;
    cursor: pointer;
    opacity: .58;
}

.district-filter.is-active {
    opacity: 1;
    border-color: color-mix(
        in srgb,
        var(--district-color) 34%,
        transparent
    );
    background: color-mix(
        in srgb,
        var(--district-color) 9%,
        transparent
    );
}

.district-filter:hover {
    background: #f3f6f7;
}

.district-dot {
    width: 14px;
    height: 14px;
    border-radius: 4px;
    background: var(--district-color);
    box-shadow:
        0 0 0 2px #fff,
        0 0 0 3px var(--district-color);
}

.district-name {
    font-size: .91rem;
}

/* V6.4.11 — onglets du panneau cartographique */
.sidebar-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin: 0 0 16px;
    padding: 4px;
    border: 1px solid var(--border-color, #d9e0dd);
    border-radius: 10px;
    background: rgba(0, 0, 0, .035);
}
.sidebar-tab {
    width: 100%;
    padding: 9px 12px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
.sidebar-tab.is-active {
    background: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .12);
}
.sidebar-tab-panel[hidden] { display: none !important; }
