/**
 * Wellington Dam Dive Map
 * Styles for the interactive dive 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: 100%;
}

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

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

/* ============================================
   Back Link (inside title card)
   ============================================ */

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

.back-link:hover {
    color: #0891b2;
}

/* ============================================
   Desktop Sidebar (Header + Legend combined)
   ============================================ */

.header {
    top: 50px;
    left: 20px;
    bottom: 30px;
    width: 320px;
    z-index: 600;
    display: flex;
    flex-direction: column;
    pointer-events: none;
}

.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 12px 0 0;
    border-bottom: none;
    padding: 20px 24px;
    pointer-events: auto;
}

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

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

.title-meta {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.attribution {
    font-size: 0.65rem;
    color: rgba(0, 0, 0, 0.4);
    margin-right: 12px;
}

.methods-link {
    font-size: 0.65rem;
    color: rgba(0, 0, 0, 0.4);
    text-decoration: none;
    transition: color 0.2s ease;
}

.methods-link:hover {
    color: #0891b2;
}

/* ============================================
   Legend / Controls Panel
   ============================================ */

.legend {
    position: static;
    z-index: 600;
    max-width: none;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.legend-toggle {
    display: none;
}

.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-top: none;
    border-radius: 0 0 12px 12px;
    padding: 0 20px 16px;
    pointer-events: auto;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
}

.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: 12px;
}

.legend-content {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* ============================================
   Depth Gradient Legend
   ============================================ */

.depth-legend {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.depth-gradient {
    height: 120px;
    width: 24px;
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.2);
    margin: 0 auto;
}

.depth-labels {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 120px;
    position: relative;
    margin-left: 32px;
    margin-top: -124px;
    font-size: 0.7rem;
    color: rgba(0, 0, 0, 0.6);
}

.depth-labels span {
    display: block;
}

/* Water Level Control */
.water-level-control {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.water-level-slider-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.water-level-slider-row input[type="range"] {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: linear-gradient(to right, #0891b2, #06b6d4);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.water-level-slider-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: white;
    border: 2px solid #0891b2;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    transition: transform 0.15s ease;
}

.water-level-slider-row input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.water-level-slider-row input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: white;
    border: 2px solid #0891b2;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.water-level-slider-row input[type="range"]:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.water-level-slider-row input[type="range"]:disabled::-webkit-slider-thumb {
    cursor: not-allowed;
}

.water-level-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: #0891b2;
    min-width: 50px;
    text-align: right;
    font-weight: 500;
}

.water-level-lock {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.7rem;
    color: rgba(0, 0, 0, 0.6);
    cursor: pointer;
}

.water-level-lock input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: #0891b2;
    cursor: pointer;
}

.water-level-note {
    font-size: 0.65rem;
    color: rgba(0, 0, 0, 0.5);
    text-align: center;
    margin-top: 4px;
    padding-top: 8px;
    border-top: 1px dashed rgba(0, 0, 0, 0.1);
}

/* ============================================
   Measure Tool Toggle
   ============================================ */

.measure-toggle {
    display: flex;
    gap: 8px;
    padding-top: 12px;
}

.measure-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    background: rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: rgba(0, 0, 0, 0.6);
    cursor: pointer;
    transition: all 0.2s ease;
}

@media (hover: hover) {
    .measure-btn:hover {
        background: rgba(8, 145, 178, 0.1);
        color: #0891b2;
    }
}

.measure-btn.active {
    background: rgba(8, 145, 178, 0.15);
    border-color: rgba(8, 145, 178, 0.3);
    color: #0891b2;
}

.measure-btn svg {
    flex-shrink: 0;
}

.clear-btn {
    padding: 10px 16px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 8px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: #dc2626;
    cursor: pointer;
    transition: all 0.2s ease;
}

.clear-btn:hover {
    background: rgba(239, 68, 68, 0.2);
}

/* ============================================
   Measure Panel
   ============================================ */

.measure-panel {
    margin-top: 12px;
    padding: 12px;
    background: rgba(8, 145, 178, 0.08);
    border: 1px solid rgba(8, 145, 178, 0.2);
    border-radius: 8px;
    overflow: hidden;
}

.measure-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(8, 145, 178, 0.2);
}

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

.measure-value {
    font-size: 1rem;
    font-weight: 400;
    color: #0891b2;
}

.measure-items {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 150px;
    overflow-y: auto;
}

.measure-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.7rem;
    color: rgba(0, 0, 0, 0.6);
    padding: 4px 0;
}

.measure-item-name {
    display: flex;
    align-items: center;
    gap: 6px;
}

.measure-item-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.measure-item-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.measure-item-bearing {
    color: #666;
    font-size: 0.85em;
}

.measure-item-distance {
    color: #0891b2;
    font-weight: 400;
}

/* ============================================
   Elevation Profile
   ============================================ */

.measure-profile {
    display: none;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(8, 145, 178, 0.2);
    overflow: hidden;
}

.measure-profile.visible {
    display: block;
}

.measure-profile svg {
    width: 100%;
    height: 80px;
    display: block;
}

