/* OAPA Meteo — M3.1 stylesheet. No external dependencies, no CDN. */

/* ============================================================
   Variables & Reset
   ============================================================ */

:root {
    --color-primary:    #2c5f8a;
    --color-primary-dk: #1a3a5c;
    --color-header-bg:  #1E293B;
    --color-header-txt: #F1F5F9;
    --color-body-bg:    #F1F5F9;
    --color-sidebar-bg: #ffffff;
    --color-border:     #E2E8F0;
    --color-card-bg:    #ffffff;
    --radius:           6px;
    --shadow-sm:        0 1px 3px rgba(0,0,0,.1);
    --sidebar-width:    200px;
}

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

/* ============================================================
   Base
   ============================================================ */

body {
    font-family: system-ui, -apple-system, sans-serif;
    font-size: 1rem;
    line-height: 1.6;
    color: #1a1a1a;
    background: var(--color-body-bg);
}

a { color: var(--color-primary); }
a:hover { color: var(--color-primary-dk); }

/* ============================================================
   Layout skeleton
   ============================================================ */

.app-wrapper {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding-bottom: 48px; /* compensate for fixed footer */
}

/* ============================================================
   Site header
   ============================================================ */

.site-header {
    background: var(--color-header-bg);
    color: var(--color-header-txt);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,.2);
}

.header-inner {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 0 1rem;
    padding: 0.7rem 1.5rem;
}

.site-brand {
    color: var(--color-header-txt);
    font-size: 1.1rem;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
    letter-spacing: 0.01em;
}

.site-brand:hover { color: #fff; }

.header-sub {
    color: #94A3B8;
    font-size: 0.8rem;
}

/* M3.3.2 / M3.4 — header center subtitle (stile uguale al brand) */
.header-center {
    text-align: center;
    color: var(--color-header-txt);
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 0.5rem;
}

/* M3.3.2 — header right cluster (lang-dropdown) */
.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    justify-content: flex-end;
}

/* ============================================================
   App body (sidebar + main)
   ============================================================ */

.app-body {
    display: flex;
    flex: 1;
}

/* ============================================================
   Sidebar navigation
   ============================================================ */

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--color-sidebar-bg);
    border-right: 1px solid var(--color-border);
    padding: 1.25rem 0;
}

.nav-list {
    list-style: none;
}

.nav-item {
    display: block;
    padding: 0.55rem 1.25rem;
    color: #334155;
    text-decoration: none;
    font-size: 0.9rem;
    border-left: 3px solid transparent;
    transition: background 0.1s, color 0.1s;
}

.nav-item:hover {
    background: #EFF6FF;
    color: var(--color-primary);
}

.nav-item--active {
    background: #EEF4FF;
    color: var(--color-primary);
    border-left-color: var(--color-primary);
    font-weight: 600;
}

/* ============================================================
   Main content area
   ============================================================ */

.site-main {
    flex: 1;
    padding: 1.5rem;
    overflow-x: hidden;
    min-width: 0;
}

.page-intro {
    color: #475569;
    font-size: 0.95rem;
    margin-bottom: 1.25rem;
}

/* ============================================================
   Site footer
   ============================================================ */

.site-footer {
    background: var(--color-header-bg);
    color: #64748B;
    font-size: 0.82rem;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    box-shadow: 0 -2px 8px rgba(0,0,0,.2);
}

.footer-inner {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 0.55rem 1.5rem;
    gap: 0 1rem;
}

.footer-left  { text-align: left; }
.footer-center { text-align: center; }
.footer-right { text-align: right; }

.footer-clock {
    font-family: ui-monospace, 'Cascadia Code', 'Consolas', monospace;
    font-size: 0.82rem;
    letter-spacing: 0.04em;
    color: #94A3B8;
    white-space: nowrap;
    user-select: none;
}

/* ============================================================
   Cards
   ============================================================ */

.card {
    background: var(--color-card-bg);
    border: 1px solid #d6dce6;
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-sm);
}

.card h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-primary-dk);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.card h3 {
    font-size: 0.9rem;
    font-weight: 600;
    margin: 1rem 0 0.4rem;
}

.card--error {
    border-color: #c0392b;
    background: #fff5f5;
}

.card--info {
    border-color: #b0c4d8;
    background: #f8fbff;
}

.card ol, .card ul {
    margin-left: 1.25rem;
    margin-top: 0.5rem;
}

.card li {
    margin-bottom: 0.25rem;
}

/* ============================================================
   Status badges
   ============================================================ */

.status-badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 3px;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    margin-bottom: 0.6rem;
}

.badge--ok {
    background: #e6f4ea;
    color: #1d7a3a;
}

.badge--warn {
    background: #fff4e5;
    color: #8a5c00;
}

.badge--error {
    background: #fde8e8;
    color: #b91c1c;
}

/* ============================================================
   Info table
   ============================================================ */

.info-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.info-table th,
.info-table td {
    text-align: left;
    padding: 0.3rem 0.5rem;
    border-bottom: 1px solid #eaecf0;
}

