:root {
  /* polices */
  --font-ui: "Manrope", Inter, Arial, sans-serif;
  --font-mono: "Roboto Mono", monospace;

  /* couleurs texte */
  --text-title: #0c3d62;
  --text-strong: #2d3748;
  --text-main: #334155;
  --text-muted: #536d85;
  --text-soft: #64748b;

  /* couleurs surfaces */
  --panel-bg: rgba(255, 255, 255, 0.72);
  --panel-card-bg: rgba(248, 250, 252, 0.68);
  --glass-bg: rgba(255, 255, 255, 0.74);

  /* couleurs bordures */
  --border-soft: rgba(15, 23, 42, 0.06);
  --border-glass: rgba(255, 255, 255, 0.58);

  /* couleurs fonds subtils */
  --surface-soft: rgba(15, 23, 42, 0.06);
  --surface-hover: rgba(15, 23, 42, 0.1);

  /* couleurs ombres */
  --shadow-soft: rgba(15, 23, 42, 0.1);
  --shadow-medium: rgba(15, 23, 42, 0.2);
  --shadow-strong: rgba(15, 23, 42, 0.3);

  /* couleurs métier */
  --accent-main: #0c3d62;
  --accent-gain: #d67c0c;
  --accent-epci: #d8a94a;
  --accent-population: #e7bf32;
  --accent-medecin: #26364d;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  font-family: Inter, Arial, sans-serif;
  font-size: 14px;
  overflow: hidden;
}

button,
input,
select,
textarea,
.leaflet-container,
.leaflet-popup-content,
.leaflet-tooltip {
  font-family: inherit;
}

* {
  box-sizing: border-box;
}

/* =========================
  PANEL / SIDEBAR
========================= */

#panel {
  position: absolute;
  top: 18px;
  left: 18px;
  z-index: 1000;

  width: 330px;
  padding: 20px 20px 140px;
  max-height: calc(100vh - 110px);

  background: var(--panel-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);

  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 24px;

  box-shadow:
    0 18px 45px var(--shadow-strong),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);

  font-family: Inter, Arial, sans-serif;
  overflow-y: auto;

  transition:
    top 0.28s ease,
    width 0.24s ease,
    height 0.24s ease,
    padding 0.24s ease;
}

#panel h2 {
  margin: 0 0 18px;

  font-family: "Manrope";
  font-size: 24px;
  line-height: 1.08;
  font-weight: 800;
  letter-spacing: -0.01em;

  color: #334155;
}

.panel-content {
  display: block;
}

.panel-section {
  margin-bottom: 14px;
  padding: 16px;

  background: var(--panel-card-bg);
  border: 1px solid var(--border-soft);
  border-radius: 18px;

  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

/* =========================
  PANEL TYPOGRAPHY
========================= */

.section-toggle {
  width: 100%;
  padding: 0;
  margin: 0 0 10px;

  display: flex;
  align-items: center;
  justify-content: space-between;

  border: none;
  background: transparent;
  cursor: pointer;
}

.section-toggle span,
.panel-section-label {
  font-family: "Manrope";
  font-size: 14px;
  font-weight: 750;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  line-height: 2;
  color: #536d85;
}

.panel-section-label {
  display: block;
  margin: 0 0 8px;
}

/* =========================
  FORM ELEMENTS
========================= */

#panel select {
  width: 100%;
  height: 42px;
  padding: 0 14px;

  border-radius: 14px;
  border: 1px solid rgba(15, 23, 42, 0.1);

  background: var(--panel-bg);

  font-size: 13px;
  font-weight: 650;

  color: #334155;
}

#panel select:focus,
#panel input:focus,
#panel button:focus {
  outline: none;
}

#communeSelect {
  font-family: "Roboto Mono";
  font-size: 14px;
  font-weight: 500;
  color: var(--text-main);
  margin-bottom: 20px;

  background: rgba(255, 255, 255, 0.75);
  border: 1px solid var(--border-soft);
}

#communeSelect option {
  font-family: "Inter";
  font-size: 12px;
  font-weight: 300;
  color: var(--text-main);
}