.measure-profile .profile-label {
    font-size: 0.55rem;
    fill: rgba(0, 0, 0, 0.5);
    font-family: 'JetBrains Mono', monospace;
}

.measure-profile .profile-axis {
    stroke: rgba(0, 0, 0, 0.15);
    stroke-width: 0.5;
}

.measure-profile .profile-fill {
    fill: rgba(8, 145, 178, 0.25);
    stroke: rgba(8, 145, 178, 0.6);
    stroke-width: 1;
}

.measure-profile .profile-surface {
    stroke: rgba(8, 145, 178, 0.4);
    stroke-width: 0.5;
    stroke-dasharray: 3 2;
}

/* Contour segment bearing label */
.measure-item-bearing.contour-label {
    color: #06b6d4;
    font-style: italic;
}

/* Profile hover line */
.profile-hover-line {
    stroke: #FF00FF;
    stroke-width: 1;
    stroke-dasharray: 3 2;
    pointer-events: none;
}

/* Profile hover depth label */
.profile-hover-label {
    position: fixed;
    pointer-events: none;
    z-index: 1500;
    background: rgba(0, 0, 0, 0.85);
    color: #FF00FF;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    padding: 4px 8px;
    border-radius: 4px;
    transform: translateX(-50%);
    display: none;
}

/* ============================================
   Color Legend (for survey lines)
   ============================================ */

.color-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    color: rgba(0, 0, 0, 0.7);
    cursor: pointer;
    padding: 6px 8px;
    margin: -2px -8px;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.color-item:hover {
    background: rgba(0, 0, 0, 0.05);
}

.color-item.selected {
    background: rgba(8, 145, 178, 0.1);
    font-weight: 500;
}

.color-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    flex-shrink: 0;
}

/* ============================================
   Loading Status
   ============================================ */

.loading-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    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(8, 145, 178, 0.2);
    border-top-color: #0891b2;
    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: #0891b2;
    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);
    }
}

/* Contours Loading Indicator */
.contours-loading {
    position: absolute;
    bottom: 80px;
    right: 20px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 4px;
    font-size: 0.75rem;
    display: none;
    z-index: 100;
    font-family: 'JetBrains Mono', monospace;
    color: rgba(0, 0, 0, 0.7);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.contours-loading.active {
    display: block;
}

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

.maplibregl-popup-content {
    background: rgba(255, 255, 255, 0.95) !important;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    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: 18px;
    color: rgba(0, 0, 0, 0.4);
    padding: 4px 8px;
}

.maplibregl-popup-close-button:hover {
    color: #0891b2;
    background: transparent;
}

.segment-popup .popup-title {
    font-family: 'Instrument Serif', serif;
    font-size: 1.1rem;
    color: #0891b2;
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.segment-popup .popup-row {
    font-size: 0.75rem;
    color: #1a1a1a;
    margin-bottom: 4px;
}

.segment-popup .popup-label {
    color: rgba(0, 0, 0, 0.5);
    text-transform: uppercase;
    font-size: 0.65rem;
    letter-spacing: 0.05em;
    margin-right: 6px;
}

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

.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;
}

.maplibregl-ctrl-attrib:not(.maplibregl-compact-show) .maplibregl-ctrl-attrib-inner {
    display: none;
}

/* ============================================
   Layer Controls
   ============================================ */

.layer-control {
    padding: 10px 12px;
    background: rgba(0, 0, 0, 0.03);
    border-radius: 8px;
    transition: all 0.2s ease;
    margin-bottom: 6px;
}

.layer-control:hover {
    background: rgba(0, 0, 0, 0.05);
}

.layer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
}

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

.layer-toggle input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #0891b2;
    cursor: pointer;
}

.layer-name {
    font-size: 0.8rem;
    color: rgba(0, 0, 0, 0.8);
    font-weight: 400;
}

.layer-description {
    font-size: 0.65rem;
    color: rgba(0, 0, 0, 0.5);
    margin-top: 4px;
    margin-left: 24px;
}

/* ============================================
   Measure Mode Cursor
   ============================================ */

.measure-mode-active,
.depth-probe-active {
    cursor: crosshair !important;
}

.measure-mode-active .maplibregl-canvas,
.depth-probe-active .maplibregl-canvas {
    cursor: crosshair;
}

/* ============================================
   Depth Probe Tooltip
   ============================================ */

/* Desktop: lightweight cursor-following tooltip */
.depth-probe-tooltip {
    position: fixed;
    pointer-events: none;
    z-index: 1500;
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    padding: 6px 10px;
    border-radius: 6px;
    white-space: nowrap;
    display: none;
    transform: translate(14px, 14px);
}

/* Mobile: MapLibre Popup with pointer arrow */
.depth-probe-popup .maplibregl-popup-content {
    background: rgba(0, 0, 0, 0.85) !important;
    color: #fff;
    padding: 6px 12px !important;
    border-radius: 6px !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
    min-width: 0;
}

.depth-probe-popup .maplibregl-popup-tip {
    border-top-color: rgba(0, 0, 0, 0.85);
}

