:root {
    --spacing: 15px;
    --button-size: 40px;
}

@media (max-width: 425px) {
    :root {
        --spacing: 10px;
        --button-size: 44px;
    }
}

@media (max-height: 425px) {
    :root {
        --spacing: 10px;
        --button-size: 44px;
    }
}

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: system-ui, sans-serif;
    font-size: 15px;
    overflow: hidden;
}

h1 {
    font-family: AlternateGothicNo2, sans-serif;
    font-weight: normal;
    font-size: 42px;
}

h2 {
    margin-bottom: 20px;
}

spacer {
    flex-grow: 1;
}


/* Header */
.header {
    padding: 0.5rem 1rem;
    z-index: 1100; /* Higher than help panel (1000) to ensure it's above */
    position: relative;
    background-color: white;
}

.header-content {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    max-width: 100%;
}

.nav {
    display: flex;
    gap: 0.5rem;
}

.nav-btn {
    padding: 10px 20px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    border: none;
    border-radius: 10px;
    font-size: 15px;
}

/* Main Layout */
.main {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
}

/* Sidebar Container - flexbox container */
.sidebar-container {
    position: absolute;
    top: var(--spacing);
    left: var(--spacing);
    width: 350px;
    max-width: calc(100% - 60px - calc(var(--spacing) * 4));
    max-height: calc(100dvh - 42px - var(--spacing)); /* Match legend panel height */
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0; /* No gap initially, instruction panel will add its own margin */
    transition: transform 0.2s ease;
    user-select: none;
    -webkit-user-select: none;
}

/* Hidden state for sidebar container */
.sidebar-container.hidden {
    transform: translateX(calc(-100% + var(--button-size) + 20px)); /* Slide left by width minus button space (button size + 20px margin) */
    pointer-events: none; /* Let touches pass through to the map */
}

/* Show toggle button and reposition when hidden */
.sidebar-container.hidden .sidebar-toggle-btn {
    opacity: 1;
    pointer-events: auto;
    right: auto;
    left: calc(100% - var(--button-size) - 20px); /* Cancels the container's translateX, anchoring the button near the screen's left edge */
}

/* Hide sidebar and instruction panel content when hidden */
.sidebar-container.hidden .sidebar,
.sidebar-container.hidden .instruction-panel,
.sidebar-container.hidden .logo-panel {
    opacity: 0;
    pointer-events: none;
}

/* Logo Panel */
.logo-panel {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: white;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    margin-bottom: var(--spacing);
    padding: 10px;
    padding-left: 20px;
    padding-right: 15px;;
    transition: opacity 0.2s ease;
}

.logo-panel-text {
    font-family: AlternateGothicNo2, sans-serif;
    font-weight: normal;
    font-size: 26px;
    margin: 0;
}

.sidebar-close-btn {
    background: none;
    border: none;
}

.sidebar-close-btn:hover {
    background-color: #f0f0f0;
}

.sidebar-close-btn .control-icon {
    width: 20px;
    height: 20px;
}


/* Instruction Panel */
.instruction-panel {
    flex: 0 0 auto; /* Don't grow or shrink, take natural height */
    background-color: white;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    opacity: 0;
    max-height: 0;
    margin-bottom: 0;
    overflow: hidden;
    transform: translateY(-10px);
    transition: opacity 0.2s ease-out 0.1s, transform 0.2s ease-out 0.1s, max-height 0.2s ease-out 0.1s, margin-bottom 0.2s ease-out 0.1s;
    pointer-events: none;
}

@media (min-height: 425px) {
    .instruction-panel.visible {
        opacity: 1;
        transform: translateY(0);
        max-height: 500px; /* Large enough for any content */
        margin-bottom: var(--spacing); /* Add spacing only when visible */
        pointer-events: auto;
    }
}

.instruction-content {
    padding: 1rem;
}

.instruction-content p {
    color: #333;
    font-size: 0.9rem;
    line-height: 1.5;
}

