/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: "Inter", system-ui, sans-serif; background: #1a1a1a; }
#map { position: absolute; inset: 0; }

/* ── Header panel ─────────────────────────────────────────────────────────── */
#header {
  position: absolute; top: 12px; left: 12px; z-index: 10;
  background: rgba(255,255,255,0.96); border-radius: 10px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15); max-width: 260px;
  transition: max-height 0.3s ease, padding 0.3s ease;
}
#header.open { padding: 0; }
#header.closed { max-height: 40px; overflow: hidden; padding: 0; }

#header-toggle {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 10px 14px;
  border: none; background: transparent; cursor: pointer;
  font-size: 12px; font-weight: 700; color: #333;
  text-align: left;
}
#header-toggle:hover { color: #111; }
#header-toggle:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: -2px;
  background: rgba(37, 99, 235, 0.05);
}
#header-toggle .chevron {
  width: 16px; height: 16px; transition: transform 0.25s ease;
  flex-shrink: 0;
}
#header.closed #header-toggle .chevron { transform: rotate(180deg); }

#header-content {
  overflow: hidden;
  transition: max-height 0.3s ease, opacity 0.2s ease;
  padding: 0 14px 12px;
}
#header.open #header-content { max-height: 700px; opacity: 1; }
#header.closed #header-content { max-height: 0; opacity: 0; padding: 0 14px; }

#header h1 { font-size: 14px; font-weight: 700; color: #111; line-height: 1.2; }
#header .subtitle { font-size: 11px; color: #666; margin-top: 2px; }
#osm-date { font-size: 10px; color: #999; margin-top: 6px; }
#build-date { font-size: 10px; color: #999; margin-top: 2px; }
#routing-stats { font-size: 10px; color: #777; margin-top: 4px; line-height: 1.5; }
#routing-stats span { font-weight: 600; color: #444; }

/* ── Flow threshold slider ────────────────────────────────────────────────── */
.flow-filter-wrap {
  margin-top: 10px;
  padding: 8px 10px;
  background: #f3f4f6;
  border-radius: 7px;
  border: 1px solid #e5e7eb;
}
.flow-filter-label {
  font-size: 10px;
  color: #666;
  margin-bottom: 5px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.flow-filter-label span {
  font-weight: 700;
  color: #333;
  min-width: 30px;
  text-align: right;
}
#flow-threshold-slider {
  width: 100%;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: linear-gradient(to right, #ef4444 0%, #fdba74 100%);
  border-radius: 2px;
  cursor: pointer;
}
#flow-threshold-slider:focus-visible { outline: 2px solid #2563eb; outline-offset: 2px; }
#flow-threshold-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #ef4444;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  transition: border-color 0.15s, transform 0.1s;
}
#flow-threshold-slider::-webkit-slider-thumb:hover { transform: scale(1.15); border-color: #dc2626; }
#flow-threshold-slider::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #ef4444;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

