:root {
  /* Modern Palette */
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-surface-dim: #f1f5f9;

  --color-primary: #0f766e; /* Teal 700 */
  --color-primary-dark: #0d5e56;
  --color-primary-light: #ccfbf1;

  --color-accent: #f59e0b; /* Amber 500 */

  --color-text-main: #1e293b; /* Slate 800 */
  --color-text-muted: #64748b; /* Slate 500 */
  --color-border: #e2e8f0;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
  --shadow-up: 0 -4px 6px -1px rgb(0 0 0 / 0.1);

  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --nav-height: 64px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

.hidden {
  display: none !important;
}

body {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  background-color: var(--color-bg);
  color: var(--color-text-main);
  /* Prevent scroll chaining/rubber banding on mobile body */
  overscroll-behavior: none;
}

/* APP SHELL */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  /* Fix for mobile browser height issues */
  height: 100dvh;
  overflow: hidden;
}

.viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.view {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 0.2s ease,
    visibility 0.2s;
  overflow-y: auto;
  background: var(--color-bg);
  z-index: 1;
}

.view.active {
  opacity: 1;
  visibility: visible;
  z-index: 2;
}

.view-header {
  position: sticky;
  top: 0;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  padding: 1rem;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 10;
}

.view-header h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

/* BOTTOM NAVIGATION */
.bottom-nav {
  height: var(--nav-height);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 50;
  box-shadow: var(--shadow-up);
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-item {
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--color-text-muted);
  font-size: 0.75rem; /* 12px */
  font-weight: 500;
  cursor: pointer;
  width: 100%;
  height: 100%;
  transition: color 0.2s;
}

.nav-item svg {
  width: 24px;
  height: 24px;
}

.nav-item.active {
  color: var(--color-primary);
}

/* MAP VIEW */
#map {
  width: 100%;
  height: 100%;
  /* Fix leaflet z-index context */
  z-index: 1;
}

.map-controls-overlay {
  position: absolute;
  top: 1rem;
  left: 1rem;
  right: 1rem;
  z-index: 400; /* Above Leaflet defaults */
  display: flex;
  justify-content: center;
  pointer-events: none; /* Let clicks pass through around items */
}

.search-bar {
  pointer-events: auto;
  background: var(--color-surface);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-md);
  padding: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  max-width: 400px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}

.filter-summary {
  flex: 1;
  background: var(--color-surface-dim);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-full);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
}

/* LIST & GRID CONTAINERS */
.list-container {
  padding: 1rem;
  display: grid;
  gap: 1rem;
  padding-bottom: 2rem;
}

.content-container {
  padding: 1rem;
  max-width: 600px;
  margin: 0 auto;
}

/* CARDS */
.station-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
  transition: transform 0.1s;
  cursor: pointer;
}

.station-card:active {
  transform: scale(0.98);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.5rem;
}

.card-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.amenity-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.card-title {
  font-weight: 600;
  font-size: 1.05rem;
  margin: 0;
}

.card-distance {
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.card-meta {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  margin-bottom: 0.75rem;
  line-height: 1.4;
}

.card-badges {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.badge {
  font-size: 0.75rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--color-surface-dim);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}

/* MODAL OVERLAY */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(2px);
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: flex-end; /* Bottom sheet by default */
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s;
}

.modal-overlay:not(.hidden) {
  opacity: 1;
  visibility: visible;
}

.modal-content {
  background: var(--color-surface);
  width: 100%;
  max-width: 600px;
  max-height: 90vh; /* Leave some space at top */
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
}

.modal-content.bottom-sheet {
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
}

.modal-content.full-sheet {
  height: 95vh;
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
}

/* MODAL HEADER/BODY/FOOTER */
.modal-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  background: var(--color-surface);
  z-index: 10;
}

.modal-header h3 {
  margin: 0;
}

.close-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  padding: 0 0.5rem;
  cursor: pointer;
  color: var(--color-text-muted);
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  position: sticky;
  bottom: 0;
}

/* FILTER INPUTS */
.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.label-text {
  font-weight: 500;
  font-size: 0.95rem;
}

select {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 1rem;
  background: var(--color-bg);
}

input[type="range"] {
  width: 100%;
}

.range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.amenity-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
  gap: 0.75rem;
}

.amenity-toggle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: transform 0.1s;
}

.amenity-toggle.active {
  transform: scale(1.05);
}

.amenity-toggle img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  filter: grayscale(100%);
  opacity: 0.6;
  transition: filter 0.2s, opacity 0.2s;
}

.amenity-toggle.active img {
  filter: grayscale(0%);
  opacity: 1;
}

.amenity-name {
  font-size: 0.7rem;
  text-align: center;
}

/* BUTTONS */
.primary-btn {
  background: var(--color-primary);
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-md);
  width: 100%;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.text-btn {
  background: none;
  border: 1px solid var(--color-border);
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
}

/* DETAIL MODAL SPECIFIC */
.detail-hero {
  height: 200px;
  min-height: 200px;
  flex: 0 0 200px;
  position: relative;
  background: var(--color-surface-dim);
}

.detail-mini-map {
  width: 100%;
  height: 100%;
}

.mini-amenity-marker {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
}

.mini-amenity-marker img {
  width: 16px;
  height: 16px;
}

.mini-amenity-marker.fallback {
  width: 16px;
  height: 16px;
  color: var(--color-text-muted);
  font-size: 14px;
  line-height: 1;
}

.close-btn-float {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 500;
  background: white;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--color-text-main);
}

.detail-body {
  padding: 1.5rem;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.5rem;
  gap: 1rem;
}

.detail-header h2 {
  margin: 0;
  font-size: 1.5rem;
  line-height: 1.2;
}

.fav-btn-round {
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
}

