:root {
  --blue: #0d5fb3;
  --blue-dark: #0a4a8c;
  --blue-soft: #e8f1fb;
  --orange: #f37a1f;
  --orange-dark: #d9650f;
  --orange-soft: #fef1e6;
  --land: #d8352a;
  --ink: #1c2b3a;
  --ink-soft: #52637a;
  --line: #e2e8f0;
  --card: #ffffff;
  --sea-1: #cfe8f8;
  --sea-2: #f1f8fd;
  --radius: 14px;
  --shadow: 0 8px 28px rgba(12, 52, 92, .12);
  --font: "Segoe UI", "Helvetica Neue", Roboto, Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: #eef4f9;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ------------------------------------------------------------------ */
/* Mise en page                                                        */
/* ------------------------------------------------------------------ */

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  height: 100vh;
  padding: 18px;
}

.map-panel {
  position: relative;
  min-height: 0;
  border-radius: var(--radius);
  overflow: hidden;
  background:
    radial-gradient(ellipse at 20% 35%, rgba(255, 255, 255, .75), transparent 55%),
    radial-gradient(ellipse at 85% 90%, rgba(255, 255, 255, .6), transparent 50%),
    linear-gradient(160deg, #9fd2f1 0%, var(--sea-1) 35%, var(--sea-2) 100%);
  box-shadow: var(--shadow);
}

.map-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='40'%3E%3Cpath d='M0 20c15 0 15-8 30-8s15 8 30 8 15-8 30-8 15 8 30 8' fill='none' stroke='%23ffffff' stroke-opacity='.35' stroke-width='1.2'/%3E%3C/svg%3E");
  opacity: .6;
  pointer-events: none;
}

/* ------------------------------------------------------------------ */
/* En-tête / légende                                                   */
/* ------------------------------------------------------------------ */

.brand {
  position: absolute;
  z-index: 3;
  top: 22px;
  left: 26px;
  padding-left: 14px;
  border-left: 3px solid var(--blue);
  pointer-events: none;
}

.brand__logo {
  margin: 0;
  font-size: 40px;
  line-height: 1;
  font-weight: 800;
  letter-spacing: .02em;
  color: var(--blue);
}

.brand__ar {
  margin: 6px 0 2px;
  font-size: 15px;
  font-weight: 600;
  color: var(--blue-dark);
  text-align: left;
}

.brand__fr {
  margin: 0;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--blue-dark);
}

.brand__bar {
  display: block;
  width: 230px;
  height: 3px;
  margin-top: 8px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--blue) 0 38%, #2eaa4a 38% 70%, #f6b319 70% 100%);
}

.legend {
  position: absolute;
  z-index: 3;
  top: 150px;
  left: 26px;
  display: grid;
  gap: 4px;
  padding: 10px;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(6px);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(12, 52, 92, .1);
}

.legend__item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  font-size: 13px;
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}

.legend__item:hover { background: rgba(13, 95, 179, .07); }
.legend__item[aria-pressed="false"] { opacity: .45; }
.legend__item[aria-pressed="false"] .legend__dot { background: #b8c2cc; box-shadow: none; }

.legend__dot {
  flex: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .08), 0 2px 5px rgba(0, 0, 0, .2);
}

.legend__dot--dessalement { background: var(--blue); }
.legend__dot--traitement { background: var(--orange); }

/* ------------------------------------------------------------------ */
/* Carte                                                               */
/* ------------------------------------------------------------------ */

.map {
  position: absolute;
  inset: 0;
  touch-action: none;
  user-select: none;
}

.map__svg {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}

.map.is-dragging .map__svg { cursor: grabbing; }