.depth-probe-popup-text {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    font-weight: 400;
    white-space: nowrap;
}

/* ============================================
   Mobile Responsive (< 768px)
   ============================================ */

@media (max-width: 768px) {

    /* Prevent default touch behavior on profile for hover/touch interaction */
    .measure-profile svg {
        touch-action: none;
    }

    .back-link {
        font-size: 0.6rem;
        margin-top: 4px;
        margin-bottom: 4px;
    }

    .header {
        top: 12px;
        left: 12px;
        right: 12px;
        bottom: auto;
        width: auto;
        display: block;
    }

    .title-card {
        padding: 10px 14px;
        cursor: pointer;
        border-radius: 12px;
        border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    }

    .title-card h1 {
        font-size: 1rem;
        margin-bottom: 0;
    }

    .title-card h1::after {
        content: ' i';
        font-size: 0.7rem;
        opacity: 0.4;
    }

    .title-card.expanded h1::after {
        content: '';
    }

    .title-card .subtitle,
    .title-card .back-link,
    .title-card .title-meta {
        display: none;
    }

    .title-card.expanded {
        cursor: default;
    }

    .title-card.expanded .subtitle,
    .title-card.expanded .back-link,
    .title-card.expanded .title-meta {
        display: block;
    }

    .title-card.expanded h1 {
        margin-bottom: 4px;
    }

    .legend {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        max-width: 100%;
        flex: none;
        z-index: 600;
        pointer-events: none;
    }

    .legend-toggle {
        display: block;
        position: absolute;
        bottom: 100%;
        left: 50%;
        transform: translateX(-50%);
        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-bottom: none;
        border-radius: 12px 12px 0 0;
        padding: 6px 16px;
        font-size: 0.7rem;
        font-family: 'JetBrains Mono', monospace;
        color: rgba(0, 0, 0, 0.7);
        cursor: pointer;
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
        transition: all 0.2s ease;
        z-index: 1;
        user-select: none;
        -webkit-tap-highlight-color: transparent;
        pointer-events: auto;
        white-space: nowrap;
    }

    .legend-toggle:active {
        background: rgba(8, 145, 178, 0.15);
        color: #0891b2;
        transform: translateY(1px);
    }

    .legend-toggle::before {
        content: 'Up ';
        font-size: 0.6rem;
    }

    .legend.collapsed .legend-toggle::before {
        content: 'Down ';
    }

    .legend-card {
        border-radius: 16px 16px 0 0;
        border-top: 1px solid rgba(0, 0, 0, 0.1);
        padding: 8px 16px 16px;
        max-height: 40vh;
        overflow-y: auto;
        transition: max-height 0.3s ease, opacity 0.3s ease, padding 0.3s ease;
    }

    .legend.collapsed .legend-card {
        max-height: 0;
        opacity: 0;
        padding-top: 0;
        padding-bottom: 0;
        overflow: hidden;
    }

    .legend-title {
        margin-top: 8px;
        padding-top: 8px;
    }

    .measure-toggle {
        padding-top: 8px;
    }

    .measure-btn {
        padding: 8px 12px;
        font-size: 0.7rem;
    }

    .clear-btn {
        padding: 8px 12px;
        font-size: 0.7rem;
    }

    .layer-control {
        padding: 8px 10px;
    }

    .layer-name {
        font-size: 0.75rem;
    }

    .layer-description {
        font-size: 0.6rem;
        margin-left: 22px;
    }

    .color-item {
        font-size: 0.7rem;
        padding: 4px 6px;
    }

    .color-dot {
        width: 10px;
        height: 10px;
    }

    /* Depth gradient on mobile */
    .depth-gradient {
        height: 80px;
    }

    .depth-labels {
        height: 80px;
        margin-top: -84px;
    }
}

/* ============================================
   Very Small Screens (< 480px)
   ============================================ */

@media (max-width: 480px) {
    .back-link {
        font-size: 0.65rem;
    }

    .title-card h1 {
        font-size: 0.9rem;
    }

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

    .measure-btn {
        padding: 6px 10px;
        font-size: 0.65rem;
    }

    .clear-btn {
        padding: 6px 10px;
        font-size: 0.65rem;
    }

    .color-item {
        font-size: 0.65rem;
    }

    .color-dot {
        width: 8px;
        height: 8px;
    }

    .measure-panel {
        padding: 8px;
    }

    .measure-value {
        font-size: 0.9rem;
    }

    .layer-control {
        padding: 6px 8px;
    }

    .layer-toggle input[type="checkbox"] {
        width: 14px;
        height: 14px;
    }

    .layer-name {
        font-size: 0.7rem;
    }

    /* Depth gradient even smaller */
    .depth-gradient {
        height: 60px;
    }

    .depth-labels {
        height: 60px;
        margin-top: -64px;
        font-size: 0.6rem;
    }
}

/* ============================================
   Context Menu (Right-Click Coordinate Copy)
   ============================================ */

.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;
    font-family: 'JetBrains Mono', monospace;
}

.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(8, 145, 178, 0.1);
    color: #0891b2;
}

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