    /* ── Reset & base ─────────────────────────────────────────── */
    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

    :root {
      --bg:        #0d1117;
      --panel:     #161b22;
      --border:    #30363d;
      --accent:    #00c853;
      --accent2:   #00a844;
      --text:      #e6edf3;
      --text-muted:#8b949e;
      --danger:    #c43e4a;
      --warn:      #d29922;
      --ok:        #3fb950;
      --font-ui:   'Segoe UI', system-ui, sans-serif;
    }

    html, body { height: 100%; background: var(--bg); color: var(--text); font-family: var(--font-ui); }

    /* ── Layout ───────────────────────────────────────────────── */
    #app { display: flex; height: 100vh; overflow: hidden; }

    /* ── Sidebar ──────────────────────────────────────────────── */
    #sidebar {
      width: 320px; min-width: 320px;
      background: var(--panel);
      border-right: 1px solid var(--border);
      display: flex; flex-direction: column;
      overflow: hidden; z-index: 1000;
    }

    #sidebar-header {
      padding: 12px 14px 10px;
      border-bottom: 1px solid var(--border);
      background: #ffffff;
    }
    #sidebar-header p {
      font-size: .7rem; color: var(--text-muted); margin-top: 2px;
    }

    /* ── Nav menu SLAPIS ─────────────────────────────────────── */
    #slapis-nav {
      background: #000;
      padding: 10px 12px 12px;
      border-bottom: 1px solid var(--border);
    }

    .nav-grid {
      display: grid; grid-template-columns: 1fr 1fr;
      gap: 6px;
    }
    .nav-btn {
      display: flex; align-items: center; gap: 7px;
      padding: 9px 12px;
      background: #fff; border-radius: 5px;
      color: #000; font-size: .85rem; font-weight: 600;
      cursor: pointer; text-decoration: none;
      border: none; outline: none;
      transition: background .18s, color .18s;
      white-space: nowrap; overflow: hidden;
      text-overflow: ellipsis;
    }
    .nav-btn:hover { background: #00c853; color: #fff; }
    .nav-btn svg { flex-shrink: 0; }
    .nav-btn.nav-more {
      grid-column: 2 / 3; justify-self: end;
      background: transparent; border: 1.5px solid #444;
      color: #ccc; position: relative;
      overflow: visible;
    }
    .nav-btn.nav-more:hover { background: #00c853; border-color: #00c853; color: #fff; }

    /* Dropdown MORE */
    #more-dropdown {
      display: none; position: fixed;
      background: #161b22; border: 1px solid #30363d; border-radius: 7px;
      width: max-content;
      z-index: 9999; box-shadow: 0 8px 24px rgba(0,0,0,.5);
      overflow: visible;
    }
    #more-dropdown.open { display: block; }
    .more-item {
      display: block; padding: 10px 18px;
      color: #c9d1d9; font-size: .88rem; font-weight: 600;
      text-decoration: none; text-transform: uppercase; letter-spacing: .04em;
      border-bottom: 1px solid #21262d; cursor: pointer;
      transition: background .15s, color .15s;
      white-space: nowrap;
    }
    .more-item:last-child { border-bottom: none; }
    .more-item:hover { background: #00c853; color: #fff; }

    #sidebar-body { flex: 1; overflow-y: auto; padding: 12px 0; }
    #sidebar-body::-webkit-scrollbar { width: 5px; }
    #sidebar-body::-webkit-scrollbar-track { background: transparent; }
    #sidebar-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

    /* Layer groups */
    .layer-group { margin-bottom: 4px; }
    .group-header {
      display: flex; align-items: center; gap: 8px;
      padding: 7px 16px; cursor: pointer;
      font-size: .88rem; font-weight: 600; letter-spacing: .06em;
      text-transform: uppercase; color: var(--text-muted);
      user-select: none;
      transition: color .15s;
    }
    .group-header:hover { color: var(--text); }
    .group-header .arrow {
      margin-left: auto; transition: transform .2s;
      font-size: .6rem; opacity: .6;
    }
    .group-header.open .arrow { transform: rotate(90deg); }

    .group-items { display: none; }
    .group-items.open { display: block; }

    /* Layer item */
    .layer-item {
      display: flex; align-items: center; gap: 10px;
      padding: 6px 16px 6px 28px; cursor: pointer;
      font-size: .88rem; border-radius: 4px;
      transition: background .12s;
      user-select: none;
    }
    .layer-item:hover { background: rgba(255,255,255,.04); }
    .layer-item.active { color: var(--text); }
    .layer-item:not(.active) { color: var(--text-muted); }

    /* Custom checkbox */
    .layer-check {
      width: 15px; height: 15px; border-radius: 3px;
      border: 1.5px solid var(--border); flex-shrink: 0;
      display: flex; align-items: center; justify-content: center;
      transition: background .12s, border-color .12s;
    }
    .layer-item.active .layer-check {
      background: var(--accent2); border-color: var(--accent2);
    }
    .layer-check::after {
      content: '✓'; font-size: .6rem; color: #fff;
      opacity: 0; transition: opacity .1s;
    }
    .layer-item.active .layer-check::after { opacity: 1; }

    /* Color swatch */
    .layer-swatch {
      width: 22px; height: 6px; border-radius: 2px; flex-shrink: 0;
    }

    /* Loading badge */
    .layer-loading {
      margin-left: auto; font-size: .85rem; color: var(--warn);
      animation: pulse 1s infinite;
    }
    @keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }

    /* Basemap selector */
    #basemap-section {
      border-top: 1px solid var(--border);
      padding: 10px 16px 14px;
    }
    #basemap-section label {
      font-size: .85rem; font-weight: 600; letter-spacing: .06em;
      text-transform: uppercase; color: var(--text-muted);
      display: block; margin-bottom: 8px;
    }
    .basemap-btns { display: flex; gap: 6px; }
    .bm-btn {
      flex: 1; padding: 6px; font-size: .85rem; font-weight: 500;
      border: 1.5px solid var(--border); border-radius: 5px;
      background: transparent; color: var(--text-muted); cursor: pointer;
      transition: all .15s;
    }
    .bm-btn:hover { border-color: var(--accent); color: var(--text); }
    .bm-btn.active { border-color: var(--accent2); color: var(--accent); background: rgba(47,129,247,.1); }

    /* ── Map ──────────────────────────────────────────────────── */
    #map { flex: 1; background: #1a2332; }

    /* ── Popup ────────────────────────────────────────────────── */
    .leaflet-popup-content-wrapper {
      background: var(--panel) !important;
      border: 1px solid var(--border) !important;
      border-radius: 8px !important;
      box-shadow: 0 8px 32px rgba(0,0,0,.6) !important;
      padding: 0 !important;
    }
    .leaflet-popup-tip { background: var(--panel) !important; }
    .leaflet-popup-content { margin: 0 !important; width: auto !important; }
    .leaflet-popup-close-button { color: var(--text-muted) !important; font-size: 18px !important; top: 8px !important; right: 10px !important; }

    .popup-inner { padding: 17px 20px; min-width: 360px; max-width: 420px; }

    /* Blocco osservato + graphique complet */
    .popup-obs-chart-block {
      margin-top: 4px; width: 100%; padding: 14px 14px;
      border-radius: 10px; border: 1px solid rgba(21,172,232,.25);
      background: rgba(21,172,232,.06); cursor: pointer;
      transition: background .15s, border-color .15s;
      box-sizing: border-box;
    }
    .popup-obs-chart-block:hover {
      background: rgba(21,172,232,.14);
      border-color: rgba(21,172,232,.5);
    }
    .popup-obs-row {
      display: flex; align-items: stretch; gap: 12px;
    }
    .popup-obs-left {
      flex: 1; min-width: 120px;
      border-right: 1px solid rgba(255,255,255,.08);
      padding-right: 12px;
    }
    .popup-obs-label {
      font-size: .85rem; font-weight: 700; text-transform: uppercase;
      letter-spacing: .04em; color: var(--text-muted); margin-bottom: 6px;
      white-space: nowrap;
    }
    .popup-obs-val {
      font-size: 1.8rem; font-weight: 700; line-height: 1;
      white-space: nowrap;
    }
    .popup-obs-unit {
      font-size: .9rem; font-weight: 500; opacity: .55;
    }
    .popup-obs-date {
      font-size: .85rem; color: var(--text-muted); margin-top: 8px;
    }
    .popup-obs-fresh-row {
      font-size: .85rem; color: var(--text-muted); margin-top: 3px;
      display: flex; align-items: center; gap: 5px;
      opacity: .8;
    }
    /* Pallini freshness */
    .obs-dot {
      display: inline-block; width: 7px; height: 7px;
      border-radius: 50%; flex-shrink: 0;
    }
    .obs-dot-green  { background: #3fb950; box-shadow: 0 0 4px #3fb95088; }
    .obs-dot-orange { background: #e07b30; box-shadow: 0 0 4px #e07b3088; }
    .obs-dot-red    { background: #c43e4a; box-shadow: 0 0 4px #c43e4a88; }
    .obs-dot-grey   { background: #8b949e; }

    .popup-obs-right {
      display: flex; flex-direction: column;
      align-items: center; justify-content: center;
      flex-shrink: 0; text-align: center;
      gap: 1px; padding-left: 2px;
      max-width: 130px;
    }
    .popup-obs-chart-label {
      font-size: .85rem; font-weight: 700; color: var(--text);
      line-height: 1.2; margin-bottom: 4px;
    }
    .popup-obs-chart-sub {
      font-size: .85rem; color: var(--text-muted); line-height: 1.2;
    }

    /* Mini-cards modelli */
    .popup-model-cards { display: flex; gap: 6px; margin-top: 8px; }
    .popup-model-card {
      flex: 1; padding: 7px 8px; border-radius: 7px;
      border: 1px solid var(--border); cursor: pointer;
      transition: border-color .15s, background .15s;
      background: rgba(255,255,255,.03);
      overflow: hidden; box-sizing: border-box;
      min-width: 0;
    }
    .popup-model-card:hover { border-color: var(--accent); background: rgba(21,172,232,.08); }
    .popup-model-card-title { font-size: .85rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .popup-model-card-val { font-size: 1.3rem; font-weight: 700; line-height: 1; white-space: nowrap; }
    .popup-model-card-sub { font-size: .85rem; color: var(--text-muted); margin-top: 3px; white-space: nowrap; }

    /* Soglie vigilanza nel popup */
    .popup-seuils {
      margin-top: 10px; padding: 8px 10px;
      background: rgba(255,255,255,.04);
      border: 1px solid var(--border);
      border-radius: 6px;
    }
    .popup-seuils-title {
      font-size: .85rem; font-weight: 700; letter-spacing: .06em;
      text-transform: uppercase; color: var(--text-muted); margin-bottom: 6px;
    }
    .seuils-row { display: flex; gap: 6px; }
    .seuil-chip {
      flex: 1; text-align: center; padding: 4px 2px;
      border-radius: 5px; font-size: .85rem; font-weight: 700;
    }

    /* Sezione serie storiche nel popup */
    .popup-series {
      margin-top: 6px; padding: 8px 10px;
      background: rgba(255,255,255,.03);
      border: 1px solid var(--border); border-radius: 6px;
    }
    .popup-series-title {
      font-size: .85rem; font-weight: 700; letter-spacing: .05em;
      text-transform: uppercase; color: var(--text-muted); margin-bottom: 7px;
    }

    /* Separatore sezione Observations et Prévisions */
    .popup-section-divider {
      margin: 18px 0 14px;
      border-top: 1.5px solid var(--border);
      text-align: center;
      position: relative;
      height: 0;
    }
    .popup-section-divider span {
      position: relative;
      top: -9px;
      background: var(--panel);
      padding: 0 10px;
      font-size: .85rem;
      font-weight: 700;
      letter-spacing: .05em;
      text-transform: uppercase;
      color: var(--text-muted);
    }

    /* Label modelli individuali */
    .popup-models-label {
      font-size: .85rem; font-weight: 700; text-transform: uppercase;
      letter-spacing: .05em; color: var(--text-muted);
      margin-bottom: 6px;
      padding-bottom: 4px;
      border-bottom: 1px solid rgba(255,255,255,.06);
    }
    .series-row { display: flex; gap: 6px; }
    .series-btn {
      flex: 1; padding: 7px 6px; border-radius: 6px; border: 1px solid var(--border);
      background: rgba(255,255,255,.05); color: var(--text);
      font-size: .86rem; font-weight: 600; cursor: pointer;
      transition: background .15s, border-color .15s;
      text-align: center;
    }
    .series-btn:hover { background: rgba(255,255,255,.1); border-color: var(--text-muted); }
    .series-btn.disabled { opacity: .4; cursor: default; pointer-events: none; }

    /* Monographie station button */
    .popup-mono-btn {
      display: flex; align-items: center; gap: 10px;
      margin-top: 8px; width: 100%; padding: 12px 14px;
      border-radius: 8px; border: none;
      background: rgba(0,210,210,.06); color: var(--text);
      text-decoration: none; cursor: pointer;
      transition: background .15s, color .15s;
    }
    .popup-mono-btn:hover {
      background: rgba(0,210,210,.15); color: #00d4d4;
    }

    /* Grafico live placeholder */
    .popup-live {
      margin-top: 10px; padding: 8px 10px;
      background: rgba(63,185,80,.05);
      border: 1px solid rgba(63,185,80,.2); border-radius: 6px;
    }
    .popup-live-title {
      font-size: .85rem; font-weight: 700; letter-spacing: .06em;
      text-transform: uppercase; color: #3fb950; margin-bottom: 5px;
      display: flex; align-items: center; gap: 5px;
    }
    .live-dot {
      width: 7px; height: 7px; background: #3fb950;
      border-radius: 50%; animation: pulse 1.4s infinite;
    }

    /* ── Modal Serie Storica ──────────────────────────── */
    #series-overlay {
      display: none; position: fixed; inset: 0;
      background: rgba(0,0,0,.6); backdrop-filter: blur(3px);
      z-index: 2100; align-items: center; justify-content: center;
    }
    #series-overlay.open { display: flex; }
    #series-modal {
      background: var(--panel); border: 1px solid var(--border);
      border-radius: 12px; box-shadow: 0 24px 80px rgba(0,0,0,.7);
      width: min(1000px, 96vw); max-height: 90vh;
      display: flex; flex-direction: column; overflow: hidden;
      animation: modalIn .22s cubic-bezier(.4,0,.2,1);
    }
    #series-modal-header {
      padding: 13px 18px; border-bottom: 1px solid var(--border);
      display: flex; align-items: center; gap: 10px;
      background: var(--bg); flex-shrink: 0;
    }
    #series-modal-title { flex: 1; font-size: 1.14rem; font-weight: 700; color: var(--text); }
    #series-modal-close {
      background: none; border: none; color: var(--text-muted);
      font-size: 1.3rem; cursor: pointer; padding: 4px 8px;
      border-radius: 6px; transition: background .12s;
    }
    #series-modal-close:hover { background: var(--border); color: var(--text); }
    #series-modal-body { display: flex; flex-direction: column; padding: 16px 20px 20px; gap: 14px; overflow-y: auto; }
    #series-modal-body::-webkit-scrollbar { width: 5px; }
    #series-modal-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
    .series-controls {
      display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
    }
    .series-controls-row2 {
      margin-top: -4px;
    }
    .series-date-label {
      font-size: .85rem; color: var(--text-muted); font-weight: 600;
    }
    .series-date-input {
      background: var(--bg); border: 1px solid var(--border);
      color: var(--text); padding: 5px 8px; border-radius: 6px;
      font-size: .85rem; cursor: pointer;
      color-scheme: dark;
    }
    .series-date-input:focus { outline: none; border-color: var(--accent); }
    .series-select {
      background: var(--bg); border: 1px solid var(--border);
      color: var(--text); padding: 6px 10px; border-radius: 6px;
      font-size: .8rem; cursor: pointer;
    }
    .series-select:focus { outline: none; border-color: var(--accent); }
    .series-type-btn {
      padding: 5px 14px; border-radius: 6px; border: 1px solid var(--border);
      background: transparent; color: var(--text-muted); font-size: .85rem;
      cursor: pointer; transition: all .15s;
    }
    .series-type-btn.active {
      background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 700;
    }
    .series-separator {
      display: inline-block; width: 1px; height: 22px;
      background: var(--border); margin: 0 2px;
    }
    .series-view-btn {
      padding: 5px 10px; border-radius: 6px; border: 1px solid var(--border);
      background: transparent; color: var(--text-muted); font-size: .85rem;
      cursor: pointer; transition: all .15s; line-height: 1;
    }
    .series-view-btn.active {
      background: rgba(21,172,232,.15); color: #15ace8;
      border-color: rgba(21,172,232,.4);
    }
    .series-view-btn:hover { border-color: var(--text-muted); }
    .series-export-btn {
      padding: 5px 10px; border-radius: 6px; border: 1px solid var(--border);
      background: transparent; color: var(--text-muted); font-size: .85rem;
      font-weight: 600; cursor: pointer; transition: all .15s;
      letter-spacing: .02em;
    }
    .series-export-btn:hover {
      background: rgba(255,255,255,.06); border-color: var(--text-muted);
      color: var(--text);
    }
    /* Tabella serie storiche */
    .series-table-wrap {
      max-height: 400px; overflow-y: auto;
      border: 1px solid var(--border); border-radius: 8px;
    }
    .series-table-wrap::-webkit-scrollbar { width: 5px; }
    .series-table-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
    .series-table {
      width: 100%; border-collapse: collapse; font-size: .88rem;
    }
    .series-table thead {
      position: sticky; top: 0; z-index: 1;
    }
    .series-table th {
      background: var(--bg); color: var(--text-muted);
      font-weight: 700; font-size: .85rem; text-transform: uppercase;
      letter-spacing: .04em; padding: 8px 14px; text-align: left;
      border-bottom: 1.5px solid var(--border);
    }
    .series-table td {
      padding: 5px 14px; color: var(--text);
      border-bottom: 1px solid rgba(255,255,255,.04);
    }
    .series-table tr:hover td {
      background: rgba(255,255,255,.03);
    }
    #series-chart-wrap { flex: 1; min-height: 280px; }
    #series-loading {
      font-size: .8rem; color: var(--text-muted);
      text-align: center; padding: 40px 0;
      animation: pulse 1s infinite;
    }
    .popup-title {
      font-size: 1.14rem; font-weight: 700; color: var(--accent);
      margin-bottom: 12px; padding-bottom: 9px;
      border-bottom: 1px solid var(--border);
    }
    .popup-row { display: flex; gap: 8px; margin-bottom: 6px; font-size: .94rem; }
    .popup-label { color: var(--text-muted); min-width: 90px; flex-shrink: 0; }
    .popup-value { color: var(--text); word-break: break-word; }
    .popup-glofas {
      margin-top: 10px; padding: 8px 10px;
      background: rgba(21,172,232,.08); border: 1px solid rgba(21,172,232,.2);
      border-radius: 6px; overflow: hidden;
    }
    .popup-glofas-title { font-size: .85rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--accent); margin-bottom: 6px; }
    .glofas-val { font-size: 1.4rem; font-weight: 700; }
    .glofas-sub { font-size: .85rem; color: var(--text-muted); margin-top: 1px; }
    .glofas-loading { font-size: .85rem; color: var(--text-muted); animation: pulse 1s infinite; }

    /* ── Chart Modal – popup rettangolare orizzontale ─────────── */
    #chart-overlay {
      display: none;
      position: fixed; inset: 0;
      background: rgba(0,0,0,.55);
      backdrop-filter: blur(3px);
      z-index: 2000;
      align-items: center; justify-content: center;
    }
    #chart-overlay.open { display: flex; }

    #chart-modal {
      background: var(--panel);
      border: 1.5px solid rgba(21,172,232,.3);
      border-radius: 14px;
      box-shadow: 0 32px 100px rgba(0,0,0,.8), 0 0 0 1px rgba(21,172,232,.1);
      width: min(1100px, 96vw);
      max-height: 92vh;
      min-height: 420px;
      display: flex; flex-direction: column;
      overflow: hidden;
      animation: modalIn .22s cubic-bezier(.4,0,.2,1);
    }
    @keyframes modalIn {
      from { opacity:0; transform: scale(.96) translateY(12px); }
      to   { opacity:1; transform: scale(1)  translateY(0); }
    }

    #chart-modal-header {
      padding: 14px 18px 12px;
      border-bottom: 1px solid var(--border);
      display: flex; align-items: center; gap: 12px;
      background: var(--bg); flex-shrink: 0;
    }
    #chart-modal-icon {
      font-size: 1.5rem; line-height: 1;
    }
    #chart-panel-title {
      flex: 1; font-size: 1.2rem; font-weight: 700; color: var(--text);
    }
    #chart-modal-meta {
      font-size: .86rem; color: var(--text-muted);
    }
    #chart-panel-back {
      background: none; border: 1px solid var(--border); color: var(--text-muted);
      font-size: .85rem; font-weight: 600; cursor: pointer; padding: 5px 12px;
      border-radius: 6px; transition: background .12s, color .12s, border-color .12s;
      margin-right: 6px;
    }
    #chart-panel-back:hover { background: var(--border); color: var(--text); border-color: var(--text-muted); }
    #chart-panel-close {
      background: none; border: none; color: var(--text-muted);
      font-size: 1.3rem; cursor: pointer; padding: 4px 8px;
      border-radius: 6px; transition: background .12s, color .12s;
      line-height: 1;
    }
    #chart-panel-close:hover { background: var(--border); color: var(--text); }

    #chart-modal-body {
      display: grid; grid-template-columns: 240px 1fr;
      gap: 0; overflow: hidden; flex: 1; min-height: 320px;
    }

    /* Colonna sinistra: info + stats */
    #chart-modal-left {
      padding: 20px 18px;
      border-right: 1px solid var(--border);
      overflow-y: auto;
      display: flex; flex-direction: column; gap: 10px;
    }
    #chart-modal-left::-webkit-scrollbar { width: 4px; }
    #chart-modal-left::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

    /* Colonna destra: grafico */
    #chart-modal-right {
      padding: 18px 20px 16px;
      display: flex; flex-direction: column;
      overflow: hidden;
    }

    #chart-panel-body {
      flex: 1; overflow-y: auto; padding: 0;
    }

    /* stat cards verticali */
    .chart-stat-card {
      background: rgba(255,255,255,.04);
      border: 1px solid var(--border);
      border-radius: 6px; padding: 6px 10px;
    }
    .chart-stat-label {
      font-size: .85rem; text-transform: uppercase; letter-spacing: .05em;
      color: var(--text-muted); margin-bottom: 2px;
    }
    .chart-stat-val {
      font-size: 1.15rem; font-weight: 700; color: var(--text); line-height: 1;
    }
    .chart-stat-unit {
      font-size: .85rem; color: var(--text-muted); margin-top: 2px;
    }
    .chart-section-title {
      font-size: .88rem; text-transform: uppercase; letter-spacing: .05em;
      color: var(--text-muted); font-weight: 600;
      margin: 4px 0 8px; padding-bottom: 5px;
      border-bottom: 1px solid var(--border);
    }

    .chart-run-info {
      font-size: .85rem; color: var(--text-muted);
      line-height: 1.6;
      padding: 7px 10px; background: rgba(255,255,255,.03);
      border-radius: 6px; border-left: 3px solid var(--accent);
    }
    .chart-run-info strong { color: var(--text); }
    .chart-peak-row {
      display: flex; align-items: baseline; gap: 6px; margin-bottom: 10px;
    }
    .chart-peak-val {
      font-size: 1.9rem; font-weight: 700; line-height: 1;
    }
    .chart-peak-label {
      font-size: .85rem; color: var(--text-muted); line-height: 1.5;
    }
    .chart-no-data {
      font-size: .85rem; color: var(--text-muted); padding: 10px 0;
      border-top: 1px solid var(--border); margin-top: 6px;
    }

    /* Btn nel popup compatto */
    .popup-chart-btn {
      display: block; width: 100%;
      margin-top: 12px; padding: 8px 14px;
      background: rgba(21,172,232,.1);
      border: 1px solid rgba(21,172,232,.3);
      border-radius: 6px; color: var(--accent);
      font-size: .8rem; font-weight: 600; cursor: pointer;
      text-align: left;
      transition: background .15s;
    }
    .popup-chart-btn:hover { background: rgba(21,172,232,.2); }

    /* ── Status bar ───────────────────────────────────────────── */
    #statusbar {
      position: absolute; bottom: 24px; left: 336px;
      background: rgba(22,27,34,.85); border: 1px solid var(--border);
      border-radius: 6px; padding: 5px 12px;
      font-size: .85rem; color: var(--text-muted);
      pointer-events: none; z-index: 900;
      backdrop-filter: blur(4px);
    }

    /* ── Leaflet overrides ────────────────────────────────────── */
    .leaflet-control-zoom a {
      background: var(--panel) !important; color: var(--text) !important;
      border-color: var(--border) !important;
    }
    .leaflet-control-zoom a:hover { background: var(--border) !important; }
    .leaflet-control-attribution {
      background: rgba(22,27,34,.8) !important; color: var(--text-muted) !important;
      font-size: .7rem !important;
    }
    .leaflet-control-attribution a { color: var(--accent) !important; }

    /* ── Situation Hydrologique Button ──────────────────────────── */
    #situation-btn {
      position: absolute;
      top: 14px;
      right: 14px;
      z-index: 1000;
      background: #000;
      color: #fff;
      border: none;
      border-radius: 30px;
      padding: 10px 18px 10px 20px;
      font-size: .88rem;
      font-weight: 700;
      cursor: pointer;
      letter-spacing: .02em;
      box-shadow: 0 2px 10px rgba(0,0,0,.55);
      transition: background .18s, box-shadow .18s;
      display: flex;
      align-items: center;
      gap: 10px;
      white-space: nowrap;
    }
    #situation-btn:hover {
      background: #1a1a1a;
      box-shadow: 0 4px 18px rgba(0,0,0,.7);
    }
    #situation-btn img {
      width: 26px;
      height: 26px;
      flex-shrink: 0;
    }

    /* ── Simulation Mode Button ───────────────────────────────── */
    #sim-mode-btn {
      position: absolute;
      top: 76px;
      right: 14px;
      z-index: 1000;
      background: var(--panel);
      color: var(--text);
      border: 1.5px solid var(--border);
      border-radius: 8px;
      padding: 8px 16px;
      font-size: .8rem;
      font-weight: 600;
      cursor: pointer;
      letter-spacing: .03em;
      box-shadow: 0 2px 8px rgba(0,0,0,.5);
      transition: all .2s;
    }
    #sim-mode-btn:hover {
      border-color: #00c853;
      color: #00c853;
    }
    #sim-mode-btn.active {
      background: rgba(196,62,74,0.15);
      border-color: #c43e4a;
      color: #c43e4a;
      box-shadow: 0 0 12px rgba(196,62,74,0.3);
    }

