:root {
  --navy: #05053a;
  --navy-2: #12124d;
  --bg: #e9edf1;
  --surface: #ffffff;
  --surface-2: #f5f7f9;
  --text: #1d1d2c;
  --muted: #8a8f9c;
  --border: #e3e6eb;
  --accent: #05053a;
  --link: #2b6cd4;
  --ok: #3fae49;
  --warn: #e39b18;
  --bad: #d63031;
  --work: #2b6cd4;
  --private: #8a5cc8;
  --lime: #a6ff00;
  --radius: 4px;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  background: var(--bg); color: var(--text);
  font: 13px/1.45 "Poppins", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.25rem; font-weight: 500; margin: 0 0 .25rem; }
h2 { font-size: 1rem; font-weight: 500; margin: 0 0 .6rem; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* ---- top bar */
header.top { background: var(--navy); color: #fff; }
header.top .inner {
  max-width: 1480px; margin: 0 auto; padding: 0 16px; height: 50px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 8px; color: #fff; font-weight: 700; font-size: 1.15rem; letter-spacing: .02em; }
.brand:hover { text-decoration: none; }
.brand .logo {
  width: 26px; height: 26px; background: #fff; color: var(--navy); display: grid; place-items: center;
  font-weight: 800; border-radius: 2px; font-size: .95rem;
}
.top-right { display: flex; align-items: center; gap: 10px; }
.car-pill {
  display: flex; align-items: center; gap: 8px; background: var(--navy-2); color: #fff; border-radius: 4px;
  padding: 5px 12px; font-size: .85rem; white-space: nowrap;
}

/* ---- section nav */
nav.sub { background: var(--surface); border-bottom: 1px solid var(--border); }
nav.sub .inner {
  max-width: 1480px; margin: 0 auto; padding: 0 16px; display: flex; gap: 4px; overflow-x: auto; height: 42px; align-items: center;
}
nav.sub a {
  color: var(--muted); padding: 6px 8px; white-space: nowrap; display: flex; align-items: center; gap: 6px; font-size: .85rem;
}
nav.sub a i { font-size: .8rem; }
nav.sub a:hover { color: var(--text); text-decoration: none; }
nav.sub a.active { color: var(--navy); font-weight: 500; }
nav.sub .spacer { flex: 1; }

main { flex: 1; width: 100%; max-width: 1480px; margin: 0 auto; padding: 16px 16px 40px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }

footer.foot { background: var(--navy); color: #fff; font-size: .78rem; }
footer.foot .inner { max-width: 1480px; margin: 0 auto; padding: 16px; display: flex; gap: 20px; flex-wrap: wrap; }
footer.foot a { color: #fff; }

/* ---- cards */
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); margin-bottom: 12px; }
.grid.g4 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.card { background: var(--surface); border-radius: var(--radius); padding: 14px 16px; min-width: 0; box-shadow: 0 1px 2px rgba(5, 5, 58, .04); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.card-head h2, .card-head .title { margin: 0; font-size: 1rem; font-weight: 500; }
.card-head .icon { font-size: 1rem; }
.card .label { color: var(--muted); font-size: .72rem; }
.card .value { font-size: 1rem; font-weight: 500; font-variant-numeric: tabular-nums; }
.card .value small { font-size: .8rem; font-weight: 400; color: var(--muted); }
.stat-row { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.stat { min-width: 0; }
.stat .label { display: block; }
.ic-red { color: #e74c3c; } .ic-blue { color: #2e86de; } .ic-yellow { color: #f1c40f; } .ic-green { color: #27ae60; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

.soc-bar { position: relative; height: 16px; background: #e8f5e9; border-radius: 3px; overflow: hidden; margin-top: 6px; }
.soc-bar > span { position: absolute; inset: 0 auto 0 0; background: #4caf50; }
.soc-bar > b { position: relative; display: block; text-align: center; font-size: .72rem; line-height: 16px; font-weight: 600; }
.ratio-bar { display: flex; height: 14px; border-radius: 2px; overflow: hidden; background: #e8f5e9; font-size: .68rem; }
.ratio-bar span { display: grid; place-items: center; color: #1d1d2c; }
.ratio-bar .ac { background: #4caf50; } .ratio-bar .dc { background: #e8f5e9; }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; background: var(--muted); }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }

.alert { border-radius: var(--radius); padding: 10px 14px; margin-bottom: 12px; border: 1px solid; background: var(--surface); }
.alert.bad { border-color: var(--bad); color: var(--bad); }
.alert.warn { border-color: var(--warn); color: #9a6400; }

/* ---- buttons and inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); border-radius: 3px; padding: 6px 12px; font: inherit; font-size: .82rem;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary, .btn.dark { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover, .btn.dark:hover { background: var(--navy-2); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.icon { width: 34px; padding: 6px 0; }
.btn.lime { background: var(--lime); border-color: var(--lime); color: var(--navy); border-radius: 20px; padding: 8px 40px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.filter-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.filter-bar .grow { flex: 1; }
.field { position: relative; display: inline-flex; flex-direction: column; }
.field > span { position: absolute; top: -7px; left: 8px; background: var(--surface); padding: 0 3px; font-size: .68rem; color: var(--muted); }
input[type=text], input[type=number], input[type=date], input[type=month], select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid #c8ccd4; border-radius: 3px;
  padding: 7px 9px; min-width: 0;
}
input[type=date] { min-width: 150px; }
select.cat-lavoro { border-color: var(--work); color: var(--work); }
select.cat-privato { border-color: var(--private); color: var(--private); }
input.note { width: 100%; min-width: 140px; }
.saved { outline: 2px solid var(--ok); outline-offset: 1px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px 12px; align-items: end; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: .78rem; color: var(--muted); }
.form-grid label.check { flex-direction: row; align-items: center; gap: 6px; }

/* ---- tables */
.table-wrap { overflow-x: auto; background: var(--surface); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 10px; text-align: left; vertical-align: middle; font-size: .8rem; }
th { font-weight: 500; color: var(--text); white-space: nowrap; border-bottom: 1px solid var(--border); }
td { border-bottom: 1px solid var(--border); }
tbody tr:hover > td { background: #fafbfc; }
tfoot td { font-weight: 600; border-bottom: 0; }
table.trips td { border-bottom: 0; }
table.trips tr.main > td { border-top: 1px solid var(--border); padding-top: 11px; padding-bottom: 6px; }
table.trips tr.sub > td { padding-top: 0; padding-bottom: 8px; font-size: .74rem; color: #444; }
table.trips tr.sub select { padding: 2px 6px; font-size: .72rem; }
table.trips tr.sub .route { text-align: right; }
td.when { white-space: nowrap; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions a { color: var(--text); padding: 0 6px; }

.tag { display: inline-block; font-size: .7rem; padding: 1px 7px; border-radius: 99px; border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.tag.live { border-color: var(--ok); color: var(--ok); }
.tag.inferred { border-color: var(--warn); color: #9a6400; }
.badge { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; color: #fff; font-size: .68rem; font-weight: 700; }
.badge.casa { background: #3fae49; } .badge.pubblica { background: #f39c12; } .badge.privata { background: #8e44ad; }
.badge.aziendale { background: #2e86de; } .badge.none { background: #b2b7c2; }

.tabs { display: flex; gap: 2px; background: var(--surface); border-radius: var(--radius); padding: 0 8px; margin-bottom: 12px; }
.tabs a { padding: 10px 10px; color: var(--text); font-size: .82rem; border-bottom: 2px solid transparent; }
.tabs a.active { border-bottom-color: var(--navy); font-weight: 500; }
.tabs a:hover { text-decoration: none; }

.month-nav { display: flex; align-items: center; gap: 8px; }
.month-nav strong { min-width: 140px; text-align: center; font-weight: 500; }

#map, .map { height: 300px; border-radius: var(--radius); }
#map.map-tall, .map-tall { height: 420px; }
.chart-box { position: relative; height: 240px; }

/* calendar */
.cal { width: 100%; background: var(--surface); border-radius: var(--radius); border-collapse: collapse; table-layout: fixed; }
.cal th { text-align: center; font-size: .66rem; color: var(--muted); font-weight: 500; padding: 4px; border: 0; }
.cal td { vertical-align: top; height: 92px; border: 1px solid var(--border); padding: 6px 8px; font-size: .72rem; }
.cal td.out { background: #efefef; color: #999; }
.cal .d { text-align: center; font-size: .82rem; margin-bottom: 4px; }
.cal .d.today span { display: inline-grid; place-items: center; width: 24px; height: 24px; border: 1px solid var(--text); border-radius: 50%; }
.cal .line { display: flex; gap: 6px; align-items: center; white-space: nowrap; overflow: hidden; }
.cal .line i { width: 12px; text-align: center; }

.code { font: 600 2rem/1.2 ui-monospace, Consolas, monospace; letter-spacing: .15em; padding: 12px 18px; background: var(--surface-2); border-radius: var(--radius); display: inline-block; }
ol.steps li { margin-bottom: 6px; }
code { font-family: ui-monospace, Consolas, monospace; font-size: .8em; background: var(--surface-2); padding: 1px 5px; border-radius: 3px; overflow-wrap: anywhere; }
ul.keys { columns: 2 320px; padding-left: 18px; }
details > summary { cursor: pointer; }
.addr-lines { line-height: 1.6; }

@media (max-width: 640px) {
  header.top .inner, nav.sub .inner, main { padding-left: 16px; padding-right: 16px; }
  .car-pill span { display: none; }
  .cal td { height: 70px; font-size: .62rem; padding: 3px; }
}
.approx { color: #8a8f9c; font-style: italic; }
