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

:root {
    --brand: #33347c;
    --brand-dark: #1f2059;
    --brand-darker: #14154a;
    --brand-light: #4a4ba0;
    --accent: #fde047;
    --accent-dark: #facc15;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --glass-bg: rgba(255, 255, 255, 0.06);
    --glass-bg-strong: rgba(255, 255, 255, 0.10);
    --glass-border: rgba(255, 255, 255, 0.12);
    --glass-shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--text-primary);
    background:
        radial-gradient(1200px 600px at 20% 0%, rgba(74, 75, 160, 0.45) 0%, transparent 60%),
        radial-gradient(900px 500px at 90% 100%, rgba(51, 52, 124, 0.5) 0%, transparent 55%),
        linear-gradient(135deg, #14154a 0%, #1f2059 45%, #33347c 100%);
    background-attachment: fixed;
}

body {
    display: flex;
    flex-direction: column;
}

/* === Header === */
header {
    padding: 14px 24px;
    background: rgba(31, 32, 89, 0.55);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    color: var(--text-primary);
    display: flex;
    align-items: baseline;
    gap: 16px;
    border-bottom: 1px solid var(--glass-border);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 4px 24px rgba(0, 0, 0, 0.2);
}

.header-logo {
    max-height: 20px;
}

header h1 {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

#status {
    font-size: 13px;
    color: var(--text-muted);
}

/* === Controls bar === */
.controls {
    padding: 12px 24px;
    background: rgba(20, 21, 74, 0.4);
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    align-items: center;
    gap: 14px;
    z-index: 999;
    color: var(--text-primary);
}

.controls label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}

.controls #comune-filter + .choices {
    flex: 1;
    margin-bottom: 0;
    min-width: 0;
}

.controls .choices__inner {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    min-height: 38px;
    min-width: 350px;
    padding: 4px 8px;
    color: var(--text-primary);
}

/* Stato disabilitato: niente sfondo bianco, solo un look attenuato */
.controls .choices.is-disabled .choices__inner {
    background: rgba(255, 255, 255, 0.02);
    border-color: rgba(255, 255, 255, 0.08);
    opacity: 0.5;
}

.controls .choices.is-disabled .choices__input {
    background-color: transparent;
}

.controls .choices.is-disabled .choices__placeholder {
    color: var(--text-muted);
}

.controls .choices.is-disabled,
.controls .choices.is-disabled * {
    cursor: not-allowed;
}

.controls .choices__input {
    background: transparent;
    color: var(--text-primary);
}

.controls .choices__input::placeholder {
    color: var(--text-muted);
}

.controls .choices__placeholder {
    color: var(--text-muted);
    opacity: 1;
}

.controls .choices__list--multiple .choices__item {
    background: var(--accent);
    color: var(--brand-dark);
    border-color: var(--accent-dark);
    font-size: 12px;
    font-weight: 600;
    border-radius: 999px;
    padding: 3px 10px;
}

.controls .choices__list--dropdown,
.controls .choices[data-type*="select-multiple"] .choices__list--dropdown {
    background: rgba(20, 21, 74, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    margin-top: 4px;
    color: var(--text-primary);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

.controls .choices__list--dropdown .choices__input {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    color: var(--text-primary);
}

.controls .choices__list--dropdown .choices__item {
    color: var(--text-primary);
}

.controls .choices__list--dropdown .choices__item--selectable.is-highlighted {
    background: rgba(253, 224, 71, 0.18);
    color: var(--accent);
}

/* X button on multi-select chips */
.controls .choices__list--multiple .choices__button {
    appearance: none;
    background: transparent !important;
    background-image: none !important;
    border: 0;
    border-left: none !important;
    cursor: pointer;
    opacity: 0.75;
    text-indent: 0;
    font-size: 0;
    line-height: 1;
    width: auto;
    height: auto;
    padding: 0 2px;
    margin: 0 0 0 6px;
    color: transparent;
}

.controls .choices__list--multiple .choices__button::after {
    content: "×";
    display: inline-block;
    font-size: 16px;
    font-weight: 700;
    line-height: 1;
    color: var(--brand-dark);
}

.controls .choices__list--multiple .choices__button:hover { opacity: 1; }
.controls .choices__list--multiple .choices__button:hover::after { color: #b91c1c; }

/* === Year filter chips === */
.year-filter {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
}

.year-filter-label {
    font-weight: 600;
    color: var(--text-secondary);
    margin-right: 2px;
}

.year-checkbox {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
    line-height: 1.2;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.year-checkbox:hover {
    background: rgba(255, 255, 255, 0.1);
}

.year-checkbox input {
    margin: 0;
    cursor: pointer;
    accent-color: var(--accent);
}

.year-checkbox:has(input:checked) {
    background: rgba(253, 224, 71, 0.18);
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 600;
}

/* === Action button === */
.controls button {
    padding: 8px 14px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary);
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s;
}

.controls button:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.25);
}

/* === Map === */
main {
    flex: 1;
    position: relative;
    min-height: 0;
}

#map {
    width: 100%;
    height: 100%;
    background: var(--brand-darker);
}

