/* ==========================================================================
   Sidebar Drawer & Collapsible Bottom Sheet Layout
   ========================================================================== */
#sidebar {
  position: absolute;
  top: 14px;
  left: 14px;
  width: 420px;
  max-height: calc(100vh - 28px);
  background: var(--bg-surface);
  backdrop-filter: blur(14px);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(255, 255, 255, 0.8);
  overflow: hidden;
  transition: max-height 0.32s cubic-bezier(0.4, 0, 0.2, 1),
              transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 0.25s ease;
}

.sheet-drag-handle {
  display: none;
  width: 100%;
  padding: 8px 0 4px 0;
  background: white;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  touch-action: none;
  user-select: none;
}

.handle-pill {
  width: 42px;
  height: 4px;
  background: #cbd5e1;
  border-radius: 2px;
  transition: background 0.2s ease, width 0.2s ease;
}

.sheet-drag-handle:hover .handle-pill {
  background: var(--primary);
  width: 50px;
}

.sidebar-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.sidebar-header-titles {
  flex: 1;
  cursor: pointer;
}

.sidebar-header-titles:hover h1 {
  color: var(--primary);
}

.sidebar-header-titles h1 {
  font-size: 1.1rem;
  font-weight: 800;
  color: #0f172a;
  display: flex;
  align-items: center;
  gap: 6px;
}

.sidebar-header-titles p {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.sidebar-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-toggle-sidebar, .btn-change-region {
  padding: 6px 10px;
  border-radius: 8px;
  background: #f8fafc;
  border: 1.5px solid #cbd5e1;
  font-size: 0.76rem;
  font-weight: 700;
  color: #1e293b;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-toggle-sidebar:hover, .btn-change-region:hover {
  background: #eff6ff;
  border-color: var(--primary);
  color: var(--primary);
}

/* Collapsed State on Desktop */
#sidebar.collapsed {
  max-height: 56px;
  box-shadow: var(--shadow-md);
}

#sidebar.collapsed .sidebar-content {
  display: none !important;
}

#sidebar.collapsed .sidebar-header {
  border-bottom: none;
}

/* Quick Bar when Collapsed */
.collapsed-quick-bar {
  display: none;
  background: #0f172a;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  padding: 8px 12px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

#sidebar.collapsed .collapsed-quick-bar {
  display: flex;
}

.quick-bar-nav-group, .quick-bar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.btn-quick-nav {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: white;
  font-size: 1rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  padding: 0;
  line-height: 1;
}

.btn-quick-nav:hover {
  background: var(--primary);
  border-color: var(--primary);
  transform: scale(1.05);
}

.quick-bar-info {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  flex: 1;
}

.quick-bar-tag {
  background: var(--primary);
  color: white;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}

.quick-bar-name {
  font-size: 0.78rem;
  font-weight: 700;
  color: #f8fafc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.quick-bar-stats {
  font-size: 0.7rem;
  color: #fed7aa;
  white-space: nowrap;
}

.btn-quick-gpx {
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  border: none;
  padding: 5px 10px;
  border-radius: 16px;
  font-size: 0.72rem;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.4);
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-quick-gpx:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.6);
}

