/* ─────────────────────────────────────────
   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:     #8d2643;
  --ir-rose:      #be3564;
  --ir-vert:      #afc01f;
  --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: 'Manrope', '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: #afc01f;
  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-title-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

.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.5rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--white);
}

/* Logo — colonne tout à droite, remplit la hauteur du header */
.header-logo {
  display: block;
  height: 89px;
  width: auto;
  object-fit: scale-down;
  object-position: center;
  background: white;
  padding: 6px 12px;
  border-left: 3px solid var(--ir-vert);
  flex-shrink: 0;
}

header .subtitle {
  font-size: 0.82rem;
  color: rgba(255,255,255,0.70);
  font-style: italic;
  font-family: var(--font-main);
}

.header-right {
  display: flex;
  align-items: stretch;
  gap: 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;
  font-family: var(--font-main);
}

.meta-tag--link {
  display: inline-block;
  text-decoration: none;
  background: #ff6f00;
  border: 1px solid black;
  color: black;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  font-weight: 600;
}

.meta-tag--link:hover {
  background: red;
  transform: translateY(-1px);
}

/* ─────────────────────────────────────────
   LAYOUT
───────────────────────────────────────── */
main {
  display: flex;
  height: calc(100vh - 78px);
  overflow: hidden;
}

aside.controls {
  width: 285px;
  min-width: 260px;
  background: var(--sidebar-bg);
  border-right: 3px solid var(--ir-vert);
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
}

.chart-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px 28px 12px;
  overflow: hidden;
}

/* ─────────────────────────────────────────
   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 30px 9px 12px;
  font-family: var(--font-main);
  font-size: 0.95rem;
  color: var(--ink);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.select-wrapper select option {
  font-family: var(--font-main), Arial, sans-serif;
  font-size: 0.95rem;
  color: var(--ink);
}

.select-wrapper select:focus {
  outline: none;
  border-color: var(--ir-vert);
  box-shadow: 0 0 0 3px rgba(174,190,65,0.18);
}

.credits-link {
  color: var(--ir-bleu);
  text-decoration: none;
  font-weight: 600;
}

.credits-link:hover {
  text-decoration: underline;
  color: var(--ir-bleu-dk);
}

.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;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow);
}

.toggle-btn {
  flex: 1;
  padding: 10px 6px;
  background: var(--white);
  border: none;
  font-family: var(--font-title);
  font-size: 0.90rem;
  font-weight: 600;
  color: var(--ink-mid);
  cursor: pointer;
  transition: background 0.18s, color 0.18s;
}

.toggle-btn + .toggle-btn {
  border-left: 1.5px solid var(--border);
}

.toggle-btn.active {
  background: var(--ir-rouge-dk);
  color: var(--white);
}

/* ─────────────────────────────────────────
   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: 10px;
  font-size: 0.92rem;
  color: var(--ink);
  margin-bottom: 6px;
  font-family: var(--font-main);
}

.legend-dot {
  width: 20px;
  height: 4px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* ─────────────────────────────────────────
   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;
  white-space: normal;
  font-family: var(--font-main);
}

/* ─────────────────────────────────────────
   CHART AREA
───────────────────────────────────────── */
#chart-header {
  margin-bottom: 6px;
}

#chart-header h2 {
  font-family: var(--font-title);
  font-size: 1.28rem;
  font-weight: 700;
  color: var(--ir-rouge-dk);
}

#chart-header p {
  font-size: 0.90rem;
  color: var(--ink-mid);
  font-style: italic;
  font-family: var(--font-main);
}

#prediction-banner {
  background: #ff6f00;
  color: var(--white);
  border-radius: var(--radius);
  padding: 9px 18px;
  font-size: 0.90rem;
  font-weight: 600;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-md);
  font-family: var(--font-main);
  border-left: 4px solid var(--ir-vert);
}


#prediction-banner.hidden {
  display: none;
}

#chart-container {
  flex: 1;
  position: relative;
  min-height: 0;
}

#main-chart {
  width: 100%;
  height: 100%;
}

.y-label-ext { display: none; }

/* ─────────────────────────────────────────
   AXES & CHART ELEMENTS (D3)
───────────────────────────────────────── */
.axis path,
.axis line {
  stroke: var(--border);
}

.axis text {
  fill: var(--ink-mid);
  font-family: var(--font-main);
  font-size: 12px;
}

.axis--x .tick line { display: none; }

.grid line {
  stroke: rgba(147,36,70,0.07);
  stroke-dasharray: 3,4;
}

.grid .domain { display: none; }

.threshold-line {
  stroke: var(--ir-vert);
  stroke-width: 2.5;
}

.threshold-label {
  fill: var(--ir-vert-dk);
  font-family: var(--font-main);
  font-size: 12px;
  font-weight: 700;
}

.line-current {
  fill: none;
  stroke: var(--c-2026);
  stroke-width: 2.8;
}

.area-current {
  fill: rgba(28,24,32,0.04);
}

/* ─────────────────────────────────────────
   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.88rem;
  color: var(--ink);
  box-shadow: var(--shadow-md);
  opacity: 0;
  transition: opacity 0.12s;
  min-width: 175px;
  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.95rem;
}

#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; }

/* ─────────────────────────────────────────
   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.75);
  font-size: 1rem;
}

/* ─────────────────────────────────────────
   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); }
  .chart-area { padding: 16px; }
  #chart-container { height: 65vw; min-height: 300px; max-height: 480px; }
  .header-meta { display: none; }
  .header-logo { height: 80px; }
  header h1 { font-size: 1.15rem; }
}
