:root {
  --pgr-green: #2e4a32;
  --pgr-green-dark: #1e3121;
  --pgr-gold: #8a7a4a;
  --pgr-me-yellow: #ffd500;
  --pgr-gold-light: #c2b183;
  --pgr-ivory: #faf7f0;
  --pgr-ivory-dim: #f0ead9;
  --pgr-ink: #2b2b26;
  --pgr-danger: #8a3a2e;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, "Segoe UI", serif;
  background: var(--pgr-ivory);
  color: var(--pgr-ink);
  -webkit-tap-highlight-color: transparent;
}

button, input {
  font-family: inherit;
}

/* ---------- App shell ---------- */

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

header.pgr-header {
  padding: max(5px, var(--safe-top)) 16px 5px;
  background: linear-gradient(180deg, var(--pgr-green) 0%, var(--pgr-green-dark) 100%);
  color: var(--pgr-ivory);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  z-index: 20;
  box-shadow: 0 2px 10px rgba(0,0,0,0.25);
}

.pgr-compass {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.pgr-title-stack {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.pgr-subtitle {
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--pgr-gold-light);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

header.pgr-header h1 {
  font-size: 15px;
  letter-spacing: 0.03em;
  margin: 0;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

header.pgr-header h1 a {
  color: inherit;
  text-decoration: none;
}
header.pgr-header h1 a:active { opacity: 0.75; }

.pgr-status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--pgr-gold-light);
  flex-shrink: 0;
}
.pgr-status-dot.offline { background: var(--pgr-danger); }
.pgr-status-dot.online { background: #6f9a5a; }

/* ---------- Views ---------- */

.pgr-view {
  flex: 1;
  min-height: 0;
  display: none;
}
.pgr-view.active { display: flex; flex-direction: column; }

/* --- Liste des traces --- */

#view-list {
  overflow: hidden;
}

.pgr-search-bar {
  padding: 12px 16px;
  background: var(--pgr-ivory-dim);
  border-bottom: 1px solid rgba(46,74,50,0.12);
  flex-shrink: 0;
}

.pgr-search-bar input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--pgr-gold-light);
  background: #fff;
  font-size: 15px;
  outline: none;
}
.pgr-search-bar input:focus {
  border-color: var(--pgr-gold);
  box-shadow: 0 0 0 3px rgba(138,122,74,0.15);
}

.pgr-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px calc(16px + var(--safe-bottom));
}

.pgr-card {
  background: #fff;
  border: 1px solid rgba(46,74,50,0.10);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
  display: flex;
  gap: 12px;
  align-items: center;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.pgr-card:active { transform: scale(0.98); }

.pgr-card-swatch {
  width: 6px;
  align-self: stretch;
  border-radius: 4px;
  flex-shrink: 0;
}

.pgr-card-body { flex: 1; min-width: 0; }

.pgr-card-title {
  font-weight: 700;
  font-size: 15.5px;
  color: var(--pgr-green-dark);
  margin: 0 0 3px;
}

.pgr-card-meta {
  font-size: 12.5px;
  color: #6b6a5f;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
}

.pgr-pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--pgr-ivory-dim);
  border: 1px solid var(--pgr-gold-light);
  font-size: 11.5px;
  color: var(--pgr-gold);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.pgr-card-fiche {
  color: var(--pgr-green);
  text-decoration: underline;
  text-decoration-color: var(--pgr-gold-light);
  text-underline-offset: 2px;
  font-size: 12.5px;
  font-weight: 600;
}
.pgr-card-fiche:active { opacity: 0.7; }

.pgr-card-ref {
  margin-left: auto;
  font-size: 11px;
  font-style: italic;
  color: #a8a396;
  letter-spacing: 0.02em;
}

.pgr-empty, .pgr-loading, .pgr-error {
  padding: 40px 24px;
  text-align: center;
  color: #6b6a5f;
  font-size: 14px;
  line-height: 1.5;
}
.pgr-error { color: var(--pgr-danger); }
.pgr-error button, .pgr-empty button {
  margin-top: 12px;
}

/* --- Vue carte --- */

#view-map {
  position: relative;
}

#map {
  flex: 1;
  min-height: 0;
  background: var(--pgr-ivory-dim);
}

/* Décale les boutons +/- natifs de Leaflet sous notre rangée de boutons ronds
   (retour / réglages / nord / suivi), au lieu de se placer tout en haut. */
#map .leaflet-top.leaflet-right {
  top: 58px;
}

.pgr-map-topbar {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  z-index: 500;
  display: flex;
  gap: 8px;
  align-items: flex-start;
  pointer-events: none;
}

.pgr-btn-round {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--pgr-gold-light);
  background: rgba(250,247,240,0.96);
  color: var(--pgr-green-dark);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
  cursor: pointer;
  pointer-events: all;
  flex-shrink: 0;
}
.pgr-btn-round:active { transform: scale(0.94); }
.pgr-btn-round.active {
  background: var(--pgr-green);
  color: var(--pgr-ivory);
}

.pgr-map-title {
  background: rgba(250,247,240,0.96);
  border: 1px solid var(--pgr-gold-light);
  border-radius: var(--radius);
  padding: 9px 12px 3px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--pgr-green-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pgr-map-title-stack {
  flex: 1;
  min-width: 0;
  pointer-events: all;
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
  border-radius: var(--radius);
  overflow: hidden;
}

.pgr-map-title-stack .pgr-map-title {
  box-shadow: none;
  border-bottom: none;
  padding-bottom: 2px;
}

.pgr-map-location {
  background: rgba(250,247,240,0.96);
  border: 1px solid var(--pgr-gold-light);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 0 12px 6px;
  font-size: 11px;
  color: var(--pgr-gold);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: none;
}
.pgr-map-location.show { display: block; }

.pgr-stats-panel {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: max(6px, var(--safe-bottom));
  z-index: 500;
  background: rgba(250,247,240,0.97);
  border: 1px solid var(--pgr-gold-light);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.22);
  padding: 8px 12px;
}