.info-table th {
    width: 40%;
    color: #555;
    font-weight: 500;
}

.info-table tr:last-child th,
.info-table tr:last-child td {
    border-bottom: none;
}

/* ============================================================
   Code, notes, detail
   ============================================================ */

code {
    font-family: ui-monospace, 'Cascadia Code', 'Fira Mono', monospace;
    font-size: 0.85em;
    background: #f0f2f5;
    padding: 0.1em 0.35em;
    border-radius: 3px;
}

.note {
    color: #666;
    font-size: 0.85rem;
    margin-top: 0.75rem;
}

.detail {
    color: #c0392b;
    font-size: 0.85rem;
    margin-top: 0.4rem;
}

/* ============================================================
   Quick-links grid (homepage)
   ============================================================ */

.quicklinks {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.quicklink {
    display: block;
    background: #f0f5fb;
    border: 1px solid #c8d8ec;
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
    text-decoration: none;
    color: var(--color-primary-dk);
    font-weight: 600;
    font-size: 0.9rem;
    transition: background 0.1s, border-color 0.1s;
}

.quicklink:hover {
    background: #dceeff;
    border-color: #7aaac8;
    color: var(--color-primary-dk);
}

.quicklink-desc {
    display: block;
    font-weight: 400;
    font-size: 0.8rem;
    color: #556;
    margin-top: 0.2rem;
}

/* ============================================================
   M2 — Dashboard components
   ============================================================ */

/* Compact card (system debug info) */
.card--compact { padding: 0.75rem 1rem; }
.card--compact .info-table th { width: 20%; }
.card--compact .info-table td { width: 30%; }

/* Freshness header */
.freshness-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.freshness-ts {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--color-primary-dk);
}

/* Weather cards grid */
.weather-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.weather-card {
    background: #f0f5fb;
    border: 1px solid #c8d8ec;
    border-radius: var(--radius);
    padding: 0.75rem 0.875rem;
}

.wc-title {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #4a6a8a;
    margin-bottom: 0.3rem;
}

.wc-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--color-primary-dk);
    line-height: 1.2;
    margin-bottom: 0.3rem;
}

.wc-sub {
    display: flex;
    justify-content: space-between;
    font-size: 0.78rem;
    color: #555;
    margin-top: 0.15rem;
}

.wc-sub-label {
    color: #888;
    margin-right: 0.25rem;
}

/* Recent readings table */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-top: 0.5rem;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
    white-space: nowrap;
}

.data-table th {
    background: #f0f5fb;
    color: var(--color-primary-dk);
    font-weight: 600;
    text-align: right;
    padding: 0.35rem 0.6rem;
    border-bottom: 2px solid #c8d8ec;
}

.data-table th:first-child { text-align: left; }

.data-table td {
    text-align: right;
    padding: 0.3rem 0.6rem;
    border-bottom: 1px solid #eaecf0;
    color: #333;
}

.data-table td:first-child {
    text-align: left;
    color: #555;
}

.data-table tbody tr:hover { background: #f8fafc; }

/* ============================================================
   M3 — Chart components
   ============================================================ */

.card--charts { padding-bottom: 1rem; }

.chart-tabs {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    margin-bottom: 0.85rem;
}

.chart-tab {
    padding: 0.3rem 0.8rem;
    border: 1px solid #b8cfe0;
    border-radius: 4px;
    background: #eef4fa;
    color: var(--color-primary-dk);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    line-height: 1.5;
    transition: background 0.12s, border-color 0.12s;
}

.chart-tab:hover {
    background: #d8eaf8;
    border-color: #7aaac8;
}

.chart-tab.active {
    background: var(--color-primary-dk);
    color: #fff;
    border-color: var(--color-primary-dk);
    font-weight: 600;
}

.chart-status {
    min-height: 1.4rem;
    font-size: 0.82rem;
    margin-bottom: 0.6rem;
    border-radius: 3px;
    padding: 0.2rem 0.4rem;
    line-height: 1.5;
}

.chart-status--loading    { color: #666; font-style: italic; }
.chart-status--ok         { color: #1d7a3a; }
.chart-status--info       { color: #555; }

.chart-status--error {
    background: #fde8e8;
    color: #b91c1c;
    padding: 0.45rem 0.75rem;
    border: 1px solid #f5c6c6;
}

.chart-status--unavailable {
    background: #fff8e8;
    color: #7a5500;
    padding: 0.45rem 0.75rem;
    border: 1px solid #f0d88a;
}

.chart-status-hint {
    font-size: 0.78rem;
    color: #a07020;
    font-style: italic;
}

/* M3.4 — multi-panel chart layout */
#chart-panels {
    margin-top: 0.25rem;
}

#chart-panels canvas {
    width: 100% !important;
    display: block;
}

.chart-panel {
    padding-bottom: 0.35rem;
    margin-bottom: 0.2rem;
    border-bottom: 1px solid #eef1f5;
}

.chart-panel--last {
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
}

.chart-panel-label {
    font-size: 0.7rem;
    font-weight: 700;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.1rem;
    padding-left: 0.2rem;
}

/* ============================================================
   M3.8 — Chart export buttons
   ============================================================ */

.chart-export-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0.75rem 0 0.25rem;
}

.chart-export-btn {
    padding: 0.35rem 0.9rem;
    font-size: 0.82rem;
    font-weight: 600;
    border: 1px solid #94a3b8;
    border-radius: 4px;
    background: #f8fafc;
    color: #334155;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.chart-export-btn:hover:not(:disabled) {
    background: #e2e8f0;
    border-color: #64748b;
}

.chart-export-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ============================================================
   M3.8 — Print-only institutional header (hidden on screen)
   ============================================================ */

.chart-print-header {
    display: none;
}

/* ============================================================
   M3.8 — Data summary block
   ============================================================ */

.chart-summary {
    margin: 1rem 0 0;
    padding: 0.75rem 1rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
}

.chart-summary-title {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #475569;
    margin-bottom: 0.5rem;
}

.chart-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.25rem 1.5rem;
}

