/**
 * Wadjemup Rottnest Bathymetry Visualization
 * Styles for the interactive depth map
 */

/* ============================================
   Reset & Base
   ============================================ */

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

body {
    font-family: 'JetBrains Mono', monospace;
    background: #f5f5f0;
    color: #1a1a1a;
    overflow: hidden;
}

/* ============================================
   Map Container
   ============================================ */

#map {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: calc(100% - 280px);
}

/* ============================================
   Overlay System
   ============================================ */

.overlay {
    position: absolute;
    z-index: 100;
    pointer-events: none;
}

/* ============================================
   Back Link
   ============================================ */

.back-link {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 101;
    font-size: 0.75rem;
    color: rgba(0, 0, 0, 0.5);
    text-decoration: none;
    transition: color 0.2s ease;
}

.back-link:hover {
    color: #2563eb;
}

/* ============================================
   Header & Title Card
   ============================================ */

.header {
    top: 50px;
    left: 20px;
    right: 20px;
    z-index: 600;
    /* Above POIs (500) */
}

.title-card {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    padding: 20px 24px;
    display: inline-block;
    pointer-events: auto;
}

.title-card h1 {
    font-family: 'Instrument Serif', serif;
    font-size: 1.8rem;
    font-weight: 400;
    margin-bottom: 4px;
    color: #1e40af;
}

.title-card .subtitle {
    font-size: 0.75rem;
    color: rgba(0, 0, 0, 0.5);
    font-weight: 300;
}

.methods-link {
    display: inline-block;
    margin-top: 8px;
    font-size: 0.65rem;
    color: rgba(0, 0, 0, 0.4);
    text-decoration: none;
    transition: color 0.2s ease;
}

.methods-link:hover {
    color: #1e40af;
}

/* ============================================
   Location Button
   ============================================ */

.location-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 601;
    /* Above POIs and header */
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(0, 0, 0, 0.6);
    transition: all 0.2s ease;
}

.location-btn:hover {
    background: rgba(255, 255, 255, 1);
    color: #1e40af;
}

.location-btn.active {
    color: #1e40af;
    border-color: rgba(30, 64, 175, 0.3);
}

/* Lock Zoom Button */
.lock-zoom-btn {
    position: absolute;
    top: 64px;
    right: 20px;
    z-index: 601;
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(0, 0, 0, 0.6);
    transition: all 0.2s ease;
}

.lock-zoom-btn:hover {
    background: rgba(255, 255, 255, 1);
    color: #1e40af;
}

.lock-zoom-btn.active {
    color: #1e40af;
    border-color: rgba(30, 64, 175, 0.3);
    background: rgba(30, 64, 175, 0.1);
}

/* User location marker */
.user-location-marker {
    position: relative;
    width: 24px;
    height: 24px;
}

.location-dot {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 16px;
    height: 16px;
    background: #1e40af;
    border: 3px solid white;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

/* Viewing cone indicator (Google Maps style) */
.location-heading {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 60px;
    height: 60px;
    background: conic-gradient(from -30deg,
            transparent 0deg,
            rgba(30, 64, 175, 0.25) 0deg,
            rgba(30, 64, 175, 0.15) 30deg,
            rgba(30, 64, 175, 0.25) 60deg,
            transparent 60deg);
    border-radius: 50%;
    transform-origin: center center;
    transform: translate(-50%, -50%) rotate(-90deg);
    display: none;
    pointer-events: none;
}

/* ============================================
   Legend
   ============================================ */

.legend {
    bottom: 300px;
    /* Above the 280px shelf */
    left: 20px;
    z-index: 3000;
    /* Ensure above POIs (500) */
}

.legend-card {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    padding: 16px 20px;
    pointer-events: auto;
}

.legend-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgba(0, 0, 0, 0.5);
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    margin-bottom: 10px;
}

.legend-bar {
    width: 200px;
    height: 16px;
    border-radius: 4px;
    margin-bottom: 6px;
}

.legend-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    color: rgba(0, 0, 0, 0.7);
}

/* ============================================
   Cursor Depth (in Legend)
   ============================================ */

.cursor-depth-row {
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.cursor-depth-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: rgba(0, 0, 0, 0.5);
}