.region {
  fill: url(#land-gradient);
  transition: filter .2s;
}

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

.land-outline {
  fill: none;
  stroke: #9e1d17;
  stroke-width: 1.4;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.land-shadow {
  fill: #c62f25;
  filter: url(#land-shadow);
}

.region-borders {
  fill: none;
  stroke: rgba(255, 214, 205, .7);
  stroke-width: 1;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.sea-labels text {
  fill: #2a7ab8;
  font-size: 19px;
  font-style: italic;
  letter-spacing: .28em;
  pointer-events: none;
}

.leaders line {
  stroke: var(--blue);
  stroke-width: 1.3;
  opacity: .85;
}

.leaders line.is-traitement { stroke: var(--orange); }

/* Marqueurs */
.marker {
  cursor: pointer;
  outline: none;
}

.marker__halo {
  fill: currentColor;
  opacity: 0;
  transform-box: fill-box;
  transform-origin: center;
}

.marker__dot {
  fill: currentColor;
  stroke: #fff;
  stroke-width: 3;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .3));
  transform-box: fill-box;
  transform-origin: center;
  transition: transform .15s;
}

.marker--dessalement { color: var(--blue); }
.marker--traitement { color: var(--orange); }

.marker:hover .marker__dot,
.marker:focus-visible .marker__dot,
.marker.is-hover .marker__dot,
.marker.is-active .marker__dot { transform: scale(1.35); }

.marker.is-hover .marker__halo,
.marker:hover .marker__halo,
.marker:focus-visible .marker__halo,
.marker.is-active .marker__halo {
  animation: pulse 1.4s ease-out infinite;
}

@keyframes pulse {
  from { opacity: .45; transform: scale(1); }
  to { opacity: 0; transform: scale(2.6); }
}

.is-filtered { display: none; }

/* Étiquettes */
.label {
  cursor: pointer;
}

.label__box {
  fill: #fff;
  stroke: rgba(13, 95, 179, .35);
  stroke-width: 1;
  filter: url(#label-shadow);
  transition: stroke .15s;
}

.label--traitement .label__box { stroke: rgba(243, 122, 31, .45); }

.label__name {
  font-size: 14px;
  font-weight: 700;
  fill: var(--ink);
}

.label__sub {
  font-size: 11px;
  fill: var(--ink-soft);
}

.label:hover .label__box,
.label.is-hover .label__box,
.label.is-active .label__box { stroke: var(--blue); stroke-width: 2; }

.label--traitement:hover .label__box,
.label--traitement.is-hover .label__box,
.label--traitement.is-active .label__box { stroke: var(--orange); }

.map__tooltip {
  position: absolute;
  z-index: 4;
  padding: 5px 10px;
  border-radius: 6px;
  background: rgba(28, 43, 58, .9);
  color: #fff;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, calc(-100% - 12px));
  transition: opacity .12s;
}

.map__tooltip.is-visible { opacity: 1; }

.map__controls {
  position: absolute;
  z-index: 3;
  right: 18px;
  top: 18px;
  display: grid;
  gap: 6px;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: #fff;
  color: var(--blue);
  box-shadow: 0 3px 10px rgba(12, 52, 92, .15);
  cursor: pointer;
  transition: background .15s, color .15s;
}

.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { background: var(--blue); color: #fff; }
.icon-btn:focus-visible, .legend__item:focus-visible, .station-list button:focus-visible, .nav-btn:focus-visible {
  outline: 3px solid rgba(13, 95, 179, .45);
  outline-offset: 2px;
}

.icon-btn--ghost { background: rgba(255, 255, 255, .15); color: #fff; box-shadow: none; }
.icon-btn--ghost:hover { background: rgba(255, 255, 255, .3); color: #fff; }

.map__scale {
  position: absolute;
  z-index: 3;
  right: 24px;
  bottom: 22px;
  display: flex;
  align-items: flex-end;
  gap: 18px;
  pointer-events: none;
}

.map__north { width: 16px; height: 22px; }

.map__north-label {
  position: absolute;
  left: 4px;
  top: -16px;
  font-size: 11px;
  font-weight: 700;
}

.scalebar { font-size: 11px; color: var(--ink); }

.scalebar__bar {
  height: 6px;
  border: 1.5px solid var(--ink);
  border-top: 0;
}

.scalebar__ticks {
  position: relative;
  height: 14px;
  margin-top: 3px;
}

.scalebar__ticks span {
  position: absolute;
  transform: translateX(-50%);
  white-space: nowrap;
}

.map__hint {
  position: absolute;
  z-index: 3;
  left: 26px;
  bottom: 18px;
  margin: 0;
  padding: 6px 12px;
  border-radius: 20px;
  background: rgba(255, 255, 255, .8);
  font-size: 12px;
  color: var(--ink-soft);
  pointer-events: none;
}

/* ------------------------------------------------------------------ */
/* Colonne latérale                                                    */
/* ------------------------------------------------------------------ */

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
  scrollbar-width: thin;
}

.card {
  flex: none;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card__head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  padding: 11px 16px;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.25;
}

.card__head small { display: block; font-size: 13px; font-weight: 500; opacity: .9; }
.card__icon { flex: none; width: 30px; height: 30px; }
.card--dessalement .card__head { background: linear-gradient(120deg, var(--blue), var(--blue-dark)); }
.card--traitement .card__head { background: linear-gradient(120deg, var(--orange), var(--orange-dark)); }

.station-list {
  margin: 0;
  padding: 8px;
  list-style: none;
}

.station-list li + li { margin-top: 3px; }

.station-list button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 4px 10px;
  border: 0;
  border-radius: 8px;
  background: #f5f8fb;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: background .15s, transform .15s;
}

.station-list li:nth-child(even) button { background: #eef3f8; }

.card--dessalement .station-list button:hover,
.card--dessalement .station-list button.is-hover { background: var(--blue-soft); }
.card--traitement .station-list button:hover,
.card--traitement .station-list button.is-hover { background: var(--orange-soft); }

.station-list button.is-filtered-out { opacity: .4; }

.station-list__num {
  flex: none;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.card--dessalement .station-list__num { background: var(--blue); }
.card--traitement .station-list__num { background: var(--orange); }

.station-list__name { flex: 1; }

.station-list__tag {
  padding: 2px 8px;
  border-radius: 10px;
  background: #e3e9f0;
  color: var(--ink-soft);
  font-size: 11px;
  white-space: nowrap;
}

.station-list__note {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 10px;
  border-radius: 8px;
  background: #f5f8fb;
  font-size: 12.5px;
  color: var(--ink-soft);
}

.figures__title {
  margin: 0;
  padding: 14px 16px 4px;
  font-size: 16px;
  color: var(--blue-dark);
}

.figures {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 0;
  padding: 8px 10px 16px;
  list-style: none;
}

.figures li { padding: 0 6px; }
.figures li + li { border-left: 1px solid var(--line); }

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

.figures__icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
}

.figures__icon svg { width: 17px; height: 17px; }
.figures__value { font-size: 22px; font-weight: 800; color: var(--blue-dark); line-height: 1; }
.figures__unit { display: block; font-size: 10.5px; font-weight: 700; color: var(--blue-dark); }
.figures__label { margin: 6px 0 0; font-size: 11.5px; line-height: 1.35; color: var(--ink-soft); }

/* ------------------------------------------------------------------ */
/* Fiche station                                                       */
/* ------------------------------------------------------------------ */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
}

.sheet[hidden] { display: none; }

.sheet__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 30, 52, .55);
  backdrop-filter: blur(3px);
  animation: fade .2s ease-out;
}

.sheet__dialog {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(1040px, 100%);
  max-height: calc(100vh - 48px);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .35);
  overflow: hidden;
  outline: none;
  animation: rise .25s cubic-bezier(.2, .8, .3, 1);
}

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(18px) scale(.98); } }

