/* --- Variables --- */
:root {
  --bg: #000000;
  --surface: #1a1a1a;
  --text: #e0e0e0;
  --text-muted: #888888;
  --accent: #7aa2f7;
  --line: #333333;
  --timeline-line: #666666;
  --timeline-label: #b0b0b0;
  --marker: #bb9af7;
  --error: #f7768e;
  --lane-height: 52px;
}

/* --- Reset & base --- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- Layout --- */
.header {
  position: relative;
  padding: 2rem 1.5rem;
  text-align: center;
  border-bottom: 1px solid var(--line);
}

.lang-switch {
  position: absolute;
  top: 50%;
  right: 1.5rem;
  transform: translateY(-50%);
  font-size: 1.6rem;
  line-height: 1;
  text-decoration: none;
  opacity: 0.7;
  transition: opacity .15s;
}

.lang-switch:hover {
  opacity: 1;
}

.header h1 {
  margin: 0 0 0.5rem;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text);
}

.header h1 a {
  color: inherit;
  text-decoration: none;
}

.description {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.main {
  flex: 1;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: 2rem 1rem;
}

.error {
  color: var(--error);
  padding: 1rem;
  background: rgba(247, 118, 142, 0.1);
  border-radius: 8px;
}

/* --- En-tête sticky (onglets + échelle + filtres) --- */
.timeline-sticky-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 0.5rem;
}

.timeline-filters {
  min-height: 2.25rem;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--line);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* --- Filtres --- */
.filter-section {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.3rem 0.5rem;
}

.filter-section + .filter-section {
  padding-left: 0.75rem;
  border-left: 1px solid var(--line);
}

.filter-section-label {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  white-space: nowrap;
}

.filter-check {
  accent-color: var(--accent);
  cursor: pointer;
  margin: 0;
}

.filter-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  margin-right: 0.25rem;
}

.filter-label:hover {
  color: var(--text);
}

/* --- Zoom slider --- */
.timeline-zoom {
  margin-top: 0.4rem;
  padding-top: 0.4rem;
  border-top: 1px dashed var(--line);
}

.zoom-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.zoom-label {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  white-space: nowrap;
}

.zoom-slider-wrap {
  position: relative;
  flex: 1;
  max-width: 360px;
  height: 20px;
  display: flex;
  align-items: center;
}

.zoom-track {
  position: absolute;
  left: 7px;
  right: 7px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  pointer-events: none;
}

.zoom-range {
  position: absolute;
  width: 100%;
  height: 100%;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  outline: none;
  pointer-events: none;
  margin: 0;
}

.zoom-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
  cursor: pointer;
  pointer-events: auto;
}

.zoom-range::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
  cursor: pointer;
  pointer-events: auto;
  box-shadow: none;
}

.zoom-range::-webkit-slider-runnable-track,
.zoom-range::-moz-range-track {
  background: transparent;
}

.zoom-display {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 9rem;
  text-align: center;
}

.zoom-reset {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0.1rem 0.3rem;
  font-family: inherit;
}

.zoom-reset:hover {
  color: var(--text);
}

/* --- Frise chronologique --- */
.timeline-scroll-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.timeline {
  position: relative;
  min-width: 900px;
  padding-right: 10rem;
  box-sizing: border-box;
}

/* Lignes verticales pointillées (échelle) sur toute la hauteur de la frise */
.timeline-vertical-grid {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 0;
  pointer-events: none;
}

.timeline-vline {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 0;
  border-left: 1px dashed var(--timeline-line);
  transform: translateX(-50%);
}

.timeline-section {
  position: relative;
  z-index: 1;
}

.timeline-section-title {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
}

.timeline-section-evenements {
  margin-top: 0;
  padding-top: 1rem;
}

.timeline-tableaux,
.timeline-evenements-frise,
.timeline-axis-bottom,
.timeline-scale-h {
  position: relative;
  z-index: 0;
}

/* Échelle horizontale (années) — en bas de la frise avec graduations */
.timeline-axis-bottom {
  position: relative;
  height: 10px;
  margin-top: 0.5rem;
}

.timeline-ticks {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 8px;
  pointer-events: none;
}

.axis-tick {
  position: absolute;
  bottom: 0;
  transform: translateX(-50%);
  width: 2px;
  height: 100%;
  background: var(--timeline-line);
}

.timeline-line-h {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--timeline-line);
}

.timeline-scale-h {
  position: relative;
  height: 28px;
  margin-top: 6px;
}

.axis-label-h {
  position: absolute;
  transform: translateX(-50%);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--timeline-label);
  white-space: nowrap;
}

.axis-label-h:first-child {
  transform: translateX(0);
}

.axis-label-h:last-child {
  transform: translateX(-100%);
}

@media (max-width: 768px) {
  .axis-label-h {
    font-size: 0.65rem;
  }
}