.cursor-depth-value {
    font-size: 1.4rem;
    font-weight: 300;
    background: linear-gradient(135deg, #1e40af, #047857);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.cursor-depth-unit {
    font-size: 0.75rem;
    color: rgba(0, 0, 0, 0.5);
}

.cursor-coords {
    font-size: 0.6rem;
    color: rgba(0, 0, 0, 0.45);
    margin-top: 4px;
    font-variant-numeric: tabular-nums;
}

/* ============================================
   Click Marker
   ============================================ */

.click-marker {
    width: 14px;
    height: 14px;
    background: #1e40af;
    border: 3px solid white;
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 1000;
}

.click-marker:active {
    transform: scale(0.9);
}

/* Waypoint Markers with Labels */
.wp-marker {
    width: 14px;
    height: 14px;
    background: #dc2626;
    border: 3px solid white;
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
    cursor: grab;
    z-index: 1000;
}

.wp-marker:active {
    cursor: grabbing;
}

.wp-marker::before {
    content: attr(data-label);
    position: absolute;
    top: -16px;
    left: 50%;
    transform: translateX(-50%);
    color: #dc2626;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.6rem;
    font-weight: 600;
    white-space: nowrap;
    pointer-events: none;
}

/* Mid-line Insertion Button */
.midpoint-marker {
    cursor: pointer;
    color: rgba(255, 255, 255, 0.6);
    font-size: 20px;
    font-weight: bold;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    transition: color 0.15s, transform 0.15s;
    user-select: none;
    z-index: 2000;
}

.midpoint-marker:hover {
    color: rgba(255, 255, 255, 0.9);
    transform: scale(1.3);
}

/* POI markers */
.poi-marker {
    pointer-events: none;
    z-index: 500;
}

.poi-label {
    font-family: 'Instrument Serif', serif;
    font-style: italic;
    font-size: 0.85rem;
    color: rgba(30, 64, 175, 0.7);
    white-space: nowrap;
    text-shadow:
        0 0 4px rgba(255, 255, 255, 0.9),
        0 0 8px rgba(255, 255, 255, 0.6);
}

/* ============================================
   MapLibre Popup Styles
   ============================================ */

.maplibregl-popup {
    z-index: 1000 !important;
}

.maplibregl-popup-content {
    background: #ffffff !important;
    border-radius: 8px !important;
    padding: 12px 16px !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2) !important;
    font-family: 'JetBrains Mono', monospace;
}

.maplibregl-popup-close-button {
    font-size: 16px;
    color: rgba(0, 0, 0, 0.4);
    padding: 4px 8px;
}

.popup-depth {
    font-size: 1.3rem;
    font-weight: 300;
    background: linear-gradient(135deg, #1e40af, #047857);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.popup-unit {
    font-size: 0.8rem;
}

.popup-coords {
    font-size: 0.7rem;
    color: #1e40af;
    margin-top: 4px;
    font-variant-numeric: tabular-nums;
}

.popup-coords-dm {
    font-size: 0.6rem;
    color: rgba(0, 0, 0, 0.5);
    margin-top: 2px;
}

.popup-share-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    padding: 6px 12px;
    background: rgba(30, 64, 175, 0.1);
    border: 1px solid rgba(30, 64, 175, 0.2);
    border-radius: 6px;
    color: #1e40af;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.popup-share-btn:hover {
    background: rgba(30, 64, 175, 0.2);
}

.popup-share-btn svg {
    flex-shrink: 0;
}

/* ============================================
   Copyable Elements
   ============================================ */

.copyable {
    cursor: pointer;
    user-select: all;
    transition: background 0.2s ease;
    padding: 1px 4px;
    margin: -1px -4px;
    border-radius: 3px;
}

.copyable:hover {
    background: rgba(30, 64, 175, 0.1);
}

/* ============================================
   Loading Status (Floating Text)
   ============================================ */

.loading-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    /* No background/box */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.5s ease;
    pointer-events: none;
}

.loading-overlay.hidden {
    opacity: 0;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(30, 64, 175, 0.2);
    border-top-color: #1e40af;
    border-radius: 50%;
    animation: spin 1s cubic-bezier(0.55, 0.055, 0.675, 0.19) infinite;
    margin-bottom: 16px;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}