/* Sidebar */
.sidebar {
    flex: 0 1 auto; /* Don't force growth, but allow shrinking */
    background-color: white;
    overflow-y: auto;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-height: 0; /* Allow flexbox to shrink below content size */
    max-height: calc(100% - var(--button-size));
    position: relative;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

/* Sidebar Toggle Button (open button — only visible when sidebar is hidden) */
.sidebar-toggle-btn {
    position: absolute;
    top: 0;
    right: calc(-var(--button-size) - var(--spacing)); /* margin from panel + button width */
    width: var(--button-size);
    height: var(--button-size);
    background: white;
    border: 1px solid #ccc;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: background-color 0.2s, opacity 0.2s ease;
    user-select: none;
    padding: 0;
    z-index: 1001; /* Above sidebar content */
    box-sizing: content-box;
    opacity: 0;
    pointer-events: none;
}

.sidebar-toggle-btn:hover {
    background-color: #f5f5f5;
}

.sidebar-toggle-btn .control-icon {
    width: 20px;
    height: 20px;
    display: block;
    margin: auto;
    transition: transform 0.2s ease;
}

.sidebar-section {
    margin: 1.1rem;
    margin-bottom: 1.75rem;
}

.sidebar-section:last-of-type {
    margin-bottom: 1.1rem;
}

/* Prevent sidebar sections from flashing during initialization */
#route-info,
#elevation-profile-container,
#surface-info-container,
#options-container {
    opacity: 0;
    transition: opacity 0.2s ease-out 0.1s;
}

/* Show sections after initialization */
.sidebar.initialized #route-info,
.sidebar.initialized #elevation-profile-container,
.sidebar.initialized #surface-info-container,
.sidebar.initialized #options-container {
    opacity: 1;
}

#route-info-section {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.route-info-name {
    font-size: 18px;
    font-weight: 600;
    /* margin-bottom: 15px; */
}

.route-info-description {
    color: #555;
    white-space: pre-wrap;
}


.sidebar-section h3 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
    color: #444;
}

/* Search */
.search-container {
    position: relative;
    margin-top: 20px;
}

.search-container input {
    width: 100%;
    padding: 0.75rem 2.5rem 0.75rem 0.75rem; /* Add right padding for clear button */
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
}

.search-clear-btn {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.6;
}

.search-clear-btn .control-icon {
    width: 16px;
    height: 16px;
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    z-index: 1200;
    display: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.search-result {
    padding: 0.75rem;
    cursor: pointer;
    border-bottom: 1px solid #eee;
}

.search-result:hover {
    background-color: #f5f5f5;
}

.search-result:last-child {
    border-bottom: none;
}

.search-result-name {
    font-weight: 500;
    color: #333;
}

.search-result-address {
    color: #555;
    margin-top: 0.25rem;
}

/* Route Controls */
.route-controls {
    display: flex;
    gap: 0.75rem;
}

.route-controls label {
    font-weight: 500;
    color: #555;
}

.route-controls select {
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
}

/* Route Stats */
.route-stats {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 5px;
}

.stat {
    padding: 0.5rem;
    background-color: #f9f9f9;
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stat div {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stat-label {
    font-weight: 500;
    color: #555;
}

.stat-value {
    font-weight: 700;
    color: #151515;
}

.incl-ferries-line * {
    font-weight: normal;
    color: #878787;
}


/* Route Actions */
.route-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}


/* Buttons */
.btn {
    padding: 0.75rem 1rem;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
    text-align: center;
    text-decoration: none;
    display: inline-block;
}

.btn:disabled {
    opacity: 0.5;
    cursor: default;
    /* background-color: #aaa !important; */
}

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

.btn-primary:hover:not(:disabled) {
    background-color: #444;
}

.btn-secondary {
    background-color: #6c757d;
    color: white;
}

.btn-secondary:hover:not(:disabled) {
    background-color: #545b62;
}

#edit-imported-route-btn {
    background-color: #dc4a4a;
}

#edit-imported-route-btn:hover:not(:disabled) {
    background-color: #c43e3e;
}

.btn-secondary-icon {
    width: 45px;
    height: 45px;
    background: #f9f9f9;;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
    user-select: none;
    padding: 0;
    box-sizing: content-box;
}

.btn-secondary-icon:disabled {
    opacity: 0.3;
    background-color: unset;
}

.btn-secondary-icon:hover:not(:disabled) {
    background-color: #eee;
}

.btn-secondary-icon img {
    width: 24px;
    height: 24px;
}

.btn-danger {
    background-color: #ee0000;
    color: white;
}

