*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-dark: #1b2a1f;
  --bg-card: #2a3d2a;
  --bg-card-hover: #334a33;
  --accent-gold: #e8a84c;
  --accent-red: #c45a3a;
  --text-heading: #d4c4a0;
  --text-muted: #7a9a6a;
  --text-dim: #5a7a5a;
  --border-subtle: #3a5a3a;
  --color-easy: #6abf5c;
  --color-moderate: #e8a84c;
  --color-hard: #c45a3a;
  --header-height: 60px;
  --legend-height: 90px;
  --sheet-max-height: 45vh;
}

html, body { height: 100%; overflow: hidden; background: var(--bg-dark); color: var(--text-heading); font-family: system-ui, -apple-system, 'Segoe UI', sans-serif; }

.header { position: fixed; top: 0; left: 0; right: 0; z-index: 1000; height: var(--header-height); background: var(--bg-dark); border-bottom: 1px solid var(--border-subtle); display: flex; align-items: center; justify-content: space-between; padding: 0 16px; }
.header-title h1 { font-size: 16px; font-weight: 800; color: var(--text-heading); letter-spacing: -0.5px; text-transform: uppercase; }
.header-subtitle { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 2px; }

/* -- Header Actions -- */
.header-actions { display: flex; align-items: center; gap: 8px; }
.header-text-btn { background: none; border: none; color: var(--text-dim); font-size: 12px; cursor: pointer; padding: 6px 0; transition: color 0.2s; -webkit-tap-highlight-color: transparent; }
.header-text-btn:hover { color: var(--text-heading); }

/* -- Table Overlay -- */
.table-overlay { position: fixed; inset: 0; z-index: 3000; background: var(--bg-dark); transform: translateY(100%); transition: transform 0.3s ease-out; display: flex; flex-direction: column; }
.table-overlay.open { transform: translateY(0); }
.table-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-bottom: 1px solid var(--border-subtle); flex-shrink: 0; }
.table-header h2 { font-size: 16px; font-weight: 800; color: var(--text-heading); text-transform: uppercase; }
.table-close-btn { background: none; border: none; color: var(--text-muted); font-size: 28px; cursor: pointer; padding: 0 4px; line-height: 1; }
.table-close-btn:hover { color: var(--text-heading); }
.table-scroll { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; padding: 0 12px 20px; }

.trails-table { width: 100%; border-collapse: collapse; font-size: 12px; min-width: 900px; }
.trails-table th { position: sticky; top: 0; background: var(--bg-dark); color: var(--text-dim); text-transform: uppercase; font-size: 10px; letter-spacing: 0.5px; padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--border-subtle); white-space: nowrap; }
.trails-table td { padding: 8px; color: var(--text-muted); border-bottom: 1px solid rgba(58,90,58,0.3); vertical-align: top; }
.trails-table tr:hover td { background: var(--bg-card); }
.trails-table .trail-name-cell { color: var(--text-heading); font-weight: 600; white-space: nowrap; }
.trails-table .difficulty-badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 10px; font-weight: 700; text-transform: uppercase; }
.difficulty-badge.easy { background: rgba(106,191,92,0.15); color: var(--color-easy); }
.difficulty-badge.moderate { background: rgba(232,168,76,0.15); color: var(--color-moderate); }
.difficulty-badge.hard { background: rgba(196,90,58,0.15); color: var(--color-hard); }

/* -- Location Button -- */
.location-btn { flex-shrink: 0; height: 34px; padding: 0 12px; border: 1px solid var(--border-subtle); border-radius: 17px; background: var(--bg-card); color: var(--text-muted); font-size: 12px; font-weight: 600; cursor: pointer; transition: background 0.2s, color 0.2s, border-color 0.2s; -webkit-tap-highlight-color: transparent; }
.location-btn:hover { background: var(--bg-card-hover); }
.location-btn.location-set { border-color: var(--accent-gold); color: var(--accent-gold); }

/* -- Driving Time in Sheet -- */
.sheet-driving { display: inline-flex; align-items: center; gap: 6px; margin-top: 8px; padding: 6px 12px; background: var(--bg-card); border-radius: 6px; border-left: 3px solid var(--accent-gold); }
.sheet-driving-label { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }
.sheet-driving-value { font-size: 14px; font-weight: 700; color: var(--accent-gold); }

