/* ─────────────────────────────────────────
   ROOT & RESET
───────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@300;400;500;600;700;800&family=Comfortaa:wght@400;600;700&display=swap');

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

:root {
  /* Palette IR */
  --ir-rouge:     #932446;
  --ir-rose:      #be3564;
  --ir-vert:      #aebe41;
  --ir-bleu:      #169ab5;

  /* Dérivés */
  --ir-rouge-dk:  #6e1a34;
  --ir-rouge-lt:  #d4748f;
  --ir-vert-dk:   #8aa032;
  --ir-bleu-dk:   #0d7389;
  --ir-bleu-lt:   #a8dce8;

  /* Neutres */
  --bg:           #f7f5f2;
  --sidebar-bg:   #f0ecea;
  --white:        #ffffff;
  --ink:          #1c1820;
  --ink-mid:      #5a4f58;
  --ink-lt:       #9e8fa0;
  --border:       rgba(147, 36, 70, 0.12);

  /* Courbes années */
  --c-2022: #e6194B;
  --c-2023: #f58231;
  --c-2024: #4363d8;
  --c-2025: #006400;
  --c-2026: #1c1820;

  /* Typo */
  --font-main:  'Manrope', system-ui, sans-serif;
  --font-title: 'Comfortaa', 'Manrope', sans-serif;

  --radius:    8px;
  --radius-lg: 14px;
  --shadow:    0 2px 12px rgba(147, 36, 70, 0.08);
  --shadow-md: 0 4px 20px rgba(147, 36, 70, 0.13);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-main);
  font-size: 16px;
  line-height: 1.6;
}

/* ─────────────────────────────────────────
   HEADER
───────────────────────────────────────── */
header {
  background: linear-gradient(100deg, var(--ir-rouge-dk) 0%, var(--ir-rouge) 60%, var(--ir-rose) 100%);
  color: var(--white);
  border-bottom: 3px solid var(--ir-vert);
  box-shadow: 0 2px 16px rgba(147, 36, 70, 0.20);
}

.header-inner {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  min-height: 72px;
}

.header-left {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  padding: 14px 24px;
  flex: 1;
}

header h1 {
  font-family: var(--font-title);
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--white);
}

header .subtitle {
  font-size: 0.82rem;
  color: rgba(255, 255, 255, 0.70);
  font-style: italic;
}

.header-right {
  display: flex;
  align-items: stretch;
}

.header-logo {
  display: block;
  height: 100%;
  width: auto;
  object-fit: contain;
  object-position: center;
  background: white;
  padding: 6px 12px;
  border-left: 3px solid var(--ir-vert);
  flex-shrink: 0;
}

.header-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 5px;
  padding: 14px 16px;
}

.meta-tag {
  font-size: 0.68rem;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 20px;
  padding: 2px 10px;
  color: rgba(255, 255, 255, 0.85);
  white-space: nowrap;
}

/* ─────────────────────────────────────────
   NAV TABS
───────────────────────────────────────── */
.nav-tabs {
  display: flex;
  background: var(--ir-rouge-dk);
  border-bottom: 2px solid var(--ir-vert);
  overflow-x: auto;
}

.nav-tab {
  padding: 10px 22px;
  font-family: var(--font-title);
  font-size: 0.92rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.70);
  cursor: pointer;
  border: none;
  background: none;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
  transition: all 0.15s;
}

.nav-tab:hover {
  color: var(--white);
  background: rgba(255, 255, 255, 0.08);
}

.nav-tab.active {
  color: var(--white);
  border-bottom-color: var(--ir-vert);
  background: rgba(255, 255, 255, 0.12);
}

/* ─────────────────────────────────────────
   LAYOUT
───────────────────────────────────────── */
main {
  display: flex;
  height: calc(100vh - 116px); /* header + nav */
  overflow: hidden;
}

aside.controls {
  width: 278px;
  min-width: 250px;
  background: var(--sidebar-bg);
  border-right: 3px solid var(--ir-vert);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

.chart-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 18px 26px 12px;
  overflow: hidden;
  min-width: 0;
}

/* ─────────────────────────────────────────
   CONTROLS
───────────────────────────────────────── */
.control-group label {
  display: block;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: var(--ir-rouge);
  margin-bottom: 6px;
  font-family: var(--font-main);
}

.select-wrapper {
  position: relative;
}

.select-wrapper select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  background: var(--white);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 28px 9px 11px;
  font-family: var(--font-main);
  font-size: 0.92rem;
  color: var(--ink);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.select-wrapper select:focus {
  outline: none;
  border-color: var(--ir-vert);
  box-shadow: 0 0 0 3px rgba(174, 190, 65, 0.18);
}

.select-arrow {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--ir-rouge);
  font-size: 0.75rem;
}

/* Toggle */
.toggle-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.toggle-btn {
  padding: 9px 10px;
  background: var(--white);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-title);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-mid);
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
}

.toggle-btn:hover {
  border-color: var(--ir-bleu-lt);
  color: var(--ink);
}

.toggle-btn.active {
  background: linear-gradient(135deg, var(--ir-bleu-dk) 0%, var(--ir-bleu) 100%);
  color: var(--white);
  border-color: var(--ir-bleu-dk);
}