.btn-danger:hover {
    background-color: #dc0000;
}

.btn-icon-sm {
    background: none;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.btn-icon-sm:hover {
    opacity: 1;
}

#gpx-buttons {
    display: flex;
    gap: 10px;
}

#gpx-buttons button {
    width: 100%;
}

/* Map Container */
.map-container {
    width: 100%;
    height: 100%;
    position: relative;
}

#map {
    height: 100%;
    width: 100%;
    cursor: crosshair;
    pointer-events: auto;
    position: relative;
    z-index: 1;
}


#map * {
    cursor: crosshair;
}

/* Map Controls */
.map-controls {
    position: absolute;
    top: var(--spacing);
    right: var(--spacing);
    bottom: var(--spacing);
    display: flex;
    flex-direction: column;
    align-items: end;
    gap: 5px;
    z-index: 400;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
    scrollbar-width: none;
}

/* Zoom button group */
.zoom-group {
    display: flex;
    flex-direction: column;
    border-radius: 10px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    border: 1px solid #ccc;
    background: white;
    height: fit-content;
    width: fit-content;
}

.map-control-btn {
    width: var(--button-size);
    height: var(--button-size);
    background: white;
    border: 1px solid #ccc;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: background-color 0.2s;
    user-select: none;
    padding: 0;
    box-sizing: content-box;
    flex-shrink: 0;
    pointer-events: all;
}

.map-control-btn.standalone {
    position: fixed;
    top: var(--spacing);
    right: var(--spacing);
}

/* Zoom buttons in group styling */
.zoom-group .map-control-btn {
    box-shadow: none;
    border: none;
    border-radius: 10px;
}

#menu-btn {
    z-index: 100;
}

/* Add larger gap after menu button */
.menu-btn-separator {
    margin-bottom: calc(var(--spacing) - 5px);
}

.control-icon {
    width: 20px;
    height: 20px;
    display: block;
    margin: auto;
}

.map-control-btn:hover {
    background-color: #f5f5f5;
}

.map-control-btn:disabled {
    opacity: 0.5;
    cursor: default;
    background-color: #f9f9f9;
}

.map-control-btn:disabled:hover {
    background-color: #f9f9f9;
}

.bottom-controls-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
}


/* Location road sign */

#location-label-container {
    position: fixed;
    width: calc(100% - var(--spacing) * 2);
    bottom: calc(var(--button-size) + var(--spacing) * 2);
    left: var(--spacing);
    z-index: 500;
    pointer-events: all;
    box-sizing: border-box;
    text-align: center;
}

#location-label {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: 10px;
    background: #ffe93b;
    border: 3px solid #e00419;
    border-radius: 10px;
    font-weight: 600;
    padding: 14px 12px;
    min-width: 160px;
}

#location-label-primary {
    font-size: 16px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#location-label-secondary {
    font-size: 14px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.location-label:not([hidden]) {
    display: flex;
}


/* Elevation Chart */
#elevation-chart {
    width: 100%;
    max-width: 100%;
    background: white;
    touch-action: pan-y; /* Let the browser handle vertical scrolling; we handle horizontal interaction */
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    justify-content: center;
    align-items: center;
    padding-bottom: 100px;
}

.modal-content {
    background-color: white;
    margin: 5% auto;
    padding: 2rem;
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-content.large {
    max-width: 800px;
}

.modal-content h3 {
    margin-bottom: 20px;
    font-size: 1.1rem;
}

.close {
    position: absolute;
    right: 1rem;
    top: 1rem;
    font-size: 1.5rem;
    cursor: pointer;
    color: #999;
}

.close:hover {
    color: #333;
}

/* Alert Panel */
.alert-panel {
    max-width: 460px;
}

.alert-panel h3 {
    margin: 0 0 0.75rem;
    font-size: 1.1rem;
}

.alert-panel p {
    margin: 0 0 1rem;
    line-height: 1.5;
}

.alert-panel-select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
    margin-bottom: 0;
    background-color: #f7f7f7;
}

.alert-panel-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 25px;
}

.alert-panel-btn-cancel {
    background: none;
    color: #555;
    border: 1px solid #ddd;
}

.alert-panel-btn-cancel:hover {
    background: #f5f5f5;
    border-color: #ccc;
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #555;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
}

