:root {
    --primary-color: #1a5276;
    --secondary-color: #f4f6f8;
    --text-color: #333;
    --text-muted: #555;
    --border-color: #e1e4e8;
    --hover-bg: #eaf0f6;
    --accent-color: #2980b9;
    --badge-bg: #d4e6f1;
    --badge-color: #154360;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background-color: var(--secondary-color);
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

header {
    background-color: var(--primary-color);
    color: white;
    padding: 1.5rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 15px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    position: relative; 
    z-index: 1000; 
}

.header-content h1 {
    font-size: 1.8rem;
    margin-bottom: 0.3rem;
}

.header-content p {
    font-size: 0.95rem;
    opacity: 0.85;
}

.search-container {
    position: relative;
    width: 100%;
    max-width: 700px;
    display: flex;
    align-items: center;
}

.search-container input {
    width: 100%;
    padding: 1rem 45px 1rem 1.2rem;
    font-size: 1.05rem;
    border: none;
    border-radius: 8px;
    outline: none;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
    transition: box-shadow 0.2s;
}

.search-container input:focus {
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1), 0 0 0 3px rgba(255,255,255,0.3);
}

.clear-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background-color: #fff;
    border: none;
    font-size: 1.8rem;
    color: #e74c3c;
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 4px;
    z-index: 1050; 
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: all 0.2s ease;
}

.clear-btn:hover {
    color: #c0392b;
    background-color: #f2f2f2;
}

.suggestions-list {
    position: absolute;
    top: calc(100% + 5px); 
    left: 0;
    width: 100%;
    background-color: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    max-height: 250px;
    overflow-y: auto;
    z-index: 2000;
    list-style: none;
    padding: 0;
    margin: 0;
}

.suggestions-list li {
    padding: 12px 15px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--text-color);
}

.suggestions-list li:last-child {
    border-bottom: none;
}

.suggestions-list li:hover {
    background-color: var(--hover-bg);
}

.suggestion-name {
    font-weight: 600;
    font-size: 1rem;
}

.suggestion-region {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.sidebar {
    width: 420px;
    background-color: white;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.sidebar-header {
    padding: 1.2rem 1rem;
    border-bottom: 1px solid var(--border-color);
    background-color: #f9fbfd;
    position: sticky;
    top: 0;
    z-index: 5;
}

.sidebar-header h2 {
    font-size: 1.05rem;
    color: var(--primary-color);
}

#municipalityList {
    list-style: none;
}

#municipalityList li {
    padding: 1.5rem 1.2rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background-color 0.2s ease;
}

#municipalityList li:hover {
    background-color: var(--hover-bg);
}

.municipality-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.8rem;
}

.municipality-name {
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--primary-color);
}

.badge {
    background-color: var(--badge-bg);
    color: var(--badge-color);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.35rem 0.6rem;
    border-radius: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.municipality-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 1.2rem;
    padding: 0.6rem 0.8rem;
    background-color: var(--secondary-color);
    border-radius: 6px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.municipality-stats span {
    display: flex;
    align-items: center;
    font-weight: 500;
}

.municipality-details {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.detail-row {
    font-size: 0.95rem;
    line-height: 1.4;
}

/* NEW: For the text snippet in the sidebar */
.description-snippet {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.9rem;
    margin: 4px 0;
}

.detail-row a {
    color: var(--accent-color);
    text-decoration: none;
    font-weight: 500;
}

.detail-row a:hover {
    text-decoration: underline;
}

.limit-message {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem !important;
    cursor: default !important;
    background-color: transparent !important;
}

.map-container {
    flex: 1;
    position: relative;
    z-index: 1;
}

#map {
    height: 100%;
    width: 100%;
}

/* NEW: To force a defined width to accommodate long text */
.popup-container {
    font-family: 'Segoe UI', sans-serif;
    max-width: 320px; 
}

.popup-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 4px;
}

.popup-subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 600;
}

.popup-divider {
    border: 0;
    border-top: 1px solid var(--border-color);
    margin: 10px 0;
}

.popup-info {
    font-size: 0.95rem;
    margin-bottom: 6px;
}

/* NEW: Internal scrollbar for historical text */
.popup-desc-scroll {
    max-height: 150px;
    overflow-y: auto;
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.4;
    padding-right: 5px;
    margin: 8px 0;
    text-align: justify;
}

/* Scrollbar style for the popup */
.popup-desc-scroll::-webkit-scrollbar {
    width: 4px;
}
.popup-desc-scroll::-webkit-scrollbar-track {
    background: #f1f1f1; 
}
.popup-desc-scroll::-webkit-scrollbar-thumb {
    background: #ccc; 
    border-radius: 4px;
}

.popup-link {
    margin-top: 12px;
    font-size: 0.95rem;
}

.popup-link a {
    color: var(--accent-color);
    text-decoration: none;
    font-weight: 600;
}

.popup-link a:hover {
    text-decoration: underline;
}

@media (max-width: 768px) {
    .container {
        flex-direction: column-reverse;
    }
    .sidebar {
        width: 100%;
        height: 50%;
        border-right: none;
        border-top: 1px solid var(--border-color);
    }
    .map-container {
        height: 50%;
    }
}