.loading-text {
    font-family: 'Instrument Serif', serif;
    font-style: italic;
    font-size: 1.5rem;
    font-weight: 400;
    color: #1e40af;
    text-shadow:
        0 0 20px rgba(255, 255, 255, 0.9),
        0 0 10px rgba(255, 255, 255, 0.8);
    white-space: nowrap;
    letter-spacing: 0.02em;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ============================================
   Mobile Responsive & Info Toggle
   ============================================ */

.info-btn {
    display: none;
    /* Hidden by default (Desktop) */
    position: absolute;
    top: 66px;
    /* Below location button */
    right: 20px;
    width: 36px;
    height: 36px;
    z-index: 101;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    color: #1e40af;
    font-family: 'Instrument Serif', serif;
    font-style: italic;
    font-size: 1.2rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

@media (max-width: 768px) {

    /* Hide the info button - not needed */
    .info-btn {
        display: none;
    }

    /* Force MapLibre attribution to always be collapsed on mobile */
    .maplibregl-ctrl-attrib.maplibregl-compact {
        display: block;
    }

    .maplibregl-ctrl-attrib.maplibregl-compact::after {
        content: '';
        display: block;
    }

    .maplibregl-ctrl-attrib-inner {
        display: none;
    }

    .maplibregl-ctrl-attrib.maplibregl-compact-show .maplibregl-ctrl-attrib-inner {
        display: block;
    }

    /* Mobile Typography Adjustments */
    .title-card h1 {
        font-size: 1.2rem;
    }

    .title-card {
        padding: 14px 18px;
    }

    /* Hide "At cursor" section on mobile (users tap instead of hover) */
    .cursor-depth {
        display: none;
    }

    /* Remove the border separator since cursor section is hidden */
    .legend-title {
        margin-top: 0;
        padding-top: 0;
        border-top: none;
    }

    .legend-card {
        padding: 12px 16px;
    }

    .legend-bar {
        width: 150px;
    }
}

/* ============================================
   MapLibre Attribution - Force Compact
   ============================================ */

/* Force attribution to always be in compact mode */
.maplibregl-ctrl-attrib {
    display: none !important;
}

.maplibregl-ctrl-attrib.maplibregl-compact {
    display: block !important;
    min-height: 20px;
    background-color: rgba(255, 255, 255, 0.5);
    border-radius: 12px;
}

.maplibregl-ctrl-attrib-button {
    display: block !important;
}

/* Hide the inner text by default */
.maplibregl-ctrl-attrib:not(.maplibregl-compact-show) .maplibregl-ctrl-attrib-inner {
    display: none;
}

/* ============================================
   Context Menu (Right Click)
   ============================================ */

.context-menu {
    position: absolute;
    z-index: 2000;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    padding: 6px 0;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    min-width: 180px;
    font-size: 0.8rem;
    color: #1a1a1a;
    pointer-events: auto;
}

.context-menu-item {
    padding: 8px 16px;
    cursor: pointer;
    transition: background 0.2s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.context-menu-item:hover {
    background: rgba(30, 64, 175, 0.1);
    color: #1e40af;
}

.context-menu-separator {
    height: 1px;
    background: rgba(0, 0, 0, 0.1);
    margin: 4px 0;
}

/* ============================================
   Route Profiler UI
   ============================================ */

/* Draw Button */
.draw-btn {
    position: absolute;
    bottom: 200px;
    /* Above shelf */
    right: 20px;
    z-index: 601;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: #1e40af;
    color: white;
    border: none;
    border-radius: 24px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(30, 64, 175, 0.3);
    font-family: 'Instrument Serif', serif;
    font-size: 1.1rem;
    font-style: italic;
    transition: all 0.2s ease;
}

.draw-btn:hover {
    background: #172554;
    transform: translateY(-2px);
}

.draw-btn.active {
    background: #dc2626;
    /* Red for 'Cancel/Stop' */
}

/* Swap Button (Table) */
.swap-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: transparent;
    border: 1px solid rgba(30, 64, 175, 0.4);
    border-radius: 12px;
    color: #1e40af;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.65rem;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.swap-btn:hover {
    background: rgba(30, 64, 175, 0.1);
    border-color: #1e40af;
    transform: translateY(-1px);
}

.swap-btn svg {
    width: 10px;
    height: 10px;
    flex-shrink: 0;
}

/* Bottom Shelf (Dashboard Style) */
.shelf {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 280px;
    /* Fixed height for chart */
    background: #ffffff;
    /* Solid white dashboard */
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
    z-index: 1500;
    /* Above waypoint markers (1000) */
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.shelf.collapsed {
    transform: translateY(100%);
}

.shelf-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    background: #f8fafc;
}

.shelf-header h3 {
    font-family: 'Instrument Serif', serif;
    font-size: 1.3rem;
    font-weight: 400;
    color: #1e40af;
    margin: 0;
}

.shelf-title {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.shelf-subtitle {
    font-size: 0.7rem;
    color: rgba(0, 0, 0, 0.5);
}

.shelf-subtitle a {
    color: #1e40af;
    text-decoration: none;
}

.shelf-subtitle a:hover {
    text-decoration: underline;
}

.shelf-controls {
    display: flex;
    align-items: center;
    gap: 16px;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: rgba(0, 0, 0, 0.6);
}

.control-group label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
}

.control-group input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: #1e40af;
}

.control-group input {
    width: 60px;
    padding: 4px 8px;
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
}

.control-group select {
    padding: 4px 8px;
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    background: white;
}

.speed-desc {
    font-size: 0.7rem;
    color: #94a3b8;
    font-style: italic;
    width: 85px;
    text-align: right;
    margin-right: 8px;
}

/* Desktop: show full 'Speed', hide 'Sp.' */
.speed-full {
    display: inline;
}

.speed-short {
    display: none;
}

.shelf-close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    color: rgba(0, 0, 0, 0.5);
    cursor: pointer;
    padding: 4px;
    transition: color 0.2s;
}

