/* ============================================
   PROVENCE BY BIKE — Stylesheet
   Earth tones, outdoor-inspired, responsive
   ============================================ */

/* ---------- CSS Variables ---------- */
:root {
  --color-bg: #faf8f5;
  --color-surface: #ffffff;
  --color-text: #2c2416;
  --color-text-secondary: #6b5e4f;
  --color-border: #e0d8cd;
  --color-accent: #4a7c59;
  --color-accent-hover: #3d6649;
  --color-accent-light: #e8f0ea;
  --color-warm: #c47a3b;
  --color-warm-light: #fdf1e6;
  --color-danger: #c0392b;

  --sidebar-width: 320px;
  --detail-width: 400px;
  --header-height: 56px;

  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: 'Playfair Display', Georgia, serif;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);

  --radius: 8px;
  --radius-sm: 4px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
}

h1, h2, h3, h4 {
  line-height: 1.2;
}

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

ul {
  padding-left: 1.2em;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-primary {
  background: var(--color-accent);
  color: #fff;
}
.btn-primary:hover {
  background: var(--color-accent-hover);
}

.btn-outline {
  background: transparent;
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
.btn-outline:hover {
  background: var(--color-accent-light);
  border-color: var(--color-accent);
}

/* ---------- Header ---------- */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  color: var(--color-text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-icon {
  font-size: 22px;
}

.tagline {
  color: var(--color-text-secondary);
  font-size: 13px;
}

.header-center {
  flex: 1;
  text-align: center;
}

/* Hamburger */
.sidebar-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}
.sidebar-toggle span {
  display: block;
  height: 2px;
  width: 100%;
  background: var(--color-text);
  border-radius: 1px;
  transition: 0.2s;
}

/* ---------- App Layout ---------- */
.app-layout {
  display: flex;
  height: calc(100vh - var(--header-height));
  margin-top: var(--header-height);
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  z-index: 500;
  transition: transform 0.3s ease;
}

.sidebar-content {
  padding: 16px;
}

.sidebar-section {
  margin-bottom: 24px;
}

.section-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--color-accent);
}

/* Route Cards */
.route-card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
  overflow: hidden;
}
.route-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
}
.route-card:hover {
  border-color: var(--color-accent);
  box-shadow: var(--shadow-sm);
}
.route-card.active {
  border-color: var(--color-accent);
  background: var(--color-accent-light);
}

.route-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 6px;
}

.route-card-name {
  font-weight: 600;
  font-size: 14px;
}

.route-card-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.badge-easy {
  background: #d5f0db;
  color: #1a7a32;
}
.badge-moderate {
  background: #fde8d0;
  color: #a35c1a;
}
.badge-hard {
  background: #fcd5d1;
  color: #a32919;
}

.route-card-meta {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--color-text-secondary);
}

/* Filter Toggles */
.filter-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
  user-select: none;
}
.filter-toggle:hover {
  background: var(--color-bg);
}

.filter-toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--color-accent);
  cursor: pointer;
}

.filter-toggle-label {
  font-size: 13px;
  font-weight: 500;
  flex: 1;
}

.filter-toggle-icon {
  font-size: 16px;
}

.filter-toggle-count {
  font-size: 11px;
  color: var(--color-text-secondary);
  background: var(--color-bg);
  padding: 1px 6px;
  border-radius: 8px;
}

/* Tips */
.tips-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tip {
  font-size: 12px;
  color: var(--color-text-secondary);
  padding: 8px 10px;
  background: var(--color-warm-light);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--color-warm);
}

.tip strong {
  color: var(--color-text);
}

/* ---------- Map ---------- */
.map-container {
  flex: 1;
  position: relative;
}

#map {
  width: 100%;
  height: 100%;
}

/* Map Legend */
.map-legend {
  position: absolute;
  bottom: 24px;
  left: 12px;
  z-index: 800;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.legend-toggle {
  display: block;
  width: 100%;
  padding: 8px 14px;
  background: none;
  border: none;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text);
  cursor: pointer;
  text-align: left;
}
.legend-toggle:hover {
  background: var(--color-bg);
}

.legend-content {
  display: none;
  padding: 4px 14px 12px;
}
.legend-content.open {
  display: block;
}

.legend-section {
  margin-bottom: 8px;
}
.legend-section:last-child {
  margin-bottom: 0;
}

.legend-section h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-secondary);
  margin-bottom: 4px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  padding: 2px 0;
}

