/**
 * Abrolhos Islands Dive Trails
 * Styles for the interactive dive trail 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 (part of sidebar on desktop)
   ============================================ */

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

/* Hide toggle button on desktop */
.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;
    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;
}

/* ============================================
   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;
}

.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-distance {
    color: #0891b2;
    font-weight: 400;
}

.measure-item-depth {
    color: rgba(0, 0, 0, 0.5);
    font-size: 0.65rem;
}

/* ============================================
   Color Legend (for trails)
   ============================================ */

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

.segment-popup .popup-distance {
    font-size: 1rem;
    color: #0891b2;
    margin-top: 8px;
}

/* ============================================
   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;
}

.layer-opacity {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    margin-left: 24px;
}

.opacity-slider {
    flex: 1;
    height: 4px;
    border-radius: 2px;
    background: rgba(0, 0, 0, 0.1);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.opacity-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #0891b2;
    cursor: pointer;
    transition: all 0.2s ease;
}

.opacity-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.opacity-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #0891b2;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.opacity-slider::-moz-range-thumb:hover {
    transform: scale(1.2);
}

.opacity-value {
    font-size: 0.7rem;
    color: rgba(0, 0, 0, 0.5);
    min-width: 36px;
    text-align: right;
}

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

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

.measure-mode-active .maplibregl-canvas {
    cursor: crosshair !important;
}

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

@media (max-width: 768px) {

    /* Back link - always visible on mobile */
    .back-link {
        font-size: 0.6rem;
        margin-top: 4px;
        margin-bottom: 4px;
    }

    /* Header - compact, positioned at top only (no bottom) */
    .header {
        top: 12px;
        left: 12px;
        right: 12px;
        bottom: auto;
        width: auto;
        display: block;
    }

    /* Title card - collapsible, fully rounded on mobile */
    .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;
    }

    /* Add expand indicator */
    .title-card h1::after {
        content: ' ⓘ';
        font-size: 0.7rem;
        opacity: 0.4;
    }

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

    /* Hide details by default on mobile */
    .title-card .subtitle,
    .title-card .back-link,
    .title-card .title-meta {
        display: none;
    }

    /* Show on expanded state */
    .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 - separate from header, fixed to viewport bottom */
    .legend {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        max-width: 100%;
        flex: none;
        z-index: 600;
        pointer-events: none;
    }

    /* Legend toggle button - positioned absolutely above the card */
    .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: '▲ ';
        font-size: 0.6rem;
    }

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

    .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 state */
    .legend.collapsed .legend-card {
        max-height: 0;
        opacity: 0;
        padding-top: 0;
        padding-bottom: 0;
        overflow: hidden;
    }

    /* Legend - tighter spacing on mobile */
    .legend-title {
        margin-top: 8px;
        padding-top: 8px;
    }

    /* Measure toggle - more compact */
    .measure-toggle {
        padding-top: 8px;
    }

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

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

    /* Layer controls - more compact */
    .layer-control {
        padding: 8px 10px;
    }

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

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

    .layer-opacity {
        margin-left: 22px;
    }

    /* Color items - more compact */
    .color-item {
        font-size: 0.7rem;
        padding: 4px 6px;
    }

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

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

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

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

    /* Legend - even more compact */
    .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;
    }

    .layer-opacity {
        margin-top: 4px;
    }
}

/* ============================================
   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;
}
