:root {
    --color-background: #f8f8f6;
    --color-surface: #ffffff;
    --color-text: #1a2b33;
    --color-text-secondary: #5c6970;
    --color-primary: #1d6d78;
    --color-primary-hover: #155960;
    --color-primary-faint: rgba(29, 109, 120, 0.08);
    --color-border: rgba(29, 45, 51, 0.12);
    --color-error: #b91c32;
    --color-warning: #d97340;
    --color-success: #1d6d78;
    --font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 2px 6px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.08), 0 2px 6px rgba(0,0,0,0.04);
    --radius: 6px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --color-background: #171a1b;
        --color-surface: #1e2224;
        --color-text: #eaecec;
        --color-text-secondary: rgba(200, 205, 207, 0.7);
        --color-primary: #3ab5c2;
        --color-primary-hover: #2fa0ac;
        --color-primary-faint: rgba(58, 181, 194, 0.1);
        --color-border: rgba(200, 205, 207, 0.12);
        --color-error: #ef5561;
        --color-warning: #d97340;
        --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
        --shadow-md: 0 2px 6px rgba(0,0,0,0.25), 0 1px 2px rgba(0,0,0,0.15);
        --shadow-lg: 0 8px 24px rgba(0,0,0,0.35), 0 2px 6px rgba(0,0,0,0.15);
    }
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background-color: var(--color-background);
    color: var(--color-text);
    height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
}

.accent-bar {
    height: 3px;
    background: linear-gradient(90deg, var(--color-primary), var(--color-warning), var(--color-error));
    flex-shrink: 0;
}

header {
    background-color: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 10px 24px;
    box-shadow: var(--shadow-md);
    position: relative;
    z-index: 500;
}

.header-row {
    display: flex;
    align-items: flex-start;
    gap: 24px;
}

.header-left {
    flex: 1;
    min-width: 0;
    padding-top: 12px;
}

.header-title {
    text-align: center;
    font-size: 22px;
    font-weight: 700;
    color: var(--color-text);
    letter-spacing: 0.3px;
    margin: 0 0 6px 0;
    padding-top: 6px;
}

.header-right {
    flex-shrink: 0;
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    align-self: flex-end;
    gap: 8px;
}

.methodo-link {
    display: inline-block;
    background: rgba(100, 170, 220, 0.15);
    border: 1px solid rgba(100, 170, 220, 0.35);
    color: var(--color-primary);
    font-family: var(--font-family);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 20px;
    transition: background 0.15s, border-color 0.15s;
}

.methodo-link:hover {
    background: rgba(100, 170, 220, 0.28);
    border-color: rgba(100, 170, 220, 0.5);
}

.legal-link {
    background: none;
    border: none;
    color: var(--color-text-secondary);
    font-family: var(--font-family);
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.5px;
    cursor: pointer;
    padding: 4px 2px;
    opacity: 0.65;
    transition: opacity 0.15s, color 0.15s;
    text-transform: lowercase;
    align-self: flex-end;
}

.legal-link:hover {
    opacity: 1;
    color: var(--color-text);
}

.map-wrapper {
    position: relative;
    flex: 1;
    overflow: hidden;
}

.map-logo {
    position: absolute;
    bottom: 12px;
    left: 12px;
    height: 56px;
    width: auto;
    z-index: 1000;
    filter: brightness(0) saturate(100%);
    opacity: 0.7;
    pointer-events: none;
}

/* ── Methodology modal ── */

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 24px;
    animation: fade-in 0.2s ease-out;
}

.modal-overlay.open {
    display: flex;
}

.modal-content {
    position: relative;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
    max-width: 680px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    padding: 36px 40px;
    color: var(--color-text);
    font-size: 14px;
    line-height: 1.65;
    animation: dropdown-in 0.2s ease-out;
}

.modal-close {
    position: absolute;
    top: 14px;
    right: 18px;
    background: none;
    border: none;
    font-size: 26px;
    color: var(--color-text-secondary);
    cursor: pointer;
    line-height: 1;
    padding: 4px;
    transition: color 0.15s;
}

.modal-close:hover {
    color: var(--color-text);
}

.modal-heading {
    font-size: 18px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0 0 8px 0;
}

.modal-divider {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: 20px 0;
}

.modal-content h3 {
    font-size: 15px;
    font-weight: 700;
    margin: 0 0 12px 0;
    color: var(--color-text);
}

.methodo-card {
    background: var(--color-primary-faint);
    border-left: 3px solid var(--color-primary);
    border-radius: 0 6px 6px 0;
    padding: 12px 16px;
    margin-bottom: 10px;
}

.methodo-card strong {
    display: block;
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 4px;
}

.methodo-card p {
    margin: 0 0 6px 0;
    font-size: 13px;
    color: var(--color-text-secondary);
}

.methodo-card p:last-child {
    margin-bottom: 0;
}

.methodo-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 12px;
    font-size: 13px;
}

.methodo-table th {
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--color-text-secondary);
    padding: 8px 12px;
    border-bottom: 2px solid var(--color-border);
}

