/* ==========================================================
   Zones de production agricole · Aaprovidir · disposition v2
   La carte occupe tout l'écran ; filières et détails flottent dessus.
   ========================================================== */

:root {
    /* Couleurs de marque (inchangées) */
    --blue: #3B65B3;
    --blue-map: #4267B2;
    --blue-dark: #365899;
    --green: #4CAF50;
    --green-dark: #3B8E3F;
    --bg: #F6F5F8;

    /* Dérivées */
    --blue-soft: #E8EEF9;
    --green-soft: #E7F4E8;
    --amber-soft: #FFF4DE;
    --amber-ink: #8A5A00;
    --region-absent: #ECEDF3;
    --region-missing: #DCDBE3;
    --ink: #1F2636;
    --muted: #626A7D;
    --line: #E4E2EA;
    --white: #FFFFFF;
    --glass: rgba(255, 255, 255, 0.94);

    /* Formes */
    --radius-lg: 20px;
    --radius-md: 14px;
    --radius-sm: 8px;
    --shadow-float: 0 2px 4px rgba(31, 38, 54, 0.04), 0 12px 32px rgba(31, 38, 54, 0.10);

    /* Dimensions des éléments flottants (ordinateur) */
    --gap: 16px;
    --rail-w: 210px;
    --sheet-w: 380px;
    --sheet-peek: 200px;

    --font: "Parkinsans", system-ui, -apple-system, "Segoe UI", sans-serif;
}

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

[hidden] {
    display: none !important;
}

html,
body {
    height: 100%;
}

body {
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--bg);
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

img,
svg {
    display: block;
    max-width: 100%;
}

button,
input {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
}

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

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 2px;
}

/* ==========================================================
   Barre d'application
   ========================================================== */
.appbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 24px;
    padding: 10px 24px;
    background: var(--white);
    border-bottom: 1px solid var(--line);
    position: relative;
    z-index: 30;
}

.appbar__logo img {
    width: 150px;
    height: auto;
}

.appbar__cta {
    background: var(--blue);
    color: var(--white);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    padding: 10px 20px;
    border-radius: 999px;
    white-space: nowrap;
    transition: background-color 0.2s ease;
}

.appbar__cta:hover {
    background: var(--blue-dark);
}

/* Recherche centrée */
.search {
    position: relative;
    width: 100%;
    max-width: 560px;
    justify-self: center;
}

.search__icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    pointer-events: none;
}

.search__input {
    width: 100%;
    border: 1px solid var(--line);
    background: var(--bg);
    border-radius: 999px;
    padding: 11px 18px 11px 46px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

.search__input:focus {
    background: var(--white);
    border-color: var(--blue);
}

.search__input::placeholder {
    color: #8D93A1;
}

.search__list {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    z-index: 40;
    list-style: none;
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-float);
    max-height: 320px;
    overflow-y: auto;
    padding: 6px;
}

.search__item {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
}

.search__item small {
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}

.search__item:hover,
.search__item.is-highlighted {
    background: var(--blue-soft);
}

.search__empty {
    padding: 10px 12px;
    font-size: 13px;
    color: var(--muted);
}

/* ==========================================================
   Scène : la carte en fond, les panneaux par-dessus
   ========================================================== */
.stage {
    position: relative;
    min-height: 0;
    overflow: hidden;
}

/* ---------- Carte ---------- */
.map {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at 50% 40%, #FDFDFE 0%, var(--bg) 70%);
}

.map__canvas {
    position: absolute;
    inset: 0;
    /* Laisse de la place aux panneaux flottants pour que la carte ne soit jamais cachée */
    padding: 24px calc(var(--sheet-w) + var(--gap) * 3) 56px calc(var(--rail-w) + var(--gap) * 3);
    display: flex;
    justify-content: center;
    align-items: center;
}

.map__canvas > svg {
    width: 100%;
    height: 100%;
    max-width: none;
    overflow: visible;
}

.map__status {
    color: var(--muted);
    font-size: 14px;
}

/* Régions */
.region {
    stroke: var(--white);
    stroke-width: 1.5;
    stroke-linejoin: round;
    vector-effect: non-scaling-stroke;
    cursor: pointer;
    transition: fill 0.35s ease, filter 0.2s ease, stroke-width 0.2s ease;
    outline: none;
}

