/* ==========================================================================
   TCAP · Parcours — feuille de style
   Bureau  : carte plein écran, panneau liste à gauche et panneau infos à droite, repliables.
   Mobile  : onglets Liste / Carte en haut, panneau infos en modale glissante depuis le bas.
   Palette et rythme inspirés de Tailwind (slate + vert du club), CSS pur.
   ========================================================================== */

/* ---------- tokens ---------- */
:root {
  --slate-50: #f8fafc; --slate-100: #f1f5f9; --slate-200: #e2e8f0; --slate-300: #cbd5e1;
  --slate-400: #94a3b8; --slate-500: #64748b; --slate-600: #475569; --slate-700: #334155; --slate-900: #0f172a;
  --green-50: #f0fdf4; --green-100: #dcfce7; --green-600: #16a34a; --green-700: #15803d;
  --track: #4f46e5;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .06);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, .10), 0 4px 6px -4px rgba(15, 23, 42, .10);
  --topbar-h: 60px; --panel-w: 400px; --panel-w-tablet: 340px; --gap: 12px; --peek: 64px;
  --font: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font); font-size: 14px; line-height: 1.5; color: var(--slate-900); background: var(--slate-100);
  display: flex; flex-direction: column; overflow: hidden; -webkit-font-smoothing: antialiased;
}
a { color: var(--green-700); }
button, select, input { font: inherit; }
[hidden] { display: none !important; }
@media (min-width: 701px) { .mobile-only { display: none !important; } #count-desktop { display: none; } }

/* ---------- boutons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 14px;
  border: 1px solid var(--slate-200); border-radius: 10px; background: #fff; color: var(--slate-700);
  font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap; box-shadow: var(--shadow);
}
.btn:hover { background: var(--slate-50); }
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--green-600); border-color: var(--green-600); color: #fff; }
.btn-primary:hover { background: var(--green-700); }
.btn.is-active { background: var(--green-50); border-color: #bbf7d0; color: var(--green-700); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; box-shadow: none; }
#share-selection { margin-left: auto; }
#share-selection:disabled { opacity: .45; cursor: default; }
.filters-foot .link-btn + .link-btn { margin-left: 10px; }
.link-btn { border: 0; background: none; padding: 0; color: var(--green-700); font-size: 12px; font-weight: 500; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
.back { display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; padding: 0; color: var(--green-700); font-size: 13px; font-weight: 600; cursor: pointer; }
.back:hover { text-decoration: underline; }
.badge {
  display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; margin-left: 6px;
  border-radius: 999px; background: var(--green-600); color: #fff; font-size: 11px; font-weight: 700;
}

/* ---------- topbar ---------- */
.topbar {
  flex: 0 0 auto; height: var(--topbar-h); display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: #fff; border-bottom: 1px solid var(--slate-200); z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--slate-900); text-decoration: none; white-space: nowrap; }
.brand img { width: 40px; height: auto; }
.brand-name { font-weight: 700; font-size: 16px; }
.brand-sub { color: var(--slate-500); font-weight: 500; }

/* ---------- disposition : colonne à gauche, carte à droite ---------- */
.main { flex: 1; min-height: 0; position: relative; display: flex; }
.panel { order: -1; flex: 0 0 var(--panel-w); width: var(--panel-w); display: flex; flex-direction: column; background: #fff; border-right: 1px solid var(--slate-200); z-index: 20; }
.view { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.panel-head { flex: 0 0 auto; padding: 14px 18px; border-bottom: 1px solid var(--slate-200); }
.head-row { display: flex; align-items: center; gap: 10px; }
.head-row strong { font-size: 15px; }
.head-row .count { color: var(--slate-500); font-size: 13px; }
.head-row .btn { margin-left: auto; }
.head-row .btn + .btn { margin-left: 8px; }
.detail-head .actions .btn.mobile-only { display: none; }
.close { margin-left: auto; width: 32px; height: 32px; border: 1px solid var(--slate-200); border-radius: 999px; background: #fff; color: var(--slate-600); font-size: 20px; line-height: 1; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.close:hover { background: var(--slate-50); }
.panel-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.map-area { flex: 1; min-width: 0; position: relative; }
#map { position: absolute; inset: 0; z-index: 0; background: var(--slate-200); } /* z-index 0 : isole les calques Leaflet des panneaux */

/* fiche : en-tête (retour, titre, actions) */
.detail-head .back { margin-bottom: 8px; }
.detail-head h1 { margin: 2px 0 2px; font-size: 19px; font-weight: 700; line-height: 1.25; }
.detail-head .start { margin: 0 0 10px; font-size: 12px; color: var(--slate-500); }
.detail-head .meta { font-size: 13px; color: var(--slate-500); margin: 0 0 10px; }
.detail-head .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.detail-head .actions .btn { height: 34px; padding: 0 11px; font-size: 13px; }

/* Leaflet */
.leaflet-left .leaflet-control { margin-left: var(--gap); }
.leaflet-bar { border: 1px solid var(--slate-200) !important; border-radius: 10px !important; box-shadow: var(--shadow) !important; overflow: hidden; }
.leaflet-bar a { color: var(--slate-700) !important; border-bottom-color: var(--slate-200) !important; }
.leaflet-control-attribution { font-family: var(--font); font-size: 10px; background: rgba(255, 255, 255, .8) !important; }


/* ---------- filtres ---------- */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; padding: 14px 16px 12px; background: var(--slate-50); border-bottom: 1px solid var(--slate-200); }
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--slate-500); }
.filters select {
  width: 100%; height: 38px; padding: 0 32px 0 10px; border: 1px solid var(--slate-300); border-radius: 8px; background: #fff;
  color: var(--slate-900); font-size: 14px; font-weight: 500; text-transform: none; letter-spacing: 0; cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat; background-position: right 12px center;
}
.filters select:focus { outline: 2px solid var(--green-600); outline-offset: 1px; border-color: var(--green-600); }
/* curseur de distance (deux <input type=range> superposés) */
.filter-range { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 6px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--slate-500); }
.filter-range-title em { font-style: normal; text-transform: none; letter-spacing: 0; color: var(--green-700); margin-left: 6px; }
.dual-range { position: relative; height: 22px; }
.dual-range-track { position: absolute; left: 0; right: 0; top: 9px; height: 4px; border-radius: 2px; background: var(--slate-200); }
.dual-range-fill { position: absolute; top: 0; bottom: 0; border-radius: 2px; background: var(--green-600); }
.dual-range input[type="range"] {
  position: absolute; left: 0; top: 0; width: 100%; height: 22px; margin: 0; padding: 0; background: none; border: 0; outline: none;
  pointer-events: none; -webkit-appearance: none; appearance: none;
}
.dual-range input[type="range"]::-webkit-slider-runnable-track { height: 22px; background: transparent; }
.dual-range input[type="range"]::-moz-range-track { height: 22px; background: transparent; }
.dual-range input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; pointer-events: auto; width: 18px; height: 18px; margin-top: 2px; border-radius: 50%;
  background: #fff; border: 2px solid var(--green-600); box-shadow: var(--shadow); cursor: pointer;
}
.dual-range input[type="range"]::-moz-range-thumb { pointer-events: auto; width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 2px solid var(--green-600); box-shadow: var(--shadow); cursor: pointer; }
.dual-range input[type="range"]:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--green-600); outline-offset: 2px; }
.filters-foot { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--slate-500); }