.methodo-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--color-border);
}

.methodo-table tbody tr:last-child td {
    border-bottom: none;
}

.methodo-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.2px;
}

.methodo-score {
    font-size: 14px;
    margin: 8px 0 4px 0;
}

.modal-content > p {
    margin: 0 0 4px 0;
    font-size: 13px;
    color: var(--color-text-secondary);
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.controls {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.search-wrapper {
    position: relative;
    max-width: 260px;
}

.search-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background-color: var(--color-surface);
    box-shadow: var(--shadow-sm);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.search-bar:focus-within {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-faint);
}

.search-icon {
    flex-shrink: 0;
    color: var(--color-text-secondary);
}

.search-bar input {
    border: none;
    outline: none;
    background: transparent;
    color: var(--color-text);
    font-size: 13px;
    font-family: var(--font-family);
    width: 100%;
    min-width: 0;
    padding: 0;
    box-shadow: none;
}

.search-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 4px;
    max-height: 260px;
    overflow-y: auto;
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    z-index: 900;
    animation: dropdown-in 0.15s ease-out;
}

.search-dropdown.open {
    display: block;
}

.search-dropdown-item {
    padding: 8px 12px;
    font-size: 13px;
    color: var(--color-text);
    cursor: pointer;
    border-bottom: 1px solid var(--color-border);
    transition: background-color 0.1s;
    line-height: 1.4;
}

.search-dropdown-item:last-child {
    border-bottom: none;
}

.search-dropdown-item:hover,
.search-dropdown-item.active {
    background-color: var(--color-primary);
    color: #fff;
}

.search-dropdown-item mark {
    background: transparent;
    color: inherit;
    font-weight: 700;
}

.search-dropdown-empty {
    padding: 10px 12px;
    font-size: 13px;
    color: var(--color-text-secondary);
    font-style: italic;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-left: 2px;
}

.filter-group label {
    font-size: 18px;
    font-weight: 800;
    color: var(--color-text);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

select, input[type="text"], input[type="date"] {
    padding: 7px 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background-color: var(--color-surface);
    color: var(--color-text);
    font-size: 13px;
    font-family: var(--font-family);
    min-width: 150px;
    transition: border-color 0.15s, box-shadow 0.15s;
    box-shadow: var(--shadow-sm);
}

select:focus, input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-faint);
}

.btn-reset {
    padding: 8px 16px;
    background-color: transparent;
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 500;
    font-family: var(--font-family);
    cursor: pointer;
    transition: all 0.15s;
}

.btn-reset:hover {
    background-color: var(--color-primary-faint);
    color: var(--color-text);
    border-color: var(--color-primary);
}

.stats {
    display: flex;
    gap: 12px;
    margin-left: 0;
    font-size: 12px;
    font-weight: 600;
    align-items: center;
    align-self: flex-end;
    margin-top: 0;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.stat-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background-color: var(--color-text-secondary);
    flex-shrink: 0;
}

.stat-dot--active {
    background-color: var(--color-primary);
}

.stat-label {
    color: var(--color-text-secondary);
    font-weight: 600;
}

.stat-value {
    font-weight: 800;
    color: var(--color-text);
    font-variant-numeric: tabular-nums;
}

/* ---- Map ---- */

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

.leaflet-control-attribution {
    display: none !important;
}

/* ---- Popups ---- */

.leaflet-popup-content-wrapper {
    background-color: var(--color-surface);
    color: var(--color-text);
    border-radius: 8px;
    padding: 0;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.leaflet-popup-content {
    margin: 0;
    width: 420px !important;
}

.leaflet-popup-tip {
    background-color: var(--color-surface);
}

.popup-card {
    display: flex;
    flex-direction: row;
    position: relative;
}

.popup-card-bar {
    width: 5px;
    flex-shrink: 0;
    border-radius: 8px 0 0 8px;
}

.popup-card-body {
    flex: 1;
    min-width: 0;
    padding: 14px 16px;
}

.popup-card-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    flex-shrink: 0;
    background-color: var(--color-primary);
    cursor: pointer;
    transition: background-color 0.15s;
    text-decoration: none;
    border-radius: 0 8px 8px 0;
}

.popup-card-arrow:hover {
    background-color: var(--color-primary-hover);
}

.popup-card-arrow svg {
    width: 14px;
    height: 14px;
}

.popup-card-type {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-secondary);
    margin-bottom: 3px;
}

.popup-card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text);
    line-height: 1.35;
    margin-bottom: 4px;
}

.popup-card-location {
    font-size: 11px;
    color: var(--color-text-secondary);
    line-height: 1.35;
    margin-bottom: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.popup-card-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
    border-top: 1px solid var(--color-border);
    margin-top: 2px;
}

.popup-card-table td {
    padding: 5px 0;
    vertical-align: top;
    border-bottom: 1px solid var(--color-border);
}

.popup-card-table tr:last-child td {
    border-bottom: none;
}

.popup-card-table .pc-label {
    color: var(--color-text-secondary);
    font-weight: 500;
    white-space: nowrap;
    width: 1%;
    padding-right: 10px;
}