.shelf-close-btn:hover {
    color: #dc2626;
}

.chart-container {
    flex: 1;
    position: relative;
    padding: 16px 24px;
    min-height: 0;
    /* Important for Chart.js flex container */
}

.chart-dist-unit {
    position: absolute;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    color: #666;
}

.chart-dist-unit select {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    background: rgba(30, 64, 175, 0.1);
    border: 1px solid rgba(30, 64, 175, 0.25);
    border-radius: 4px;
    padding: 3px 8px;
    color: #1e40af;
    cursor: pointer;
    font-weight: 500;
}

.chart-dist-unit select:hover {
    background: rgba(30, 64, 175, 0.2);
}

.chart-dist-unit::before {
    content: 'Distance:';
}

/* ============================================
   Tab Navigation (Mobile)
   ============================================ */

.shelf-tabs {
    display: none;
    /* Hidden on desktop */
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    background: #f8fafc;
}

.shelf-tab {
    flex: 1;
    padding: 14px 20px;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    font-weight: 500;
    color: rgba(0, 0, 0, 0.5);
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 44px;
    /* Touch-friendly */
}

.shelf-tab.active {
    color: #1e40af;
    border-bottom-color: #1e40af;
    background: rgba(30, 64, 175, 0.05);
}

.shelf-tab-panel {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.shelf-tab-panel.active {
    opacity: 1;
    pointer-events: auto;
    position: relative;
}

/* Hide inactive panels on mobile */
@media (max-width: 768px) {
    .shelf-tab-panel:not(.active) {
        display: none;
    }
}

.planner-mobile-content {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* Desktop: ensure button text is visible, hide icons */
.btn-text {
    display: inline;
}

.shelf-btn svg,
.share-btn svg {
    display: none;
}


@media (max-width: 768px) {

    /* Show tab navigation on mobile */
    .shelf-tabs {
        display: flex;
    }

    /* Hide desktop sidebar on mobile */
    .waypoint-sidebar {
        display: none !important;
    }

    /* Map takes more space on mobile */
    #map {
        height: calc(100% - 400px);
        /* Account for taller shelf */
    }

    /* Shelf adjustments for mobile */
    .shelf {
        height: 400px;
        /* Taller for better content area */
    }

    .shelf-header {
        padding: 8px 10px;
        flex-wrap: wrap;
        gap: 6px;
    }

    .shelf-title h3 {
        font-size: 0.95rem;
    }

    .shelf-subtitle {
        font-size: 0.6rem;
    }

    .shelf-controls {
        flex-wrap: wrap;
        gap: 6px;
    }

    .control-group {
        font-size: 0.7rem;
    }

    .control-group label {
        white-space: nowrap;
        /* Keep on one line */
        font-size: 0.7rem;
    }

    .control-group input,
    .control-group select {
        font-size: 0.8rem;
        padding: 3px 6px;
    }

    /* Smaller speed input on mobile */
    #speed-input {
        width: 50px;
        /* Slightly wider for better usability */
    }

    /* Hide 'Assist' text on mobile */
    .assist-text {
        display: none;
    }

    /* Abbreviated speed label on mobile */
    .speed-full {
        display: none !important;
    }

    .speed-short {
        display: inline !important;
    }

    /* Icon-only square buttons on mobile */
    .shelf-btn,
    .finish-btn {
        min-height: 32px;
        width: 32px;
        padding: 6px;
        font-size: 0.7rem;
        margin-left: 0 !important;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .shelf-btn .btn-text,
    .share-btn .btn-text {
        display: none;
        /* Hide text on mobile, show icon only */
    }

    .shelf-btn svg {
        display: inline-block;
        /* Show icon on mobile */
        width: 14px;
        height: 14px;
        margin: 0;
    }

    .share-btn {
        min-height: 32px;
        width: 32px;
        padding: 6px;
        font-size: 0.7rem;
        gap: 0;
        margin-left: 0 !important;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .share-btn svg {
        display: inline-block;
        /* Show icon on mobile */
        width: 14px;
        height: 14px;
        margin: 0;
    }

    .start-btn {
        min-height: 44px;
        padding: 14px 28px;
        font-size: 1.2rem;
    }

    /* Chart in mobile */
    .chart-container {
        padding: 8px;
        padding-bottom: 32px;
        /* Space for distance unit */
        display: flex;
        flex-direction: column;
    }

    /* Distance unit positioning on mobile */
    .chart-dist-unit {
        bottom: 8px;
        /* Closer to bottom on mobile */
        font-size: 0.65rem;
    }

    .chart-dist-unit select {
        font-size: 0.7rem;
        padding: 2px 6px;
    }

    /* Loading overlay centered on visible map area */
    .loading-overlay {
        top: calc((100% - 400px) / 2);
        /* Center vertically in map area */
        transform: translate(-50%, -50%);
    }

    /* Legend positioning and sizing on mobile */
    .legend {
        bottom: 425px;
        /* Above taller shelf */
        left: 8px;
    }

    .legend-card {
        padding: 4px 8px;
        /* Minimal padding */
        background: rgba(255, 255, 255, 0.85);
        /* Slightly more transparent */
    }

    .legend-title {
        display: none;
        /* Hide "Depth Scale" label on mobile */
    }

    .legend-bar {
        width: 70px;
        /* Tiny bar */
        height: 8px;
        /* Very thin */
        margin-bottom: 2px;
    }

    .legend-labels {
        font-size: 0.55rem;
        /* Tiny text */
    }

    /* Location button positioning */
    .location-btn {
        top: 12px;
        right: 12px;
        width: 40px;
        height: 40px;
    }

    /* Lock zoom button positioning */
    .lock-zoom-btn {
        top: 60px;
        right: 12px;
        width: 40px;
        height: 40px;
    }

    /* Very compact speed description on mobile */
    .speed-desc {
        display: block;
        font-size: 0.6rem;
        width: auto;
        text-align: left;
        margin-right: 4px;
        opacity: 0.7;
    }

    /* Improve waypoint markers for touch */
    .wp-marker {
        width: 18px;
        height: 18px;
    }

    .midpoint-marker {
        font-size: 28px;
        /* Bigger touch target */
    }

    /* Mobile planner panel styles */
    .planner-mobile-content {
        padding: 0;
    }

    .planner-mobile-content .waypoint-header {
        position: sticky;
        top: 0;
        z-index: 10;
        background: #f8fafc;
    }

    .planner-mobile-content .waypoint-content {
        flex: 1;
        overflow-y: auto;
    }

    .planner-mobile-content #waypoint-table {
        font-size: 0.7rem;
    }

    .planner-mobile-content .depth-stats {
        font-size: 0.7rem;
    }
}

.finish-btn,
.shelf-btn {
    padding: 6px 12px;
    background: #dc2626;
    color: white;
    border: none;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s;
}

.finish-btn:hover,
.shelf-btn:hover {
    background: #b91c1c;
}

.shelf-btn {
    background: #f1f5f9;
    color: #1a1a1a;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.shelf-btn:hover {
    background: #e2e8f0;
}

.share-btn {
    padding: 6px 12px;
    background: #f1f5f9;
    color: #1a1a1a;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 5px;
    margin-left: 4px;
}

.share-btn:hover {
    background: #e2e8f0;
}

.share-btn.copied {
    background: #22c55e;
    color: white;
    border-color: #22c55e;
}

/* Share Modal */
.share-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    padding: 20px;
}

