/* ============================================================================
   RESET & BASE STYLES
   ============================================================================ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #475e41;
    --primary-dark: #3a4d35;
    --accent-purple: #9C27B0;
    --green: #4CAF50;
    --yellow: #FFC107;
    --red: #F44336;
    --blue: #808080;
    --gray-light: #f5f5f5;
    --gray-medium: #e0e0e0;
    --gray-dark: #666;
    --text-primary: #333;
    --text-secondary: #666;
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.2);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.3);
    --sidebar-width: min(280px, 80vw);
    --header-height: clamp(50px, 8vh, 64px); /* Use vh for better height adaptation */
    --transition-speed: 0.3s;
    --min-touch-target: 44px;
    --spacing-unit: clamp(0.5rem, 2vw, 1rem);
}

html, body {
    height: 100%;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

html {
    font-size: clamp(13px, 3.5vw, 16px); /* Global responsive font scaling */
    max-width: 100vw;
    overflow-x: hidden;
}

/* Mobile Safari viewport height fix */
@supports (-webkit-touch-callout: none) {
    html {
        height: -webkit-fill-available;
    }
    body {
        min-height: -webkit-fill-available;
    }
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
    display: flex;
    flex-direction: column;
    background: var(--gray-light);\n    color: var(--text-primary);
    font-size: clamp(13px, 3.5vw, 16px);
    line-height: 1.5;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    position: relative;
}

/* Ensure emojis render properly */
.logo-icon,
.bike-icon,
.btn-icon,
.btn-icon-large,
.weather-icon {
    font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji', sans-serif;
    font-style: normal;
    font-weight: normal;
}

/* ============================================================================
   TOP NAVIGATION BAR
   ============================================================================ */

.top-bar {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    padding: clamp(0.35rem, 1.5vw, 0.75rem) clamp(0.5rem, 2vw, 1rem);
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-md);
    z-index: 1000;
    height: var(--header-height);
    position: relative;
}

.logo {
    display: flex;
    align-items: center;
    gap: clamp(0.3rem, 1vw, 0.5rem);
}

.logo-icon {
    font-size: clamp(1.2rem, 4vw, 1.75rem);
}

.logo .title {
    font-size: clamp(0.85rem, 4vw, 1.25rem);
    font-weight: 700;
    white-space: nowrap;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.instagram-link {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.15);
    color: white;
    text-decoration: none;
    transition: all var(--transition-speed);
    cursor: pointer;
    border: none;
    font-weight: 600;
    font-size: clamp(12px, 2.5vw, 14px);
    white-space: nowrap;
}

.instagram-link:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.instagram-link:active {
    transform: translateY(0);
}

.instagram-icon {
    width: clamp(18px, 4vw, 20px);
    height: clamp(18px, 4vw, 20px);
    fill: currentColor;
    transition: transform var(--transition-speed);
}
.instagram-qr-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: clamp(0.4rem, 1.5vw, 0.6rem);
    padding: clamp(0.4rem, 1.5vw, 0.5rem) clamp(0.6rem, 2vw, 0.75rem);
    border-radius: clamp(6px, 1.5vw, 8px);
    background: rgba(255, 255, 255, 0.12);
    color: white;
    border: none;
    cursor: pointer;
    transition: all var(--transition-speed);
    font-size: clamp(12px, 2.5vw, 14px);
    min-height: 40px;
}

.instagram-qr-btn:hover {
    background: rgba(255, 255, 255, 0.22);
    transform: translateY(-2px);
}

.instagram-qr-btn:active {
    transform: translateY(0);
}

.instagram-qr-icon {
    width: clamp(18px, 4vw, 20px);
    height: clamp(18px, 4vw, 20px);
    fill: currentColor;
}

.instagram-qr-text {
    font-weight: 600;
    font-size: clamp(11px, 2.5vw, 13px);
    color: white;
}

