/* Pilgrim Explorer - Mobile-first, performance-optimized */

* { box-sizing: border-box; }

:root {
  --primary: #1a5f4a;
  --primary-hover: #145a44;
  --accent: #2e7d63;
  --bg-sidebar: #fff;
  --bg-country: #f0f7f4;
  --bg-country-hover: #e0efe8;
  --border: #e0e0e0;
  --text: #1a1a1a;
  --text-muted: #555;
  --shadow: 0 2px 8px rgba(0,0,0,0.1);
  --radius: 8px;
  --radius-sm: 6px;
  --touch-min: 44px;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  padding: 0.5rem 1rem;
  min-height: var(--touch-min);
  background: var(--primary);
  color: white;
  flex-shrink: 0;
}

.menu-btn {
  background: none;
  border: none;
  color: white;
  font-size: 1.5rem;
  padding: 0.5rem;
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  cursor: pointer;
  margin: -0.5rem 0.25rem -0.5rem -0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.close-btn {
  background: none;
  border: none;
  color: white;
  font-size: 1.5rem;
  padding: 0.5rem;
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  cursor: pointer;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.title { margin: 0; font-size: 1.1rem; flex: 1; }

.dashboard-link {
  color: rgba(255,255,255,0.95);
  font-size: 0.9rem;
  text-decoration: none;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
}
.dashboard-link:hover { background: rgba(255,255,255,0.15); }

/* Sidebar */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 999;
  -webkit-tap-highlight-color: transparent;
}
.sidebar-backdrop.visible { display: block; }

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 300px;
  max-width: 90vw;
  height: 100vh;
  height: 100dvh;
  background: var(--bg-sidebar);
  box-shadow: 2px 0 12px rgba(0,0,0,0.15);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
}
.sidebar.open { transform: translateX(0); }

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  min-height: var(--touch-min);
  background: var(--primary);
  color: white;
  flex-shrink: 0;
}
.sidebar-header h2 { margin: 0; font-size: 1.1rem; font-weight: 600; }

/* Filters */
.filters-panel {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: #fafafa;
  flex-shrink: 0;
}

.filter-group {
  margin-bottom: 0.75rem;
}
.filter-group:last-child { margin-bottom: 0; }

.filter-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.filter-select,
#searchInput {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  background: white;
  min-height: 38px;
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.filter-chip {
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
  background: white;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s ease;
}

.filter-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.filter-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

/* Country list - collapsed by default */
.route-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

.country-header {
  padding: 0.6rem 1rem;
  background: var(--bg-country);
  font-weight: 600;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  min-height: var(--touch-min);
  transition: background 0.15s;
}

.country-header:hover { background: var(--bg-country-hover); }

.country-chevron {
  font-size: 1rem;
  transition: transform 0.2s ease;
  color: var(--text-muted);
  flex-shrink: 0;
}

.country-header.expanded .country-chevron { transform: rotate(90deg); }

.country-name { flex: 1; }

.country-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
  background: rgba(0,0,0,0.06);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}

.country-routes {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  list-style: none;
  margin: 0;
  padding: 0;
}
.country-routes.expanded { max-height: 3000px; }

.country-routes-inner { border-bottom: 1px solid var(--border); }

.route-item {
  padding: 0.65rem 1rem 0.65rem 2rem;
  cursor: pointer;
  border-bottom: 1px solid #eee;
  transition: background 0.15s;
  min-height: var(--touch-min);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.route-item:hover { background: #f8f8f8; }

.route-item.active {
  background: #e8f5e9;
  border-left: 3px solid var(--primary);
  padding-left: calc(2rem - 3px);
}

.route-item.loading-route { opacity: 0.7; pointer-events: none; }

.route-item.loading-route::after {
  content: '...';
  margin-left: 0.25rem;
  animation: blink 0.8s infinite;
}

@keyframes blink {
  0%, 50% { opacity: 0; }
  100% { opacity: 1; }
}

.route-name { font-weight: 500; font-size: 0.95rem; }

.route-meta { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.15rem; }

/* Map */
.map-container {
  flex: 1;
  position: relative;
  min-height: 0;
}

#map {
  width: 100%;
  height: 100%;
  background: #e8e8e8;
}

.map-overlay {
  position: absolute;
  bottom: 1rem;
  left: 1rem;
  right: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  background: white;
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 500;
}

.overlay-option {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0.25rem 0;
}

.poi-marker, .sanctuary-marker { background: transparent; border: none; }

/* Loading */
body.loading .map-container::after {
  content: attr(data-loading);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: white;
  padding: 1rem 1.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 1000;
  font-size: 0.95rem;
}

.error { padding: 2rem; font-family: sans-serif; }
.error h2 { color: #c62828; }

/* Desktop */
@media (min-width: 768px) {
  .app { flex-direction: row; }
  .header { display: none; }
  .sidebar {
    position: relative;
    transform: none;
    flex-shrink: 0;
    box-shadow: none;
    border-right: 1px solid var(--border);
  }
  .sidebar .close-btn { display: none; }
  .map-container { flex: 1; }
  .map-overlay {
    left: 1rem;
    right: auto;
  }
}

/* Mobile: safe area */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .map-overlay { padding-bottom: calc(0.6rem + env(safe-area-inset-bottom)); }
}