.fav-btn-round.active {
  color: var(--color-accent);
  fill: var(--color-accent);
}

.detail-address {
  color: var(--color-text-muted);
  margin-bottom: 1.5rem;
}

.detail-stats {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-pill {
  background: var(--color-surface-dim);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-md);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.detail-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  text-decoration: none;
  background: var(--color-primary);
  color: white;
}

.action-btn.secondary {
  background: var(--color-surface-dim);
  color: var(--color-text-main);
  border: 1px solid var(--color-border);
}

.amenity-list-section h3 {
  font-size: 1.1rem;
  margin-bottom: 1rem;
}

.amenity-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.amenity-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem;
  border-radius: 8px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
}

.amenity-item img {
  width: 24px;
  height: 24px;
}

.amenity-detail {
  display: flex;
  flex-direction: column;
}

.amenity-detail-name {
  font-weight: 500;
  font-size: 0.9rem;
}

.amenity-detail-meta {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

/* INFO VIEW */
.info-card {
  background: white;
  padding: 1.5rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  margin-bottom: 1.5rem;
}

.info-card h3 {
  margin-top: 0;
  color: var(--color-primary);
}

.legend-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.legend-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}

.dot.gold {
  background-color: #f59e0b;
}
.dot.silver {
  background-color: #94a3b8;
}
.dot.bronze {
  background-color: #b45309;
}
.dot.grey {
  background-color: #64748b;
}

.link-btn {
  display: inline-block;
  padding: 8px 16px;
  background: var(--color-text-main);
  color: white;
  text-decoration: none;
  border-radius: 6px;
  font-size: 0.9rem;
}

.station-page {
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(15, 118, 110, 0.12), transparent 28rem),
    linear-gradient(180deg, #f8fafc 0%, #eef6f5 100%);
}

.station-shell {
  max-width: 860px;
  margin: 0 auto;
  padding: 24px 18px 56px;
}

.station-hero {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(226, 232, 240, 0.92);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  padding: 28px 22px;
  margin-bottom: 20px;
}

.station-summary {
  margin: 0 0 18px;
  color: var(--color-text-muted);
  line-height: 1.7;
}

.station-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}

.station-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(15, 118, 110, 0.08);
  color: var(--color-primary-dark);
  font-weight: 600;
}

.station-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.station-actions .link-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
}

.station-actions .link-btn.secondary-link {
  background: white;
  color: var(--color-text-main);
  border: 1px solid var(--color-border);
}

.station-list {
  list-style: none;
  padding: 0;
  margin: 16px 0 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.station-list li {
  padding: 14px 16px;
  border-radius: 14px;
  background: rgba(248, 250, 252, 0.9);
  border: 1px solid var(--color-border);
}

.station-list strong {
  display: block;
  margin-bottom: 4px;
  color: var(--color-text-main);
}

.station-note {
  margin-top: 16px;
  color: var(--color-text-muted);
  font-size: 0.95rem;
  line-height: 1.6;
}

.legal-page {
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(15, 118, 110, 0.12), transparent 28rem),
    linear-gradient(180deg, #f8fafc 0%, #eef6f5 100%);
}

.legal-shell {
  max-width: 860px;
  margin: 0 auto;
  padding: 24px 18px 56px;
}

.legal-back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--color-primary-dark);
  font-weight: 600;
  text-decoration: none;
  margin-bottom: 18px;
}

.legal-card {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(226, 232, 240, 0.92);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  padding: 28px 22px;
  backdrop-filter: blur(10px);
}

.legal-kicker {
  margin: 0 0 10px;
  color: var(--color-primary-dark);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.legal-card h1 {
  margin: 0 0 12px;
  font-size: clamp(2rem, 6vw, 3.5rem);
  line-height: 0.95;
}

.legal-intro {
  margin: 0 0 22px;
  max-width: 52rem;
  color: var(--color-text-muted);
  font-size: 1rem;
  line-height: 1.7;
}

.legal-card h2 {
  margin: 28px 0 10px;
  color: var(--color-primary);
  font-size: 1.1rem;
}

.legal-card h3 {
  margin: 18px 0 8px;
  color: var(--color-text-main);
  font-size: 1rem;
}

.legal-card p,
.legal-card li {
  color: var(--color-text-main);
  line-height: 1.75;
}

.legal-card ul {
  margin: 10px 0 0;
  padding-left: 1.2rem;
}

.legal-meta {
  margin-top: 28px;
  padding-top: 18px;
  border-top: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: 0.92rem;
}

/* TABLET/DESKTOP TWEAKS */
@media (min-width: 768px) {
  .viewport {
    display: flex;
  }

  .bottom-nav {
    display: none; /* We could switch to side nav, but sticking to bottom nav for consistency for now */
  }

  /* Just make the shell centered on desktop */
  .app-shell {
    max-width: 100%;
    background: #e2e8f0;
    align-items: center;
    justify-content: center;
  }

  .viewport {
    width: 100%;
    max-width: 450px; /* Mobile simulation mode */
    background: white;
    height: 85vh;
    border-radius: 20px;
    box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1);
    border: 8px solid #1e293b;
    overflow: hidden;
  }

  .bottom-nav {
    width: 100%;
    max-width: 450px;
    display: flex;
    border-bottom-left-radius: 20px;
    border-bottom-right-radius: 20px;
    border: 8px solid #1e293b;
    border-top: none;
    background: white;
  }

  .legal-shell {
    padding: 40px 24px 72px;
  }

  .legal-card {
    padding: 40px 44px;
  }

  .station-shell {
    padding: 40px 24px 72px;
  }

  .station-hero {
    padding: 40px 44px;
  }
}

@media (max-width: 640px) {
  .station-actions {
    flex-direction: column;
  }

  .station-actions .link-btn {
    width: 100%;
  }
}
