/* Global Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    background: #0a0e27;
    color: #e8eaed;
    line-height: 1.6;
    position: relative;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Prevent horizontal scroll on mobile */
html, body {
    overflow-x: hidden;
    width: 100%;
}

/* Rider watermark */
body::before {
    content: '';
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-15deg);
    width: 600px;
    height: 600px;
    background-image: url('../img/rider-outline.jpeg');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    opacity: 0.03;
    z-index: 0;
    pointer-events: none;
    filter: grayscale(100%) contrast(1.5);
}

/* Hero Section */
.hero {
    position: relative;
    background: linear-gradient(120deg, #0a0e27 0%, #0f1420 25%, #141b2d 50%, #1a2332 75%, #1f2937 100%);
    border-bottom: 2px solid #2563eb;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.hero-bg {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: url('../img/hero-mono-blue-alpha.png');
    background-size: 500px auto;
    background-position: right center;
    background-repeat: no-repeat;
    opacity: 0.18;
    filter: contrast(1.15) brightness(0.9);
    z-index: 0;
}

.hero-content {
    max-width: 1800px;
    margin: 0 auto;
    padding: 24px 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    z-index: 1;
}

.hero-top-row {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-bottom: 8px;
}

.hero-badge {
    display: inline-block;
    background: rgba(59, 130, 246, 0.2);
    border: 1px solid #3b82f6;
    color: #60a5fa;
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 2px;
}

.hero-title {
    margin: 0;
    font-size: 36px;
    font-weight: 800;
    color: #ffffff;
    letter-spacing: -1px;
    line-height: 1;
}

.hero-name {
    color: #e0e7ff;
    text-shadow: 0 0 20px rgba(96, 165, 250, 0.3);
}

.hero-divider {
    color: #60a5fa;
    margin: 0 16px;
}

.hero-bike {
    color: #93c5fd;
    text-shadow: 0 0 20px rgba(147, 197, 253, 0.2);
}

.hero-subtitle {
    font-size: 13px;
    color: #8b92a7;
    font-weight: 500;
    margin-bottom: 10px;
    line-height: 1.4;
}

.hero-bottom-row {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.hero-locations {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.hero-locations span {
    font-size: 12px;
    color: #8b92a7;
    background: rgba(59, 130, 246, 0.1);
    padding: 4px 12px;
    border-radius: 12px;
}

.hero-link {
    display: inline-block;
    color: #3b82f6;
    text-decoration: none;
    font-size: 11px;
    font-weight: 600;
    padding: 5px 12px;
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid #3b82f6;
    border-radius: 6px;
    transition: all 0.2s;
    white-space: nowrap;
}

.hero-link:hover {
    background: rgba(59, 130, 246, 0.2);
    transform: translateY(-2px);
}

.hero-meta {
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-items: flex-end;
}

.hero-meta-item {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.hero-meta-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #6b7280;
}

.hero-meta-value {
    font-size: 14px;
    font-weight: 700;
    color: #4ade80;
    font-family: 'Courier New', monospace;
}

/* Container */
.container {
    max-width: 1800px;
    margin: 0 auto;
    padding: 24px 32px;
    width: 100%;
    overflow-x: hidden;
}

/* Stats Bar */
.stats-bar {
    background: #141b2d;
    border: 1px solid #2d3748;
    border-radius: 4px;
    padding: 16px;
    margin-bottom: 24px;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 20px;
}

.stat-item {
    border-right: 1px solid #2d3748;
    padding-right: 20px;
}

.stat-item:last-child {
    border-right: none;
}

.stat-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #8b92a7;
    margin-bottom: 6px;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: #ffffff;
    font-family: 'Courier New', monospace;
}

.stat-meta {
    font-size: 10px;
    color: #6b7280;
    margin-top: 2px;
}

/* Color Classes */
.stat-green { color: #4ade80; }
.stat-blue { color: #60a5fa; }
.stat-orange { color: #f59e0b; }
.stat-purple { color: #a78bfa; }
.stat-red { color: #ef4444; }
.stat-amber { color: #fb923c; }
.stat-teal { color: #10b981; }

.highlight {
    color: #4ade80;
    font-family: 'Courier New', monospace;
}

.mono {
    font-family: 'Courier New', monospace;
}

/* Filter Bar */
.filter-bar {
    background: #141b2d;
    border: 1px solid #2d3748;
    border-radius: 4px;
    padding: 16px;
    margin-bottom: 24px;
    display: flex;
    gap: 16px;
    align-items: center;
    flex-wrap: wrap;
}

.filter-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #8b92a7;
    font-weight: 600;
}

.filter-btn {
    background: #1a2332;
    color: #8b92a7;
    border: 1px solid #2d3748;
    padding: 6px 14px;
    border-radius: 3px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
}

.filter-btn:hover {
    background: #2d3748;
}

.filter-btn.active {
    background: #3b82f6;
    color: white;
    border-color: #3b82f6;
    font-weight: 600;
}

.filter-divider {
    border-left: 1px solid #2d3748;
    height: 20px;
    margin: 0 8px;
}

/* Main Grid */
.main-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
    margin-bottom: 24px;
    max-width: 100%;
}

.left-column, .right-column {
    display: flex;
    flex-direction: column;
    gap: 24px;
    min-width: 0; /* Prevent flex children from overflowing */
}

/* Cards */
.card {
    background: #141b2d;
    border: 1px solid #2d3748;
    border-radius: 4px;
    padding: 16px;
    max-width: 100%;
    overflow-x: auto;
}

.card h2, .card h3 {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: #8b92a7;
    margin: 0 0 12px 0;
    font-weight: 600;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

/* Map */
#map {
    height: 500px;
    border-radius: 4px;
    border: 1px solid #2d3748;
}

.map-controls {
    display: flex;
    gap: 8px;
}

.map-btn {
    background: #1a2332;
    color: #8b92a7;
    border: 1px solid #2d3748;
    padding: 4px 10px;
    border-radius: 3px;
    font-size: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.map-btn:hover {
    background: #2d3748;
}

.map-btn.active {
    background: #3b82f6;
    color: white;
}

.map-legend {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-top: 12px;
    font-size: 10px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #8b92a7;
}

.legend-color {
    width: 24px;
    height: 3px;
    border-radius: 2px;
}

/* Regions */
.region-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.region-card {
    background: #1a2332;
    border-left: 3px solid;
    padding: 12px;
    border-radius: 3px;
}

.region-label {
    font-size: 11px;
    color: #8b92a7;
    margin-bottom: 6px;
}

.region-value {
    font-size: 20px;
    font-weight: 700;
    color: #ffffff;
    font-family: 'Courier New', monospace;
    margin-bottom: 4px;
}

.region-meta {
    font-size: 9px;
    color: #6b7280;
}

/* Charts */
.chart-container {
    position: relative;
    height: 200px;
    z-index: 1;
}

.chart-container canvas {
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.chart-divider {
    margin: 16px 0;
    padding-top: 16px;
    border-top: 1px solid #2d3748;
}

/* Top Rides */
.top-rides {
    font-size: 11px;
}

.top-ride {
    display: flex;
    justify-content: space-between;
    padding: 8px;
    background: #1a2332;
    margin-bottom: 4px;
    border-radius: 3px;
    border-left: 3px solid #2d3748;
    color: #e8eaed;
}

.top-ride.clickable {
    cursor: pointer;
    transition: all 0.2s;
}

.top-ride.clickable:hover {
    background: #2d3748;
    transform: translateX(3px);
}

.rank {
    opacity: 0.5;
    margin-right: 4px;
}

/* Waypoints */
.waypoints-list {
    font-size: 11px;
    color: #e8eaed;
    line-height: 1.8;
}

.waypoint-item {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    border-bottom: 1px solid #1a2332;
}

/* All Rides List */
.all-rides-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 500px;
    overflow-y: auto;
    padding-right: 8px;
}

.all-rides-list::-webkit-scrollbar {
    width: 6px;
}

.all-rides-list::-webkit-scrollbar-track {
    background: #1a2332;
    border-radius: 3px;
}

.all-rides-list::-webkit-scrollbar-thumb {
    background: #2d3748;
    border-radius: 3px;
}

.all-rides-list::-webkit-scrollbar-thumb:hover {
    background: #3b82f6;
}

.ride-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: #1a2332;
    border-radius: 3px;
    border-left: 3px solid #2d3748;
    cursor: pointer;
    transition: all 0.2s;
}

.ride-card:hover {
    background: #2d3748;
    transform: translateX(3px);
}

.ride-card-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.ride-card-name {
    font-size: 12px;
    color: #e8eaed;
    font-weight: 500;
}

.ride-card-meta {
    display: flex;
    gap: 12px;
    font-size: 10px;
    color: #8b92a7;
}

.ride-card-distance {
    font-size: 12px;
    font-weight: 600;
}

.ride-card-source-btn {
    padding: 4px 12px;
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.3);
    color: #60a5fa;
    border-radius: 3px;
    font-size: 10px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    margin-left: 12px;
}

.ride-card-source-btn:hover {
    background: rgba(59, 130, 246, 0.2);
    border-color: #60a5fa;
}

/* Analytics Grid */
.analytics-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
    margin-bottom: 24px;
    max-width: 100%;
}

.analytics-grid > .card {
    min-width: 0; /* Prevent grid items from overflowing */
}

/* Tags */
.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 10px;
}

.tag {
    background: #1a2332;
    color: #8b92a7;
    padding: 5px 10px;
    border-radius: 3px;
    border: 1px solid #2d3748;
}

/* Characteristic bars */
.characteristic-bars {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 4px 0;
}

.characteristic-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 11px;
}

.characteristic-label {
    min-width: 100px;
    color: #8b92a7;
    flex-shrink: 0;
}

.characteristic-bar-container {
    flex: 1;
    background: #1a2332;
    height: 20px;
    border-radius: 3px;
    overflow: hidden;
    position: relative;
    max-width: 100%;
}

.characteristic-bar {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s ease;
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.3);
}

.characteristic-value {
    min-width: 35px;
    text-align: right;
    color: #8b92a7;
    font-weight: 600;
    font-family: 'Courier New', monospace;
    flex-shrink: 0;
}

/* Calendar Heatmap */
#calendarHeatmap {
    overflow-x: auto;
    font-size: 10px;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

#calendarHeatmap::-webkit-scrollbar {
    height: 6px;
}

#calendarHeatmap::-webkit-scrollbar-track {
    background: #1a2332;
    border-radius: 3px;
}