.legend-line {
  width: 24px;
  height: 3px;
  border-radius: 2px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

/* ---------- Detail Panel ---------- */
.detail-panel {
  width: 0;
  min-width: 0;
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  overflow-y: auto;
  transition: width 0.3s ease, min-width 0.3s ease;
  z-index: 500;
}
.detail-panel.open {
  width: var(--detail-width);
  min-width: var(--detail-width);
}

.detail-close {
  position: sticky;
  top: 0;
  float: right;
  width: 32px;
  height: 32px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 12px 12px 0 0;
  z-index: 1;
}
.detail-close:hover {
  background: var(--color-border);
}

.detail-content {
  padding: 16px;
}

.detail-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--color-text-secondary);
}
.detail-empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
}
.detail-empty h3 {
  margin-bottom: 8px;
  color: var(--color-text);
}

/* Route Detail */
.route-detail-header {
  margin-bottom: 16px;
}

.route-detail-name {
  font-family: var(--font-display);
  font-size: 22px;
  margin-bottom: 8px;
}

.route-detail-meta {
  display: flex;
  gap: 16px;
  font-size: 13px;
  color: var(--color-text-secondary);
  margin-bottom: 10px;
}

.route-detail-summary {
  font-size: 14px;
  color: var(--color-text-secondary);
  line-height: 1.6;
}

.stage-list {
  margin-top: 16px;
}

.stage-card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
}

.stage-day {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-accent);
  font-weight: 600;
  margin-bottom: 4px;
}

.stage-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}

.stage-stats {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-bottom: 6px;
}

.stage-desc {
  font-size: 13px;
  color: var(--color-text-secondary);
  line-height: 1.5;
}

.route-tips {
  margin-top: 16px;
  padding: 12px;
  background: var(--color-warm-light);
  border-radius: var(--radius);
  border-left: 3px solid var(--color-warm);
}

.route-tips h4 {
  font-size: 13px;
  margin-bottom: 8px;
}

.route-tips ul {
  font-size: 12px;
  color: var(--color-text-secondary);
}
.route-tips li {
  margin-bottom: 4px;
}

/* POI Detail */
.poi-detail-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 12px;
}

.poi-detail-icon {
  font-size: 28px;
  line-height: 1;
}

.poi-detail-name {
  font-family: var(--font-display);
  font-size: 20px;
}

.poi-detail-type {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-secondary);
}

.poi-detail-price {
  display: inline-block;
  padding: 4px 10px;
  background: var(--color-accent-light);
  color: var(--color-accent);
  font-weight: 600;
  font-size: 13px;
  border-radius: var(--radius-sm);
  margin: 8px 0;
}

.poi-detail-desc {
  font-size: 14px;
  color: var(--color-text-secondary);
  line-height: 1.6;
  margin-bottom: 12px;
}

.poi-detail-routes {
  font-size: 12px;
  color: var(--color-text-secondary);
}
.poi-detail-routes strong {
  color: var(--color-text);
}

/* ---------- Modal ---------- */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 2000;
  justify-content: center;
  align-items: center;
  padding: 20px;
}
.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius);
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  padding: 32px;
  position: relative;
  box-shadow: var(--shadow-lg);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-close:hover {
  background: var(--color-border);
}

.modal h2 {
  font-family: var(--font-display);
  font-size: 24px;
  margin-bottom: 16px;
}

.modal h3 {
  font-size: 16px;
  font-weight: 600;
  margin-top: 20px;
  margin-bottom: 8px;
  color: var(--color-accent);
}

.modal p, .modal li {
  font-size: 14px;
  color: var(--color-text-secondary);
  line-height: 1.6;
  margin-bottom: 8px;
}

.modal ul {
  margin-bottom: 12px;
}

/* ---------- Custom Leaflet Markers ---------- */
.custom-marker {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  line-height: 1;
}

/* ---------- Leaflet Popup Overrides ---------- */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow-md) !important;
}

.leaflet-popup-content {
  margin: 12px 16px !important;
  font-family: var(--font-body) !important;
  font-size: 13px !important;
  line-height: 1.5 !important;
}

.popup-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}

.popup-category {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-secondary);
  margin-bottom: 4px;
}

.popup-desc {
  color: var(--color-text-secondary);
  margin-bottom: 6px;
}

.popup-link {
  font-size: 12px;
  color: var(--color-accent);
  cursor: pointer;
  font-weight: 500;
}
.popup-link:hover {
  text-decoration: underline;
}

/* ---------- Sidebar Backdrop (mobile) ---------- */
.sidebar-backdrop {
  display: none;
  position: fixed;
  top: var(--header-height);
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 899;
  opacity: 0;
  transition: opacity 0.3s ease;
  -webkit-tap-highlight-color: transparent;
}
.sidebar-backdrop.visible {
  display: block;
  opacity: 1;
}

/* ---------- Detail Panel Drag Handle (mobile) ---------- */
.detail-drag-handle {
  display: none;
  justify-content: center;
  padding: 10px 0 4px;
  cursor: grab;
  -webkit-tap-highlight-color: transparent;
}
.detail-drag-handle span {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--color-border);
}

