:root {
    --primary: #FF6B35;
    --primary-dark: #E55A2B;
    --primary-gradient: linear-gradient(135deg, #FF6B35, #F7931E);
    --accent: #2D3047;
    --text-dark: #333;
    --text-muted: #666;
    --climb-green: #4CAF50;
    --bg-light: #f5f5f7;
}
* { box-sizing: border-box; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    max-width: 1100px;
    margin: 0 auto;
    padding: 10px;
    background: #f5f5f7;
    overflow-x: hidden;
}
body.collection-mode {
    padding: 6px;
}
@media (min-width: 1200px) {
    body { max-width: 1300px; }
    body.collection-mode { max-width: 98%; padding: 6px; }
}
@media (max-width: 480px) {
    body { padding: 6px; }
    body.collection-mode { padding: 4px; }
}
h1 { color: var(--accent); font-size: 1.5em; }
form {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
label:not(.toggle-label) {
    display: block;
    margin-top: 15px;
    font-weight: 600;
    color: #555;
}
label:not(.toggle-label):first-child { margin-top: 0; }
input[type="text"], input[type="number"], select {
    width: 100%;
    padding: 12px;
    margin-top: 5px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 16px;
}
input[type="text"]:focus, input[type="number"]:focus, select:focus {
    outline: none;
    border-color: var(--primary);
}
.param-row {
    display: flex;
    gap: 15px;
}
form > .param-row { margin-top: 8px; }
.param-row > div { flex: 1; }
.param-row-main { position: relative; padding-right: 128px; }
.compass-rose {
    position: absolute;
    right: 0;
    top: -4px;
    width: 120px;
    height: 120px;
    cursor: pointer;
    z-index: 1;
}
.compass-wedge {
    fill: #eee;
    stroke: #bbb;
    stroke-width: 0.6;
    transition: fill 0.15s;
}
.compass-wedge:hover {
    fill: #d8d8d8;
}
.compass-wedge.active {
    fill: var(--primary);
    stroke: var(--primary);
}
.compass-label {
    font-size: 9px;
    fill: #888;
    text-anchor: middle;
    dominant-baseline: central;
    pointer-events: none;
    font-family: system-ui, sans-serif;
}
.compass-label.cardinal {
    font-size: 11px;
    font-weight: 600;
    fill: #555;
}
form > button[type="submit"],
.analyze-btn {
    width: 100%;
    padding: 14px;
    margin-top: 20px;
    background: var(--primary-gradient);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}
form > button[type="submit"]:hover,
.analyze-btn:hover { background: #0056b3; }
form > button[type="submit"]:disabled,
.analyze-btn:disabled { background: #999; cursor: not-allowed; }
.results {
    background: white;
    padding: 20px;
    border-radius: 8px;
    margin-top: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    overflow-x: auto;  /* Allow horizontal scroll for wide tables */
}
.results.route-results {
    border-left: 4px solid #4CAF50;
}
.results.trip-results {
    border-left: 4px solid #2196F3;
}
.result-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    height: 28px;
    box-sizing: border-box;
}
.route-badge {
    background: #E8F5E9;
    color: #2E7D32;
}
.trip-badge {
    background: #E3F2FD;
    color: #1565C0;
}
.offline-badge {
    background: #FFF3E0;
    color: #E65100;
}
.results h2 { margin-top: 0; font-size: 1.2em; color: #333; }
.results h2 a { color: inherit; text-decoration: none; }
.results h2 a:hover { color: var(--primary); }
.results-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}
#chartToggleContainer {
    margin-left: auto;
}
.results-header h2 {
    margin: 0;
}
.share-btn {
    padding: 4px 10px;
    background: white;
    border: 1.5px solid var(--primary);
    color: var(--primary);
    border-radius: 4px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 500;
    flex-shrink: 0;
    width: auto;
    height: 28px;
    box-sizing: border-box;
    margin: 0;
}
.share-btn svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
}
.share-btn:hover {
    background: var(--primary);
    color: white;
}
.share-btn.copied {
    background: #28a745;
    border-color: #28a745;
    color: white;
}
.result-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #eee;
}
.result-row:last-child { border-bottom: none; }
#collectionResults .result-row {
    max-width: 350px;
}
.result-label { color: #666; }
.result-value { font-weight: 600; color: #333; }
.result-row.primary {
    background: #f0f7ff;
}
.result-row.primary .result-value {
    font-weight: 700;
}
.unit-select {
    padding: 1px 2px;
    font-size: 0.75em;
    border: 1px solid #ccc;
    border-radius: 3px;
    background: #fff;
    cursor: pointer;
    max-width: 70px;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 2px center;
    background-size: 12px;
    padding-right: 16px;
}
.unit-select:hover {
    border-color: #4CAF50;
}
.result-row .unit-select {
    margin-left: 4px;
}
.result-row .result-label {
    flex-shrink: 0;
}
.result-row .result-value {
    text-align: right;
    margin-left: auto;
}
.climate-waypoints .result-value {
    display: flex;
    flex-wrap: wrap;
    gap: 2px 4px;
    align-items: baseline;
}
.climate-waypoint-link {
    color: #f59e0b;
    text-decoration: none;
    font-size: 0.9em;
}
.climate-waypoint-link:hover {
    text-decoration: underline;
}
.climate-elev {
    font-size: 0.85em;
    color: #999;
}
.primary-results {
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid #ccc;
}
.steepness-results {
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid #ccc;
}
.steepness-results .result-row {
    background: #fff8f0;
}
.steepness-results .result-row .result-value {
    font-weight: 600;
}
.results-stats {
    max-width: 350px;
}
@media (min-width: 900px) {
    .results-body {
        display: grid;
        grid-template-columns: 350px 1fr;
        gap: 24px;
        align-items: start;
    }
    .results-body .result-row,
    .results-body .primary-results {
        max-width: none;
    }
    .results-visuals .histogram-bar .bar-container {
        height: 120px;
    }
}
.error {
    background: #fee;
    color: #c00;
    padding: 15px;
    border-radius: 6px;
    margin-top: 20px;
}
.note {
    font-size: 0.85em;
    color: #888;
    margin-top: 10px;
    padding: 10px;
    background: #f9f9f9;
    border-radius: 4px;
}
.anomaly-note {
    background: #FFF3E0;
    border-left: 3px solid #FF9800;
    color: #5D4037;
}
.anomaly-note strong {
    color: #E65100;
}
.anomaly-item {
    display: inline-block;
    background: #FFE0B2;
    padding: 2px 6px;
    border-radius: 3px;
    margin: 2px 0;
}
.noise-note {
    background: #E3F2FD;
    border-left: 3px solid #2196F3;
    color: #1565C0;
    white-space: nowrap;
    padding: 4px 8px;
}
.noise-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-weight: 500;
    line-height: 1;
}
.noise-badge .info-btn {
    vertical-align: middle;
}
.histograms-container {
    display: flex;
    gap: 8px;
    margin-top: 6px;
}
@media (max-width: 600px) {
    .histograms-container {
        flex-direction: column;
    }
}
.grade-histogram {
    flex: 1;
    padding: 15px;
    background: #f9f9f9;
    border-radius: 6px;
}
.grade-histogram h4 {
    margin: 0 0 10px 0;
    font-size: 0.9em;
    color: #555;
}
.steep-section {
    margin-top: 20px;
    padding: 15px;
    background: #fff5f0;
    border-radius: 6px;
    border-left: 3px solid #ff6600;
}
.steep-section > h4 {
    margin: 0 0 12px 0;
    font-size: 1em;
    color: #e55a00;
}
.steep-chart-link {
    font-size: 0.85em;
    font-weight: 400;
    color: #e55a00;
    text-decoration: underline;
    margin-left: 6px;
}
.steep-stats {
    display: flex;
    gap: 15px 25px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}
.steep-stat {
    display: flex;
    align-items: baseline;
    gap: 6px;
}
.steep-label {
    font-size: 0.85em;
    color: #666;
    white-space: nowrap;
}
.steep-value {
    font-weight: 600;
    color: #e55a00;
}
.steep-section .histograms-container {
    margin-top: 10px;
}
.steep-section .grade-histogram {
    background: white;
}
.histogram-bars {
    display: flex;
    align-items: flex-end;
    gap: 2px;
}
.histogram-bar {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    min-width: 0;
    min-height: 80px;
}
.histogram-bar .bar-container {
    width: 100%;
    height: 60px;
    display: flex;
    align-items: flex-end;
    cursor: pointer;
    /* Extend touch target area */
    padding: 10px 2px 0 2px;
    margin: -10px -2px 0 -2px;
}
.histogram-bar .bar {
    width: 100%;
    border-radius: 2px 2px 0 0;
    min-height: 4px;  /* Larger minimum for touch */
}
/* Make entire histogram-bar touchable on mobile */
@media (pointer: coarse) {
    .histogram-bar {
        cursor: pointer;
    }
    .histogram-bar .bar {
        min-height: 8px;  /* Even larger on touch devices */
    }
}
.histogram-bar .label {
    font-size: 0.6em;
    color: #888;
    margin-top: 4px;
    white-space: nowrap;
}
.histogram-bar .pct {
    font-size: 0.6em;
    color: #666;
}
.elevation-profile {
    margin-top: 20px;
    background: white;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
@media (max-width: 600px) {
    .elevation-profile { padding: 5px; }
}
.elevation-profile h4 {
    margin: 0 0 10px 0;
    font-size: 0.95em;
    color: #333;
}
.elevation-profile-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.elevation-profile-header h4 {
    margin: 0;
}
.elevation-profile-header h4 a {
    color: #333;
    text-decoration: none;
}
.elevation-profile-header h4 a:hover {
    color: #1a73e8;
    text-decoration: underline;
}
.ride-link {
    white-space: nowrap;
}
@media (max-width: 600px) {
    .elevation-profile-header {
        flex-wrap: wrap;
        gap: 8px;
    }
    .elevation-profile-header h4 {
        width: 100%;
    }
    .ride-link {
        order: 3;
        margin-left: auto;
    }
}
.elevation-profile-toggles {
    display: flex;
    gap: 12px;
    align-items: center;
    font-size: 0.85em;
}
.collapse-stops-toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    vertical-align: middle;
}
.collapse-stops-toggle input {
    margin: 0;
    cursor: pointer;
    vertical-align: middle;
}
.collapse-stops-toggle label {
    cursor: pointer;
    color: #666;
    font-weight: normal;
    line-height: 1;
    vertical-align: middle;
    margin-top: 0;
}
.elevation-profile-container {
    position: relative;
    width: 100%;
}
.elevation-profile img {
    width: 100%;
    height: auto;
    display: block;
    /* Prevent Safari long-press context menu */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}
.elevation-canvas {
    width: 100%;
    height: 250px !important;
    aspect-ratio: auto;
    display: block;
    /* Prevent Safari long-press context menu */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}
.elevation-tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    white-space: nowrap;
    z-index: 100;
    transform: translateX(-50%);
}
.elevation-tooltip.visible {
    opacity: 1;
}
.elevation-tooltip .grade {
    font-weight: bold;
    font-size: 14px;
}
.elevation-tooltip .elev {
    color: #ccc;
    margin-top: 2px;
}
.elevation-tooltip .poi-name {
    font-weight: bold;
    font-size: 11px;
    color: #8bc34a;
    margin-bottom: 2px;
}
.elevation-cursor {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1px;
    background: rgba(0, 0, 0, 0.5);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
}
.elevation-cursor.visible {
    opacity: 1;
}
.elevation-selection {
    position: absolute;
    top: 0;
    bottom: 0;
    background: rgba(59, 130, 246, 0.2);
    border-left: 2px solid rgba(59, 130, 246, 0.6);
    border-right: 2px solid rgba(59, 130, 246, 0.6);
    pointer-events: none;
    opacity: 0;
    z-index: 50;
}
.elevation-selection.visible {
    opacity: 1;
}
.elevation-selection-popup {
    position: absolute;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 12px;
    z-index: 200;
    white-space: nowrap;
    transform: translateX(-50%);
    pointer-events: auto;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.elevation-selection-popup .selection-close {
    position: absolute;
    top: 2px;
    right: 6px;
    cursor: pointer;
    color: #888;
    font-size: 14px;
    line-height: 1;
}
.elevation-selection-popup .selection-close:hover {
    color: white;
}
.elevation-selection-popup .selection-stat {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}
.elevation-selection-popup .stat-label {
    color: #aaa;
}
.elevation-selection-popup .stat-value {
    font-weight: bold;
}
.selection-zoom-btn {
    margin-top: 8px;
    padding: 6px 12px;
    background: #3b82f6;
    color: white;
    border-radius: 4px;
    text-align: center;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
}
.selection-zoom-btn:hover {
    background: #2563eb;
}
.selection-climate-btn {
    margin-top: 4px;
    padding: 6px 12px;
    background: #f59e0b;
    color: white;
    border-radius: 4px;
    text-align: center;
    cursor: pointer;
    font-size: 12px;
}
.selection-climate-btn:hover {
    background: #d97706;
}
.zoom-out-link {
    position: absolute;
    bottom: 2px;
    right: 10%;
    z-index: 100;
}
.zoom-out-link a {
    color: #3b82f6;
    font-size: 12px;
    text-decoration: none;
}
.zoom-out-link a:hover {
    text-decoration: underline;
}
.profile-climate-link {
    position: absolute;
    bottom: 2px;
    left: 10%;
    z-index: 100;
}
.profile-climate-link a {
    color: #f59e0b;
    font-size: 12px;
    text-decoration: none;
}
.profile-climate-link a:hover {
    text-decoration: underline;
}

/* Long-press indicator for touch selection */
.long-press-indicator {
    position: absolute;
    width: 60px;
    height: 60px;
    margin-left: -30px;
    margin-top: -30px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease-out;
    z-index: 100;
}
.long-press-indicator.active {
    opacity: 1;
}
.long-press-ring {
    width: 100%;
    height: 100%;
    border: 3px solid #2196F3;
    border-radius: 50%;
    animation: long-press-pulse 0.4s ease-out forwards;
    box-sizing: border-box;
}
@keyframes long-press-pulse {
    0% {
        transform: scale(0.3);
        opacity: 0.8;
    }
    100% {
        transform: scale(1);
        opacity: 0;
        border-width: 2px;
    }
}

.elevation-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 120px;
    background: #f8f8f8;
    border-radius: 4px;
}
.elevation-loading.hidden {
    display: none;
}
.elevation-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #e0e0e0;
    border-top-color: #666;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
