/* ==========================================================================
   HikeCamp PWA - app.css
   ========================================================================== */

/* 1. NATIVE APP BEHAVIOUR RESETS */
:root {
    --primary: #2c7a7b;
    --surface: #ffffff;
    --text-dark: #1a202c;
    --text-muted: #a0aec0;
    --bg-blur: rgba(255, 255, 255, 0.85);
}

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

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100dvh; 
    overflow: hidden;
    background-color: #f7fafc;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    overscroll-behavior-y: none; 
    user-select: none; 
}

/* 2. MAIN LAYOUT */
#app-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

#map {
    flex-grow: 1;
    width: 100%;
    z-index: 1;
}

/* 3. FLOATING SEARCH PILL */
.floating-search-bar {
    position: absolute;
    top: calc(16px + env(safe-area-inset-top));
    left: 16px;
    right: 16px;
    max-width: 450px; 
    margin: 0 auto;   
    height: 52px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 26px; 
    box-shadow: 0 4px 15px rgba(0,0,0,0.15); 
    z-index: 1000; 
    display: flex;
    align-items: center;
    padding: 0 16px 0 12px;
}

.floating-logo {
    width: 40px;
    height: 40px;
    border-radius: 50%; 
    object-fit: contain;
    margin-right: 12px;
}

.search-input {
    flex-grow: 1;
    border: none;
    background: transparent;
    font-size: 16px; 
    color: var(--text-dark);
    outline: none;
}

.search-input::placeholder {
    color: var(--text-muted);
}

/* Search Autocomplete Dropdown Styles */
#search-results {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    box-sizing: border-box;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    margin-top: 5px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
    text-align: left;
}

.search-item {
    padding: 12px 15px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
}

.search-item > div:first-child {
    flex: 1 1 auto;
    min-width: 0;
}

.search-item > div:last-child {
    flex: 0 0 auto; 
}

.search-item:last-child { border-bottom: none; }
.search-item:hover { background: #f8f9fa; }

.search-item-title { 
    font-weight: bold; 
    color: #333; 
    font-size: 14px;
    white-space: nowrap; 
    overflow: hidden; 
    text-overflow: ellipsis;
}

.search-item-meta { font-size: 12px; color: #777; }

/* 4. FLOATING ACTION BUTTONS (FAB) */
.fab-container {
    position: absolute;
    right: 16px;
    bottom: calc(240px + env(safe-area-inset-bottom));
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.fab {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--surface);
    border: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-dark);
}

/* 5. ELEVATION SHEET & CHART STATS */
#elevation-sheet {
    position: absolute;
    bottom: 0 !important;
    left: 0;
    width: 100%;
    /* Removed the hardcoded 220px height so the sheet can grow! */
    height: auto; 
    min-height: 230px; 
    background: var(--surface);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
    z-index: 20;
    transform: translateY(120%); 
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 15px 20px;
    /* Proper safe area inset for iOS bottom bars */
    padding-bottom: max(30px, calc(15px + env(safe-area-inset-bottom))) !important;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

#elevation-sheet.active {
    transform: translateY(0); 
}

#elevation-sheet h3 {
    margin: 0 0 2px 0 !important;
    font-size: 1.0em;
}

.trail-stats {
    display: flex;
    justify-content: space-around; 
    max-width: 450px;
    width: 100%;
    margin: 0 auto 8px auto;
}

/* Clean, merged chart rules */
.chart-container {
    position: relative;
    height: 130px; 
    width: 100%;
    margin-top: 10px;
    flex-shrink: 0; /* Prevents flexbox from squishing the chart */
}

.stat-box {
    text-align: center;
}

.stat-value {
    font-weight: bold;
    font-size: 1.1em;
    color: var(--primary);
}

