@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap');

:root {
    --primary: #4F46E5;
    --primary-hover: #4338CA;
    --bg-dark: #f3f4f6;
    /* Light gray bg */
    --card-bg: rgba(255, 255, 255, 0.85);
    --text-main: #1f2937;
    /* Dark gray text */
    --text-muted: #6b7280;
    --success: #10B981;
    --warning: #F59E0B;
    --error: #EF4444;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --blur: 12px;
}

body.dark-theme {
    --bg-dark: #121212;
    --card-bg: rgba(30, 30, 30, 0.85);
    --text-main: #FFFFFF;
    --text-muted: #A0A0A0;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

/* Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body,
html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-dark);
    color: var(--text-main);
}

/* Map Container */
#map {
    width: 100%;
    height: 100%;
    z-index: 1;
    margin-top: 0;
    transition: margin-top 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Course-Up Mode: Oversize map */
body.course-up #map {
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    margin-top: 15vh;
    /* Standard offset because menus block bottom */
}

/* When drawer is closed, shift the map even further down to maximize view ahead */
body.course-up.drawer-collapsed #map {
    margin-top: 30vh;
}

/* UI Overlay */
.ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* Let clicks pass through to map */
    z-index: 1000;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

/* Header */
.app-header {
    pointer-events: auto;
    background: var(--card-bg);
    backdrop-filter: blur(var(--blur));
    padding: 0.5rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: var(--shadow);
}

.logo {
    font-weight: 700;
    font-size: 1.25rem;
    background: linear-gradient(to right, #6366f1, #a855f7);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.status-indicator {
    font-size: 0.875rem;
    color: var(--warning);
    /* Default: Waiting */
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-indicator::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: currentColor;
    display: inline-block;
    animation: blink 1.5s infinite;
}

@keyframes blink {
    50% {
        opacity: 0.5;
    }
}

/* Bottom Controls */
.controls-bottom {
    pointer-events: auto;
    padding: 1rem;
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
    /* Allow wrapping on small screens */
    /* Center buttons */
    /* Add gradient fade at bottom to improve contrast */
    background: linear-gradient(to top, rgba(0, 0, 0, 0.8) 0%, transparent 100%);
    /* push to bottom */
    margin-top: auto;
}

/* Floating Action Button (FAB) */
.fab-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: var(--card-bg);
    color: var(--text-main);
    backdrop-filter: blur(var(--blur));
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.3s;
    font-size: 1.25rem;
}

.fab-btn:active {
    transform: scale(0.95);
}

.fab-btn.primary {
    background: var(--primary);
    color: white;
}

.fab-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.fab-btn.primary:hover {
    background: var(--primary-hover);
}

/* Info Panel */
.info-panel {
    pointer-events: auto;
    position: absolute;
    bottom: 160px;
    /* Increased to avoid overlap with bottom buttons */
    left: 50%;
    transform: translateX(-50%);
    background: var(--card-bg);
    backdrop-filter: blur(var(--blur));
    padding: 1rem;
    border-radius: 1rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: var(--shadow);
    min-width: 280px;
    animation: slideUp 0.3s ease-out;
    max-height: calc(100% - 200px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    scrollbar-width: thin;
    max-width: 90%;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.info-panel.hidden {
    display: none;
}

.info-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 0.5rem;
}

.info-row:last-of-type {
    border-bottom: none;
}

.info-row span:first-child {
    color: var(--text-muted);
}

.text-btn {
    background: none;
    border: none;
    color: var(--primary);
    font-weight: 600;
    margin-top: 0.5rem;
    cursor: pointer;
    align-self: flex-end;
}

/* Animations */
@keyframes slideUp {
    from {
        transform: translate(-50%, 20px);
        opacity: 0;
    }

    to {
        transform: translate(-50%, 0);
        opacity: 1;
    }
}

/* Responsive tweaks for desktop */
@media (min-width: 768px) {
    .controls-bottom {
        justify-content: flex-end;
        /* Right align on desktop */
        padding-right: 2rem;
        padding-bottom: 2rem;
    }

    .logo {
        font-size: 1.5rem;
    }

    .info-panel {
        left: auto !important;
        right: 2rem !important;
        bottom: 100px;
        transform: none !important;
        width: 350px;
        max-width: 350px;
    }

    @keyframes slideUp {

        /* Override animation for desktop position if needed */
        from {
            transform: translateY(20px);
            opacity: 0;
        }

        to {
            transform: translateY(0);
            opacity: 1;
        }
    }
}

/* Cockpit/Dashboard Styles (Komoot-inspired) */
/* Cockpit/Dashboard New Swipe Layout */
.cockpit {
    pointer-events: auto;
    width: 100%;
    height: 135px;
    transition: transform 0.25s ease, opacity 0.25s ease;
    /* Gradient background for better readability over map */
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.2) 0%, rgba(0, 0, 0, 0) 100%);

    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    /* Firefox */
    -ms-overflow-style: none;
    /* IE/Edge */

    /* Ensure pages are stacked horizontally */
    flex-direction: row;
}