#calendarHeatmap::-webkit-scrollbar-thumb {
    background: #2d3748;
    border-radius: 3px;
}

#calendarHeatmap::-webkit-scrollbar-thumb:hover {
    background: #3b82f6;
}

/* Table */
.table-card {
    overflow: hidden;
    padding: 0;
}

.table-header {
    background: #1a2332;
    padding: 16px;
    border-bottom: 1px solid #2d3748;
}

.rides-table {
    width: 100%;
    border-collapse: collapse;
}

.rides-table thead {
    background: #1a2332;
}

.rides-table th {
    text-align: left;
    padding: 12px 16px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #8b92a7;
    font-weight: 600;
    border-bottom: 1px solid #2d3748;
}

.rides-table th:last-child {
    text-align: center;
}

.rides-table tbody tr {
    border-bottom: 1px solid #2d3748;
}

.rides-table td {
    padding: 12px 16px;
    font-size: 11px;
}

.rides-table td:first-child {
    font-family: 'Courier New', monospace;
    color: #8b92a7;
}

.rides-table td:nth-child(2) {
    color: #e8eaed;
}

.rides-table td:nth-child(3) {
    font-family: 'Courier New', monospace;
}

.rides-table td:nth-child(4) {
    color: #8b92a7;
}

.rides-table td:last-child {
    text-align: center;
}