.stat-label {
    font-size: 0.75em;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* 6. BOTTOM NAVIGATION BAR */
.bottom-nav {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: calc(65px + env(safe-area-inset-bottom)); 
    background: var(--bg-blur);
    backdrop-filter: blur(12px); 
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid rgba(0,0,0,0.05);
    z-index: 30;
    display: flex;
    justify-content: space-around;
    padding-bottom: env(safe-area-inset-bottom);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.7em;
    font-weight: 600;
    gap: 4px;
}

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

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

/* 7. TABLET & DESKTOP LOCK */
@media (min-width: 768px) {
    #elevation-sheet {
        max-width: 600px;
        left: 50%;
        margin-left: -300px;
        border-radius: 20px 20px 0 0;
    }
    
    .bottom-nav {
        max-width: 600px;
        left: 50%;
        margin-left: -300px;
        border-radius: 20px 20px 0 0;
    }
    
    #trail-title {
        text-align: center;
    }
}

/* ==========================================================================
   MAP SPECIFIC STYLES
   ========================================================================== */
/* Clean Map Tooltips */
.custom-tooltip {
    background: rgba(0, 0, 0, 0.8);
    border: none;
    color: white;
    border-radius: 4px;
    padding: 6px 10px;
    font-family: sans-serif;
    text-align: center;
}
.leaflet-tooltip-top:before { border-top-color: rgba(0, 0, 0, 0.8); }

/* Custom Red Dot Icon for Trailheads */
.trailhead-dot {
    background-color: #e53e3e;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 0 4px rgba(0,0,0,0.4);
}

/* ==========================================================================
   HAMBURGER SIDE MENU & UI TWEAKS
   ========================================================================== */
#menu-overlay {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); z-index: 2999;
    display: none; opacity: 0; transition: opacity 0.3s ease;
}
#menu-overlay.active { display: block; opacity: 1; }

#side-menu {
    position: absolute; top: 0; left: 0; width: 280px; height: 100%;
    background: white; z-index: 3000;
    box-shadow: 2px 0 15px rgba(0,0,0,0.2);
    transform: translateX(-100%); transition: transform 0.3s ease;
    display: flex; flex-direction: column;
}
#side-menu.active { transform: translateX(0); }

.menu-header {
    padding: 30px 20px 20px 20px; background: var(--primary); color: white;
    display: flex; align-items: center; gap: 15px;
}
.menu-link {
    padding: 18px 20px; display: flex; align-items: center; gap: 15px;
    color: #333; text-decoration: none; font-size: 1.1em; border-bottom: 1px solid #eee;
}
.menu-link svg { width: 22px; height: 22px; stroke: var(--primary); }


/* ==========================================================================
   SLIDE-OVER VIEWS (Saved Trails & Gear Guide)
   ========================================================================== */
#saved-trails-view, #gear-guide-view, #profile-view {
    position: absolute;
    top: 0;
    right: 0; left: auto; /* Anchors panel to the right edge! */
    width: 100%;
    height: 100% !important; 
    background: #f7fafc;
    z-index: 25; /* Above map and FABs */
    display: flex;
    flex-direction: column;
    transform: translateX(100%); /* Start hidden off-screen to the right */
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#saved-trails-view.active, #gear-guide-view.active, #profile-view.active {
    transform: translateX(0); /* Slide in */
}

.saved-header {
    padding: 20px 16px;
    background: white;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.saved-header h2 { 
    margin: 0; 
    color: #1a202c; 
    font-size: 1.4em; 
}

#saved-list, .gear-list {
    flex-grow: 1;
    overflow-y: auto;
    padding: 10px 0;
}

/* Saved Trails Remove Button */
.btn-remove-saved {
    background: none;
    border: none;
    color: #e53e3e; /* Red color for delete */
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: background 0.2s;
}
.btn-remove-saved:active {
    background: #fed7d7;
}

