:root {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #6b7280;
  --border: #d9dde3;
  --grid: #eceef1;
  --accent: #1c7ed6;
  --accent-text: #ffffff;
  --track: #1c7ed6;
  --removed: #b8bec7;
  --sel: #0ca678;
  --jump: #e03131;
  --stop: #f08c00;
  --vehicle: #7048e8;
  --preview: #212529;
  --ele-fill: rgb(134 142 150 / .30);
  --ele-line: #868e96;
  --danger: #c92a2a;
  --ok: #2b8a3e;
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column;
}

button {
  font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 11px; cursor: pointer; white-space: nowrap;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.primary:hover:not(:disabled) { filter: brightness(1.08); }
button.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }

/* ---------- barra in alto ---------- */
.bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; margin-right: 6px; }
.file-info { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.file-info b { color: var(--text); }
.spacer { flex: 1; }

/* ---------- area principale ---------- */
.layout { flex: 1; display: flex; min-height: 0; }
.work { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
#map { flex: 1; min-height: 200px; background: #dde3ea; }
.chart-wrap { height: 190px; position: relative; background: var(--panel); border-top: 1px solid var(--border); }
#chart { display: block; cursor: crosshair; }
.chart-hint { position: absolute; left: 52px; top: 1px; font-size: 11px; color: var(--muted); pointer-events: none; }

.empty {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--bg) 92%, transparent); z-index: 1000;
}
.empty[hidden] { display: none; }
.drop {
  border: 2px dashed var(--border); border-radius: 14px; padding: 40px 56px;
  text-align: center; background: var(--panel);
}
.drop .big { font-size: 20px; margin-top: 0; }
body.dragover .drop { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--panel)); }

