/* ============================================================
 * style.css — Élections Municipales 2026 dashboard
 * Vanilla CSS, no framework. CSS Grid app shell, 100vh, no scroll.
 * ============================================================ */

:root {
  /* Colors */
  --color-bg: #F4F3EF;
  --color-card: #FFFFFF;
  --color-border: #E3E1DA;
  --color-text: #18181A;
  --color-muted: #72706A;

  /* Accents (echo the political bloc palette in parties.js) */
  --accent-blue: #1B5FA8;
  --accent-green: #1A8C5B;
  --accent-red: #C0392B;
  --accent-navy: #1A1A4E;

  /* Fonts */
  --font-head: 'Playfair Display', Georgia, serif;
  --font-body: 'IBM Plex Sans', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;

  /* Layout */
  --sidebar-width: 300px;
  --header-height: 48px;
  --kpi-height: 104px;
  --copyright-height: 22px;

  /* Spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;

  /* Misc */
  --radius: 6px;
  --radius-lg: 10px;
  --shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.12);
  --transition: 160ms ease;
}

/* ── Reset ─────────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
}
body {
  font-family: var(--font-body);
  color: var(--color-text);
  background: var(--color-bg);
  font-size: 14px;
  line-height: 1.45;

  /* App shell: grid, full viewport, no scroll */
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: var(--header-height) 1fr var(--kpi-height) var(--copyright-height);
  grid-template-areas:
    "header  header"
    "sidebar map"
    "sidebar kpi"
    "sidebar copyright";
  height: 100vh;
  overflow: hidden;
}
h1,
h2,
p,
dl,
dd {
  margin: 0;
}
button {
  font-family: inherit;
  cursor: pointer;
}

/* ── Header ────────────────────────────────────────────────────────────── */
#app-header {
  grid-area: header;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: 0 var(--space-4);
  background: var(--color-card);
  border-bottom: 1px solid var(--color-border);
  z-index: 500;
}
.header-titles {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
  min-width: 0;
}
.header-title {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 19px;
  line-height: 1;
  white-space: nowrap;
}
.header-subtitle {
  color: var(--color-muted);
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-tools {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex: none;
}

/* ── Segmented buttons ─────────────────────────────────────────────────── */
.seg-group {
  display: inline-flex;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 2px;
  gap: 2px;
}
.seg-btn {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--color-muted);
  font-size: 12.5px;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 4px;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition);
}
.seg-btn:hover {
  color: var(--color-text);
}
.seg-btn.is-active {
  background: var(--color-text);
  color: #fff;
}
.seg-btn sup {
  font-size: 0.7em;
}

/* ── Sidebar ───────────────────────────────────────────────────────────── */
#sidebar {
  grid-area: sidebar;
  background: var(--color-card);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* ── Sidebar tabs ──────────────────────────────────────────────────────── */
#sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.stab {
  flex: 1;
  padding: 8px 2px;
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--color-muted);
  border-bottom: 2px solid transparent;
  transition: all 0.12s;
}
.stab.active {
  color: var(--color-text);
  border-bottom-color: var(--color-text);
}
.tab-panel {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
.tab-panel.active {
  display: flex;
}
.def-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 10px 13px;
}
.def-section-title {
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--color-muted);
  padding: 10px 0 5px;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 8px;
}
.def-item {
  margin-bottom: 10px;
}
.def-term {
  font-size: 0.74rem;
  font-weight: 600;
}
.def-desc {
  font-size: 0.7rem;
  color: var(--color-muted);
  line-height: 1.55;
  margin-top: 1px;
}
.def-formula {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  background: var(--color-bg);
  border-radius: 4px;
  padding: 3px 7px;
  margin-top: 4px;
  display: inline-block;
}

/* ── À propos tab ──────────────────────────────────────────────────────── */
.about-wrap {
  padding: 14px 13px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  text-align: center;
}
.about-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--color-text);
  color: white;
  font-weight: 700;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 8px;
}
.about-name {
  font-family: var(--font-head);
  font-size: 0.95rem;
  font-weight: 700;
}
.about-title {
  font-size: 0.7rem;
  color: var(--color-muted);
}
.about-links {
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 100%;
}
.about-link {
  font-size: 0.72rem;
  color: var(--color-text);
  text-decoration: none;
  padding: 5px 9px;
  border: 1px solid var(--color-border);
  border-radius: 5px;
  text-align: left;
  transition: background 0.1s;
}
.about-link:hover {
  background: #f0eeea;
}
.about-hr {
  width: 100%;
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 2px 0;
}
.about-desc {
  font-size: 0.7rem;
  color: var(--color-muted);
  line-height: 1.6;
  text-align: left;
  width: 100%;
}
.about-desc p {
  margin-bottom: 6px;
}
.about-desc ul {
  padding-left: 14px;
}
.about-desc li {
  margin-bottom: 2px;
}
.about-version {
  font-size: 0.62rem;
  color: var(--color-muted);
}