.region:hover {
    filter: brightness(0.92);
}

.region:focus-visible {
    stroke: var(--ink);
    stroke-width: 3;
}

.region.is-absent {
    fill: var(--region-absent);
}

.region.is-missing {
    fill: var(--region-missing);
}

/* Région sélectionnée : contour vert, la couleur de la donnée reste visible */
.region.is-active,
.region.is-active:hover {
    stroke: var(--green);
    stroke-width: 4;
    filter: drop-shadow(0 6px 10px rgba(31, 38, 54, 0.28));
}

/* Points scintillants */
.region-dot {
    fill: var(--white);
    stroke: rgba(31, 38, 54, 0.35);
    stroke-width: 1;
    vector-effect: non-scaling-stroke;
    pointer-events: none;
    filter: drop-shadow(0 0 3px rgba(255, 255, 255, 0.9));
    transform-box: fill-box;
    transform-origin: center;
    animation: twinkle 2.4s ease-in-out infinite;
}

.region-dot.is-active {
    stroke: var(--green-dark);
    stroke-width: 2;
    animation: pulse-active 1.6s ease-in-out infinite;
}

@keyframes twinkle {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.35; transform: scale(0.6); }
}

@keyframes pulse-active {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.8); }
}

/* Noms des régions écrits sur la carte */
.region-label {
    font-family: var(--font);
    font-weight: 600;
    text-anchor: middle;
    dominant-baseline: hanging;
    pointer-events: none;
    paint-order: stroke;
    stroke-linejoin: round;
    transition: fill 0.35s ease;
}

.region-label--dark {
    fill: var(--ink);
    stroke: rgba(255, 255, 255, 0.8);
}

.region-label--light {
    fill: var(--white);
    stroke: rgba(20, 35, 70, 0.35);
}

/* Infobulle */
.tooltip {
    position: absolute;
    z-index: 25;
    pointer-events: none;
    background: var(--ink);
    color: var(--white);
    font-size: 13px;
    padding: 7px 11px;
    border-radius: var(--radius-sm);
    transform: translate(-50%, calc(-100% - 14px));
    white-space: nowrap;
}

.tooltip small {
    display: block;
    opacity: 0.75;
    font-size: 12px;
}

/* Légende (échelle) */
.scale {
    position: absolute;
    z-index: 10;
    left: calc(var(--rail-w) + var(--gap) * 2);
    bottom: var(--gap);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 18px;
    background: var(--glass);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-float);
    padding: 10px 14px;
    font-size: 12px;
    color: var(--muted);
    max-width: calc(100% - var(--rail-w) - var(--sheet-w) - var(--gap) * 5);
}

.scale:empty {
    display: none;
}

.scale__gradient {
    display: grid;
    grid-template-columns: auto 140px auto;
    align-items: center;
    gap: 8px;
}

.scale__bar {
    height: 8px;
    border-radius: 999px;
}

.scale__item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.scale__swatch {
    width: 14px;
    height: 14px;
    border-radius: 4px;
    flex-shrink: 0;
}

.scale__swatch--absent {
    background: var(--region-absent);
    border: 1px solid var(--line);
}

.scale__swatch--missing {
    background: var(--region-missing);
}

.scale__swatch--hatch {
    background: repeating-linear-gradient(45deg, var(--blue-map) 0 2px, var(--blue-soft) 2px 6px);
}

.scale__swatch--active {
    background: var(--white);
    border: 3px solid var(--green);
}

/* ==========================================================
   Rail des filières
   ========================================================== */
.filieres {
    position: absolute;
    z-index: 10;
    top: var(--gap);
    left: var(--gap);
    width: var(--rail-w);
    background: var(--glass);
    backdrop-filter: blur(8px);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-float);
    padding: 16px 10px 10px;
}

.filieres__title {
    font-size: 13px;
    font-weight: 500;
    color: var(--muted);
    padding: 0 10px 8px;
}