.chart-summary-row {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    font-size: 0.82rem;
    padding: 0.15rem 0;
    border-bottom: 1px solid #e8edf3;
}

.chart-summary-label {
    color: #64748b;
    flex-shrink: 0;
}

.chart-summary-value {
    font-weight: 600;
    color: #1e293b;
    text-align: right;
}

/* ============================================================
   M3.8 — Data table block
   ============================================================ */

.chart-data-table-wrap {
    margin: 0.75rem 0 0;
    overflow-x: auto;
}

.chart-data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
}

.chart-data-table th,
.chart-data-table td {
    text-align: right;
    padding: 0.25rem 0.5rem;
    border-bottom: 1px solid #eaecf0;
    white-space: nowrap;
}

.chart-data-table th:first-child,
.chart-data-table td:first-child {
    text-align: left;
}

.chart-data-table th {
    background: #f0f5fb;
    font-weight: 700;
    color: #334155;
    position: sticky;
    top: 0;
}

.chart-data-table-note {
    font-size: 0.8rem;
    color: #64748b;
    font-style: italic;
    padding: 0.5rem 0;
}

/* ============================================================
   M3.8 — Print layout (@media print)
   ============================================================ */

@media print {
    /* Hide non-content UI */
    .site-header,
    .site-nav,
    .sidebar,
    .site-footer,
    .chart-tabs,
    .chart-export-actions,
    .chart-status,
    .graphs-subnav,
    .card--info {
        display: none !important;
    }

    /* Show print header */
    .chart-print-header {
        display: flex;
        align-items: center;
        gap: 1rem;
        background: #1E293B;
        color: #fff;
        padding: 0.6rem 1rem;
        margin-bottom: 1rem;
        border-radius: 4px;
    }

    .chart-print-logo img {
        max-height: 44px;
        width: auto;
    }

    /* INAF logo has a clean transparent background — inverting it to white
       reads correctly on this dark header, same treatment as the homepage
       hero would need if it inverted logos (it doesn't). The OAPA logo
       carries non-transparent content that this same invert flattens into
       a solid white disc, so it keeps its natural colours instead — exactly
       how it already renders correctly elsewhere on an equally dark
       background (see .institutional-logo on the homepage hero, no invert
       filter there either). */
    .chart-print-logo--left img {
        filter: brightness(0) invert(1);
    }

    .chart-print-content {
        flex: 1;
        text-align: center;
    }

    .chart-print-title {
        font-size: 1rem;
        font-weight: 700;
        letter-spacing: 0.03em;
    }

    .chart-print-coords,
    .chart-print-org {
        font-size: 0.72rem;
        opacity: 0.85;
    }

    .chart-print-meta {
        font-size: 0.7rem;
        opacity: 0.75;
        margin-top: 0.15rem;
    }

    /* Full-width single-column layout */
    .site-main {
        padding: 0;
        margin: 0;
    }

    .card--charts {
        box-shadow: none;
        border: none;
        padding: 0;
    }

    /* Each chart panel avoids page breaks inside */
    .chart-panel {
        break-inside: avoid;
        page-break-inside: avoid;
        margin-bottom: 0.5rem;
    }

    /* Summary and data table remain visible */
    .chart-summary,
    .chart-data-table-wrap {
        display: block !important;
        break-inside: avoid;
        page-break-inside: avoid;
    }

    /* Export buttons already hidden via .chart-export-actions above */
}

/* ============================================================
   Station description table
   ============================================================ */

.station-vars {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
    margin-top: 0.5rem;
}

.station-vars th,
.station-vars td {
    text-align: left;
    padding: 0.35rem 0.6rem;
    border-bottom: 1px solid #eaecf0;
}

.station-vars th {
    background: #f0f5fb;
    color: var(--color-primary-dk);
    font-weight: 600;
    border-bottom: 2px solid #c8d8ec;
}

.station-vars tr:last-child td { border-bottom: none; }
.station-vars code { font-size: 0.82em; }