/* ── Header buttons ───────────────────────────────────────────────────────── */
.header-btn {
  display: flex; align-items: center; gap: 8px; margin-top: 10px;
  width: 100%; padding: 7px 10px; border: none; border-radius: 7px;
  font-size: 12px; font-weight: 600; cursor: pointer; text-decoration: none;
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
}
.header-btn:hover:not(.disabled) { transform: translateY(-1px); }
.header-btn:focus-visible { outline: 2px solid #2563eb; outline-offset: 2px; }
.header-btn.disabled { background: #ddd !important; color: #aaa !important; cursor: not-allowed; pointer-events: none; }
.header-btn svg { flex-shrink: 0; }

#edit-btn { background: #e74c3c; color: #fff; }
#edit-btn:hover:not(.disabled) { background: #c0392b; }
#edit-hint { font-size: 10px; color: #aaa; margin-top: 4px; text-align: center; min-height: 14px; }

#nav-btn { background: #2563eb; color: #fff; }
#nav-btn:hover:not(.disabled) { background: #1d4ed8; }
#nav-btn.active { background: #16a34a; }
#nav-btn.active:hover { background: #15803d; }
#nav-btn.loading { background: #9ca3af; pointer-events: none; }
#nav-hint { font-size: 10px; color: #aaa; margin-top: 4px; text-align: center; min-height: 14px; }

/* ── Route stats panel ────────────────────────────────────────────────────── */
#route-panel {
  position: absolute; bottom: 28px; right: 12px; z-index: 10;
  background: rgba(255,255,255,0.96); border-radius: 10px;
  padding: 14px 16px; box-shadow: 0 2px 12px rgba(0,0,0,0.15);
  min-width: 230px; max-width: 280px;
  display: none;
}
#route-panel.visible { display: block; }
#route-panel h3 { font-size: 13px; font-weight: 700; color: #111; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.route-summary { font-size: 20px; font-weight: 800; color: #111; margin-bottom: 2px; }
.route-time { font-size: 12px; color: #666; margin-bottom: 10px; }

.route-bar-container { margin-bottom: 10px; }
.route-bar {
  height: 10px; border-radius: 5px; overflow: hidden; display: flex;
  background: #e5e7eb;
}
.route-bar-seg { height: 100%; transition: width 0.3s; }
.route-bar-ped { background: #22c55e; }
.route-bar-road { background: #ef4444; }
.route-bar-cyc { background: #7c3aed; }

.route-breakdown { font-size: 11px; line-height: 1.8; }
.route-row { display: flex; align-items: center; gap: 8px; }
.route-dot { width: 10px; height: 10px; margin: 0 16px 0 8px; border-radius: 50%; flex-shrink: 0; }
.route-row .rlabel { color: #666; flex: 1; }
.route-row .rvalue { font-weight: 600; color: #333; text-align: right; min-width: 50px; }
.route-row .rpct { font-weight: 700; color: #111; text-align: right; min-width: 38px; }

#route-clear {
  margin-top: 10px; width: 100%; padding: 6px; border: 1px solid #ddd;
  border-radius: 6px; background: #fff; color: #666; font-size: 11px;
  font-weight: 600; cursor: pointer; transition: all 0.15s;
}
#route-clear:hover { background: #f3f4f6; border-color: #bbb; color: #333; }
#route-clear:focus-visible { outline: 2px solid #2563eb; outline-offset: 2px; }

/* ── Legend panel ─────────────────────────────────────────────────────────── */
#legend {
  position: absolute; bottom: 28px; left: 12px; z-index: 10;
  background: rgba(255,255,255,0.96); border-radius: 10px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
  min-width: 210px; max-height: calc(100vh - 120px); overflow-y: auto;
  transition: max-height 0.3s ease, padding 0.3s ease;
}
#legend.open { padding: 12px 14px; }
#legend.closed { max-height: 40px; overflow: hidden; padding: 0; }

#legend-toggle {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 10px 14px;
  border: none; background: transparent; cursor: pointer;
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: #444;
}
#legend-toggle:hover { color: #111; }
#legend-toggle:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: -2px;
  background: rgba(37, 99, 235, 0.05);
}
#legend-toggle .chevron {
  width: 16px; height: 16px; transition: transform 0.25s ease;
  flex-shrink: 0;
}
#legend.closed #legend-toggle .chevron { transform: rotate(180deg); }

#legend-content {
  overflow: hidden;
  transition: max-height 0.3s ease, opacity 0.2s ease;
}
#legend.open #legend-content { max-height: 800px; opacity: 1; }
#legend.closed #legend-content { max-height: 0; opacity: 0; }

.legend-section { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: #888; margin: 10px 0 4px; }
.legend-item {
  display: flex; align-items: center; gap: 8px; margin-bottom: 5px; cursor: pointer; user-select: none;
  padding: 2px 4px; border-radius: 4px; transition: background 0.1s;
}
.legend-item:hover { background: rgba(0,0,0,0.04); }
.legend-item:focus-visible { outline: 2px solid #2563eb; outline-offset: 1px; }
.legend-item.hidden { opacity: 0.25; }
.legend-line { width: 26px; height: 4px; border-radius: 2px; flex-shrink: 0; }
.legend-line.dashed { background: repeating-linear-gradient(to right, var(--c) 0px, var(--c) 6px, transparent 6px, transparent 10px); }
.legend-line.gradient { background: linear-gradient(to right, var(--c1), var(--c2)); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.legend-dot.gradient-dot { background: linear-gradient(135deg, var(--c1) 0%, var(--c2) 100%); }
.legend-label { font-size: 12px; color: #333; }

/* ── Sub-filter under a legend item ───────────────────────────────────────── */
.legend-sub.parent-hidden { opacity: 0.4; pointer-events: none; }
.legend-sub {
  margin: 4px 0 8px 0;
}
.legend-sub-header {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 9px; text-transform: uppercase; letter-spacing: 0.04em;
  color: #999; margin: 4px 4px 4px 8px;
}
.legend-sub-reset {
  background: none; border: none; cursor: pointer;
  font-size: 10px; color: #71717a; padding: 0;
  text-transform: none; letter-spacing: 0; font-weight: 400;
}
.legend-sub-reset:hover { color: #3f3f46; text-decoration: underline; }
.legend-sub-reset:focus-visible { outline: 2px solid #2563eb; outline-offset: 2px; }
.legend-sub-item {
  display: flex; align-items: center; gap: 0;
  padding: 2px 4px; cursor: pointer; user-select: none;
  font-size: 11px; border-radius: 4px; transition: background 0.1s;
}
.legend-sub-item:hover { background: rgba(0,0,0,0.04); }
.legend-sub-item:focus-visible { outline: 2px solid #2563eb; outline-offset: 1px; }
.legend-sub-item.hidden { opacity: 0.3; }
.legend-sub-dot {
  width: 10px; height: 10px; margin: 0 16px 0 8px; border-radius: 50%; flex-shrink: 0;
}
.legend-sub-label { color: #444; }

/* ── Zoom badge ───────────────────────────────────────────────────────────── */
#zoom-badge {
  position: absolute; top: 12px; right: 52px; z-index: 10;
  background: rgba(255,255,255,0.9); border-radius: 6px; padding: 4px 8px;
  font-size: 11px; color: #555; pointer-events: none;
}

/* ── Map popups ───────────────────────────────────────────────────────────── */
.maplibregl-popup-content {
  background: rgba(30,30,30,0.92) !important;
  color: #eee !important;
  border-radius: 8px !important;
  padding: 10px 14px !important;
  font-size: 12px !important;
  line-height: 1.6 !important;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4) !important;
  max-width: 280px !important;
}
.maplibregl-popup-tip { border-top-color: rgba(30,30,30,0.92) !important; }
.popup-title { font-weight: 700; font-size: 13px; margin-bottom: 4px; color: #fff; }
.popup-row { display: flex; justify-content: space-between; gap: 12px; }
.popup-row .label { color: #aaa; }
.popup-row .value { color: #fff; font-weight: 600; }
/* Bouton ✕ du popup persistant (click) */
.maplibregl-popup-close-button {
  color: #aaa !important;
  font-size: 16px !important;
  padding: 2px 6px !important;
  line-height: 1 !important;
  top: 4px !important;
  right: 4px !important;
}
.maplibregl-popup-close-button:hover { color: #fff !important; }
/* Liens OSM/JOSM/iD dans le popup */
.popup-row .value a {
  color: #7dd3fc;
  text-decoration: none;
}
.popup-row .value a:hover { text-decoration: underline; }

/* ── Nav mode cursor ──────────────────────────────────────────────────────── */
.nav-mode-cursor .maplibregl-canvas { cursor: crosshair !important; }

/* ── Mobile responsive ────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  #header { max-width: 200px; }
  #header h1 { font-size: 12px; }
  #legend { min-width: 180px; bottom: 16px; left: 8px; }
  #route-panel { bottom: 16px; right: 8px; min-width: 200px; max-width: 240px; }
}

/* ── Header nav ── */
.header-nav {
  margin-top: 12px;
  display: flex;
  gap: 12px;
  border-top: 1px solid #eee;
  padding-top: 10px;
}
.header-nav a {
  font-size: 11px;
  font-weight: 600;
  color: #555;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 4px;
}
.header-nav a:hover { color: #111; text-decoration: underline; }
