html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    max-width: 100%;
    overflow-x: hidden;
    font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
    box-sizing: border-box;
}

*, *::before, *::after {
    box-sizing: inherit;
    font-family: inherit;
}

/* ----------------------------------------------------------
   CONTAINER
---------------------------------------------------------- */
.container {
    max-width: 600px;
    width: 100%;
    margin: 0 auto;
    padding: 20px;
    text-align: center;
}

/* ----------------------------------------------------------
   LOGO
---------------------------------------------------------- */
.site-logo {
    width: fit-content;
    margin: 0 auto;
}

.site-logo img {
    height: 67px;
    width: auto;
    display: block;
}

/* ----------------------------------------------------------
   HELP ICON + PANEL
---------------------------------------------------------- */
#help-icon {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 20px;
    height: 20px;
    background: rgba(255,255,255,0.9);
    border-radius: 50%;
    border: 1px solid #aaa;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-weight: bold;
    color: #333;
    box-shadow: 0 1px 3px rgba(0,0,0,0.25);
    z-index: 1000;
}

#help-panel {
    display: none;
    position: absolute;
    top: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255,255,255,0.95);
    padding: 10px 14px;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.25);
    width: 80%;
    max-width: 550px;
    z-index: 9999;
}

#help-panel.visible {
    display: block;
}

/* ----------------------------------------------------------
   LOCATION + DISTANCE
---------------------------------------------------------- */
.location-selection {
    display: flex;
    gap: 32px; /* reduced from 64px to prevent overflow */
    justify-content: center;
    align-items: center;
    width: 100%;
    flex-wrap: wrap; /* prevents overflow on narrow screens */
}

.field {
    display: flex;
    align-items: center;
    gap: 8px;
}

.field label {
    white-space: nowrap;
    font-size: 0.9rem;
}

/* ----------------------------------------------------------
   AUTOCOMPLETE
---------------------------------------------------------- */
.autocomplete-wrapper {
    position: relative;
    width: 220px;
}

.autocomplete-wrapper input {
    width: 100%;
    padding: 6px 8px;
    font-size: 0.9rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fafafa;
}

.dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fafafa;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.9rem;
    max-height: 200px;
    overflow-y: auto;
    z-index: 9000;
}

.dropdown div {
    padding: 6px 8px;
    cursor: pointer;
}

.dropdown div:hover {
    background: #f0f0f0;
}

.hidden {
    display: none;
}

/* ----------------------------------------------------------
   DISTANCE INPUT
---------------------------------------------------------- */
#distance-input {
    width: 64px;
    padding: 6px 8px;
    font-size: 0.9rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fafafa;
}

.checkbox-row-wrapper {
    margin: 10px 0;
    width: 100%;
    padding: 0.75rem 1rem;
    text-align: center;
    position: relative;
}

/* ----------------------------------------------------------
   SLIDERS
---------------------------------------------------------- */
.slider-row {
    margin: 20px 0;
    width: 100%;
    padding: 0.75rem 1rem;
    text-align: center;
    position: relative;
}

.slider-row label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
}

.weight-slider {
    width: 100%;
    max-width: 100%;
}

/* Modern slider styling */
input[type="range"] {
    appearance: none;
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #ddd;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
    height: 6px;
    border-radius: 3px;
    background: linear-gradient(
        to right,
        #2f5fa7 var(--percent, 50%),
        #ddd var(--percent, 50%)
    );
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 20px;
    width: 20px;
    border-radius: 50%;
    background: #2f5fa7;
    border: 2px solid black;
    margin-top: -7px;
}

input[type="range"]::-moz-range-track {
    height: 6px;
    border-radius: 3px;
    background: #ddd;
}

input[type="range"]::-moz-range-progress {
    height: 6px;
    border-radius: 3px;
    background: #2f5fa7;
}

input[type="range"]::-moz-range-thumb {
    height: 20px;
    width: 20px;
    border-radius: 50%;
    background: white;
    border: 2px solid #2f5fa7;
}

/* ----------------------------------------------------------
   INFO POPUPS
---------------------------------------------------------- */
.info-icon {
    display: inline-block;
    margin-left: 6px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #0066CC;
    color: white;
    font-size: 12px;
    line-height: 16px;
    text-align: center;
    cursor: pointer;
    position: relative;
}