.btn-quick-expand {
  background: rgba(255, 255, 255, 0.16);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-quick-expand:hover {
  background: var(--primary);
  border-color: var(--primary);
}

/* Sidebar Scrollable Body */
.sidebar-content {
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Departure Point Card */
.start-loc-card {
  background: #fdf4ff;
  border: 1px solid #f0abfc;
  border-radius: var(--radius-md);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.start-loc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  font-weight: 800;
  color: #86198f;
}

.start-loc-search-box {
  display: flex;
  gap: 6px;
  position: relative;
}

.start-search-input-wrapper {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

.start-address-input {
  width: 100%;
  padding: 6px 24px 6px 8px;
  border-radius: 6px;
  border: 1px solid #d8b4fe;
  background: white;
  font-size: 0.78rem;
  color: #581c87;
}

.btn-clear-address {
  position: absolute;
  right: 6px;
  background: transparent;
  color: #a855f7;
  font-size: 0.75rem;
}

.address-results-list {
  background: white;
  border: 1px solid #d8b4fe;
  border-radius: 6px;
  max-height: 160px;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  z-index: 1050;
}

.address-result-item {
  padding: 6px 10px;
  border-bottom: 1px solid #f3e8ff;
  font-size: 0.75rem;
  color: #3b0764;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  text-align: left;
}

.address-result-item:hover {
  background: #fae8ff;
}

.start-loc-select-row {
  display: flex;
  gap: 6px;
}

.start-loc-select {
  flex: 1;
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid #d8b4fe;
  background: white;
  font-size: 0.78rem;
  color: #581c87;
}

.btn-icon {
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid #d8b4fe;
  background: white;
  color: #86198f;
  font-size: 0.78rem;
  font-weight: 700;
}

/* Map Legend */
.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  background: white;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 0.72rem;
  font-weight: 600;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

.legend-line {
  width: 14px;
  height: 4px;
  border-radius: 2px;
}

.legend-line.transit { background: var(--transit); border-top: 1px dashed white; }
.legend-line.walk { background: var(--walk); border-top: 1px dotted white; }
.legend-line.trail { background: var(--primary); }

/* Trail Search & Filter Bar */
.trail-search-input {
  width: 100%;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 0.76rem;
  background: white;
  color: var(--text-main);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.trail-search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(234, 88, 12, 0.15);
}

.trail-filter-pills {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.trail-filter-pills::-webkit-scrollbar { display: none; }

.filter-pill {
  flex-shrink: 0;
  padding: 3px 8px;
  border-radius: 12px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  font-size: 0.7rem;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  transition: all 0.15s ease;
}

.filter-pill:hover {
  background: #e2e8f0;
  color: #0f172a;
}

.filter-pill.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

/* Route Selector Chips Wrapper & Controls */
.route-chips-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  margin-top: 2px;
}

.route-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 4px 2px 8px 2px;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 #f1f5f9;
  touch-action: pan-x;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  width: 100%;
}

.route-chips::-webkit-scrollbar {
  height: 5px;
  display: block;
}

.route-chips::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: 4px;
}

.route-chips::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

.route-chips::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

.btn-chips-scroll {
  position: absolute;
  top: 50%;
  transform: translateY(-60%);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: white;
  border: 1.5px solid var(--border);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  color: var(--text-main);
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  z-index: 10;
  display: none;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
  line-height: 1;
  padding: 0;
}

.btn-chips-scroll:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(234, 88, 12, 0.35);
}

.btn-chips-scroll.left {
  left: -6px;
}

.btn-chips-scroll.right {
  right: -6px;
}

.route-chip {
  flex-shrink: 0;
  padding: 6px 12px;
  border-radius: 12px;
  background: white;
  border: 1.5px solid var(--border);
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  transition: all 0.2s ease;
  cursor: pointer;
  white-space: nowrap;
  text-align: left;
}

.route-chip .chip-main {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-main);
}

.route-chip.active .chip-main {
  color: white;
}

.route-chip .chip-id {
  font-weight: 800;
  color: var(--primary);
}

.route-chip.active .chip-id {
  color: #fed7aa;
}

.route-chip .chip-sub {
  font-size: 0.68rem;
  font-weight: 600;
  color: #64748b;
}

.route-chip.active .chip-sub {
  color: rgba(255, 255, 255, 0.9);
}

.route-chip:hover {
  border-color: var(--primary);
  background: #fff7ed;
}

.route-chip:hover .chip-main {
  color: var(--primary);
}

.route-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(234, 88, 12, 0.35);
}

/* Route Hero 1-Click Action Buttons */
.route-hero-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 4px 0 6px 0;
}

.btn-primary-gpx {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  background: linear-gradient(135deg, #ea580c, #c2410c);
  color: white;
  font-size: 0.84rem;
  font-weight: 800;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(234, 88, 12, 0.35);
  transition: all 0.2s ease;
}

.btn-primary-gpx:hover {
  background: linear-gradient(135deg, #f97316, #ea580c);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(234, 88, 12, 0.45);
}

/* Collapsible Departure Accordion */
.departure-accordion {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-md);
  padding: 8px 12px;
  transition: all 0.2s ease;
}

.departure-accordion[open] {
  background: #fdf4ff;
  border-color: #f0abfc;
}

.departure-accordion-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 700;
  color: #475569;
  user-select: none;
  list-style: none;
}

.departure-accordion-summary::-webkit-details-marker {
  display: none;
}

.departure-accordion-summary:hover {
  color: var(--primary);
}

.departure-accordion[open] .accordion-arrow {
  transform: rotate(180deg);
}

.accordion-arrow {
  transition: transform 0.2s ease;
  font-size: 0.85rem;
}

/* Active Trail Detail Card */
.active-card {
  background: white;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow-sm);
}

.active-card-header h2 {
  font-size: 1rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.2;
}

.active-card-location {
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  background: #f8fafc;
  padding: 6px 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  text-align: center;
}

