/* ============================================================
   PALETTE — Charte SMA Syndicat (sma-syndicat.org)
   Police Transducer Medium (primaire) + Archivo (fallback).
   Palette : Bleu #005AFF · Gris Clair #EBEBEB · Gris-Noir #2D323C
   ============================================================ */

@font-face {
  font-family: 'Transducer';
  src: url('../fonts/transducer-medium.otf') format('opentype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Couleurs SMA */
  --sma-blue:       #005AFF;
  --sma-blue-dark:  #0046cc;
  --sma-blue-light: #80ADFF;
  --sma-gray-dark:  #2D323C;
  --sma-gray-mid:   #808590;
  --sma-gray-light: #EBEBEB;
  --sma-near:       #2D323C;
  --sma-dark:       #2D323C;
  --sma-light:      #f7f7f7;
  --sma-border:     #e0e0e0;

  /* Variables fonctionnelles */
  --bg:            var(--sma-light);
  --bg-panel:      #ffffff;
  --bg-header:     var(--sma-near);
  --text:          #2D323C;
  --text-light:    #6a6d75;
  --text-header:   #ffffff;
  --border:        var(--sma-border);
  --accent:        var(--sma-blue);
  --accent-hover:  var(--sma-blue-dark);
  --shadow:        rgba(45, 50, 60, 0.08);
  --tooltip-bg:    var(--sma-near);
  --tooltip-text:  #ffffff;

  /* Choroplèthe diverging : Gris-Noir → Gris Clair → Bleu SMA */
  --color-very-low:  #2D323C;
  --color-low:       #808590;
  --color-medium:    #EBEBEB;
  --color-stable:    #80ADFF;
  --color-positive:  #005AFF;
  --color-nodata:    #EBEBEB;

  --transition: 0.2s ease;

  --font-display: 'Transducer', 'Archivo Black', Arial, sans-serif;
  --font-body:    'Transducer', 'Archivo', -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  margin: 0;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button { font-family: inherit; }

::selection { background: var(--sma-blue); color: #fff; }

/* ============================================================
   LAYOUT PRINCIPAL
   ============================================================ */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 500px;
  background: var(--bg);
}

/* En-tête : barre bleue SMA */
#app-header {
  background: #1A1F2E;
  color: #fff;
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  border-bottom: 4px solid rgba(255,255,255,0.2);
}

#app-header h1 {
  font-family: var(--font-display);
  font-weight: 400; /* Archivo Black est intrinsèquement très épais */
  font-size: clamp(18px, 1.8vw, 24px);
  line-height: 1.15;
  letter-spacing: -0.01em;
  color: #fff;
}

/* Sélecteur de période */
#year-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: rgba(255,255,255,0.7);
  flex-wrap: wrap;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
}

#year-select {
  background: transparent;
  color: #fff;
  border: 1.5px solid rgba(255,255,255,0.35);
  border-radius: 0;
  padding: 7px 32px 7px 14px;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transition: border-color var(--transition);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23fff' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  outline: none;
}

#year-select:hover  { border-color: #fff; }
#year-select:focus  { border-color: var(--sma-blue); }
#year-select option { background: #2D323C; color: #fff; text-transform: none; }

/* Fil d'Ariane */
#breadcrumb {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 10px 28px;
  font-size: 0.85rem;
  color: var(--text-light);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.breadcrumb-item {
  cursor: pointer;
  color: var(--sma-blue);
  font-weight: 600;
  transition: color var(--transition);
}

.breadcrumb-item:hover { color: var(--sma-blue-dark); text-decoration: underline; }
.breadcrumb-item.active { color: var(--text); cursor: default; text-decoration: none; }

.breadcrumb-separator { color: var(--text-light); pointer-events: none; }

/* Contenu principal : carte (gauche) + bandeau (droite) */
#main-content {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
  background: var(--bg);
}

/* ============================================================
   ZONE CARTE
   ============================================================ */
#map-wrapper {
  flex: 1;
  position: relative;
  min-height: 400px;
  overflow: hidden;
  background: #EEF1F8;
}

#map-container { width: 100%; height: 100%; }

#map-container svg {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}

#map-container svg:active { cursor: grabbing; }

/* Paths de la carte */
.region-path,
.dept-path {
  stroke: rgba(255, 255, 255, 0.5);
  stroke-width: 0.8px;
  cursor: pointer;
  transition: fill var(--transition);
}

.region-path:hover {
  fill: #80ADFF;
}

.region-path.selected {
  fill: #2D323C;
  stroke: #fff;
  stroke-width: 1.5px;
}

.dom-group { transform: translate(0, 0); }

/* ============================================================
   TOOLTIP
   ============================================================ */
#tooltip {
  position: absolute;
  background: var(--sma-near);
  color: #fff;
  padding: 10px 14px;
  border-radius: 0;
  font-size: 0.82rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 100;
  max-width: 240px;
  line-height: 1.4;
  white-space: nowrap;
  border-left: 3px solid var(--sma-blue);
  box-shadow: 0 4px 12px rgba(0,0,0,0.18);
}

