:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1d2733;
  --muted: #6b7785;
  --border: #dde3ea;
  --accent: #1565c0;
  --accent-2: #0d47a1;
  --ok: #2e7d32;
  --warn: #f9a825;
  --bad: #c62828;
  --water: #00acc1;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px; color: var(--text); background: var(--bg); }
#app { display: flex; height: 100vh; }
#sidebar { width: 420px; min-width: 340px; overflow-y: auto; padding: 12px; background: var(--bg);
  border-right: 1px solid var(--border); }
#map { flex: 1; }
.brand { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.brand h1 { font-size: 20px; margin: 0; }
.brand small { color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.card h2 { font-size: 15px; margin: 0 0 8px; text-transform: uppercase; letter-spacing: .04em; color: var(--accent-2); }
.row { display: flex; gap: 6px; align-items: center; margin: 6px 0; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid2 .span2 { grid-column: span 2; }
label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 13px; margin: 4px 0; }
input, select, textarea { font: inherit; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px;
  background: #fff; color: var(--text); width: 100%; }
label.check input { width: auto; }
select { width: 100%; }
button { font: inherit; padding: 6px 10px; border-radius: 6px; border: 1px solid var(--border); background: #fff;
  cursor: pointer; color: var(--text); }
button:hover { background: #eef3f9; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.primary:hover { background: var(--accent-2); }
button.danger { color: var(--bad); border-color: #f0c4c4; }
button.icon { font-size: 18px; padding: 4px 8px; }
button.small { padding: 2px 6px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }
.muted { color: var(--muted); }
.neg { color: var(--bad); font-weight: 600; }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
.hidden { display: none !important; }
details summary { cursor: pointer; margin: 8px 0; color: var(--accent-2); }
.specs { font-size: 12px; color: var(--muted); display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px; }
.specs b { color: var(--text); font-weight: 600; }
.badge { display: inline-block; padding: 1px 6px; border-radius: 10px; font-size: 11px; background: #e3f2fd; color: var(--accent-2); }
.badge.water { background: #e0f7fa; color: #00838f; }
.badge.ok { background: #e8f5e9; color: var(--ok); }
.badge.bad { background: #ffebee; color: var(--bad); }
.badge.warn { background: #fff8e1; color: #8d6e00; }

/* route editor */
.wp { display: flex; gap: 6px; align-items: flex-start; margin-bottom: 6px; position: relative; }
.wp .tag { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; display: flex;
  align-items: center; justify-content: center; font-size: 12px; flex-shrink: 0; margin-top: 3px; }
.wp.dep .tag { background: var(--ok); }
.wp.dest .tag { background: var(--bad); }
.wp .body { flex: 1; position: relative; }
.wp .chosen { padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; background: #fafbfc; }
.wp .chosen .sub { font-size: 11px; color: var(--muted); }
.wp .acts { display: flex; flex-direction: column; gap: 2px; }
.wp .tag[data-a=focus] { cursor: pointer; }
.wp.focus .tag { box-shadow: 0 0 0 3px #ffb300; }
.wp .fuel { display: flex; align-items: center; gap: 4px; margin-top: 4px; flex-wrap: wrap; font-size: 12px; }
.wp .fuel select { width: auto; flex: 1 1 130px; padding: 3px 4px; font-size: 12px; }
.wp .fuel input[type=number] { width: 80px; padding: 3px 4px; font-size: 12px; }
.wp .fuel input[type=range] { flex: 1 1 100%; padding: 0; border: none; }
.wp .fuel-info { font-size: 11px; color: var(--muted); margin-top: 2px; }
.wp .fuel-info b { color: var(--text); font-weight: 600; }
.wp .fuel-info .msg { margin: 2px 0 0; }
.ac-list { position: absolute; z-index: 1000; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--border);
  border-radius: 6px; box-shadow: 0 6px 18px rgba(0,0,0,.12); max-height: 320px; overflow-y: auto; }
.ac-item { padding: 6px 8px; border-bottom: 1px solid #f0f2f5; cursor: pointer; }
.ac-item:hover { background: #eef3f9; }
.ac-item.disabled { opacity: .55; cursor: not-allowed; background: #fafafa; }
.ac-item .sub { font-size: 11px; color: var(--muted); }
.ac-item .why { font-size: 11px; color: var(--bad); }

/* results */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 8px; }
.kpi { background: #f6f9fc; border-radius: 8px; padding: 6px 8px; }
.kpi .v { font-size: 17px; font-weight: 700; }
.kpi .l { font-size: 11px; color: var(--muted); }
.kpi.big { grid-column: span 3; background: #e3f2fd; }
.kpi.big .v { font-size: 24px; color: var(--accent-2); }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { text-align: left; padding: 4px; border-bottom: 1px solid #eef1f4; vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
.msg { font-size: 12px; margin: 3px 0; padding: 4px 6px; border-radius: 4px; }
.msg.err { background: #ffebee; color: var(--bad); }
.msg.warn { background: #fff8e1; color: #6d5600; }
.legend { display: flex; flex-wrap: wrap; gap: 8px; font-size: 11px; color: var(--muted); margin-top: 8px; }
.legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 3px; vertical-align: middle; }
.legend .sq { display: inline-block; width: 12px; height: 10px; margin-right: 3px; vertical-align: middle; opacity: .7; }
.disclaimer { font-size: 11px; color: var(--muted); padding: 4px 4px 20px; }

/* dialogs */
dialog { border: none; border-radius: 12px; padding: 0; width: min(760px, 96vw); max-height: 92vh; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(10, 20, 30, .45); }
dialog form { padding: 16px 18px; overflow-y: auto; max-height: 92vh; }
dialog h2 { margin-top: 0; }
fieldset { border: 1px solid var(--border); border-radius: 8px; margin: 0 0 10px; padding: 8px 10px; }
legend { font-weight: 600; color: var(--accent-2); padding: 0 4px; }
.fgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.fgrid .wide { grid-column: span 3; }
.note { background: #fff8e1; border-radius: 6px; padding: 8px; font-size: 12px; margin-bottom: 8px; }
.surfaces { display: flex; gap: 10px; flex-wrap: wrap; }
#toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: #263238; color: #fff;
  padding: 8px 14px; border-radius: 8px; opacity: 0; transition: opacity .3s; pointer-events: none; z-index: 5000; max-width: 90vw; }
#toast.show { opacity: .95; }

/* map popups */
.leaflet-popup-content { font-size: 13px; min-width: 220px; }
.pop h3 { margin: 0 0 4px; font-size: 14px; }
.pop .sub { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.pop .btns { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.pop .btns button { font-size: 12px; padding: 3px 6px; }
.compass { display: grid; grid-template-columns: repeat(6, 1fr); gap: 2px; font-size: 10px; margin-top: 4px; }
.compass span { padding: 1px 2px; border-radius: 3px; text-align: center; }
.spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid #cfd8dc; border-top-color: var(--accent);
  border-radius: 50%; animation: spin 1s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 860px) {
  #app { flex-direction: column-reverse; height: auto; }
  #map { height: 55vh; flex: none; }
  #sidebar { width: 100%; min-width: 0; border-right: none; }
  .fgrid { grid-template-columns: 1fr 1fr; }
  .fgrid .wide { grid-column: span 2; }
}

/* ---------- account, feedback, export ---------- */
.brand-acts { display: flex; align-items: center; gap: 6px; }
body.pubblico .admin-only { display: none !important; }
button.link { border: 0; background: none; padding: 2px 4px; color: var(--accent); text-decoration: underline; }
button.link:hover { background: none; color: var(--accent-2); }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; }
.hp { position: absolute !important; left: -10000px; width: 1px; height: 1px; opacity: 0; }
.err-text { color: var(--bad); font-size: 13px; min-height: 1em; margin-top: 6px; }
#dlg-account, #dlg-me, #dlg-feedback { width: min(440px, calc(100vw - 32px)); }
#dlg-account label, #dlg-feedback label { margin-bottom: 8px; }
#acc-code { font-size: 22px; letter-spacing: 6px; text-align: center; font-variant-numeric: tabular-nums; }
.voto { border: 1px solid var(--border); border-radius: 6px; display: flex; gap: 10px; margin: 0 0 8px; padding: 4px 10px 8px; }
.voto legend { font-size: 12px; color: var(--muted); }
.voto label { flex-direction: row; align-items: center; gap: 3px; color: var(--text); margin: 0; }
.voto input { width: auto; }
.foot-links { margin-top: 6px; }
.reazione { position: fixed; left: 50%; bottom: 70px; transform: translateX(-50%); z-index: 1200; background: var(--card);
  border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px; box-shadow: 0 4px 16px rgba(0,0,0,.15);
  display: flex; align-items: center; gap: 6px; font-size: 13px; }
.reazione.hidden { display: none; }
.reazione button { padding: 2px 8px; }
#print-frame { position: fixed; width: 0; height: 0; border: 0; visibility: hidden; }
#export-tools { margin-top: 8px; }
#dlg-account, #dlg-me { padding: 16px 18px; }
#dlg-account form { padding: 0; overflow: visible; }

/* ricerca aeroporti sulla mappa */
.map-search { background: #fff; width: min(320px, calc(100vw - 80px)); }
.map-search input { width: 100%; box-sizing: border-box; border: 0; padding: 8px 10px; font-size: 14px; border-radius: 4px; }
.map-search input:focus { outline: 2px solid #1565c0; outline-offset: -2px; }
.map-search-list { max-height: 50vh; overflow: auto; border-top: 1px solid #e3e6ea; }
.leaflet-popup-content .ac-item { margin: 0 -4px; }