.view-btn {
    background: #1a2332;
    color: #60a5fa;
    border: 1px solid #2d3748;
    padding: 4px 10px;
    border-radius: 3px;
    font-size: 10px;
    cursor: pointer;
}

.view-btn:hover {
    background: #2d3748;
}

.type-badge {
    background: #1a2332;
    padding: 4px 8px;
    border-radius: 3px;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(10, 14, 39, 0.95);
    animation: fadeIn 0.2s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: #141b2d;
    margin: 2vh auto;
    border: 1px solid #2d3748;
    border-radius: 8px;
    width: 96%;
    max-width: 1600px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    position: relative;
    max-height: 96vh;
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 1001;
    background: rgba(20, 27, 45, 0.9);
    border: 1px solid #2d3748;
    color: #8b92a7;
    font-size: 28px;
    cursor: pointer;
    line-height: 1;
    padding: 4px 12px;
    border-radius: 4px;
    transition: all 0.2s;
}

.modal-close:hover {
    background: rgba(45, 55, 72, 0.95);
    color: #ffffff;
}

.modal-map {
    height: 400px;
    background: #0a0e27;
    border-radius: 8px 8px 0 0;
    position: relative;
}

/* Modal with details section below map */
.modal-with-details {
    display: flex;
    flex-direction: column;
    max-height: 85vh;
    overflow: hidden;
}