#tooltip.visible { opacity: 1; }

#tooltip .tt-name {
  font-weight: 700;
  margin-bottom: 3px;
  color: #fff;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 0.92rem;
}
#tooltip .tt-budget { color: #d8def0; font-size: 0.8rem; }
#tooltip .tt-evol { margin-top: 3px; font-weight: 700; color: #80ADFF; }

/* ============================================================
   BOUTON RETOUR — visible en vue départements
   ============================================================ */
#map-back {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 50;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  background: #fff;
  color: var(--sma-near);
  border: 1.5px solid var(--sma-near);
  border-radius: 0;
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 2px 8px var(--shadow);
  transition: background var(--transition), color var(--transition);
}

#map-back[hidden] { display: none; }

#map-back:hover {
  background: var(--sma-blue);
  color: #fff;
  border-color: var(--sma-blue);
}

#map-back span { font-size: 1.05em; line-height: 1; }

/* ============================================================
   CONTRÔLES ZOOM
   ============================================================ */
#zoom-controls {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 0;
  z-index: 50;
  border: 1px solid var(--border);
  background: #fff;
  box-shadow: 0 2px 8px var(--shadow);
}

#zoom-controls button {
  width: 36px;
  height: 36px;
  background: #fff;
  border: none;
  border-radius: 0;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  color: var(--text);
  transition: background var(--transition), color var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

#zoom-controls button + button { border-top: 1px solid var(--border); }

#zoom-controls button:hover {
  background: var(--sma-blue);
  color: #fff;
}

/* ============================================================
   BANDEAU LATÉRAL DROIT — toujours visible
   ============================================================ */
#info-panel {
  width: 480px;
  flex-shrink: 0;
  background: #fff;
  border-left: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* Mode INTRO ─────────────────────────────────────────────────── */
#info-intro {
  padding: 28px 28px 32px;
}

#info-intro[hidden] { display: none; }

.info-eyebrow {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--sma-blue);
  margin-bottom: 10px;
}

.info-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.7rem;
  line-height: 1.1;
  color: var(--sma-near);
  margin-bottom: 16px;
  letter-spacing: -0.01em;
}

.info-lede {
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--text);
  margin-bottom: 28px;
  text-align: justify;
}

.info-lede strong { color: var(--sma-near); font-weight: 700; }

/* Grille de statistiques nationales */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 24px;
}

.stat-item {
  border: 1px solid var(--border);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 80px;
}

.stat-num {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 400;
  color: var(--sma-blue);
  line-height: 1.1;
  letter-spacing: -0.01em;
  margin-bottom: 6px;
}

.stat-label {
  font-size: 0.72rem;
  color: var(--text-light);
  line-height: 1.35;
  text-align: justify;
}

.info-section { margin-bottom: 26px; }
.info-section[hidden] { display: none; }

.info-section-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--sma-near);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--sma-blue);
}

.info-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.info-list li {
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--text);
  padding: 6px 0 6px 18px;
  position: relative;
}

.info-list li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 13px;
  width: 8px;
  height: 8px;
  background: var(--sma-blue);
}

.info-credits {
  font-size: 0.85rem;
  color: var(--text-light);
  line-height: 1.55;
}

.info-credits a {
  color: var(--sma-blue);
  text-decoration: underline;
  text-underline-offset: 2px;
  font-weight: 600;
}

.info-credits a:hover { color: var(--sma-blue-dark); }

/* Légende dans le panneau intro */
.legend-scale { display: flex; flex-direction: column; gap: 6px; }

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--text);
}
.legend-item[hidden] { display: none; }

.legend-swatch {
  width: 18px;
  height: 18px;
  border-radius: 0;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.15);
}

.legend-nodata { background: var(--color-nodata); }

/* Mode DÉTAIL ───────────────────────────────────────────────── */
#side-panel {
  padding: 20px 28px 32px;
  position: relative;
  flex: 1;
  animation: slideIn 0.25s ease;
}

#side-panel[hidden] { display: none; }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(12px); }
  to   { opacity: 1; transform: translateX(0); }
}

#panel-close {
  background: transparent;
  border: 1.5px solid var(--sma-near);
  border-radius: 0;
  padding: 6px 14px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--sma-near);
  cursor: pointer;
  margin-bottom: 18px;
  transition: background var(--transition), color var(--transition);
}

#panel-close:hover {
  background: var(--sma-near);
  color: #fff;
}

#panel-content .panel-region-supertitle {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sma-blue);
  margin-bottom: 4px;
  cursor: pointer;
  display: inline-block;
}
#panel-content .panel-region-supertitle:hover {
  text-decoration: underline;
}

#panel-content .panel-region-name {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 1.5rem;
  line-height: 1.15;
  color: var(--sma-near);
  margin-bottom: 22px;
  letter-spacing: -0.01em;
}

