/* ─────────────────────────────────────────
   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);

  /* 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: var(--ir-rouge-dk);
  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: 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-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-vert);
  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(--ir-rouge);
  background: rgba(255, 255, 255, 0.08);
}

.nav-tab.active {
  color: var(--white);
  border-bottom-color: #ff6f00;
  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;
}

/* ─────────────────────────────────────────
   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; }

/* ─────────────────────────────────────────
   ÉVOLUTION (vue détail)
───────────────────────────────────────── */
.evolution-sub {
  font-size: 0.78rem;
  color: var(--ink-lt);
  font-style: italic;
  margin-bottom: 10px;
}

.evolution-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.86rem;
  color: var(--ink);
  padding: 4px 0;
  border-bottom: 1px dashed var(--border);
}
.evolution-row:last-child { border-bottom: none; }

.evolution-row .ev-label { color: var(--ink-mid); font-weight: 600; }
.evolution-row .ev-val   { font-weight: 700; }
.evolution-row .ev-val.up   { color: #c0392b; }
.evolution-row .ev-val.down { color: #1a6ecc; }

/* ─────────────────────────────────────────
   TABLEAU RÉSULTATS (vue détail)
───────────────────────────────────────── */
#table-wrap {
  margin-top: 12px;
  max-height: 26vh;
  min-height: 90px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--white);
  box-shadow: var(--shadow);
}

.matu-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-main);
  font-size: 0.84rem;
}

.matu-table thead th {
  position: sticky;
  top: 0;
  background: var(--ir-vert);
  color: var(--white);
  font-weight: 700;
  text-align: left;
  padding: 8px 12px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  z-index: 1;
}

.matu-table tbody td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--ink);
}

.matu-table tbody tr:hover { background: rgba(22, 154, 181, 0.06); }
.matu-table tbody tr:nth-child(even) { background: rgba(147, 36, 70, 0.025); }

/* ─────────────────────────────────────────
   CHART AREA
───────────────────────────────────────── */
#chart-header {
  margin-bottom: 6px;
}

.chart-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

#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;
}

.download-btn {
  flex-shrink: 0;
  padding: 8px 14px;
  background: var(--white);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-title);
  font-size: 0.80rem;
  font-weight: 600;
  color: var(--ir-bleu-dk);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}

.download-btn:hover {
  background: var(--ir-bleu);
  color: var(--white);
  border-color: var(--ir-bleu-dk);
}

#chart-container {
  flex: 1;
  position: relative;
  min-height: 0;
}

#main-chart {
  width: 100%;
  height: 100%;
}

/* ─────────────────────────────────────────
   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; }

/* ─────────────────────────────────────────
   LOADING / EMPTY STATE
───────────────────────────────────────── */
#chart-container.loading::after,
#chart-container.no-data::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);
  text-align: center;
  white-space: pre-line;
  padding: 20px;
}

#chart-container.no-data::after {
  content: attr(data-message);
}

/* ─────────────────────────────────────────
   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;
  }

  .header-meta { display: none; }
  header h1   { font-size: 1.1rem; }

  .nav-tab { padding: 8px 14px; font-size: 0.82rem; }
}