/* =========================
  PANEL COLLAPSE
========================= */

.panel-collapse-btn {
  position: absolute;
  top: 12px;
  right: 12px;

  width: 32px;
  height: 32px;
  padding: 0;

  border: none;
  border-radius: 999px;

  background: var(--surface-soft);
  color: #334155;

  font-size: 17px;
  font-weight: 900;
  cursor: pointer;

  transition:
    background 0.18s ease,
    transform 0.18s ease;
}

.panel-collapse-btn:hover {
  background: var(--surface-hover);
  transform: translateY(-1px);
}

#panel.collapsed {
  width: 320px;
  height: auto;
  padding: 16px 52px 16px 20px;
  overflow: hidden;
}

#panel.collapsed .panel-content {
  display: block;
}

#panel.collapsed .panel-content > :not(h2) {
  display: none;
}

#panel.collapsed h2 {
  margin: 0;
  font-size: 26px;
  line-height: 1.12;
}

#panel.collapsed .panel-collapse-btn {
  position: absolute;
  top: 14px;
  right: 14px;
}

#panel.collapsed ~ #map .mode-badge {
  left: 20px;
  width: 460px;
}

#panel.collapsed > .panel-section {
  display: none;
}

/* =========================
  DOCTOR STEPPER
========================= */

.doctor-stepper {
  width: 118px;
  height: 38px;
  margin-top: 4px;

  display: grid;
  grid-template-columns: 36px 46px 36px;
  align-items: center;

  background: var(--panel-bg);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  overflow: hidden;
}

.doctor-stepper button {
  height: 100%;
  border: none;
  background: transparent;

  color: #334155;

  font-family: "Manrope";
  font-size: 17px;
  font-weight: 850;
  cursor: pointer;
}

.doctor-stepper input {
  width: 100%;
  height: 100%;

  border: none;
  background: transparent;

  font-family: "Manrope";
  text-align: center;
  font-size: 16px;
  font-weight: 850;
  color: #334155;
}

.doctor-stepper input::-webkit-outer-spin-button,
.doctor-stepper input::-webkit-inner-spin-button {
  appearance: none;
  margin: 0;
}

.doctor-stepper input[type="number"] {
  appearance: textfield;
}

/* =========================
  PRIMARY ACTION
========================= */
.simulation-actions {
  display: grid;
  grid-template-columns: 1fr 44px;
  gap: 8px;
  margin-top: 16px;
}

#simulateBtn {
  width: 100%;
  height: 44px;
  margin-top: 0px;

  border: none;
  border-radius: 15px;

  background: #0c3d62;
  color: #ffffff;

  font-family: "Manrope";
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;

  cursor: pointer;
  box-shadow:
    0 10px 22px rgba(31, 79, 70, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

#simulateBtn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow:
    0 14px 30px rgba(31, 79, 70, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

#simulateBtn:disabled {
  background: var(--surface-hover);
  color: rgba(15, 23, 42, 0.35);
  box-shadow: none;
  cursor: not-allowed;
}

.reset-icon-btn {
  width: 44px;
  height: 44px;

  border: none;
  border-radius: 15px;

  background: var(--panel-bg);
  color: #0c3d62;

  font-size: 26px;
  font-weight: 900;

  cursor: pointer;
  box-shadow:
    0 8px 18px var(--shadow-soft),
    inset 0 1px 0 rgba(255, 255, 255, 0.65);

  transition: all 0.18s ease;
}

.reset-icon-btn:hover {
  background: rgba(255, 255, 255, 0.95);
  transform: translateY(-1px);
}

.reset-icon-btn.is-hidden {
  display: none;
}

.simulation-actions:has(.reset-icon-btn.is-hidden) {
  grid-template-columns: 1fr;
}

.simulation-mode-switch {
  margin-top: 14px;
}

/* =========================
  MODE SWITCH
========================= */

.mode-switch {
  display: flex;
  gap: 6px;

  padding: 5px;

  border-radius: 18px;

  background: rgba(15, 23, 42, 0.04);

  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.mode-switch button {
  flex: 1;

  height: 36px;

  border: none;
  border-radius: 14px;

  background: transparent;
  color: #64748b;

  font-family: "Roboto Mono";
  font-size: 13px;
  font-weight: 800;

  cursor: pointer;

  transition:
    background 0.22s ease,
    color 0.22s ease,
    transform 0.18s ease,
    box-shadow 0.22s ease;
}

.mode-switch button:hover {
  color: #334155;
}

.mode-switch button.active {
  background: rgba(255, 255, 255, 0.82);

  color: #334155;

  box-shadow:
    0 4px 12px var(--shadow-soft),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

#showInitialBtn.active {
  color: #0c3d62;
}

#showSimulationBtn.active {
  color: #2563eb;
}

#showGainBtn.active {
  color: var(--accent-gain);
}