.popup-card-table .pc-value {
    color: var(--color-text);
    font-weight: 600;
    text-align: right;
}

.badge {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    margin-right: 3px;
    margin-bottom: 2px;
    line-height: 1.4;
}

.badge-country {
    background-color: var(--color-primary-faint);
    color: var(--color-primary);
    border: 1px solid rgba(29, 109, 120, 0.2);
}

.badge-severity-faible {
    background-color: rgba(29, 109, 120, 0.1);
    color: var(--color-success);
    border: 1px solid rgba(29, 109, 120, 0.2);
}

.badge-severity-modere {
    background-color: rgba(217, 115, 64, 0.1);
    color: var(--color-warning);
    border: 1px solid rgba(217, 115, 64, 0.2);
}

.badge-severity-grave {
    background-color: rgba(239, 85, 97, 0.1);
    color: var(--color-error);
    border: 1px solid rgba(239, 85, 97, 0.2);
}

.badge-severity-tres-grave {
    background-color: rgba(185, 28, 50, 0.12);
    color: var(--color-error);
    border: 1px solid rgba(185, 28, 50, 0.25);
    font-weight: 700;
}

.popup-link {
    color: var(--color-primary);
    text-decoration: none;
    font-size: 11px;
    font-weight: 600;
    transition: color 0.15s;
}

.popup-link:hover {
    color: var(--color-primary-hover);
    text-decoration: underline;
}

/* ---- Custom Select Dropdowns ---- */

.custom-select {
    position: relative;
    min-width: 150px;
}

.custom-select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background-color: var(--color-surface);
    color: var(--color-text);
    font-size: 15px;
    font-family: var(--font-family);
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
    box-shadow: var(--shadow-sm);
    text-align: left;
    -webkit-appearance: none;
}

.custom-select-trigger:hover {
    border-color: var(--color-primary);
}

.custom-select-trigger:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-faint);
}

.custom-select-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.custom-select-chevron {
    flex-shrink: 0;
    color: var(--color-text-secondary);
    transition: transform 0.2s;
}

.custom-select.open .custom-select-chevron {
    transform: rotate(180deg);
}

.custom-select-options {
    display: none;
    position: absolute;
    top: calc(100% + 2px);
    left: 0;
    z-index: 600;
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    max-height: 320px;
    overflow-y: auto;
    padding: 6px;
    animation: dropdown-in 0.15s ease-out;
    display: none;
    flex-wrap: wrap;
    gap: 4px;
    width: max-content;
    max-width: 360px;
    min-width: 100%;
}

@keyframes dropdown-in {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.custom-select.open .custom-select-options {
    display: flex;
}

.custom-select-option {
    padding: 6px 14px;
    font-size: 15px;
    color: var(--color-text);
    cursor: pointer;
    transition: all 0.1s;
    white-space: nowrap;
    border-radius: 4px;
    border: 1px solid var(--color-border);
    background-color: var(--color-surface);
}

.custom-select-option:hover {
    background-color: var(--color-primary-faint);
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.custom-select-option.selected {
    color: #fff;
    font-weight: 600;
    background-color: var(--color-primary);
    border-color: var(--color-primary);
}

.custom-select-options::-webkit-scrollbar {
    width: 6px;
}

.custom-select-options::-webkit-scrollbar-track {
    background: transparent;
}

.custom-select-options::-webkit-scrollbar-thumb {
    background-color: var(--color-border);
    border-radius: 3px;
}

/* ---- Legend ---- */

.legend {
    background: var(--color-surface);
    padding: 12px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.legend-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 8px;
    color: var(--color-text);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 5px;
    font-size: 12px;
    color: var(--color-text);
}

.legend-item:last-child {
    margin-bottom: 0;
}

.legend-bubble-wrap {
    width: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.legend-bubble {
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.7);
    box-shadow: var(--shadow-sm);
}

/* ---- Pulse animation for critical markers ---- */

@keyframes pulse-ring {
    0% { transform: scale(1); opacity: 0.6; }
    100% { transform: scale(2.2); opacity: 0; }
}

/* ---- Responsive ---- */

@media (max-width: 768px) {
    header {
        padding: 10px 12px;
    }

    .header-row {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .header-right {
        align-items: flex-start;
    }

    .controls {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-group {
        width: 100%;
    }

    .custom-select {
        width: 100%;
        min-width: auto;
    }

    .stats {
        margin-left: 0;
        margin-top: 4px;
    }

    .leaflet-popup-content {
        width: 300px !important;
    }

    .popup-card-arrow {
        width: 36px;
    }
}

@media (prefers-color-scheme: dark) {
    .map-logo {
        filter: none;
        opacity: 0.85;
    }

    .leaflet-popup-content-wrapper {
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    }

    .badge-country {
        background-color: rgba(58, 181, 194, 0.12);
        border-color: rgba(58, 181, 194, 0.25);
    }

    .legend-bubble {
        border-color: rgba(255, 255, 255, 0.4);
    }
}
