/* =========================================================
   DESIGN TOKENS
   Structure reprise du POC foncier pour une esthétique commune AULA.
   Palette adaptée au thème de l'eau : bleu profond, azur et turquoise.
   ========================================================= */

:root {
    --ink: #0f172a;
    --muted: #64748b;
    --muted-strong: #475569;
    --line: #e2e8f0;
    --card: #ffffff;
    --bg: #e5e7eb;
    --panel: #f8fafc;
    --night: #083344;
    --night-2: #164e63;
    --primary: #0369a1;
    --primary-2: #0e7490;
    --primary-soft: #e0f2fe;
    --accent: #67e8f9;
    --orange: #f97316;
    --blue: #0ea5e9;
    --green: #22c55e;
    --radius: 26px;
    --radius-sm: 16px;
    --shadow: 0 18px 46px rgba(15, 23, 42, .10);
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

button, select, input {
    font: inherit;
}

button {
    cursor: pointer;
}


/* =========================================================
   LAYOUT (page continue, comme le POC foncier)
   ========================================================= */

.page-layout {
    width: min(100%, 520px);
    min-height: 100vh;
    margin: 0 auto;
    background: var(--panel);
    box-shadow: 0 0 0 1px rgba(15, 23, 42, .06), 0 20px 80px rgba(15, 23, 42, .12);
    overflow: hidden;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}


/* =========================================================
   HEADER (hero) — couleur et forme des boutons conservées
   ========================================================= */

.hero {
    position: relative;
    padding: 18px 18px 76px;
    color: #fff;
    background:
        radial-gradient(circle at 86% 6%, rgba(103, 232, 249, .26), transparent 34%),
        linear-gradient(150deg, #062f3d 0%, #075985 56%, #0e7490 100%);
    overflow: hidden;
}

.hero::after {
    content: "";
    position: absolute;
    left: -15%;
    right: -15%;
    bottom: -42px;
    height: 92px;
    background: var(--panel);
    border-radius: 50% 50% 0 0 / 58% 58% 0 0;
    z-index: 1;
}

.hero-nav,
.hero-content {
    position: relative;
    z-index: 3;
}

.hero-nav {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
}

.back {
    color: rgba(255, 255, 255, .94);
    text-decoration: none;
    font-size: 13px;
    font-weight: 850;
    font-style: italic;
}

/* filtre territoire (select unique, remplace l'ancien bouton + dropdown) */

.territory {
    display: grid;
    gap: 6px;
    min-width: 148px;
}

.territory span {
    color: rgba(255, 255, 255, .74);
    font-size: 11px;
    font-weight: 950;
    text-transform: uppercase;
    letter-spacing: .08em;
}

.territory select {
    width: 100%;
    max-width: 170px;
    border: 1px solid rgba(255, 255, 255, .18);
    border-radius: 999px;
    padding: 11px 13px;
    background: rgba(255, 255, 255, .14);
    color: #fff;
    font-weight: 900;
    outline: none;
    backdrop-filter: blur(10px);
}

.territory option {
    color: #111827;
}

h1 {
    margin: 24px 0 0;
    color: #fff;
    font-size: clamp(32px, 9vw, 44px);
    line-height: .95;
    letter-spacing: -.05em;
}

.lead {
    margin: 12px 0 0;
    max-width: 30ch;
    color: rgba(255, 255, 255, .96);
    font-size: clamp(15px, 4vw, 17px);
    line-height: 1.4;
    font-weight: 600;
    text-wrap: balance;
}

.chapter-row {
    display: flex;
    gap: 10px;
    margin-top: 22px;
    padding: 2px 0 12px;
    overflow-x: auto;
    scrollbar-width: none;
}

.chapter-row::-webkit-scrollbar {
    display: none;
}

.chapter {
    flex: 0 0 auto;
    border: 1px solid rgba(255, 255, 255, .24);
    border-radius: 999px;
    padding: 10px 15px;
    background: rgba(255, 255, 255, .14);
    color: rgba(255, 255, 255, .96);
    font-size: 13px;
    font-weight: 950;
    white-space: nowrap;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .12);
    backdrop-filter: blur(8px);
}

.chapter.active {
    border-color: var(--accent);
    background: var(--accent);
    color: #111827;
}


/* =========================================================
   FILTRE DE PÉRIMÈTRE (2 boutons EPCI / Commune)
   ========================================================= */

.scope-strip {
    position: relative;
    z-index: 4;
    display: flex;
    align-items: center;
    gap: 8px;
    margin: -36px 18px 10px;
    padding: 8px;
    border: 1px solid rgba(226, 232, 240, .85);
    border-radius: 999px;
    background: rgba(255, 255, 255, .94);
    box-shadow: 0 12px 32px rgba(15, 23, 42, .08);
    overflow-x: auto;
}

.scope-btn {
    flex: 0 0 auto;
    border: 0;
    border-radius: 999px;
    padding: 9px 13px;
    background: transparent;
    color: var(--muted-strong);
    font-size: 13px;
    font-weight: 950;
}

.scope-btn.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 10px 24px rgba(3, 105, 161, .24);
}

.scope-strip p {
    min-width: 190px;
    margin: 0 6px 0 2px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.25;
    font-weight: 700;
}


/* =========================================================
   FIL NARRATIF
   ========================================================= */

.narrative-intro {
    padding: 12px 18px 4px;
}

.narrative-intro article {
    position: relative;
    overflow: hidden;
    padding: 16px 17px;
    border-radius: 26px;
    color: #fff;
    background: linear-gradient(135deg, #0369a1 0%, #083344 100%);
    box-shadow: 0 16px 42px rgba(15, 23, 42, .14);
}

.narrative-intro article::after {
    content: "";
    position: absolute;
    right: -30px;
    top: -40px;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .10);
}

