:root {
  --blu: #1a3a5c; --blu-mid: #2a5f8f; --blu-light: #e8f1f9;
  --oro: #c8922a; --oro-light: #fdf3e3;
  --verde: #2e7d52; --rosso: #b03a2e;
  --ink: #18222d; --muted: #5a6570; --line: #d9e1e8; --bg: #f4f7fa; --card: #fff;
  --r: 14px; --tabs-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink); line-height: 1.45;
  display: flex; flex-direction: column; -webkit-text-size-adjust: 100%;
}
button, input, select { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.top {
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + var(--safe-t)) 16px 12px;
  background: var(--blu); color: #fff;
}
.mark { width: 38px; height: 38px; border-radius: 10px; background: var(--oro); display: grid; place-items: center; font-weight: 800; letter-spacing: .5px; }
.ttl h1 { margin: 0; font-size: 1.1rem; }
.ttl p { margin: 0; font-size: .78rem; opacity: .8; }

main { flex: 1; position: relative; overflow: hidden; }
.view { position: absolute; inset: 0; overflow-y: auto; padding: 14px 14px 28px; display: none; -webkit-overflow-scrolling: touch; }
.view.active { display: block; }
.view > * { max-width: 760px; margin-left: auto; margin-right: auto; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; margin-bottom: 12px; }
.card h2 { margin: 0 0 4px; font-size: 1.02rem; color: var(--blu); }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.notice { background: var(--oro-light); border-color: #ecd3a3; }
.hint { color: var(--muted); font-size: .88rem; margin: 4px 0 10px; }
.small { font-size: .76rem; }
.big { font-size: 1.7rem; font-weight: 800; color: var(--blu); margin: 4px 0 0; }
.updated { font-size: .8rem; color: var(--muted); margin: 0 auto 10px; }
.link { border: 0; background: none; color: var(--blu-mid); font-weight: 600; font-size: .88rem; min-height: 44px; padding: 0 4px; cursor: pointer; }

.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 12px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; }
.kpi b { display: block; font-size: 1.35rem; color: var(--blu); line-height: 1.15; }
.kpi span { font-size: .78rem; color: var(--muted); }
@media (min-width: 640px) { .kpis { grid-template-columns: repeat(4, 1fr); } .kpis.two { grid-template-columns: repeat(2, 1fr); } }