/* Un bloc par tableau = une ligne de la frise */
.timeline-tableaux {
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* Groupe de lanes d'un même tableau (avec son label) */
.timeline-tableau-group {
  display: block;
  margin-top: 0.75rem;
}

.timeline-tableau-group:first-child {
  margin-top: 0;
}

/* Label du groupe : sticky gauche pendant le scroll horizontal */
.tableau-group-label {
  position: sticky;
  left: 0;
  display: inline-block;
  z-index: 4;
  font-size: 0.66rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
  padding: 0 1.5rem 0.2rem 0;
  background: linear-gradient(90deg, var(--bg) 78%, transparent 100%);
  pointer-events: none;
}

/* Séparation entre les deux frises = échelle des périodes (la ligne de l’échelle = ligne de séparation) */
.timeline-axis-sticky {
  overflow: hidden;
  margin-top: 0.4rem;
}

.timeline-axis-sticky-inner {
  position: relative;
  min-width: 900px;
  padding-right: 10rem;
}

.timeline-separator {
  margin-top: 3.75rem;
  padding-top: 1.25rem;
  position: relative;
  z-index: 1;
}

.timeline-tableau {
  position: relative;
  height: calc(var(--lane-height) * var(--lanes, 1));
  min-height: var(--lane-height);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.timeline-tableau:nth-child(odd) {
  background: rgba(255, 255, 255, 0.03);
}

.timeline-tableau[data-lanes] {
  height: calc(var(--lane-height) * attr(data-lanes number));
}

.timeline-tableau-lanes {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: var(--lane-height);
}

/* Période : barre horizontale (left % / width %), une lane = une sous-ligne */
.periode {
  position: absolute;
  min-height: calc(var(--lane-height) - 4px);
  height: auto;
  top: 2px;
  min-width: 6px;
  padding: 0.4rem 0.6rem;
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 6px;
  overflow: hidden;
  pointer-events: auto;
  box-sizing: border-box;
}

.periode-titre {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Contraste texte sur couleur : fond coloré → texte lisible */
.periode {
  color: rgba(0, 0, 0, 0.9);
}

.periode-titre {
  color: rgba(0, 0, 0, 0.95);
}

/* --- Événements sur la frise (épingles / pins avec titre) --- */
.timeline-evenements-groupe {
  margin-top: 0.75rem;
}

.timeline-evenements-groupe:first-child {
  margin-top: 0;
}

.timeline-evenements-frise {
  position: relative;
  min-height: 2.5rem;
  margin-top: 0.25rem;
}

.event-marker {
  position: absolute;
  top: 0;
  display: inline-flex;
  align-items: flex-end;
  gap: 0.35rem;
  pointer-events: auto;
  cursor: pointer;
  max-width: 18rem;
}

.periode {
  cursor: pointer;
}

.event-pin {
  flex-shrink: 0;
  width: 16px;
  margin-left: -8px;
  color: var(--marker);
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}

.event-pin svg {
  display: block;
  height: 24px;
  width: auto;
}

.event-marker-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.45;
  max-width: 16rem;
  word-wrap: break-word;
  margin-top: 0.15rem;
}

.event-marker:hover .event-pin {
  color: var(--accent);
}

/* Hauteur du bloc tableaux : chaque .timeline-tableau a une hauteur dynamique */
.timeline-tableau {
  --lanes: 1;
}

.timeline-tableau[data-lanes="1"] { min-height: var(--lane-height); height: var(--lane-height); }
.timeline-tableau[data-lanes="2"] { min-height: calc(var(--lane-height) * 2); height: calc(var(--lane-height) * 2); }
.timeline-tableau[data-lanes="3"] { min-height: calc(var(--lane-height) * 3); height: calc(var(--lane-height) * 3); }
.timeline-tableau[data-lanes="4"] { min-height: calc(var(--lane-height) * 4); height: calc(var(--lane-height) * 4); }
.timeline-tableau[data-lanes="5"] { min-height: calc(var(--lane-height) * 5); height: calc(var(--lane-height) * 5); }

/* --- Onglets des vues (en bas, ordre du plus large au plus restreint) --- */
.timeline-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0;
  margin-bottom: 0.5rem;
  justify-content: flex-start;
}

.tab-btn {
  padding: 0.5rem 0.9rem;
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}

.tab-btn:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.tab-btn.active {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(122, 162, 247, 0.1);
}

/* --- Bouton rafraîchir (AJAX) --- */
.timeline-actions {
  margin-bottom: 1rem;
  text-align: center;
}

.btn-refresh {
  display: inline-block;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--accent);
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
}

.btn-refresh:hover {
  background: rgba(122, 162, 247, 0.15);
}

/* --- Popup (clic sur période ou événement) --- */
.timeline-popup {
  position: fixed;
  z-index: 1000;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem 1rem 0.75rem 1rem;
  max-width: 22rem;
  min-width: 12rem;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.7);
  display: none;
}

.timeline-popup.visible {
  display: block;
}

.timeline-popup-date {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.timeline-popup-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.35rem;
  padding-right: 1.2rem;
}

.timeline-popup-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.timeline-popup-close {
  position: absolute;
  top: 0.4rem;
  right: 0.5rem;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0.2rem 0.3rem;
}

.timeline-popup-close:hover {
  color: var(--text);
}

/* --- Footer --- */
.footer-nav {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  margin-bottom: 0.75rem;
}

.footer-nav a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 1.1rem;
}

.footer-nav a:hover {
  color: var(--accent);
}

.footer {
  padding: 1.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--line);
}

.footer code {
  padding: 0.15em 0.4em;
  background: var(--surface);
  border-radius: 4px;
  font-size: 0.9em;
}

.footer a {
  color: var(--text-muted);
  text-decoration: underline;
}

.footer a:hover {
  color: var(--accent);
}