.cockpit::-webkit-scrollbar {
    display: none;
}

.cockpit-page {
    /* Each page takes full width */
    min-width: 100%;
    width: 100%;
    height: 100%;
    padding: 8px;

    /* 2x2 Grid */
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 4px;

    scroll-snap-align: start;
}

.tile {
    /* Glassmorphism Card */
    background: var(--card-bg);
    backdrop-filter: blur(var(--blur));
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    overflow: hidden;
    color: var(--text-main);
}

.tile.disabled {
    opacity: 0.5;
    background: rgba(0, 0, 0, 0.3);
}

/* Typography for Tiles */
.val-xl {
    font-size: 2.2rem;
    font-weight: 800;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.val-lg {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.unit {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
}

.unit-sm {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.label {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 2px;
    letter-spacing: 0.5px;
}


/* ------------------------------------------------------------- */
/* Leaflet Zoom Controls Styling                                   */
/* ------------------------------------------------------------- */

/* Zoom buttons - replaced by custom buttons in ui-overlay */
.leaflet-control-zoom {
    display: none !important;
}


.leaflet-control-zoom a {
    background: var(--card-bg) !important;
    backdrop-filter: blur(12px);
    color: var(--text-main) !important;
    width: 44px !important;
    height: 44px !important;
    line-height: 44px !important;
    font-size: 1.2rem !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
    display: block;
}

.leaflet-control-zoom a:last-child {
    border-bottom: none !important;
}

.leaflet-control-zoom a:hover {
    background: var(--primary) !important;
    color: white !important;
}

/* Hide the old Leaflet layer control entirely - we use our own */
.leaflet-control-layers {
    display: none !important;
}



/* Add FontAwesome Icon for Layers */
.leaflet-control-layers-toggle::after {
    content: "\f5fd";
    /* fa-layer-group icon */
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    font-size: 1.1rem;
    color: var(--text-main);
}

/* Expanded Layer List */
.leaflet-control-layers-expanded {
    padding: 12px !important;
    border-radius: 12px !important;
    min-width: 180px;
}

.leaflet-control-layers-base label,
.leaflet-control-layers-overlays label {
    display: flex !important;
    align-items: center;
    margin-bottom: 6px;
    font-size: 0.95rem;
    cursor: pointer;
}

.leaflet-control-layers-selector {
    margin-right: 8px;
    top: 1px;
    width: 16px;
    height: 16px;
    cursor: pointer;
}

/* Hillshading Blend Mode (Photoshop-Style Multiply) */
/* Requires .hillshade-overlay class on the tile layer */
/* Hillshading Blend Mode (Photoshop-Style Multiply) */
/* Requires .hillshade-overlay class on the tile layer */
.hillshade-overlay {
    mix-blend-mode: multiply !important;
    filter: contrast(130%) brightness(105%) !important;
}

/* Visibility Helper */
.hidden {
    display: none !important;
}

/* Modal Overlay & Card System */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
    z-index: 10000;
    /* High z-index to cover map */
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.modal-card {
    background: var(--bg-dark);
    /* Fallback */
    background: var(--card-bg);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    max-width: 400px;
    width: 100%;
    color: var(--text-main);
    animation: simpleFadeIn 0.2s ease-out;
}

@keyframes simpleFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Ensure inputs in modals are readable */
.modal-card input {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 10px;
    border-radius: 8px;
    width: 100%;
    margin-bottom: 10px;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* Off-Route Guide Line Animation (Marching Ants) */
.off-route-line {
    stroke-dasharray: 12, 12;
    animation: dash 1s linear infinite;
}

@keyframes dash {
    to {
        stroke-dashoffset: -24;
    }
}

/* Hillshading Blend Mode */
.multiply-blend {
    mix-blend-mode: multiply;
    filter: contrast(1.5) brightness(1.0);
}

/* Toggle Switch Style */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.1);
    transition: .4s;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.dark-theme .slider {
    background-color: rgba(255, 255, 255, 0.1);
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
}

input:checked+.slider {
    background-color: #6366f1;
}

input:checked+.slider:before {
    transform: translateX(20px);
}

.slider.round {
    border-radius: 24px;
}

.slider.round:before {
    border-radius: 50%;
}