/* Gear Guide Dynamic Cards */
.gear-list { padding: 16px; }
.gear-card {
    display: flex; gap: 15px; align-items: center; 
    background: white; margin-bottom: 16px; padding: 15px;
    border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    text-decoration: none; color: inherit; border: 1px solid #eee;
}
.gear-card:active { background: #f8f9fa; }
.gear-card img { 
    width: 80px; height: 80px; object-fit: contain; 
    border-radius: 8px; flex-shrink: 0; mix-blend-mode: multiply;
}
.gear-info { flex-grow: 1; }
.gear-brand { 
    font-size: 0.75em; color: #888; text-transform: uppercase; 
    font-weight: bold; letter-spacing: 0.5px; 
}
.gear-card h3 { 
    margin: 4px 0; color: #1a202c; font-size: 0.95em; line-height: 1.3; 
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.gear-price { color: #2c7a7b; font-weight: bold; margin-bottom: 8px; font-size: 1.1em; }
.gear-btn {
    display: inline-block; background: #2c7a7b; color: white;
    padding: 6px 12px; border-radius: 6px; font-weight: bold; font-size: 0.8em;
}


/* ==========================================================================
   MAP SETTINGS & FILTERS SLIDE-OVER PANEL
   ========================================================================== */
#filter-view {
    position: absolute;
    top: 0;
    left: 0;
    width: 85%;
    max-width: 340px;
    height: 100%;
    background: #f7fafc;
    z-index: 2000; /* Above everything */
    box-shadow: 2px 0 20px rgba(0,0,0,0.2);
    transform: translateX(-100%); /* Start hidden on the left */
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}

#filter-view.active {
    transform: translateX(0); /* Slide in */
}

.filter-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 20px;
    border-bottom: 1px solid #e2e8f0;
    background: white;
}

.filter-header h2 { margin: 0; font-size: 1.4em; color: #1a202c; }
#close-filter-btn { background: none; border: none; font-size: 2em; line-height: 1; cursor: pointer; color: #a0aec0; }

.filter-content {
    padding: 20px;
    overflow-y: auto;
    flex-grow: 1;
}

.filter-section-title {
    font-size: 0.9em;
    color: #2c7a7b;
    margin: 0 0 12px 0;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 700;
}

.filter-group {
    margin-bottom: 30px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: white;
    padding: 15px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.radio-label {
    font-size: 1.05em;
    display: flex;
    align-items: center;
    gap: 10px;
    color: #333;
    cursor: pointer;
}

.filter-select {
    width: 100%;
    padding: 12px;
    border: 1px solid #cbd5e0;
    border-radius: 8px;
    font-size: 1em;
    background: white;
    color: #1a202c;
    outline: none;
}

.dist-slider-container {
    display: flex;
    align-items: center;
    gap: 15px;
}

#filter-distance { flex-grow: 1; accent-color: #2c7a7b; }
#filter-distance-val { font-weight: bold; color: #1a202c; min-width: 65px; text-align: right; }

.apply-btn {
    width: 100%;
    padding: 16px;
    background: #2c7a7b;
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1.1em;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(44, 122, 123, 0.3);
}


/* ==========================================================================
   DESKTOP LAYOUT & PANEL CONTROLS (Must remain at bottom)
   ========================================================================== */
/* Make panels act as a sleek sidebar on laptops instead of stretching full width */
@media (min-width: 768px) {
    #saved-trails-view, #gear-guide-view, #profile-view {
        width: 400px;
        border-left: 1px solid #e2e8f0; 
        box-shadow: -4px 0 24px rgba(0,0,0,0.1); 
    }
}

/* Close Buttons */
.close-panel-top {
    background: none; border: none; font-size: 1.8em; 
    line-height: 1; cursor: pointer; color: #4a5568; 
    padding: 0 8px;
}
.close-panel-bottom {
    display: block; width: 100%; text-align: center;
    background: #4a5568; color: white; padding: 14px;
    border-radius: 8px; font-weight: bold; font-size: 1em;
    border: none; cursor: pointer; margin-top: 20px;
}