.station-links-list {
    list-style: none;
    padding: 0;
    margin: 0.25rem 0 0;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.station-links-list li a {
    display: inline-block;
    color: var(--color-primary);
    font-size: 0.92rem;
    text-decoration: none;
}

.station-links-list li a:hover { text-decoration: underline; }

/* ============================================================
   Card title alignment utilities
   ============================================================ */

.card-title--center { text-align: center; }

/* ============================================================
   M3.2 / M3.4 — Institutional intro
   ============================================================ */

.institutional-intro {
    background: var(--color-primary-dk);
    color: #e2eaf5;
    border-radius: var(--radius);
    padding: 1rem 1.5rem;
    margin-bottom: 1.25rem;
    display: grid;
    grid-template-columns: 110px 1fr 110px;
    align-items: center;
    gap: 1.25rem;
}

.institutional-logo {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.institutional-logo--left  { justify-content: flex-start; }
.institutional-logo--right { justify-content: flex-end; }

.institutional-logo img {
    max-height: 68px;
    width: 100%;
    max-width: 100%;
    object-fit: contain;
    display: block;
}

.institutional-content {
    text-align: center;
}

.institutional-name {
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    color: #fff;
}

.institutional-system {
    font-size: 0.88rem;
    color: #93c5fd;
    margin-top: 0.15rem;
    font-weight: 500;
}

.institutional-wigos {
    font-size: 0.8rem;
    color: #93c5fd;
    margin-top: 0.3rem;
    margin-bottom: 0;
}

.institutional-desc {
    font-size: 0.8rem;
    color: #94a3b8;
    margin-top: 0.35rem;
}

.institutional-intro a {
    color: #93c5fd;
    text-underline-offset: 2px;
}
.institutional-intro a:hover { color: #bfdbfe; }

.institutional-location {
    display: inline-flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: baseline;
    gap: 0.15rem 0.5rem;
}

/* ============================================================
   Archive search form
   ============================================================ */

.archive-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem 1rem;
    align-items: flex-end;
    margin-bottom: 1rem;
}

.archive-form-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.archive-form-field > label {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #4a6a8a;
}

.archive-form input[type="datetime-local"],
.archive-form select {
    padding: 0.38rem 0.6rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-size: 0.88rem;
    background: #fff;
    color: #334155;
    min-width: 0;
}

.archive-form button[type="submit"] {
    padding: 0.42rem 1.1rem;
    background: var(--color-primary);
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 1px;
}

.archive-form button[type="submit"]:hover {
    background: var(--color-primary-dk);
}

.btn-csv {
    display: inline-block;
    padding: 0.38rem 0.9rem;
    background: #f0f5fb;
    color: #334155;
    border: 1px solid #c8d8ec;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}

.btn-csv:hover {
    background: #e0ebf5;
    text-decoration: none;
}

.archive-results-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.archive-error-list {
    list-style: none;
    padding: 0.5rem 0.8rem;
    margin: 0 0 1rem;
    background: #fff5f5;
    border-left: 3px solid #ef4444;
    border-radius: 4px;
    font-size: 0.9rem;
    color: #b91c1c;
}

.archive-error-list li + li { margin-top: 0.25rem; }

/* ============================================================
   M3.2 — Archive Size stats grid
   ============================================================ */

.archive-stats {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.archive-stat {
    background: #f0f5fb;
    border: 1px solid #c8d8ec;
    border-radius: var(--radius);
    padding: 0.6rem 0.9rem;
}

.archive-stat-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #4a6a8a;
    margin-bottom: 0.25rem;
}

.archive-stat-value {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--color-primary-dk);
}

/* ============================================================
   M3.2 — Health Status grid
   ============================================================ */

.health-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.health-item {
    background: #f0f5fb;
    border: 1px solid #c8d8ec;
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
}

.health-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #4a6a8a;
    margin-bottom: 0.4rem;
}

.health-value {
    font-size: 0.92rem;
    color: #334155;
    font-weight: 500;
}

/* Neutral badge (disabled / not configured) */
.badge--neutral {
    background: #f1f5f9;
    color: #475569;
}

/* ============================================================
   M3.3.1 — Language dropdown (stile SPA details/summary + PNG flag)
   ============================================================ */

/* Adattamento da SPA: position:relative; ora dentro .header-actions (flex) */
.lang-dropdown {
    position: relative;
}

.lang-dropdown summary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.4px;
    cursor: pointer;
    list-style: none;
    border: 1.5px solid rgba(255,255,255,0.45);
    color: #fff;
    background: rgba(255,255,255,0.08);
    user-select: none;
    transition: background 0.15s, border-color 0.15s;
}

.lang-dropdown summary::-webkit-details-marker { display: none; }
.lang-dropdown summary::after { content: ' \25BE'; font-size: 10px; opacity: 0.7; }
.lang-dropdown[open] summary::after { content: ' \25B4'; }

.lang-dropdown summary:hover {
    background: rgba(255,255,255,0.18);
    border-color: rgba(255,255,255,0.75);
}

.lang-dropdown-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.18);
    min-width: 110px;
    overflow: hidden;
    z-index: 200;
}