.filieres__list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.filiere {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 1px;
    text-align: left;
    background: none;
    border: 0;
    border-radius: var(--radius-sm);
    padding: 9px 10px;
    min-height: 44px;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.filiere:hover {
    background: var(--blue-soft);
}

.filiere__name {
    font-size: 14px;
    font-weight: 500;
    line-height: 1.3;
}

.filiere__value {
    font-size: 12px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.filiere[aria-pressed="true"] {
    background: var(--blue);
    color: var(--white);
}

.filiere[aria-pressed="true"] .filiere__value {
    color: rgba(255, 255, 255, 0.8);
}

/* ==========================================================
   Panneau contextuel
   ========================================================== */
.sheet {
    position: absolute;
    z-index: 20;
    top: var(--gap);
    right: var(--gap);
    bottom: var(--gap);
    width: var(--sheet-w);
    background: var(--white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-float);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sheet__handle {
    display: none;
}

.sheet__body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 22px 22px 24px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    scrollbar-width: thin;
    scrollbar-color: var(--line) transparent;
}

.sheet__status {
    color: var(--muted);
    font-size: 14px;
}

.sheet__status--error {
    color: #A12C2C;
}

/* En-tête du panneau */
.head__back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: 0;
    color: var(--blue);
    font-size: 13px;
    font-weight: 500;
    padding: 4px 0;
    margin-bottom: 6px;
}

.head__back:hover {
    color: var(--blue-dark);
}

.head__title {
    font-size: 24px;
    font-weight: 600;
    line-height: 1.2;
}

.head__sub {
    font-size: 13px;
    color: var(--muted);
    margin-top: 2px;
}

.total {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 4px 10px;
    padding: 14px 16px;
    background: var(--blue-soft);
    border-radius: var(--radius-md);
}

.total__value {
    font-size: 26px;
    font-weight: 600;
    color: var(--blue);
    font-variant-numeric: tabular-nums;
}

.total__label {
    font-size: 13px;
    color: var(--muted);
}

/* Badges de fiabilité */
.badge {
    display: inline-block;
    font-size: 11.5px;
    font-weight: 500;
    padding: 3px 10px;
    border-radius: 999px;
    white-space: nowrap;
}

.badge--officiel {
    background: var(--green-soft);
    color: var(--green-dark);
}

.badge--national {
    background: var(--blue-soft);
    color: var(--blue);
}

.badge--a_completer {
    background: var(--amber-soft);
    color: var(--amber-ink);
}

/* Blocs */
.block__title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
}

/* Bloc de la filière dans la fiche région */
.block__head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 10px;
}

.block__head .block__title,
.block__head .head__sub {
    margin: 0;
}