.mode-buttons.secondary {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.mode-buttons.secondary .mode-btn {
  height: 30px;
  padding: 0 10px;

  border: none;
  border-radius: 999px;

  background: var(--panel-bg);
  color: #64748b;

  font-family: "Roboto Mono";
  font-size: 13px;
  font-weight: 850;

  cursor: pointer;

  box-shadow:
    0 4px 10px var(--shadow-soft),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);

  transition:
    background 0.2s ease,
    color 0.2s ease,
    transform 0.18s ease;
}

.mode-buttons.secondary .mode-btn:hover {
  color: #334155;
  transform: translateY(-1px);
}

.mode-buttons.secondary .mode-btn.active {
  background: rgba(59, 73, 148, 0.12);
  color: #3b4994;
}

.mode-btn.active[data-mode="gain"] {
  color: var(--accent-gain);
}

/* =========================
  COLLAPSIBLE SECTIONS
========================= */

.section-toggle {
  width: 100%;

  border: none;
  background: transparent;
  padding: 0;
  margin: 0 0 10px;

  display: flex;
  justify-content: space-between;
  align-items: center;

  cursor: pointer;
}

.section-help {
  font-family: "Manrope";
  color: #536d85;
}

.section-content {
  font-family: "Manrope";
  color: #536d85;
  text-align: left;
  line-height: 1.6;
}

.section-content.is-collapsed,
.is-collapsed {
  display: none !important;
}

/* =========================
  LAYER SWITCHES
========================= */

.layer-switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;

  padding: 11px 0;
  border-bottom: 1px solid var(--border-soft);
}

.layer-switch:last-child {
  border-bottom: none;
}

.layer-switch span {
  font-family: "Roboto Mono";
  font-size: 12px;
  font-weight: 6500;
  color: #536d85;
  white-space: nowrap;
}

.switch {
  position: relative;
  width: 38px;
  height: 22px;
  flex: 0 0 38px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;

  border-radius: 999px;

  background: var(--surface-hover);

  transition:
    background 0.24s ease,
    box-shadow 0.24s ease;
}

.slider::before {
  content: "";

  position: absolute;
  left: 3px;
  top: 3px;

  width: 16px;
  height: 16px;

  border-radius: 50%;

  background: white;

  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);

  transition: transform 0.24s ease;
}

.switch input:checked + .slider {
  background: #0c3d62;
}

.switch input:checked + .slider::before {
  transform: translateX(16px);
}

.layer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mini-layer-btn {
  width: 35px;
  height: 22px;

  border: none;
  border-radius: 999px;

  background: rgba(15, 23, 42, 0.06);
  color: #64748b;

  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 800;

  cursor: pointer;
}

.mini-layer-btn.active {
  background: rgba(31, 78, 95, 0.12);
  color: var(--accent-main);
}

/* =========================
  METHOD CONTENT
========================= */

.info-content {
  display: none;
  margin-top: 12px;

  color: #4b5563;
  font-size: 13px;
  line-height: 1.45;
}

.info-section.open .info-content {
  display: block;
}

/* =========================
   MAP
========================= */

#map {
  height: 100vh;
  width: 100vw;
}

