:root {
  --header-height: 56px;
  --radius: 8px;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --bg-primary: #0a1628;
  --bg-secondary: #12233d;
  --bg-card: #1a2e4a;
  --bg-hover: #223a56;
  --accent: #64b5f6;
  --accent-dim: rgba(100, 181, 246, 0.15);
  --text: #e8eaed;
  --text-muted: #9aa0a6;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: rgba(0, 0, 0, 0.4);
  --header-bg: rgba(10, 22, 40, 0.92);
  --panel-bg: rgba(12, 25, 45, 0.92);
}

[data-theme="warm"] {
  --bg-primary: #2c1e12;
  --bg-secondary: #3d2b1a;
  --bg-card: #4a3525;
  --bg-hover: #5c4430;
  --accent: #e8a838;
  --accent-dim: rgba(232, 168, 56, 0.15);
  --text: #f5ede4;
  --text-muted: #b8a898;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: rgba(0, 0, 0, 0.5);
  --header-bg: rgba(44, 30, 18, 0.92);
  --panel-bg: rgba(44, 30, 18, 0.92);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg-primary);
  color: var(--text);
  overflow: hidden;
  height: 100vh;
}

/* Header */
header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 1000;
}

.logo {
  font-size: 1.2rem;
  font-weight: 700;
  white-space: nowrap;
}

.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-secondary);
  padding: 4px;
  border-radius: 20px;
}

.tab {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 6px 16px;
  border-radius: 16px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  background: var(--accent);
  color: #000;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.stats-bar {
  display: flex;
  gap: 16px;
}

.stat {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.stat strong {
  color: var(--accent);
  font-weight: 600;
}

.theme-toggle {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.theme-toggle:hover {
  background: var(--bg-hover);
  transform: scale(1.1);
}

/* Pages */
main {
  margin-top: var(--header-height);
  height: calc(100vh - var(--header-height));
}

.page {
  display: none;
  height: 100%;
}

.page.active {
  display: block;
}

/* Map */
#map {
  width: 100%;
  height: 100%;
}

.leaflet-container {
  background: var(--bg-primary);
}

/* ─── Trips Control Panel (Leaflet topleft) ─────────────────── */
.trips-panel {
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 230px;
  max-width: 300px;
  overflow: hidden;
  box-shadow: 0 4px 16px var(--shadow);
}

.trips-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
}

.trips-panel-header:hover {
  background: var(--bg-hover);
}

.trips-panel-header-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.trips-panel-chevron {
  font-size: 0.75rem;
  color: var(--text-muted);
  transition: transform 0.2s ease;
}

.trips-panel.expanded .trips-panel-chevron {
  transform: rotate(180deg);
}

.trips-panel-body {
  display: none;
  border-top: 1px solid var(--border);
  max-height: calc(100vh - var(--header-height) - 60px);
  overflow-y: auto;
}

.trips-panel.expanded .trips-panel-body {
  display: block;
}

/* Panel sections */
.panel-section {
  border-bottom: 1px solid var(--border);
}

.panel-section:last-child {
  border-bottom: none;
}

.section-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background var(--transition);
  user-select: none;
}

.section-toggle:hover {
  background: var(--bg-hover);
}

.section-icon {
  font-size: 1rem;
  flex-shrink: 0;
}

.section-label {
  flex: 1;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
}

.section-chevron {
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.toggle-switch {
  width: 34px;
  height: 18px;
  border-radius: 9px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  position: relative;
  flex-shrink: 0;
  transition: var(--transition);
}

.toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: var(--transition);
}

.toggle-switch.on {
  background: var(--accent);
  border-color: var(--accent);
}

.toggle-switch.on::after {
  left: 18px;
  background: #000;
}

.section-list {
  max-height: 400px;
  overflow-y: auto;
}

.section-list.collapsed {
  display: none;
}

/* Trip toggle buttons
   .trips-panel prefix beats Leaflet's .leaflet-bar a { color:black; bg:#fff }
   specificity: 0-2-0 > 0-1-1                                               */

.trips-panel .trip-toggle-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  cursor: pointer;
  color: var(--text);
  background: transparent;
  text-decoration: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  transition: var(--transition);
}

.trips-panel .trip-toggle-btn:last-child {
  border-bottom: none;
}

.trips-panel .trip-toggle-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.trips-panel .trip-toggle-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.trips-panel .trip-toggle-btn.active .trip-toggle-year {
  color: var(--accent);
  opacity: 0.75;
}

.trip-toggle-icon {
  flex-shrink: 0;
  font-size: 1.1rem;
  line-height: 1;
  align-self: flex-start;
  margin-top: 1px;
}

/* Two-line layout: name on top, year below */
.trip-toggle-content {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0; /* allow text truncation inside flex */
}