.stat-val {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text-main);
}

.stat-lbl {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 700;
  margin-top: 1px;
}

.transit-journey-box {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.transit-header-line {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  font-weight: 700;
  color: #166534;
}

.transit-badge {
  background: #dcfce7;
  color: #15803d;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.7rem;
}

.btn-download {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  background: var(--primary);
  color: white;
  padding: 10px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 700;
  box-shadow: 0 2px 4px rgba(234, 88, 12, 0.2);
  transition: background-color 0.2s ease;
}

.btn-download:hover {
  background: var(--primary-hover);
}

/* Mobile Responsive Drawer */
@media (max-width: 840px) {
  #sidebar {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100vw;
    border-radius: 18px 18px 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.18);
    max-height: 72dvh;
    height: auto;
  }

  .sheet-drag-handle { display: flex; }

  .sidebar-header { padding: 9px 12px; }
  .sidebar-header-titles h1 { font-size: 0.96rem; }
  .sidebar-header-titles p { font-size: 0.68rem; }
  .btn-change-region { padding: 5px 8px; font-size: 0.72rem; }
  .btn-region-label { display: none; }

  .sidebar-content {
    max-height: calc(72dvh - 58px);
    padding: 10px 12px 28px 12px;
  }

  #sidebar.collapsed {
    max-height: 64px !important;
    height: 64px !important;
  }
}

/* Delete Route Button & Restore Action */
.btn-delete-route {
  background: #fef2f2;
  color: #ef4444;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.btn-delete-route:hover {
  background: #fee2e2;
  border-color: #f87171;
  color: #dc2626;
  transform: scale(1.08);
}

.btn-restore-routes {
  background: #f0fdf4;
  color: #16a34a;
  border: 1px solid #bbf7d0;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  padding: 3px 8px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  transition: all 0.2s;
}

.btn-restore-routes:hover {
  background: #dcfce7;
  border-color: #86efac;
  color: #15803d;
}

/* Travel Mode Switcher inside Transit Journey Card */
.travel-mode-switcher {
  display: inline-flex;
  gap: 3px;
  background: rgba(15, 23, 42, 0.08);
  padding: 2px;
  border-radius: 6px;
}

.mode-btn {
  background: transparent;
  border: none;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 4px;
  cursor: pointer;
  color: #475569;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.mode-btn:hover {
  background: rgba(255, 255, 255, 0.6);
  color: #0f172a;
}

.mode-btn.active {
  background: #0284c7;
  color: white;
  box-shadow: 0 1px 4px rgba(2, 132, 199, 0.35);
}

.departure-transport-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed #d8b4fe;
}

.departure-transport-label {
  font-size: 0.72rem;
  font-weight: 800;
  color: #581c87;
  letter-spacing: 0.2px;
}

/* PDF Export Button */
.btn-export-pdf {
  background: #f8fafc;
  color: #0f172a;
  border: 1px solid #cbd5e1;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.btn-export-pdf:hover {
  background: #0284c7;
  color: white;
  border-color: #0284c7;
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(2, 132, 199, 0.35);
}

.mode-btn:disabled, .mode-btn.disabled {
  opacity: 0.35 !important;
  cursor: not-allowed !important;
  background: transparent !important;
  color: #94a3b8 !important;
  text-decoration: line-through;
}

/* === Bookmark & Favorites Styling === */
.btn-bookmark {
  background: none;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 0.72rem;
  cursor: pointer;
  color: #94a3b8;
  transition: all 0.15s;
}
.btn-bookmark:hover {
  border-color: #f59e0b;
  color: #f59e0b;
}
.btn-bookmark.active {
  background: #fef3c7;
  border-color: #f59e0b;
  color: #d97706;
  font-weight: 700;
}

.fav-filter-toggle {
  background: none;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.72rem;
  cursor: pointer;
  color: #64748b;
  transition: all 0.15s;
}
.fav-filter-toggle:hover {
  border-color: #f59e0b;
}
.fav-filter-toggle.active {
  background: #fffbeb;
  border-color: #f59e0b;
  color: #b45309;
  font-weight: 700;
}

.favorites-summary-card {
  background: linear-gradient(135deg, #fffbeb, #fef3c7);
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 8px;
  font-size: 0.75rem;
  color: #92400e;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.route-chip.bookmarked {
  border-color: #f59e0b;
  background: #fffbeb;
}
.route-chip.bookmarked::after {
  content: '⭐';
  font-size: 0.6rem;
  margin-left: 4px;
}