.sheet__header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 20px 18px 24px;
  color: #fff;
  background: linear-gradient(120deg, var(--blue), var(--blue-dark));
}

.sheet--traitement .sheet__header { background: linear-gradient(120deg, var(--orange), var(--orange-dark)); }

.sheet__badge {
  flex: none;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: rgba(255, 255, 255, .18);
}

.sheet__badge svg { width: 30px; height: 30px; }

.sheet__titles { flex: 1; min-width: 0; }

.sheet__type {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  opacity: .85;
}

.sheet__title { margin: 2px 0; font-size: 26px; line-height: 1.15; }

.sheet__region {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-size: 13.5px;
  opacity: .9;
}

.sheet__region svg { width: 14px; height: 14px; }

.sheet__status {
  flex: none;
  padding: 5px 12px;
  border-radius: 20px;
  background: rgba(255, 255, 255, .2);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.sheet__status::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 50%;
  background: #6ee08a;
}

.sheet__status.is-programme::before { background: #ffd24d; }

.sheet__body {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr);
  gap: 24px;
  padding: 24px;
  overflow-y: auto;
}

.sheet__summary {
  margin: 0 0 18px;
  font-size: 15px;
  line-height: 1.6;
}

.facts {
  display: grid;
  gap: 8px;
  margin: 0;
}