.lang-dropdown-menu a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    color: #374151;
    transition: background 0.1s;
}

.lang-dropdown-menu a:hover { background: #f3f4f6; text-decoration: none; }
.lang-dropdown-menu a.lang-active { background: #f0fdf4; color: #065f46; }

.lang-flag {
    width: 20px;
    height: auto;
    border-radius: 2px;
    vertical-align: middle;
}

/* ============================================================
   M3.3.5 — Graphs sub-navigation
   ============================================================ */

.graphs-subnav {
    font-size: 0.8rem;
    color: #64748b;
    margin-top: 0.75rem;
    padding-top: 0.5rem;
    border-top: 1px solid #e2e8f0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.2rem 0.4rem;
    align-items: center;
}

.graphs-subnav a { color: var(--color-primary); text-decoration: none; }
.graphs-subnav a:hover { text-decoration: underline; }

/* ============================================================
   M3.9 — Historical JPG gallery
   ============================================================ */

.legacy-plot-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1rem;
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid #e2e8f0;
}

.legacy-plot-filters label {
    font-size: 0.82rem;
    font-weight: 600;
    color: #475569;
}

.legacy-plot-filters select {
    font-size: 0.82rem;
    padding: 0.3rem 0.6rem;
    border: 1px solid #94a3b8;
    border-radius: 4px;
    background: #f8fafc;
    color: #334155;
    cursor: pointer;
}

.legacy-plot-reset {
    font-size: 0.8rem;
    color: #64748b;
    text-decoration: none;
    padding: 0.25rem 0.5rem;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
}
.legacy-plot-reset:hover { background: #f1f5f9; }

.legacy-plot-count {
    margin-left: auto;
    font-size: 0.78rem;
    color: #64748b;
}

.legacy-plot-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
}

.legacy-plot-card {
    border: 1px solid #e2e8f0;
    border-radius: var(--radius);
    overflow: hidden;
    background: #fff;
    display: flex;
    flex-direction: column;
    transition: box-shadow 0.15s;
}
.legacy-plot-card:hover {
    box-shadow: 0 3px 10px rgba(0,0,0,0.10);
}

.legacy-plot-image-link {
    display: block;
    background: #f8fafc;
    line-height: 0;
}

.legacy-plot-image {
    width: 100%;
    height: 160px;
    object-fit: cover;
    display: block;
    transition: opacity 0.2s;
}
.legacy-plot-image:hover { opacity: 0.9; }

.legacy-plot-meta {
    padding: 0.6rem 0.75rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    flex: 1;
}

.legacy-plot-title {
    font-size: 0.88rem;
    font-weight: 600;
    color: #1e293b;
    line-height: 1.3;
}

.legacy-plot-badges {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.3rem 0.5rem;
}

.legacy-plot-badge {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.1rem 0.45rem;
    border-radius: 3px;
}
.legacy-plot-badge--monthly   { background: #dbeafe; color: #1e40af; }
.legacy-plot-badge--bimonthly { background: #dcfce7; color: #166534; }
.legacy-plot-badge--yearly    { background: #fef3c7; color: #92400e; }

.legacy-plot-size {
    font-size: 0.72rem;
    color: #94a3b8;
}

.legacy-plot-open {
    font-size: 0.78rem;
    color: var(--color-primary);
    text-decoration: none;
    margin-top: auto;
    padding-top: 0.3rem;
}
.legacy-plot-open:hover { text-decoration: underline; }

/* ============================================================
   Graph configuration forms (graphs-temporal.php, graphs-comparative.php)
   ============================================================ */

.graph-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1.25rem;
    align-items: flex-start;
    margin-bottom: 1.25rem;
}

.graph-form-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.graph-form-field > label {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #4a6a8a;
}

.graph-form select {
    padding: 0.38rem 0.6rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-size: 0.88rem;
    background: #fff;
    color: #334155;
    min-width: 140px;
}

.graph-form select[multiple] {
    min-height: 110px;
    min-width: 120px;
}

.graph-form-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem 1rem;
    padding-top: 0.15rem;
}

.graph-form-check {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.88rem;
    color: #334155;
    cursor: pointer;
}

.graph-form-check input[type="checkbox"] {
    width: 14px;
    height: 14px;
    cursor: pointer;
}

.graph-form button[type="submit"] {
    padding: 0.42rem 1.25rem;
    background: var(--color-primary);
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    align-self: flex-end;
}

.graph-form button[type="submit"]:hover {
    background: var(--color-primary-dk);
}

.graph-panel-note {
    background: #f0f5fb;
    border: 1px solid #c8d8ec;
    border-left: 3px solid var(--color-primary);
    border-radius: 4px;
    padding: 1rem 1.25rem;
    font-size: 0.9rem;
    color: #334155;
    line-height: 1.6;
}

/* ============================================================
   Temporal chart panels (graphs-temporal.php)
   ============================================================ */

#temporal-panels {
    margin-top: 0.5rem;
}

#temporal-panels canvas {
    width: 100% !important;
    display: block;
}