.leaflet-control-scale-line {
  border-color: rgba(51, 65, 85, 0.25);
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(8px);
  color: #334155;
}

.map-intro {
  position: absolute;
  inset: 0;
  z-index: 1150;

  height: 100vh;
  min-height: 100vh;

  display: flex;
  align-items: center;

  padding: 80px 120px 80px 360px;

  background: linear-gradient(180deg, #f7f9fb 0%, #eef3f6 100%);

  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);

  transition:
    height 0.38s ease,
    min-height 0.38s ease,
    padding 0.38s ease,
    background 0.38s ease;

  overflow: hidden;

  animation: introFade 0.7s ease;
}

.map-intro.collapsed {
  inset: 0 0 auto 0;
  height: 72px;
  min-height: 72px;

  justify-content: center;
  padding: 0 90px;

  background: rgba(255, 255, 255, 0.88);
  border-bottom: 1px solid var(--border-soft);
  box-shadow: 0 10px 28px var(--shadow-medium);

  pointer-events: auto;
}

.map-intro.collapsed .map-intro-content {
  text-align: center;
}

.map-intro-toggle {
  position: absolute;
  right: 24px;
  top: 18px;
  z-index: 5;

  width: 36px;
  height: 36px;

  display: flex;
  align-items: center;
  justify-content: center;

  border: none;
  border-radius: 999px;
  background: var(--surface-soft);
  color: #334155;

  font-size: 18px;
  font-weight: 900;
  cursor: pointer;

  pointer-events: auto;
  z-index: 20;
}

.map-intro:not(.collapsed) .map-intro-toggle {
  display: none;
}

.map-intro.collapsed .map-intro-toggle {
  display: flex;
}

.map-intro-content {
  max-width: 920px;
  position: relative;
  z-index: 2;
}

.map-intro-kicker {
  margin: 0 0 8px;
  color: #64748b;
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.map-intro h1 {
  margin: 0 0 22px;

  color: #334155;

  font-family: "Manrope";
  font-size: clamp(52px, 5vw, 84px);
  line-height: 0.92;
  font-weight: 950;
  letter-spacing: -0.075em;
}

.map-intro p {
  margin: 0;

  max-width: 760px;

  color: #475569;

  font-family: "Manrope";
  font-size: 20px;
  line-height: 1.65;
  font-weight: 520;
}

.map-intro::before {
  content: "";
  position: absolute;
  inset: -10%;

  background:
    radial-gradient(
      circle at 18% 28%,
      rgba(56, 189, 248, 0.14),
      transparent 34%
    ),
    radial-gradient(circle at 82% 18%, rgba(31, 78, 95, 0.18), transparent 30%),
    radial-gradient(circle at 72% 78%, rgba(211, 79, 61, 0.08), transparent 28%);

  filter: blur(10px);
  z-index: -2;
}

.map-intro::after {
  content: "";
  position: absolute;
  inset: 0;

  background-image:
    linear-gradient(rgba(31, 78, 95, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(31, 78, 95, 0.035) 1px, transparent 1px);

  background-size: 42px 42px;

  mask-image: radial-gradient(circle at center, black 35%, transparent 90%);

  opacity: 0.55;

  z-index: -1;
}

.map-intro.collapsed .map-intro-content > p {
  display: none;
}

.map-intro.collapsed .map-intro-heading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;

  text-align: center;
}

.map-intro.collapsed .map-intro-kicker {
  display: block;
  margin: 0 0 4px;

  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.12em;
  line-height: 1;
  text-transform: uppercase;

  color: rgba(100, 116, 139, 0.85);
}

.map-intro.collapsed h1 {
  text-align: center;
  margin: 0;

  font-family: "Manrope";
  font-size: 28px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.04em;
}

.map-intro.collapsed .map-intro-cta {
  display: none;
}

.map-intro-cta {
  margin-top: 28px;
  padding: 14px 22px;

  border: none;
  border-radius: 999px;

  background: #0c3d62;
  color: white;

  font-family: "Manrope";
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;

  box-shadow: 0 14px 30px rgba(31, 78, 95, 0.28);
}

.map-intro-cta:hover {
  transform: translateY(-1px);
}

body.intro-started #panel {
  top: 82px;
}