.form-group textarea {
    resize: vertical;
    font-family: inherit;
}

/* Checkbox styling for form labels */
.form-group label input[type="checkbox"] {
    width: auto;
    margin: 0 0.5rem 0 0;
    padding: 0;
    vertical-align: middle;
}

.form-group label:has(input[type="checkbox"]) {
    display: flex;
    align-items: center;
    margin-bottom: 0.5rem;
    cursor: pointer;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: #2c5530;
    box-shadow: 0 0 0 2px rgba(44, 85, 48, 0.1);
}

.form-link {
    text-align: center;
    margin-top: 1rem;
    color: #555;
}

.form-link a {
    color: black;
}

/* Login Error Display */
.login-error {
    background-color: #fecaca;
    color: #dc2626;
    padding: 20px;
    border-radius: 0;
    font-weight: 500;
    text-align: left;
    border: none;
    font-size: 0.9rem;
}

/* Routes List */
.routes-list {
    display: grid;
    gap: 1rem;
}

.route-item {
    background: white;
    font-size: 1.2em;
    display: flex;
    gap: 25px;
    border-bottom: 1px solid #e1e1e1;
    padding-bottom: 20px;
}

.route-thumbnail {
    flex-shrink: 0;
    width: 150px;
    height: 150px;
    overflow: hidden;
}

.route-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: filter 0.2s ease;
}

.route-item-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.route-item-header {
    display: flex;
    justify-content: between;
    align-items: flex-start;
    margin-bottom: 0.5rem;
}

.route-item-title {
    font-weight: 600;
    color: #333;
    display: flex;
    justify-content: space-between;
    gap: 25px;
}

.route-item-title a {
    color: #000000;
    text-decoration: none;
    font-size: 1.4em;
}

.route-item-buttons {
    display: flex;
    gap: 20px;
}

.route-item-date {
    color: #555;
}

.route-badges-row img {
    transition: opacity 0.15s ease;
}

.route-badges-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    margin-top: 10px;
}

.route-badge {
    color: white;
    padding: 3px 8px;
    border-radius: 5px;
    display: inline-block;
    align-self: flex-start;
    font-size: 15px;
    font-weight: 500;
    cursor: default;
    user-select: none;
}

#route-gpx-badge {
    background-color: #6b9fd4;
}

#route-public-badge {
    background-color: #cc88c2;
}

.route-days-badge {
    background-color: #7eb87e;
}

.route-item-description {
    color: #555;
    white-space: pre-wrap;
}

.route-item-stats {
    display: flex;
    gap: 0.8rem;
    color: #555;
    margin-bottom: 5px;
}

.route-item-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 20px;
}

.route-item-actions .btn {
    padding: 0.5rem 1rem;
}


@media (max-width: 500px) {
    .route-item-title {
        flex-direction: column;
        gap: 20px;
    }
    .route-item-title a {
        font-size: 1.2em;
    }
    .route-item-buttons {
        gap: 30px;
    }
    .route-item-stats {
        font-size: 1em;
        gap: 0.5rem;
    }
}


/* Responsive Design */
@media (max-width: 768px) {
    /* .sidebar-container {
        left: -350px;
        transition: left 0.2s ease;
        z-index: 1500;
    }

    .sidebar-container.open {
        left: 20px;
    }

    .instruction-panel {
        border-radius: 0 10px 10px 0;
    }

    .sidebar {
        border-radius: 0 10px 10px 0;
    } */

    /* Make thumbnail smaller on mobile */
    .route-thumbnail {
        width: 100px;
        height: 100px;
    }

    .modal-content {
        margin: 10% auto;
        width: 95%;
        padding: 1rem;
    }
}