.temporal-meta {
    font-size: 0.78rem;
    color: #64748b;
    margin-top: 0.75rem;
    padding-top: 0.5rem;
    border-top: 1px solid #eef1f5;
}

/* ============================================================
   Comparative chart panels (graphs-comparative.php)
   ============================================================ */

#comparative-panels {
    margin-top: 0.5rem;
}

#comparative-panels canvas {
    width: 100% !important;
    display: block;
}

.graph-form-field--wide {
    flex-basis: 100%;
}

/* ============================================================
   Graph navigation cards (graphs.php)
   ============================================================ */

.graph-nav-cards {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.graph-nav-card {
    display: flex;
    background: var(--color-card-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    box-shadow: var(--shadow-sm);
    min-height: 160px;
    transition: box-shadow 0.18s, border-color 0.18s;
}

.graph-nav-card:hover {
    box-shadow: 0 4px 20px rgba(0,0,0,0.12);
    border-color: var(--color-primary);
    color: inherit;
    text-decoration: none;
}

.graph-nav-card__img-wrap {
    flex: 0 0 280px;
    overflow: hidden;
    background: #d8e6f0;
}

.graph-nav-card__img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.graph-nav-card__body {
    flex: 1;
    padding: 1.5rem 1.75rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.4rem;
}

.graph-nav-card__title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--color-primary-dk);
}

.graph-nav-card__desc {
    font-size: 0.9rem;
    color: #4a5568;
    line-height: 1.55;
}

.graph-nav-card__cta {
    display: inline-block;
    margin-top: 0.2rem;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--color-primary);
}

.graph-nav-card:hover .graph-nav-card__cta { text-decoration: underline; }

/* ============================================================
   Mobile / responsive
   ============================================================ */

@media (max-width: 700px) {
    .app-body { flex-direction: column; }

    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
        padding: 0.4rem 0;
    }

    .nav-list {
        display: flex;
        flex-wrap: wrap;
    }

    .nav-item {
        padding: 0.4rem 0.9rem;
        border-left: none;
        border-bottom: 2px solid transparent;
    }

    .nav-item--active {
        border-bottom-color: var(--color-primary);
        border-left-color: transparent;
    }

    .site-main {
        padding: 1rem;
    }

    .header-sub    { display: none; }
    .header-center { display: none; }

    .header-inner {
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex-wrap: nowrap;
        gap: 0.5rem;
    }

    .footer-inner {
        grid-template-columns: 1fr;
        text-align: center;
        gap: 0.2rem 0;
        padding: 0.4rem 1rem;
    }

    .footer-left,
    .footer-right { text-align: center; }

    .institutional-intro {
        grid-template-columns: 1fr;
        gap: 0.75rem;
        padding: 1rem;
        text-align: center;
    }

    .institutional-logo,
    .institutional-logo--left,
    .institutional-logo--right { justify-content: center; }

    .institutional-logo img { max-height: 52px; }

    .weather-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }

    .quicklinks {
        grid-template-columns: 1fr 1fr;
    }

    .graph-nav-card {
        flex-direction: column;
    }

    .graph-nav-card__img-wrap {
        flex: 0 0 140px;
    }
}

/* ============================================================
   Normali Climatiche — page anchors nav
   ============================================================ */

.normali-anchors {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 0.75rem;
    font-size: 0.82rem;
    padding: 0.6rem 0;
    border-bottom: 1px solid #e2e8f0;
    margin-bottom: 0.5rem;
    color: #64748b;
}

.normali-anchors a {
    color: var(--color-primary);
    text-decoration: none;
    white-space: nowrap;
}

.normali-anchors a:hover { text-decoration: underline; }

/* ============================================================
   Normali Climatiche — section header
   ============================================================ */

.normali-section-heading {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-primary-dk);
    margin: 0 0 0.75rem;
    padding-bottom: 0.35rem;
    border-bottom: 2px solid #c8d8ec;
}

/* ============================================================
   Normali Climatiche — chart image gallery
   ============================================================ */

.normali-plot-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 1rem;
    margin-top: 0.75rem;
}

.normali-plot-card {
    border: 1px solid #e2e8f0;
    border-radius: var(--radius);
    overflow: hidden;
    background: #fff;
    display: flex;
    flex-direction: column;
    transition: box-shadow 0.15s;
}

.normali-plot-card:hover {
    box-shadow: 0 3px 10px rgba(0,0,0,0.10);
}

.normali-plot-thumb-link {
    display: block;
    background: #f0f5fb;
    line-height: 0;
}

.normali-plot-thumb {
    width: 100%;
    height: 150px;
    object-fit: cover;
    display: block;
    transition: opacity 0.2s;
}

.normali-plot-thumb:hover { opacity: 0.88; }

.normali-plot-meta {
    padding: 0.6rem 0.8rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    flex: 1;
}

.normali-plot-title {
    font-size: 0.88rem;
    font-weight: 600;
    color: #1e293b;
    line-height: 1.3;
}