.trip-toggle-name {
  font-size: 0.83rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.trip-toggle-year {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Trips Page */
.trips-container {
  padding: 24px;
  max-width: 900px;
  margin: 0 auto;
  overflow-y: auto;
  height: 100%;
}

.trips-container h2 {
  margin-bottom: 16px;
  font-size: 1.1rem;
}

.trip-detail {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.trip-detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.trip-detail-icon {
  font-size: 2rem;
}

.trip-detail-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.trip-detail-subtitle {
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* Distance badge — shown on linear (route) trips in the Trips page */
.trip-distance-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--accent);
  margin-top: 5px;
  letter-spacing: 0.01em;
}

.trip-stops {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.trip-stop {
  font-size: 0.78rem;
  padding: 4px 10px;
  background: var(--bg-secondary);
  border-radius: 12px;
  color: var(--text-muted);
}

/* Stats Page */
.stats-container {
  padding: 24px;
  max-width: 900px;
  margin: 0 auto;
  overflow-y: auto;
  height: 100%;
}

/* Sticky header: h2 + person selector */
.stats-sticky-header {
  position: sticky;
  top: -24px;          /* cancels the container's 24px top padding */
  background: var(--bg-primary);
  margin: -24px -24px 0;
  padding: 24px 24px 16px;
  border-bottom: 1px solid var(--border);
  z-index: 5;
}

.stats-sticky-header h2 {
  margin-bottom: 14px;
  font-size: 1.1rem;
}

/* Person selector — pill-style buttons */
.person-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.person-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  transition: var(--transition);
}

.person-btn:hover {
  background: var(--bg-hover);
}

.person-btn.active {
  background: var(--person-color);
  border-color: var(--person-color);
  color: #000;
  font-weight: 600;
}

/* Stats content — scrollable body below the sticky header */
.stats-content {
  padding-top: 24px;
}

/* Country chips */
.country-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.country-chip {
  font-size: 0.78rem;
  padding: 4px 10px;
  background: var(--bg-secondary);
  border-radius: 12px;
  color: var(--text-muted);
}

/* Section heading in per-person stats */
.stats-section-heading {
  margin-top: 28px;
  margin-bottom: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

/* Trip history rows */
.stats-trip-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
}

.stats-trip-icon {
  font-size: 1.4rem;
  flex-shrink: 0;
}

.stats-trip-info {
  min-width: 0;
}

.stats-trip-name {
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stats-trip-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
}

.stat-card-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
}

.stat-card-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Leaflet Popup Override */
.leaflet-popup-content-wrapper {
  background: var(--bg-card);
  color: var(--text);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px var(--shadow);
  border: 1px solid var(--border);
}

.leaflet-popup-tip {
  background: var(--bg-card);
}

.leaflet-popup-content {
  margin: 12px 16px;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.85rem;
  line-height: 1.5;
}

.popup-title {
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 4px;
}

.popup-meta {
  color: var(--text-muted);
  font-size: 0.78rem;
}

/* Thumbtack / pushpin markers */
.map-tack {
  transition: transform 0.15s ease;
  transform-origin: center bottom; /* scale from needle tip = exact map location */
}

.map-tack:hover {
  transform: scale(1.25);
}

.hub-marker {
  font-size: 1.6rem;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
}

.cluster-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 0.8rem;
  font-weight: 700;
  color: #000;
  border: 3px solid rgba(255,255,255,0.85);
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

.marker-cluster {
  background: transparent !important;
}

.marker-cluster div {
  background: transparent !important;
}

/* Responsive */
@media (max-width: 768px) {
  .header-left .logo {
    font-size: 1rem;
  }

  .stats-bar {
    display: none;
  }

  .tab {
    padding: 6px 12px;
    font-size: 0.8rem;
  }

  .trips-panel {
    min-width: 160px;
    max-width: 210px;
  }

  .trips-panel-header {
    padding: 8px 10px;
  }

  .trips-panel-header-label {
    font-size: 0.8rem;
  }

  .trips-panel-body {
    max-height: calc(100vh - var(--header-height) - 80px);
  }

  .section-toggle {
    padding: 7px 10px;
    gap: 5px;
  }

  .section-label {
    font-size: 0.75rem;
  }

  .section-icon {
    font-size: 0.85rem;
  }

  .toggle-switch {
    width: 28px;
    height: 15px;
    border-radius: 8px;
  }

  .toggle-switch::after {
    width: 9px;
    height: 9px;
  }

  .toggle-switch.on::after {
    left: 15px;
  }

  .trips-panel .trip-toggle-btn {
    padding: 6px 10px;
    gap: 6px;
  }

  .trip-toggle-name {
    font-size: 0.78rem;
  }

  .trip-toggle-year {
    font-size: 0.65rem;
  }

  .trip-toggle-icon {
    font-size: 0.95rem;
  }

  .section-list {
    max-height: 260px;
  }
}

/* ─── Trip photo galleries ─────────────────────────────────────────────── */
.trip-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 6px;
  margin-top: 14px;
}

.trip-gallery-thumb {
  padding: 0;
  border: none;
  cursor: pointer;
  aspect-ratio: 1 / 1;
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg-hover);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.trip-gallery-thumb:hover {
  transform: scale(1.04);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}

.trip-gallery-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;   /* uniform square tiles regardless of orientation */
  display: block;
}

/* ─── Lightbox overlay ─────────────────────────────────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(4px);
}

.lightbox.open { display: flex; }

.lightbox-img {
  max-width: 90vw;
  max-height: 88vh;
  border-radius: 8px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.6);
}

.lightbox-close,
.lightbox-nav {
  position: absolute;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.15s ease;
}

.lightbox-close:hover,
.lightbox-nav:hover { background: rgba(255, 255, 255, 0.28); }

.lightbox-close {
  top: 18px;
  right: 22px;
  width: 44px;
  height: 44px;
  font-size: 1.8rem;
  line-height: 1;
}

.lightbox-nav {
  top: 50%;
  transform: translateY(-50%);
  width: 52px;
  height: 52px;
  font-size: 2.4rem;
  line-height: 1;
}

.lightbox-prev { left: 18px; }
.lightbox-next { right: 18px; }

.lightbox-counter {
  position: absolute;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.9rem;
  letter-spacing: 0.04em;
}

@media (max-width: 600px) {
  .lightbox-nav { width: 42px; height: 42px; font-size: 1.9rem; }
  .lightbox-prev { left: 8px; }
  .lightbox-next { right: 8px; }
}
