* {
    box-sizing: border-box; /* A good practice for easier layout math */
}

html, body {
    height: 100%;
    margin: 0; /* Remove any browser-default margin */
    padding: 0;
    overflow: hidden; /* This is the key: prevents any scrolling on the body */
    font-family: sans-serif;
}

#map {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
}

.maplibregl-ctrl-top-left {
    margin: 60px 0 0 10px;
}

.header {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 50px;
    background-color: rgba(51, 51, 51, 0.85);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    color: white;
    display: flex;
    justify-content: space-between; /* This is key */
    align-items: center;
    padding: 0 15px;
    z-index: 10;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.header-left, .header-center, .header-right {
    flex: 1; /* Each section takes up a third of the space */
}

.header-center {
    text-align: center; /* Center the dropdown */
}

.header-right {
    text-align: right; /* Right-align the metrics button */
}

.city-selector-container {
    position: relative; /* This is crucial for positioning the dropdown list */
    display: inline-block;
}

#city-selector-button {
    background-color: #333;
    color: white;
    padding: 8px 16px;
    font-size: 1em;
    font-weight: bold;
    border: 1px solid #555;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    min-width: 220px; /* Give it some initial width */
    justify-content: center; /* This will center the content */
    text-align: center;
}
#city-selector-button:hover {
    background-color: #444;
}

/* The little down-arrow (chevron) */
#city-selector-button .chevron {
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 6px solid #4ade80; /* A nice green accent */
    margin-left: 10px; /* Keep some space for the chevron */
    position: absolute; /* Take chevron out of flex flow */
    right: 15px; /* Position it on the far right */
}

#city-selector-label {
    flex-grow: 1; /* Allow the label to fill space if needed */
}

/* The dropdown panel itself */
.dropdown-list {
    display: block; /* Use display for show/hide */
    position: absolute;
    background-color: #2a2a2a;
    width: 100%;
    border: 1px solid #555;
    border-radius: 6px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 100;
    margin-top: 5px;
    max-height: 40vh; /* Prevent it from being too long */
    overflow-y: auto;
}

.dropdown-list.hidden {
    display: none;
}

/* The individual city items in the list */
.dropdown-item {
    color: white;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    cursor: pointer;
    text-align: left;
}

.dropdown-item:hover {
    background-color: #444;
}

.header h1 {
    margin: 0;
    font-size: 1.2em;
    margin-right: 20px;
}

/* Style the popup that appears on hover */
.mapboxgl-popup {
    max-width: 200px;
}

.mapboxgl-popup-content {
    text-align: center;
    font-family: 'Open Sans', sans-serif;
    padding: 8px 12px;
    background-color: rgba(0, 0, 0, 0.75);
    color: white;
    border-radius: 4px;
}

.city-hover-popup .mapboxgl-popup-content {
    background-color: rgba(0, 0, 0, 0.8); /* Dark, slightly transparent background */
    color: #fff; /* White text */
    font-size: 14px;
    font-weight: bold;
    padding: 5px 10px;
    border-radius: 4px;
}

/* Hide the little triangle tip of the popup */
.city-hover-popup .mapboxgl-popup-tip {
    display: none;
}

/* Style for the new segment popup */
.segment-popup .mapboxgl-popup-content {
    background-color: rgba(30, 30, 30, 0.9); /* Dark, very transparent background */
    backdrop-filter: blur(5px); /* Nice "glass" effect */
    -webkit-backdrop-filter: blur(5px);
    color: #fff;
    font-size: 13px;
    line-height: 1.6;
    padding: 10px 15px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

.segment-popup .mapboxgl-popup-tip {
    display: none; /* Often looks cleaner without the tip on hover */
}

#legend {
    position: absolute;
    bottom: 20px;
    left: 10px;
    background-color: rgba(255, 255, 255, 0.9);
    padding: 10px 15px;
    border-radius: 5px;
    z-index: 10;
    font-size: 14px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

#legend h4 {
    margin: 0 0 5px 0;
    display: flex;
    align-items: center;
}