.filiere-block {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Classement en barres */
.ranking {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.rank {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 4px 12px;
    background: none;
    border: 0;
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    margin: 0 -10px;
    width: calc(100% + 20px);
    text-align: left;
    transition: background-color 0.15s ease;
}

.rank:hover {
    background: var(--bg);
}

.rank__name {
    font-size: 14px;
    font-weight: 500;
}

.rank__value {
    font-size: 13px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.rank__track {
    grid-column: 1 / -1;
    height: 8px;
    background: var(--bg);
    border-radius: 999px;
    overflow: hidden;
}

.rank__bar {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: var(--blue-map);
    transition: width 0.4s ease;
}

/* Bassin sans répartition régionale */
.bassin {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    list-style: none;
}

.bassin button {
    border: 1px solid var(--line);
    background: var(--white);
    border-radius: 999px;
    padding: 6px 14px;
    font-size: 13px;
    transition: border-color 0.15s ease, color 0.15s ease;
}

.bassin button:hover {
    border-color: var(--blue-map);
    color: var(--blue);
}

/* Statistiques */
.stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.stat {
    padding: 12px 14px;
    border-right: 1px solid var(--line);
}

.stat:last-child {
    border-right: 0;
}

.stat dt {
    font-size: 12px;
    color: var(--muted);
}

.stat dd {
    font-size: 17px;
    font-weight: 500;
    margin-top: 2px;
    font-variant-numeric: tabular-nums;
    line-height: 1.25;
}

.stat dd.is-empty {
    font-size: 13px;
    font-weight: 400;
    color: #9AA0AE;
    padding-top: 3px;
}

.note {
    font-size: 13px;
    color: var(--muted);
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
}

.source {
    font-size: 12.5px;
    color: var(--muted);
}

.varieties {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    list-style: none;
}

.varieties li {
    font-size: 13px;
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 4px 10px;
}

/* Autres cultures de la région */
.crops {
    list-style: none;
}

.crop {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
    font-size: 14px;
}

.crops li:last-child .crop {
    border-bottom: 0;
}

button.crop {
    width: 100%;
    background: none;
    border-left: 0;
    border-right: 0;
    border-top: 0;
    text-align: left;
}

button.crop:hover .crop__name {
    color: var(--blue);
}

.crop.is-highlighted .crop__name {
    color: var(--blue);
    font-weight: 600;
}

.crop__meta {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.empty {
    font-size: 14px;
    color: var(--muted);
}

/* ==========================================================
   Barre d'état
   ========================================================== */
.statusbar {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 8px 24px;
    font-size: 12px;
    color: var(--muted);
    background: var(--white);
    border-top: 1px solid var(--line);
}

/* ==========================================================
   Écrans moyens : panneaux plus étroits
   ========================================================== */
@media (max-width: 1200px) {
    :root {
        --rail-w: 180px;
        --sheet-w: 340px;
    }

    .scale__gradient {
        grid-template-columns: auto 100px auto;
    }
}

/* ==========================================================
   Tablette et mobile : pastilles en haut, panneau glissant en bas
   ========================================================== */
@media (max-width: 960px) {
    :root {
        --gap: 12px;
    }

    body {
        font-size: 14px;
    }

    .appbar {
        grid-template-columns: auto auto;
        grid-template-areas:
            "logo cta"
            "search search";
        justify-content: space-between;
        gap: 10px 12px;
        padding: 10px 14px 12px;
    }

    .appbar__logo { grid-area: logo; }
    .appbar__cta { grid-area: cta; padding: 8px 14px; font-size: 13px; }
    .search { grid-area: search; max-width: none; }

    .appbar__logo img {
        width: 128px;
    }

    /* Filières en pastilles défilables horizontalement */
    .filieres {
        top: var(--gap);
        left: 0;
        right: 0;
        width: auto;
        background: none;
        backdrop-filter: none;
        box-shadow: none;
        padding: 0;
    }

    .filieres__title {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
    }

    .filieres__list {
        flex-direction: row;
        gap: 8px;
        overflow-x: auto;
        padding: 0 var(--gap) 4px;
        scrollbar-width: none;
    }

    .filieres__list::-webkit-scrollbar {
        display: none;
    }

    .filiere {
        flex-direction: row;
        align-items: center;
        gap: 8px;
        width: auto;
        white-space: nowrap;
        background: var(--glass);
        box-shadow: var(--shadow-float);
        border-radius: 999px;
        padding: 8px 14px;
    }

    .filiere__value {
        display: none;
    }

    .map__canvas {
        padding: 64px 12px calc(var(--sheet-peek) + 56px);
    }

    .scale {
        left: var(--gap);
        right: var(--gap);
        bottom: calc(var(--sheet-peek) + 10px);
        max-width: none;
        padding: 8px 12px;
        gap: 6px 14px;
    }

    /* Panneau glissant */
    .sheet {
        top: auto;
        left: 0;
        right: 0;
        bottom: 0;
        width: auto;
        height: var(--sheet-peek);
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        transition: height 0.3s ease;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .sheet[data-state="open"] {
        height: 64%;
    }

    .sheet__handle {
        display: block;
        flex-shrink: 0;
        width: 100%;
        height: 26px;
        background: none;
        border: 0;
        position: relative;
        touch-action: none;
    }

    .sheet__handle::before {
        content: "";
        position: absolute;
        left: 50%;
        top: 10px;
        width: 44px;
        height: 5px;
        border-radius: 999px;
        background: var(--line);
        transform: translateX(-50%);
    }

    .sheet__body {
        padding: 2px 18px 20px;
        gap: 16px;
    }

    .head__title {
        font-size: 21px;
    }

    .total__value {
        font-size: 22px;
    }

    .statusbar {
        display: none;
    }
}

@media (max-width: 400px) {
    .stats {
        grid-template-columns: 1fr 1fr;
    }

    .stat:nth-child(2) {
        border-right: 0;
    }

    .stat:nth-child(3) {
        grid-column: 1 / -1;
        border-top: 1px solid var(--line);
        border-right: 0;
    }

    .scale__gradient {
        grid-template-columns: auto 80px auto;
    }
}

/* Mouvements réduits */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition: none !important;
        animation: none !important;
    }
}