.info-popup {
    display: none;
    position: absolute;
    top: 0;
    left: 24px; 
    background: #ffffff;
    color: #333;
    padding: 10px 12px;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    font-size: 0.85rem;
    width: 260px;
    z-index: 9000;
}

.info-popup a {
    color: #0066CC;
    text-decoration: underline;
}

/* ----------------------------------------------------------
   LOADING OVERLAY
---------------------------------------------------------- */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.55);
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    z-index: 9999;
    color: white;
    font-size: 20px;
    font-weight: 600;
}

.loader {
    border: 6px solid rgba(255,255,255,0.3);
    border-top: 6px solid white;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    animation: spin 0.9s linear infinite;
    margin-bottom: 15px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}


/* FOR MAP PAGE */
.map-logo {
    position: absolute;
    top: 20px;
    right: 20px;
    height: 42px;   /* adjust as needed */
    width: auto;
    z-index: 1000;  /* ensures it sits above map tiles */
}


.back-icon {
    position: absolute;
    top: 20px;
    left: 20px;
    display: flex;          
    align-items: center;
    gap: 8px;              /* spacing between icon + text */
    color: black;          /* makes both icon + text white */
    font-size: 20px;       /* text size */
    font-weight: 600;      /* bold text */
    text-decoration: none;
    cursor: pointer;
    transition: color 0.2s ease;
    z-index: 1000;
}

.back-icon:hover {
    color: white;
}

.back-icon svg {
    display: block;
}


.rank-marker div {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: rgba(255,255,255,0.8);
    border: 2px solid black;
    text-align: center;
    line-height: 26px;
    font-weight: bold;
}

/* Legend container */
.legend {
    position: absolute;
    bottom: 90px;
    left: 10px;
    background: rgba(255,255,255,0.9);
    padding: 10px 12px;
    border: 1px solid #aaa;
    border-radius: 6px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.25);
    font-size: 13px;
    z-index: 1000;
    width: 160px;
}

/* Header */
.legend-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    font-weight: 600;
}

.legend-left {
    display: flex;
    align-items: center;
    gap: 6px; 
}

.legend-toggle.off {
    opacity: 0.35;
}

.legend-toggle {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
    padding: 2px 6px;
}


/* Labels above/below ramp */
.legend-text {
    margin-left: 8px;
    font-size: 12px;
    white-space: nowrap;
}

/* Each row of the legend */
.legend-row {
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

/* Colour bars */
.legend-row span {
    width: 48px;                
    height: 18px;
    margin: 0;
    border-radius: 0;
}

/* ZOOM BUTTONS */
#zoom-controls {
    position: absolute;
    bottom: 10px;
    left: 10px;
    display: flex;
    flex-direction: row;
    gap: 12px;
    z-index: 1000;
}

.zoom-btn {
    width: 64px;
    height: 64px;
    border: 1px solid #aaa;
    border-radius: 4px;
    background: #fff;
    font-size: 22px;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}

.zoom-btn:hover {
    background: #f0f0f0;
}

/* Map container */
#map,
.maplibregl-map {
    width: 100%;
    height: 100vh;
}

#map {
    min-height: 600px;
    position: relative;
}

#map canvas {
    cursor: default;
}

/* map attribution */
#map-attribution {
    position: absolute;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    font-size: 11px;
    line-height: 1.3;
}

.maplibregl-ctrl-scale {
    position: absolute ;
    bottom: 20px;
    right: 60px;
    z-index: 1000;
    margin: 0 ;
}


/* The small circular info icon */
#attrib-icon {
    width: 20px;
    height: 20px;
    background: rgba(255,255,255,0.9);
    border-radius: 50%;
    border: 1px solid #aaa;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-weight: bold;
    color: #333;
    box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}

/* The hidden panel */
#attrib-panel {
    display: none;
    margin-top: 6px;
    background: rgba(255,255,255,0.9);
    padding: 8px 12px;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.25);
    max-width: 600px;
}

/* When visible */
#attrib-panel.visible {
    display: block;
}