.share-modal.show {
    opacity: 1;
}

.share-modal-content {
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    width: 100%;
    max-width: 500px;
    transform: scale(0.9) translateY(20px);
    transition: transform 0.3s ease;
}

.share-modal.show .share-modal-content {
    transform: scale(1) translateY(0);
}

.share-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid #e2e8f0;
}

.share-modal-header h3 {
    margin: 0;
    font-family: 'Instrument Serif', serif;
    font-size: 1.5rem;
    color: #1a1a1a;
}

.share-modal-close {
    background: none;
    border: none;
    font-size: 2rem;
    color: #64748b;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
    line-height: 1;
}

.share-modal-close:hover {
    background: #f1f5f9;
    color: #1a1a1a;
}

.share-modal-body {
    padding: 24px;
}

.share-modal-body label {
    display: block;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    color: #64748b;
    margin-bottom: 8px;
}

.share-url-container {
    display: flex;
    gap: 8px;
}

#share-url-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    color: #1a1a1a;
    background: #f8fafc;
    transition: border-color 0.2s;
}

#share-url-input:focus {
    outline: none;
    border-color: #1e40af;
    background: white;
}

.share-copy-btn {
    padding: 12px 24px;
    background: #1e40af;
    color: white;
    border: none;
    border-radius: 8px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.share-copy-btn:hover {
    background: #172554;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(30, 64, 175, 0.3);
}

.share-copy-btn.copied {
    background: #22c55e;
}

.share-copy-btn:active {
    transform: translateY(0);
}

/* Mobile Optimizations */
@media (max-width: 768px) {
    .share-modal {
        padding: 16px;
    }

    .share-modal-content {
        max-width: 100%;
    }

    .share-modal-header {
        padding: 16px 20px;
    }

    .share-modal-header h3 {
        font-size: 1.25rem;
    }

    .share-modal-body {
        padding: 20px;
    }

    .share-url-container {
        flex-direction: column;
    }

    #share-url-input {
        font-size: 0.8rem;
        padding: 10px 12px;
    }

    .share-copy-btn {
        width: 100%;
        padding: 12px;
        font-size: 0.95rem;
    }
}