.panel-section { margin-bottom: 22px; }

.panel-section-title {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--sma-near);
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--sma-blue);
}

.budget-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.76rem;
  table-layout: fixed;
}

.budget-table th {
  text-align: right;
  color: var(--text-light);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.64rem;
  padding: 5px 4px 5px 0;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.budget-table th:first-child { text-align: left; padding-left: 0; }

.budget-table th.col-evol-th {
  color: var(--sma-blue);
  padding-left: 4px;
}

.budget-table tr.budget-row td {
  padding: 9px 4px 9px 0;
  text-align: right;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

.budget-table tr.budget-row td.col-year {
  text-align: left;
  padding-left: 0;
  font-weight: 700;
  color: var(--sma-near);
}

.budget-table tr.budget-row td.col-evol {
  padding-left: 4px;
  font-size: 0.72rem;
}

/* Couleurs texte évolution */
.evol-up   { color: #005AFF; font-weight: 700; }
.evol-down { color: #2D323C; font-weight: 700; }
.evol-zero { color: var(--text-light); font-weight: 600; }
.nd        { color: var(--text-light); }

/* Badge évolution */
.evol-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 6px;
  border-radius: 0;
  font-size: 0.76rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.evol-badge.badge-up   { background: #D4EDDA; color: #1A6B30; border: 1px solid #82C89A; }
.evol-badge.badge-down { background: #FDDEDE; color: #B71C1C; border: 1px solid #F08080; }
.evol-badge.zero       { background: #EBEBEB; color: #808590; border: 1px solid #c0c0c0; }
.evol-badge.nd         { background: transparent; color: var(--text-light); border: none; font-weight: 400; }

/* Ligne évolution dans le tableau */
.evol-row td {
  padding: 6px 4px 6px 0;
  text-align: right;
  border-top: 2px solid var(--border);
}
.evol-row td:first-child { text-align: left; padding-left: 0; }
.evol-row .evol-label { font-size: 0.72rem; color: var(--text-light); font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }

/* Split investissement / fonctionnement */
.split-bar-wrap { margin-top: 6px; }

.split-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-light);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.split-bar {
  display: flex;
  height: 10px;
  border-radius: 0;
  overflow: hidden;
  background: var(--border);
}

.split-bar .invest { background: var(--sma-blue); }
.split-bar .fonct  { background: var(--sma-near); }

/* Liens départements */
.dept-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.dept-link {
  background: none;
  border: 1px solid var(--sma-blue);
  color: var(--sma-blue);
  border-radius: 4px;
  padding: 3px 10px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.dept-link:hover {
  background: var(--sma-blue);
  color: #fff;
}

/* Lien source */
.panel-source {
  font-size: 0.82rem;
  color: var(--text-light);
}

.panel-source a {
  color: var(--sma-blue);
  word-break: break-all;
  text-decoration: underline;
  text-underline-offset: 2px;
  font-weight: 600;
}

.panel-source a:hover { color: var(--sma-blue-dark); }

/* Message "données non disponibles" */
.no-data-msg {
  font-size: 0.85rem;
  color: var(--text-light);
  font-style: italic;
  padding: 8px 0;
}

/* Analyse textuelle */
.panel-analyse {
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--text);
  text-align: justify;
}
.panel-analyse a {
  color: inherit;
  text-decoration: underline;
}
.panel-analyse ul {
  margin: 6px 0 8px 0;
  padding-left: 18px;
}
.panel-analyse li {
  margin-bottom: 3px;
}


/* ============================================================
   LOADER
   ============================================================ */
#loader {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  gap: 14px;
  z-index: 200;
  font-size: 0.88rem;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

#loader[hidden] { display: none; }

.spinner {
  width: 38px;
  height: 38px;
  border: 3px solid var(--border);
  border-top-color: var(--sma-blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   MESSAGE D'ERREUR
   ============================================================ */
#error-message {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 200;
  padding: 40px;
  text-align: center;
  color: var(--text);
  font-size: 0.95rem;
  border-top: 4px solid var(--sma-blue);
}

#error-message[hidden] { display: none; }

#error-message code {
  background: var(--sma-near);
  color: #fff;
  padding: 2px 6px;
  font-family: 'Roboto Mono', monospace;
  font-size: 0.9em;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 980px) {
  #main-content { flex-direction: column; }

  #map-wrapper {
    flex: none;
    height: 55vh;
    min-height: 320px;
  }

  #info-panel {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: 50vh;
  }
}

@media (max-width: 768px) {
  #app-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 18px;
  }

  #breadcrumb { padding: 8px 18px; }

  #info-intro,
  #side-panel { padding-left: 18px; padding-right: 18px; }

  .info-title { font-size: 1.4rem; }

  #map-wrapper {
    height: 50vh;
    min-height: 280px;
  }
}

@media (max-width: 480px) {
  .legend-scale { flex-direction: column; }
}