/* ─── Etichette nome stazioni ─────────────────────────────── */

/* ── Legenda Elevation ─────────────────────────────────────── */
#elevation-legend {
  display: none;
  position: absolute;
  bottom: 56px;
  left: 336px;
  z-index: 900;
  background: rgba(22,27,34,.9);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px 8px;
  backdrop-filter: blur(4px);
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
  min-width: 200px;
}
#elevation-legend.visible { display: block; }
.elev-legend-title {
  font-size: .85rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
  letter-spacing: .03em;
}
.elev-legend-bar {
  height: 12px;
  border-radius: 3px;
  background: linear-gradient(to right,
    #00a46d, #2ab27a, #54c088, #7dce95,
    #a7dca3, #b6e2a8, #c3e7b0, #cfe9b3,
    #dbeab3, #e8f6b7, #f4fabb, #fffebe,
    #fff3b1, #fee8a4, #fedc97, #fed18a,
    #fec67d, #fdbb70, #fdb063, #f9a05a,
    #f58f53, #f17e4b, #ec6d43, #e85c3b,
    #e44b33, #e03b2c, #db2a24, #d7191c
  );
}
.elev-legend-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: .85rem;
  color: var(--text-muted);
}

/* ── Elevation loading overlay ─────────────────────────────── */
#elev-loading-overlay {
  position: absolute; inset: 0; z-index: 1100;
  background: rgba(13,17,23,.6);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.elev-loading-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 22px 32px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
  min-width: 260px;
}
.elev-loading-spinner {
  width: 32px; height: 32px;
  margin: 0 auto 12px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: elev-spin .8s linear infinite;
}
@keyframes elev-spin { to { transform: rotate(360deg); } }
.elev-loading-text {
  font-size: .88rem; font-weight: 600;
  color: var(--text); margin-bottom: 12px;
}
.elev-loading-bar-wrap {
  height: 6px; background: var(--border);
  border-radius: 3px; overflow: hidden;
}
.elev-loading-bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #00a46d, #fffebe, #db2a24);
  border-radius: 3px;
  transition: width .2s;
}
.elev-loading-pct {
  font-size: .85rem; color: var(--text-muted);
  margin-top: 6px;
}