.bike-type-btn {
    padding: clamp(0.5rem, 1.5vw, 0.625rem) clamp(0.75rem, 2.5vw, 1.25rem);
    font-size: clamp(12px, 2.5vw, 14px);
    font-weight: 600;
    border: none;
    border-radius: clamp(6px, 1.5vw, 8px);
    cursor: pointer;
    transition: all var(--transition-speed);
    background: linear-gradient(135deg, var(--accent-purple) 0%, #7B1FA2 100%);
    color: white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    gap: clamp(0.35rem, 1vw, 0.5rem);
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    min-height: 40px;
}

.bike-type-btn:hover {
    background: linear-gradient(135deg, #7B1FA2 0%, #6A1B9A 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

.bike-type-btn:active {
    transform: translateY(0);
}

.bike-icon {
    font-size: 1.25rem;
}

/* Hide mobile text on desktop, show desktop text */
.instagram-text-mobile,
.bike-name-mobile {
    display: none;
}

.instagram-text-desktop,
.bike-name-desktop {
    display: inline;
}

/* Hamburger Menu Toggle (Mobile Only) */
.menu-toggle {
    display: none;
    width: clamp(40px, 9vw, 44px);
    height: clamp(40px, 9vw, 44px);
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: clamp(6px, 1.5vw, 8px);
    cursor: pointer;
    padding: 0;
    position: relative;
    transition: background var(--transition-speed);
    -webkit-tap-highlight-color: transparent;
}

.menu-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
}

.hamburger {
    display: block;
    position: relative;
    width: clamp(20px, 5vw, 24px);
    height: clamp(2px, 0.4vw, 2px);
    background: white;
    margin: 0 auto;
    transition: all var(--transition-speed);
}

.hamburger::before,
.hamburger::after {
    content: '';
    position: absolute;
    width: clamp(20px, 5vw, 24px);
    height: clamp(2px, 0.4vw, 2px);
    background: white;
    left: 0;
    transition: all var(--transition-speed);
}

.hamburger::before {
    top: clamp(-6px, -1.5vw, -8px);
}

.hamburger::after {
    bottom: clamp(-6px, -1.5vw, -8px);
}

.menu-toggle.active .hamburger {
    background: transparent;
}

.menu-toggle.active .hamburger::before {
    transform: rotate(45deg);
    top: 0;
}

.menu-toggle.active .hamburger::after {
    transform: rotate(-45deg);
    bottom: 0;
}

/* ============================================================================
   MAIN CONTAINER
   ============================================================================ */

.main-container {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* ============================================================================
   SIDEBAR
   ============================================================================ */

.sidebar {
    width: var(--sidebar-width);
    background: white;
    box-shadow: 2px 0 8px rgba(0,0,0,0.1);
    z-index: 500;
    display: flex;
    flex-direction: column;
    transition: transform var(--transition-speed);
}

.sidebar-content {
    overflow-y: auto;
    overflow-x: hidden;
    height: 100%;
    -webkit-overflow-scrolling: touch;
    background: white; /* ADD */
    position: relative; /* ADD */
    z-index: 1; /* ADD */
}

.sidebar-section {
    padding: clamp(0.75rem, 2.5vw, 1.25rem);
    border-bottom: 1px solid var(--gray-medium);
    background: white; /* ADD */
    position: relative; /* ADD */
    z-index: 1; /* ADD */
}

.sidebar-section h3 {
    font-size: clamp(10px, 2.5vw, 12px);
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: clamp(0.65rem, 2vw, 1rem);
    letter-spacing: clamp(0.3px, 0.1vw, 0.5px);
}

.sidebar-close {
    display: none;
}

.sidebar-overlay {
    display: none;
}

/* Legend Section */
.legend-items {
    display: flex;
    flex-direction: column;
    gap: clamp(0.5rem, 1.5vw, 0.75rem);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: clamp(0.5rem, 1.5vw, 0.75rem);
    font-size: clamp(12px, 2.5vw, 14px);
    color: var(--text-primary);
}

.legend-color {
    width: clamp(32px, 8vw, 40px);
    height: clamp(16px, 4vw, 20px);
    border-radius: clamp(3px, 0.8vw, 4px);
    flex-shrink: 0;
}

.legend-color.green { background: var(--green); }
.legend-color.yellow { background: var(--yellow); }
.legend-color.red { background: var(--red); }
.legend-color.blue { background: var(--blue); }

/* Weather Section */
.weather-status {
    display: flex;
    align-items: center;
    gap: clamp(0.65rem, 2vw, 1rem);
    padding: clamp(0.75rem, 2vw, 1rem);
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    border-radius: clamp(8px, 2vw, 12px);
    border: 2px solid var(--blue);
}

.weather-icon {
    font-size: clamp(1.75rem, 5vw, 2.5rem);
    flex-shrink: 0;
}

.weather-text {
    flex: 1;
    font-size: clamp(11px, 2.5vw, 13px);
    color: #1976D2;
    font-weight: 600;
}

.weather-status.muddy {
    background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%);
    border-color: #FF9800;
}

.weather-status.muddy .weather-text {
    color: #E65100;
}

/* Controls Section */
.controls-panel {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.sidebar-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    background: var(--gray-light);
    border: 2px solid var(--gray-medium);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    width: 100%;
    text-align: left;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}

.sidebar-btn:hover {
    background: #e3f2fd;
    border-color: var(--blue);
    transform: translateX(4px);
}

.sidebar-btn:active {
    transform: translateX(2px);
}

a.sidebar-btn {
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 600;
}

a.sidebar-btn:visited {
    color: var(--text-primary);
}

.btn-icon {
    font-size: clamp(1rem, 2.5vw, 1.25rem);
    flex-shrink: 0;
}

.btn-icon-large {
    font-size: clamp(1.1rem, 3vw, 1.5rem);
}

.btn-text {
    font-size: clamp(11px, 2.5vw, 14px);
    line-height: 1.2;
}

/* Filter Section */
.filter-toggles {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.filter-toggle {
    display: flex;
    align-items: center;
    gap: clamp(0.5rem, 1.5vw, 0.75rem);
    padding: clamp(0.65rem, 2vw, 0.875rem) clamp(0.75rem, 2.5vw, 1rem);
    background: white;
    border: 2px solid #ddd;
    border-radius: clamp(6px, 1.5vw, 8px);
    cursor: pointer;
    transition: all 0.2s;
    font-size: clamp(12px, 2.5vw, 14px);
    font-weight: 600;
    color: var(--text-secondary);
    width: 100%;
    text-align: left;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
}

.toggle-indicator {
    width: clamp(18px, 4vw, 20px);
    height: clamp(18px, 4vw, 20px);
    border: 2px solid currentColor;
    border-radius: 50%;
    position: relative;
    flex-shrink: 0;
}

.filter-toggle.active .toggle-indicator::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: clamp(8px, 2vw, 10px);
    height: clamp(8px, 2vw, 10px);
    border-radius: 50%;
    background: currentColor;
}

.filter-toggle.green { border-color: var(--green); color: var(--green); }
.filter-toggle.yellow { border-color: var(--yellow); color: #F57F17; }
.filter-toggle.red { border-color: var(--red); color: var(--red); }
.filter-toggle.blue { border-color: var(--blue); color: var(--blue); }

.filter-toggle.active.green { background: #E8F5E9; }
.filter-toggle.active.yellow { background: #FFF8E1; }
.filter-toggle.active.red { background: #FFEBEE; }
.filter-toggle.active.blue { background: #E3F2FD; }

/* Analysis Mode Section */
.analysis-mode-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.analysis-mode-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(0.35rem, 1vw, 0.5rem);
    padding: clamp(0.75rem, 2vw, 1rem) clamp(0.4rem, 1.5vw, 0.5rem);
    background: white;
    border: 2px solid #ddd;
    border-radius: clamp(6px, 1.5vw, 8px);
    cursor: pointer;
    transition: all 0.2s;
    font-size: clamp(11px, 2.5vw, 13px);
    font-weight: 600;
    color: var(--text-secondary);
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
}

.analysis-mode-btn .btn-icon {
    font-size: clamp(20px, 5vw, 24px);
}

.analysis-mode-btn:hover {
    border-color: var(--primary-color);
    background: #f5f5f5;
}

.analysis-mode-btn.active {
    border-color: var(--primary-color);
    background: #E8F5E9;
    color: var(--primary-color);
}

.selection-tool-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.selection-tool-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 0.875rem;
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9rem;
    color: #333;
}

.selection-tool-btn .btn-icon {
    font-size: 1.1rem;
}

.selection-tool-btn:hover {
    border-color: var(--primary-color);
    background: #f5f5f5;
}

.selection-tool-btn.active {
    background: #E3F2FD;
    border-color: #2196F3;
    color: #2196F3;
    font-weight: 600;
}

/* Vertex markers for lasso selection */
.vertex-marker {
    cursor: move !important;
    transition: all 0.2s;
}

.vertex-marker:hover {
    transform: scale(1.3);
}

/* Shortcuts Section */
.shortcut-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
    font-size: 13px;
    color: var(--text-secondary);
}

kbd {
    padding: 0.25rem 0.5rem;
    background: #fff;
    border: 2px solid #ddd;
    border-radius: 4px;
    font-family: monospace;
    font-weight: 600;
    font-size: 12px;
    color: var(--text-primary);
    min-width: 50px;
    text-align: center;
    box-shadow: 0 2px 0 #ddd;
}

/* ============================================================================
   RESPONSIVE DESIGN - MOBILE SIDEBAR
   ============================================================================ */

@media (max-width: 768px) {
    /* Sidebar becomes overlay */
    .sidebar {
        position: fixed;
        top: 0;
        right: 0;
        left: auto;
        height: 100%;
        width: 85%;
        max-width: 320px;
        transform: translateX(100%);
        z-index: 2000;
        box-shadow: var(--shadow-lg);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        visibility: hidden;
        transition: opacity var(--transition-speed), visibility var(--transition-speed);
        z-index: 1999;
        pointer-events: none; /* ADD THIS */
    }

    .sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
        pointer-events: all; /* ADD THIS */
    }

    .sidebar-close {
        display: flex;
        position: absolute;
        top: 0.75rem;
        left: 0.75rem;
        width: 40px;
        height: 40px;
        background: var(--gray-light);
        border: none;
        border-radius: 50%;
        font-size: 20px;
        cursor: pointer;
        align-items: center;
        justify-content: center;
        color: var(--text-secondary);
        z-index: 10;
        transition: all 0.2s;
        -webkit-tap-highlight-color: transparent;
    }

    .sidebar-close:active {
        background: var(--gray-medium);
    }

    .sidebar-content {
        padding-top: 3.5rem;
    }

    /* Adjust sidebar sections for mobile */
    .sidebar-section {
        padding: 1rem;
    }

    .sidebar-section h3 {
        font-size: 11px;
        margin-bottom: 0.75rem;
    }

    .sidebar-btn,
    .filter-toggle {
        padding: 0.75rem;
        font-size: 13px;
    }

    /* Weather panel */
    .weather-status {
        padding: 0.875rem;
    }

    .weather-icon {
        font-size: 2rem;
    }

    .weather-text {
        font-size: 12px;
    }
}

/* ============================================================================
   MAP WRAPPER
   ============================================================================ */

.map-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#map {
    flex: 1;
    width: 100%;
    min-height: 0;
}

/* ============================================================================
   LEGEND OVERLAY (Always visible on map)
   ============================================================================ */

.map-controls-left {
    position: absolute;
    top: clamp(5px, 1.25vh, 12px);
    left: clamp(5px, 1.25vw, 12px);
    z-index: 800;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.map-controls-left > * {
    pointer-events: auto;
}

@media (min-width: 769px) {
    .map-controls-left {
        left: 20px;
    }
}

.legend-overlay {
    background: rgba(242, 234, 215, 0.95);
    backdrop-filter: blur(10px);
    border-radius: clamp(5px, 1.25vw, 8px);
    padding: clamp(5px, 1.25vw, 8px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-width: min(100px, 28vw);
    max-width: min(180px, 40vw);
}

/* Move Leaflet controls out of the way of legend */
.leaflet-control-container {
    z-index: 799;
}

.leaflet-top.leaflet-left {
    top: 300px;
    left: 10px;
}

.legend-header {
    margin-bottom: clamp(3px, 0.75vw, 5px);
}

.legend-header h3 {
    font-size: clamp(9px, 2.25vw, 12px);
    font-weight: 700;
    color: #000;
    margin: 0;
}

.legend-overlay .legend-items {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.legend-item-toggle {
    display: flex;
    align-items: center;
    gap: clamp(3px, 1vw, 5px);
    background: none;
    border: none;
    padding: clamp(2px, 0.6vw, 4px) clamp(3px, 1vw, 5px);
    cursor: pointer;
    transition: all 0.2s;
    border-radius: clamp(2px, 0.6vw, 4px);
    font-size: clamp(8px, 2vw, 11px);
    font-weight: 600;
    color: #000;
    text-align: left;
    -webkit-tap-highlight-color: transparent;
    min-height: 30px;
}

.legend-item-toggle:hover {
    background: rgba(255, 255, 255, 0.5);
}

.legend-item-toggle:active {
    transform: scale(0.98);
}

.legend-square {
    width: clamp(14px, 4vw, 20px);
    height: clamp(14px, 4vw, 20px);
    border-radius: clamp(2px, 0.6vw, 4px);
    flex-shrink: 0;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.legend-square.green { background: var(--green); }
.legend-square.yellow { background: var(--yellow); }
.legend-square.red { background: var(--red); }
.legend-square.blue { background: var(--blue); }

.legend-item-toggle.active .legend-square {
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.3);
}

.legend-item-toggle:not(.active) {
    opacity: 0.4;
}

.legend-item-toggle:not(.active) .legend-square {
    background: #ccc !important;
}

.legend-label {
    flex: 1;
}

/* Weather Toggle in Legend */
.weather-toggle {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
}

/* Location Button */
.location-button {
    background: rgba(242, 234, 215, 0.95);
    backdrop-filter: blur(10px);
    border: none;
    border-radius: clamp(5px, 1.25vw, 8px);
    padding: clamp(8px, 2vw, 12px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    color: #475e41;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: clamp(36px, 10vw, 44px);
    height: clamp(36px, 10vw, 44px);
}

.location-button:hover {
    background: rgba(242, 234, 215, 1);
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.location-button:active {
    transform: scale(0.95);
}

.location-button svg {
    width: clamp(18px, 5vw, 22px);
    height: clamp(18px, 5vw, 22px);
}

/* Weather Toggle for Mobile (below buttons) */
.weather-toggle-mobile {
    display: none; /* Hidden by default, shown on small screens */
    margin-top: 12px;
    padding: 10px 16px;
    background: rgba(242, 234, 215, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.switch-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: #475e41;
    position: relative;
}

.switch-label input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-slider {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    background: #ccc;
    border-radius: 11px;
    transition: background 0.3s;
}

.switch-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: white;
    top: 2px;
    left: 2px;
    transition: transform 0.3s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.switch-label input:checked + .switch-slider {
    background: var(--primary-color);
}

.switch-label input:checked + .switch-slider::before {
    transform: translateX(18px);
}

.switch-text {
    user-select: none;
}

/* ============================================================================
   FLOATING ACTION BUTTONS - UPDATED FOR ELEVATION PANEL INTEGRATION
   ============================================================================ */

.floating-actions {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    z-index: 1000;
    pointer-events: none;
    
    /* Dynamic positioning based on elevation panel state */
    bottom: 20px;
    transition: bottom 0.3s ease;
}

/* When elevation panel is active (open) */
.elevation-panel.active ~ .floating-actions {
    bottom: 170px; /* 150px panel height + 20px margin */
}

/* When elevation panel is collapsed */
.elevation-panel.collapsed ~ .floating-actions {
    bottom: 65px; /* 45px panel height + 20px margin */
}

.floating-actions > * {
    pointer-events: all;
}

.primary-route-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 1rem;
    width: 100%;
}

.primary-route-btn {
    padding: clamp(0.4rem, 1.75vw, 0.65rem);
    border: none;
    border-radius: clamp(10px, 2.5vw, 14px);
    font-size: clamp(11px, 2.5vw, 13px);
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition-speed);
    box-shadow: 0 6px 20px rgba(71, 94, 65, 0.4);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: clamp(0.1rem, 0.4vw, 0.2rem);
    width: min(190px, 80vw);
    min-height: clamp(50px, 12vw, 62px);
    color: white;
    -webkit-tap-highlight-color: transparent;
}

.find-gravel-btn {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
}

.find-gravel-btn:hover {
    background: linear-gradient(135deg, var(--primary-dark) 0%, #2d3a27 100%);
    transform: translateY(-4px);
    box-shadow: 0 8px 28px rgba(71, 94, 65, 0.5);
}

.find-gravel-btn:active {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(71, 94, 65, 0.4);
}

.undo-btn {
    background: linear-gradient(135deg, #FF9800 0%, #F57C00 100%);
    box-shadow: 0 6px 20px rgba(255, 152, 0, 0.35);
}

.undo-btn:hover {
    background: linear-gradient(135deg, #F57C00 0%, #EF6C00 100%);
    transform: translateY(-4px);
    box-shadow: 0 8px 28px rgba(255, 152, 0, 0.45);
}

.undo-btn:active {
    transform: translateY(-2px);
}

/* Mobile: place Find Gravel and Undo side-by-side with mobile-friendly sizing
   Keep desktop layout untouched; on mobile we use fixed positioning and vw-based
   widths so buttons scale with the viewport. */
@media (max-width: 768px) {
    .find-gravel-btn,
    .undo-btn {
        position: fixed;
        bottom: 16px;
        /* smaller sizes for compact mobile appearance */
        width: 40vw; /* slightly narrower */
        max-width: 180px;
        min-width: 100px;
        height: 48px; /* reduced height */
        padding: 0.4rem 0.6rem;
        border-radius: 10px;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        gap: 0.4rem;
        box-shadow: 0 4px 14px rgba(0,0,0,0.10);
        font-size: 13px;
        transition: left 0.3s ease, transform 0.3s ease;
    }

    /* Find Gravel button: centered when alone, moves right when draw mode is active */
    .find-gravel-btn {
        left: 50%;
        transform: translateX(-50%);
    }
    
    /* Fix jump on hover/active while centered */
    .find-gravel-btn:hover {
        transform: translateX(-50%) translateY(-4px);
    }
    .find-gravel-btn:active {
        transform: translateX(-50%) translateY(-2px);
    }
    
    /* When draw mode is active, Find Gravel shifts to the RIGHT to sit next to Undo */
    .find-gravel-btn.draw-mode-active {
        left: 50%;
        transform: translateX(4px);
    }
    
    .find-gravel-btn.draw-mode-active:hover {
        transform: translateX(4px) translateY(-4px);
    }
    .find-gravel-btn.draw-mode-active:active {
        transform: translateX(4px) translateY(-2px);
    }
    
    /* Undo button sits on the LEFT of the center */
    .undo-btn {
        left: 50%;
        transform: translateX(calc(-100% - 4px));
    }
    
    .undo-btn:hover {
        transform: translateX(calc(-100% - 4px)) translateY(-4px);
    }
    .undo-btn:active {
        transform: translateX(calc(-100% - 4px)) translateY(-2px);
    }

    /* Icon/text sizing tweaks for compact mobile */
    .find-gravel-btn .btn-icon-large,
    .undo-btn .btn-icon-large {
        font-size: 18px;
    }
    .find-gravel-btn .btn-text,
    .undo-btn .btn-text {
        font-size: 12px;
        line-height: 1;
    }
}
/* Route Action Buttons */
.clear-route-btn,
.export-gpx-btn {
    padding: 1rem 1.5rem;
    border: none;
    border-radius: 50px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all var(--transition-speed);
    color: white;
    -webkit-tap-highlight-color: transparent;
}

.clear-btn {
    position: absolute;
    top: 1px;
    right: 1px;
    z-index: 1300;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
    border: none;
    min-width: 64px;
    height: 36px;
    padding: 0 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    transition: left 0.3s, right 0.3s, top 0.3s, transform 0.2s;
}

.clear-btn.left-of-stats {
    right: auto !important;
    left: calc(12px + var(--sidebar-width, 280px));
    top: 32px;
}

.clear-btn.left-of-stats:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 28px rgba(244, 67, 54, 0.4);
}

.export-gpx-btn {
    background: linear-gradient(135deg, var(--blue) 0%, #1976D2 100%);
}

.export-gpx-btn:hover {
    background: linear-gradient(135deg, #1976D2 0%, #1565C0 100%);
    transform: translateY(-4px);
    box-shadow: 0 8px 28px rgba(33, 150, 243, 0.4);
}

/* ============================================================================
   LOADING OVERLAY
   ============================================================================ */

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.loading-content {
    background: white;
    padding: 2.5rem;
    border-radius: 16px;
    text-align: center;
    box-shadow: var(--shadow-lg);
    max-width: 90%;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--green);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-text {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

/* ============================================================================
   POPUP STYLES
   ============================================================================ */

.road-popup {
    font-size: 13px;
    min-width: 200px;
}

.road-popup h4 {
    margin: 0 0 0.5rem 0;
    color: #2c3e50;
    font-size: 15px;
}

.road-popup .score {
    font-size: 24px;
    font-weight: bold;
    margin: 0.5rem 0;
}

.road-popup .score.green { color: var(--green); }
.road-popup .score.yellow { color: var(--yellow); }
.road-popup .score.red { color: var(--red); }
.road-popup .score.blue { color: var(--blue); }

.road-popup .tags {
    margin-top: 0.5rem;
    font-size: 11px;
    color: var(--text-secondary);
}

.road-popup .tag {
    display: flex;
    justify-content: space-between;
    margin: 0.25rem 0;
}

.road-popup .tag-key {
    font-weight: 600;
    margin-right: 0.5rem;
}

/* ============================================================================
   UTILITY CLASSES
   ============================================================================ */

.btn-hint {
    font-size: 12px;
    opacity: 0.75;
}

.desktop-only {
    display: block;
}

.mobile-only {
    display: none;
}

/* ============================================================================
   RESPONSIVE DESIGN - TABLET
   ============================================================================ */

@media (max-width: 1024px) {
    :root {
        --sidebar-width: 260px;
    }

    .logo .title {
        font-size: 1.125rem;
    }

    .bike-type-btn {
        padding: 0.5rem 1rem;
        font-size: 13px;
    }
}

/* ============================================================================
   RESPONSIVE DESIGN - STANDARD PHONES (376px - 768px)
   ============================================================================ */

@media (max-width: 768px) and (min-width: 376px) {
    :root {
        --header-height: clamp(54px, 8vh, 60px);
    }

    /* Optimize for standard phone screens */
    .legend-overlay {
        top: 12px;
        left: 12px;
    }

    .route-stats {
        top: 70px;
        right: 8px;
    }

    .floating-actions {
        bottom: 18px;
    }
}

/* ============================================================================
   RESPONSIVE DESIGN - IPHONE SE & SMALL PHONES (320px - 375px)
   ============================================================================ */

@media (max-width: 375px) {
    :root {
        --header-height: clamp(48px, 7.5vh, 56px);
        --sidebar-width: 90%;
    }

    /* Optimize spacing for smaller screens */
    .top-bar {
        padding: 0.35rem 0.5rem;
        gap: 0.3rem;
    }

    .logo .title {
        font-size: clamp(0.8rem, 4vw, 1rem);
    }

    .bike-type-btn,
    .instagram-link {
        padding: 0.4rem 0.65rem;
        font-size: 12px;
    }

    /* Make legend more compact */
    .legend-overlay {
        top: 4px;
        left: 4px;
        padding: 4px;
        min-width: min(75px, 24vw);
        max-width: min(130px, 35vw);
        border-radius: 4px;
    }

    .legend-header {
        margin-bottom: 2px;
    }

    .legend-header h3 {
        font-size: 7px;
        font-weight: 700;
    }

    .legend-overlay .legend-items {
        gap: 2px;
    }

    .legend-item-toggle {
        font-size: 6px;
        min-height: 22px;
        padding: 1px 2px;
        gap: 2px;
        font-weight: 600;
    }

    .legend-square {
        width: 10px;
        height: 10px;
        border-radius: 2px;
        border-width: 1px;
    }

    /* Hide weather toggle in legend on small screens */
    .legend-overlay .weather-toggle {
        display: none;
    }

    /* Show mobile weather toggle on small screens */
    .weather-toggle-mobile {
        display: block;
    }

    /* Route stats positioning */
    .route-stats {
        top: 56px;
        right: 6px;
        min-width: min(150px, 40vw);
    }

    /* Button sizing */
    .primary-route-btn {
        width: min(170px, 85vw);
        min-height: 48px;
        font-size: 10px;
        padding: 0.35rem 0.5rem;
    }

    .btn-icon-large {
        font-size: 1rem;
    }

    /* Sidebar */
    .sidebar {
        width: 92%;
    }
}

/* ============================================================================
   RESPONSIVE DESIGN - VERY SMALL PHONES (320px and below)
   ============================================================================ */

@media (max-width: 320px) {
    :root {
        --header-height: 46px;
        --sidebar-width: 95%;
    }

    /* Ultra-compact for 320px screens */
    .top-bar {
        padding: 0.3rem 0.4rem;
        gap: 0.2rem;
    }

    .logo .title {
        font-size: 0.75rem;
    }

    .logo-icon {
        font-size: 1.1rem;
    }

    .bike-type-btn,
    .instagram-link {
        padding: 0.35rem 0.5rem;
        font-size: 11px;
    }

    .menu-toggle {
        width: 36px;
        height: 36px;
    }

    /* Very compact legend */
    .legend-overlay {
        top: 6px;
        left: 6px;
        padding: 6px;
        min-width: min(120px, 36vw);
    }

    .legend-header h3 {
        font-size: 10px;
    }

    .legend-item-toggle {
        font-size: 9px;
        padding: 3px 4px;
        min-height: 34px;
    }

    .legend-square {
        width: 16px;
        height: 16px;
    }

    /* Route stats */
    .route-stats {
        top: 50px;
        right: 4px;
        min-width: min(140px, 42vw);
    }

    .route-stats-header h3 {
        font-size: 11px;
    }

    /* Buttons */
    .primary-route-btn {
        width: min(200px, 90vw);
        min-height: 50px;
        font-size: 11px;
        padding: 0.4rem 0.5rem;
    }

    .btn-text {
        font-size: 10px;
    }

    /* Floating action buttons - ensure they don't overflow */
    .floating-actions {
        gap: 0.6rem;
    }

    .primary-route-actions {
        gap: 0.6rem;
    }

    /* Clear button */
    .clear-btn {
        width: 40px;
        height: 40px;
        top: 12px;
        right: 12px;
        font-size: 16px;
    }

    /* Map container - ensure it fills available space */
    #map {
        width: 100%;
        height: 100%;
        min-height: 200px;
    }

    /* Sidebar sections - more compact */
    .sidebar-section {
        padding: 0.75rem;
    }

    .sidebar-section h3 {
        font-size: 10px;
        margin-bottom: 0.5rem;
    }

    .sidebar-btn,
    .filter-toggle {
        padding: 0.65rem;
        font-size: 12px;
    }

    /* Weather panel */
    .weather-status {
        padding: 0.75rem;
    }

    .weather-icon {
        font-size: 1.75rem;
    }

    .weather-text {
        font-size: 11px;
    }

    /* Loading overlay */
    .loading-content {
        padding: 1.5rem;
    }

    .spinner {
        width: 40px;
        height: 40px;
    }

    .loading-text {
        font-size: 13px;
    }
}

/* ============================================================================
   RESPONSIVE DESIGN - MOBILE (481px - 768px)
   ============================================================================ */

@media (max-width: 768px) {
    :root {
        --header-height: 56px;
    }

    /* Improve touch scrolling on iOS */
    body {
        -webkit-overflow-scrolling: touch;
    }

/* Header adjustments */
    .top-bar {
        padding: 0.5rem 0.75rem;
    }

    .logo .title {
        font-size: 1rem;
    }

    .logo-icon {
        font-size: 1.5rem;
    }

    /* Show mobile text, hide desktop text */
    .instagram-text-desktop,
    .bike-name-desktop {
        display: none;
    }

    .instagram-text-mobile,
    .bike-name-mobile {
        display: inline;
    }

    .bike-type-btn {
        padding: 0.5rem 0.875rem;
        min-width: auto;
    }

    .bike-icon {
        font-size: 1.5rem;
    }

    /* Hide Instagram QR button on mobile */
    .instagram-qr-btn {
        display: none;
    }

    .instagram-link {
        padding: 0.5rem 0.875rem;
        min-width: auto;
    }

    /* Show hamburger menu */
    .menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Sidebar becomes overlay */
    .sidebar {
        position: fixed;
        top: 0;
        right: 0;
        left: auto;
        height: 100%;
        width: 85%;
        max-width: min(320px, 100vw);
        transform: translateX(100%);
        z-index: 2001;
        box-shadow: var(--shadow-lg);
        background: white;
        pointer-events: all;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        visibility: hidden;
        transition: opacity var(--transition-speed), visibility var(--transition-speed);
        z-index: 2000; /* CHANGED from 1999 */
        pointer-events: none; /* KEEP THIS */
    }

    .sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
        pointer-events: all; /* KEEP THIS */
    }

    .sidebar-close {
        display: flex;
        position: absolute;
        top: 0.75rem;
        left: 0.75rem;
        width: 40px;
        height: 40px;
        background: var(--gray-light);
        border: none;
        border-radius: 50%;
        font-size: 20px;
        cursor: pointer;
        align-items: center;
        justify-content: center;
        color: var(--text-secondary);
        z-index: 10;
        transition: all 0.2s;
        -webkit-tap-highlight-color: transparent;
        pointer-events: all; /* ADD THIS */
    }

    .sidebar-content {
        padding-top: 3.5rem;
        background: white;
        pointer-events: all; /* ADD THIS */
    }

    .sidebar-section {
        padding: 1rem;
        background: white;
        pointer-events: all; /* ADD THIS */
    }

    .sidebar-btn,
    .filter-toggle {
        padding: 0.75rem;
        font-size: 13px;
        pointer-events: all; /* ADD THIS */
    }

    /* Legend overlay adjustments for mobile */
    .legend-overlay {
        top: 14px;
        left: 14px;
        padding: 10px;
        min-width: min(140px, 40vw);
        max-width: calc(100vw - 100px);
        font-size: 12px;
    }

    .legend-header h3 {
        font-size: 14px;
    }

    .legend-item-toggle {
        padding: 5px 6px;
        font-size: 13px;
        gap: 6px;
    }

    .legend-square {
        width: 24px;
        height: 24px;
    }

    .weather-toggle {
        margin-top: 10px;
        padding-top: 10px;
    }

    .switch-label {
        font-size: 11px;
    }

    .switch-slider {
        width: 36px;
        height: 20px;
    }

    .switch-slider::before {
        width: 16px;
        height: 16px;
    }

    .switch-label input:checked + .switch-slider::before {
        transform: translateX(16px);
    }

    /* Floating buttons adjustments */
    .find-gravel-btn {
        padding: 0.875rem 1.5rem;
        font-size: 14px;
        min-width: auto;
    }

    .btn-icon-large {
        font-size: 1.25rem;
    }

    .btn-text {
        font-size: 14px;
    }

    .clear-btn {
        width: 44px;
        height: 44px;
        top: 16px;
        right: 16px;
        font-size: 18px;
    }

    /* Hide desktop-only elements */
    .desktop-only {
        display: none !important;
    }

    .mobile-only {
        display: block;
    }

    /* Adjust sidebar sections for mobile */
    .sidebar-section {
        padding: 1rem;
    }

    .sidebar-section h3 {
        font-size: 11px;
        margin-bottom: 0.75rem;
    }

    .sidebar-btn,
    .filter-toggle {
        padding: 0.75rem;
        font-size: 13px;
    }

    /* Weather panel */
    .weather-status {
        padding: 0.875rem;
    }

    .weather-icon {
        font-size: 2rem;
    }

    .weather-text {
        font-size: 12px;
    }

    /* Loading overlay */
    .loading-content {
        padding: 2rem;
    }

    .spinner {
        width: 50px;
        height: 50px;
    }

    .loading-text {
        font-size: 14px;
    }
}

/* ============================================================================
   ANIMATIONS
   ============================================================================ */

@keyframes slideIn {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(400px);
        opacity: 0;
    }
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* ============================================================================
   ACCESSIBILITY
   ============================================================================ */

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus styles for keyboard navigation */
button:focus-visible,
.filter-toggle:focus-visible {
    outline: 3px solid var(--blue);
    outline-offset: 2px;
}

/* Touch target sizes for mobile */
@media (hover: none) and (pointer: coarse) {
    button,
    .filter-toggle,
    .sidebar-btn {
        min-height: 44px;
    }
}

/* ============================================================================
   ROUTING MODE STYLES
   ============================================================================ */

.route-mode-btn {
    padding: 0.625rem 1.25rem;
    font-size: 14px;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all var(--transition-speed);
    background: linear-gradient(135deg, var(--blue) 0%, #1976D2 100%);
    color: white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

.route-mode-btn:hover {
    background: linear-gradient(135deg, #1976D2 0%, #1565C0 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

.route-mode-btn.active {
    background: linear-gradient(135deg, var(--red) 0%, #D32F2F 100%);
}

.route-mode-btn.active:hover {
    background: linear-gradient(135deg, #D32F2F 0%, #C62828 100%);
}

.route-icon {
    font-size: 1.25rem;
}

/* Route Mode Banner */
.route-banner {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 900;
    background: var(--blue);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    font-weight: 600;
    font-size: 14px;
    display: none;
    align-items: center;
    gap: 0.75rem;
}

.route-banner.active {
    display: flex;
}

.route-banner-icon {
    font-size: 1.25rem;
}

/* Route Stats Panel */
.route-stats {
    position: fixed;
    top: clamp(60px, 14vh, 90px);
    right: clamp(1px, 1vw, 10px);
    z-index: 1200;
    background: white;
    border-radius: clamp(8px, 2vw, 12px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    min-width: min(160px, 40vw);
    max-width: min(320px, 90vw);
    display: none;
    overflow: hidden;
    transition: all 0.3s ease;
}

.route-stats.active {
    display: block;
}

.route-stats.collapsed {
    min-width: auto;
    max-width: min(200px, 50vw);
}

.route-stats-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: clamp(0.5rem, 2vw, 1rem);
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-bottom: 1px solid #dee2e6;
    cursor: pointer;
    user-select: none;
    gap: clamp(0.3rem, 1vw, 0.5rem);
}

.route-stats-header:hover {
    background: linear-gradient(135deg, #e9ecef 0%, #dee2e6 100%);
}

.route-stats-header h3 {
    font-size: clamp(12px, 3vw, 16px);
    margin: 0;
    color: #333;
    flex: 1;
}

.route-stats-toggle {
    background: none;
    border: none;
    font-size: 14px;
    cursor: pointer;
    color: #666;
    padding: 0 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease;
}

.route-stats-toggle:hover {
    color: #333;
}

.route-stats-close {
    background: none;
    border: none;
    font-size: 20px;
    color: #999;
    cursor: pointer;
    padding: 0 4px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}

.route-stats-close:hover {
    color: var(--red);
}

/* Visual style for disabled route-stats close button */
.route-stats-close[aria-disabled="true"] {
    opacity: 0.45;
    cursor: default;
    pointer-events: auto; /* keep pointer so header click blocker still works */
    color: #999;
    background: transparent;
    border: none;
}

.route-stats-content {
    padding: clamp(0.5rem, 2vw, 1rem);
    max-height: 600px;
    overflow-y: auto;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    opacity: 1;
}

.route-stats.collapsed .route-stats-content {
    max-height: 0;
    padding: 0;
    opacity: 0;
    overflow: hidden;
}

.route-stat-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.1rem;
    font-size: clamp(11px, 2.5vw, 14px);
}

.stat-label {
    color: #666;
}

.stat-value {
    font-weight: 700;
    color: #333;
}

/* Road Type Breakdown Styles */
.route-stat-section {
    margin-top: 0.1rem;
    padding-top: 0.1rem;
    border-top: 1px solid #ddd;
}

.route-stat-section h4 {
    font-size: 13px;
    font-weight: 700;
    color: #333;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.road-type-stat {
    margin-bottom: 0.5rem;
}

.road-type-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    font-size: 12px;
}

.road-type-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    color: #333;
}

.road-type-color {
    width: 16px;
    height: 16px;
    border-radius: 3px;
    flex-shrink: 0;
}

.road-type-value {
    font-weight: 600;
    color: #333;
    min-width: 70px;
    text-align: right;
}

.road-type-percent {
    font-weight: 600;
    color: #666;
    min-width: 45px;
    text-align: right;
}

.road-type-bar {
    width: 100%;
    height: 12px;
    background: #f0f0f0;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}

.road-type-fill {
    height: 100%;
    transition: width 0.2s ease;
    border-radius: 6px;
}

/* Mobile Adjustments */
@media (max-width: 768px) {
    .route-stats {
        top: 76px;
        right: 16px;
        min-width: 180px;
        max-width: calc(100vw - 20px);
    }

    .route-stats-header {
        padding: 0.75rem;
    }

    .route-stats-header h3 {
        font-size: 14px;
    }

    .route-stats-content {
        padding: 0.75rem;
    }

    .route-stat-row {
        font-size: 13px;
    }

    .road-type-header {
        font-size: 11px;
    }
}

@media (max-width: 480px) {
    .route-stats {
        top: 68px; /* Adjusted for small mobile */
        right: 12px;
        max-width: calc(100vw - 24px);
    }
}

/* Route Instructions */
.route-instructions {
    position: fixed;
    top: 580px;
    right: 20px;
    z-index: 900;
    background: white;
    border-radius: 12px;
    padding: 0.75rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    max-width: 300px;
    display: none;
}

.route-instructions.active {
    display: block;
}

.route-instructions-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    cursor: pointer;
}

.route-instructions-header h4 {
    margin: 0;
    color: #333;
    font-size: 13px;
    font-weight: 700;
    flex: 1;
}

.route-instructions-toggle {
    background: none;
    border: none;
    color: #333;
    font-size: 14px;
    cursor: pointer;
    padding: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
}

.route-instructions-toggle.collapsed {
    transform: rotate(-90deg);
}

.route-instructions-close {
    background: none;
    border: none;
    font-size: 20px;
    color: #999;
    cursor: pointer;
    padding: 0 4px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}

.route-instructions-close:hover {
    color: var(--red);
}

.route-instructions-content {
    list-style: none;
    padding: 0;
    margin: 0.5rem 0 0 0;
    max-height: 500px;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    opacity: 1;
}

.route-instructions-content.collapsed {
    max-height: 0;
    opacity: 0;
    margin: 0;
}

.route-instructions-content li {
    padding: 0.15rem 0;
    color: #666;
    font-size: 11px;
}

/* Mobile Adjustments - HIDE COMPLETELY ON MOBILE */
@media (max-width: 768px) {
    .route-instructions {
        display: none !important; /* Force hide on mobile */
    }
    
    /* Even when active class is present, keep it hidden */
    .route-instructions.active {
        display: none !important;
    }
}

@media (max-width: 480px) {
    .route-instructions {
        display: none !important;
    }
    
    .route-instructions.active {
        display: none !important;
    }
}

/* Route Action Buttons */
.clear-route-btn,
.export-gpx-btn {
    padding: 1rem 1.5rem;
    border: none;
    border-radius: 50px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all var(--transition-speed);
    color: white;
    -webkit-tap-highlight-color: transparent;
}

.clear-route-btn {
    background: linear-gradient(135deg, var(--red) 0%, #D32F2F 100%);
}

.clear-route-btn:hover {
    background: linear-gradient(135deg, #D32F2F 0%, #C62828 100%);
    transform: translateY(-4px);
    box-shadow: 0 8px 28px rgba(244, 67, 54, 0.4);
}

.export-gpx-btn {
    background: linear-gradient(135deg, var(--blue) 0%, #1976D2 100%);
}

.export-gpx-btn:hover {
    background: linear-gradient(135deg, #1976D2 0%, #1565C0 100%);
    transform: translateY(-4px);
    box-shadow: 0 8px 28px rgba(33, 150, 243, 0.4);
}

/* Mobile Adjustments for Routing */
@media (max-width: 768px) {
    .route-mode-btn .route-text {
        display: none;
    }
    
    .route-mode-btn {
        padding: 0.5rem;
        min-width: 44px;
        justify-content: center;
    }
    
    .route-banner {
        left: 10px;
        right: 10px;
        transform: none;
        font-size: 13px;
        padding: 0.875rem 1.25rem;
    }
    
    .route-stats {
        right: 10px;
        top: 70px;
        min-width: 180px;
        padding: 1rem;
    }
    
    .route-instructions {
        bottom: 100px;
        left: 10px;
        right: 10px;
        transform: none;
        max-width: none;
    }
    
    .clear-route-btn,
    .export-gpx-btn {
        padding: 0.875rem 1.25rem;
        font-size: 13px;
    }
    
    .btn-text {
        display: none;
    }
}

/* Waypoint marker styles for draggable markers */
.wp-marker {
    display: block;
    line-height: 0;
}
.wp-marker .wp-inner {
    transition: all 0.12s ease;
    display: block;
}
.wp-marker .wp-inner.selected {
    border-color: #FFD700 !important;
    box-shadow: 0 0 8px rgba(255, 215, 0, 0.6);
}

/* Road Type Breakdown Styles */
.route-stat-section {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid #ddd;
}

.route-stat-section h4 {
    font-size: 13px;
    font-weight: 700;
    color: #333;
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.road-type-stat {
    margin-bottom: 1rem;
}

.road-type-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    font-size: 12px;
}

.road-type-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    color: #333;
}

.road-type-color {
    width: 16px;
    height: 16px;
    border-radius: 3px;
    flex-shrink: 0;
}

.road-type-value {
    font-weight: 600;
    color: #333;
    min-width: 70px;
    text-align: right;
}

.road-type-percent {
    font-weight: 600;
    color: #666;
    min-width: 45px;
    text-align: right;
}

.road-type-bar {
    width: 100%;
    height: 12px;
    background: #f0f0f0;
    border-radius: 6px;
    overflow: hidden;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}

.road-type-fill {
    height: 100%;
    transition: width 0.2s ease;
    border-radius: 6px;
}

/* ============================================================================
   ELEVATION PANEL - UPDATED
   ============================================================================ */

.elevation-panel {
    position: relative;
    width: 100%;
    height: 0;
    background: white;
    border-top: 1px solid #ddd;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
    padding: 0;
    z-index: 850;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: height 0.3s ease;
    flex-shrink: 0;
    min-height: 0;
}

.elevation-panel.active {
    height: 150px !important;
    min-height: 150px;
}

.elevation-panel.collapsed {
    height: 45px !important;
}

.elevation-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.3rem 0.5rem;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
}

.elevation-header:hover {
    background: #f9f9f9;
}

.elevation-header h3 {
    margin: 0;
    font-size: 11px;
    font-weight: 700;
    color: #333;
    flex: 1;
}

.elevation-toggle {
    background: none;
    border: none;
    font-size: 12px;
    cursor: pointer;
    color: #666;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease;
    min-height: auto;
    height: auto;
    line-height: 1;
}

.elevation-toggle:hover {
    color: #333;
}

.elevation-panel.collapsed .elevation-toggle {
    transform: rotate(180deg);
}

.elevation-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #666;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: auto;
    height: auto;
    line-height: 1;
}

.elevation-close:hover {
    color: #f44336;
}

.elevation-content {
    display: flex;
    flex: 1;
    min-height: 0;
    gap: 0.5rem;
    padding: 0.5rem;
    overflow: hidden;
    transition: opacity 0.3s ease;
}

.elevation-panel.collapsed .elevation-content {
    display: none;
}

#elevationCanvas {
    flex: 1;
    height: 100%;
    border-radius: 4px;
    background: #f9f9f9;
    border: 1px solid #eee;
}

.elevation-stats {
    display: flex;
    flex-direction: row;
    gap: 0.75rem;
    flex-shrink: 0;
    align-items: center;
}

.elevation-stat {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.elevation-stat .stat-label {
    font-size: 9px;
    color: #999;
    font-weight: 600;
    text-transform: uppercase;
    white-space: nowrap;
}

.elevation-stat .stat-value {
    font-size: 10px;
    font-weight: 700;
    color: #333;
    white-space: nowrap;
}

/* ============================================================================
   MOBILE RESPONSIVE ADJUSTMENTS
   ============================================================================ */

@media (max-width: 768px) {
    .floating-actions {
        bottom: 16px;
    }
    
    .elevation-panel.active ~ .floating-actions {
        bottom: 136px; /* 120px panel height + 16px margin */
    }
    
    .elevation-panel.collapsed ~ .floating-actions {
        bottom: 61px; /* 45px panel height + 16px margin */
    }
    
    .elevation-panel.active {
        height: 120px !important;
        min-height: 120px;
    }

    .elevation-content {
        gap: 0.3rem;
        padding: 0.25rem;
    }

    .elevation-header {
        padding: 0.2rem 0.3rem;
    }

    .elevation-header h3 {
        font-size: 9px;
    }

    .elevation-toggle {
        font-size: 10px;
        padding: 0;
    }

    .elevation-close {
        font-size: 16px;
        padding: 0;
    }

    .elevation-stats {
        gap: 0.4rem;
    }

    .elevation-stat {
        flex-direction: row;
    }

    .elevation-stat .stat-label {
        font-size: 8px;
    }

    .elevation-stat .stat-value {
        font-size: 9px;
    }
    
    .primary-route-btn {
        width: min(300px, 85vw);
        font-size: 14px;
    }
    
    .clear-route-btn,
    .export-gpx-btn {
        padding: 0.875rem 1.25rem;
        font-size: 13px;
    }
}

@media (max-width: 480px) {
    .floating-actions {
        bottom: 12px;
    }
    
    .elevation-panel.active ~ .floating-actions {
        bottom: 132px;
    }
    
    .elevation-panel.collapsed ~ .floating-actions {
        bottom: 57px;
    }
    
    .primary-route-btn {
        width: min(280px, 92vw);
        font-size: 13px;
    }
}

/* ============================================================================
   WEATHER PANEL ENHANCEMENTS - Added
   ============================================================================ */

/* Weather Status */
.weather-status {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    border-radius: 12px;
    border: 2px solid #2196F3;
    transition: all 0.3s ease;
}

.weather-icon {
    font-size: 2.5rem;
    flex-shrink: 0;
    animation: weatherPulse 2s ease-in-out infinite;
}

@keyframes weatherPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.weather-text {
    flex: 1;
    font-size: 13px;
    color: #1565C0;
    font-weight: 600;
    line-height: 1.4;
}

.weather-text small {
    display: block;
    margin-top: 0.25rem;
    font-size: 11px;
    opacity: 0.9;
}

/* Muddy conditions styling */
.weather-status.muddy {
    background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%);
    border-color: #FF9800;
    animation: muddyWarning 1.5s ease-in-out infinite;
}

@keyframes muddyWarning {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 152, 0, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(255, 152, 0, 0); }
}

.weather-status.muddy .weather-text {
    color: #E65100;
}

.weather-status.muddy .weather-icon {
    animation: muddyShake 0.5s ease-in-out infinite;
}

@keyframes muddyShake {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-5deg); }
    75% { transform: rotate(5deg); }
}

/* Weather loading state (best-effort; :has/:contains are not fully supported everywhere) */
/* Fallback: add .loading class to .weather-status from JS if needed */
.weather-status.loading .weather-icon {
    animation: spin 1s linear infinite;
}

/* Weather error/unavailable state */
.weather-status.unavailable {
    background: linear-gradient(135deg, #f5f5f5 0%, #e0e0e0 100%);
    border-color: #9E9E9E;
}

.weather-status.unavailable .weather-text {
    color: #616161;
}

/* Weather toggle in legend */
.weather-toggle {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    transition: opacity 0.3s ease;
}

.weather-toggle:hover {
    opacity: 0.9;
}

.switch-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: #475e41;
    position: relative;
    user-select: none;
}

.switch-label input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-slider {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    background: #ccc;
    border-radius: 11px;
    transition: background 0.3s;
}

.switch-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: white;
    top: 2px;
    left: 2px;
    transition: transform 0.3s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.switch-label input:checked + .switch-slider {
    background: var(--primary-color);
}

.switch-label input:checked + .switch-slider::before {
    transform: translateX(18px);
}

.switch-label input:disabled + .switch-slider {
    opacity: 0.5;
    cursor: not-allowed;
}

.switch-text {
    user-select: none;
}

/* Notification styling for weather warnings */
.notification.warning {
    background: linear-gradient(135deg, #FF9800 0%, #F57C00 100%);
    color: white;
    animation: slideInWarning 0.3s ease-out;
}

@keyframes slideInWarning {
    from {
        transform: translateX(400px) scale(0.9);
        opacity: 0;
    }
    to {
        transform: translateX(0) scale(1);
        opacity: 1;
    }
}

/* Weather data attribution (optional) */
.weather-attribution {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    font-size: 10px;
    color: #999;
    text-align: center;
}

.weather-attribution a {
    color: inherit;
    text-decoration: none;
}

.weather-attribution a:hover {
    text-decoration: underline;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .weather-status {
        padding: 0.875rem;
    }

    .weather-icon {
        font-size: 2rem;
    }

    .weather-text {
        font-size: 12px;
    }

    .weather-text small {
        font-size: 10px;
    }

    .switch-label {
        font-size: 11px;
    }

    .switch-slider {
        width: 36px;
        height: 20px;
    }

    .switch-slider::before {
        width: 16px;
        height: 16px;
    }

    .switch-label input:checked + .switch-slider::before {
        transform: translateX(16px);
    }
}

@media (max-width: 480px) {
    .weather-status {
        padding: 0.75rem;
        gap: 0.75rem;
    }

    .weather-icon {
        font-size: 1.75rem;
    }

    .weather-text {
        font-size: 11px;
    }
}

/* ============================================================================
   TIDEACE HOMEPAGE BANNER POSITIONING - UPDATED
   ============================================================================ */

#tideaceHomepageBanner {
    position: absolute;
    bottom: 10px; /* Above the "Find Gravel" button */
    left: 20px;
    z-index: 850;
    width: auto;
    max-width: 400px;
    pointer-events: none;
}

#tideaceHomepageBanner > * {
    pointer-events: all;
}

@media (max-width: 768px) {
    #tideaceHomepageBanner {
        bottom: 90px;
        left: 16px;
        right: 16px;
        max-width: calc(100% - 32px);
    }
}

@media (max-width: 480px) {
    #tideaceHomepageBanner {
        bottom: 85px;
        left: 12px;
        right: 12px;
        max-width: calc(100% - 24px);
    }
}
/* ============================================================================
   LEGAL FOOTER
   ============================================================================ */

.legal-footer {
    background: #f8f8f8;
    border-top: 1px solid #ddd;
    padding: 20px 0;
    text-align: center;
    font-size: 0.9em;
    color: #666;
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

.footer-copyright {
    margin-bottom: 10px;
}

.footer-links {
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
}

.footer-links a {
    color: #475e41;
    text-decoration: none;
    transition: color 0.2s;
}

.footer-links a:hover {
    color: #5a7550;
    text-decoration: underline;
}

@media (max-width: 600px) {
    .footer-links {
        flex-direction: column;
        gap: 10px;
    }
}

/* ============================================================================
   LEGAL PAGES - SCROLLABLE
   ============================================================================ */

.legal-container {
    overflow-y: auto;
    max-height: 90vh;
}

/* ============================================================================
   SIDEBAR LEGAL FOOTER
   ============================================================================ */

.sidebar-legal-footer {
    margin-top: auto;
    padding: 1rem 0 0 0;
    border-top: 1px solid var(--gray-medium, #e0e0e0);
    font-size: 0.8em;
    color: var(--text-secondary, #666);
}

.sidebar-copyright {
    margin: 0 0 0.75rem 0;
    text-align: center;
    font-size: 0.9em;
}

.sidebar-legal-links {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.sidebar-legal-links a {
    color: var(--primary-color, #475e41);
    text-decoration: none;
    padding: 0.4rem 0;
    transition: color 0.2s;
    font-size: 0.95em;
    text-align: center;
}

.sidebar-legal-links a:hover {
    color: var(--primary-dark, #5a7550);
    text-decoration: underline;
}

/* ==========================================================================
   Auto-Route Generator Styles
   ========================================================================== */

.auto-gen-btn {
    background: linear-gradient(135deg, #FF9800, #F44336) !important;
    color: white !important;
    border: none;
    box-shadow: 0 4px 15px rgba(244, 67, 54, 0.4);
}

.auto-gen-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(244, 67, 54, 0.6);
}

.auto-route-modal {
    max-width: 400px;
    padding: 24px;
    border-radius: 12px;
    background: #ffffff;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.auto-route-modal h2 {
    margin: 0;
    color: #333;
    font-size: 1.5rem;
}

.auto-route-modal .modal-body {
    margin-top: 16px;
}

.auto-route-modal p {
    color: #666;
    margin-bottom: 20px;
    line-height: 1.5;
}

.control-group {
    margin-bottom: 20px;
}

.control-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #333;
}

.control-group input[type="range"] {
    width: 100%;
    margin-top: 8px;
}

.action-btn {
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.outline-btn {
    background: transparent;
    border: 2px solid #4CAF50;
    color: #4CAF50;
    width: 100%;
}

.outline-btn:hover {
    background: rgba(76, 175, 80, 0.1);
}

.primary-btn {
    background: #4CAF50;
    color: white;
}

.primary-btn:hover {
    background: #388E3C;
}

.primary-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.full-width {
    width: 100%;
}

.info-text {
    font-size: 0.9rem;
    color: #2196F3;
    font-weight: 500;
}