body.intro-started #simulation-summary {
  top: 82px;
}

body.intro-started .leaflet-top {
  top: 80px;
}

.leaflet-popup-content {
  font-size: 18px; /* augmente ici */
  line-height: 1.5;
}

.epci-label {
  background: rgba(255, 255, 255, 0.5);
  border: none !important;
  border-radius: 8px;

  padding: 4px 8px;

  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.2);

  color: rgba(51, 65, 85, 0.75);
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 600;
  line-height: 1.2;

  letter-spacing: 0;
}

.epci-labels-muted .epci-label {
  background: rgba(255, 255, 255, 0);

  color: rgba(51, 65, 85, 0);

  box-shadow: none;
}

.map-loader {
  position: absolute;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(1px);
}

.loader-card {
  padding: 18px 22px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.22);
  font-weight: 800;
  color: #1f2937;
  display: flex;
  align-items: center;
  gap: 12px;
}

.loader-spinner {
  width: 24px;
  height: 24px;
  border: 3px solid #d1d5db;
  border-top-color: #2f6654;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.commune-tooltip {
  background: #ffffff;
  color: #334155;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.mode-badge {
  position: absolute;
  left: 30px;
  bottom: 32px;
  width: 460px;

  z-index: 1100;

  min-height: 96px;
  padding: 18px 24px 18px 20px;

  display: flex;
  flex-direction: column;
  justify-content: center;

  border-radius: 24px;

  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);

  border: 1px solid var(--border-glass);
  border-left: 7px solid #1d4e6d;

  box-shadow:
    0 18px 45px var(--shadow-medium),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);

  color: #475569;
}

body.panel-overlaps-mode-badge .mode-badge {
  left: calc(320px + 35px);
}

.mode-badge strong {
  display: block;

  margin-bottom: 8px;

  font-family: "Manrope";
  font-size: 22px;
  line-height: 1.1;
  font-weight: 900;
  letter-spacing: -0.01em;

  color: #2d3748;
}

.mode-badge span {
  display: block;

  font-family: "Manrope";
  font-size: 16px;
  line-height: 1.5;
  font-weight: 550;

  color: #536d85;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.implantation-badge {
  display: inline-block;
  margin-top: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #334155;
  color: white;

  font-family: "Roboto Mono";
  font-size: 14px;
  font-weight: 800;
}

/* =========================
  RESULTS
========================= */

#simulation-summary {
  position: absolute;
  top: 96px;
  right: 24px;
  z-index: 900;
  width: 280px;

  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);

  border: 1px solid var(--border-glass);
  border-radius: 24px;

  box-shadow:
    0 18px 45px var(--shadow-medium),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);

  overflow: hidden;

  transition: top 0.28s ease;
}

.results-toggle {
  width: 100%;
  border: none;
  background: rgba(255, 255, 255, 0.3);
  padding: 13px 16px;

  display: flex;
  align-items: center;
  justify-content: space-between;

  cursor: pointer;
  text-align: left;
}

.results-toggle small {
  font-family: "Manrope";
  font-size: 14px;
  font-weight: 750;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  line-height: 2;
  color: #536d85;
}

.results-toggle strong {
  font-family: "Manrope";
  font-size: 22px;
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: #475569;
}

#resultsToggleIcon {
  font-size: 18px;
  font-weight: 700;
  color: #21242a;
}

#simulation-summary-content {
  padding: 0 14px 14px;
}