#map-help-icon {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 20px;
    height: 20px;
    background: rgba(255,255,255,0.9);
    border-radius: 50%;
    border: 1px solid #aaa;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-weight: bold;
    color: #333;
    box-shadow: 0 1px 3px rgba(0,0,0,0.25);
    z-index: 1000;
}

#map-help-panel {
    display: none;
    position: absolute;
    top: 50px;
    right: 20px;
    background: rgba(255,255,255,0.95);
    padding: 10px 14px;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.25);
    max-width: 680px;
    z-index: 1000;
}

#map-help-panel.visible {
    display: block;
}


/* Sidebar styling */
.sidebar {
    position: absolute;
    top: 0;
    right: 0;
    width: 360px;
    height: 100vh;
    background: #ffffff;
    box-shadow: -2px 0 10px rgba(0,0,0,0.15);
    padding: 20px 20px 24px 20px;
    box-sizing: border-box;
    overflow-y: auto;       
    overflow-x: hidden; 
    z-index: 2000;
    transform: translateX(100%);
    transition: transform 0.25s ease-out;
    box-shadow: -2px 0 6px rgba(0,0,0,0.15);
    scroll-behavior: smooth;
}

.sidebar.visible {
    transform: translateX(0);
}

.sidebar-close {
    background: none;
    border: none;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    float: right;
    color: #555;
}

#sidebar-title {
    margin: 8px 0 4px 0;
    font-size: 18px;
    font-weight: 600;
    color: #2f5fa7;
}

#sidebar-composite {
    margin: 0 0 12px 0;
    font-size: 14px;
    color: #333;
}

.sidebar-info {
    margin-top: 0.5rem;
    padding: 0.75rem 1rem;
    background: #f5f5f7;
    border-left: 3px solid #2f5fa7; /* subtle premium blue */
    border-radius: 4px;
    font-size: 0.9rem;
    line-height: 1.35;
}

.sidebar-info p {
    margin: 0.25rem 0;
}

.sidebar-info strong {
    font-weight: 600;
    color: #333;
}

.sidebar-note {
    margin: 0 0 12px 0;
    font-size: 10px;
    color: #333;
}

/* rank RUC21CD */
#rank-section {
    margin-top: 12px;
    padding: 10px 0;
    border-top: 1px solid #ddd;
}

#ruc-description {
    font-size: 0.9rem;
    margin-bottom: 10px;
    line-height: 1.35;
}

.rank-label {
    font-size: 0.9rem;
    font-weight: 600;
    display: block;
    margin-bottom: 6px;
}

#rank-select {
    width: 100%;
    padding: 6px 8px;
    font-size: 0.9rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fafafa;
}

#rank-display {
    margin-top: 10px;
    font-size: 0.9rem;
    line-height: 1.35;
}

.rank-row {
    display: flex;
    align-items: center;
    gap: 8px; 
}

.rank-label {
    display: inline-block;
    margin-bottom: 0;
    white-space: nowrap;
}

#rank-select {
    flex: 1; /
}



/* Top 5 markers */

.top-marker {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #ffffff;
    border: 3px solid #2f5fa7;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
    color: #2f5fa7;
    box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}

/* MapLibre popup for top 5 */

.maplibregl-popup-content {
    font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
    font-size: 13px;
}

.maplibregl-popup-content strong {
    font-weight: 600;
}