.elevation-profile img.loading {
    display: none;
}
.route-map {
    margin-top: 20px;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: relative;
    width: 100%;
    /* Tall ratio on mobile to show both map and elevation */
    padding-bottom: 120%;
}
.route-map iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
}
@media (min-width: 500px) {
    .route-map {
        /* Square-ish on medium screens */
        padding-bottom: 90%;
    }
}
@media (min-width: 768px) {
    .route-map {
        /* 16:10 aspect ratio on larger screens */
        padding-bottom: 62.5%;
    }
}
/* Progress bar styles */
.progress-container {
    background: white;
    padding: 20px;
    border-radius: 8px;
    margin-top: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.progress-bar {
    width: 100%;
    height: 24px;
    background: #e0e0e0;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 10px;
}
.progress-fill {
    height: 100%;
    background: var(--primary-gradient);
    border-radius: 12px;
    transition: width 0.3s ease;
    width: 0%;
}
.progress-text {
    font-size: 0.9em;
    color: #666;
}
.progress-route {
    font-size: 0.85em;
    color: #888;
    margin-top: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* Collection table styles */
.collection-rwgps-link {
    margin-top: 10px;
    font-size: 0.85em;
}
.collection-rwgps-link a {
    color: var(--primary);
    text-decoration: none;
}
.collection-rwgps-link a:hover {
    text-decoration: underline;
}
.collection-table {
    width: 100%;
    min-width: 600px;  /* Prevent excessive squishing on mobile */
    border-collapse: collapse;
    margin-top: 8px;
    font-size: 0.85em;
}
.collection-table th {
    background: #f5f5f5;
    padding: 6px 3px;
    text-align: left;
    font-weight: 600;
    color: #555;
    border-bottom: 2px solid #ddd;
    white-space: nowrap;
}
.collection-table td {
    padding: 5px 3px;
    border-bottom: 1px solid #eee;
}
.collection-table tr:last-child td {
    border-bottom: none;
}
.collection-table .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.collection-table .u {
    font-size: 0.8em;
    color: #888;
}
.totals-row {
    font-weight: 600;
    background: #f9f9f9;
}
.totals-row td {
    border-top: 2px solid #ddd;
}
.collection-table .primary {
    background: #f0f7ff;
    font-weight: 600;
}
.collection-table th.primary {
    background: #e3effa;
}
.collection-table .separator {
    border-right: 2px solid #ccc;
}
/* Steepness columns: tan treatment matching analysis summary */
.collection-table .steepness {
    background: #fff8f0;
}
.collection-table th.steepness {
    background: #fff0e0;
}
.collection-table th.steepness.sortable:hover {
    background: #f5e6d0;
}
.totals-row .steepness {
    background: #fff3e6;
}
/* Route selection in collections table */
.route-select-checkbox {
    width: 14px;
    height: 14px;
    cursor: pointer;
    accent-color: #3b82f6;
    margin: 0;
}
.collection-table .cmp-col {
    padding: 2px 2px 2px 4px;
    text-align: center;
    width: 1%;
    white-space: nowrap;
}
.collection-table .cmp-col input[type="checkbox"] {
    margin: 0;
    vertical-align: middle;
}
.collection-table .type-col {
    padding: 2px 2px;
    text-align: center;
    width: 1%;
    white-space: nowrap;
}
.type-badge {
    display: inline-block;
    width: 15px;
    height: 15px;
    line-height: 15px;
    border-radius: 3px;
    font-size: 9px;
    font-weight: 700;
    text-align: center;
    color: white;
    vertical-align: middle;
    position: relative;
    cursor: default;
}
.type-badge:hover::after {
    content: attr(data-tip);
    position: absolute;
    left: 0;
    top: 100%;
    margin-top: 4px;
    background: rgba(45,48,71,0.92);
    color: white;
    font-size: 11px;
    font-weight: 400;
    padding: 4px 8px;
    border-radius: 4px;
    white-space: nowrap;
    z-index: 200;
    pointer-events: none;
}
.type-trip { background: #3b82f6; }
.type-route { background: #f59e0b; }
.collection-table .date-col {
    white-space: nowrap;
}
.collection-table tr.selected-route {
    background-color: #dbeafe !important;
}
.collection-table tr.selected-route:hover {
    background-color: #bfdbfe !important;
}
.collection-table tr.route-saved {
    border-left: 3px solid #2e7d32;
}
.saved-badge {
    color: #2e7d32;
    font-weight: bold;
    flex-shrink: 0;
    cursor: default;
    position: relative;
}
.saved-badge:hover::after {
    content: attr(data-tip);
    position: absolute;
    left: 50%;
    top: 100%;
    transform: translateX(-50%);
    margin-top: 4px;
    background: rgba(45,48,71,0.92);
    color: white;
    font-size: 11px;
    font-weight: 400;
    padding: 4px 8px;
    border-radius: 4px;
    white-space: nowrap;
    z-index: 200;
    pointer-events: none;
}
.collection-action-bar {
    display: none;
    padding: 8px 12px;
    background: #f0f9ff;
    border: 1px solid #3b82f6;
    border-radius: 8px;
    margin-bottom: 12px;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
}
.collection-action-bar.visible {
    display: flex;
}
.action-btn {
    padding: 4px 10px;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    font-size: 13px;
    text-decoration: none;
    display: inline-block;
}
.compare-btn {
    background: #3b82f6;
}
.compare-btn:hover {
    background: #2563eb;
}
.save-btn {
    background: #0d9488;
}
.save-btn:hover {
    background: #0f766e;
}
.save-btn:disabled {
    background: #99d5cf;
    cursor: not-allowed;
}
.delete-action-btn { background: #dc2626; }
.delete-action-btn:hover { background: #b91c1c; }
.action-selection-info {
    color: #1e40af;
    font-size: 13px;
    white-space: nowrap;
}
.save-progress {
    color: #0d9488;
    font-size: 13px;
    white-space: nowrap;
}
.route-name {
    max-width: 280px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.route-name a:first-of-type {
    color: var(--primary);
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}
.route-name a:first-of-type:hover {
    text-decoration: underline;
}
.route-name .rwgps-link {
    flex-shrink: 0;
    display: inline-block;
    background: #FA6400;
    color: white;
    padding: 1px 4px;
    font-size: 0.65em;
    font-weight: 600;
    text-decoration: none;
    border-radius: 3px;
}
.route-name .rwgps-link:hover {
    background: #e55a00;
}
.route-name .climate-link {
    flex-shrink: 0;
    display: inline-block;
    background: #f59e0b;
    color: white;
    padding: 1px 4px;
    font-size: 0.65em;
    font-weight: 600;
    text-decoration: none;
    border-radius: 3px;
    margin-left: 2px;
    vertical-align: middle;
    position: relative;
}
.route-name .climate-link:hover {
    background: #d97706;
}
.route-name .climate-link:hover::after {
    content: attr(data-tip);
    position: absolute;
    left: 50%;
    top: 100%;
    transform: translateX(-50%);
    margin-top: 4px;
    background: rgba(45,48,71,0.92);
    color: white;
    font-size: 11px;
    font-weight: 400;
    padding: 4px 8px;
    border-radius: 4px;
    white-space: nowrap;
    z-index: 200;
    pointer-events: none;
}
/* Sortable table headers */
.collection-table th.sortable {
    cursor: pointer;
    user-select: none;
}
.collection-table th.sortable:hover {
    background: rgba(0,0,0,0.05);
}
.collection-table th .sort-indicator {
    font-size: 0.7em;
    margin-left: 2px;
    opacity: 0.4;
}
.collection-table th.sorted .sort-indicator {
    opacity: 1;
}
@media (min-width: 1200px) {
    .route-name { max-width: 400px; }
    .collection-table { font-size: 0.9em; }
}
@media (max-width: 768px) {
    .route-name { max-width: 200px; }
}
@media (max-width: 600px) {
    .collection-table { font-size: 0.75em; }
    .collection-table th, .collection-table td { padding: 4px 2px; }
    .collection-table .cmp-col { padding: 1px 1px 1px 2px; }
    .collection-table .type-col { padding: 1px 1px; }
    .route-name { max-width: 140px; }
    /* Compact mobile form layout */
    form { padding: 12px; }
    .param-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
    .param-row > div {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 6px;
    }
    .param-row .label-row {
        flex-shrink: 0;
        min-width: 0;
    }
    .param-row .label-row label {
        font-size: 0.75em;
        margin-top: 0;
        white-space: nowrap;
    }
    .param-row .label-row .info-btn {
        display: none;
    }
    .label-row .wind-history-link {
        display: none !important;
    }
    .param-row input[type="number"] {
        width: 70px;
        min-width: 60px;
        padding: 6px 4px;
        font-size: 14px;
        margin-top: 0;
        flex-shrink: 0;
    }
    /* Shorter labels on mobile */
    .param-row label[for="climbing_power"] { font-size: 0; }
    .param-row label[for="climbing_power"]::before { content: "Climb (W)"; font-size: 11px; }
    .param-row label[for="flat_power"] { font-size: 0; }
    .param-row label[for="flat_power"]::before { content: "Flat (W)"; font-size: 11px; }
    /* mass + wind_speed labels are updated by JS on imperial toggle.
       Read the short-form text from a data attribute so we don't need
       two separate shortenings (css) and the JS updates stay effective. */
    .param-row label[for="mass"] { font-size: 0; }
    .param-row label[for="mass"]::before {
        content: attr(data-short-label); font-size: 11px;
    }
    .param-row label[for="wind_speed"] { font-size: 0; }
    .param-row label[for="wind_speed"]::before {
        content: attr(data-short-label); font-size: 11px;
    }
    .param-row-main { padding-right: 108px; }
    .compass-rose { width: 100px; height: 100px; }
    /* Reduce button margin */
    form > button[type="submit"],
    .analyze-btn { margin-top: 12px; padding: 10px; }
    /* Compact results */
    .results { padding: 12px; margin-top: 12px; }
    /* Compact URL input */
    input[type="text"] { padding: 10px; font-size: 14px; }
    /* Compact file upload */
    .file-drop-zone { padding: 16px; }
    .mode-tab { padding: 5px 12px; font-size: 0.85em; }
    /* Compact compare and advanced rows */
    .compare-toggle { margin-top: 6px; margin-bottom: 4px; }
    .advanced-row { margin-top: 8px; }
    .advanced-toggle { font-size: 0.85em; }
    /* Compact labels */
    label:not(.toggle-label) { margin-top: 8px; font-size: 0.85em; }
    .label-row label { font-size: 0.85em; }
    /* Compact units row */
    .units-row { margin-top: 6px; }
    .units-row span { font-size: 0.85em; }
    /* Compact advanced options */
    .advanced-options { padding: 10px; margin-top: 8px; }
    .advanced-options .param-row label[for="descending_power"] { font-size: 0; }
    .advanced-options .param-row label[for="descending_power"]::before { content: "Desc (W)"; font-size: 11px; }
    .advanced-options .param-row label[for="descent_braking_factor"] { font-size: 0; }
    .advanced-options .param-row label[for="descent_braking_factor"]::before { content: "Braking"; font-size: 11px; }
    .advanced-options .param-row label[for="gravel_grade"] { font-size: 0; }
    .advanced-options .param-row label[for="gravel_grade"]::before { content: "Gravel"; font-size: 11px; }
    .advanced-options .param-row label[for="smoothing"] { font-size: 0; }
    .advanced-options .param-row label[for="smoothing"]::before { content: "Smooth (m)"; font-size: 11px; }
}
.hidden { display: none; }
.back-link {
    display: inline-block;
    margin-bottom: 12px;
    color: var(--primary);
    text-decoration: none;
    font-size: 14px;
}
.back-link:hover { text-decoration: underline; }
/* Dev banner — shown on non-main branches */
.dev-banner {
    background: #e65100;
    color: #fff;
    text-align: center;
    padding: 4px 0;
    font-size: 0.85em;
    font-weight: 600;
    letter-spacing: 0.5px;
}
/* Header styles */
.header-section {
    margin-bottom: 20px;
    text-align: center;
}
.logo-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 8px;
}
.logo-link {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: inherit;
}
.logo {
    width: 48px;
    height: 48px;
}
.header-section h1 {
    margin: 0;
    font-size: 1.4em;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
@media (max-width: 480px) {
    .logo { width: 36px; height: 36px; }
    .header-section { margin-bottom: 10px; }
    .header-section h1 { font-size: 1.1em; }
    .logo-container { margin-bottom: 4px; }
    .logo-link { gap: 8px; }
    .tagline { font-size: 0.75em; }
    .how-link { margin-top: 4px; font-size: 0.8em; }
}
.tagline {
    color: var(--text-muted);
    font-size: 0.9em;
    margin: 0;
    line-height: 1.4;
    text-align: center;
}
.how-link {
    display: inline-block;
    color: var(--primary);
    font-size: 0.85em;
    text-decoration: none;
}
.how-link:hover {
    text-decoration: underline;
}
/* Info button styles */
.label-row {
    display: flex;
    align-items: center;
    gap: 6px;
}
.info-btn {
    width: 16px;
    height: 16px;
    min-width: 16px;
    min-height: 16px;
    border-radius: 50%;
    border: 1.5px solid var(--primary);
    background: white;
    color: var(--primary);
    font-size: 10px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
    vertical-align: middle;
}
.info-btn:hover {
    background: var(--primary);
    color: white;
}
.th-with-info, .label-with-info {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    vertical-align: middle;
}
.th-with-info .info-btn, .label-with-info .info-btn {
    margin: 0;
    top: 0;
}
@media (max-width: 600px) {
    .info-btn {
        width: 18px;
        height: 18px;
        min-width: 18px;
        min-height: 18px;
        font-size: 11px;
    }
}
/* Inline tooltip for input fields */
.input-with-tooltip {
    display: flex;
    align-items: center;
    gap: 4px;
}
.input-with-tooltip input {
    flex: 1;
    min-width: 0;
}
.noise-warning-btn {
    background: none;
    border: none;
    color: #F57C00;
    font-size: 16px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
    width: 20px;
}
.noise-warning-btn:hover {
    color: #E65100;
}
/* Modal styles */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal-overlay.active {
    display: flex;
}
.modal {
    background: white;
    border-radius: 12px;
    max-width: 400px;
    width: 100%;
    padding: 24px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}
.modal.modal-large {
    max-width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
}
@media (min-width: 900px) {
    .modal.modal-large {
        max-width: 800px;
    }
}
.modal h4 {
    margin: 16px 0 8px 0;
    font-size: 1em;
    color: #444;
}
.modal h4:first-of-type {
    margin-top: 0;
}
.modal .param-list {
    margin: 0 0 12px 0;
    padding-left: 0;
    list-style: none;
}
.modal .param-list li {
    margin-bottom: 8px;
    padding-left: 16px;
    position: relative;
}
.modal .param-list li::before {
    content: "•";
    position: absolute;
    left: 0;
    color: var(--primary);
}
.modal .param-name {
    font-weight: 600;
    color: #333;
}
.modal h3 {
    margin: 0 0 12px 0;
    font-size: 1.1em;
    color: #333;
}
.modal p {
    margin: 0 0 16px 0;
    color: #555;
    font-size: 0.95em;
    line-height: 1.5;
}
.modal-close {
    width: 100%;
    padding: 12px;
    background: #f0f0f0;
    border: none;
    border-radius: 8px;
    font-size: 1em;
    font-weight: 500;
    cursor: pointer;
    color: #333;
}
.modal-close:hover {
    background: #e0e0e0;
}
/* Units toggle */
.units-row {
    margin-top: 15px;
}
.toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: normal;
    color: #555;
    margin: 0;
}
.toggle-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--primary);
}
/* Advanced options */
.advanced-row {
    margin-top: 15px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}
.advanced-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    color: #666;
    font-size: 0.9em;
    user-select: none;
}
.advanced-toggle:hover {
    color: var(--primary);
}
.advanced-toggle .chevron {
    transition: transform 0.2s ease;
    font-size: 0.8em;
}
.advanced-toggle.expanded .chevron {
    transform: rotate(90deg);
}
.advanced-options {
    display: none;
    margin-top: 10px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}
.advanced-options.visible {
    display: block;
}
.advanced-options .param-row {
    margin-top: 0;
}
.advanced-options label {
    font-size: 0.85em;
    margin-top: 10px;
}
.advanced-options label:first-child {
    margin-top: 0;
}
.advanced-options input[type="number"] {
    padding: 8px 10px;
    font-size: 14px;
}
.advanced-options select {
    padding: 8px 10px;
    font-size: 14px;
}
.advanced-reset {
    margin-top: 12px;
    text-align: right;
}
.reset-btn {
    background: none;
    border: 1px solid #ccc;
    color: #666;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.85em;
    cursor: pointer;
}
.reset-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}
.custom-settings {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: 12px;
    padding-left: 12px;
    border-left: 1px solid #ccc;
    font-size: 0.85em;
    color: #555;
}
.custom-settings .setting {
    white-space: nowrap;
}
.custom-settings .setting-label {
    color: #888;
}
.custom-settings .setting-value {
    font-weight: 500;
}
.custom-settings .setting.modified .setting-value {
    color: var(--primary);
    font-weight: 600;
}
@media (max-width: 600px) {
    .custom-settings {
        margin-left: 0;
        margin-top: 4px;
        padding-left: 0;
        border-left: none;
        font-size: 0.8em;
        flex-basis: 100%;
        flex-wrap: wrap;
        row-gap: 2px;
    }
    .units-row {
        flex-wrap: wrap;
    }
}
.footer {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #ddd;
    text-align: center;
    font-size: 0.85em;
    color: #888;
}
.footer a {
    color: var(--primary);
    text-decoration: none;
}
.footer a:hover {
    text-decoration: underline;
}
.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.footer-links {
    display: flex;
    gap: 20px;
}
.footer-version {
    color: #aaa;
    font-size: 0.9em;
}
.footer-copyright {
    color: #aaa;
    font-size: 0.9em;
}
/* Input mode toggle (URL vs Upload) */
.input-mode-toggle {
    display: flex;
    margin-bottom: 8px;
    border: 1px solid #ddd;
    border-radius: 6px;
    overflow: hidden;
    width: fit-content;
}
.mode-tab {
    padding: 6px 16px;
    border: none;
    background: #f5f5f5;
    color: #666;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 500;
    transition: background 0.2s, color 0.2s;
}
.mode-tab:hover { background: #eee; }
.mode-tab.active {
    background: var(--primary, #FF6B35);
    color: white;
}

/* File drop zone */
.file-drop-zone {
    border: 2px dashed #ccc;
    border-radius: 8px;
    padding: 24px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}
.file-drop-zone:hover,
.file-drop-zone.drag-over {
    border-color: var(--primary, #FF6B35);
    background: rgba(255, 107, 53, 0.05);
}
.drop-zone-content { color: #777; }
.drop-zone-content p { margin: 6px 0; }
.drop-zone-content strong { color: var(--primary, #FF6B35); }
.drop-zone-hint { font-size: 0.85em; color: #aaa; }

/* File selected state */
.file-selected {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}
.file-name {
    font-weight: 500;
    color: #333;
    font-size: 1em;
}
.clear-file-btn {
    background: none;
    border: none;
    color: #999;
    font-size: 1.4em;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}
.clear-file-btn:hover { color: #c00; }
.file-input-hidden { display: none; }
.file-analyzing {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 10px;
    color: #666;
    font-size: 0.95em;
}

/* File drop zone 2 (compare mode) — smaller variant */
.file-drop-zone-2 {
    padding: 16px;
    margin-top: 4px;
}
.file-drop-zone-2 svg { width: 20px; height: 20px; }
.file-drop-zone-2 p { font-size: 0.9em; margin: 4px 0; }

/* Saved routes picker */
.saved-routes-picker {
    margin-top: 8px;
}
.saved-routes-divider {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #999;
    font-size: 0.85em;
    margin: 8px 0 6px;
}
.saved-routes-divider::before,
.saved-routes-divider::after {
    content: '';
    flex: 1;
    border-top: 1px solid #ddd;
}
.saved-routes-picker select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 0.9em;
    background: #fff;
    color: #333;
    cursor: pointer;
}
.saved-routes-picker select:focus {
    border-color: var(--primary, #FF6B35);
    outline: none;
}

.upload-save-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #e8f5e9;
    border: 1px solid #a5d6a7;
    border-radius: 8px;
    padding: 12px 16px;
    margin: 16px 0;
    font-size: 0.9em;
    color: #2e7d32;
}
.upload-save-banner span { flex: 1; }
.banner-save-btn {
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 6px 16px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9em;
}
.banner-save-btn:hover { opacity: 0.9; }
.banner-dismiss-btn {
    background: none;
    border: none;
    color: #666;
    font-size: 1.3em;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}
.banner-dismiss-btn:hover { color: #333; }

.url-input-wrapper {
    position: relative;
    margin-top: 5px;
}
.url-input-wrapper input[type="text"] {
    margin-top: 0;
}
.url-name-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 12px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 16px;
    color: #333;
    cursor: text;
    display: none;
    align-items: center;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.url-name-overlay.visible {
    display: flex;
}
.url-name-overlay .route-name {
    font-size: 16px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    flex: 1;
    max-width: none;
}
.url-name-overlay .route-type {
    color: #888;
    font-size: 13px;
    margin-left: 8px;
    flex-shrink: 0;
}
.recent-urls-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-top: none;
    border-radius: 0 0 6px 6px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    z-index: 100;
    max-height: 300px;
    overflow-y: auto;
}
.recent-urls-dropdown.hidden {
    display: none;
}
.recent-url-item {
    padding: 10px 12px;
    cursor: pointer;
    font-size: 14px;
    border-bottom: 1px solid #eee;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.recent-url-item:last-child {
    border-bottom: none;
}
.recent-url-item:hover,
.recent-url-item.highlighted {
    background: #f0f7ff;
}
.recent-urls-header {
    padding: 8px 12px;
    font-size: 12px;
    color: #888;
    background: #f9f9f9;
    border-bottom: 1px solid #eee;
}
.recent-url-name {
    font-weight: 500;
    color: #333;
}
.recent-url-path {
    font-size: 12px;
    color: #888;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* Compare mode styles */
.compare-toggle {
    margin-top: 8px;
    margin-bottom: 5px;
}
.compare-toggle label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: normal;
    color: #555;
}
.compare-toggle input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--primary);
}
#compareUrlWrapper {
    margin-top: 10px;
}
#compareUrlWrapper.hidden {
    display: none;
}
.compare-label {
    display: block;
    font-size: 0.9em;
    color: #555;
    margin-bottom: 4px;
}
/* Comparison table styles */
.comparison-table-wrapper {
    margin: 20px 0;
    overflow-x: auto;
    max-width: 800px;
}
.comparison-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95em;
}
.comparison-table th,
.comparison-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid #eee;
}
.comparison-table th {
    background: #f5f5f5;
    font-weight: 600;
    border-bottom: 8px solid white;
}
.comparison-table td:first-child {
    white-space: nowrap;
    padding-right: 3%;
}
@media (max-width: 700px) {
    .comparison-table td:first-child {
        white-space: normal;
    }
}
.comparison-table .route-col {
    text-align: right;
    min-width: 100px;
}
.comparison-table .diff-col {
    text-align: right;
    color: #666;
    font-size: 0.9em;
    min-width: 80px;
}
.comparison-table tr.primary {
    background: #f0f7ff;
}
.comparison-table tr.primary td {
    font-weight: 600;
}
.comparison-table tr.steepness {
    background: #fff8f0;
}
.comparison-table tr.steepness td {
    font-weight: 600;
}
.comparison-table tr.group-spacer td {
    padding: 6px 0;
    border-bottom: none;
    background: transparent;
}
.comparison-table tr.group-spacer td hr {
    border: none;
    border-top: 2px solid #ccc;
    margin: 0;
}
.est-marker {
    color: #999;
    font-size: 0.85em;
    font-weight: normal;
    cursor: help;
}
.comparison-footnote {
    font-size: 0.8em;
    color: #888;
    margin-top: 8px;
    font-style: italic;
}
/* Steep comparison table - match steep-section background, grey separator */
.steep-comparison-table th {
    background: transparent;
    border-bottom: 2px solid #ccc;
}
.steep-comparison-table th:not(:first-child) {
    min-width: 120px;
}
.steep-comparison-table th:first-child,
.steep-comparison-table td:first-child {
    white-space: nowrap;
}
@media (max-width: 600px) {
    .steep-comparison-table th:not(:first-child) {
        min-width: auto;
    }
    .steep-comparison-table th:first-child {
        width: auto;
    }
    .steep-comparison-table th .result-badge {
        display: block;
        margin-top: 4px;
    }
}
/* Comparison histograms */
.histogram-bars.comparison-mode {
    gap: 12px;  /* spacing between grade bins */
}
.histogram-bars.comparison-mode .histogram-bar {
    flex: 1;
    min-width: 0;
}
.histogram-bars.comparison-mode .bar-container {
    display: flex;
    gap: 2px;
    align-items: flex-end;
}
.histogram-bars.comparison-mode .bar {
    flex: 1;
}
.histogram-bars.comparison-mode .bar.route2 {
    background-image: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 2px,
        rgba(255,255,255,0.4) 2px,
        rgba(255,255,255,0.4) 4px
    ) !important;
}
/* Histogram tooltip */
.bar-tooltip {
    position: fixed;
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.85em;
    pointer-events: none;
    z-index: 1000;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.bar-tooltip .tooltip-title {
    font-weight: 600;
    margin-bottom: 4px;
    border-bottom: 1px solid rgba(255,255,255,0.3);
    padding-bottom: 4px;
}
.bar-tooltip .tooltip-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}
.bar-tooltip .tooltip-label {
    color: #aaa;
}
.histogram-legend {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 10px;
    font-size: 0.8em;
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
}
.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 2px;
}
.legend-color.striped {
    background-image: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 2px,
        rgba(255,255,255,0.4) 2px,
        rgba(255,255,255,0.4) 4px
    );
}
/* Chart type toggle (Bars / Donut) */
.chart-toggle-row {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 2px;
}
.chart-type-toggle {
    display: flex;
    gap: 0;
    border: 1px solid #ddd;
    border-radius: 6px;
    overflow: hidden;
    width: fit-content;
}
.chart-toggle-btn {
    padding: 5px 14px;
    border: none;
    background: #f5f5f5;
    color: #666;
    cursor: pointer;
    font-size: 0.82em;
    font-weight: 500;
    transition: background 0.2s, color 0.2s;
}
.chart-toggle-btn:hover { background: #eee; }
.chart-toggle-btn.active {
    background: var(--primary);
    color: white;
}
/* Donut chart styles */
.grade-donut {
    flex: 1;
    padding: 4px 4px 2px 4px;
    background: #f9f9f9;
    border-radius: 6px;
    text-align: center;
    overflow: visible;
}
.grade-donut h4 {
    margin: 0 0 2px 0;
    font-size: 0.9em;
    color: #555;
}
.donut-svg {
    width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
    overflow: visible;
}
.donut-slice {
    transition: opacity 0.15s;
}
.donut-slice:hover {
    opacity: 0.8;
}
.donut-slice-clickable {
    cursor: pointer;
    stroke-dasharray: 4 2;
}
.donut-slice-clickable:hover {
    opacity: 0.75;
    filter: brightness(1.1);
}
.donut-label {
    font-size: 11px;
    fill: #444;
    pointer-events: none;
}
.donut-pct {
    font-size: 10px;
    fill: #fff;
    pointer-events: none;
    font-weight: 600;
}
.donut-center-name {
    font-size: 12px;
    fill: #555;
    font-weight: 600;
}
.donut-center-value {
    font-size: 11px;
    fill: #888;
}
.donut-hint {
    font-size: 0.75em;
    font-style: italic;
    color: #999;
    margin-top: 6px;
}
.donut-legend {
    font-size: 0.8em;
    color: #666;
    margin-top: 2px;
    text-align: center;
}
.donut-legend-item {
    display: inline-block;
    margin: 0 8px;
}
.donut-legend-swatch {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 4px;
    vertical-align: middle;
}
.donut-range-label {
    font-size: 8px;
    fill: #333;
    stroke: white;
    stroke-width: 2px;
    paint-order: stroke fill;
    pointer-events: none;
}
.donut-leader {
    stroke: #999;
    stroke-width: 0.7;
}
.donut-nested-name {
    font-size: 9px;
    fill: #666;
}
@media (max-width: 600px) {
    .donut-label { font-size: 9px; }
    .donut-pct { font-size: 8px; }
    .donut-center-name { font-size: 10px; }
    .donut-center-value { font-size: 9px; }
    .donut-range-label { font-size: 7px; }
    .donut-nested-name { font-size: 6px; }
}
/* Stacked elevation profiles (comparison mode) */
.elevation-profiles-stacked .elevation-profile {
    margin-top: 10px;
    margin-bottom: 10px;
    padding: 10px;
}
.elevation-profiles-stacked .elevation-profile:last-child {
    margin-bottom: 0;
}
.elevation-profiles-stacked .elevation-canvas {
    height: 300px;
}
.elevation-profiles-stacked .elevation-profile-header {
    margin-bottom: 6px;
}
/* Side-by-side RWGPS embeds */
.route-maps-comparison {
    display: flex;
    gap: 15px;
    margin-top: 20px;
}
.route-maps-comparison .route-map {
    flex: 1;
}
.route-maps-comparison .route-map h4 {
    margin: 0 0 10px 0;
    font-size: 0.9em;
    color: #555;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
@media (max-width: 768px) {
    .route-maps-comparison {
        flex-direction: column;
    }
}

/* PWA - Service Worker Update Notification */
.sw-update-notification {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 10000;
    font-size: 0.9em;
}
.sw-update-notification button {
    background: white;
    color: var(--accent);
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
}
.sw-update-notification button:hover {
    background: #f0f0f0;
}

/* PWA - Offline Banner */
.offline-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #ff9800;
    color: white;
    text-align: center;
    padding: 8px 12px;
    font-size: 0.85em;
    z-index: 10001;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
}
.offline-banner-link {
    color: white;
    text-decoration: underline;
    font-weight: 500;
}
body.offline {
    padding-top: 40px;
}

/* PWA - Save for Offline Button */
.save-offline-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #f0f0f0;
    border: 1.5px solid #ddd;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    color: #555;
    transition: all 0.2s;
    height: 28px;
    box-sizing: border-box;
    width: auto;
    margin: 0;
}
.save-offline-btn:hover {
    background: #e8e8e8;
    border-color: #ccc;
}
.save-offline-btn svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
}
.save-offline-btn.saved {
    background: #e8f5e9;
    border-color: #a5d6a7;
    color: #2e7d32;
}
.save-offline-btn.saved .save-icon,
.save-offline-btn.saved .save-text {
    display: none;
}
.save-offline-btn.saved .saved-icon,
.save-offline-btn.saved .saved-text {
    display: inline !important;
}
.save-offline-btn.saving {
    opacity: 0.7;
    cursor: wait;
}
.save-offline-btn.saving .save-text::after {
    content: '...';
}