.results-kpi {
  background: rgba(248, 250, 252, 0.58);
  border: 1px solid rgba(15, 23, 42, 0.045);
  border-radius: 16px;
  padding: 11px 12px;
  margin-bottom: 8px;

  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.results-kpi span {
  display: block;
  font-family: "Manrope";
  font-size: 14px;
  font-weight: 600;
  color: #64748b;
  margin-bottom: 5px;
}

.results-kpi strong {
  display: block;
  font-family: "Roboto Mono";
  font-size: 28px;
  line-height: 1;
}

.results-kpi small {
  font-family: "Manrope";
  font-size: 12px;
  color: #64748b;
}

/* =========================
  LEGEND
========================= */

#legend {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 1000;

  width: 190px;
  min-width: unset;
  padding: 14px;

  font-family: Inter, Arial, sans-serif;
  font-size: 13px;

  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);

  border: 1px solid var(--border-glass);
  border-radius: 20px;

  box-shadow:
    0 18px 45px var(--shadow-medium),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

#legend strong {
  color: #334155;
}

.legend-block {
  margin-bottom: 10px;
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
}

.legend-block:last-child {
  margin-bottom: 0;
}

.legend-note {
  font-family: "Manrope";
  font-size: 12px;
  font-weight: 400;
  color: #475569;
  margin-bottom: 10px;
}

.legend-title {
  font-family: "Manrope";
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 5px;
  margin-top: 15px;
  color: #475569;
}

.legend-subtitle {
  font-family: "Manrope";
  font-size: 13px;
  font-weight: 600;
  color: #475569;
  margin-bottom: 10px;
}

.legend-item {
  gap: 10px;
  margin: 8px 0;

  font-family: "Manrope";
  font-size: 12px;
  font-weight: 550;
  line-height: 1.25;
  color: #536d85;
}

.legend-swatch {
  display: inline-block;
  flex: 0 0 18px;
  width: 18px;
  height: 13px;
  border-radius: 2px;
  border: 1px solid var(--border-soft);
}

.legend-gradient-spatial {
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(
    to right,
    #e8f7fa,
    #b8e1ea,
    #73bfd3,
    #3f88a8,
    #1d4e6d
  );
}

.legend-scale {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  margin-bottom: 8px;
  font-family: "Roboto Mono";
  font-size: 12px;
  font-weight: 500;
  color: #475569;
}

.legend-dot {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #1f2937;
}

.legend-circle {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid white;
  background: #e7bf32;
}

.legend-line {
  display: inline-block;
  width: 26px;
  height: 0;
  border-top: 5px solid #303030;
}

.bivariate-reset:hover {
  background: #e5e7eb;
}

.legend-classes .legend-item {
  margin: 3px 0;
}

.legend-classes {
  display: flex;
  flex-direction: column;
  gap: 3px;

  margin-top: 8px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;

  font-family: "Roboto Mono";
  font-size: 12px;
  font-weight: 500;
  color: #475569;
}

.legend-color {
  width: 14px;
  height: 14px;

  border-radius: 4px;
  border: 1px solid var(--border-soft);

  flex-shrink: 0;
}

.legend-pop-wrapper {
  display: block;
}

.legend-pop-title {
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 700;
  color: #475569;
}