/* Loading States */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.spinner {
    border: 2px solid #f3f3f3;
    border-top: 2px solid #2c5530;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
    display: inline-block;
    margin-right: 0.5rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Surface Information Styles */
.surface-breakdown {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.surface-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem;
    background-color: #f8f9fa;
    border-radius: 4px;
    border: 2px solid transparent;
    border-left: 3px solid #c2c2c2;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.surface-item:hover {
    background-color: #e9ecef;
}

.surface-item.selected {
    border-color: #808080 !important;
}

.surface-item.steps {
    background-color: #ffe0e0;
    border-left-color: #e74c3c;
}

.surface-item.ferry {
    background-color: #e0f4ff;
    border-left-color: #86d2eb;
}

.surface-item.dismount {
    background-color: #fff3cd;
    border-left-color: #f0ad4e;
    padding: 0;
    flex-direction: column;
    align-items: stretch;
}

.dismount-header {
    display: flex;
    align-items: center;
    padding: 8px 10px;
}

.dismount-header .surface-info {
    flex: 1;
}

.dismount-chevron {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    opacity: 0.6;
    transition: transform 0.2s;
}

.surface-item.dismount.expanded .dismount-chevron {
    transform: rotate(180deg);
}

.dismount-sections {
    display: none;
    border-top: 1px solid #f0ad4e;
}

.dismount-section-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px 6px 16px;
    cursor: pointer;
    font-size: 0.9rem;
}

.dismount-section-item:hover {
    background-color: #ffe8a1;
}

.dismount-section-item.selected {
    background-color: #ffd970;
}

.dismount-section-distance {
    color: #555;
    font-size: 0.8rem;
}

.surface-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.surface-name {
    font-weight: 500;
    text-transform: capitalize;
}

.surface-distance {
    font-size: 0.8rem;
    color: #555;
}

.surface-percentage {
    font-size: 0.9rem;
    font-weight: 500;
}

/* Options Section */
.options-controls {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.option-item {
    display: flex;
    flex-direction: column;
}

.option-item label {
    gap: 0.5rem;
    font-weight: 500;
    color: #555;
    user-select: none;
}

.option-item input[type="checkbox"] {
    margin: 0;
}

/* Average speed input styling */
.option-item #average-speed-input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
    margin-top: 0.5rem;
}

.option-item #average-speed-input:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

/* Update average speed option item to be full width */
.option-item:has(#average-speed-input) {
    flex-direction: column;
    align-items: flex-start;
}

.option-item:has(#average-speed-input) label {
    margin-bottom: 0;
}

.map-option {
    padding-bottom: 12px;
}

.map-option label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-weight: 400;
    color: #333;
    user-select: none;
}

.map-option input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
}

.map-option span {
    flex: 1;
}

.map-option-template {
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 0.5rem;
    row-gap: 0.5rem;
    margin-top: 10px;
    align-items: center;
}

.map-option-template input[type="checkbox"] {
    grid-column: 1;
    grid-row: 1;
    align-self: center;
    cursor: pointer;
    margin: 0;
}

.map-option-template-header {
    grid-column: 2;
    grid-row: 1;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.map-option-template-header label {
    cursor: pointer;
    font-weight: 400;
    color: #333;
    user-select: none;
}

.template-route-help-text,
#template-route-select {
    grid-column: 2;
}

.template-route-help-btn {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    opacity: 0.5;
    flex-shrink: 0;
}

.template-route-help-btn:hover {
    opacity: 0.8;
}

.template-route-help-icon {
    width: 16px;
    height: 16px;
}

.template-route-help-text {
    color: #555;
    line-height: 1.4;
    border-radius: 0 4px 4px 0;
    font-style: italic;
    margin-bottom: 4px;
}

#template-route-select {
    display: none;
}

#template-route-select.visible {
    display: block;
    min-width: 0;
    font-size: 14px;
    padding: 8px 10px;
    border: 1px solid #ccc;
    border-radius: 6px;
    background: white;
    color: #333;
    cursor: pointer;
    margin-top: 2px;
}

#template-route-select:has(option[disabled]:checked) {
    color: #999;
}

/* Waypoint Surface Popover */
.waypoint-popover {
    position: absolute;
    background: white;
    border: 1px solid #ddd;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    padding: 12px;
    z-index: 900; /* below sidebar and legend panel */
    font-size: 14px;
    width: 185px;
    pointer-events: auto;
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.waypoint-popover.visible {
    opacity: 1;
    transform: translateY(0);
}

.waypoint-popover::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -8px;
    border: 8px solid transparent;
    border-top-color: white;
}

.waypoint-popover::before {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -9px;
    border: 9px solid transparent;
    border-top-color: #ddd;
}

.waypoint-popover.popover-below::after {
    top: auto;
    bottom: 100%;
    border-top-color: transparent;
    border-bottom-color: white;
}