#legend-info-icon {
    width: 16px;
    height: 16px;
    margin-left: 8px;
    cursor: pointer;
    filter: invert(50%);
}
#legend-info-icon:hover {
    filter: invert(100%);
}

/* In style.css */

/* --- Legend Info Modal Styling --- */
#legend-info-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(20, 20, 20, 0.7); /* Slightly more transparent */
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    z-index: 1000; /* Higher than the about overlay */
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity 0.2s ease-in-out;
}

#legend-info-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.info-modal-content {
    background-color: #f9f9f9; /* A light background for the modal */
    color: #333; /* Dark text for readability */
    padding: 25px 30px;
    border-radius: 8px;
    max-width: 550px;
    width: 90%;
    text-align: justify;
    position: relative;
    box-shadow: 0 5px 20px rgba(0,0,0,0.25);
}

#legend-info-close-btn {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    color: #999;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
}
#legend-info-close-btn:hover {
    color: #333;
}

.info-modal-content h3 {
    margin-top: 0;
    margin-bottom: 20px;
    font-size: 1.4em;
    color: #111;
}

#legend-info-text p {
    margin: 0 0 15px 0;
    line-height: 1.6;
}

#legend-info-text strong {
    color: #111;
}

.legend-key {
    display: inline-block;
    width: 15px;
    height: 15px;
    margin-right: 8px;
    vertical-align: middle;
    border-radius: 3px;
}

.legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 5px;
    padding: 2px 5px;
    border-radius: 4px;
    cursor: pointer;
    opacity: 1; /* Fully visible by default */
    transition: opacity 0.2s, background-color 0.2s;
}

.legend-item:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.legend-item.inactive {
    opacity: 0.4; /* Greyed out when inactive */
}

.popup-table {
    border-collapse: collapse;
    width: 100%;
}
.popup-table td {
    padding: 2px 5px;
}
.popup-table td:first-child {
    text-align: right;
    padding-right: 10px;
    opacity: 0.8;
}

#metrics-panel {
    position: absolute;
    top: 0;
    right: 0;
    width: 320px;
    height: 100%;
    background-color: #1e1e1e;
    color: #f0f0f0; /* Default text color for the panel */
    z-index: 20;
    box-shadow: -5px 0 15px rgba(0,0,0,0.3);
    transform: translateX(100%);
    transition: transform 0.3s ease-in-out;
    display: flex;
    flex-direction: column;
}

#metrics-panel.visible {
    transform: translateX(0);
}

/* --- Panel Header --- */
.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid #444;
}

.panel-header h3 {
    margin: 0;
    font-size: 1.2em;
    color: white; /* Explicitly set header color */
}

#metrics-close-btn {
    background: none; border: none;
    color: #aaa; font-size: 28px; line-height: 1;
    cursor: pointer;
    padding: 0;
}
#metrics-close-btn:hover {
    color: white;
}

/* --- Panel Content Area --- */
.panel-content {
    padding: 0 20px 20px 20px;
    overflow-y: auto;
}

.panel-content h4 { /* City Name */
    font-size: 1.8em;
    font-weight: bold;
    color: white; /* Explicitly set city name color */
    margin-top: 20px;
    margin-bottom: 25px;
}

.metric-group h5 { /* Section Titles like "CLUSTER DISTRIBUTION" */
    margin-top: 25px;
    margin-bottom: 15px;
    text-transform: uppercase;
    font-size: 0.8em;
    color: #aaa; /* Keep this light grey for contrast */
    letter-spacing: 0.5px;
}

/* --- Bar Chart --- */
#bar-chart-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
}
.bar-chart-item {
    width: 100%;
}
.bar-chart-item .label-line {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 6px;
    font-size: 1.1em;
    color: #f0f0f0; /* Ensure text inherits the light color */
}
.bar-chart-item .label-line .value {
    font-weight: bold;
    color: white; /* Make the percentage pure white for emphasis */
}
.bar-track {
    width: 100%;
    height: 3px;
    background-color: #444;
}
.bar-fill {
    height: 100%;
    transition: width 0.5s ease-out;
}