.station-label {
  background: rgba(10, 14, 20, 0.82);
  border: 1px solid rgba(0, 200, 83, 0.45);
  border-radius: 4px;
  color: #e6f4ea;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  padding: 2px 6px;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 1px 4px rgba(0,0,0,0.5);
}
.station-label::before {
  display: none;
}

/* ── Modal Situation Hydrologique ────────────────────────── */
#situation-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.6); backdrop-filter: blur(3px);
  z-index: 2200; align-items: center; justify-content: center;
}
#situation-overlay.open { display: flex; }
#situation-modal {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 24px 80px rgba(0,0,0,.7);
  width: min(960px, 96vw); max-height: 92vh;
  display: flex; flex-direction: column; overflow: hidden;
  animation: modalIn .22s cubic-bezier(.4,0,.2,1);
}
#situation-modal-header {
  padding: 13px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
  background: var(--bg); flex-shrink: 0;
}
#situation-modal-title { flex: 1; font-size: 1.1rem; font-weight: 700; color: var(--text); }
#situation-modal-close {
  background: none; border: none; color: var(--text-muted);
  font-size: 1.3rem; cursor: pointer; padding: 4px 8px;
  border-radius: 6px; transition: background .12s;
}
#situation-modal-close:hover { background: var(--border); color: var(--text); }
#situation-modal-body {
  padding: 14px 16px 18px; overflow-y: auto; flex: 1;
}
#situation-modal-body::-webkit-scrollbar { width: 5px; }
#situation-modal-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Tabella situation compatta ── */
.sit-table { width: 100%; border-collapse: collapse; font-size: .92rem; table-layout: auto; }
.sit-table thead tr { background: #222; color: #ccc; }
.sit-table thead th { padding: 4px 5px; font-size: .78rem; font-weight: 600; white-space: nowrap; border-bottom: 1px solid var(--border); text-align: center; }
.sit-table thead tr:last-child th { font-size: .72rem; color: #8b949e; font-weight: 500; border-bottom: 2px solid var(--border); }
.sit-table td { padding: 5px 5px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.sit-table tbody tr:nth-child(even) { background: rgba(255,255,255,.03); }
.sit-table tbody tr:hover { background: rgba(255,255,255,.06); }
.sit-table .st-name { font-weight: 700; white-space: nowrap; text-align: left; }
.sit-table .st-c { text-align: center; white-space: nowrap; }
.sit-table .st-flow { text-align: right; white-space: nowrap; }
.sit-table .st-date { color: #8b949e; font-size: .8rem; white-space: nowrap; text-align: center; }
.sit-table .st-lv { text-align: center; white-space: nowrap; padding: 5px 2px; }

/* ── Hamburger menu button (mobile) ──────────────────────── */
#sidebar-toggle {
  display: none;
  position: absolute; top: 12px; right: 12px; z-index: 1200;
  background: #000; border: none;
  border-radius: 10px; padding: 10px 13px; cursor: pointer;
  color: #fff; font-size: 1.4rem; line-height: 1;
  box-shadow: 0 2px 10px rgba(0,0,0,.6);
}
#sidebar-toggle:hover { background: #222; }

/* ── Global loading overlay ──────────────────────────────── */
#global-loading {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px;
  transition: opacity .4s;
}
#global-loading.fade-out {
  opacity: 0; pointer-events: none;
}
#global-loading .gl-spinner {
  width: 44px; height: 44px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: elev-spin .8s linear infinite;
}
#global-loading .gl-title {
  font-size: 1.1rem; font-weight: 700; color: var(--text);
  letter-spacing: .02em;
}
#global-loading .gl-status {
  font-size: .88rem; color: var(--text-muted);
  text-align: center; line-height: 1.6;
}
#global-loading .gl-bar-wrap {
  width: min(300px, 70vw); height: 6px;
  background: var(--border); border-radius: 3px;
  overflow: hidden;
}
#global-loading .gl-bar {
  height: 100%; width: 0%;
  background: var(--accent);
  border-radius: 3px;
  transition: width .3s;
}