.normali-plot-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 0.7rem;
    margin-top: auto;
    padding-top: 0.35rem;
}

.normali-plot-links a {
    font-size: 0.78rem;
    color: var(--color-primary);
    text-decoration: none;
}

.normali-plot-links a:hover { text-decoration: underline; }

.normali-img-missing {
    width: 100%;
    height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8fafc;
    color: #94a3b8;
    font-size: 0.8rem;
}

/* ============================================================
   Normali Climatiche — annual full image
   ============================================================ */

.normali-annual-img-wrap {
    text-align: center;
    margin: 0.75rem 0;
}

.normali-annual-img-wrap a {
    display: inline-block;
    line-height: 0;
}

.normali-annual-thumb {
    max-width: 100%;
    height: auto;
    border: 1px solid #e2e8f0;
    border-radius: var(--radius);
    transition: opacity 0.2s;
}

.normali-annual-thumb:hover { opacity: 0.88; }

/* ============================================================
   Normali Climatiche — anno tipo large images
   ============================================================ */

.normali-annotype-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1rem;
    margin-top: 0.75rem;
}

.normali-annotype-item {
    border: 1px solid #e2e8f0;
    border-radius: var(--radius);
    overflow: hidden;
    background: #fff;
}

.normali-annotype-link {
    display: block;
    line-height: 0;
}

.normali-annotype-img {
    width: 100%;
    height: auto;
    display: block;
    transition: opacity 0.2s;
}

.normali-annotype-img:hover { opacity: 0.88; }

.normali-annotype-caption {
    font-size: 0.8rem;
    color: #64748b;
    padding: 0.5rem 0.75rem 0.6rem;
    line-height: 1.4;
}

.normali-annotype-caption a {
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 600;
}

.normali-annotype-caption a:hover { text-decoration: underline; }

/* ============================================================
   Normali Climatiche — data summary table
   ============================================================ */

.normali-summary-table-wrap {
    overflow-x: auto;
    margin-top: 0.5rem;
}

.normali-summary-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
    white-space: nowrap;
}

.normali-summary-table th,
.normali-summary-table td {
    text-align: right;
    padding: 0.3rem 0.6rem;
    border-bottom: 1px solid #eaecf0;
}

.normali-summary-table th:first-child,
.normali-summary-table td:first-child {
    text-align: left;
    font-weight: 600;
}

.normali-summary-table th {
    background: #f0f5fb;
    font-weight: 700;
    color: var(--color-primary-dk);
    position: sticky;
    top: 0;
}

.normali-summary-table tr:hover td {
    background: #f8fafc;
}

.normali-summary-table .null-cell {
    color: #94a3b8;
}

/* ============================================================
   Normali Climatiche — download CSV list
   ============================================================ */

.normali-dl-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 0.6rem;
    margin-top: 0.75rem;
}

.normali-dl-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: var(--radius);
    padding: 0.6rem 0.9rem;
}

.normali-dl-label {
    font-size: 0.85rem;
    color: #1e293b;
    line-height: 1.3;
}

.normali-dl-btn {
    flex-shrink: 0;
    display: inline-block;
    padding: 0.28rem 0.75rem;
    background: var(--color-primary);
    color: #fff;
    border-radius: 4px;
    font-size: 0.78rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}

.normali-dl-btn:hover {
    background: var(--color-primary-dk);
    text-decoration: none;
    color: #fff;
}

.normali-dl-btn--disabled {
    background: #94a3b8;
    cursor: not-allowed;
    pointer-events: none;
}

/* ============================================================
   Normali Climatiche — methodology note box
   ============================================================ */

.normali-method-box {
    background: #f0f5fb;
    border-left: 3px solid var(--color-primary);
    border-radius: 4px;
    padding: 0.9rem 1.1rem;
    font-size: 0.88rem;
    color: #334155;
    line-height: 1.65;
    margin-bottom: 0.75rem;
}

.normali-method-box + .normali-method-box { margin-top: 0.5rem; }

/* ============================================================
   Normali Climatiche — technical notes
   ============================================================ */

.normali-notes-list {
    list-style: none;
    padding: 0;
    margin: 0.5rem 0 0;
    font-size: 0.87rem;
    color: #475569;
    line-height: 1.6;
}

.normali-notes-list li {
    padding: 0.25rem 0;
    border-bottom: 1px solid #f1f5f9;
}

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

@media (max-width: 700px) {
    .normali-plot-grid  { grid-template-columns: 1fr 1fr; }
    .normali-annotype-grid { grid-template-columns: 1fr; }
    .normali-dl-list    { grid-template-columns: 1fr; }
}

/* ============================================================
   Custom date-range chart section (graphs-standard.php)
   ============================================================ */

.custom-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 1rem;
}