/* ----------------------------------------------------------
   MOBILE OPTIMISATION (max-width: 600px)
   Desktop layout remains unchanged
---------------------------------------------------------- */
@media (max-device-width: 600px) {

    .container {
        padding: 12px;
        max-width: 100%;
    }

    .site-logo img {
        height: 54px;
    }

    #help-icon {
        top: 12px;
        right: 12px;
        width: 22px;
        height: 22px;
        font-size: 13px;
    }

    #help-panel {
        top: 60px;
        width: 92%;
        padding: 14px;
        font-size: 0.9rem;
    }

    .location-selection {
        flex-direction: column;
        gap: 20px;
        width: 100%;
    }

    .field {
        flex-direction: column;
        align-items: flex-start;
        width: 100%;
        gap: 6px;
    }

    .autocomplete-wrapper {
        width: 100%;
    }

    .autocomplete-wrapper input {
        font-size: 1rem;
        padding: 10px;
    }

    .dropdown {
        font-size: 1rem;
        max-height: 180px;
    }

    #distance-input {
        width: 100%;
        padding: 10px;
        font-size: 1rem;
    }

    .slider-row {
        margin: 24px 0;
        text-align: left;
        position: relative;
    }

    .slider-row label {
        font-size: 1rem;
        margin-bottom: 10px;
    }

    .weight-slider {
        width: 100%;
    }

    .info-icon {
        width: 18px;
        height: 18px;
        font-size: 12px;
        line-height: 18px;
    }

    .info-popup {
        position: fixed;
        top: 35%;              
        left: 50%;
        transform: translateX(-50%);
        width: 90vw;
        padding: 12px;
        z-index: 9999;
    }

    #loading-overlay {
        font-size: 22px;
    }
}

/* ----------------------------------------------------------
   MOBILE OPTIMISATION FOR MAP PAGE (max-width: 600px)
---------------------------------------------------------- */
@media (max-device-width: 600px) {

    /* Map takes full height minus safe area */
    #map,
    .maplibregl-map {
        height: 100vh;
        min-height: 100vh;
    }

    /* Logo smaller + tucked in */
    .map-logo {
        top: 12px;
        right: 12px;
        height: 32px;
    }

    /* Back icon larger tap target */
    .back-icon {
        top: 12px;
        left: 12px;
        font-size: 18px;
        gap: 6px;
    }

    /* Help icon repositioned */
    #map-help-icon {
        top: 12px;
        right: 12px;
        width: 22px;
        height: 22px;
        font-size: 13px;
    }

    /* Help panel becomes full-width modal */
    #map-help-panel {
        top: 50px;
        right: 50%;
        transform: translateX(50%);
        width: 92%;
        max-width: none;
        padding: 14px;
        font-size: 0.9rem;
    }

    /* Legend shrinks + moves up */
    .legend {
        bottom: 20px ;
        left: 10px ;
        right: auto ;
        width: auto;
        max-width: 160px;
        padding: 8px 10px;
    }
    .legend-row span {
        width: 40px;
        height: 14px;
    }

    .legend-text {
        font-size: 11px;
    }

    /* Sidebar becomes full-screen bottom sheet */
    .sidebar {
        width: 100%;
        height: 70vh;
        bottom: 0;
        top: auto;
        right: 0;
        border-radius: 12px 12px 0 0;
        padding: 16px;
        transform: translateY(100%);
        transition: transform 0.25s ease-out;
    }

    .sidebar.visible {
        transform: translateY(0);
    }

    .sidebar-close {
        font-size: 26px;
    }

    #sidebar-title {
        font-size: 17px;
    }

    #sidebar-composite {
        font-size: 13px;
    }

    .sidebar-info {
        font-size: 0.85rem;
        padding: 0.65rem 0.9rem;
    }

    /* Rank section spacing */
    #rank-section {
        margin-top: 10px;
        padding-top: 8px;
    }

    #rank-select {
        font-size: 0.9rem;
        padding: 8px;
    }

    /* Top 5 markers slightly larger for visibility */
    .top-marker {
        width: 30px;
        height: 30px;
        font-size: 15px;
    }

    /* Popups scale better on mobile */
    .maplibregl-popup-content {
        font-size: 12px;
        padding: 8px 10px;
        max-width: 240px;
    }

    /* Force monochrome eye icon */
    .legend-toggle svg,
    .legend-toggle svg * {
        fill: black ;
        stroke: black ;
        color: black ;
        filter: none ;
    }

    /* 2. Remove zoom buttons */
    #zoom-controls {
        display: none ;
    }

    /* Ensure attribution + scale bar show */
    #map-attribution {
        position: absolute ;
        top: 50px ;
        right: 12px ;
        bottom: auto ;
        font-size: 13px ;
        z-index: 1000 ;
        display: block ;
    }

    .maplibregl-ctrl-scale {
        bottom: 6px ;
        left: 6px ;
        right: auto ;
        z-index: 2000 ;
        display: block ;
    }

}