/* Toast Notification (kept for error messages) */
.share-toast {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: rgba(34, 197, 94, 0.95);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    z-index: 10000;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
    backdrop-filter: blur(8px);
}

.share-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.share-toast.error {
    background: rgba(245, 158, 11, 0.95);
}

@media (max-width: 768px) {
    .share-toast {
        top: 12px;
        font-size: 0.85rem;
        padding: 10px 20px;
    }
}

.finish-btn.hidden,
.shelf-btn.hidden {
    display: none;
}

/* Hide finish button - redundant with Complete Route button */
.finish-btn {
    display: none !important;
}

/* Start Overlay */
.start-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(4px);
    display: flex;
    /* Flex by default */
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: opacity 0.3s ease;
}

.start-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.start-overlay.background-hidden {
    background: transparent;
    backdrop-filter: none;
    pointer-events: none;
}

.start-overlay.background-hidden .start-btn {
    pointer-events: auto;
}

.start-btn {
    padding: 12px 24px;
    background: #1e40af;
    color: white;
    border: none;
    border-radius: 8px;
    font-family: 'Instrument Serif', serif;
    font-size: 1.4rem;
    font-style: italic;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(30, 64, 175, 0.3);
    transition: transform 0.2s ease, background 0.2s ease, opacity 0.3s;
}