/* Header Links Container */
.header-links {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

/* Saved Routes Link in Header */
.saved-routes-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.85em;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.2s;
}
.saved-routes-link:hover {
    background: rgba(0,0,0,0.05);
    color: var(--text-dark);
}
.saved-routes-link svg {
    opacity: 0.7;
}
.saved-routes-link .count-badge {
    background: var(--primary);
    color: white;
    font-size: 0.75em;
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: 500;
}
/* Saved Routes Page Styles */
.saved-routes-page {
    background: white;
    border-radius: 12px;
    padding: 20px;
    margin-top: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.saved-routes-page h2 {
    margin-top: 0;
    color: var(--accent);
}
.storage-stats {
    background: #f5f5f7;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
}
.storage-stats p {
    margin: 0 0 8px 0;
    font-size: 0.9em;
    color: var(--text-muted);
}
.storage-bar {
    height: 8px;
    background: #ddd;
    border-radius: 4px;
    overflow: hidden;
}
.storage-used {
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
    transition: width 0.3s;
}
.storage-used.has-usage {
    min-width: 6px;
}
.storage-used.warning {
    background: #ff9800;
}
.storage-used.critical {
    background: #f44336;
}
.saved-routes-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.saved-route-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid #eee;
}
.saved-route-item:last-child {
    border-bottom: none;
}
.saved-routes-page .route-info {
    flex: 1;
    min-width: 0;
}
.saved-routes-page .route-name a:first-of-type {
    color: var(--primary);
    text-decoration: none;
}
.saved-routes-page .route-name a:first-of-type:hover {
    text-decoration: underline;
}
.route-meta {
    display: block;
    font-size: 0.8em;
    color: var(--text-muted);
    white-space: nowrap;
}
.delete-btn {
    width: auto !important;
    padding: 8px 16px !important;
    margin: 0 !important;
    margin-left: 16px !important;
    background: #f5f5f5 !important;
    border: 1px solid #ddd !important;
    color: #666 !important;
    border-radius: 4px !important;
    cursor: pointer;
    font-size: 0.85em !important;
    flex-shrink: 0;
}
.delete-btn:hover {
    background: #fee !important;
    border-color: #f99 !important;
    color: #c00 !important;
}
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}
.empty-state p {
    margin: 8px 0;
}
.empty-state a {
    color: var(--primary);
}
.clear-all-btn {
    width: auto !important;
    background: #f5f5f5 !important;
    border: 1px solid #ddd !important;
    color: #666 !important;
    padding: 8px 16px !important;
    border-radius: 6px !important;
    cursor: pointer;
    font-size: 0.85em !important;
    margin-top: 16px !important;
}
.clear-all-btn:hover {
    background: #fee !important;
    border-color: #f99;
    color: #c00;
}
.saved-routes-page .loading {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}
/* POI finder */
.poi-finder {
    margin-top: 12px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-subtle, #fafafa);
}
.poi-finder > summary {
    cursor: pointer;
    font-weight: 600;
    padding: 4px 0;
}
.poi-finder-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 16px;
    align-items: center;
    margin: 10px 0;
}
.poi-finder-controls label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.9em;
}
.poi-finder-controls input[type="number"] {
    width: 70px;
    padding: 2px 4px;
}
.poi-finder-controls button {
    padding: 4px 12px;
}
.poi-status {
    color: var(--text-muted);
    font-size: 0.9em;
}
.poi-status.is-loading::before {
    content: "";
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-right: 6px;
    vertical-align: -2px;
    border: 2px solid #ccc;
    border-top-color: #1a73e8;
    border-radius: 50%;
    animation: poi-spinner-rot 0.7s linear infinite;
}
@keyframes poi-spinner-rot {
    to { transform: rotate(360deg); }
}
.poi-results {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
    margin-top: 8px;
}
.poi-results th {
    text-align: left;
    padding: 4px 8px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-subtle, #fafafa);
    position: sticky;
    top: 0;
}
.poi-results td {
    padding: 3px 8px;
    border-bottom: 1px solid var(--border-light, #eee);
}
.poi-results td.num {
    text-align: left;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.poi-results .poi-icon {
    text-align: left;
    font-size: 1.1em;
}
.poi-results .poi-hours {
    color: var(--text-muted);
    font-size: 0.85em;
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* POI filter chips */
.poi-filters {
    display: flex;
    gap: 6px;
    align-items: center;
    margin: 8px 0;
    font-size: 0.9em;
    flex-wrap: wrap;
}
.poi-filter-label {
    color: var(--text-muted);
}
.poi-chip {
    padding: 2px 10px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg, #fff);
    cursor: pointer;
    font-size: 0.85em;
}
.poi-chip:hover {
    background: var(--bg-subtle, #f0f0f0);
}
.poi-chip.active {
    background: var(--accent, #2a6fb0);
    color: white;
    border-color: var(--accent, #2a6fb0);
}
.poi-filter-detail {
    color: var(--text-muted);
    margin-left: auto;
}

/* POI map (Leaflet) — route polyline + POI markers with bidirectional
   hover/click sync to the elevation chart. */
.poi-map-container {
    position: relative;
    margin: 8px 0;
}
.poi-map {
    height: 400px;
    border: 1px solid var(--border, #ccc);
    border-radius: 6px;
    background: var(--bg-subtle, #f7f7f7);
}
.poi-map-legend {
    position: absolute;
    bottom: 10px;
    left: 10px;
    background: rgba(255, 255, 255, 0.92);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.82em;
    display: flex;
    gap: 12px;
    align-items: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
    z-index: 400;
}

/* POI info panel — RWGPS-style dialog at the top-left of the map. Click a
   marker → panel shows with full details and link buttons. Close via × or
   by tapping empty map. Desktop also gets a brief hover tooltip via Leaflet. */
.poi-map-info {
    position: absolute;
    top: 10px;
    left: 10px;
    right: auto;
    max-width: min(320px, calc(100% - 20px));
    background: #fff;
    border: 1px solid var(--border, #d0d0d0);
    border-radius: 8px;
    padding: 12px 36px 12px 12px;
    font-size: 0.9em;
    line-height: 1.35;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
    z-index: 600;
}
.poi-map-info-close {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    color: var(--text-muted, #666);
    padding: 0;
}
.poi-map-info-close:hover { color: #000; }
.poi-map-info-header {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 6px;
}
.poi-map-info-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    flex-shrink: 0;
}
.poi-map-info-icon .material-icons {
    font-size: 18px;
    line-height: 1;
}
.poi-map-info-name {
    font-weight: 600;
    font-size: 1.05em;
}
.poi-map-info-city {
    color: var(--text-muted, #666);
    font-size: 0.9em;
}
.poi-map-info-meta {
    color: var(--text-muted, #444);
    font-size: 0.9em;
    margin: 4px 0;
}
.poi-map-info-hours {
    color: var(--text-muted, #444);
    font-size: 0.85em;
    margin: 4px 0;
}
.poi-map-info-links {
    margin-top: 8px;
    font-size: 0.9em;
}
.poi-map-info-links a {
    color: var(--accent, #2a6fb0);
    text-decoration: none;
    margin-right: 12px;
}
.poi-map-info-links a:hover { text-decoration: underline; }

@media (max-width: 600px) {
    .poi-map-info { font-size: 0.85em; padding: 10px 32px 10px 10px; }
}
.legend-line {
    display: inline-block;
    width: 28px;
    height: 4px;
    vertical-align: middle;
    margin-right: 2px;
}
.legend-line-paved  {
    background: #d93535;
    height: 5px;
    border-top: 1px solid #7a1a1a;
    border-bottom: 1px solid #7a1a1a;
    box-sizing: content-box;
}
.legend-line-gravel {
    height: 5px;
    border-top: 1px solid #7a1a1a;
    border-bottom: 1px solid #7a1a1a;
    box-sizing: content-box;
    background: repeating-linear-gradient(90deg,
        #d93535 0, #d93535 5px,
        #ffffff 5px, #ffffff 9px);
}

/* POI divIcon markers on the map: circle with the type icon.
   Disable iOS touch callout / text selection so long-press triggers our
   navigate-to-card handler instead of Safari's Copy/Find Selection menu. */
.poi-map-divicon {
    background: transparent;
    border: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}
.poi-map-marker {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    color: white;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}
.poi-map-marker .material-icons {
    font-size: 14px;
    line-height: 1;
}

/* POI icons used elsewhere (cards, chips, tooltips, summaries) */
.poi-icon-glyph {
    font-size: 18px !important;
    line-height: 1;
    vertical-align: middle;
}
.poi-chip-icon {
    font-size: 16px !important;
    vertical-align: middle;
}
.poi-icon-count {
    font-size: 0.85em;
    color: var(--text-muted);
    margin-right: 4px;
}

@media (max-width: 600px) {
    .poi-map { height: 300px; }
}

/* ---- Fullscreen / maximize mode ----
   Triggered by the expand button on the map. Body gets .poi-fullscreen-on.
   Layout (top → bottom): elevation chart (flex 1) → density strip →
   map (60vh) → POI type checkboxes. Works on iPad + iPhone, portrait +
   landscape. Uses CSS pseudo-fullscreen (position:fixed) because iPhone
   Safari does not support the Fullscreen API on non-video elements. */
body.poi-fullscreen-on { overflow: hidden; }
body.poi-fullscreen-on .elevation-profile {
    position: fixed;
    inset: 0;
    z-index: 9999;
    margin: 0;
    padding: 8px;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    background: white;
    overflow: hidden;
}
/* Trim the header: hide title/link, keep only the speed/grade/unpaved toggles */
body.poi-fullscreen-on .elevation-profile-header {
    flex: 0 0 auto;
    margin-bottom: 4px;
}
body.poi-fullscreen-on .elevation-profile-header > h4,
body.poi-fullscreen-on .elevation-profile-header .ride-link { display: none; }
body.poi-fullscreen-on .elevation-profile-header .elevation-profile-toggles {
    flex-wrap: wrap;
}
/* Chart: take all remaining space between toggles and density strip */
body.poi-fullscreen-on .elevation-profile-container {
    flex: 1 1 0;
    min-height: 120px;
}
body.poi-fullscreen-on .elevation-profile-container .elevation-canvas {
    width: 100% !important;
    height: 100% !important;
}
/* POI density strip is hidden in fullscreen — the map shows the POIs,
   so the strip is redundant and takes space away from the chart+map. */
body.poi-fullscreen-on .poi-density-strip {
    display: none !important;
}
/* Map takes 3/5 of the viewport height */
body.poi-fullscreen-on .poi-map-container {
    flex: 0 0 60vh;
    margin: 4px 0;
    position: relative;
}
body.poi-fullscreen-on .poi-map {
    height: 100% !important;
    width: 100%;
}
body.poi-fullscreen-on .poi-map-legend { display: none; }
/* POI finder: pin to bottom, force open, show only the type checkboxes */
body.poi-fullscreen-on .poi-finder {
    flex: 0 0 auto;
    margin: 0;
    border: none;
    padding: 0;
}
body.poi-fullscreen-on .poi-finder > summary { display: none; }
/* No search has been run yet — hide the category filter checkboxes
   entirely so the user doesn't wonder why checked types show no markers */
body.poi-fullscreen-no-results .poi-finder,
body.poi-fullscreen-no-results .poi-finder-controls { display: none !important; }
body.poi-fullscreen-on .poi-finder .poi-filters,
body.poi-fullscreen-on .poi-finder .poi-sections { display: none !important; }
body.poi-fullscreen-on .poi-finder-controls {
    flex-wrap: wrap;
    gap: 6px 10px;
    padding: 6px 2px 2px;
    border-top: 1px solid var(--border-light, #eee);
}
/* Match speed/grade/unpaved checkbox size + weight + color */
body.poi-fullscreen-on .poi-finder-controls label {
    font-size: 0.85em;
    font-weight: normal;
    color: #666;
    line-height: 1;
    gap: 2px;
}
body.poi-fullscreen-on .poi-finder-controls .poi-chip-icon {
    font-size: 14px;
}
/* Hide radius input, search button, status text in fullscreen — only
   the four type checkboxes remain as on/off filters for map markers */
body.poi-fullscreen-on .poi-finder-controls > label:first-of-type,
body.poi-fullscreen-on #poiSearchBtn,
body.poi-fullscreen-on .poi-status { display: none; }

/* Phones (portrait): shrink the map so the elevation chart gets ~1.5x
   more vertical space than the default 60vh layout would give it */
@media (max-width: 600px) {
    body.poi-fullscreen-on .poi-map-container { flex: 0 0 55vh; }
}
/* Landscape on phones: give the map even less so the chart stays readable */
@media (max-height: 500px) {
    body.poi-fullscreen-on .poi-map-container { flex: 0 0 50vh; }
}

/* ---- Bottom-sheet reader (Wikipedia articles) ---- */
.reader-sheet-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.2);
    z-index: 9998;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}
.reader-sheet-backdrop-visible {
    opacity: 1;
    pointer-events: auto;
}
.reader-sheet {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    background: #fff;
    z-index: 9999;
    border-top-left-radius: 14px;
    border-top-right-radius: 14px;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.25s ease, height 0.25s ease;
    max-height: 95vh;
    -webkit-overflow-scrolling: touch;
}
.reader-sheet-peek     { transform: translateY(0); height: 45vh; }
.reader-sheet-expanded { transform: translateY(0); height: 85vh; }
.reader-sheet-closed   { transform: translateY(100%); }

.reader-sheet-handle {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 32px;
    flex: 0 0 auto;
    cursor: ns-resize;
    touch-action: none;
}
.reader-sheet-handle-bar {
    width: 40px;
    height: 4px;
    background: #ccc;
    border-radius: 2px;
}
.reader-sheet-close {
    position: absolute;
    top: 2px; right: 6px;
    background: transparent;
    border: none;
    font-size: 24px;
    line-height: 1;
    color: #888;
    cursor: pointer;
    padding: 2px 8px;
    z-index: 2;
}
.reader-sheet-close:hover { color: #000; }
.reader-sheet-toggle {
    position: absolute;
    top: 4px;
    right: 42px;
    background: transparent;
    border: none;
    color: #666;
    cursor: pointer;
    padding: 2px 4px;
    z-index: 2;
    display: flex;
    align-items: center;
}
.reader-sheet-toggle .material-icons { font-size: 20px; }
.reader-sheet-toggle:hover { color: #000; }
/* Give the header a draggable look + better hit area for iOS */
.reader-sheet-header {
    cursor: ns-resize;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}
.reader-sheet-content {
    flex: 1 1 0;
    overflow-y: auto;
    padding: 0 16px 24px;
}
.reader-sheet-header {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 8px 0 12px;
    /* No border here — the handle area above provides visual separation.
       An accent bar here would collide with the absolute-positioned
       toggle/close buttons. */
}
.reader-sheet-thumb {
    width: 96px;
    height: 96px;
    object-fit: cover;
    border-radius: 6px;
    flex: 0 0 auto;
    background: #f0f0f0;
}
.reader-sheet-heading { flex: 1 1 0; min-width: 0; }
.reader-sheet-title {
    font-size: 1.2em;
    font-weight: 600;
    line-height: 1.2;
    color: #222;
}
.reader-sheet-subtitle {
    font-size: 0.85em;
    color: #666;
    margin-top: 4px;
}
.reader-sheet-body {
    font-size: 0.95em;
    line-height: 1.5;
    color: #333;
    white-space: pre-wrap;
}
.reader-sheet-footer-fixed {
    flex: 0 0 auto;
    padding: 10px 16px;
    border-top: 1px solid #eee;
    font-size: 0.9em;
    background: #fff;
}
.reader-sheet-footer-fixed:empty { display: none; }
.reader-sheet-nav {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9em;
    color: #555;
}
.reader-sheet-nav-btn {
    background: none;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 2px 10px;
    font-size: 1.1em;
    font-weight: bold;
    color: #6a4c93;
    cursor: pointer;
    line-height: 1;
    touch-action: manipulation;
}
.reader-sheet-nav-btn:hover { background: #f4f4f4; }
.reader-sheet-footer-fixed a { color: #6a4c93; text-decoration: none; }
.reader-sheet-footer-fixed a:hover { text-decoration: underline; }
@media (max-width: 600px) {
    .reader-sheet-thumb { width: 72px; height: 72px; }
    .reader-sheet-title { font-size: 1.05em; }
}

.reader-sheet-loading-more {
    margin-top: 12px;
    font-size: 0.85em;
    color: #888;
    font-style: italic;
    text-align: center;
}
.reader-sheet-translated-note {
    margin-top: 12px;
    font-size: 0.8em;
    color: #888;
    font-style: italic;
}
.wiki-full-article p { margin: 0 0 0.8em 0; }
.wiki-full-article a { color: #6a4c93; }
.wiki-full-article img { max-width: 100%; height: auto; border-radius: 4px; }
.wiki-full-article figure { margin: 0.8em 0; }
.wiki-full-article figcaption { font-size: 0.85em; color: #666; margin-top: 4px; }
/* Hide elements that break outside Wikipedia's own page context */
.wiki-full-article .infobox { display: none; }
.wiki-full-article .mw-kartographer-container,
.wiki-full-article .mw-kartographer-map,
.wiki-full-article .mw-kartographer-mapDialog,
.wiki-full-article .sistersitebox,
.wiki-full-article .noprint,
.wiki-full-article .mw-editsection,
.wiki-full-article .reference { display: none; }
.wiki-full-article .reflist { display: none; }
.wiki-full-article .thumb { float: none; margin: 8px 0; }
.wiki-full-article table { font-size: 0.85em; max-width: 100%; overflow-x: auto; display: block; }

/* Put historyStatus on its own line so it doesn't run into poiStatus */
#historyStatus { display: block; width: 100%; color: var(--text-muted); font-size: 0.9em; }

/* History loading progress bar (two-phase: geosearch + extract) */
.history-progress {
    display: block;
    width: 100%;
    font-size: 0.85em;
    color: #555;
    margin-top: 4px;
}
.history-progress-label {
    display: flex;
    justify-content: space-between;
    margin-bottom: 2px;
}
.history-progress-bar-wrap {
    width: 100%;
    max-width: 400px;
    height: 6px;
    background: #e0e0e0;
    border-radius: 3px;
    overflow: hidden;
}
.history-progress-bar-fill {
    height: 100%;
    width: 0;
    background: #6a4c93;
    transition: width 0.15s ease;
}

/* Compare mode: show/hide toggle for Route 1 / Route 2 / Both */
.compare-map-toggle {
    display: flex;
    gap: 4px;
    padding: 6px 8px;
    justify-content: center;
}
.compare-toggle-btn {
    padding: 4px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
    font-size: 0.85em;
    cursor: pointer;
    color: #555;
}
.compare-toggle-btn.active {
    background: #e8f0fe;
    border-color: #3580d9;
    color: #1a3d7a;
    font-weight: 600;
}
.compare-toggle-btn:hover { background: #f4f4f4; }
/* Legend line swatch for compare mode (blue) */
.legend-line-compare {
    display: inline-block;
    width: 24px;
    height: 4px;
    background: #3580d9;
    vertical-align: middle;
    margin: 0 4px;
    border-radius: 2px;
    opacity: 0.6;
}
/* Stop markers on trip maps (pause_circle icon) */
.stop-marker-wrapper {
    background: transparent !important;
    border: none !important;
}
.stop-marker {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.stop-marker .material-icons {
    font-size: 18px;
    color: #e67e22;
    background: #fff;
    border-radius: 50%;
}

/* Photo markers on trip maps (photo_camera icon) */
.photo-marker-wrapper {
    background: transparent !important;
    border: none !important;
}
.photo-marker {
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.photo-marker .material-icons {
    font-size: 18px;
    color: #1a73e8;
    background: #fff;
    border-radius: 50%;
    padding: 1px;
}
.photo-tooltip .leaflet-tooltip-content img {
    display: block;
    margin-bottom: 2px;
}
/* (photo-sheet styles removed — photos go straight to lightbox) */

/* Full-screen photo lightbox */
.photo-lightbox {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0, 0, 0, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}
.photo-lightbox-open {
    opacity: 1;
    pointer-events: auto;
    touch-action: none;
}
.photo-lightbox-img {
    max-width: 92vw;
    max-height: 88vh;
    object-fit: contain;
    border-radius: 4px;
    user-select: none;
    -webkit-user-select: none;
}
.photo-lightbox-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none;
    border: none;
    color: #fff;
    font-size: 36px;
    cursor: pointer;
    z-index: 2;
    line-height: 1;
}
.photo-lightbox-prev,
.photo-lightbox-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    font-size: 36px;
    cursor: pointer;
    padding: 8px 14px;
    border-radius: 6px;
    z-index: 2;
}
.photo-lightbox-prev { left: 12px; }
.photo-lightbox-next { right: 12px; }
.photo-lightbox-prev:hover,
.photo-lightbox-next:hover { background: rgba(255,255,255,0.3); }
.photo-lightbox-caption {
    position: absolute;
    bottom: 16px;
    left: 0;
    right: 0;
    text-align: center;
    color: rgba(255,255,255,0.8);
    font-size: 0.9em;
    padding: 0 20px;
}
@media (max-width: 600px) {
    .photo-lightbox-prev,
    .photo-lightbox-next { font-size: 28px; padding: 6px 10px; }
    .photo-lightbox-close { font-size: 28px; top: 8px; right: 10px; }
}

/* Legend line swatch for trip GPS track */
.legend-line-trip {
    display: inline-block;
    width: 24px;
    height: 4px;
    background: #d93535;
    vertical-align: middle;
    margin: 0 4px;
    border-radius: 2px;
}

/* ---- History (Wikipedia) POI markers ---- */
.poi-map-marker-history {
    background: #6a4c93 !important;
}
/* Pentagon shape for density strip (Wikipedia articles) */
.poi-density-marker.shape-pentagon {
    clip-path: polygon(14px 8px, 21px 13px, 18px 20px, 10px 20px, 7px 13px);
}

/* "Remaining" summary card shown while Locate tracking is active —
   sits just above the elevation chart. 4 equal cells; stacks nicely on
   phones. Compact so it doesn't eat into the chart's visible area. */
.locate-summary-card {
    display: flex;
    flex-direction: column;
    padding: 6px 10px;
    margin: 4px 0;
    background: #f1f8fe;
    border: 1px solid #c9def0;
    border-radius: 6px;
    font-size: 0.85em;
}
.locate-summary-title {
    font-size: 0.75em;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #5a7a93;
    margin-bottom: 2px;
    font-weight: 600;
}
.locate-summary-cells {
    display: flex;
    gap: 8px;
}
.locate-summary-cell {
    flex: 1 1 0;
    min-width: 0;
    text-align: center;
}
.locate-summary-label {
    color: #5a7a93;
    font-size: 0.8em;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.locate-summary-value {
    color: #0b3d66;
    font-weight: 700;
    font-size: 1.5em;
    line-height: 1.15;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
@media (max-width: 420px) {
    .locate-summary-card { padding: 4px 6px; }
    .locate-summary-cells { gap: 4px; }
    .locate-summary-label { font-size: 0.7em; }
    .locate-summary-value { font-size: 1.2em; }
}

/* "Locate me" button in the elevation-profile toggles row */
.locate-me-btn {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 3px 8px;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    color: #555;
    font-size: 0.85em;
    line-height: 1;
    cursor: pointer;
}
.locate-me-btn .material-icons { font-size: 14px; }
.locate-me-btn:hover { background: #f4f4f4; }
.locate-me-btn.active {
    background: #00d9ff;
    border-color: #003c4c;
    color: #003c4c;
    font-weight: 600;
}
.locate-me-btn.active .material-icons { color: #003c4c; }

/* Fullscreen button — match leaflet-bar style */
.poi-fs-btn {
    display: block;
    width: 30px;
    height: 30px;
    line-height: 30px;
    text-align: center;
    font-size: 18px;
    color: #000;
    text-decoration: none;
    font-weight: bold;
}
.poi-fs-btn:hover { background: #f4f4f4; }

/* POI density strip — aligns with elevation chart's data region.
   Margins mirror the canvas margins (left:50, right:60) so markers
   sit directly below the corresponding x-axis position. Strip is
   taller to accommodate vertical offset (y-axis = detour distance). */
.poi-density-strip {
    position: relative;
    height: 28px;
    margin: 2px 0 6px;
    padding: 0 60px 0 50px;
}
.poi-density-inner {
    position: relative;
    height: 100%;
    border-top: 1px solid var(--border-light, #eee);
    border-bottom: 1px dashed var(--border-light, #eee);
}
/* All density-strip markers share a fixed box and hit area (18x18 invisible
   pad, visible 8px shape inside via background + clip-path). Consistent
   dimensions matter for iOS touch — zero-sized elements don't receive
   reliable touchstart, which was causing taps to fall through to the
   browser's synthetic click and navigate prematurely. */
.poi-density-marker {
    position: absolute;
    /* Larger hit area for reliable finger taps on iOS. Visible shape stays
       compact via clip-path (below) at 22-78% of the box. */
    width: 28px;
    height: 28px;
    transform: translate(-50%, -50%);
    background: currentColor;
    opacity: 0.8;
    cursor: pointer;
    transition: transform 0.1s, opacity 0.1s;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
}
.poi-density-marker:hover { opacity: 1; z-index: 10; }
.poi-density-marker:hover { transform: translate(-50%, -50%) scale(1.4); }

/* Box is 28×28 (finger-friendly tap area) but the *visible* shape stays
   compact (~10px) — absolute pixel clip-path values so they don't scale
   when we change the box size. */
.poi-density-marker.shape-circle {
    clip-path: circle(5px at 50% 50%);
}
.poi-density-marker.shape-square {
    clip-path: polygon(9px 9px, 19px 9px, 19px 19px, 9px 19px);
}
.poi-density-marker.shape-diamond {
    clip-path: polygon(14px 8px, 20px 14px, 14px 20px, 8px 14px);
}
.poi-density-marker.shape-triangle {
    clip-path: polygon(14px 8px, 20px 20px, 8px 20px);
}
.poi-density-marker.shape-hexagon {
    clip-path: polygon(14px 7px, 20px 11px, 20px 17px, 14px 21px, 8px 17px, 8px 11px);
}

/* Custom tooltip for POI density strip (zero delay, styled) */
.poi-strip-tooltip {
    position: fixed;
    z-index: 1000;
    background: rgba(20, 20, 20, 0.92);
    color: white;
    padding: 6px 9px;
    border-radius: 4px;
    font-size: 0.85em;
    line-height: 1.35;
    max-width: 280px;
    pointer-events: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}
.poi-strip-tooltip strong {
    font-weight: 600;
}

/* Card highlight animation when a dot is clicked */
.poi-card-highlight {
    animation: poi-card-pulse 1.5s ease-out;
}
@keyframes poi-card-pulse {
    0%   { box-shadow: 0 0 0 3px rgba(42, 111, 176, 0.6); background: rgba(42, 111, 176, 0.08); }
    100% { box-shadow: 0 0 0 0 rgba(42, 111, 176, 0); background: transparent; }
}

/* POI sections (8ths of ride, each is a <details> expando) */
.poi-sections {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}
.poi-section {
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg, #fff);
}
.poi-section[open] {
    background: var(--bg-subtle, #fafafa);
}
.poi-section-summary {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 10px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.9em;
    list-style: none;
}
.poi-section-summary::-webkit-details-marker { display: none; }
.poi-section-summary::before {
    content: '▸';
    display: inline-block;
    width: 12px;
    color: var(--text-muted);
}
.poi-section[open] > .poi-section-summary::before { content: '▾'; }
.poi-section-km {
    font-weight: 600;
    min-width: 100px;
}
.poi-section-eta {
    color: var(--text-muted);
    min-width: 120px;
}
.poi-section-icons {
    font-size: 1em;
    margin-left: auto;
}
.poi-section-count {
    color: var(--text-muted);
    font-weight: normal;
}

/* POI card grid inside an expanded section */
.poi-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 8px;
    padding: 8px 12px 12px;
}
.poi-card {
    border: 1px solid var(--border-light, #e5e5e5);
    border-left: 4px solid var(--poi-accent, #999);
    border-radius: 5px;
    padding: 8px 10px;
    background: var(--bg, #fff);
    font-size: 0.88em;
}
.poi-card-type-toilets    { --poi-accent: #6c757d; }
.poi-card-type-bakery     { --poi-accent: #d49a3a; }
.poi-card-type-restaurant { --poi-accent: #a04040; }
.poi-card-type-cafe       { --poi-accent: #a04040; }

/* Detour-length chip (three bins: near / mid / far) */
.poi-detour-chip {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 0.95em;
    white-space: nowrap;
}
.poi-detour-near { background: #d4edda; color: #155724; }
.poi-detour-mid  { background: #fff3cd; color: #7a5200; }
.poi-detour-far  { background: #e9ecef; color: #495057; }
.poi-card-header {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-bottom: 3px;
}
.poi-card-icon {
    font-size: 1.1em;
    flex-shrink: 0;
}
.poi-card-name {
    font-weight: 600;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.poi-card-city {
    color: var(--text-muted);
    font-size: 0.9em;
    flex-shrink: 0;
}
.poi-card-meta {
    color: var(--text-muted);
    font-size: 0.9em;
    line-height: 1.3;
}
.poi-card-hours {
    color: var(--text-muted);
    font-size: 0.85em;
    margin-top: 2px;
}
.poi-card-links {
    margin-top: 4px;
}

/* External links (Google Maps, website) on POI cards */
.poi-ext-link {
    font-size: 0.9em;
    text-decoration: none;
    color: var(--accent, #2a6fb0);
}
.poi-ext-link:hover {
    text-decoration: underline;
}

@media (max-width: 600px) {
    .poi-section-summary {
        font-size: 0.85em;
        gap: 6px;
    }
    .poi-section-icons {
        margin-left: 0;
        flex-basis: 100%;
    }
}

/* RWGPS link in results header */
.rwgps-link {
    display: inline-flex; align-items: center; gap: 4px;
    color: var(--text-muted); font-size: 0.85em; text-decoration: none;
    margin-left: 8px;
}
.rwgps-link:hover { color: var(--primary); }

/* Embed mode — hide input form, keep branding */
.embed-mode #analyzeForm,
.embed-mode .saved-routes-link,
.embed-mode .save-offline-btn { display: none !important; }