.modal-with-details .modal-map {
    flex-shrink: 0;
}

/* Modal with sidebar layout (waypoints on left) */
.modal-with-sidebar {
    height: 96vh;
    max-height: 96vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-layout {
    display: flex;
    gap: 0;
    flex: 1;
    overflow: hidden;
}

.modal-sidebar {
    width: 280px;
    flex-shrink: 0;
    background: #0a0e27;
    border-right: 1px solid #2d3748;
    overflow-y: auto;
}

.modal-sidebar::-webkit-scrollbar {
    width: 6px;
}

.modal-sidebar::-webkit-scrollbar-track {
    background: rgba(26, 35, 50, 0.5);
}

.modal-sidebar::-webkit-scrollbar-thumb {
    background: rgba(139, 146, 167, 0.5);
    border-radius: 3px;
}

.modal-sidebar-card {
    padding: 16px;
}

.modal-sidebar-title {
    font-size: 11px;
    color: #8b92a7;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 12px;
    font-weight: 600;
}

.modal-sidebar-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.modal-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-main .modal-map {
    flex: 1;
    border-radius: 0 8px 0 0;
}

.modal-main .modal-details {
    flex-shrink: 0;
}

.modal-details {
    background: #141b2d;
    padding: 12px 20px;
    border-radius: 0 0 8px 8px;
    border-top: 1px solid #2d3748;
}

.modal-details-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.modal-details-header h3 {
    margin: 0;
    font-size: 16px;
    color: #ffffff;
    font-weight: 600;
}

.modal-details-info {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    font-size: 11px;
    color: #8b92a7;
    font-family: 'Courier New', monospace;
}

.modal-waypoints-section {
    margin-bottom: 16px;
}

.modal-waypoints-title {
    font-size: 11px;
    color: #8b92a7;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
    font-weight: 600;
}

.modal-waypoints-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 8px;
}

.modal-waypoints-list .waypoint-item {
    background: #1a2332;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 11px;
    color: #e8eaed;
    border-left: 3px solid #3b82f6;
}

.modal-details-actions {
    display: flex;
    gap: 12px;
    margin-top: 8px;
}

