:root {
    color-scheme: light;
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #eef2f5;
    color: #1d2733;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; }
button, select { font: inherit; }

.app-header {
    display: flex;
    justify-content: space-between;
    gap: 24px;
    align-items: center;
    padding: 18px 24px;
    background: #172a3a;
    color: white;
}
.header-brand {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}
.header-brand-main {
    display: flex;
    align-items: flex-end;
    gap: 10px;
}
.header-logo {
    display: block;
    width: auto;
    height: 72px;
    max-width: 100%;
    object-fit: contain;
}
.app-version {
    margin-bottom: 6px;
    font-size: .78rem;
    font-weight: 700;
    opacity: .72;
    white-space: nowrap;
}
.header-brand p { margin: 0; opacity: .78; }
.header-tools { display: grid; justify-items: end; gap: 9px; }
.updated { text-align: right; font-size: .9rem; opacity: .9; }
.header-button {
    border: 1px solid rgba(255,255,255,.55);
    border-radius: 6px;
    background: transparent;
    color: white;
    padding: 7px 12px;
    cursor: pointer;
    font-weight: 700;
}
.header-button:hover,
.header-button:focus-visible { background: rgba(255,255,255,.12); }

main { padding: 18px; max-width: 1640px; margin: 0 auto; }
.workspace {
    display: grid;
    grid-template-columns: minmax(270px, 320px) minmax(0, 1fr);
    gap: 16px;
    align-items: start;
}
.control-column {
    display: grid;
    gap: 12px;
    min-width: 0;
}
.controls {
    display: grid;
    gap: 13px;
    padding: 16px;
    background: white;
    border: 1px solid #d6dee6;
    border-radius: 10px;
}
.controls h2 {
    margin: 0;
    padding-bottom: 10px;
    border-bottom: 1px solid #e1e7ec;
    font-size: 1.02rem;
}
.controls label {
    display: grid;
    gap: 5px;
    min-width: 0;
    color: #46586a;
    font-size: .8rem;
    font-weight: 700;
}
.controls select,
.controls button,
.control-actions button {
    width: 100%;
    min-height: 40px;
    border: 1px solid #b8c4cf;
    border-radius: 6px;
    background: white;
    padding: 7px 10px;
    color: #1d2733;
}
.controls button,
.control-actions button { cursor: pointer; font-weight: 700; }
.controls button:disabled,
.control-actions button:disabled { cursor: not-allowed; opacity: .45; }
.controls .model-updates-button {
    min-height: 34px;
    margin-top: -6px;
    border-style: dashed;
    background: #f7fafc;
    color: #315570;
    font-size: .78rem;
}
.controls .model-updates-button:hover,
.controls .model-updates-button:focus-visible {
    border-style: solid;
    background: #edf5fa;
}
.time-navigation { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }

.forecast-animation-controls,
.radar-controls {
    display: grid;
    gap: 9px;
    padding-top: 13px;
    border-top: 1px solid #d6dee6;
}
.forecast-animation-status,
.radar-status {
    color: #526477;
    font-size: .76rem;
    line-height: 1.35;
}

.forecast-animation-speed {
    display: grid;
    gap: 6px;
}
.forecast-animation-speed-label {
    color: #526477;
    font-size: .72rem;
    font-weight: 700;
}
.forecast-animation-speed-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    overflow: hidden;
    border: 1px solid #b8c4cf;
    border-radius: 7px;
    background: #f8fafb;
}
.forecast-animation-speed-options label {
    position: relative;
    display: grid;
    grid-template-columns: auto auto;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: 38px;
    padding: 5px 7px;
    border-right: 1px solid #d6dee6;
    cursor: pointer;
    user-select: none;
}
.forecast-animation-speed-options label:last-child { border-right: 0; }
.forecast-animation-speed-options input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}
.forecast-animation-speed-options span { font-size: 1.05rem; line-height: 1; }
.forecast-animation-speed-options small { font-size: .68rem; color: #43586b; }
.forecast-animation-speed-options label:has(input:checked) {
    background: #e7f3fa;
    box-shadow: inset 0 0 0 2px #4d93bd;
}
.forecast-animation-speed-options label:focus-within {
    outline: 2px solid #2b77a8;
    outline-offset: -2px;
}
.forecast-animation-controls.is-running button {
    border-color: #b64b4b;
    background: #fff5f5;
    color: #963b3b;
}
.controls .radar-toggle {
    display: flex;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 8px 10px;
    border: 1px solid #b8c4cf;
    border-radius: 6px;
    background: #f8fafb;
    color: #33485b;
    cursor: pointer;
}
.radar-toggle input {
    width: 17px;
    height: 17px;
    margin: 0;
    accent-color: #2b77a8;
}
.controls .radar-product { font-size: .76rem; }

.control-actions {
    padding: 13px;
    background: white;
    border: 1px solid #d6dee6;
    border-radius: 10px;
}
.guide-button {
    background: #172a3a !important;
    border-color: #172a3a !important;
    color: white !important;
}
.guide-button:hover,
.guide-button:focus-visible { background: #24435c !important; }

.map-column { min-width: 0; }
.summary {
    display: grid;
    grid-template-columns: repeat(5, minmax(100px, 1fr));
    gap: 1px;
    overflow: hidden;
    border: 1px solid #d6dee6;
    border-bottom: 0;
    border-radius: 10px 10px 0 0;
    background: #d6dee6;
}
.summary article { min-width: 0; padding: 12px 14px; background: white; }
.summary span { display: block; color: #65778a; font-size: .76rem; }
.summary strong { display: block; margin-top: 2px; font-size: 1.38rem; }
.model-coverage-card small {
    display: block;
    margin-top: 2px;
    color: #526477;
    font-size: .7rem;
}
.model-coverage-value {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-top: 2px;
}
.model-coverage-value strong { margin: 0; }

.map-wrap {
    position: relative;
    overflow: hidden;
    border: 1px solid #d6dee6;
    border-radius: 0 0 10px 10px;
    background: white;
}
#map { width: 100%; height: min(calc(72vh + 50px), 840px); min-height: 610px; }
.forecast-animation-timestamp {
    position: absolute;
    z-index: 520;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 14px;
    border: 1px solid rgba(255,255,255,.7);
    border-radius: 8px;
    background: rgba(14, 32, 49, .82);
    box-shadow: 0 2px 10px rgba(0,0,0,.28);
    color: white;
    font-size: 1rem;
    font-weight: 800;
    letter-spacing: .01em;
    line-height: 1.15;
    text-align: center;
    text-transform: capitalize;
    pointer-events: none;
    backdrop-filter: blur(3px);
}
.legend {
    position: absolute;
    z-index: 500;
    right: 12px;
    bottom: 20px;
    padding: 10px 12px;
    background: rgba(255,255,255,.94);
    border-radius: 7px;
    box-shadow: 0 1px 8px rgba(0,0,0,.22);
    font-size: .76rem;
    line-height: 1.65;
}
.legend strong { display: block; margin-bottom: 3px; }
.legend i { display: inline-block; width: 14px; height: 10px; margin-right: 5px; border-radius: 2px; }
.c0 { background:#d8f3dc; border: 1px solid #b7dfbd; }
.c1 { background:#4caf50; }
.c2 { background:#d7b600; }
.c3 { background:#f28c18; }
.c4 { background:#d84343; }
.c5 { background:#7b2cbf; }
.loading {
    position: absolute;
    z-index: 600;
    inset: 50% auto auto 50%;
    transform: translate(-50%, -50%);
    background: rgba(23,42,58,.93);
    color: white;
    padding: 12px 18px;
    border-radius: 7px;
}

.traffic-light {
    display: inline-grid;
    gap: 2px;
    flex: 0 0 auto;
    padding: 3px;
    border-radius: 7px;
    background: #273746;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
}
.traffic-light i {
    display: block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #6d7780;
    opacity: .34;
}
.traffic-light.is-red .traffic-red {
    background: #e54848;
    opacity: 1;
    box-shadow: 0 0 6px rgba(229,72,72,.65);
}
.traffic-light.is-amber .traffic-amber {
    background: #f0b429;
    opacity: 1;
    box-shadow: 0 0 6px rgba(240,180,41,.65);
}
.traffic-light.is-green .traffic-green {
    background: #39a866;
    opacity: 1;
    box-shadow: 0 0 6px rgba(57,168,102,.65);
}
.traffic-light.is-single { background: #647587; }

.popup h3 { margin: 0 0 7px; }
.popup div { margin: 2px 0; }
.popup-source-note {
    margin: 0 0 7px !important;
    padding: 5px 7px;
    border-left: 3px solid #2b77a8;
    background: #eef5f9;
    color: #526477;
    font-size: .78rem;
    line-height: 1.35;
}
.popup-model-coverage {
    display: flex;
    align-items: center;
    gap: 5px;
    margin: 5px 0 3px !important;
    padding: 5px 7px;
    border-radius: 5px;
    background: #f3f6f8;
}
.popup-model-coverage i {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex: 0 0 auto;
}
.popup-model-coverage.coverage-green i { background: #39a866; }
.popup-model-coverage.coverage-amber i { background: #f0b429; }
.popup-model-coverage.coverage-red i { background: #e54848; }
.model-scores {
    margin: 7px 0;
    padding: 6px 8px;
    background: #f3f6f8;
    border-radius: 5px;
}
.model-scores > b { display: block; margin-bottom: 3px; }
.popup-score-label {
    margin: -3px 0 7px !important;
    color: #526477;
    font-size: .78rem;
    font-weight: 700;
}
.score-comparison {
    margin: 7px 0 !important;
    padding: 7px 9px;
    border: 1px solid #dce4eb;
    border-radius: 6px;
    background: #f7f9fb;
}
.popup-section-title {
    margin: 9px 0 4px !important;
    padding-top: 6px;
    border-top: 1px solid #e1e7ec;
    color: #2f455a;
    font-size: .75rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .025em;
}

.trend-panel {
    margin-top: 16px;
    padding: 18px;
    background: white;
    border: 1px solid #d6dee6;
    border-radius: 9px;
}
.trend-heading {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 24px;
    margin-bottom: 14px;
}
.trend-heading h2 { margin: 0 0 4px; font-size: 1.1rem; }
.trend-heading p { margin: 0; color: #647587; font-size: .86rem; }
.trend-key { display: flex; flex-wrap: wrap; gap: 14px; font-size: .8rem; color: #526477; }
.trend-key span { display: inline-flex; align-items: center; gap: 6px; }
.trend-key i { width: 22px; height: 3px; border-radius: 3px; display: inline-block; }
.trend-max-key { background: #172a3a; }
.trend-average-key { background: #2b77a8; }
.trend-summary {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 14px;
}
.trend-summary article {
    padding: 12px 14px;
    border: 1px solid #dfe6ec;
    border-radius: 7px;
    background: #f8fafb;
}
.trend-summary span { display: block; color: #65778a; font-size: .76rem; }
.trend-summary strong { display: block; margin: 3px 0 2px; font-size: 1.2rem; }
.trend-summary small { color: #526477; }
.trend-chart-wrap { position: relative; min-height: 250px; overflow-x: auto; }
.trend-chart { display: block; width: 100%; min-width: 760px; height: auto; }
.trend-empty {
    display: grid;
    place-items: center;
    min-height: 250px;
    color: #647587;
    background: #f8fafb;
    border: 1px dashed #c8d3dc;
    border-radius: 7px;
}
.trend-description { margin: 8px 0 0; color: #526477; font-size: .84rem; line-height: 1.5; }
.trend-band-low { fill: rgba(76, 175, 80, .06); }
.trend-band-watch { fill: rgba(215, 182, 0, .06); }
.trend-band-possible { fill: rgba(242, 140, 24, .06); }
.trend-band-high { fill: rgba(216, 67, 67, .055); }
.trend-band-strong { fill: rgba(123, 44, 191, .055); }
.trend-grid-line { stroke: #cfd8df; stroke-width: 1; }
.trend-axis-tick { stroke: #738496; stroke-width: 1; }
.trend-axis-label { fill: #647587; font-size: 12px; }
.trend-line { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.trend-line-max { stroke: #172a3a; stroke-width: 3; }
.trend-line-average { stroke: #2b77a8; stroke-width: 2.5; }
.trend-selected-line { stroke: #65778a; stroke-width: 1.5; stroke-dasharray: 5 4; }
.trend-selected-max { fill: #172a3a; stroke: white; stroke-width: 2; }
.trend-selected-average { fill: #2b77a8; stroke: white; stroke-width: 2; }

.app-dialog {
    width: min(760px, calc(100vw - 32px));
    max-height: calc(100vh - 48px);
    padding: 0;
    border: 0;
    border-radius: 10px;
    box-shadow: 0 16px 55px rgba(0,0,0,.32);
    color: #1d2733;
}
.app-dialog::backdrop { background: rgba(8, 20, 30, .68); }
.app-dialog-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    padding: 16px 18px;
    background: #172a3a;
    color: white;
}
.app-dialog-header h2 { margin: 0; font-size: 1.15rem; }
.dialog-close-x {
    border: 0;
    background: transparent;
    color: white;
    font-size: 1.7rem;
    line-height: 1;
    cursor: pointer;
}
.app-dialog-body { padding: 18px; line-height: 1.55; }
.app-dialog-body p { margin: 0 0 13px; }
.app-dialog-body p:last-child { margin-bottom: 0; }
.app-dialog-actions { padding: 0 18px 18px; text-align: right; }
.app-dialog-actions button {
    border: 0;
    border-radius: 6px;
    background: #172a3a;
    color: white;
    padding: 9px 16px;
    cursor: pointer;
    font-weight: 700;
}
.guide-dialog { width: min(860px, calc(100vw - 32px)); }

.model-updates-dialog { width: min(900px, calc(100vw - 32px)); }
.model-updates-dialog .app-dialog-body {
    max-height: calc(100vh - 190px);
    overflow-y: auto;
}
.model-updates-intro {
    color: #526477;
    font-size: .88rem;
}
.model-updates-generated {
    margin: 0 0 12px;
    color: #65778a;
    font-size: .76rem;
    text-align: right;
}
.model-updates-list {
    display: grid;
    gap: 12px;
}
.model-updates-loading,
.model-updates-error {
    padding: 20px;
    border: 1px dashed #c6d1da;
    border-radius: 8px;
    background: #f8fafc;
    color: #526477;
    text-align: center;
}
.model-updates-error {
    border-color: #e2b6b6;
    background: #fff6f6;
    color: #8d3838;
}
.model-update-card {
    overflow: hidden;
    border: 1px solid #d7e0e7;
    border-left: 5px solid #8494a3;
    border-radius: 9px;
    background: #fff;
}
.model-update-card.is-fresh { border-left-color: #2f9e44; }
.model-update-card.is-running { border-left-color: #2b77a8; }
.model-update-card.is-stale { border-left-color: #d39b00; }
.model-update-card.is-failed,
.model-update-card.is-missing { border-left-color: #c74848; }
.model-update-card > header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    padding: 13px 14px;
    border-bottom: 1px solid #e4eaef;
    background: #f9fbfc;
}
.model-update-card h3 {
    margin: 0 0 3px;
    color: #203446;
    font-size: .98rem;
}
.model-update-card header small {
    color: #6a7b8c;
    font-size: .72rem;
}
.model-update-status {
    flex: 0 0 auto;
    padding: 4px 8px;
    border-radius: 999px;
    background: #edf1f4;
    color: #526477;
    font-size: .7rem;
    font-weight: 800;
    white-space: nowrap;
}
.is-fresh .model-update-status { background: #e6f6e9; color: #267338; }
.is-running .model-update-status { background: #e7f2f8; color: #286485; }
.is-stale .model-update-status { background: #fff5d8; color: #8a6500; }
.is-failed .model-update-status,
.is-missing .model-update-status { background: #fdeaea; color: #963b3b; }
.model-update-card dl {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin: 0;
}
.model-update-card dl > div {
    min-width: 0;
    padding: 11px 14px;
    border-bottom: 1px solid #edf1f4;
}
.model-update-card dl > div:nth-child(odd) {
    border-right: 1px solid #edf1f4;
}
.model-update-card dt {
    margin-bottom: 3px;
    color: #718293;
    font-size: .7rem;
}
.model-update-card dd {
    margin: 0;
    color: #263b4d;
    font-size: .84rem;
    font-weight: 700;
}
.model-update-error {
    padding: 10px 14px;
    background: #fff6f6;
    color: #8d3838;
    font-size: .76rem;
    overflow-wrap: anywhere;
}
.model-updates-actions {
    display: flex;
    justify-content: flex-end;
    gap: 9px;
}
.app-dialog-actions .secondary-dialog-button {
    border: 1px solid #b8c4cf;
    background: white;
    color: #30485d;
}

.guide-content section + section {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid #e0e7ed;
}
.guide-content h3 { margin: 0 0 8px; color: #2f455a; font-size: 1rem; }
.guide-index-list { margin-top: 10px; }
.guide-index-list p { margin: 0; }
.guide-index-list p + p { margin-top: 10px; }
.radar-image {
    image-rendering: auto;
}
.radar-image-sri {
    /* Il contrasto principale viene applicato pixel per pixel via canvas. */
    filter: saturate(1.03) contrast(1.02);
}

.app-footer {
    margin-top: 18px;
    padding: 16px 20px;
    border-top: 1px solid #cbd5df;
    background: #f8fafc;
    color: #516273;
    font-size: .78rem;
    line-height: 1.55;
    text-align: center;
}
.app-footer > div + div { margin-top: 3px; }
.footer-copyright { color: #1d2d3d; font-weight: 700; }
.app-footer a { color: #245f89; text-decoration: none; }
.app-footer a:hover,
.app-footer a:focus-visible { text-decoration: underline; }
.footer-licence-note { font-size: .72rem; opacity: .85; }

.fatal { max-width: 720px; margin: 40px auto; background: white; padding: 24px; border-radius: 8px; }

@media (max-width: 1180px) {
    .workspace { grid-template-columns: minmax(245px, 285px) minmax(0, 1fr); }
    .summary { grid-template-columns: repeat(3, minmax(100px, 1fr)); }
    .model-coverage-card { grid-column: span 2; }
}

@media (max-width: 900px) {
    .workspace { grid-template-columns: 1fr; }
    .controls {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-items: end;
    }
    .controls h2,
    .forecast-animation-controls,
    .radar-controls { grid-column: 1 / -1; }
    .time-navigation { align-self: end; }
    #map { min-height: 540px; }
}

@media (max-width: 720px) {
    .model-update-card > header {
        display: grid;
        gap: 8px;
    }
    .model-update-status { justify-self: start; }
    .model-update-card dl { grid-template-columns: 1fr; }
    .model-update-card dl > div:nth-child(odd) { border-right: 0; }
    .app-header { align-items: flex-start; flex-direction: column; }
    .header-tools { justify-items: start; }
    .updated { text-align: left; }
    main { padding: 12px; }
    .controls { grid-template-columns: 1fr; }
    .controls h2,
    .forecast-animation-controls,
    .radar-controls { grid-column: auto; }
    .summary { grid-template-columns: repeat(2, 1fr); }
    .model-coverage-card { grid-column: 1 / -1; }
    .legend { right: 8px; bottom: 12px; max-width: calc(100% - 16px); }
    .trend-heading { flex-direction: column; gap: 10px; }
    .trend-summary { grid-template-columns: 1fr; }
    .app-footer { padding: 14px 16px; text-align: left; }
}

/* Dettaglio del punto di griglia: pannello laterale sovrapposto alla mappa. */
.point-details {
    position: absolute;
    z-index: 850;
    top: 0;
    right: 0;
    bottom: 0;
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    width: min(410px, calc(100% - 56px));
    background: rgba(255, 255, 255, .985);
    border-left: 1px solid #cbd6df;
    box-shadow: -10px 0 30px rgba(20, 39, 54, .24);
    transform: translateX(calc(100% + 16px));
    visibility: hidden;
    transition: transform .22s ease, visibility .22s step-end;
}
.point-details.is-open {
    transform: translateX(0);
    visibility: visible;
    transition: transform .22s ease, visibility 0s;
}
.point-details-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    padding: 15px 16px 12px;
    background: #172a3a;
    color: white;
}
.point-details-kicker {
    display: block;
    margin-bottom: 3px;
    color: #bed2e1;
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .045em;
    text-transform: uppercase;
}
.point-details-header h2 {
    margin: 0;
    font-size: 1.08rem;
}
.point-details-close {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, .3);
    border-radius: 6px;
    background: transparent;
    color: white;
    font-size: 1.55rem;
    line-height: 1;
    cursor: pointer;
}
.point-details-close:hover,
.point-details-close:focus-visible { background: rgba(255, 255, 255, .12); }
.point-details-meta {
    padding: 9px 16px;
    border-bottom: 1px solid #dfe6ec;
    background: #f3f6f8;
    color: #526477;
    font-size: .78rem;
}
.point-details-content {
    min-height: 0;
    padding: 14px 16px 22px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
}
.point-details-content .popup h3 { font-size: 1.05rem; }
.point-details-content .popup { font-size: .86rem; line-height: 1.42; }
.point-details-content .model-scores,
.point-details-content .score-comparison { padding: 8px 10px; }

@media (max-width: 720px) {
    .point-details {
        top: auto;
        left: 0;
        width: 100%;
        height: min(72%, 590px);
        border-top: 1px solid #cbd6df;
        border-left: 0;
        box-shadow: 0 -10px 30px rgba(20, 39, 54, .26);
        transform: translateY(calc(100% + 16px));
    }
    .point-details.is-open { transform: translateY(0); }
}

@media (max-width: 700px) {
    .header-logo { height: 54px; }
    .header-brand-main { align-items: center; gap: 8px; }
    .app-version { margin-bottom: 0; font-size: .72rem; }
    .forecast-animation-timestamp {
        top: 10px;
        max-width: calc(100% - 90px);
        padding: 7px 10px;
        font-size: .82rem;
    }
    .forecast-animation-speed-options small { display: none; }
    .forecast-animation-speed-options span { font-size: 1.15rem; }
}