/* ─────────────────────────────────────────
   LEGEND
───────────────────────────────────────── */
.legend-box {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.legend-title {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: var(--ir-rouge);
  margin-bottom: 10px;
  font-family: var(--font-main);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 0.88rem;
  color: var(--ink);
  margin-bottom: 5px;
  font-family: var(--font-main);
}

.legend-swatch {
  flex-shrink: 0;
  width: 20px;
  height: 4px;
  border-radius: 2px;
}

.legend-swatch.sq {
  height: 14px;
  border-radius: 3px;
  opacity: 0.85;
}

.legend-swatch.dash {
  height: 2px;
  background: repeating-linear-gradient(90deg, #555 0 5px, transparent 5px 9px);
}

/* ─────────────────────────────────────────
   INFO BOX
───────────────────────────────────────── */
.info-box {
  background: rgba(22, 154, 181, 0.07);
  border: 1px solid rgba(22, 154, 181, 0.22);
  border-left: 4px solid var(--ir-bleu);
  border-radius: var(--radius);
  padding: 10px 13px;
  font-size: 0.80rem;
  color: var(--ink-mid);
  line-height: 1.55;
  min-height: 40px;
}

.info-box strong { color: var(--ir-bleu-dk); }

/* ─────────────────────────────────────────
   CREDITS
───────────────────────────────────────── */
.credits {
  margin-top: auto;
  font-size: 0.70rem;
  color: var(--ink-lt);
  line-height: 1.8;
  border-top: 1px solid var(--border);
  padding-top: 12px;
  word-break: break-word;
  font-family: var(--font-main);
}

.credits-link {
  color: var(--ir-bleu);
  text-decoration: none;
  font-weight: 600;
}
.credits-link:hover { text-decoration: underline; }

/* ─────────────────────────────────────────
   CHART AREA
───────────────────────────────────────── */
#chart-header {
  margin-bottom: 6px;
}

#chart-header h2 {
  font-family: var(--font-title);
  font-size: 1.22rem;
  font-weight: 700;
  color: var(--ir-rouge-dk);
}

#chart-header p {
  font-size: 0.88rem;
  color: var(--ink-mid);
  font-style: italic;
}

#chart-container {
  flex: 1;
  position: relative;
  min-height: 0;
}

#main-chart {
  width: 100%;
  height: 100%;
}

/* ─────────────────────────────────────────
   CARTE LEAFLET
───────────────────────────────────────── */
#map-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

#leaflet-map {
  flex: 1;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  min-height: 0;
}

#map-legend {
  position: absolute;
  bottom: 32px;
  right: 10px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-family: var(--font-main);
  font-size: 0.82rem;
  color: var(--ink);
  box-shadow: var(--shadow-md);
  z-index: 1000;
  min-width: 160px;
}

#map-legend .map-legend-title {
  font-weight: 800;
  font-size: 0.70rem;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: var(--ir-rouge);
  margin-bottom: 8px;
}

#map-legend .map-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

#map-legend .map-legend-color {
  width: 18px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.15);
  flex-shrink: 0;
}

/* Leaflet popup override */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow-md) !important;
  font-family: var(--font-main) !important;
  font-size: 0.88rem !important;
}

.popup-title {
  font-family: var(--font-title);
  font-weight: 700;
  color: var(--ir-rouge-dk);
  margin-bottom: 6px;
  font-size: 1rem;
}

.popup-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 3px;
}

.popup-label { color: var(--ink-mid); }
.popup-val   { font-weight: 700; }

/* ─────────────────────────────────────────
   AXES & CHART ELEMENTS (D3)
───────────────────────────────────────── */
.axis path,
.axis line {
  stroke: var(--border);
}

.axis text {
  fill: var(--ink-mid);
  font-family: var(--font-main);
  font-size: 11px;
}

.axis--x .tick line { display: none; }

.axis--y-right path,
.axis--y-right line { stroke: var(--border); }
.axis--y-right text {
  fill: var(--ink-mid);
  font-family: var(--font-main);
  font-size: 11px;
}

.grid line {
  stroke: rgba(147, 36, 70, 0.07);
  stroke-dasharray: 3, 4;
}
.grid .domain { display: none; }

/* ─────────────────────────────────────────
   TOOLTIP
───────────────────────────────────────── */
#tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--white);
  border: 1px solid var(--border);
  border-left: 4px solid var(--ir-bleu);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 0.85rem;
  color: var(--ink);
  box-shadow: var(--shadow-md);
  opacity: 0;
  transition: opacity 0.12s;
  min-width: 180px;
  z-index: 10;
  font-family: var(--font-main);
}

#tooltip.visible { opacity: 1; }

#tooltip .tt-date {
  font-weight: 700;
  margin-bottom: 5px;
  color: var(--ir-rouge);
  font-family: var(--font-title);
  font-size: 0.92rem;
}

#tooltip .tt-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 3px;
}

#tooltip .tt-label { color: var(--ink-mid); }
#tooltip .tt-val   { font-weight: 700; }

#tooltip .tt-sep {
  border: none;
  border-top: 1px solid var(--border);
  margin: 5px 0 3px;
}

/* ─────────────────────────────────────────
   LOADING STATE
───────────────────────────────────────── */
#chart-container.loading::after {
  content: "Chargement…";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-title);
  font-style: italic;
  color: var(--ink-lt);
  background: rgba(247, 245, 242, 0.85);
  font-size: 1rem;
  border-radius: var(--radius);
}

/* ─────────────────────────────────────────
   UTILITY
───────────────────────────────────────── */
.hidden { display: none !important; }

/* ─────────────────────────────────────────
   RESPONSIVE
───────────────────────────────────────── */
@media (max-width: 768px) {
  main {
    flex-direction: column;
    height: auto;
    overflow: auto;
  }

  aside.controls {
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 14px;
  }

  .chart-area {
    padding: 14px;
  }

  #chart-container {
    height: 62vw;
    min-height: 280px;
    max-height: 460px;
  }

  #leaflet-map {
    height: 62vw;
    min-height: 280px;
    max-height: 460px;
  }

  .header-meta { display: none; }
  header h1   { font-size: 1.1rem; }

  .nav-tab { padding: 8px 14px; font-size: 0.82rem; }
}