.legend-pop-scale {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.legend-pop-scale div {
  display: grid;
  grid-template-columns: 28px auto;
  align-items: center;
  column-gap: 8px;
}

.legend-pop-scale span:last-child {
  line-height: 1;
}

.pop-circle {
  justify-self: center;
  display: inline-block;
  border-radius: 50%;
  background: #e7bf32;
  border: 2px solid white;
}

.pop-circle.p300 {
  width: 6px;
  height: 6px;
}

.pop-circle.p3000 {
  width: 15px;
  height: 15px;
}

.pop-circle.p10000 {
  width: 26px;
  height: 26px;
}

.bivariate-legend {
  display: grid;
  grid-template-columns: repeat(3, 30px);
  grid-template-rows: repeat(3, 30px);
  gap: 4px;
}

.bivariate-cell {
  width: 30px;
  height: 30px;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.bivariate-cell:hover {
  transform: scale(1.08);
}

.bivariate-cell.active {
  outline: 2px solid #334155;
  outline-offset: 2px;
}

.bivar-center {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.bivar-axis-layout {
  display: grid;
  grid-template-columns: 22px 18px auto;
  column-gap: 5px;
  align-items: start;
  margin-top: 10px;
}

.bivar-y-label {
  height: 98px;

  display: flex;
  align-items: center;
  justify-content: center;

  writing-mode: vertical-rl;
  transform: rotate(180deg);

  font-family: "Roboto Mono";
  font-size: 12px;
  font-weight: 750;
  color: #475569;
  line-height: 1.05;
  text-align: center;
}

.bivar-y-axis {
  position: relative;
  width: 18px;
  height: 98px;
}

.bivar-center {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.bivar-x-axis {
  width: 96px;
  display: grid;
  grid-template-columns: 12px 1fr 12px;
  align-items: center;
  justify-items: center;
  margin-top: 5px;
}

.bivar-x-label {
  margin-top: 1px;
  font-family: "Roboto Mono";
  font-size: 12px;
  font-weight: 750;
  color: #475569;
}

.axis-sign {
  font-size: 13px;
  font-weight: 900;
  color: #475569;
  line-height: 1.2;
}

.axis-line {
  background: #475569;
}

.bivar-y-axis .axis-plus {
  position: absolute;
  top: -2px;
  left: 50%;
  transform: translateX(-50%);
}

.bivar-y-axis .axis-minus {
  position: absolute;
  bottom: -2px;
  left: 50%;
  transform: translateX(-50%);
}

.axis-line.vertical {
  position: absolute;
  top: 20px;
  bottom: 20px;
  left: 50%;

  width: 2px;
  height: auto;

  transform: translateX(-50%);
  background: #475569;
}

.axis-line.vertical::before {
  content: "";
  position: absolute;
  top: -8px;
  left: -4px;

  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 7px solid #475569;
}

.axis-line.horizontal {
  position: relative;
  width: 58px;
  height: 2px;
  background: #475569;
}

.axis-line.horizontal::before {
  content: "";
  position: absolute;
  right: -5px;
  top: -3px;

  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 7px solid #475569;
}

.bivariate-reset-icon {
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 999px;
  background: #f3f4f6;
  color: #374151;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 6px;
}

.bivariate-reset-icon:hover {
  background: #e5e7eb;
}

.legend-sources {
  margin-top: 8px;

  font-size: 10px;
  color: rgba(71, 85, 105, 0.65);

  border-top: 1px solid rgba(15, 23, 42, 0.06);
  padding-top: 6px;
}

/* =========================
POPUP
========================= */

.leaflet-popup-content-wrapper {
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);

  border-radius: 18px;

  box-shadow:
    0 10px 30px var(--shadow-medium),
    0 2px 10px var(--shadow-soft);

  border: 1px solid rgba(255, 255, 255, 0.45);
}

.leaflet-popup-tip {
  background: rgba(255, 255, 255, 0.82);
}

.leaflet-popup-content {
  margin: 18px 20px;
  min-width: 220px;

  font-family: Inter, sans-serif;
  color: #334155;
  line-height: 1.45;
}

.popup-title {
  margin-bottom: 14px;

  font-family: "Manrope";
  font-size: 28px;
  font-weight: 800;
  line-height: 1.05;

  color: #475569;
}

.popup-section {
  margin-top: 12px;
}

.popup-label {
  font-family: "Manrope";
  font-size: 14px;
  font-weight: 750;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  line-height: 2;
  color: #536d85;
}

.popup-value {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 15px;
  color: #334155;
}

.popup-note {
  margin-top: 14px;

  font-size: 13px;
  line-height: 1.45;

  color: #64748b;
}

/* =========================
  RESPONSIVE & ANIMATIONS
========================= */

@media (max-width: 900px) {
  #panel {
    width: calc(90vw - 24px);
    max-height: 45vh;
    left: 12px;
    right: 12px;
    top: 12px;
  }

  .mode-badge {
    top: auto;
    bottom: 90px;
    left: 12px;
  }

  #legend {
    width: 220px;
    right: 12px;
    bottom: 12px;
  }
}

@keyframes introFade {
  from {
    opacity: 0;
    transform: translateY(-12px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}
