/* Tracce — stili */

:root {
  --ink: #182420;          /* verde-inchiostro scuro */
  --ink-soft: #24332e;
  --paper: #f7f6f2;
  --line: #d8d5cc;
  --text: #23292a;
  --muted: #6d746f;
  --accent: #e05d44;       /* corallo tracciato */
  --radius: 10px;
  --sidebar-w: 330px;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "Archivo", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--paper);
}

h1 {
  font-weight: 800;
  font-stretch: 80%;
  letter-spacing: -0.02em;
  margin: 0;
}

/* ---------- Landing ---------- */

.landing {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(24, 36, 32, 0.88), rgba(24, 36, 32, 0.88)),
    repeating-linear-gradient(115deg, transparent 0 38px, rgba(224, 93, 68, 0.16) 38px 40px);
  background-color: var(--ink);
}

.landing-card {
  max-width: 460px;
  background: var(--paper);
  border-radius: var(--radius);
  padding: 40px 36px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.landing-card h1 { font-size: 2.6rem; }

.tagline {
  font-weight: 600;
  font-size: 1.1rem;
  margin: 6px 0 14px;
  color: var(--accent);
}

.landing-card p { line-height: 1.5; }

.hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 18px;
}

/* ---------- Bottoni ---------- */

.btn {
  display: inline-block;
  border: 0;
  border-radius: 8px;
  padding: 12px 22px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  background: var(--ink);
  color: #fff;
  transition: transform 0.12s ease, opacity 0.12s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: 0.55; cursor: wait; transform: none; }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.btn-strava { background: var(--accent); }
.btn-small { padding: 8px 14px; font-size: 0.9rem; width: 100%; }

/* ---------- Layout app ---------- */

.app {
  display: flex;
  height: 100vh;
  overflow: hidden;   /* ogni blocco scorre per conto suo */
}

.main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
#map { flex: 1; min-height: 0; }

.sidebar {
  display: flex;
  flex-direction: column;
  flex: 0 0 var(--sidebar-w);
  width: var(--sidebar-w);
  background: var(--paper);
  border-right: 1px solid var(--line);
  overflow-y: auto;                     /* scroll indipendente dal main */
  transition: margin-left 0.25s ease;
  position: relative;
}

/* Sidebar collassata: scivola fuori a sinistra, il main occupa tutto */
.app.sidebar-collapsed .sidebar { margin-left: calc(-1 * var(--sidebar-w)); }

.sidebar-toggle {
  position: absolute;
  top: 14px;
  right: 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 6px;
  width: 26px;
  height: 26px;
  font-size: 0.7rem;
  cursor: pointer;
  padding: 0;
}
.sidebar-toggle:hover { color: var(--accent); border-color: var(--accent); }

.sidebar-show {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 6px;
  width: 30px;
  font-size: 0.7rem;
  cursor: pointer;
  padding: 0;
  margin: 0 4px 8px 0;
}
.sidebar-show:hover { color: var(--accent); border-color: var(--accent); }
.sidebar-show[hidden] { display: none; }

.sidebar-head {
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--line);
}
.sidebar-head h1 { font-size: 1.5rem; }

.athlete {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  font-size: 0.92rem;
}
.avatar { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; }
.logout {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.85rem;
  text-decoration: none;
}
.logout:hover { color: var(--accent); }

.controls {
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-bottom: 1px solid var(--line);
}

/* ---------- Import GPX ---------- */

.gpx-box summary {
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
}
.gpx-box form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
  font-size: 0.85rem;
}
.gpx-box input[type="text"] {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
}

/* ---------- Filtri ---------- */

.filter-group { display: flex; flex-direction: column; gap: 8px; }

.filter-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.filter-title button {
  border: 0;
  background: none;
  font: inherit;
  font-size: 0.75rem;
  text-transform: none;
  letter-spacing: 0;
  color: var(--accent);
  cursor: pointer;
}

#type-filters { display: flex; flex-wrap: wrap; gap: 6px; }