/* ---------- Mobile Bottom Nav ---------- */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 950;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: 6px 0;
  padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
}

.mobile-nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
  background: none;
  border: none;
  color: var(--color-text-secondary);
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
  justify-content: center;
}
.mobile-nav-btn:active {
  color: var(--color-accent);
}
.mobile-nav-btn.active {
  color: var(--color-accent);
}

/* ---------- Scrollbar ---------- */
.sidebar::-webkit-scrollbar,
.detail-panel::-webkit-scrollbar,
.modal::-webkit-scrollbar {
  width: 6px;
}
.sidebar::-webkit-scrollbar-track,
.detail-panel::-webkit-scrollbar-track,
.modal::-webkit-scrollbar-track {
  background: transparent;
}
.sidebar::-webkit-scrollbar-thumb,
.detail-panel::-webkit-scrollbar-thumb,
.modal::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 3px;
}

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .detail-panel.open {
    width: 340px;
    min-width: 340px;
  }
  .tagline {
    display: none;
  }
}

@media (max-width: 768px) {
  :root {
    --mobile-nav-height: calc(56px + env(safe-area-inset-bottom, 0px));
  }

  .sidebar-toggle {
    display: flex;
  }

  .tagline {
    display: none;
  }

  /* Show mobile nav */
  .mobile-nav {
    display: flex;
  }

  /* Show drag handle on detail panel */
  .detail-drag-handle {
    display: flex;
  }

  /* Adjust app layout for bottom nav */
  .app-layout {
    height: calc(100vh - var(--header-height) - var(--mobile-nav-height));
  }

  /* Sidebar as overlay */
  .sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: var(--mobile-nav-height);
    width: 300px;
    min-width: 300px;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
    z-index: 900;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar.open {
    transform: translateX(0);
  }

  /* Detail panel as bottom sheet */
  .detail-panel {
    position: fixed;
    bottom: var(--mobile-nav-height);
    left: 0;
    right: 0;
    width: 100% !important;
    min-width: 100% !important;
    height: 0;
    max-height: calc(100vh - var(--header-height) - var(--mobile-nav-height));
    border-left: none;
    border-top: none;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
    transition: height 0.3s ease;
    z-index: 900;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  .detail-panel.open {
    height: 55vh;
    width: 100% !important;
    min-width: 100% !important;
  }
  /* When dragged to full height */
  .detail-panel.expanded {
    height: calc(100vh - var(--header-height) - var(--mobile-nav-height));
  }

  /* Make detail close button more visible */
  .detail-close {
    width: 36px;
    height: 36px;
    font-size: 20px;
  }

  /* Bigger touch targets for route cards */
  .route-card {
    padding: 14px 14px 14px 18px;
    min-height: 44px;
  }

  /* Bigger touch targets for filter toggles */
  .filter-toggle {
    padding: 12px 10px;
    min-height: 44px;
  }

  .filter-toggle input[type="checkbox"] {
    width: 20px;
    height: 20px;
  }

  /* Bigger popup links for touch */
  .popup-link {
    display: inline-block;
    padding: 6px 0;
    font-size: 14px;
    min-height: 44px;
    line-height: 32px;
  }

  /* Move legend above mobile nav and out of bottom-sheet way */
  .map-legend {
    bottom: 12px;
    left: 8px;
    max-width: 150px;
  }

  /* Move zoom controls up to avoid bottom sheet overlap */
  .leaflet-top.leaflet-right {
    top: 8px;
    right: 8px;
  }
  .leaflet-bottom.leaflet-left {
    bottom: 8px;
  }

  /* Modal improvements */
  .modal-overlay {
    padding: 12px;
    align-items: flex-end;
  }
  .modal {
    max-height: 85vh;
    padding: 24px 20px;
    border-radius: 16px 16px 0 0;
    margin-bottom: 0;
  }

  /* Safe area padding for header */
  .header {
    padding-left: calc(16px + env(safe-area-inset-left, 0px));
    padding-right: calc(16px + env(safe-area-inset-right, 0px));
  }
}

@media (max-width: 480px) {
  .logo {
    font-size: 16px;
  }
  /* Keep About visible via bottom nav; hide header button */
  .header-right {
    display: none;
  }
  .sidebar {
    width: 85vw;
    min-width: 85vw;
    max-width: 320px;
  }

  /* Full-screen modal on very small phones */
  .modal-overlay {
    padding: 0;
    align-items: stretch;
  }
  .modal {
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
    padding-top: 48px;
  }
  .modal-close {
    top: 10px;
    right: 10px;
    width: 36px;
    height: 36px;
    font-size: 20px;
  }
}