.waypoint-popover.popover-below::before {
    top: auto;
    bottom: 100%;
    border-top-color: transparent;
    border-bottom-color: #ddd;
}

.waypoint-number-title {
    font-weight: 600;
    margin-bottom: 4px;
}

.search-popover-name {
    font-weight: 500;
    color: #333;
    margin-bottom: 4px;
}

.search-popover-address {
    color: #555;
    margin-bottom: 18px;
}

.waypoint-location-name {
    color: #666;
    margin-top: 8px;
    margin-bottom: 14px;
    min-height: 0;
}

.popover-title {
    font-weight: 600;
    color: #2c5530;
    margin-bottom: 8px;
    font-size: 13px;
}

.surface-toggle-group {
    display: flex;
    border: 1px solid #ddd;
    border-radius: 6px;
    overflow: hidden;
    background: #f8f9fa;
    margin-bottom: 10px;
}

.surface-toggle-btn {
    flex: 1;
    padding: 8px 12px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
    color: #555;
}

.surface-toggle-btn:hover {
    background: rgba(44, 85, 48, 0.1);
}

.surface-toggle-btn.active {
    background: #202020;
    color: white;
}

.surface-ferry-label {
    width: 100%;
    padding: 8px 12px;
    text-align: center;
    color: #555;
    user-select: none;
}

.waypoint-action-buttons {
    display: flex;
    gap: 7px;
    margin-top: 12px;
}

.waypoint-action-buttons button:disabled {
    opacity: 0.25;
}

.waypoint-action-buttons button:disabled:hover {
    filter: none;
}

.search-location-buttons {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.search-location-buttons .surface-toggle-btn {
    width: 100%;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: #f8f9fa;
}

.search-location-buttons .surface-toggle-btn:hover {
    background: rgba(44, 85, 48, 0.1);
}

.search-location-buttons .surface-toggle-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.search-location-buttons .surface-toggle-btn:disabled:hover {
    background: #f8f9fa;
}

#search-finish-btn.hidden,
#search-start-btn.hidden {
    display: none;
}

#search-cancel-btn {
    border: none;
    background: none;
    color: #555;
    padding: 4px 0;
    margin-top: 2px;
    text-decoration: none;
    cursor: pointer;
}

#search-cancel-btn:hover {
    background: none;
    color: #333;
}