.type-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.82rem;
  cursor: pointer;
  background: #fff;
  user-select: none;
}
.type-chip:has(input:checked) {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}
.type-chip input[type="checkbox"] { position: absolute; opacity: 0; pointer-events: none; }
.type-chip .count { opacity: 0.6; font-size: 0.75rem; }

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.dates { display: flex; gap: 10px; font-size: 0.82rem; }
.dates label { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.dates input {
  padding: 5px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  font-size: 0.82rem;
}

.stats { font-size: 0.88rem; color: var(--muted); }
.stats strong { color: var(--text); }

/* ---------- Lista attività ---------- */

.activity-list {
  list-style: none;
  margin: 0;
  padding: 8px 10px 20px;
}

.activity {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.activity:hover { background: #eeece6; }
.activity.selected { background: #e8e4da; }
.activity .dot { margin-top: 5px; }

.act-main { display: flex; flex-direction: column; min-width: 0; }
.act-name {
  font-weight: 600;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.act-meta { font-size: 0.78rem; color: var(--muted); }

.act-del {
  margin-left: auto;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  visibility: hidden;
}
.activity:hover .act-del, .poi-table tr:hover .act-del { visibility: visible; }
.act-del:hover { color: #c0392b; background: #fdf1ef; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 11px 20px;
  border-radius: 8px;
  font-size: 0.9rem;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
  z-index: 2000;
  max-width: min(90vw, 560px);
}

/* ---------- Mobile ---------- */

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 1fr 45vh; }
  .sidebar { order: 2; border-right: 0; border-top: 1px solid var(--line); }
  .main { order: 1; min-height: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---------- Accesso locale ---------- */

.local-form { margin-top: 18px; }
.local-form label {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 6px;
}
.local-row { display: flex; gap: 8px; }
.local-row input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
}
.form-error {
  color: var(--accent);
  font-size: 0.85rem;
  margin: 8px 0 0;
}

/* ---------- Vette ---------- */

.peak-dist { display: flex; flex-direction: column; gap: 4px; font-size: 0.82rem; }
.peak-dist input {
  width: 110px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
}
.peak-note { font-size: 0.75rem; color: var(--muted); margin: 2px 0 0; line-height: 1.4; }

/* ---------- Icone Material Symbols (POI) ---------- */

.material-symbols-outlined.poi-ico {
  font-size: 1.05em;
  line-height: 1;
  vertical-align: -0.18em;
}
.tab-ico { font-size: 1.15em !important; vertical-align: -0.22em; }

.poi-peak { color: var(--ink); }
.poi-pass { color: #8a5a2b; }
.poi-hut  { color: #2f6fa8; }

.peak-marker {
  text-align: center;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 4px #fff;
}
.peak-marker .material-symbols-outlined {
  font-size: 20px;
  line-height: 1;
}
.peak-marker.poi-peak { color: var(--ink); }
.peak-marker.poi-pass { color: #8a5a2b; }
.peak-marker.poi-hut  { color: #2f6fa8; }

.popup-peaks { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 6px; }
.popup-peaks ul { margin: 0 0 6px; padding-left: 4px; list-style: none; font-size: 0.85rem; }
.popup-peaks li { margin: 2px 0; }
.peak-dist-label { color: var(--muted); font-size: 0.78rem; }
.btn-detect {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  padding: 4px 10px;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}
.btn-detect:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- Import archivio ZIP ---------- */

.gpx-box select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  font-size: 0.85rem;
}
#zip-types { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
#zip-type-list { display: flex; flex-wrap: wrap; gap: 6px; }

.progress-track {
  height: 8px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 10px;
}
.progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.3s ease;
}

/* ---------- Eliminazione ---------- */

.act-del {
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
  opacity: 0;
  margin-left: auto;
  flex: 0 0 auto;
}
.activity:hover .act-del { opacity: 1; }
.act-del:hover { color: #fff; background: var(--accent); }

.btn-danger {
  border: 1px solid var(--line);
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.82rem;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.btn-danger:hover { border-color: #c0342b; color: #c0342b; }

#peaks-queue { display: flex; flex-direction: column; gap: 6px; }
#peaks-queue[hidden] { display: none; }


/* ---------- Tab e tabelle POI ---------- */

.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 12px 0;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.tab {
  border: 1px solid transparent;
  border-bottom: 0;
  background: none;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active {
  background: #fff;
  border-color: var(--line);
  color: var(--text);
  margin-bottom: -1px;
}

#poi-view, #tracks-view { flex: 1; min-height: 0; overflow: auto; background: #fff; padding: 0 0 30px; }

.tracks-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  font-size: 0.85rem;
}
.tracks-bar select {
  margin-left: 8px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  font-size: 0.85rem;
  background: #fff;
  max-width: 260px;
}
#tracks-table th { top: 0; }
#tracks-table .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; vertical-align: baseline; margin-right: 4px; }

.poi-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.poi-table th {
  position: sticky;
  top: 0;
  background: var(--paper);
  text-align: left;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.poi-table th.sorted::after { content: " \2191"; }
.poi-table th.sorted.desc::after { content: " \2193"; }
.poi-table td { padding: 9px 14px; border-bottom: 1px solid #eeece6; }
.poi-table td.num, .poi-table th.num { text-align: right; }
.poi-table tbody tr { cursor: pointer; }
.poi-table tbody tr:hover { background: #f4f2ec; }

.poi-empty { padding: 30px 20px; color: var(--muted); font-size: 0.9rem; }

/* Righe raggruppate (passaggi multipli) */
.poi-count {
  display: inline-block;
  min-width: 22px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 0.8rem;
  text-align: center;
}
.poi-caret { color: var(--muted); font-size: 0.8em; transition: transform 0.15s ease; display: inline-block; }
tr.poi-multi.open .poi-caret { transform: rotate(180deg); }
tr.poi-sub td { background: #faf9f5; padding-top: 6px; padding-bottom: 6px; font-size: 0.85rem; }
tr.poi-sub:hover td { background: #f0eee7; }

/* ---------- Color picker nei chip ---------- */

.type-chip { padding-left: 6px; }
.type-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.type-color {
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  border-radius: 50%;
  overflow: hidden;
  cursor: pointer;
  background: none;
  flex: 0 0 auto;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.85), 0 0 0 1px rgba(0, 0, 0, 0.25);
}
.type-color:hover { transform: scale(1.15); }
.type-color::-webkit-color-swatch-wrapper { padding: 0; }
.type-color::-webkit-color-swatch { border: none; border-radius: 50%; }
.type-color::-moz-color-swatch { border: none; border-radius: 50%; }

/* Bottone di rimozione POI (tabella e popup) */
.poi-remove {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 999px;
  width: 20px;
  height: 20px;
  line-height: 1;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0;
  vertical-align: middle;
}
.poi-remove:hover { border-color: #c0392b; color: #c0392b; background: #fdf1ef; }
.poi-table td.poi-actions { width: 36px; text-align: center; }
.poi-table th.no-sort { cursor: default; }
.popup-peaks .poi-remove { margin-left: 4px; }


/* Riscansione totale POI */
.link-danger {
  border: 0;
  background: none;
  font: inherit;
  font-size: 0.78rem;
  color: var(--muted);
  cursor: pointer;
  text-align: left;
  padding: 0;
  text-decoration: underline;
}
.link-danger:hover { color: #c0392b; }

/* ---------- Modale di conferma (sostituisce i confirm() nativi) ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(24, 36, 32, 0.45);
  display: grid;
  place-items: center;
  z-index: 3000;              /* sopra i controlli Leaflet (~1000) */
  padding: 20px;
}
.modal {
  background: var(--paper);
  border-radius: var(--radius);
  padding: 22px 24px;
  max-width: 440px;
  width: 100%;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.35);
}
.modal-msg {
  margin: 0 0 18px;
  white-space: pre-line;      /* i \n del messaggio vanno a capo */
  line-height: 1.45;
  font-size: 0.95rem;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.modal-actions .btn-small { width: auto; }
.modal-cancel { background: #fff; color: var(--text); border: 1px solid var(--line); }
.modal-danger { background: #c0392b; }

/* Su dispositivi touch non esiste l'hover: i bottoni di eliminazione
   devono essere sempre visibili */
@media (hover: none) {
  .act-del { visibility: visible; }
}