.custom-preset-btn {
    padding: 0.25rem 0.75rem;
    background: #f1f5f9;
    border: 1px solid #c8d8ec;
    border-radius: 20px;
    font-size: 0.82rem;
    color: var(--color-primary-dk);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.custom-preset-btn:hover {
    background: #dbeafe;
    border-color: var(--color-primary);
}

.graph-form input[type="datetime-local"] {
    padding: 0.38rem 0.6rem;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    font-size: 0.88rem;
    background: #fff;
    color: #334155;
    min-width: 180px;
}

#custom-chart-status {
    min-height: 1.4rem;
    font-size: 0.85rem;
    color: #64748b;
    margin: 0.5rem 0 0.25rem;
    line-height: 1.4;
}

#custom-chart-status.custom-status--error {
    color: #dc2626;
}

#custom-chart-panels canvas {
    width: 100% !important;
    display: block;
}

/* ============================================================
   Period chart panels — graphs-period.php
   Each variable renders in its own .card.period-panel section.
   ============================================================ */

.period-panel-title {
    font-size: 0.7rem;
    font-weight: 700;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin: 0 0 0.5rem;
    padding-left: 0.1rem;
}

.period-panel canvas {
    width: 100% !important;
    display: block;
}

#period-chart-status {
    min-height: 1.4rem;
    font-size: 0.85rem;
    color: #64748b;
    margin: 0.5rem 0 0.25rem;
    line-height: 1.4;
}

#period-chart-status.period-status--error {
    color: #dc2626;
}

@media (max-width: 700px) {
    .custom-presets { gap: 0.3rem; }
    .custom-preset-btn { font-size: 0.78rem; padding: 0.22rem 0.6rem; }
    .graph-form input[type="datetime-local"] { min-width: 0; width: 100%; }
}

/* Monthly charts page */
#monthly-chart-status {
    min-height: 1.4rem;
    font-size: 0.85rem;
    color: #64748b;
    margin: 0.75rem 0 0.25rem;
    line-height: 1.4;
}

#monthly-chart-status.monthly-status--error {
    color: #dc2626;
}

/*
 * Fixed-height wrapper for each monthly canvas.
 * Chart.js (responsive:true, maintainAspectRatio:false) observes the wrapper,
 * NOT the canvas — the wrapper must have position:relative and an explicit height
 * to break the grow→resize→grow infinite loop.
 */
.monthly-chart-canvas-wrap {
    position: relative;
    width: 100%;
    height: 320px;
    max-height: 360px;
    overflow: hidden;
}

.monthly-chart-canvas-wrap--sm {
    height: 200px;
    max-height: 240px;
}

.monthly-chart-canvas-wrap--last {
    margin-bottom: 0;
}

.monthly-chart-canvas-wrap canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

@media (max-width: 600px) {
    .monthly-chart-canvas-wrap      { height: 220px; max-height: 260px; }
    .monthly-chart-canvas-wrap--sm  { height: 160px; max-height: 190px; }
}

/* ============================================================
   Data-quality view mode — raw vs filtered (read-only toggle)
   ============================================================ */

/* Institutional box: gives the toggle its own visual container so it reads
   as a mode switch, not as extra breadcrumb/subnav links. */
.quality-mode-box {
    margin: 1.1rem 0 0.25rem;
    padding: 0.7rem 0.9rem;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: #f8fafc;
}

.quality-mode-box__label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #64748b;
    margin-bottom: 0.3rem;
}

.quality-mode-box__desc {
    font-size: 0.82rem;
    color: #64748b;
    margin: 0 0 0.6rem;
}

/* Segmented control: two touching buttons sharing one border, so the pair
   reads unambiguously as a single switch rather than two separate links. */
.quality-mode-toggle {
    display: inline-flex;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    overflow: hidden;
    background: #fff;
}

.quality-mode-btn {
    display: inline-block;
    padding: 0.4rem 0.9rem;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--color-primary-dk);
    background: #fff;
    text-decoration: none;
    line-height: 1.3;
    border-right: 1px solid var(--color-border);
    white-space: nowrap;
}

.quality-mode-btn:last-child {
    border-right: none;
}

.quality-mode-btn:hover {
    background: #eef2f7;
}

/* Active state signalled by fill + weight + a leading check mark — not
   colour alone (see the ::before content below). */
.quality-mode-btn--active {
    font-weight: 700;
    background: var(--color-primary);
    color: #fff;
}

.quality-mode-btn--active:hover {
    background: var(--color-primary-dk);
}

.quality-mode-btn--active::before {
    content: '\2713\0020'; /* check mark + space */
}

@media (max-width: 480px) {
    .quality-mode-toggle {
        display: flex;
        width: 100%;
    }
    .quality-mode-btn {
        flex: 1 1 50%;
        text-align: center;
        padding: 0.45rem 0.5rem;
    }
}

/* Per-panel "fully empty series" message — shown instead of a degenerate
   empty/0-1-axis chart when every point for a grandezza is null (e.g.
   humidity in filtered mode for a fully-flagged year). */
.chart-empty-msg {
    margin: 0.5rem 0 0;
    padding: 0.6rem 0.8rem;
    font-size: 0.82rem;
    color: #64748b;
    background: #f8fafc;
    border: 1px dashed var(--color-border);
    border-radius: 4px;
    text-align: center;
}
