/* ============================================================================
   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: #2196F3;
    --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: 280px;
    --header-height: 64px;
    --transition-speed: 0.3s;
}

html, body {
    height: 100%;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* 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);
    color: var(--text-primary);
    font-size: 16px;
    line-height: 1.5;
}

/* 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: 0.75rem 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: 0.5rem;
}

.logo-icon {
    font-size: 1.75rem;
}

.logo .title {
    font-size: 1.25rem;
    font-weight: 700;
    white-space: nowrap;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.bike-type-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(--accent-purple) 0%, #7B1FA2 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;
}

.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;
}

/* Hamburger Menu Toggle (Mobile Only) */
.menu-toggle {
    display: none;
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 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: 24px;
    height: 2px;
    background: white;
    margin: 0 auto;
    transition: all var(--transition-speed);
}

.hamburger::before,
.hamburger::after {
    content: '';
    position: absolute;
    width: 24px;
    height: 2px;
    background: white;
    left: 0;
    transition: all var(--transition-speed);
}

.hamburger::before {
    top: -8px;
}

.hamburger::after {
    bottom: -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;
}

.sidebar-section {
    padding: 1.25rem;
    border-bottom: 1px solid var(--gray-medium);
}

.sidebar-section h3 {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    letter-spacing: 0.5px;
}

.sidebar-close {
    display: none;
}

.sidebar-overlay {
    display: none;
}

/* Legend Section */
.legend-items {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 14px;
    color: var(--text-primary);
}

.legend-color {
    width: 40px;
    height: 20px;
    border-radius: 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: 1rem;
    padding: 1rem;
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    border-radius: 12px;
    border: 2px solid var(--blue);
}

.weather-icon {
    font-size: 2.5rem;
    flex-shrink: 0;
}

.weather-text {
    flex: 1;
    font-size: 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;
    -webkit-tap-highlight-color: transparent;
}

.sidebar-btn:hover {
    background: #e3f2fd;
    border-color: var(--blue);
    transform: translateX(4px);
}

.sidebar-btn:active {
    transform: translateX(2px);
}

.btn-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
}

/* Filter Section */
.filter-toggles {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.filter-toggle {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    background: white;
    border: 2px solid #ddd;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    width: 100%;
    text-align: left;
    -webkit-tap-highlight-color: transparent;
}

.toggle-indicator {
    width: 20px;
    height: 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: 10px;
    height: 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; }

/* 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;
}

/* ============================================================================
   MAP WRAPPER
   ============================================================================ */

.map-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#map {
    width: 100%;
    height: 100%;
}

/* ============================================================================
   LEGEND OVERLAY (Always visible on map)
   ============================================================================ */

.legend-overlay {
    position: absolute;
    top: 20px;
    left: 20px;
    background: rgba(242, 234, 215, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 800;
    min-width: 160px;
}

.legend-header {
    margin-bottom: 8px;
}

.legend-header h3 {
    font-size: 16px;
    font-weight: 700;
    color: #000;
    margin: 0;
}

.legend-overlay .legend-items {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.legend-item-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    padding: 6px 8px;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    color: #000;
    text-align: left;
    -webkit-tap-highlight-color: transparent;
}

.legend-item-toggle:hover {
    background: rgba(255, 255, 255, 0.5);
}

.legend-item-toggle:active {
    transform: scale(0.98);
}

.legend-square {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    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);
}

.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
   ============================================================================ */

.floating-actions {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    z-index: 1000;
    pointer-events: none;
}

.floating-actions > * {
    pointer-events: all;
}

.find-gravel-btn {
    padding: 1rem 2rem;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    color: white;
    border: none;
    border-radius: 50px;
    font-size: 16px;
    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;
    gap: 0.25rem;
    min-width: 160px;
    -webkit-tap-highlight-color: transparent;
}

.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);
}

.btn-icon-large {
    font-size: 1.5rem;
}

.btn-text {
    font-size: 16px;
    line-height: 1.2;
}

.btn-hint {
    font-size: 11px;
    opacity: 0.8;
    font-weight: 400;
}

.clear-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 48px;
    height: 48px;
    background: white;
    border: 2px solid var(--gray-medium);
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    transition: all var(--transition-speed);
    box-shadow: var(--shadow-md);
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    -webkit-tap-highlight-color: transparent;
}

.clear-btn:hover {
    background: var(--red);
    color: white;
    border-color: var(--red);
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(244, 67, 54, 0.4);
}

.clear-btn:active {
    transform: scale(1.05);
}

/* ============================================================================
   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
   ============================================================================ */

.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 - MOBILE
   ============================================================================ */

@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;
    }

    .bike-type-btn .bike-name {
        display: none;
    }

    .bike-type-btn {
        padding: 0.5rem;
        min-width: 44px;
        justify-content: center;
    }

    .bike-icon {
        font-size: 1.5rem;
    }

    /* 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: 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;
    }

    .sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
    }

    .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;
    }

    /* Legend overlay adjustments for mobile */
    .legend-overlay {
        top: 16px;
        left: 16px;
        padding: 10px;
        min-width: 140px;
        max-width: calc(100vw - 120px);
    }

    .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;
    }
}

/* ============================================================================
   RESPONSIVE DESIGN - SMALL MOBILE
   ============================================================================ */

@media (max-width: 480px) {
    .sidebar {
        width: 90%;
        max-width: 280px;
    }

    .find-gravel-btn {
        padding: 0.75rem 1.25rem;
        font-size: 13px;
    }

    .floating-actions {
        bottom: 16px;
    }

    .clear-btn {
        width: 40px;
        height: 40px;
        top: 12px;
        right: 12px;
    }

    .legend-overlay {
        top: 12px;
        left: 12px;
        padding: 8px;
        min-width: 130px;
    }

    .legend-header h3 {
        font-size: 13px;
    }

    .legend-item-toggle {
        padding: 4px 5px;
        font-size: 12px;
        gap: 5px;
    }

    .legend-square {
        width: 22px;
        height: 22px;
    }
}

/* ============================================================================
   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;
    }
}

/* ============================================================================
   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;
    }
}