.narrative-intro span {
    display: inline-flex;
    padding: 5px 9px;
    border-radius: 999px;
    color: #111827;
    background: var(--accent);
    font-size: 11px;
    font-weight: 950;
    text-transform: uppercase;
    letter-spacing: .06em;
}

.narrative-intro p {
    position: relative;
    z-index: 1;
    margin: 10px 0 0;
    color: rgba(255, 255, 255, .92);
    font-size: 14px;
    line-height: 1.45;
    font-weight: 720;
}


/* =========================================================
   SECTIONS (panels) — toutes visibles, page continue
   ========================================================= */

.panel {
    padding: 22px 18px 10px;
}

.section-heading {
    margin-bottom: 14px;
}

.section-heading span {
    color: var(--primary);
    font-size: 11px;
    font-weight: 950;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.section-heading h2 {
    margin: 4px 0 0;
    font-size: 21px;
    line-height: 1.15;
    letter-spacing: -.02em;
    color: var(--ink);
}


/* =========================================================
   TITRES DE QUESTION / SOURCES / ANNOTATIONS
   ========================================================= */

.panel h3 {
    color: var(--ink);
    font-size: 1rem;
    font-weight: 800;
    line-height: 1.3;
    margin: 22px 0 8px;
    letter-spacing: -.01em;
}

.source {
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 650;
    margin: 0 0 10px;
}

.annotation {
    color: var(--muted-strong);
    font-size: 0.85rem;
    font-weight: 650;
    margin: 0 0 10px;
}


/* =========================================================
   CARDS
   ========================================================= */

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.2rem;
    box-shadow: var(--shadow);
    width: 100%;
    position: relative;
}

.chart-card {
    height: 420px;
}

.chart-card-medium {
    height: 340px;
}

.chart-card-small {
    height: 260px;
}

.indicator {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.2rem;
    box-shadow: var(--shadow);
}

.indicator-block {
    text-align: center;
}


.table-image-container {
    width: 100%;
    overflow-x: auto;
    background-color: #f1f5f9;
    border-radius: var(--radius-sm);
}

.responsive-table-image {
    width: 100%;
    height: auto;
    image-rendering: -webkit-optimize-contrast;
}

@media (max-width: 768px) {
    .responsive-table-image {
        width: 100%;
    }
}


/* =========================================================
   CHARTJS
   ========================================================= */

.card canvas {
    width: 100%;
    height: 100%;
}

#chart-prix-repartition {
    overflow: visible;
}


/* =========================================================
   CARTES (LEAFLET)
   ========================================================= */

#map-captages,
#map-masses-eau,
#map-qualite-eco,
#map-step {
    width: 100%;
    height: 500px;
    border-radius: var(--radius-sm);
}

.cluster-blue {
    background-color: rgba(14, 165, 233, .48);
    border-radius: 50%;
}

.cluster-blue div {
    background-color: rgba(14, 165, 233, .88);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cluster-blue span {
    color: white;
    font-weight: bold;
}

.cluster-small div { background: var(--primary-soft); color: var(--primary); }
.cluster-medium div { background: var(--primary-2); }
.cluster-large div { background: var(--night-2); }

.map-legend {
    max-width: 190px;
    max-height: 150px;
    overflow-y: auto;
    background: rgba(255, 255, 255, .92);
    backdrop-filter: blur(6px);
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 650;
    line-height: 1.3;
    color: var(--muted-strong);
    box-shadow: 0 12px 26px rgba(15, 23, 42, .12);
}

.map-legend strong {
    display: block;
    margin-bottom: 4px;
    color: var(--ink);
    font-size: 10px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 0;
    transition: opacity .2s ease;
}

.legend-item[data-index] {
    cursor: pointer;
}

.legend-swatch {
    flex: 0 0 auto;
    display: inline-block;
}

.legend-swatch-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.legend-swatch-square {
    width: 11px;
    height: 11px;
    border-radius: 3px;
}

.legend-swatch-line {
    width: 16px;
    height: 3px;
    border-radius: 2px;
}


/* =========================================================
   KPI / CHIFFRES CLÉS
   ========================================================= */

/* Conteneur "nu" (pas de fond/ombre) pour les indicateurs composés
   uniquement de chiffres clés : évite la double boîte blanche qu'on
   aurait en les plaçant dans .card, puisque .kpi-card est déjà elle-
   même une carte blanche. Même logique que le POC foncier, où
   .kpi-grid est posé directement sur le panel plutôt que dans une
   carte englobante. */

.kpi-block {
    padding: 4px 0 6px;
}

.kpi-block p {
    margin: 10px 6px 0;
    text-align: center;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.4;
}

.kpi-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.kpi-card {
    flex: 0 1 176px;
    max-width: 200px;
    text-align: center;
    padding: 18px 16px;
    border-radius: var(--radius-sm);
    background: var(--card);
    border: 1px solid var(--line);
    box-shadow: 0 12px 28px rgba(15, 23, 42, .055);
}

.kpi-value {
    font-size: 1.75rem;
    font-weight: 950;
    letter-spacing: -.03em;
    color: var(--primary);
}

.kpi-percent {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--muted-strong);
}

.kpi-label {
    margin-top: 5px;
    font-size: 13px;
    font-weight: 700;
    color: var(--muted-strong);
}

.numbers {
    text-align: center;
}

.key-number {
    color: var(--primary);
    font-size: 2rem;
    font-weight: 900;
    letter-spacing: -.03em;
}


/* =========================================================
   RESPONSIVE
   ========================================================= */

@media (max-width: 768px) {
    .chart-card {
        height: 360px;
    }

    .chart-card-medium {
        height: 300px;
    }

    .chart-card-small {
        height: 160px;
    }
}