/* ---------- pannello laterale ---------- */
.side {
  width: 360px; flex-shrink: 0; overflow-y: auto; padding: 10px;
  display: flex; flex-direction: column; gap: 10px;
  border-left: 1px solid var(--border);
}
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 8px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.card-head h2 { margin: 0; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.btn-row.tight { margin-top: 0; }
.btn-row button { padding: 4px 9px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.stats { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.stats th { text-align: right; font-weight: 600; color: var(--muted); font-size: 12px; padding: 2px 0 4px; }
.stats th:first-child { text-align: left; }
.stats td { padding: 3px 0; text-align: right; }
.stats td:first-child { text-align: left; color: var(--muted); }
.stats td.better { color: var(--ok); font-weight: 600; }

.sel-info { margin: 0; }
.sel-info .warn {
  display: block; margin-top: 8px; padding: 6px 9px; border-radius: 6px; font-size: 12px; line-height: 1.35;
  background: color-mix(in srgb, var(--stop) 14%, var(--panel)); color: color-mix(in srgb, var(--stop) 55%, var(--text));
}
.ele-status { margin: 8px 0 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ele-status:empty { display: none; }
.ele-status button { padding: 1px 8px; font-size: 12px; }

/* ---------- proposte ---------- */
.proposals { display: flex; flex-direction: column; gap: 10px; }
.group-head { display: flex; align-items: center; gap: 6px; font-weight: 600; margin-bottom: 4px; }
.group-head .count { color: var(--muted); font-weight: 400; }
.group-head .acts { margin-left: auto; display: flex; gap: 4px; }
.group-head .acts button { padding: 1px 7px; font-size: 12px; font-weight: 400; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; vertical-align: middle; margin-right: 4px; }
.dot.jump { background: var(--jump); }
.dot.stop { background: var(--stop); }
.dot.vehicle { background: var(--vehicle); }
.items { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow-y: auto; }
.item {
  display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-radius: 6px; cursor: pointer;
}
.item:hover { background: var(--grid); }
.item.active { background: color-mix(in srgb, var(--accent) 14%, var(--panel)); }
.item .time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; width: 38px; flex-shrink: 0; }
.item .label { flex: 1; min-width: 0; }
.item button { padding: 0 7px; font-size: 13px; line-height: 20px; }
.item .yes { color: var(--ok); }
.item .no { color: var(--danger); }
.item.accepted .label { color: var(--ok); }
.item.rejected .label { color: var(--muted); text-decoration: line-through; }
.item .state { font-size: 12px; color: var(--muted); }
.none { color: var(--muted); font-size: 13px; }
.pauses { max-height: 160px; }
.pauses .time { width: auto; min-width: 38px; }
.pauses:empty { display: none; }
.merge-list { margin: 8px 0; padding-left: 22px; }
.merge-list li { padding: 3px 0; }
.merge-list li > span { display: inline-flex; align-items: center; gap: 6px; width: 100%; }
.merge-list .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.merge-list .info { color: var(--muted); font-size: 12px; white-space: nowrap; }
.merge-list button { padding: 0 7px; line-height: 20px; }

.form { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.form label { display: flex; align-items: center; gap: 6px; }
.form input { width: 64px; font: inherit; padding: 2px 4px; border: 1px solid var(--border); border-radius: 4px; margin-left: auto; }
.form input[type=range] { flex: 1; width: auto; margin: 0; padding: 0; border: 0; }
.form input[type=radio] { width: auto; margin: 0; }
.form p { margin: 0; }
.scope { display: flex; gap: 14px; }
.scope label { gap: 5px; }
#simpTolVal { min-width: 44px; text-align: right; font-variant-numeric: tabular-nums; }
summary { cursor: pointer; font-weight: 600; }

/* ---------- finestra di aiuto ---------- */
dialog { border: 1px solid var(--border); border-radius: 12px; padding: 18px 22px; max-width: 520px; color: var(--text); background: var(--panel); }
dialog::backdrop { background: rgb(0 0 0 / .35); }
dialog h2 { margin-top: 0; }
#exportDlg { max-width: 640px; width: calc(100% - 32px); }
.export-form label.col { flex-direction: column; align-items: stretch; gap: 3px; }
.export-form input[type=text], .export-form textarea, .export-form select {
  width: 100%; margin: 0; font: inherit; padding: 5px 7px; border: 1px solid var(--border); border-radius: 6px; resize: vertical;
}
.export-form input[type=checkbox] { width: auto; margin: 0; }
.exp-preview { display: block; width: 100%; margin-top: 12px; border: 1px solid var(--border); border-radius: 6px; }
.exp-preview:not([src]) { display: none; }
.keys td { padding: 3px 12px 3px 0; vertical-align: top; }
.keys td:first-child { font-weight: 600; white-space: nowrap; }

/* ---------- mappa ---------- */
.leaflet-container.selecting { cursor: crosshair; }
.map-hint {
  background: color-mix(in srgb, var(--panel) 90%, transparent); padding: 3px 8px; border-radius: 6px;
  font-size: 12px; color: var(--muted); box-shadow: 0 1px 3px rgb(0 0 0 / .15);
}

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .side { width: auto; border-left: 0; border-top: 1px solid var(--border); max-height: 45vh; }
  .chart-hint { display: none; }
}


/* ---------- scheda del sentiero ---------- */
.sheet-view { position: fixed; inset: 0; z-index: 3000; display: flex; background: #dfe3e8; }
.sheet-view[hidden] { display: none; }
.sheet-tools {
  width: 330px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--border);
  padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px;
}
.sheet-tools h2 { margin: 0; font-size: 18px; }
.sheet-tools p { margin: 0; }
.sheet-tools .btn-row { margin-top: 0; }
.sheet-scroll { flex: 1; overflow: auto; padding: 28px; }
.sheet {
  width: 210mm; height: 297mm; margin: 0 auto; background: #fff; color: #0f172a;
  box-shadow: 0 6px 28px rgb(0 0 0 / .18);
  padding: 13mm 13mm 9mm; display: flex; flex-direction: column; gap: 4.5mm; overflow: hidden;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
.sh-head h1 { font-size: 22pt; line-height: 1.15; margin: 0; letter-spacing: -.01em; }
.sh-head p { margin: 2mm 0 0; font-size: 10pt; line-height: 1.4; color: #475569; white-space: pre-wrap; }
.sh-head p[hidden] { display: none; }
.sh-chips { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2.5mm; }
.sh-chip { background: #f1f5f9; border-radius: 3mm; padding: 2.4mm 3mm 2.6mm; min-width: 0; }
.sh-chip .l { font-size: 6.5pt; font-weight: 600; letter-spacing: .09em; text-transform: uppercase; color: #64748b; }
.sh-chip .v { font-size: 13.5pt; font-weight: 700; margin-top: .6mm; white-space: nowrap; }
.sh-est { margin: -2.5mm 0 0; font-size: 7pt; line-height: 1.35; color: #64748b; }
.sh-info { display: grid; grid-template-columns: 1fr 1fr; gap: 3mm 7mm; margin: 0; font-size: 9.5pt; line-height: 1.35; }
.sh-info[hidden] { display: none; }
.sh-info > div { border-left: 2.5px solid #1c7ed6; padding-left: 2.8mm; min-width: 0; }
.sh-info .wide { grid-column: 1 / -1; }
.sh-info dt { font-size: 6.5pt; font-weight: 600; letter-spacing: .09em; text-transform: uppercase; color: #64748b; }
.sh-info dd { margin: .4mm 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.sh-map { flex: 1; min-height: 60mm; border-radius: 2.5mm; overflow: hidden; border: 1px solid #cbd5e1; }
.sh-profile { display: block; width: 100%; height: auto; }
.sh-profile[hidden], .sh-noele[hidden] { display: none; }
.sh-noele { margin: 0; font-size: 9pt; color: #64748b; text-align: center; }
.sh-foot {
  display: flex; justify-content: space-between; gap: 6mm; font-size: 7.5pt; color: #94a3b8;
  border-top: 1px solid #e2e8f0; padding-top: 2.2mm;
}
.sh-foot .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin: 0 3px 0 6px; vertical-align: middle; }
.sh-foot .dot.start { background: #2b8a3e; }
.sh-foot .dot.end { background: #c92a2a; }
.km-mark span {
  display: flex; align-items: center; justify-content: center; width: 22px; height: 22px; box-sizing: border-box;
  border-radius: 50%; background: #fff; border: 2px solid #0f172a; color: #0f172a;
  font: 700 11px/1 "Segoe UI", system-ui, sans-serif; box-shadow: 0 1px 3px rgb(0 0 0 / .35);
}
.sh-map .leaflet-control-attribution { font-size: 9px; }

@page { size: A4 portrait; margin: 0; }
@media print {
  html, body { height: auto; background: #fff; display: block; }
  body.sheet-open > *:not(#sheetView) { display: none !important; }
  body.sheet-open #sheetView { position: static; display: block; background: none; }
  .sheet-tools { display: none; }
  .sheet-scroll { padding: 0; overflow: visible; }
  .sheet { box-shadow: none; margin: 0; page-break-after: avoid; break-after: avoid; }
  .sh-map .leaflet-control-zoom { display: none; }
}
