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

:root {
  --green-dark:   #1b4332;
  --green-mid:    #2d6a4f;
  --green-light:  #52b788;
  --green-pale:   #d8f3dc;
  --stone:        #6b5b4e;
  --stone-light:  #f5efe8;
  --sky:          #0077b6;
  --sky-light:    #caf0f8;
  --text:         #1a1a1a;
  --text-muted:   #6b7280;
  --border:       #e5e7eb;
  --white:        #ffffff;
  --radius:       8px;
  --shadow:       0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:    0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  background: var(--white);
  line-height: 1.6;
}

a { color: var(--green-mid); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Layout ===== */
.container { max-width: 1100px; margin: 0 auto; padding: 0 1.25rem; }

/* ===== Header / nav ===== */
.site-header {
  background: var(--green-dark);
  color: var(--white);
  padding: .875rem 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.site-logo {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--white);
  letter-spacing: -.5px;
}
.site-logo span { color: var(--green-light); }

.site-tagline {
  font-size: .8rem;
  color: var(--green-pale);
  opacity: .85;
}

/* ===== Hero ===== */
.hero {
  background: linear-gradient(135deg, var(--green-dark) 0%, var(--green-mid) 60%, var(--green-light) 100%);
  color: var(--white);
  padding: 3.5rem 0 3rem;
  text-align: center;
}

.hero h1 {
  font-size: clamp(1.75rem, 4vw, 2.75rem);
  font-weight: 800;
  margin-bottom: .5rem;
  letter-spacing: -.5px;
}

.hero p {
  font-size: 1.1rem;
  opacity: .9;
  max-width: 540px;
  margin: 0 auto;
}

/* ===== Filters ===== */
.filters-bar {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 1rem 0;
  position: sticky;
  top: 56px;
  z-index: 90;
}

.filters-inner {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  align-items: center;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
}

.filter-label {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  white-space: nowrap;
}

.filter-btn {
  padding: .35rem .85rem;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  background: var(--white);
  color: var(--text);
  font-size: .825rem;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.filter-btn:hover { border-color: var(--green-mid); color: var(--green-mid); }
.filter-btn.active {
  background: var(--green-mid);
  border-color: var(--green-mid);
  color: var(--white);
  font-weight: 600;
}

.filter-select {
  padding: .35rem .75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--white);
  font-size: .825rem;
  color: var(--text);
  cursor: pointer;
  outline: none;
}
.filter-select:focus { border-color: var(--green-mid); }

.filter-divider { width: 1px; height: 24px; background: var(--border); }

#trail-count {
  margin-left: auto;
  font-size: .8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ===== Trail grid ===== */
.trails-section { padding: 2rem 0 3rem; }

.trails-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.25rem;
}

/* ===== Trail card ===== */
.trail-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform .15s, box-shadow .15s;
  cursor: pointer;
  display: flex;
  flex-direction: column;
}
.trail-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.trail-card-header {
  background: linear-gradient(135deg, var(--green-dark), var(--green-mid));
  padding: 1.1rem 1.1rem .75rem;
  color: var(--white);
}

.trail-card-header h3 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: .3rem;
}

.trail-badges {
  display: flex;
  gap: .4rem;
  flex-wrap: wrap;
}

.badge {
  display: inline-block;
  padding: .15rem .55rem;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .2px;
}

.badge-region {
  background: rgba(255,255,255,.2);
  color: var(--white);
}

.badge-easy   { background: #d1fae5; color: #065f46; }
.badge-moderate { background: #fef3c7; color: #92400e; }
.badge-hard   { background: #fee2e2; color: #991b1b; }

.trail-card-body { padding: 1rem 1.1rem; flex: 1; }

.trail-stats {
  display: flex;
  gap: 1.25rem;
  margin-bottom: .75rem;
}

.stat { display: flex; flex-direction: column; }
.stat-value { font-size: 1.05rem; font-weight: 700; color: var(--green-dark); }
.stat-label { font-size: .7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .3px; }

.trail-desc {
  font-size: .85rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.trail-card-footer {
  padding: .75rem 1.1rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.seasons-list {
  display: flex;
  gap: .3rem;
}

.season-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .65rem;
  font-weight: 700;
}
.season-dot.active   { background: var(--green-light); color: var(--green-dark); }
.season-dot.inactive { background: var(--border); color: var(--text-muted); }

.card-link {
  font-size: .8rem;
  font-weight: 600;
  color: var(--green-mid);
}

/* ===== Empty state ===== */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}
.empty-state p { font-size: 1rem; }

/* ===== Footer ===== */
.site-footer {
  background: var(--green-dark);
  color: var(--green-pale);
  padding: 2rem 0;
  font-size: .85rem;
  margin-top: 2rem;
}
.site-footer .container { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 1rem; }
.site-footer a { color: var(--green-light); }

/* ===========================
   TRAIL DETAIL PAGE
   =========================== */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: 1rem 0 .5rem;
  font-size: .875rem;
  color: var(--green-mid);
  font-weight: 500;
}
.back-link:hover { text-decoration: none; color: var(--green-dark); }

.trail-hero {
  background: linear-gradient(135deg, var(--green-dark) 0%, var(--green-mid) 100%);
  color: var(--white);
  padding: 2.25rem 0 2rem;
}

.trail-hero h1 { font-size: clamp(1.5rem, 3vw, 2.25rem); font-weight: 800; margin-bottom: .5rem; }

.trail-hero-meta { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .75rem; }

.trail-stats-bar {
  display: flex;
  gap: 2rem;
  flex-wrap: wrap;
  background: var(--stone-light);
  padding: 1.25rem 0;
  border-bottom: 1px solid var(--border);
}

.trail-stats-bar .stat-value { font-size: 1.3rem; }

/* ===== Map area (Leaflet + Overpass) ===== */
.map-section { padding: 1.5rem 0; }
.map-section h2 { font-size: 1rem; font-weight: 700; margin-bottom: .75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }

.map-wrapper { position: relative; }

/* Leaflet needs display:block and explicit height on its container */
.map-frame {
  width: 100%;
  height: 420px;
  border-radius: var(--radius) var(--radius) 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
  position: relative;
  overflow: hidden;
  display: block;
  background: var(--green-pale);
}

/* Shown while OSM tiles are loading; hidden once map fires its 'load' event */
.map-loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .75rem;
  background: var(--green-pale);
  z-index: 500;
  pointer-events: none;
}

/* Status bar below the map frame */
.map-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .5rem;
  padding: .4rem .75rem;
  background: var(--stone-light);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
}