.start-btn:hover {
    background: #172554;
    transform: scale(1.05);
}

.start-btn.complete-mode {
    background: #16a34a;
    /* Green-600 */
    box-shadow: 0 4px 12px rgba(22, 163, 74, 0.3);
    transform: scale(1.1);
    /* Slightly bigger */
}

.start-btn.complete-mode:hover {
    background: #15803d;
    /* Green-700 */
    transform: scale(1.15);
}

/* Remove collapsed state from shelf (always visible) */
.shelf.collapsed {
    transform: none;
    /* Override previous collapsed transform */
}

/* Waypoint Table / NavLog */
.waypoint-sidebar {
    position: fixed;
    top: 80px;
    right: 20px;
    width: 348px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1100;
    max-height: 450px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.waypoint-sidebar.hidden {
    transform: translateX(120%);
    opacity: 0;
    pointer-events: none;
}

.waypoint-header {
    padding: 12px 16px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    font-family: 'Instrument Serif', serif;
    font-size: 1.2rem;
    color: #1a1a1a;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.edit-toggle-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    background: transparent;
    border: 1.5px solid rgba(100, 116, 139, 0.4);
    border-radius: 16px;
    cursor: pointer;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    font-weight: 500;
    color: #64748b;
    transition: all 0.2s ease;
}

.edit-toggle-btn:hover {
    border-color: #dc2626;
    color: #dc2626;
}

.edit-toggle-btn.active {
    background: transparent;
    color: #dc2626;
    border-color: #dc2626;
}

.edit-toggle-btn .edit-icon {
    display: none;
}

.edit-toggle-btn .edit-label {
    text-transform: lowercase;
}

.start-profile-link {
    color: #1e40af;
    text-decoration: none;
    font-weight: 600;
    cursor: pointer;
}

.start-profile-link:hover {
    text-decoration: underline;
}

.dist-display {
    display: flex;
    align-items: center;
    gap: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    color: #0d9488;
    background: rgba(13, 148, 136, 0.1);
    padding: 4px 10px;
    border-radius: 6px;
}

#total-dist-display {
    font-weight: 600;
}

.dist-unit-select,
#dist-unit-sidebar {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    background: rgba(13, 148, 136, 0.15);
    border: 1px solid rgba(13, 148, 136, 0.3);
    border-radius: 4px;
    color: #0d9488;
    cursor: pointer;
    padding: 2px 6px;
    margin-left: 4px;
}

.dist-unit-select:hover,
#dist-unit-sidebar:hover {
    background: rgba(13, 148, 136, 0.25);
}

.depth-stats {
    display: flex;
    justify-content: space-around;
    padding: 8px 16px;
    background: #f1f5f9;
    border-bottom: 1px solid #e2e8f0;
    font-size: 0.75rem;
    color: #64748b;
}

.depth-stats span {
    display: flex;
    gap: 4px;
}

.depth-stats strong {
    color: #334155;
}

#depth-min,
#depth-max,
#depth-avg {
    font-family: 'JetBrains Mono', monospace;
    color: #0284c7;
}

.waypoint-content {
    overflow-y: auto;
    flex: 1;
}

#waypoint-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.75rem;
    font-family: 'JetBrains Mono', monospace;
    table-layout: fixed;
}

/* Column widths: Time, Pos, Dist, Dir, Dur, Depth, Con */
#waypoint-table th:nth-child(1),
#waypoint-table td:nth-child(1) {
    width: 42px;
}

/* Time */
#waypoint-table th:nth-child(2),
#waypoint-table td:nth-child(2) {
    width: 68px;
}

/* Pos */
#waypoint-table th:nth-child(3),
#waypoint-table td:nth-child(3) {
    width: 50px;
}