.map-overlay {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 1000;
    background: rgba(20, 27, 45, 0.92);
    border: 1px solid rgba(45, 55, 72, 0.9);
    border-radius: 6px;
    padding: 12px 16px;
    min-width: 280px;
    max-width: 350px;
    backdrop-filter: blur(12px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    max-height: 580px;
    overflow-y: auto;
    pointer-events: none; /* Allow clicks to pass through to map */
    transition: all 0.3s ease;
}

.map-overlay-toggle {
    display: none;
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(59, 130, 246, 0.9);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    pointer-events: auto;
    z-index: 10;
    transition: all 0.2s;
}

.map-overlay-toggle:active {
    background: rgba(37, 99, 235, 0.9);
    transform: scale(0.95);
}

/* Re-enable pointer events for interactive elements inside overlay */
.map-overlay button,
.map-overlay a,
.map-overlay .waypoint-item {
    pointer-events: auto;
    cursor: pointer;
}

.map-overlay::-webkit-scrollbar {
    width: 6px;
}

.map-overlay::-webkit-scrollbar-track {
    background: rgba(26, 35, 50, 0.5);
    border-radius: 3px;
}

.map-overlay::-webkit-scrollbar-thumb {
    background: rgba(139, 146, 167, 0.5);
    border-radius: 3px;
}

.map-overlay::-webkit-scrollbar-thumb:hover {
    background: rgba(139, 146, 167, 0.7);
}

.overlay-header h3 {
    margin: 0;
    font-size: 16px;
    color: #ffffff;
    font-weight: 600;
    line-height: 1.4;
}

.overlay-info {
    margin: 8px 0 12px 0;
    font-size: 11px;
    color: #8b92a7;
    display: flex;
    gap: 8px;
    align-items: center;
    font-family: 'Courier New', monospace;
    flex-wrap: wrap;
}

.waypoints-section {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(45, 55, 72, 0.6);
}

.waypoints-title {
    font-size: 10px;
    color: #8b92a7;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    font-weight: 600;
}

.waypoint-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.waypoint-item {
    font-size: 10px;
    color: #8b92a7;
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
}

.waypoint-name {
    color: #e8eaed;
}

.waypoint-distance {
    color: #60a5fa;
    font-family: 'Courier New', monospace;
    font-size: 9px;
}

.overlay-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.nav-btn {
    background: #1a2332;
    color: #8b92a7;
    border: 1px solid #2d3748;
    padding: 6px 12px;
    border-radius: 3px;
    font-size: 11px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.nav-btn:hover {
    background: #2d3748;
    color: #ffffff;
}

.source-link {
    background: #1a2332;
    color: #8b92a7;
    border: 1px solid #2d3748;
    padding: 6px 12px;
    border-radius: 3px;
    font-size: 11px;
    text-decoration: none;
    font-weight: 600;
    transition: all 0.2s;
    display: inline-block;
}

.source-link:hover {
    background: #2d3748;
    color: #60a5fa;
}

/* Footer */
footer {
    background: #141b2d;
    border-top: 1px solid #2d3748;
    padding: 20px 32px;
    margin-top: 32px;
}

.footer-content {
    max-width: 1800px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    color: #6b7280;
}

/* All map zoom controls - position halfway down on right side */
#map .leaflet-top.leaflet-right,
#modalMap .leaflet-top.leaflet-right,
#waypointModalMap .leaflet-top.leaflet-right,
#compositeModalMap .leaflet-top.leaflet-right {
    top: 50% !important;
    transform: translateY(-50%);
}

/* Mobile Filter Toggle */
.filter-toggle {
    display: none;
    background: #3b82f6;
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    margin-bottom: 12px;
    transition: all 0.2s;
}

.filter-toggle:active {
    background: #2563eb;
}

.filter-toggle::after {
    content: ' ▼';
    font-size: 10px;
    margin-left: 8px;
}

.filter-toggle.active::after {
    content: ' ▲';
}

.filter-content {
    display: flex;
    gap: 16px;
    align-items: center;
    flex-wrap: wrap;
}

/* Composite overlay specific styles */
.composite-overlay {
    /* Desktop positioning */
    top: 20px;
    left: 20px;
    max-width: 300px;
}

.composite-controls {
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.composite-controls .map-btn {
    width: 100%;
}

.composite-legend {
    margin-top: 12px;
    background: rgba(20, 27, 45, 0.9);
    padding: 12px;
    border-radius: 4px;
}

/* Desktop: filters always visible, overlays expanded */
@media (min-width: 769px) {
    .filter-content {
        display: flex !important;
    }

    .filter-toggle {
        display: none !important;
    }

    .map-overlay-toggle {
        display: none !important;
    }

    .map-overlay {
        top: 10px !important;
        bottom: auto !important;
        left: 10px !important;
        right: auto !important;
        width: auto !important;
        max-height: 580px !important;
    }

    .composite-overlay {
        top: 20px !important;
        left: 20px !important;
        bottom: auto !important;
        right: auto !important;
        max-width: 300px !important;
        width: auto !important;
    }
}

/* Responsive */
@media (max-width: 1200px) {
    .container {
        padding: 20px 24px;
    }

    .stats-bar {
        grid-template-columns: repeat(4, 1fr);
        gap: 16px;
    }
}

@media (max-width: 1024px) {
    .main-grid {
        grid-template-columns: 1fr;
    }

    .analytics-grid {
        grid-template-columns: 1fr;
    }

    .stats-bar {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 768px) {
    /* Hero Mobile */
    .hero-content {
        flex-direction: column;
        align-items: flex-start;
        gap: 20px;
        padding: 24px 20px;
    }

    .hero-badge {
        font-size: 9px;
        padding: 5px 12px;
        margin-bottom: 12px;
    }

    .hero-title {
        font-size: 32px;
    }

    .hero-divider {
        margin: 0 8px;
    }

    .hero-subtitle {
        font-size: 16px;
    }

    .hero-tagline {
        font-size: 12px;
    }

    .hero-locations {
        gap: 8px;
    }

    .hero-locations span {
        font-size: 10px;
        padding: 3px 8px;
    }

    .hero-link {
        font-size: 12px;
        padding: 6px 12px;
    }

    .hero-meta {
        flex-direction: row;
        gap: 20px;
        align-items: flex-start;
    }

    .hero-meta-item {
        align-items: flex-start;
    }

    /* Container */
    .container {
        padding: 16px;
    }

    /* Stats Bar - Compact 2 column grid on mobile */
    .stats-bar {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px 12px;
        padding: 16px;
    }

    .stat-item {
        border-right: none;
        padding-right: 0;
        border-bottom: 1px solid #2d3748;
        padding-bottom: 12px;
    }

    .stat-item:nth-last-child(-n+2) {
        border-bottom: none;
        padding-bottom: 0;
    }

    .stat-label {
        font-size: 9px;
    }

    .stat-value {
        font-size: 22px;
    }

    .stat-meta {
        font-size: 9px;
    }

    .stat-item {
        border-right: none;
        padding-right: 0;
        border-bottom: 1px solid #2d3748;
        padding-bottom: 12px;
    }

    .stat-item:nth-last-child(-n+2) {
        border-bottom: none;
        padding-bottom: 0;
    }

    .stat-value {
        font-size: 24px;
    }

    /* Filter Bar - Collapsible */
    .filter-toggle {
        display: block;
    }

    .filter-bar {
        padding: 12px;
    }

    .filter-content {
        display: none;
        margin-top: 8px;
    }

    .filter-content.active {
        display: flex;
    }

    .filter-btn {
        flex: 1;
        min-width: 120px;
        padding: 10px 12px;
        font-size: 12px;
        text-align: center;
    }

    .filter-divider {
        display: none;
    }

    /* Cards */
    .card {
        padding: 12px;
    }

    .card h2, .card h3 {
        font-size: 12px;
    }

    /* Map */
    #map {
        height: 400px;
    }

    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .map-controls {
        flex-wrap: wrap;
        width: 100%;
    }

    .map-btn {
        flex: 1;
        min-width: 70px;
        padding: 8px 10px;
        font-size: 11px;
        text-align: center;
    }

    .map-legend {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Analytics Grid */
    .analytics-grid {
        gap: 16px;
    }

    /* Charts */
    .chart-container {
        height: 180px;
    }

    /* Direction Chart - make responsive */
    #directionChart {
        width: 200px !important;
        height: 200px !important;
    }

    /* Top Rides */
    .top-ride {
        padding: 10px;
        font-size: 12px;
    }

    /* Table */
    .all-rides-list {
        max-height: 400px;
    }

    .ride-card {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        padding: 12px;
    }

    .ride-card-meta {
        gap: 8px;
    }

    .ride-card-source-btn {
        margin-left: 0;
        align-self: flex-start;
    }

    /* Modal */
    .modal-content {
        width: 95%;
        margin: 5% auto;
    }

    .modal-map {
        height: 500px;
    }

    /* Modal with details - mobile layout */
    .modal-with-details {
        max-height: 90vh;
    }

    .modal-with-details .modal-map {
        height: 300px;
    }

    .modal-details {
        padding: 16px;
        max-height: 50vh;
    }

    .modal-details-header h3 {
        font-size: 16px;
    }

    .modal-details-info {
        font-size: 11px;
        gap: 12px;
    }

    .modal-waypoints-list {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }

    /* Modal with sidebar - stack vertically on mobile */
    .modal-layout {
        flex-direction: column;
    }

    .modal-sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid #2d3748;
        max-height: 200px;
    }

    .modal-main .modal-map {
        border-radius: 0;
        height: 300px;
    }

    .modal-details-actions {
        flex-direction: column;
    }

    .modal-details-actions .nav-btn,
    .modal-details-actions .source-link {
        width: 100%;
        text-align: center;
    }

    /* Map overlay controls positioned at top-center */
    .map-overlay-controls {
        top: 10px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
    }

    /* Composite map modal overlay override for mobile */
    .composite-overlay {
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        max-width: unset !important;
        width: 100% !important;
    }

    .composite-controls {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .composite-controls .map-btn {
        flex: 1;
        min-width: 100px;
    }

    .modal-close {
        font-size: 24px;
        padding: 6px 12px;
    }

    /* Footer */
    .footer-content {
        flex-direction: column;
        gap: 8px;
        text-align: center;
        font-size: 10px;
    }

    /* Hide watermark on mobile for better performance */
    body::before {
        display: none;
    }
}

@media (max-width: 640px) {
    /* Keep 2 column grid - more space efficient */
    .stats-bar {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px 8px;
        padding: 12px;
    }

    .stat-label {
        font-size: 8px;
    }

    .stat-value {
        font-size: 18px;
    }

    .stat-meta {
        font-size: 8px;
    }

    /* Hero more compact */
    .hero-content {
        padding: 20px 16px;
    }

    .hero-title {
        font-size: 28px;
    }

    .hero-subtitle {
        font-size: 14px;
    }

    .hero-tagline {
        font-size: 11px;
    }

    /* Map */
    #map {
        height: 350px;
    }

    /* Map controls stacked */
    .map-controls {
        flex-direction: column;
    }

    .map-btn {
        width: 100%;
        min-width: unset;
    }

    .map-legend {
        grid-template-columns: 1fr;
    }

    /* Filter buttons full width */
    .filter-btn {
        min-width: unset;
        width: 100%;
    }

    /* Modal map smaller */
    .modal-map {
        height: 400px;
    }

    /* Mobile overlay adjustments for small screens */
    .map-overlay {
        font-size: 11px;
        padding: 12px;
        max-height: 60%;
    }

    .map-overlay.collapsed {
        max-height: 120px;
    }

    .overlay-header h3 {
        font-size: 14px;
    }

    .overlay-actions {
        flex-direction: column;
        width: 100%;
    }

    .nav-btn, .source-link {
        width: 100%;
        text-align: center;
    }

    /* Smaller composite controls on small mobile */
    .composite-controls .map-btn {
        font-size: 10px;
        padding: 8px 8px;
    }

    /* Ride cards more compact */
    .ride-card {
        padding: 8px;
    }

    .ride-card-name {
        font-size: 10px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 100%;
    }

    .ride-card-meta {
        font-size: 8px;
    }

    /* Hide verbose metadata on Mobile S */
    .ride-card-meta span:nth-child(5), /* Hide separator before waypoints */
    .ride-card-meta span:nth-child(6), /* Hide waypoint count */
    .ride-card-meta span:nth-child(3), /* Hide separator before category */
    .ride-card-meta span:nth-child(4) { /* Hide category */
        display: none !important;
    }

    .ride-card-distance {
        font-size: 10px;
        min-width: 45px;
    }

    /* Hide source button on Mobile S - too much clutter */
    .ride-card-source-btn {
        display: none;
    }

    /* Ride card index smaller */
    .ride-card > span:first-child {
        font-size: 9px !important;
        margin-right: 6px !important;
        min-width: 18px !important;
    }
}

/* Mobile S - Extra small screens (320px-375px) */
@media (max-width: 375px) {
    /* Force everything to fit */
    * {
        max-width: 100%;
    }

    /* Container tighter padding */
    .container {
        padding: 12px;
    }

    /* Hero ultra compact */
    .hero-content {
        padding: 16px 12px;
    }

    .hero-badge {
        font-size: 8px;
        padding: 4px 10px;
    }

    .hero-title {
        font-size: 24px;
    }

    .hero-divider {
        margin: 0 6px;
    }

    .hero-subtitle {
        font-size: 12px;
    }

    .hero-tagline {
        font-size: 10px;
    }

    .hero-locations span {
        font-size: 9px;
        padding: 2px 6px;
    }

    .hero-link {
        font-size: 11px;
        padding: 5px 10px;
    }

    /* Cards tighter */
    .card {
        padding: 10px;
        margin-bottom: 12px;
    }

    .card h2, .card h3 {
        font-size: 11px;
        word-wrap: break-word;
    }

    /* Stats bar even more compact - 2 columns */
    .stats-bar {
        padding: 10px;
        gap: 10px 6px;
        grid-template-columns: repeat(2, 1fr);
    }

    .stat-label {
        font-size: 7px;
    }

    .stat-value {
        font-size: 16px;
    }

    .stat-meta {
        font-size: 7px;
    }

    .stat-item {
        padding: 10px 0;
    }

    .stat-label {
        font-size: 9px;
    }

    .stat-value {
        font-size: 20px;
    }

    .stat-meta {
        font-size: 9px;
    }

    /* Filter bar */
    .filter-bar {
        padding: 10px;
    }

    .filter-btn {
        font-size: 10px;
        padding: 8px 10px;
    }

    /* Map */
    #map {
        height: 300px;
    }

    /* Map controls smaller */
    .map-btn {
        font-size: 10px;
        padding: 6px 8px;
    }

    .map-controls {
        gap: 6px;
    }

    /* Chart containers */
    .chart-container {
        height: 150px;
    }

    /* Top rides */
    .top-ride {
        padding: 8px;
        font-size: 11px;
    }

    /* Ride cards */
    .ride-card {
        padding: 10px;
    }

    .ride-card-name {
        font-size: 10px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .ride-card-meta {
        font-size: 8px;
    }

    .ride-card-distance {
        font-size: 11px;
    }

    .ride-card-source-btn {
        font-size: 9px;
        padding: 4px 10px;
    }

    /* All rides card title */
    #ridesTable ~ h2 {
        font-size: 11px;
    }

    /* Modal */
    .modal-content {
        width: 98%;
        margin: 3% auto;
    }

    .modal-with-details .modal-map {
        height: 250px;
    }

    .modal-details {
        padding: 12px;
        font-size: 10px;
    }

    .modal-details-header h3 {
        font-size: 14px;
    }

    .modal-details-info {
        font-size: 10px;
        gap: 8px;
    }

    .modal-waypoints-list {
        grid-template-columns: 1fr;
    }

    .modal-waypoints-list .waypoint-item {
        font-size: 10px;
        padding: 6px 10px;
    }

    .modal-details-actions .nav-btn,
    .modal-details-actions .source-link {
        font-size: 10px;
        padding: 8px 10px;
    }

    /* Footer */
    .footer-content {
        font-size: 9px;
        padding: 12px 16px;
    }

    /* Analytics grid - ensure no overflow */
    .analytics-grid {
        gap: 12px;
    }

    /* Ensure text wraps */
    .overlay-header h3,
    .card h2,
    .card h3,
    .ride-card-name,
    .top-ride {
        word-wrap: break-word;
        overflow-wrap: break-word;
        hyphens: auto;
    }

    /* Map overlay controls smaller */
    .map-overlay-controls {
        padding: 6px 10px;
        gap: 6px;
    }

    .map-overlay-controls .map-btn {
        font-size: 9px;
        padding: 5px 8px;
    }

    /* Geographic distribution cards */
    .analytics-grid > .card > div > div {
        font-size: 10px;
        padding: 6px;
    }

    .analytics-grid > .card > div > div > div:first-child {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }

    /* Ensure no element causes overflow */
    .card > * {
        max-width: 100%;
        box-sizing: border-box;
    }

    /* Fix any long text */
    p, span, div {
        word-wrap: break-word;
        overflow-wrap: anywhere;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    /* Increase tap target sizes for touch devices */
    .filter-btn,
    .map-btn,
    .nav-btn,
    .view-btn,
    .top-ride.clickable,
    .ride-card {
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Better touch feedback */
    .filter-btn:active,
    .map-btn:active {
        transform: scale(0.95);
    }

    .ride-card:active,
    .top-ride.clickable:active {
        transform: scale(0.98);
    }
}

/* Landscape mobile specific */
@media (max-width: 900px) and (orientation: landscape) {
    #map {
        height: 300px;
    }

    .modal-map {
        height: calc(100vh - 60px);
    }

    .stats-bar {
        grid-template-columns: repeat(4, 1fr);
    }
}