/* Overpass API status badge */
.overpass-status {
  font-size: .72rem;
  font-weight: 600;
  padding: .15rem .5rem;
  border-radius: 4px;
}
.overpass-status.loading { background: #dbeafe; color: #1e40af; }
.overpass-status.ok      { background: #d1fae5; color: #065f46; }
.overpass-status.error   { background: #fee2e2; color: #991b1b; }

/* Custom backend API status badge */
.map-api-status {
  font-size: .7rem;
  font-weight: 600;
  padding: .15rem .5rem;
  border-radius: 4px;
}
.map-api-status.pending { background: #fef3c7; color: #92400e; }
.map-api-status.error   { background: #fee2e2; color: #991b1b; }
.map-api-status.ok      { background: #d1fae5; color: #065f46; }

/* POI legend strip shown below map-footer after Overpass responds */
.poi-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .45rem;
  padding: .55rem .75rem;
  background: var(--white);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  font-size: .78rem;
  margin-top: -1px;
}
.legend-title { font-weight: 700; color: var(--text-muted); }
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: .2rem;
  background: var(--stone-light);
  padding: .15rem .5rem;
  border-radius: 999px;
  color: var(--stone);
}

/* ===== Overview map (index page) ===== */
.overview-map-section { padding: 1.75rem 0 0; background: var(--white); }

.section-heading {
  font-size: 1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  margin-bottom: .75rem;
}

.overview-map {
  width: 100%;
  height: 300px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}

.map-hint {
  font-size: .75rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: .4rem;
  padding-bottom: 1.25rem;
}

/* ===== Detail sections ===== */
.detail-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 2rem;
  padding: 1.5rem 0 3rem;
}

@media (max-width: 720px) {
  .detail-grid { grid-template-columns: 1fr; }
  .trail-stats-bar { gap: 1rem; }
  .filters-inner { gap: .5rem; }
}

.detail-section h2 {
  font-size: 1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  margin-bottom: .75rem;
  padding-bottom: .4rem;
  border-bottom: 1px solid var(--border);
}

.detail-section p { font-size: .95rem; line-height: 1.7; margin-bottom: 1rem; }

.info-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.info-table tr { border-bottom: 1px solid var(--border); }
.info-table tr:last-child { border-bottom: none; }
.info-table td { padding: .6rem .25rem; vertical-align: top; }
.info-table td:first-child { font-weight: 600; color: var(--text-muted); width: 40%; }

.trailhead-coords {
  font-family: monospace;
  font-size: .8rem;
  background: var(--stone-light);
  padding: .5rem .75rem;
  border-radius: 4px;
  margin-top: .5rem;
  display: flex;
  gap: 1rem;
}

.seasons-grid {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  margin-top: .4rem;
}

.season-chip {
  padding: .25rem .65rem;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 600;
}
.season-chip.active   { background: var(--green-pale); color: var(--green-dark); }
.season-chip.inactive { background: var(--border); color: var(--text-muted); }

/* ===== Loading state ===== */
.loading-spinner {
  display: inline-block;
  width: 1.5rem;
  height: 1.5rem;
  border: 3px solid var(--border);
  border-top-color: var(--green-mid);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#trail-detail-content { display: none; }
#trail-loading { padding: 4rem 0; text-align: center; }

/* ===== Language switcher ===== */
.lang-switcher {
  position: relative;
  flex-shrink: 0;
}

.lang-current {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .35rem .7rem;
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.25);
  border-radius: var(--radius);
  color: var(--white);
  font-size: .825rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s;
}
.lang-current:hover { background: rgba(255,255,255,.2); }

.lang-label { font-weight: 500; }

.lang-chevron { font-size: .6rem; opacity: .75; }

.lang-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + .4rem);
  right: 0;
  min-width: 160px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  z-index: 200;
  overflow: hidden;
  list-style: none;
  padding: .25rem 0;
}
.lang-dropdown.open { display: block; }

.lang-option {
  display: flex;
  align-items: center;
  gap: .5rem;
  width: 100%;
  padding: .5rem .85rem;
  background: none;
  border: none;
  font-size: .85rem;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  transition: background .1s;
}
.lang-option:hover   { background: var(--green-pale); }
.lang-option.active  { font-weight: 700; color: var(--green-dark); background: var(--green-pale); }