.waypoint-action-btn {
    padding: 6px;
    border: none;
    background: none;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.waypoint-action-btn:hover {
    opacity: 0.7;
}

.waypoint-delete-btn:hover {
    filter: invert(23%) sepia(77%) saturate(3427%) hue-rotate(344deg) brightness(93%) contrast(85%);
}

.waypoint-streetview-btn:hover {
    filter: invert(42%) sepia(93%) saturate(5000%) hue-rotate(194deg) brightness(101%) contrast(101%);
}

.waypoint-notes-btn:hover {
    filter: invert(27%) sepia(27%) saturate(1697%) hue-rotate(92deg) brightness(95%) contrast(89%);
}

.waypoint-split-btn:hover,
.waypoint-split-btn.active {
    filter: invert(42%) sepia(93%) saturate(1352%) hue-rotate(453deg) brightness(82%) contrast(101%);
}

.day-breakdown {
    display: grid;
    grid-template-columns: 1fr auto auto auto;
    row-gap: 0.5rem;
}

.day-item {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: subgrid;
    column-gap: 0.35rem;
    padding: 0.5rem;
    background-color: #f8f9fa;
    border-radius: 4px;
    border: 2px solid transparent;
    border-left: 3px solid #b0c4de;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.day-item:hover {
    background-color: #e9ecef;
}

.day-item.selected {
    border-color: #808080 !important;
}

.day-item-distance,
.day-item-elevation {
    color: #151515;
    text-align: right;
}

.day-item-distance {
    font-weight: 700;
}

.day-item-stats-separator {
    color: #cfcfcf;
}

.waypoint-loop-btn {
    background-color: #9b59b6;
    color: #fff;
    width: 100%;
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    margin-top: 4px;
    font-weight: 500;
}

.waypoint-action-btn img {
    width: 22px;
    height: 22px;
}

.waypoint-comment-container {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e0e0e0;
}

.waypoint-comment-input {
    width: 100%;
    min-height: 60px;
    padding: 6px 8px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.25em;
    resize: none;
    box-sizing: border-box;
}

.waypoint-comment-save-btn {
    width: 100%;
    padding: 8px 12px;
    background: #2c5530;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease;
}

.waypoint-comment-save-btn:hover {
    background: #234427;
}

.waypoint-coords {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e0e0e0;
    font-size: 12px;
    color: #666;
    text-align: center;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}

/* Routes Page Styles */

.routes-main {
    margin-top: 50px;
}

.routes-page-container {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    padding: var(--spacing);
    padding-left: 40px;
    padding-right: 40px;
    min-height: calc(100vh - 80px);
}

@media (max-width: 500px) {
    .routes-page-container {
        padding: var(--spacing);
    }
}

.routes-page-header {
    text-align: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
}

.routes-page-header h1 {
    font-size: 2.5rem;
    color: #444;
    margin-bottom: 0.5rem;
}

.routes-page-header p {
    color: #555;
    font-size: 1.1rem;
}

.routes-filter-container {
    margin-bottom: 2rem;
    position: relative;
}

@media (max-width: 500px) {
    .routes-page-header {
        margin-bottom: 1rem;
    }
    .routes-filter-container {
        margin-bottom: 2rem;
    }
}

.routes-filter-container input {
    width: 100%;
    padding: 0.75rem 2.5rem 0.75rem 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
}

.routes-filter-clear-btn {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.6;
}

.routes-filter-clear-btn .control-icon {
    width: 16px;
    height: 16px;
}

.routes-sort-container {
    display: flex;
    align-items: center;
    justify-content: end;
    gap: 0.5rem;
    margin-bottom: 3rem;
    font-size: 0.9rem;
    color: #555;
}

.routes-sort-container select {
    padding: 0.35rem 0.6rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
    background: #fff;
    cursor: pointer;
}

@media (max-width: 500px) {
    .routes-sort-container {
        margin-bottom: 2rem;
    }
}


/* Override body overflow for routes page */
body.routes-page {
    overflow: auto;
}

/* Adjust routes list for full page layout */
.routes-page-container .routes-list {
    width: 100%;
    max-width: none;
}

/* Profile Page Styles */

.profile-main {
    margin-top: 50px;
}

.profile-page-container {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    padding: var(--spacing);
    padding-left: 40px;
    padding-right: 40px;
    min-height: calc(100vh - 80px);
}

.profile-page-header {
    text-align: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
}

.profile-page-header h1 {
    font-size: 2.5rem;
    color: #444;
    margin-bottom: 0.5rem;
}

.profile-page-header p {
    color: #555;
    font-size: 1.1rem;
}

/* Override body overflow for profile page */
body.profile-page {
    overflow: auto;
}

.profile-content {
    display: grid;
    gap: 2rem;
}

.profile-section {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    border: 1px solid #eee;
}

.profile-info {
    display: grid;
    gap: 1rem;
}

.profile-field {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid #f5f5f5;
    font-size: 16px;
}

.profile-field:last-child {
    border-bottom: none;
}

.profile-field label {
    font-weight: 600;
    color: #333;
    min-width: 120px;
}

.profile-value {
    color: #555;
    text-align: right;
}

.profile-role {
    background: #000;
    color: white;
    padding: 0.4rem 0.75rem;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 500;
}

.profile-stats {
    display: grid;
    gap: 1rem;
}

.coming-soon {
    color: #555;
    font-style: italic;
    text-align: center;
    padding: 2rem;
    background: #f8f9fa;
    border-radius: 6px;
    margin: 0;
}

/* Responsive adjustments for profile page */
@media (max-width: 768px) {
    .profile-page-container {
        padding: 1rem;
    }

    .profile-field {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }

    .profile-field label {
        min-width: auto;
    }

    .profile-value {
        text-align: left;
    }
}

/* Help Panel */

.help-main {
    margin-top: 50px;
}

.help-panel {
    position: fixed;
    top: var(--spacing);
    right: calc(var(--button-size) + var(--spacing) * 2); /* Leave space for map controls (2 * margin + button size) */
    width: 350px;
    max-width: calc(100% - var(--button-size) - 3 * var(--spacing));
    max-height: calc(100dvh - var(--button-size));
    background-color: white;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    overflow: hidden;
    transform: translateX(100%);
    opacity: 0;
    transition: transform 0.2s ease, opacity 0.2s ease;
    display: none; /* Start hidden */
    flex-direction: column;
    user-select: none;
    -webkit-user-select: none;
}

.help-panel.show {
    transform: translateX(0);
    opacity: 1;
}

.help-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid #eee;
    background-color: #f8f9fa;
}