.facts div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 14px;
  border-radius: 10px;
  background: #f4f7fa;
  font-size: 13.5px;
}

.facts dt { color: var(--ink-soft); }
.facts dd { margin: 0; font-weight: 700; text-align: right; }
.facts dd.is-empty { font-weight: 400; font-style: italic; color: #9aa7b5; }

/* Galerie */
.gallery__stage {
  position: relative;
  aspect-ratio: 16 / 10;
  border-radius: 12px;
  background: #0f1c2a;
  overflow: hidden;
}

.gallery__stage img,
.gallery__stage video,
.gallery__stage iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  object-fit: cover;
}

.gallery__stage video { object-fit: contain; background: #000; }

.gallery__fullscreen {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  background: rgba(0, 0, 0, .45);
  color: #fff;
  box-shadow: none;
}

.gallery__fullscreen:hover { background: rgba(0, 0, 0, .7); }

.gallery__arrow {
  position: absolute;
  top: 50%;
  width: 38px;
  height: 38px;
  margin-top: -19px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .85);
  color: var(--ink);
}

.gallery__arrow--prev { left: 10px; }
.gallery__arrow--next { right: 10px; }

.gallery__caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  padding: 26px 16px 12px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .65));
  color: #fff;
  font-size: 13px;
  pointer-events: none;
}

.gallery__thumbs {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.gallery__thumb {
  position: relative;
  flex: none;
  width: 86px;
  height: 58px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 8px;
  background: #dfe6ee center / cover no-repeat;
  cursor: pointer;
  opacity: .75;
  transition: opacity .15s, border-color .15s;
}

.gallery__thumb:hover { opacity: 1; }
.gallery__thumb.is-active { border-color: var(--blue); opacity: 1; }
.sheet--traitement .gallery__thumb.is-active { border-color: var(--orange); }

.gallery__thumb svg {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 26px;
  height: 26px;
  color: rgba(0, 0, 0, .55);
}

.gallery__empty {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  aspect-ratio: 16 / 10;
  border: 2px dashed #cdd8e3;
  border-radius: 12px;
  background: repeating-linear-gradient(45deg, #f7fafc 0 14px, #f1f5f9 14px 28px);
  color: #8395a8;
  text-align: center;
  font-size: 14px;
}

.gallery__empty svg { width: 46px; height: 46px; }
.gallery__empty strong { color: var(--ink-soft); font-size: 15px; }

.sheet__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  border-top: 1px solid var(--line);
  background: #fafcfe;
}

.sheet__counter { font-size: 12.5px; color: var(--ink-soft); }

.nav-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 42%;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .15s, color .15s;
}

.nav-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-btn svg { flex: none; width: 18px; height: 18px; }
.nav-btn:hover { border-color: var(--blue); color: var(--blue); }

/* ------------------------------------------------------------------ */
/* Responsive                                                          */
/* ------------------------------------------------------------------ */

@media (max-width: 1100px) {
  .app {
    grid-template-columns: 1fr;
    height: auto;
  }

  .map-panel { height: min(88vh, 900px); }

  .sidebar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    overflow: visible;
  }
}

@media (max-width: 720px) {
  .app { padding: 10px; gap: 12px; }
  .map-panel { height: 82vh; }
  .brand { top: 14px; left: 16px; }
  .brand__logo { font-size: 30px; }
  .brand__ar { font-size: 12px; }
  .brand__fr { font-size: 10.5px; }
  .brand__bar { width: 170px; }
  .legend { top: auto; bottom: 14px; left: 12px; padding: 6px; }
  .legend__item { font-size: 11.5px; padding: 4px 8px; }
  .legend__item br { display: none; }
  .map__hint, .map__scale { display: none; }
  .map__controls { right: 10px; top: 10px; }

  .sheet { padding: 0; align-items: end; }
  .sheet__dialog { max-height: 94vh; border-radius: 18px 18px 0 0; }
  .sheet__body { grid-template-columns: 1fr; padding: 16px; }
  .sheet__header { padding: 14px 12px 14px 16px; gap: 12px; }
  .sheet__badge { width: 42px; height: 42px; }
  .sheet__title { font-size: 20px; }
  .sheet__status { display: none; }
}

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