/* ---------- liste ---------- */
.route-list { list-style: none; margin: 0; padding: 8px; }
.route-list li[data-id] { display: flex; align-items: center; gap: 4px; }
.route-list .row { display: block; flex: 1; min-width: 0; padding: 10px 12px; border: 0; border-radius: 10px; background: transparent; text-align: left; color: var(--slate-900); cursor: pointer; }
.route-list .check { flex: 0 0 22px; width: 22px; height: 22px; margin-left: 6px; border: 2px solid var(--slate-300); border-radius: 6px; background: #fff; cursor: pointer; position: relative; }
.route-list .check:hover { border-color: var(--green-600); }
.route-list .check.is-on { background: var(--green-600); border-color: var(--green-600); }
.route-list .check.is-on::after { content: ""; position: absolute; left: 6px; top: 2px; width: 5px; height: 10px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.route-list .in-basket .name { color: var(--green-700); }
.route-list .row:hover { background: var(--slate-50); }
.route-list .is-selected .row { background: var(--green-50); box-shadow: inset 0 0 0 1px var(--green-100); }
.route-list .name { font-weight: 600; }
.route-list .meta { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 3px; font-size: 12px; color: var(--slate-500); }
.route-list .level-text { color: var(--slate-400); }
.vote-emoji { margin-right: 6px; }
/* niveau public (lien ?ids=…) : ni filtres, ni panier, ni bouton vote */
body.mode-vote .admin-only { display: none !important; }
.route-list .empty { padding: 24px 12px; text-align: center; color: var(--slate-400); }

/* pastilles type / difficulté / tags */
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.type { display: inline-block; padding: 1px 7px; border-radius: 6px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.type-trail { background: #dcfce7; color: #166534; }
.type-endurance { background: #dbeafe; color: #1d4ed8; }
.type-fractionne { background: #ffedd5; color: #c2410c; }
.type-cotes { background: #fee2e2; color: #b91c1c; }
.type-seuil { background: #f3e8ff; color: #7e22ce; }
.type-course { background: #ccfbf1; color: #0f766e; }
.type-ultra { background: #fae8ff; color: #86198f; }
.level-1 { background: #dcfce7; color: #166534; }
.level-2 { background: #ecfccb; color: #3f6212; }
.level-3 { background: #fef3c7; color: #92400e; }
.level-4 { background: #ffedd5; color: #9a3412; }
.level-5 { background: #fee2e2; color: #991b1b; }
.level-6 { background: var(--slate-900); color: #fde68a; }
.author-mark { font-size: .8em; opacity: .55; font-weight: 400; vertical-align: 1px; }
.tag { display: inline-block; padding: 2px 9px; border-radius: 999px; background: var(--slate-100); color: var(--slate-600); font-size: 11px; font-weight: 500; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- carte : contrôles ---------- */
.map-controls { position: absolute; top: var(--gap); right: var(--gap); z-index: 15; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.segmented { display: inline-flex; padding: 3px; background: #fff; border: 1px solid var(--slate-200); border-radius: 10px; box-shadow: var(--shadow); }
.segmented-btn { padding: 5px 12px; border: 0; border-radius: 7px; background: transparent; color: var(--slate-600); font-size: 12px; font-weight: 500; cursor: pointer; }
.segmented-btn.is-active { background: var(--slate-900); color: #fff; }
.slope-legend { display: flex; align-items: center; gap: 3px; padding: 5px 10px; background: #fff; border: 1px solid var(--slate-200); border-radius: 10px; box-shadow: var(--shadow); font-size: 11px; color: var(--slate-600); }
.sw { display: inline-block; width: 14px; height: 7px; margin-left: 6px; border-radius: 2px; }
.sw-1 { background: #3b82c4; } .sw-2 { background: #3c9a4a; } .sw-3 { background: #d9c11f; } .sw-4 { background: #e07b1a; } .sw-5 { background: #b3171f; }
.map-hint {
  position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 15; padding: 6px 14px;
  background: #fff; border: 1px solid var(--slate-200); border-radius: 999px; box-shadow: var(--shadow); font-size: 12px; color: var(--slate-500); white-space: nowrap; pointer-events: none;
}

/* ---------- marqueurs ---------- */
.km-marker { background: #fff; border: 1px solid var(--slate-900); border-radius: 999px; font-family: var(--font); font-size: 10px; font-weight: 700; line-height: 15px; text-align: center; color: var(--slate-900); }
.pin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1.5px var(--slate-900); }
.pin-start { background: var(--green-600); }
.pin-end { background: #dc2626; }
.cursor-marker { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 3px solid var(--track); }

/* ---------- panneau infos ---------- */
.info { padding: 18px; }
.info h1 { margin: 6px 0 2px; font-size: 19px; font-weight: 700; line-height: 1.25; }
.info h2 { margin: 22px 0 8px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--slate-400); }
.info p { margin: 4px 0; color: var(--slate-700); }
.info .start { margin: 0 0 10px; font-size: 12px; color: var(--slate-500); }
.info .hint { font-size: 12px; color: var(--slate-500); }
.variants { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
.chip { padding: 3px 9px; border: 1px solid var(--slate-200); border-radius: 999px; background: #fff; color: var(--slate-600); font-size: 12px; font-weight: 500; cursor: pointer; }
.chip.is-active { background: var(--green-600); border-color: var(--green-600); color: #fff; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { padding: 10px 12px; background: var(--slate-50); border: 1px solid var(--slate-200); border-radius: 12px; }
.stat-value { font-size: 20px; font-weight: 700; line-height: 1.15; }
.stat-value small { margin-left: 3px; font-size: 12px; font-weight: 500; color: var(--slate-500); }
.stat-label { margin-top: 2px; font-size: 11px; color: var(--slate-500); }
.profile { padding: 6px 4px 2px; background: #fff; border: 1px solid var(--slate-200); border-radius: 12px; }
.profile svg { display: block; width: 100%; height: auto; }
.climbs { list-style: none; margin: 6px 0 0; padding: 0; }
.climbs li { display: flex; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--slate-100); font-size: 13px; }
.climbs .km { min-width: 96px; font-weight: 600; }
.climbs .gain { color: #b45309; font-weight: 600; }
.climbs .detail { color: var(--slate-500); }
.chef-title { display: flex; align-items: center; gap: 8px; color: #b45309 !important; }
.chef-icon { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: 50%; background: #fde68a; color: #78350f; }
.chef-icon svg { width: 16px; height: 16px; }
.chef { margin: 0; padding: 12px 14px 12px 16px; background: #fffbeb; border: 1px solid #fde68a; border-left: 4px solid #f59e0b; border-radius: 10px; }
.chef p { margin: 0; color: #78350f; font-style: italic; }
.chef footer { margin-top: 8px; font-size: 11px; font-weight: 600; color: #b45309; }
.credits { margin-top: 22px; font-size: 11px; color: var(--slate-400); }

/* fenêtre QR code */
.modal-backdrop { position: fixed; inset: 0; z-index: 90; background: rgba(15, 23, 42, .4); }
.modal { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 95; width: min(420px, calc(100% - 32px)); max-height: calc(100% - 32px); overflow-y: auto; background: #fff; border-radius: 18px; box-shadow: var(--shadow-lg); padding: 16px 18px 18px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.modal-head strong { font-size: 15px; }
.qr-code { display: flex; justify-content: center; padding: 6px; }
.qr-code svg { width: min(280px, 70vw); height: auto; }
.qr-hint { margin: 10px 0 8px; font-size: 12px; color: var(--slate-500); text-align: center; }
.qr-url { width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--slate-200); border-radius: 10px; background: var(--slate-50); color: var(--slate-700); font-size: 12px; cursor: pointer; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 100; padding: 9px 16px; background: var(--slate-900); color: #fff; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 13px; }

/* ==========================================================================
   MOBILE (≤ 700 px, téléphones ; les tablettes gardent la disposition bureau) : carte plein écran, panneau en feuille inférieure (repliée / dépliée)
   ========================================================================== */
@media (max-width: 700px) {
  .desktop-only { display: none !important; }
  .mobile-only { display: block; }
  .topbar { padding: 0 12px; }
  .topbar .btn .label { display: none; }
  .topbar .btn { padding: 0 10px; }
  .main { display: block; }
  .map-area { position: absolute; inset: 0; }
  .map-controls { top: 10px; right: 10px; }
  .leaflet-left .leaflet-control { margin-left: 10px !important; }

  /* feuille inférieure : 3 positions (repliée / moitié / dépliée), position calculée par le script (transform) */
  .panel {
    position: absolute; left: 0; right: 0; bottom: 0; width: auto; height: min(88%, 640px); z-index: 20;
    border: 0; border-radius: 18px 18px 0 0; box-shadow: 0 -6px 24px rgba(15, 23, 42, .18);
    transition: transform .3s cubic-bezier(.2, .8, .2, 1);
  }
  body.no-anim .panel { transition: none !important; }
  .sheet-handle { display: block; width: 100%; height: 22px; border: 0; background: transparent; position: relative; cursor: pointer; flex: 0 0 auto; }
  .sheet-handle::before { content: ""; position: absolute; top: 8px; left: 50%; width: 40px; height: 4px; margin-left: -20px; border-radius: 2px; background: var(--slate-300); }
  .panel-head { padding: 4px 16px 12px; cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none; }
  .sheet-handle { touch-action: none; }
  .head-row .btn { display: inline-flex; }
  .detail-head .actions .btn.mobile-only { display: inline-flex; }

  /* filtres repliés par défaut, bouton Filtres */
  .filters { display: none; }
  body.filters-open .filters { display: grid; }
  #toggle-filters[aria-expanded="true"] { background: var(--green-50); border-color: var(--green-100); color: var(--green-700); }
}
@media (max-width: 380px) { .filters { grid-template-columns: 1fr; } }
/* tablette en portrait : colonne un peu plus étroite pour laisser de la place à la carte */
@media (min-width: 701px) and (max-width: 1024px) { .panel { flex-basis: var(--panel-w-tablet); width: var(--panel-w-tablet); } }