.pgr-elev-panel {
  display: none;
  margin-bottom: 5px;
}
.pgr-elev-panel.show { display: block; }

.pgr-elev-svg {
  width: 100%;
  height: 58px;
  display: block;
}

.pgr-elev-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: #a8a396;
  margin-top: 1px;
}

.pgr-elev-climb {
  display: none;
  margin-top: 4px;
  padding: 3px 8px;
  border-radius: 8px;
  background: rgba(201,138,46,0.15);
  border: 1px solid var(--pgr-gold-light);
  font-size: 11px;
  font-weight: 600;
  color: var(--pgr-green-dark);
  text-align: center;
}
.pgr-elev-climb.show { display: block; }

.pgr-stats-row {
  display: flex;
  gap: 10px;
}

.pgr-stat {
  flex: 1;
  text-align: center;
}
.pgr-stat b {
  display: block;
  font-size: 16px;
  color: var(--pgr-green-dark);
  font-weight: 700;
}
.pgr-stat span {
  font-size: 10px;
  color: var(--pgr-gold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.pgr-fiche-link {
  display: block;
  text-align: center;
  font-size: 12px;
  color: var(--pgr-green);
  text-decoration: underline;
  margin-top: 8px;
}

.pgr-track-marker {
  background: var(--pgr-green);
  border: 2px solid var(--pgr-ivory);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(46,74,50,0.25);
}

.pgr-me-marker {
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: var(--pgr-me-yellow);
  border: 3px solid var(--pgr-green-dark);
  box-shadow: 0 0 0 6px rgba(255,213,0,0.35), 0 1px 5px rgba(0,0,0,0.45);
}

.pgr-me-marker-arrow {
  background: transparent;
  border: none;
}

.pgr-arrow-icon {
  background: transparent;
  border: none;
}

.pgr-off-track-banner {
  background: var(--pgr-danger);
  color: #fff;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 12.5px;
  text-align: center;
  box-shadow: 0 3px 10px rgba(0,0,0,0.25);
  display: none;
}
.pgr-off-track-banner.show { display: block; }

/* --- Bandeau de virage à venir --- */

.pgr-turn-banner {
  background: var(--pgr-green);
  color: var(--pgr-ivory);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 3px 10px rgba(0,0,0,0.25);
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.pgr-turn-banner.show { display: flex; }
.pgr-turn-banner .pgr-turn-arrow { font-size: 17px; }

/* --- Pile des bandeaux (géo / hors-trace / virage) --- */

.pgr-alerts-stack {
  position: absolute;
  top: 62px;
  left: 10px;
  right: 10px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* --- Bandeau de géolocalisation (persistant, pas un toast) --- */

.pgr-geo-banner {
  background: var(--pgr-gold);
  color: #fff;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 12.5px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.25);
  display: none;
  align-items: center;
  gap: 10px;
  line-height: 1.35;
}
.pgr-geo-banner.show { display: flex; }
.pgr-geo-banner.pgr-geo-error { background: var(--pgr-danger); }

.pgr-geo-banner span { flex: 1; }

.pgr-geo-retry {
  flex-shrink: 0;
  background: rgba(255,255,255,0.25);
  border: none;
  color: #fff;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.pgr-geo-retry:active { transform: scale(0.96); }

/* --- Panneau de réglages --- */

.pgr-settings-panel {
  position: absolute;
  top: 62px;
  right: 10px;
  z-index: 600;
  background: rgba(250,247,240,0.98);
  border: 1px solid var(--pgr-gold-light);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.22);
  padding: 14px 16px;
  width: 220px;
  display: none;
  flex-direction: column;
  gap: 14px;
}
.pgr-settings-panel.show { display: flex; }

.pgr-settings-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  color: var(--pgr-green-dark);
  font-weight: 600;
}
.pgr-settings-row input[type="range"] {
  width: 100%;
  accent-color: var(--pgr-green);
}
.pgr-settings-checkbox {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}
.pgr-settings-checkbox input[type="checkbox"] {
  width: 17px;
  height: 17px;
  accent-color: var(--pgr-green);
}

/* --- Toast / erreurs --- */

.pgr-toast {
  position: fixed;
  bottom: max(20px, var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--pgr-green-dark);
  color: var(--pgr-ivory);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.pgr-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-4px);
}

.pgr-btn {
  background: var(--pgr-green);
  color: var(--pgr-ivory);
  border: none;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.pgr-btn:active { transform: scale(0.97); }

.leaflet-popup-content-wrapper {
  border-radius: 10px;
  font-family: inherit;
}
.leaflet-popup-content b { color: var(--pgr-green-dark); }
.leaflet-popup-content a { color: var(--pgr-green); }

/* Install banner */
.pgr-install-banner {
  display: none;
  align-items: center;
  gap: 10px;
  background: var(--pgr-gold);
  color: #fff;
  padding: 8px 14px;
  font-size: 12.5px;
  flex-shrink: 0;
}
.pgr-install-banner.show { display: flex; }
.pgr-install-banner button {
  background: rgba(255,255,255,0.25);
  border: none;
  color: #fff;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.pgr-install-banner .pgr-dismiss {
  margin-left: auto;
  background: transparent;
  color: rgba(255,255,255,0.85);
  padding: 4px 6px;
}