.bars { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.bar-row .lbl { display: flex; justify-content: space-between; gap: 8px; font-size: .88rem; }
.bar-row .lbl b { white-space: nowrap; }
.bar { height: 8px; background: #edf1f5; border-radius: 4px; overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; background: var(--blu-mid); border-radius: 4px; }

.rank { list-style: none; margin: 0; padding: 0; counter-reset: r; }
.rank li { counter-increment: r; }
.rank button {
  width: 100%; display: grid; grid-template-columns: 26px 1fr auto; gap: 8px; align-items: center;
  text-align: left; border: 0; border-bottom: 1px solid var(--line); background: none; padding: 10px 0; min-height: 52px; cursor: pointer;
}
.rank li:last-child button { border-bottom: 0; }
.rank button::before { content: counter(r); font-weight: 700; color: var(--oro); text-align: center; }
.rank .nm { font-weight: 600; font-size: .92rem; }
.rank .sub { display: block; font-size: .76rem; color: var(--muted); font-weight: 400; }
.rank .amt { font-weight: 700; color: var(--blu); font-size: .9rem; white-space: nowrap; }

.filters { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.search input, .filters select {
  width: 100%; min-height: 46px; border: 1.5px solid var(--line); border-radius: 12px; padding: 0 12px; background: #fff;
}
.search input:focus, .filters select:focus { outline: 3px solid rgba(42,95,143,.25); border-color: var(--blu-mid); }
.card .search input { margin-bottom: 8px; }
.frow { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.chk { display: flex; align-items: center; gap: 8px; min-height: 40px; font-size: .9rem; }
.chk input { width: 20px; height: 20px; accent-color: var(--blu); }
.resume { font-size: .85rem; color: var(--muted); margin: 6px auto 8px; }

.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: block; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px; cursor: pointer;
}
.card .item { background: #fbfcfd; }
.item:focus-visible, .rank button:focus-visible, .tabs button:focus-visible { outline: 3px solid var(--oro); outline-offset: 2px; }
.item .row1 { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.item .obj { font-weight: 600; font-size: .93rem; }
.item .amt { font-weight: 700; color: var(--blu); white-space: nowrap; }
.item .meta { font-size: .78rem; color: var(--muted); margin-top: 4px; }
.item .who { font-size: .82rem; margin-top: 4px; }
.tag { display: inline-block; font-size: .7rem; font-weight: 700; padding: 1px 7px; border-radius: 6px; margin-right: 4px; vertical-align: 1px; }
.tag.d { background: var(--oro-light); color: #8a5c00; }
.tag.g { background: #e6f4ed; color: #1e6b3a; }
.tag.p { background: var(--blu-light); color: var(--blu); }

.btn { display: block; width: 100%; min-height: 48px; border-radius: 12px; border: 1.5px solid var(--line); background: #fff; font-weight: 600; margin: 12px auto; cursor: pointer; }
.empty { text-align: center; color: var(--muted); padding: 18px 8px; font-size: .9rem; }

.plain { padding-left: 18px; margin: 6px 0; }
.plain li { margin-bottom: 6px; font-size: .92rem; }
.gloss dt { font-weight: 700; margin-top: 8px; font-size: .92rem; }
.gloss dd { margin: 2px 0 0; color: var(--muted); font-size: .88rem; }

.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-bg { position: absolute; inset: 0; background: rgba(10,20,30,.45); }
.sheet-body {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 86vh; overflow-y: auto;
  background: #fff; border-radius: 18px 18px 0 0; padding: 20px 18px calc(24px + var(--safe-b));
  max-width: 760px; margin: 0 auto;
}
.sheet-x { position: absolute; top: 8px; right: 8px; width: 44px; height: 44px; border: 0; background: none; font-size: 1.1rem; cursor: pointer; }
.sheet h3 { margin: 0 40px 6px 0; font-size: 1.08rem; color: var(--blu); }
.kv { display: grid; grid-template-columns: 40% 1fr; gap: 6px 10px; margin: 12px 0; font-size: .9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; word-break: break-word; }

.tabs {
  display: flex; height: calc(var(--tabs-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: #fff; border-top: 1px solid var(--line);
}
.tabs button { flex: 1; border: 0; background: none; display: grid; place-items: center; align-content: center; gap: 2px; color: var(--muted); font-size: .72rem; font-weight: 600; cursor: pointer; }
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs button.on { color: var(--blu); }
.tabs button.on svg { stroke: var(--oro); }

/* ---------- Lombardia: apertura con le aree ---------- */
.intro { font-size: .95rem; color: var(--muted); margin: 2px auto 12px; }
.areas { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.area-btn {
  display: grid; grid-template-columns: 52px 1fr auto; gap: 12px; align-items: center; width: 100%; text-align: left;
  background: var(--card); border: 1.5px solid var(--line); border-radius: 16px; padding: 14px; cursor: pointer; min-height: 84px;
}
.area-btn:hover { border-color: var(--blu-mid); }
.area-btn:focus-visible { outline: 3px solid var(--oro); outline-offset: 2px; }
.area-btn .ic { width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; background: var(--blu-light); }
.area-btn .ic svg { width: 28px; height: 28px; fill: none; stroke: var(--blu); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.area-btn b { display: block; font-size: 1.05rem; color: var(--blu); }
.area-btn small { display: block; color: var(--muted); font-size: .8rem; margin-top: 2px; }
.area-btn .num { text-align: right; font-weight: 800; color: var(--blu); font-size: 1rem; white-space: nowrap; }
.area-btn .num span { display: block; font-weight: 500; color: var(--muted); font-size: .72rem; }
.area-btn[disabled] { cursor: default; opacity: .75; background: #fafbfc; }
.soon { display: inline-block; background: var(--oro-light); color: #8a5c00; font-size: .7rem; font-weight: 700; border-radius: 6px; padding: 2px 8px; }
.back { display: inline-flex; align-items: center; gap: 4px; border: 0; background: none; color: var(--blu-mid); font-weight: 600; font-size: .9rem; min-height: 44px; padding: 0; cursor: pointer; margin-bottom: 4px; }
.area-title { font-size: 1.3rem; color: var(--blu); margin: 0 0 2px; }

.seg { display: flex; background: #e6ecf2; border-radius: 12px; padding: 4px; gap: 4px; margin-bottom: 10px; }
.seg button { flex: 1; border: 0; border-radius: 9px; background: none; min-height: 40px; font-weight: 600; font-size: .86rem; color: var(--muted); cursor: pointer; }
.seg button.on { background: #fff; color: var(--blu); box-shadow: 0 1px 3px rgba(10,30,50,.12); }
.seg button[disabled] { opacity: .5; cursor: default; }

.yrs { display: flex; align-items: flex-end; gap: 10px; height: 120px; margin: 10px 0 4px; }
.yrs .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.yrs .col i { display: block; width: 100%; max-width: 56px; background: var(--blu-mid); border-radius: 6px 6px 2px 2px; min-height: 3px; }
.yrs .col b { font-size: .74rem; color: var(--blu); white-space: nowrap; }
.yrs .col span { font-size: .78rem; color: var(--muted); }
.loading { text-align: center; color: var(--muted); padding: 24px 8px; font-size: .9rem; }
.prov { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