/* Dist */
#waypoint-table th:nth-child(4),
#waypoint-table td:nth-child(4) {
    width: 38px;
}

/* Dir */
#waypoint-table th:nth-child(5),
#waypoint-table td:nth-child(5) {
    width: 38px;
}

/* Dur */
#waypoint-table th:nth-child(6),
#waypoint-table td:nth-child(6) {
    width: 45px;
}

/* Depth */
#waypoint-table th:nth-child(7),
#waypoint-table td:nth-child(7) {
    width: 32px;
}

/* Con */

#waypoint-table th {
    background: #f1f5f9;
    padding: 6px 4px;
    text-align: left;
    font-weight: 600;
    color: #64748b;
    position: sticky;
    top: 0;
    z-index: 20;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

#waypoint-table td {
    padding: 6px 4px;
    border-bottom: 1px solid #f1f5f9;
    color: #334155;
    vertical-align: top;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wp-time {
    font-family: 'JetBrains Mono', monospace;
    color: #64748b;
    font-size: 0.8rem;
    white-space: nowrap;
}

.wp-pos {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: #94a3b8;
    line-height: 1.2;
}

.wp-val {
    font-weight: 500;
}

.wp-depth {
    color: #1e40af;
    font-weight: 600;
    font-size: 0.8rem;
}

/* END badge for last waypoint */
.end-badge {
    font-size: 0.6em;
    color: #dc2626;
    font-weight: 700;
    background: rgba(220, 38, 38, 0.1);
    padding: 1px 4px;
    border-radius: 3px;
    margin-left: 4px;
}

/* Subtle contour mode indicator */
.contour-hint {
    color: #9ca3af;
    font-style: italic;
    font-size: 0.85em;
    margin-left: 1px;
}

/* Contour Mode Controls */
.contour-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: linear-gradient(135deg, rgba(30, 64, 175, 0.08), rgba(4, 120, 87, 0.08));
    border-bottom: 1px solid #e2e8f0;
}

.contour-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}

.contour-toggle input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #1e40af;
    cursor: pointer;
}

.toggle-label {
    font-size: 0.8rem;
    font-weight: 500;
    color: #334155;
}

.tolerance-control {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    color: #64748b;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.contour-controls:has(#contour-mode-toggle:checked) .tolerance-control {
    opacity: 1;
}

.tolerance-control input {
    width: 48px;
    padding: 4px 6px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    text-align: center;
}

.tolerance-control input:focus {
    outline: none;
    border-color: #1e40af;
}

/* IOS Toggle Switch (Table) */
.switch {
    position: relative;
    display: inline-flex;
    width: 28px;
    height: 16px;
    margin: 0;
    vertical-align: middle;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #e5e7eb;
    /* Grey 200 */
    transition: .4s;
    border-radius: 16px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 12px;
    width: 12px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .2s;
    border-radius: 50%;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

input:checked+.slider {
    background-color: #1e40af;
    /* Blue */
}

input:checked+.slider:before {
    transform: translateX(12px);
}

input:disabled+.slider {
    opacity: 0.3;
    cursor: not-allowed;
    background-color: #d1d5db;
}

/* Available contour toggle - neutral when off */
input:not(:disabled):not(:checked)+.slider:hover {
    background-color: #cbd5e1;
    /* Slightly darker on hover */
}

/* Contour unavailable indicator */
.contour-unavailable {
    color: #9ca3af;
    font-size: 0.7rem;
    opacity: 0.6;
}

/* Add minimal padding for toggle column */
#waypoint-table td:last-child {
    padding: 2px 6px;
    text-align: center;
    vertical-align: middle;
}

/* Empty State */
.empty-state {
    padding: 24px 16px;
    text-align: center;
    color: #94a3b8;
    font-size: 0.85rem;
}

.empty-state p {
    margin: 0;
}

.empty-state strong {
    color: #1e40af;
}

/* Hide empty state when table has content */
#waypoint-table tbody:not(:empty)~.empty-state {
    display: none;
}

/* Leg Type Icon */
.wp-type {
    font-size: 0.9rem;
    text-align: center;
    width: 20px;
}