/* ── Copyright bar ─────────────────────────────────────────────────────── */
#copyright-bar {
  grid-area: copyright;
  padding: 5px 14px;
  font-size: 0.6rem;
  color: var(--color-muted);
  background: var(--color-card);
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#copyright-bar a {
  color: var(--color-muted);
  text-decoration: none;
}
#copyright-bar a:hover {
  text-decoration: underline;
}

.side-section {
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border);
  flex: none;
}
.side-section--grow {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.side-section--stats {
  background: var(--color-bg);
}
.side-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-muted);
  margin-bottom: var(--space-3);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.side-count {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--color-muted);
}

/* Bloc filter chips */
.bloc-filters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.bloc-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 9px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-card);
  color: var(--color-text);
  transition: opacity var(--transition);
}
.bloc-chip .bloc-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
}
.bloc-chip.is-off {
  opacity: 0.4;
}

/* ── Party list ────────────────────────────────────────────────────────── */
.party-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  margin: 0 calc(-1 * var(--space-4));
  padding: 0 var(--space-4);
}
.party-item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 7px 8px;
  border-left: 3px solid transparent;
  border-radius: 0 4px 4px 0;
  cursor: pointer;
  overflow: hidden;
  transition: background var(--transition);
}
/* proportional background bar (width set inline by app.js: --bar:NN%) */
.party-item::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--bar, 0%);
  background: var(--party-color, var(--color-border));
  opacity: 0.12;
  z-index: 0;
  transition: width var(--transition);
}
.party-item > * {
  position: relative;
  z-index: 1;
}
.party-item:hover {
  background: var(--color-bg);
}
.party-item.is-active {
  border-left-color: var(--party-color, var(--color-text));
  background: var(--color-bg);
}
.party-name {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}
.party-name .party-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
  background: var(--party-color, var(--color-muted));
}
.party-name .party-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.party-value {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--color-muted);
  flex: none;
}

/* ── National stats ────────────────────────────────────────────────────── */
.national-stats {
  display: grid;
  grid-template-columns: 1fr auto;
  row-gap: 6px;
  column-gap: var(--space-3);
}
.national-stats dt {
  color: var(--color-muted);
  font-size: 12.5px;
}
.national-stats dd {
  font-family: var(--font-mono);
  font-weight: 500;
  text-align: right;
}

/* ── Map ───────────────────────────────────────────────────────────────── */
#map-container {
  grid-area: map;
  position: relative;
  min-height: 0;
}
#leaflet-map {
  position: absolute;
  inset: 0;
  background: #F4F3EF !important;
}
/* No basemap tiles — France-only view on a blank background */
.leaflet-tile-pane {
  display: none;
}
.leaflet-container {
  font-family: var(--font-body);
}

/* Map top bar (title + hint) overlaid on the map */
#map-topbar {
  position: absolute;
  top: var(--space-3);
  left: var(--space-3);
  z-index: 450;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(3px);
  max-width: calc(100% - 2 * var(--space-3));
}
.map-topbar-title {
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 15px;
}
.map-topbar-hint {
  font-size: 12px;
  color: var(--color-muted);
}
/* Map mode toggle (% voix / Dominant / Écart) */
#map-mode-btns.btn-grp {
  display: flex;
  gap: 2px;
}
#map-mode-btns .seg {
  border: 1px solid var(--color-border);
  background: var(--color-card);
  color: var(--color-muted);
  font: 600 11px var(--font-body);
  padding: 3px 9px;
  cursor: pointer;
  border-radius: 4px;
  white-space: nowrap;
}
#map-mode-btns .seg:hover:not(:disabled) {
  color: var(--color-text);
}
#map-mode-btns .seg.on {
  background: var(--color-text);
  color: #fff;
  border-color: var(--color-text);
}
#map-mode-btns .seg:disabled {
  cursor: not-allowed;
}

/* Color-scale legend (bottom-right white card) */
.map-legend {
  position: absolute;
  right: var(--space-3);
  bottom: var(--space-3);
  z-index: 450;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: var(--space-3);
  font-size: 11.5px;
  min-width: 130px;
}
.map-legend .legend-title {
  font-weight: 600;
  margin-bottom: 6px;
}
.map-legend .legend-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 2px 0;
}
.map-legend .legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex: none;
}
/* Leaflet legend control rows (built in map.js) */
.map-legend-control .leg-title {
  font-weight: 600;
  margin-bottom: 6px;
}
.map-legend-control .leg-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 2px 0;
}
.map-legend-control .leg-sw {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  flex: none;
}
/* "présent dans X dép." note under a party's % in the sidebar */
.party-note {
  display: block;
  font-size: 9px;
  color: #aaa;
  font-weight: 400;
}

