/* ═══════════════════════════════════════════════════════════════
   TREKKING — Explore La Maddalena
   ═══════════════════════════════════════════════════════════════ */

:root {
  --tr-green:       #16A34A;
  --tr-green-dk:    #14532D;
  --tr-green-lt:    #DCFCE7;
  --tr-green-mid:   #22C55E;
  --tr-amber:       #D97706;
  --tr-red:         #DC2626;
  --tr-surface:     #FAFAF9;
  --tr-border:      #E7E5E4;
  --tr-text:        #1C1917;
  --tr-muted:       #78716C;
  --tr-radius-lg:   16px;
  --tr-radius-md:   10px;
  --tr-shadow-sm:   0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --tr-shadow-md:   0 4px 16px rgba(0,0,0,.08), 0 2px 6px rgba(0,0,0,.05);
  --tr-shadow-lg:   0 16px 48px rgba(0,0,0,.12), 0 4px 16px rgba(0,0,0,.06);
}

/* ── ARCHIVE HERO ─────────────────────────────────────────────── */
.trail-archive-hero {
  background: linear-gradient(150deg, #0D3321 0%, #15803D 55%, #166534 100%);
  color: #fff;
  padding: 100px 24px 72px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
/* Video hero */
.trail-archive-hero--video { background: #0a1f0f; }
.trail-hero-video {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover; object-position: center;
  z-index: 0;
  pointer-events: none;
}
.trail-hero-overlay {
  position: absolute; inset: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,.45) 0%, rgba(0,0,0,.3) 60%, rgba(0,0,0,.55) 100%);
  z-index: 1;
}
.trail-archive-hero--video .container,
.trail-archive-hero--video::before { position: relative; z-index: 2; }
/* Fallback: no video (prefers-reduced-motion) */
@media (prefers-reduced-motion: reduce) {
  .trail-hero-video { display: none; }
  .trail-archive-hero--video { background: linear-gradient(150deg, #0D3321 0%, #15803D 55%, #166534 100%); }
}
.trail-archive-hero::before {
  content: '';
  position: absolute; inset: 0;
  background: none;
  pointer-events: none;
}
.trail-archive-hero .container { position: relative; max-width: 900px; margin: 0 auto; }
.trail-archive-hero .eyebrow {
  display: inline-flex; align-items: center; gap: 8px;
  text-transform: uppercase; letter-spacing: 3px; font-size: 11px;
  font-weight: 700; color: #86EFAC;
  background: rgba(255,255,255,.1); backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,.15);
  padding: 6px 16px; border-radius: 100px; margin-bottom: 20px;
}
.trail-archive-hero h1 {
  font-family: 'Playfair Display', serif;
  font-size: clamp(2.2rem, 5.5vw, 4rem);
  font-weight: 700; line-height: 1.1; margin: 0 0 20px;
  text-shadow: 0 2px 24px rgba(0,0,0,.3);
}
.trail-archive-hero p {
  max-width: 620px; margin: 0 auto; font-size: 1.15rem;
  opacity: .9; line-height: 1.7;
}
.trail-hero-badges {
  display: flex; justify-content: center; gap: 12px; flex-wrap: wrap;
  margin-top: 32px;
}
.trail-hero-badge {
  background: rgba(255,255,255,.12); backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,.2);
  color: #fff; padding: 8px 18px; border-radius: 100px;
  font-size: .9rem; font-weight: 500;
}

/* ── CONTAINER COMUNE ─────────────────────────────────────────── */
.trail-container { max-width: 1180px; margin: 0 auto; padding: 0 24px; }

/* ── OVERVIEW MAP ─────────────────────────────────────────────── */
.trail-overview-section {
  padding: 64px 24px 0;
  background: var(--tr-surface);
}
.trail-section-header {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 20px; gap: 16px;
}
.trail-section-header h2 {
  font-family: 'Playfair Display', serif;
  font-size: 1.75rem; color: var(--tr-green-dk); margin: 0;
}
.trail-map {
  width: 100%; height: 480px;
  border-radius: var(--tr-radius-lg);
  box-shadow: var(--tr-shadow-lg);
  border: 1px solid var(--tr-border);
  overflow: hidden;
  isolation: isolate; /* nuovo stacking context — Leaflet panes non escono dal contenitore */
  position: relative; z-index: 0;
}
.trail-map-overview { height: 500px; }

/* ── Mappa 3D Mapbox: pin + popup sentieri ──────────────────────────────── */
.trail3d-pin {
  min-width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 6px;
  font-size: 13px; font-weight: 800; color: #fff;
  background: #ff6b35;
  border: 2px solid #fff;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  box-shadow: 0 2px 6px rgba(0,0,0,.4);
  cursor: pointer;
}
.trail3d-pin { line-height: 1; }
.trail3d-popup h4 { margin: 0 0 4px; font-size: 1rem; color: #0a2840; }
.trail3d-popup__meta { margin: 0 0 8px; font-size: .82rem; color: #4a5b68; }
.trail3d-popup__btn {
  display: inline-block; font-size: .82rem; font-weight: 700;
  color: #fff; background: #ff6b35; padding: 6px 12px;
  border-radius: 6px; text-decoration: none;
}
.trail3d-popup__btn:hover { background: #e85a26; }
.map-attribution {
  font-size: .78rem; color: var(--tr-muted);
  margin-top: 8px; text-align: right;
}
.map-attribution a { color: var(--tr-muted); }

/* ── GRID ARCHIVIO ────────────────────────────────────────────── */
.trail-grid-section { padding: 48px 24px 80px; background: var(--tr-surface); }
.trail-grid-section h2 {
  font-family: 'Playfair Display', serif;
  font-size: 1.75rem; color: var(--tr-green-dk); margin: 0 0 28px;
}
.trail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 24px;
}

/* ── TRAIL CARD ───────────────────────────────────────────────── */
.trail-card {
  display: flex; flex-direction: column;
  background: #fff; border-radius: var(--tr-radius-lg);
  overflow: hidden; text-decoration: none; color: inherit;
  border: 1px solid var(--tr-border);
  box-shadow: var(--tr-shadow-sm);
  transition: transform .28s cubic-bezier(.34,1.56,.64,1),
              box-shadow .28s ease;
}
.trail-card:hover {
  transform: translateY(-6px);
  box-shadow: var(--tr-shadow-lg);
  border-color: rgba(22,163,74,.2);
}
.trail-card-img {
  position: relative; height: 210px;
  background-size: cover; background-position: center;
}
.trail-card-img::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(180deg, transparent 40%, rgba(0,0,0,.45) 100%);
}
.trail-card-chips {
  position: absolute; top: 14px; left: 14px; z-index: 1;
  display: flex; gap: 6px;
}
.trail-card-body { padding: 20px 22px 22px; flex: 1; display: flex; flex-direction: column; }
.trail-card-body h3 {
  font-family: 'Playfair Display', serif;
  font-size: 1.3rem; margin: 0 0 8px;
  color: var(--tr-green-dk); line-height: 1.3;
}
.trail-card-excerpt {
  font-size: .92rem; color: var(--tr-muted); margin: 0 0 16px; flex: 1;
  display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden;
  line-height: 1.6;
}
.trail-card-stats {
  display: flex; gap: 0;
  background: var(--tr-green-lt);
  border-radius: var(--tr-radius-md);
  overflow: hidden;
}
.trail-card-stat {
  flex: 1; padding: 10px 12px; text-align: center;
  border-right: 1px solid rgba(22,163,74,.15);
}
.trail-card-stat:last-child { border-right: none; }
.trail-card-stat b {
  display: block; font-size: 1rem; color: var(--tr-green-dk);
  font-weight: 700; line-height: 1.1;
}
.trail-card-stat span {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .8px;
  color: var(--tr-green); font-weight: 600; margin-top: 2px; display: block;
}
.trail-card-arrow {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .88rem; font-weight: 600; color: var(--tr-green);
  margin-top: 14px;
}

/* ── CHIP (difficoltà e generic) ──────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 12px; border-radius: 100px;
  font-size: .82rem; font-weight: 700; letter-spacing: .3px;
  white-space: nowrap;
}
/* Generic white chip (hero) */
.chip-white {
  background: rgba(255,255,255,.18); backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,.3); color: #fff;
}
/* Difficoltà */
.chip-diff { border: none; }
.chip-diff[data-diff^="T"]  { background: #DCFCE7; color: #14532D; }
.chip-diff[data-diff^="E-"],
.chip-diff[data-diff^="E "] { background: #FEF3C7; color: #92400E; }
.chip-diff[data-diff^="EE"] { background: #FEE2E2; color: #991B1B; }

/* ── SINGLE HERO ──────────────────────────────────────────────── */
.trail-single { background: #fff; }
.trail-hero {
  position: relative; min-height: 70vh;
  background-size: cover; background-position: center;
  display: flex; flex-direction: column; justify-content: flex-end;
}
.trail-hero::before {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(180deg,
    rgba(0,0,0,.08) 0%,
    rgba(0,0,0,.25) 40%,
    rgba(0,0,0,.82) 100%);
}
.trail-hero-inner {
  position: relative; z-index: 1;
  max-width: 1180px; margin: 0 auto; width: 100%;
  padding: 48px 28px 52px;
}
.trail-breadcrumb {
  display: flex; align-items: center; gap: 8px;
  font-size: .85rem; color: rgba(255,255,255,.7);
  margin-bottom: 20px;
}
.trail-breadcrumb a { color: rgba(255,255,255,.7); text-decoration: none; }
.trail-breadcrumb a:hover { color: #fff; }
.trail-breadcrumb span { opacity: .5; }
.trail-num-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--tr-green); color: #fff;
  padding: 5px 14px; border-radius: 6px;
  font-size: .82rem; font-weight: 700; letter-spacing: 1px;
  text-transform: uppercase; margin-bottom: 14px;
}
.trail-hero h1 {
  font-family: 'Playfair Display', serif;
  font-size: clamp(2.5rem, 6vw, 4.5rem);
  font-weight: 700; line-height: 1.05; margin: 0 0 24px; color: #fff;
  text-shadow: 0 2px 32px rgba(0,0,0,.4);
}
.trail-hero-chips { display: flex; flex-wrap: wrap; gap: 10px; }

/* ── STATS BAR ────────────────────────────────────────────────── */
.trail-statsbar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  background: #fff;
  border: 1px solid var(--tr-border);
  border-radius: var(--tr-radius-lg);
  box-shadow: var(--tr-shadow-md);
  overflow: hidden;
  margin: -32px 28px 0;
  position: relative; z-index: 10;
  max-width: 1124px;
}
.stat-cell {
  padding: 20px 16px;
  border-right: 1px solid var(--tr-border);
  display: flex; flex-direction: column;
  align-items: center; text-align: center; gap: 6px;
}
.stat-cell:last-child { border-right: none; }
.stat-icon { font-size: 1.4rem; line-height: 1; }
.stat-val {
  font-size: 1.25rem; font-weight: 700;
  color: var(--tr-green-dk); line-height: 1;
}
.stat-label {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .8px;
  color: var(--tr-muted); font-weight: 600;
}

/* ── SINGLE BODY ──────────────────────────────────────────────── */
.trail-body {
  max-width: 1180px; margin: 56px auto 0;
  padding: 0 28px 160px;
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 48px;
}
.trail-body-main { min-width: 0; }
.trail-body-side {}

/* ── SECTION TITLES ───────────────────────────────────────────── */
.trail-section-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.5rem; color: var(--tr-green-dk);
  margin: 0 0 16px; padding-bottom: 12px;
  border-bottom: 2px solid var(--tr-green-lt);
}

/* ── MAP SECTION ──────────────────────────────────────────────── */
.trail-map-section { margin-bottom: 40px; }
.trail-map-single { height: 460px; margin-bottom: 6px; }

/* ── DESCRIPTION ──────────────────────────────────────────────── */
.trail-desc-section { margin-bottom: 40px; }
.trail-content {
  font-size: 1.06rem; line-height: 1.8; color: #374151;
}
.trail-content p { margin: 0 0 1.1em; }
.trail-content p:last-child { margin-bottom: 0; }

/* ── WARNING ──────────────────────────────────────────────────── */
.trail-warning-section {
  background: #FFFBEB;
  border: 1px solid #FDE68A;
  border-left: 4px solid var(--tr-amber);
  border-radius: var(--tr-radius-md);
  padding: 20px 22px;
  margin-bottom: 40px;
}
.trail-warning-section h3 {
  margin: 0 0 10px; font-size: 1rem; font-weight: 700;
  color: #92400E; display: flex; align-items: center; gap: 8px;
}
.trail-warning-section p { margin: 0; color: #78350F; line-height: 1.65; font-size: .95rem; }

/* ── SIDEBAR ──────────────────────────────────────────────────── */
.trail-sidebar-card {
  background: #fff; border: 1px solid var(--tr-border);
  border-radius: var(--tr-radius-lg); overflow: hidden;
  box-shadow: var(--tr-shadow-sm); margin-bottom: 20px;
}
.sidebar-card-head {
  background: var(--tr-green-lt); padding: 14px 18px;
  font-size: .78rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1px; color: var(--tr-green-dk);
}
.sidebar-card-body { padding: 16px 18px; }

/* Pulsanti azioni GPX/app */
.action-btn {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-radius: var(--tr-radius-md);
  text-decoration: none; color: var(--tr-text);
  border: 1px solid var(--tr-border);
  background: #fff; transition: all .2s; margin-bottom: 10px;
  font-size: .92rem;
}
.action-btn:last-child { margin-bottom: 0; }
.action-btn:hover {
  border-color: var(--tr-green);
  background: var(--tr-green-lt);
  transform: translateX(3px);
}
.action-btn.primary {
  background: var(--tr-green); color: #fff;
  border-color: var(--tr-green);
}
.action-btn.primary:hover {
  background: var(--tr-green-dk); border-color: var(--tr-green-dk);
}
.action-btn-icon { font-size: 1.4rem; flex-shrink: 0; }
.action-btn-text strong { display: block; font-weight: 700; font-size: .95rem; }
.action-btn-text span { display: block; font-size: .8rem; opacity: .7; margin-top: 1px; }
.action-btn.primary .action-btn-text span { opacity: .85; }

/* Dettagli extra sidebar */
.trail-detail-list { list-style: none; margin: 0; padding: 0; }
.trail-detail-list li {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 9px 0; border-bottom: 1px solid var(--tr-border);
  font-size: .9rem;
}
.trail-detail-list li:last-child { border-bottom: none; }
.trail-detail-list .dl-label { color: var(--tr-muted); font-size: .82rem; font-weight: 500; }
.trail-detail-list .dl-val { font-weight: 600; color: var(--tr-text); }

/* Offline tip */
.offline-tip {
  background: #EFF6FF; border: 1px solid #BFDBFE;
  border-radius: var(--tr-radius-md); padding: 16px 18px;
}
.offline-tip h4 {
  margin: 0 0 8px; font-size: .92rem; font-weight: 700; color: #1E40AF;
}
.offline-tip p { margin: 0; font-size: .85rem; color: #1D4ED8; line-height: 1.6; }
.offline-tip a { color: #1D4ED8; font-weight: 600; }

/* ── MAP MARKERS CUSTOM ───────────────────────────────────────── */
.trail-marker-icon {
  width: 30px; height: 30px;
  background: var(--tr-green); color: #fff;
  border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  border: 2px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700;
}
.trail-marker-icon span { transform: rotate(45deg); display: block; }
.trail-popup strong a {
  color: var(--tr-green-dk); text-decoration: none; font-size: .95rem;
}
.trail-popup strong a:hover { text-decoration: underline; }
.tp-meta { display: flex; gap: 10px; margin-top: 6px; font-size: .82rem; color: var(--tr-muted); }

/* ── STICKY BAR (mobile) ──────────────────────────────────────── */
.trail-stickybar {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: #fff; border-top: 1px solid var(--tr-border);
  padding: 12px 16px; z-index: 1000;
  display: none; align-items: center; gap: 12px;
  box-shadow: 0 -4px 24px rgba(0,0,0,.1);
}
.sb-stats { display: flex; gap: 0; flex: 1; }
.sb-stat {
  flex: 1; text-align: center; padding: 4px 8px;
  border-right: 1px solid var(--tr-border);
}
.sb-stat:last-child { border-right: none; }
.sb-stat b { display: block; font-size: .95rem; color: var(--tr-green-dk); font-weight: 700; }
.sb-stat span { display: block; font-size: .65rem; text-transform: uppercase; letter-spacing: .5px; color: var(--tr-muted); }
.sb-cta {
  background: var(--tr-green); color: #fff;
  padding: 12px 20px; border-radius: var(--tr-radius-md);
  font-weight: 700; font-size: .9rem; text-decoration: none;
  white-space: nowrap; flex-shrink: 0;
}

/* ── LEAFLET ELEVATION THEME ──────────────────────────────────── */
.leaflet-control-elevation {
  background: rgba(255,255,255,.97) !important;
  border: 1px solid var(--tr-border) !important;
  border-radius: 0 0 var(--tr-radius-lg) var(--tr-radius-lg) !important;
  backdrop-filter: blur(8px);
  font-family: 'DM Sans', sans-serif !important;
}
/* ── ELEVATION CHART ──────────────────────────────────────────── */
.trail-elevation-chart {
  background: #fff; border: 1px solid var(--tr-border);
  border-top: none; border-radius: 0 0 var(--tr-radius-lg) var(--tr-radius-lg);
  overflow: hidden; width: 100%;
}
.elev-svg { display: block; width: 100%; height: auto; }

/* ── MAP SECTION TITLE BAR ────────────────────────────────────── */
.trail-section-titlebar {
  display: flex; align-items: baseline;
  gap: 14px; flex-wrap: wrap; margin-bottom: 14px;
}
.trail-section-titlebar .trail-section-title { margin-bottom: 0; border-bottom: none; }
.trail-gps-hint {
  font-size: .82rem; color: var(--tr-green); font-weight: 500;
  background: var(--tr-green-lt); padding: 4px 12px; border-radius: 100px;
}

/* ── GPS LOCATE BUTTON ────────────────────────────────────────── */
.trail-locate-btn {
  display: flex !important; align-items: center; justify-content: center;
  width: 32px; height: 32px; font-size: 1.2rem;
  background: #fff; cursor: pointer; border: none;
  box-shadow: none; margin-top: 6px !important;
  transition: background .2s;
}
.trail-locate-btn:hover { background: #f0fdf4 !important; }
.trail-locate-btn.active {
  background: #f0fdf4 !important;
  box-shadow: inset 0 0 0 2px var(--tr-green) !important;
}

/* ── TRAIL START/END MARKERS ──────────────────────────────────── */
.trail-pt-start, .trail-pt-end {
  background: #fff; border: 2px solid var(--tr-green);
  border-radius: 4px; padding: 2px 8px;
  font-size: 11px; font-weight: 700; color: var(--tr-green-dk);
  white-space: nowrap; box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.trail-pt-end { border-color: #DC2626; color: #DC2626; }

/* ── SIDEBAR NOTE ─────────────────────────────────────────────── */
.sidebar-note {
  font-size: .85rem; color: var(--tr-muted); margin: 0 0 12px;
  line-height: 1.5;
}

/* ── GPX ERROR ────────────────────────────────────────────────── */
.trail-gpx-error {
  background: #FEF2F2; border: 1px solid #FECACA; color: #991B1B;
  padding: 12px 16px; border-radius: var(--tr-radius-md); font-size: .9rem;
  margin-top: 8px;
}

/* ── POPUP OVERVIEW MAP ───────────────────────────────────────── */
.tp-link {
  display: inline-block; margin-top: 8px; font-size: .85rem;
  font-weight: 600; color: var(--tr-green); text-decoration: none;
}
.tp-link:hover { text-decoration: underline; }

/* ── RESPONSIVE ───────────────────────────────────────────────── */
@media (max-width: 900px) {
  .trail-body {
    grid-template-columns: 1fr;
    padding: 0 20px 140px;
    margin-top: 32px;
    gap: 32px;
  }
  .trail-body-side { order: -1; }
  .trail-statsbar { margin: -24px 16px 0; }
  .trail-stickybar { display: flex; }
  .trail-map-single { height: 340px; }
  .trail-map-overview { height: 380px; }
  .trail-hero h1 { font-size: 2.2rem; }
  .trail-hero-inner { padding: 32px 20px 40px; }
}
@media (max-width: 600px) {
  .trail-statsbar { margin: -20px 12px 0; }
  .stat-cell { padding: 14px 10px; }
  .stat-val { font-size: 1.05rem; }
  .trail-grid { grid-template-columns: 1fr; }
}

/* Nascondi sb-* anche desktop */
@media (min-width: 901px) { .trail-stickybar { display: none !important; } }