/* === KPI cards === */
.kpis {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    padding: 18px 24px;
    background: rgba(20, 21, 74, 0.5);
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    border-top: 1px solid var(--glass-border);
}

.kpi {
    padding: 16px 18px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 4px 16px rgba(0, 0, 0, 0.15);
    transition: transform 0.15s, background 0.15s;
}

.kpi:hover {
    background: rgba(255, 255, 255, 0.09);
    transform: translateY(-1px);
}

.kpi-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 8px;
}

.kpi-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--accent);
    line-height: 1.2;
    letter-spacing: -0.01em;
}

.kpi-sub {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 6px;
}

/* === Leaflet legend === */
.legend {
    background: rgba(20, 21, 74, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    color: var(--text-primary);
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--glass-border);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    font-size: 12px;
    line-height: 1.7;
}

.legend h4 {
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.legend .swatch {
    display: inline-block;
    width: 14px;
    height: 14px;
    margin-right: 8px;
    vertical-align: middle;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

/* === Leaflet popup === */
.leaflet-popup-content-wrapper {
    background: rgba(20, 21, 74, 0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

.leaflet-popup-tip {
    background: rgba(20, 21, 74, 0.92);
    border: 1px solid var(--glass-border);
    box-shadow: none;
}

.leaflet-popup-close-button {
    color: var(--text-muted) !important;
    font-size: 18px !important;
}

.leaflet-popup-close-button:hover {
    color: var(--text-primary) !important;
}

.popup-table {
    font-size: 13px;
    border-collapse: collapse;
    color: var(--text-primary);
}

.popup-table td {
    padding: 3px 10px 3px 0;
}

.popup-table td:first-child {
    color: var(--text-muted);
}

.popup-title {
    font-weight: 700;
    font-size: 14px;
    margin-bottom: 8px;
    color: var(--accent);
}

/* === Comune name labels (selected) === */
.leaflet-tooltip.comune-label {
    background: transparent;
    border: none;
    box-shadow: none;
    color: #000000;
    font-weight: 700;
    font-size: 11px;
    padding: 0;
    text-shadow:
        -1px -1px 0 #fff,
         1px -1px 0 #fff,
        -1px  1px 0 #fff,
         1px  1px 0 #fff,
         0    0   3px #fff;
}

.leaflet-tooltip.comune-label::before {
    display: none;
}

/* === Leaflet controls (zoom, attribution) === */
.leaflet-bar a {
    background: rgba(20, 21, 74, 0.85) !important;
    color: var(--text-primary) !important;
    border-color: var(--glass-border) !important;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.leaflet-bar a:hover {
    background: rgba(31, 32, 89, 0.95) !important;
}

.leaflet-control-attribution {
    background: rgba(20, 21, 74, 0.75) !important;
    color: var(--text-secondary) !important;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 4px 0 0 0;
}

.leaflet-control-attribution a {
    color: var(--accent) !important;
}

/* === Scrollbar (per dropdown lunghi) === */
.choices__list--dropdown .choices__list {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.choices__list--dropdown .choices__list::-webkit-scrollbar {
    width: 8px;
}

.choices__list--dropdown .choices__list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}