.help-panel-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: #444;
}

.close-panel-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #555;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

.close-panel-btn:hover {
    background-color: #f0f0f0;
    color: #333;
}

.help-panel-body {
    padding: 25px;
    flex: 1;
    overflow-y: scroll;
}

/* Webkit scrollbar styling for better appearance */
.help-panel-body::-webkit-scrollbar {
    width: 6px;
}

.help-panel-body::-webkit-scrollbar-track {
    background: #f5f5f5;
    border-radius: 3px;
}

.help-panel-body::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.help-panel-body::-webkit-scrollbar-thumb:hover {
    background: #999;
}

.help-panel-body p {
    margin: 0;
    line-height: 1.5;
    color: #333;
}

/* Responsive adjustments for help panel */
@media (max-width: 768px) {
    .help-panel {
        z-index: 1500;
        transform: translateX(100%); /* Start off-screen (right) */
    }

    .help-panel.show {
        transform: translateX(0); /* Slide in from right */
    }
}

/* Menu Panel */
.menu-panel {
    position: fixed;
    top: var(--spacing);
    right: calc(var(--button-size) + var(--spacing) * 2); /* Leave space for map controls (2 * margin + button size) */
    background-color: white;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    overflow: hidden;
    transform: translateX(100%);
    opacity: 0;
    transition: transform 0.2s ease, opacity 0.2s ease;
    display: none; /* Start hidden */
    user-select: none;
    -webkit-user-select: none;
}

.menu-panel.show {
    transform: translateX(0);
    opacity: 1;
}

.menu-panel-content {
    display: flex;
    flex-direction: column;
}

.menu-panel-btn {
    padding: 15px;
    padding-left: 20px;
    padding-right: 25px;
    border: none;
    color: black;
    background-color: white;
    cursor: pointer;
    text-align: left;
    font-size: 15px;
    text-decoration: none; /* in case it's a link */
    border-bottom: 1px solid #eee;
    transition: background-color 0.2s ease;
}

.menu-panel-btn:disabled {
    color: #adadad;
}

.menu-panel-link {
    display: block;
    text-decoration: none;
    color: inherit;
}

.menu-panel-btn:last-child {
    border-bottom: none;
}

.menu-panel-btn:hover {
    background-color: #f8f9fa;
}

#crowbar-cycles-menu-link {
    color: #126e8a;
}

#menu-profile-btn.not-logged-in {
    position: relative;
}

#menu-profile-btn.not-logged-in::after {
    content: '';
    position: absolute;
    top: 50%;
    right: 14px;
    transform: translateY(-50%);
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #ee7272;
}

/* Responsive adjustments for menu panel */
@media (max-width: 768px) {
    .menu-panel {
        z-index: 1500;
        transform: translateX(100%); /* Start off-screen (right) */
    }

    .menu-panel.show {
        transform: translateX(0); /* Slide in from right */
    }
}


/* HELP PAGE */

.help-section {
    font-size: 16px;
}

.help-section p {
    margin-top: 20px;
    margin-bottom: 20px;
    line-height: 1.5;
}

.help-section li {
    list-style-position: inside;
    list-style-type: square;
    padding-left: 12px;
    padding-top: 12px;
}

/* Campsite info popup - styled to match the waypoint popovers */
.campsite-popup-wrapper .maplibregl-popup-content {
    background: white;
    border: 1px solid #ddd;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    padding: 12px;
    font-size: 14px;
    width: 185px;
}

.campsite-popup-wrapper .maplibregl-popup-tip {
    border-top-color: white;
    border-bottom-color: white;
}

.campsite-popup {
    line-height: 1.4;
}

.campsite-popup-name {
    font-weight: 600;
    margin-bottom: 15px;
    color: #333;
}

.campsite-popup-link {
    display: block;
    text-align: center;
    text-decoration: none;
}