.month-filter { display: flex; gap: 6px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.month-filter::-webkit-scrollbar { display: none; }
.month-pill { flex-shrink: 0; height: 44px; padding: 0 16px; border: none; border-radius: 22px; background: var(--bg-card); color: var(--text-muted); font-size: 13px; font-weight: 600; cursor: pointer; transition: background 0.2s, color 0.2s; -webkit-tap-highlight-color: transparent; }
.month-pill.active { background: var(--accent-gold); color: var(--bg-dark); }
.month-pill:hover { background: var(--bg-card-hover); }
.month-pill.active:hover { background: var(--accent-gold); }

.main { position: fixed; top: var(--header-height); left: 0; right: 0; bottom: var(--legend-height); }
.map { width: 100%; height: 100%; }
.leaflet-container { background: var(--bg-dark); }

.legend-strip { position: fixed; bottom: 0; left: 0; right: 0; height: var(--legend-height); background: var(--bg-dark); border-top: 1px solid var(--border-subtle); display: flex; align-items: center; gap: 10px; padding: 0 12px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; z-index: 1000; }
.legend-strip::-webkit-scrollbar { display: none; }
.legend-card { flex-shrink: 0; width: 200px; background: var(--bg-card); border-radius: 8px; padding: 10px 12px; border-left: 3px solid var(--accent-gold); cursor: pointer; transition: background 0.2s, opacity 0.3s; -webkit-tap-highlight-color: transparent; }
.legend-card:hover { background: var(--bg-card-hover); }
.legend-card.active { outline: 2px solid var(--accent-gold); outline-offset: -2px; }
.legend-card.dimmed { opacity: 0.3; pointer-events: none; }
.legend-card[data-difficulty="easy"] { border-left-color: var(--color-easy); }
.legend-card[data-difficulty="moderate"] { border-left-color: var(--color-moderate); }
.legend-card[data-difficulty="hard"] { border-left-color: var(--color-hard); }
.legend-card-name { font-size: 12px; font-weight: 700; color: var(--text-heading); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend-card-stats { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.sheet-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 1500; opacity: 0; pointer-events: none; transition: opacity 0.3s; }
.sheet-overlay.visible { opacity: 1; pointer-events: auto; }
.detail-sheet { position: fixed; bottom: 0; left: 0; right: 0; max-height: var(--sheet-max-height); background: var(--bg-dark); border-top: 2px solid var(--accent-gold); border-radius: 16px 16px 0 0; z-index: 2000; transform: translateY(100%); transition: transform 0.3s ease-out; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.detail-sheet.open { transform: translateY(0); }
.sheet-drag-handle { width: 40px; height: 4px; background: var(--border-subtle); border-radius: 2px; margin: 10px auto; }
.sheet-content { padding: 0 20px 24px; }
.sheet-trail-name { font-size: 20px; font-weight: 800; color: var(--text-heading); }
.sheet-area { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.sheet-stats { display: flex; gap: 10px; margin-top: 14px; }
.sheet-stat { background: var(--bg-card); padding: 8px 12px; border-radius: 6px; text-align: center; }
.sheet-stat-label { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }
.sheet-stat-value { font-size: 15px; font-weight: 700; color: var(--text-heading); margin-top: 2px; }
.sheet-section { margin-top: 14px; }
.sheet-section-label { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }
.sheet-section-text { font-size: 14px; color: var(--text-muted); line-height: 1.5; }
.sheet-links { display: flex; gap: 10px; margin-top: 18px; }
.sheet-link { flex: 1; display: flex; align-items: center; justify-content: center; height: 44px; background: var(--bg-card); color: var(--text-heading); border-radius: 8px; font-size: 14px; font-weight: 600; text-decoration: none; transition: background 0.2s; }
.sheet-link:hover { background: var(--bg-card-hover); }

@media (max-width: 767px) {
  .header { height: auto; flex-direction: column; align-items: flex-start; padding: 10px 12px; gap: 8px; }
  .header-title h1 { font-size: 14px; }
  .month-filter { width: 100%; }
  :root { --header-height: 110px; --legend-height: 100px; }
  .header-actions { position: absolute; top: 10px; right: 12px; }
  .legend-card { width: 160px; padding: 12px 14px; }
  .sheet-trail-name { font-size: 18px; }
  .sheet-stats { flex-wrap: wrap; }
}

/* -- Map Markers -- */
.trail-marker { background: transparent; border: none; }
.trail-marker-dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.3); transition: transform 0.2s; cursor: pointer; }

/* -- Tooltips -- */
.trail-tooltip { background: var(--bg-dark) !important; color: var(--text-heading) !important; border: 1px solid var(--border-subtle) !important; border-radius: 6px !important; padding: 8px 12px !important; font-size: 12px !important; line-height: 1.4 !important; box-shadow: 0 4px 12px rgba(0,0,0,0.4) !important; }
.trail-tooltip strong { color: var(--text-heading); }
.leaflet-tooltip-top::before { border-top-color: var(--border-subtle) !important; }

/* -- Reset View Button -- */
.reset-view-btn a { display: flex; align-items: center; justify-content: center; width: 34px; height: 34px; font-size: 20px; color: var(--bg-dark) !important; background: #fff; text-decoration: none; }
.reset-view-btn a:hover { background: #f4f4f4; }

/* -- Layer Switcher -- */
.layer-switcher { display: flex; gap: 2px; background: var(--bg-dark); border: 1px solid var(--border-subtle); border-radius: 8px; padding: 3px; }
.layer-pill { border: none; background: transparent; color: var(--text-dim); font-size: 11px; font-weight: 600; padding: 6px 10px; border-radius: 6px; cursor: pointer; transition: background 0.2s, color 0.2s; -webkit-tap-highlight-color: transparent; }
.layer-pill.active { background: var(--bg-card); color: var(--text-heading); }
.layer-pill:hover { color: var(--text-muted); }

/* -- Sheet Photos -- */
.sheet-photos { display: flex; gap: 8px; margin-top: 14px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.sheet-photos::-webkit-scrollbar { display: none; }
.sheet-photo { flex-shrink: 0; width: 120px; height: 80px; border-radius: 6px; object-fit: cover; border: 1px solid var(--border-subtle); }

/* -- Touch refinements -- */
@media (pointer: coarse) {
  .trail-marker-dot { width: 20px; height: 20px; }
  .legend-card { min-height: 60px; }
  .month-pill { min-width: 52px; }
  .sheet-drag-handle { width: 48px; height: 5px; margin: 12px auto; }
}

body { overscroll-behavior: none; }