/* ── Partner logo bar (bottom of map) ──────────────────────── */
#partner-bar {
  position: absolute;
  bottom: 6px;
  left: calc(320px + (100% - 320px) / 2);
  transform: translateX(-50%);
  z-index: 900;
  background: rgba(255,255,255,.75);
  border: 1px solid rgba(0,0,0,.1);
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 5px 18px;
  pointer-events: none;
  backdrop-filter: blur(3px);
}
#partner-bar img {
  height: 34px;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
}

/* ── RESPONSIVE: Mobile & Tablet ─────────────────────────── */
@media (max-width: 768px) {
  #sidebar-toggle { display: block; }

  #sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    z-index: 1100;
    transform: translateX(-100%);
    transition: transform .25s cubic-bezier(.4,0,.2,1);
    width: 300px; min-width: 300px;
    box-shadow: 4px 0 24px rgba(0,0,0,.6);
  }
  #sidebar.open { transform: translateX(0); }

  /* Overlay behind sidebar */
  #sidebar-backdrop {
    display: none;
    position: fixed; inset: 0; z-index: 1050;
    background: rgba(0,0,0,.5);
  }
  #sidebar.open ~ #sidebar-backdrop { display: block; }

  #map { width: 100%; }

  #statusbar { left: 12px; bottom: 12px; }

  #elevation-legend { left: 12px; bottom: 44px; }

  #situation-btn {
    top: 60px; right: 12px;
    font-size: .85rem; padding: 8px 14px 8px 16px;
  }
  #situation-btn img { width: 22px; height: 22px; }

  #sim-mode-btn {
    top: 112px; right: 12px;
    font-size: .85rem; padding: 6px 12px;
  }

  /* Popup responsive */
  .popup-inner { min-width: 260px; max-width: 90vw; padding: 14px 16px; }
  .popup-obs-row { flex-direction: column; gap: 10px; }
  .popup-obs-left { border-right: none; padding-right: 0; border-bottom: 1px solid rgba(255,255,255,.08); padding-bottom: 10px; }

  /* Chart modal: stack vertically */
  #chart-modal { width: 98vw; max-height: 96vh; }
  #chart-modal-body { grid-template-columns: 1fr; }
  #chart-modal-left {
    border-right: none; border-bottom: 1px solid var(--border);
    max-height: 180px; overflow-y: auto;
  }
  #chart-modal-header { flex-wrap: wrap; gap: 8px; }
  #chart-modal-meta { font-size: .78rem; width: 100%; order: 10; }

  /* Series modal */
  #series-modal { width: 98vw; }
  .series-controls { flex-wrap: wrap; gap: 8px; }

  /* Partner bar mobile */
  #partner-bar { left: 50%; }

  /* Situation modal */
  #situation-modal { width: 98vw; }
}

/* Small phones */
@media (max-width: 420px) {
  .popup-model-cards { flex-direction: column; }
  .popup-model-card { min-width: 100%; }
  #situation-btn span { display: none; }
  .nav-grid { grid-template-columns: 1fr; }
}