/* --- Income Level --- */
#income-level-value {
    font-size: 1.5em;
    font-weight: bold;
    color: white; /* Explicitly set income level color */
}

/* --- Header Button Styling --- */
.header-button {
    background: transparent;
    border: 1px solid #777;
    color: #f0f0f0;
    padding: 6px 15px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
    margin-left: 10px;
    transition: background-color 0.2s;
}
.header-button:hover {
    background-color: #444;
}

/* --- About Overlay Styling --- */
#about-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(20, 20, 20, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 999;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 1;
    transition: opacity 0.3s ease-in-out;
}

#about-overlay.hidden {
    opacity: 0;
    pointer-events: none; /* Can't click on it when hidden */
}

.about-content {
    background-color: #1e1e1e;
    padding: 40px;
    border-radius: 8px;
    max-width: 600px;
    width: 90%;
    text-align: justify;
    color: #f0f0f0;
    position: relative;
    box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}

#about-close-btn {
    position: absolute;
    top: 15px;
    right: 20px;
    background: none;
    border: none;
    color: #aaa;
    font-size: 32px;
    line-height: 1;
    cursor: pointer;
}
#about-close-btn:hover {
    color: white;
}

.about-content h2 {
    font-size: 2em;
    margin-top: 0;
    margin-bottom: 20px;
}

.about-content p {
    font-size: 1.1em;
    line-height: 1.6;
    color: #ccc;
}

.about-content .credits {
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid #444;
}

.about-content .credits a {
    color: #4ade80; /* Green accent color */
    text-decoration: none;
    font-weight: bold;
}

.credits-grid {
    display: grid;
    /* Create a 12-column grid and assign 8 parts to the left and 4 to the right */
    grid-template-columns: 8fr 4fr; 
    align-items: center;
    gap: 20px; /* Space between the two columns */
}

.credits-left {
    text-align: left; /* Align all text in this column to the left */
}

.developed-by {
    font-size: 0.9em;
    color: #aaa;
    margin-top: 0;
    margin-bottom: 10px;
}

.developed-by a {
    color: #ccc;
    text-decoration: underline;
}
.developed-by a:hover {
    color: white;
}

.links {
    display: flex;
    justify-content: flex-start; /* Align links to the start of the div */
    align-items: center;
    gap: 15px;
}

.logos {
    display: flex;
    justify-content: flex-end; /* Align logos to the far right of their column */
    align-items: center;
    gap: 25px; /* Space between logos */
}

.logos img {
    height: 40px;
    filter: grayscale(1) brightness(2);
    opacity: 0.7;
    transition: all 0.2s ease-in-out;
}

.logos a:hover img {
    opacity: 1;
    filter: none; /* Show original color on hover */
}

.global-stats {
    padding: 20px;
    text-align: center;
}
.global-stats .stat-item {
    margin-bottom: 20px;
}
.global-stats .stat-value {
    font-size: 2em;
    font-weight: bold;
    color: white;
}
.global-stats .stat-label {
    font-size: 0.9em;
    color: #aaa;
    text-transform: uppercase;
}

.data-source-note {
    font-size: 0.85em;
    font-style: italic;
    color: #999;
    margin-top: 30px;
    border-top: 1px solid #444;
    padding-top: 20px;
}

/* --- Search Input inside Dropdown --- */
#city-search-input {
    width: 100%;
    padding: 10px 12px;
    background-color: #1e1e1e;
    border: none;
    border-bottom: 1px solid #555;
    color: white;
    font-size: 1em;
}

#city-search-input:focus {
    outline: none;
    border-bottom: 1px solid #4ade80; /* Green accent on focus */
}

/* Container for the scrollable list items */

/* "No results" message */
#no-results-message {
    padding: 15px;
    text-align: center;
    color: #888;
    font-style: italic;
}
#no-results-message.hidden {
    display: none;
}