:root {
  --bg: #ffffff;
  --panel: #ffffff;
  --soft: #f6f7f9;
  --line: #e7e9ee;
  --ink: #0f172a;
  --ink2: #475569;
  --ink3: #94a3b8;
  --accent: #2563eb;
  --ok: #16a34a;   --ok-bg: #dcfce7;
  --warn: #d97706; --warn-bg: #fef3c7;
  --bad: #dc2626;  --bad-bg: #fee2e2;
  --night: #64748b; --night-bg: #eef1f5;
  --c10: #0ea5e9;
  --c50: #6366f1;
  --c120: #db2777;
  --cg: #94a3b8;
  --r: 16px;
  --shadow: 0 1px 2px rgba(15,23,42,.04), 0 4px 16px rgba(15,23,42,.05);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-feature-settings: "tnum" 1, "cv11" 1;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
svg { stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg.wxicon { stroke: none; stroke-width: 1; }
.muted { color: var(--ink2); font-size: 13px; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 16px;
  padding: 10px max(16px, env(safe-area-inset-left));
  background: rgba(255,255,255,.88); backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { flex: none; display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 17px; white-space: nowrap; }
.brand b { font-weight: 800; color: var(--accent); margin-left: 2px; }
.search { position: relative; flex: 1; min-width: 0; max-width: 560px; }
.search .ico { position: absolute; left: 12px; top: 50%; translate: 0 -50%; width: 18px; color: var(--ink3); }
.search input {
  width: 100%; height: 42px; padding: 0 40px 0 38px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--soft);
  font: inherit; color: var(--ink); transition: .15s;
}
.search input:focus { outline: none; background: #fff; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(37,99,235,.12); }
.search .hint { position: absolute; right: 10px; top: 50%; translate: 0 -50%; font: 12px Inter; color: var(--ink3);
  border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; background: #fff; }
.search input:focus ~ .hint { display: none; }
.suggest {
  position: absolute; left: 0; right: 0; top: 48px; margin: 0; padding: 6px; list-style: none;
  background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 12px 40px rgba(15,23,42,.14);
  max-height: 60vh; overflow: auto;
}
.suggest li { display: flex; gap: 10px; align-items: center; padding: 9px 10px; border-radius: 10px; cursor: pointer; }
.suggest li[aria-selected="true"], .suggest li:hover { background: var(--soft); }
.suggest .flag { font-size: 18px; width: 24px; text-align: center; }
.suggest .s1 { font-weight: 600; }
.suggest .s2 { color: var(--ink2); font-size: 12.5px; }
.suggest .alt { margin-left: auto; color: var(--ink3); font-size: 12px; }
.actions { display: flex; gap: 6px; flex: none; }
.icon-btn {
  width: 42px; height: 42px; display: grid; place-items: center;
  border: 1px solid var(--line); background: #fff; border-radius: 12px; transition: .15s;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { background: var(--soft); }

.favbar { display: flex; gap: 8px; overflow-x: auto; padding: 10px 16px 0; max-width: 1240px; margin: 0 auto; scrollbar-width: none; }
.favbar:empty { display: none; }
.fav {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 6px 5px 12px; font-size: 13px;
}
.fav.on { border-color: var(--accent); color: var(--accent); background: #eff6ff; }
.fav .x { border: 0; background: none; width: 22px; height: 22px; border-radius: 50%; color: var(--ink3); display: grid; place-items: center; }
.fav .x:hover { background: var(--soft); color: var(--ink); }
.fav .x svg { width: 12px; }
.fav .fn { border: 0; background: none; padding: 0 2px; font: inherit; color: inherit; }
.fav .st { width: 8px; height: 8px; border-radius: 50%; background: var(--ink3); }

/* ---------- layout ---------- */
.wrap { grid-template-columns: minmax(0, 1fr); max-width: 1240px; margin: 0 auto; padding: 14px 16px 40px; display: grid; gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 18px; min-width: 0; }
.sec-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; margin-bottom: 14px; }
h1 { font-size: 24px; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 17px; margin: 0; letter-spacing: -.01em; }
h3 { margin: 0 0 14px; font-size: 17px; }

/* ---------- hero ---------- */
.hero-head > div:first-child { min-width: 0; }
.hero-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 14px; }
.hero-tools { display: flex; gap: 6px; flex: none; }
.chip-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px;
  border: 1px solid var(--line); background: #fff; border-radius: 10px; font-size: 13px; font-weight: 500;
}
.chip-btn svg { width: 16px; height: 16px; }
.chip-btn:hover { background: var(--soft); }
.chip-btn[aria-pressed="true"] { color: #b45309; border-color: #fcd34d; background: #fffbeb; }
.chip-btn[aria-pressed="true"] svg { fill: #f59e0b; stroke: #f59e0b; }

.hero-body { display: grid; grid-template-columns: minmax(230px, 300px) 1fr; gap: 18px; }
.verdict {
  border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 6px; justify-content: center;
  background: var(--soft);
}
.verdict.ok { background: var(--ok-bg); color: #14532d; }
.verdict.warn { background: var(--warn-bg); color: #78350f; }
.verdict.bad { background: var(--bad-bg); color: #7f1d1d; }
.verdict.night { background: var(--night-bg); color: #334155; }
.verdict .lbl { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; font-weight: 600; opacity: .75; }
.verdict .big { font-size: 28px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.verdict ul { margin: 4px 0 0; padding-left: 18px; font-size: 13px; }
.verdict .next { font-size: 13px; margin-top: 6px; padding-top: 8px; border-top: 1px solid rgba(0,0,0,.08); }

.now-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.alt-card { border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; position: relative; overflow: hidden; }
.alt-card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--c); }
.alt-card .h { display: flex; justify-content: space-between; color: var(--ink2); font-size: 12.5px; font-weight: 600; }
.alt-card .v { display: flex; align-items: baseline; gap: 6px; margin-top: 4px; }
.alt-card .v b { font-size: 30px; font-weight: 800; letter-spacing: -.03em; }
.alt-card .v small { color: var(--ink2); }
.alt-card .d { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink2); }
.alt-card .bar { height: 6px; background: var(--soft); border-radius: 9px; margin-top: 10px; overflow: hidden; }
.alt-card .bar i { display: block; height: 100%; border-radius: 9px; }
.facts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.fact { display: flex; align-items: center; gap: 8px; background: var(--soft); border-radius: 10px; padding: 7px 11px; font-size: 13px; }
.fact svg { width: 16px; height: 16px; color: var(--ink2); }
.fact b { font-weight: 700; }

.arrow { display: inline-block; width: 18px; height: 18px; vertical-align: middle; transition: transform .3s; }
.arrow svg { width: 100%; height: 100%; stroke-width: 2.4; }

/* ---------- days ---------- */
.legend-inline { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12.5px; color: var(--ink2); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.dot.ok, .hb.ok { background: var(--ok); }
.dot.warn, .hb.warn { background: #f59e0b; }
.dot.bad, .hb.bad { background: var(--bad); }
.dot.night, .hb.night { background: #cbd5e1; }
.hb.na { background: var(--line); }
.days { display: grid; grid-auto-flow: column; grid-auto-columns: 132px; gap: 10px; overflow-x: auto; padding: 2px 2px 8px; scroll-snap-type: x mandatory; scrollbar-width: thin; }
.day {
  scroll-snap-align: start; text-align: left;
  border: 1px solid var(--line); background: #fff; border-radius: 14px; padding: 10px 11px; display: grid; gap: 4px; transition: .15s;
}
.day:hover { border-color: #c7d2fe; }
.day.sel { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.14); }
.day .dn { font-weight: 700; font-size: 14px; display: flex; justify-content: space-between; align-items: center; }
.day .dd { font-size: 12px; color: var(--ink2); }
.day .wx { width: 34px; height: 34px; }
.day .row { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; }
.day .t { font-size: 13px; }
.day .t b { font-weight: 700; }
.day .t span { color: var(--ink3); }
.day .w { color: var(--ink2); }
.day .w b { color: var(--ink); }
.hbar { display: grid; grid-template-columns: repeat(24, 1fr); gap: 1px; height: 8px; border-radius: 4px; overflow: hidden; margin-top: 3px; }
.hb { display: block; }
.day .fly { font-size: 12px; font-weight: 600; }
.day .fly.ok { color: var(--ok); } .day .fly.warn { color: var(--warn); } .day .fly.bad { color: var(--bad); }
.day .src { font-size: 10.5px; color: var(--ink3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- detail ---------- */
.seg { display: inline-flex; background: var(--soft); border-radius: 11px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 6px 10px; border-radius: 8px; font-size: 13px; color: var(--ink2); display: inline-flex; align-items: center; gap: 6px; }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(15,23,42,.12); font-weight: 600; }
.seg.small button { padding: 6px 14px; }
.sw { width: 14px; height: 3px; border-radius: 2px; background: var(--c); display: inline-block; }
.sw.dash { background: repeating-linear-gradient(90deg, var(--c) 0 4px, transparent 4px 7px); }
.seg button:not(.on) .sw { opacity: .35; }
.chart-tools { display: flex; flex-wrap: wrap; gap: 8px; }
.chart-box { position: relative; height: 290px; margin-bottom: 14px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
table.hours { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; white-space: nowrap; }
.hours th, .hours td { padding: 7px 9px; text-align: center; border-bottom: 1px solid var(--line); }
.hours thead th { position: sticky; top: 0; background: #fbfcfd; font-size: 11.5px; font-weight: 600; color: var(--ink2); text-transform: uppercase; letter-spacing: .03em; }
.hours thead tr.grp th { font-size: 11px; color: var(--ink3); border-bottom: 0; padding-bottom: 0; }
.hours tbody tr:last-child td { border-bottom: 0; }
.hours tbody tr:hover td { background: #f8fafc; }
.hours tbody tr.now td { background: #eff6ff; }
.hours tbody tr.night td:not(.st) { color: var(--ink2); background-image: linear-gradient(rgba(100,116,139,.045), rgba(100,116,139,.045)); }
.hours td.hr { position: sticky; left: 0; background: #fff; font-weight: 700; text-align: left; z-index: 1; }
.hours tr.now td.hr { background: #eff6ff; }
.hours td.st span { display: inline-block; min-width: 76px; font-size: 11.5px; font-weight: 700; padding: 3px 8px; border-radius: 999px; }
.st .ok { background: var(--ok-bg); color: #166534; }
.st .warn { background: var(--warn-bg); color: #92400e; }
.st .bad { background: var(--bad-bg); color: #991b1b; }
.st .night { background: var(--night-bg); color: #475569; }
.wcell { display: inline-flex; align-items: center; gap: 4px; padding: 2px 7px; border-radius: 8px; font-weight: 600; min-width: 62px; justify-content: center; }
.l0 { background: #ecfdf5; color: #065f46; }
.l1 { background: #fefce8; color: #854d0e; }
.l2 { background: #ffedd5; color: #9a3412; }
.l3 { background: #fee2e2; color: #991b1b; }
.hours .sep { border-left: 1px solid var(--line); }
.hours .wxi { width: 22px; height: 22px; vertical-align: middle; }
.hours .why { color: var(--ink3); font-size: 11.5px; text-align: left; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.mdl { font-size: 10.5px; color: var(--ink3); }
.note { color: var(--ink2); font-size: 12.5px; margin: 10px 2px 0; }

/* ---------- synoptic ---------- */
.syn-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tog { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; height: 34px; }
.tog input { accent-color: var(--accent); margin: 0; }
.syn-days { position: relative; display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 8px; scrollbar-width: thin; }
.syn-days button { flex: none; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 5px 10px; font-size: 12.5px; line-height: 1.2; text-align: center; }
.syn-days button small { display: block; color: var(--ink3); font-size: 10.5px; }
.syn-days button.sel { background: var(--ink); color: #fff; border-color: var(--ink); }
.syn-days button.sel small { color: #cbd5e1; }
.syn-wrap { position: relative; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #fff; }
#syn { stroke: none; display: block; width: 100%; height: auto; background: #fff; touch-action: pan-y; }
#syn .land { fill: none; stroke: #475569; stroke-width: .7; }
#syn .grat { fill: none; stroke: #e2e8f0; stroke-width: .6; }
#syn .zl { fill: none; stroke: #111827; stroke-width: 1.1; }
#syn .zl.major { stroke-width: 2.2; }
#syn .pl { fill: none; stroke: #ffffff; stroke-width: 1; opacity: .95; }
#syn.noshade .pl { stroke: #64748b; }
#syn .zlab { font: 600 11px Inter, sans-serif; fill: #111827; paint-order: stroke; stroke: rgba(255,255,255,.85); stroke-width: 3px; }
#syn .plab { font: 500 9.5px Inter, sans-serif; fill: #334155; paint-order: stroke; stroke: rgba(255,255,255,.9); stroke-width: 2.5px; }
#syn .hl { font: 800 22px Inter, sans-serif; paint-order: stroke; stroke: #fff; stroke-width: 3px; }
#syn .hl.H { fill: #1d4ed8; } #syn .hl.L { fill: #dc2626; }
#syn .hlv { font: 600 10px Inter, sans-serif; fill: #0f172a; paint-order: stroke; stroke: #fff; stroke-width: 2.5px; }
#syn .me circle { fill: #dc2626; stroke: #fff; stroke-width: 2.5; }
#syn .me text { font: 700 12px Inter, sans-serif; fill: #0f172a; paint-order: stroke; stroke: #fff; stroke-width: 3.5px; }
#syn .frame { fill: none; stroke: var(--line); }
#syn .stamp { font: 600 12px Inter, sans-serif; fill: #0f172a; }
#syn .stampbg { fill: rgba(255,255,255,.9); stroke: var(--line); }
.syn-tip { position: absolute; pointer-events: none; background: rgba(15,23,42,.92); color: #fff; font-size: 12px; padding: 6px 9px; border-radius: 8px; white-space: nowrap; translate: 12px -50%; }
.syn-loading { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 10px; background: rgba(255,255,255,.85); color: var(--ink2); font-size: 13px; }
.syn-loading[hidden] { display: none; }
.syn-legend { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-size: 12px; color: var(--ink2); flex-wrap: wrap; }
.syn-legend .ramp { display: flex; height: 12px; border-radius: 3px; overflow: hidden; flex: 1; min-width: 220px; max-width: 560px; }
.syn-legend .ramp i { flex: 1; }
.syn-legend .ticks { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--ink3); }

/* ---------- misc ---------- */
.skeleton { border-radius: 12px; background: linear-gradient(90deg, #f1f5f9 25%, #f8fafc 50%, #f1f5f9 75%); background-size: 200% 100%; animation: sk 1.2s infinite; }
@keyframes sk { to { background-position: -200% 0; } }
.spinner { width: 28px; height: 28px; border: 3px solid #e2e8f0; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.foot { text-align: center; padding: 6px 10px; line-height: 1.6; }
.toast { position: fixed; left: 50%; bottom: 24px; translate: -50% 0; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 100; box-shadow: 0 10px 30px rgba(0,0,0,.2); }
.err { color: var(--bad); padding: 14px; background: var(--bad-bg); border-radius: 12px; }

.dlg { border: 0; border-radius: 18px; padding: 22px; width: min(440px, calc(100vw - 32px)); box-shadow: 0 24px 80px rgba(15,23,42,.3); color: var(--ink); }
.dlg::backdrop { background: rgba(15,23,42,.35); backdrop-filter: blur(2px); }
.dlg.wide { width: min(900px, calc(100vw - 32px)); padding: 0; overflow: hidden; }
.pick-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 12px 12px 18px; }
.pick-head h3 { margin: 0; font-size: 15px; }
#pickMap { height: min(70vh, 560px); }
.profiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.profiles button { text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 9px 11px; }
.profiles button b { display: block; font-size: 13.5px; }
.profiles button small { color: var(--ink2); font-size: 12px; }
.profiles button.on { border-color: var(--accent); background: #eff6ff; }
.field { display: grid; gap: 8px; margin-bottom: 14px; font-size: 13.5px; font-weight: 500; }
.field input[type=range] { accent-color: var(--accent); width: 100%; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13.5px; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.dlg-foot { display: flex; justify-content: flex-end; margin-top: 18px; }
.btn { border: 0; border-radius: 10px; padding: 10px 18px; font-weight: 600; }
.btn.primary { background: var(--accent); color: #fff; }

@media (max-width: 860px) {
  .hero-body { grid-template-columns: 1fr; }
  .brand span { display: none; }
}
@media (max-width: 560px) {
  .topbar { gap: 8px; padding: 8px 12px; }
  .actions .icon-btn { width: 38px; height: 38px; }
  .search .hint { display: none; }
  .wrap { padding: 10px 10px 32px; gap: 12px; }
  .card { padding: 14px; border-radius: 14px; }
  .now-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .alt-card { padding: 10px; }
  .alt-card .v b { font-size: 24px; }
  .alt-card .h .mdl { display: none; }
  .alt-card .d span { display: none; }
  .brand svg { display: none; }
  .chart-box { height: 240px; }
  h1 { font-size: 20px; }
  .hero-tools .chip-btn span { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- storico del mese ---------- */
.dlg.hist { width: min(1320px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; display: none; flex-direction: column; overflow: hidden; }
.dlg.hist[open] { display: flex; }
.hist-body { overflow-y: auto; padding: 0 18px 18px; }
.hist-legend { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink2); background: #fff; padding: 4px 0 12px; }
.hist-legend .sw2 { display: inline-flex; align-items: center; gap: 5px; }
.hist-legend .sw2 i { width: 16px; height: 11px; border-radius: 3px; display: inline-block; }
.hist-legend .sw2 i.ln { width: 18px; height: 0; border-radius: 0; border-top: 1.4px solid #111827; display: inline-block; vertical-align: middle; }
.hist-legend .sw2 i.ln.major { border-top-width: 3px; }
.hist-legend .sw2 i.ramp { width: 90px; height: 10px; opacity: .75; }
.hist-status { font-size: 13px; color: var(--ink2); background: var(--soft); border-radius: 10px; padding: 9px 12px; margin-bottom: 12px; display: flex; align-items: center; gap: 10px; }
.hist-status[hidden] { display: none; }
.hist-status .spinner { width: 16px; height: 16px; border-width: 2px; }
.hist-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.hist-grid[hidden], .hist-zoom[hidden] { display: none; }
.hist-tile { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #fff; padding: 0; text-align: left; transition: .15s; font: inherit; color: inherit; cursor: zoom-in; }
.hist-tile:hover { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.14); }
.hist-tile .cap { display: flex; justify-content: space-between; align-items: baseline; padding: 6px 10px; font-size: 12.5px; font-weight: 600; border-top: 1px solid var(--line); }
.hist-tile .cap small { font-weight: 500; color: var(--ink3); font-size: 11px; }
.hist-map { display: block; width: 100%; height: auto; background: #fff; }
.hist-map .zl { fill: none; stroke: #111827; stroke-width: 1.6; }
.hist-map .zl.major { stroke-width: 3.6; }
.hist-map .zlab { font: 600 12px Inter, sans-serif; fill: #111827; paint-order: stroke; stroke: rgba(255,255,255,.85); stroke-width: 3px; }
#histBig { border: 1px solid var(--line); border-radius: 12px; }
#histBig .zl { stroke-width: 1.1; } #histBig .zl.major { stroke-width: 2.2; }
.hist-zoom-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.hist-zoom-bar b { flex: 1; text-transform: capitalize; }
.hist-nav { display: flex; gap: 6px; }