/* ── KPI row ───────────────────────────────────────────────────────────── */
#kpi-row {
  grid-area: kpi; /* placed by the body grid */
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 10px 14px;
  background: var(--color-card);
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
  height: var(--kpi-height, 88px);
}
.kpi-card {
  border-left: 4px solid var(--color-border);
  border-radius: 6px;
  padding: 8px 11px;
  background: white;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.07);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  overflow: hidden;
}
.kpi-label {
  font-size: 0.58rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-muted);
  white-space: nowrap;
}
.kpi-value {
  font-family: var(--font-head);
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.3; /* room for Playfair glyphs (avoids vertical clipping) */
  white-space: nowrap;
}
.kpi-sub {
  font-size: 0.6rem;
  color: var(--color-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}
.kpi-scope {
  font-size: 0.58rem;
  color: var(--color-muted);
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Leaflet popup ─────────────────────────────────────────────────────── */
.leaflet-popup.muni-popup .leaflet-popup-content-wrapper {
  background: var(--color-card);
  color: var(--color-text);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  font-family: var(--font-body);
}
.leaflet-popup.muni-popup .leaflet-popup-content {
  margin: var(--space-3) var(--space-4);
  font-size: 13px;
  line-height: 1.5;
}
.leaflet-popup.muni-popup .leaflet-popup-tip {
  box-shadow: var(--shadow-md);
}
.muni-popup .popup-title {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 4px;
}
.muni-popup .popup-row {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
}
.muni-popup .popup-row .v {
  font-family: var(--font-mono);
}

/* ── Loading screen ────────────────────────────────────────────────────── */
#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  transition: opacity 400ms ease, visibility 400ms ease;
}
#loading-screen.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
}
.loader-spinner {
  width: 38px;
  height: 38px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-text);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}
.loader-text {
  color: var(--color-muted);
  font-size: 13px;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
@media (prefers-reduced-motion: reduce) {
  .loader-spinner {
    animation-duration: 2s;
  }
}

/* ── Page navigation (Carte / Analyse) ─────────────────────────────────── */
#page-nav {
  display: flex;
  gap: 4px;
  margin-left: auto;
  margin-right: 4px;
}
.pnav {
  padding: 4px 11px;
  border-radius: 5px;
  font-size: 0.7rem;
  font-weight: 500;
  border: 1px solid var(--color-border);
  background: none;
  cursor: pointer;
  color: var(--color-muted);
  transition: all 0.1s;
}
.pnav.active {
  background: var(--color-text);
  color: white;
  border-color: var(--color-text);
}

/* ── Analyse page (full-width overlay below the header) ────────────────── */
.app-page {
  display: none;
}
.app-page.active {
  display: flex;
  flex-direction: column;
}
#page-analysis {
  position: fixed;
  top: var(--header-height);
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1100;
  background: var(--color-bg);
  overflow: hidden;
}
#analysis-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  padding: 14px;
  flex: 1;
  overflow: auto;
}
.analysis-card {
  background: white;
  border-radius: 8px;
  border: 1px solid var(--color-border);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 6px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.chart-title {
  font-size: 0.72rem;
  font-weight: 600;
}
.chart-body {
  flex: 1;
  overflow: hidden;
  padding: 8px;
  position: relative;
}
.log-btn {
  font-size: 0.62rem;
  padding: 2px 7px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: var(--color-bg);
  cursor: pointer;
  color: var(--color-muted);
  transition: all 0.1s;
}
.log-btn.active {
  background: var(--color-text);
  color: white;
  border-color: var(--color-text);
}
.chart-tip {
  position: absolute;
  z-index: 10;
  pointer-events: none;
  background: var(--color-text);
  color: #fff;
  font: 11px var(--font-body);
  padding: 4px 7px;
  border-radius: 4px;
  white-space: nowrap;
  transform: translate(-50%, -130%);
  opacity: 0;
  transition: opacity 100ms ease;
}
.chart-tip.show {
  opacity: 1;
}

/* ── Explanatory tooltips (ⓘ) ──────────────────────────────────────────── */
#tip-box {
  position: fixed;
  z-index: 9999;
  background: #1a1a1a;
  color: #ffffff;
  font-family: var(--font-body);
  font-size: 0.71rem;
  line-height: 1.55;
  padding: 8px 11px;
  border-radius: 7px;
  max-width: 230px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.15s, transform 0.15s;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
}
#tip-box.show {
  opacity: 1;
  transform: translateY(0);
}
.tip-trigger {
  display: inline-block;
  cursor: help;
  font-size: 0.65rem;
  color: var(--color-muted);
  margin-left: 3px;
  border-bottom: 1px dashed var(--color-muted);
  line-height: 1;
}

/* ── Responsive: < 768px → stacked (sidebar slides under the map) ──────── */
@media (max-width: 767px) {
  body {
    grid-template-columns: 1fr;
    grid-template-rows: var(--header-height) 60vh var(--kpi-height) auto auto;
    grid-template-areas:
      "header"
      "map"
      "kpi"
      "sidebar"
      "copyright";
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }
  #sidebar {
    border-right: 0;
    border-top: 1px solid var(--color-border);
    overflow: visible;
  }
  .party-list {
    max-height: 320px;
  }
  .header-subtitle {
    display: none;
  }
  #kpi-row {
    grid-template-columns: repeat(2, 1fr);
    height: auto;
    gap: var(--space-2);
  }
  /* Analyse page: stack the 3 charts on mobile */
  #analysis-grid {
    grid-template-columns: 1fr;
  }
}
